symlink.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * linux/cluster/ssi/cfs/symlink.c
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE
  14. * or NON INFRINGEMENT. See the GNU General Public License for more
  15. * details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. *
  21. * Questions/Comments/Bugfixes to ssic-linux-devel@lists.sourceforge.net
  22. *
  23. * Copyright (C) 1992 Rick Sladkey
  24. *
  25. * Optimization changes Copyright (C) 1994 Florian La Roche
  26. *
  27. * Jun 7 1999, cache symlink lookups in the page cache. -DaveM
  28. *
  29. * Portions Copyright (C) 2001 Compaq Computer Corporation
  30. *
  31. * ocfs2 symlink handling code.
  32. *
  33. * Copyright (C) 2004, 2005 Oracle.
  34. *
  35. */
  36. #include <linux/fs.h>
  37. #include <linux/types.h>
  38. #include <linux/slab.h>
  39. #include <linux/pagemap.h>
  40. #include <linux/namei.h>
  41. #define MLOG_MASK_PREFIX ML_NAMEI
  42. #include <cluster/masklog.h>
  43. #include "ocfs2.h"
  44. #include "alloc.h"
  45. #include "file.h"
  46. #include "inode.h"
  47. #include "journal.h"
  48. #include "symlink.h"
  49. #include "xattr.h"
  50. #include "buffer_head_io.h"
  51. static char *ocfs2_fast_symlink_getlink(struct inode *inode,
  52. struct buffer_head **bh)
  53. {
  54. int status;
  55. char *link = NULL;
  56. struct ocfs2_dinode *fe;
  57. mlog_entry_void();
  58. status = ocfs2_read_inode_block(inode, bh);
  59. if (status < 0) {
  60. mlog_errno(status);
  61. link = ERR_PTR(status);
  62. goto bail;
  63. }
  64. fe = (struct ocfs2_dinode *) (*bh)->b_data;
  65. link = (char *) fe->id2.i_symlink;
  66. bail:
  67. mlog_exit(status);
  68. return link;
  69. }
  70. static int ocfs2_readlink(struct dentry *dentry,
  71. char __user *buffer,
  72. int buflen)
  73. {
  74. int ret;
  75. char *link;
  76. struct buffer_head *bh = NULL;
  77. struct inode *inode = dentry->d_inode;
  78. mlog_entry_void();
  79. link = ocfs2_fast_symlink_getlink(inode, &bh);
  80. if (IS_ERR(link)) {
  81. ret = PTR_ERR(link);
  82. goto out;
  83. }
  84. /*
  85. * Without vfsmount we can't update atime now,
  86. * but we will update atime here ultimately.
  87. */
  88. ret = vfs_readlink(dentry, buffer, buflen, link);
  89. brelse(bh);
  90. out:
  91. mlog_exit(ret);
  92. return ret;
  93. }
  94. static void *ocfs2_fast_follow_link(struct dentry *dentry,
  95. struct nameidata *nd)
  96. {
  97. int status = 0;
  98. int len;
  99. char *target, *link = ERR_PTR(-ENOMEM);
  100. struct inode *inode = dentry->d_inode;
  101. struct buffer_head *bh = NULL;
  102. mlog_entry_void();
  103. BUG_ON(!ocfs2_inode_is_fast_symlink(inode));
  104. target = ocfs2_fast_symlink_getlink(inode, &bh);
  105. if (IS_ERR(target)) {
  106. status = PTR_ERR(target);
  107. mlog_errno(status);
  108. goto bail;
  109. }
  110. /* Fast symlinks can't be large */
  111. len = strlen(target);
  112. link = kzalloc(len + 1, GFP_NOFS);
  113. if (!link) {
  114. status = -ENOMEM;
  115. mlog_errno(status);
  116. goto bail;
  117. }
  118. memcpy(link, target, len);
  119. nd_set_link(nd, link);
  120. bail:
  121. brelse(bh);
  122. mlog_exit(status);
  123. return status ? ERR_PTR(status) : link;
  124. }
  125. static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
  126. {
  127. char *link = cookie;
  128. kfree(link);
  129. }
  130. const struct inode_operations ocfs2_symlink_inode_operations = {
  131. .readlink = page_readlink,
  132. .follow_link = page_follow_link_light,
  133. .put_link = page_put_link,
  134. .getattr = ocfs2_getattr,
  135. .setattr = ocfs2_setattr,
  136. .setxattr = generic_setxattr,
  137. .getxattr = generic_getxattr,
  138. .listxattr = ocfs2_listxattr,
  139. .removexattr = generic_removexattr,
  140. };
  141. const struct inode_operations ocfs2_fast_symlink_inode_operations = {
  142. .readlink = ocfs2_readlink,
  143. .follow_link = ocfs2_fast_follow_link,
  144. .put_link = ocfs2_fast_put_link,
  145. .getattr = ocfs2_getattr,
  146. .setattr = ocfs2_setattr,
  147. .setxattr = generic_setxattr,
  148. .getxattr = generic_getxattr,
  149. .listxattr = ocfs2_listxattr,
  150. .removexattr = generic_removexattr,
  151. };