symlink.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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/utsname.h>
  41. #include <linux/namei.h>
  42. #define MLOG_MASK_PREFIX ML_NAMEI
  43. #include <cluster/masklog.h>
  44. #include "ocfs2.h"
  45. #include "alloc.h"
  46. #include "file.h"
  47. #include "inode.h"
  48. #include "journal.h"
  49. #include "symlink.h"
  50. #include "xattr.h"
  51. #include "buffer_head_io.h"
  52. static char *ocfs2_fast_symlink_getlink(struct inode *inode,
  53. struct buffer_head **bh)
  54. {
  55. int status;
  56. char *link = NULL;
  57. struct ocfs2_dinode *fe;
  58. mlog_entry_void();
  59. status = ocfs2_read_inode_block(inode, bh);
  60. if (status < 0) {
  61. mlog_errno(status);
  62. link = ERR_PTR(status);
  63. goto bail;
  64. }
  65. fe = (struct ocfs2_dinode *) (*bh)->b_data;
  66. link = (char *) fe->id2.i_symlink;
  67. bail:
  68. mlog_exit(status);
  69. return link;
  70. }
  71. static int ocfs2_readlink(struct dentry *dentry,
  72. char __user *buffer,
  73. int buflen)
  74. {
  75. int ret;
  76. char *link;
  77. struct buffer_head *bh = NULL;
  78. struct inode *inode = dentry->d_inode;
  79. mlog_entry_void();
  80. link = ocfs2_fast_symlink_getlink(inode, &bh);
  81. if (IS_ERR(link)) {
  82. ret = PTR_ERR(link);
  83. goto out;
  84. }
  85. /*
  86. * Without vfsmount we can't update atime now,
  87. * but we will update atime here ultimately.
  88. */
  89. ret = vfs_readlink(dentry, buffer, buflen, link);
  90. brelse(bh);
  91. out:
  92. mlog_exit(ret);
  93. return ret;
  94. }
  95. static void *ocfs2_fast_follow_link(struct dentry *dentry,
  96. struct nameidata *nd)
  97. {
  98. int status = 0;
  99. int len;
  100. char *target, *link = ERR_PTR(-ENOMEM);
  101. struct inode *inode = dentry->d_inode;
  102. struct buffer_head *bh = NULL;
  103. mlog_entry_void();
  104. BUG_ON(!ocfs2_inode_is_fast_symlink(inode));
  105. target = ocfs2_fast_symlink_getlink(inode, &bh);
  106. if (IS_ERR(target)) {
  107. status = PTR_ERR(target);
  108. mlog_errno(status);
  109. goto bail;
  110. }
  111. /* Fast symlinks can't be large */
  112. len = strlen(target);
  113. link = kzalloc(len + 1, GFP_NOFS);
  114. if (!link) {
  115. status = -ENOMEM;
  116. mlog_errno(status);
  117. goto bail;
  118. }
  119. memcpy(link, target, len);
  120. nd_set_link(nd, link);
  121. bail:
  122. brelse(bh);
  123. mlog_exit(status);
  124. return status ? ERR_PTR(status) : link;
  125. }
  126. static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
  127. {
  128. char *link = cookie;
  129. kfree(link);
  130. }
  131. const struct inode_operations ocfs2_symlink_inode_operations = {
  132. .readlink = page_readlink,
  133. .follow_link = page_follow_link_light,
  134. .put_link = page_put_link,
  135. .getattr = ocfs2_getattr,
  136. .setattr = ocfs2_setattr,
  137. .setxattr = generic_setxattr,
  138. .getxattr = generic_getxattr,
  139. .listxattr = ocfs2_listxattr,
  140. .removexattr = generic_removexattr,
  141. };
  142. const struct inode_operations ocfs2_fast_symlink_inode_operations = {
  143. .readlink = ocfs2_readlink,
  144. .follow_link = ocfs2_fast_follow_link,
  145. .put_link = ocfs2_fast_put_link,
  146. .getattr = ocfs2_getattr,
  147. .setattr = ocfs2_setattr,
  148. .setxattr = generic_setxattr,
  149. .getxattr = generic_getxattr,
  150. .listxattr = ocfs2_listxattr,
  151. .removexattr = generic_removexattr,
  152. };