symlink.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #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_page_getlink(struct dentry * dentry,
  52. struct page **ppage);
  53. static char *ocfs2_fast_symlink_getlink(struct inode *inode,
  54. struct buffer_head **bh);
  55. /* get the link contents into pagecache */
  56. static char *ocfs2_page_getlink(struct dentry * dentry,
  57. struct page **ppage)
  58. {
  59. struct page * page;
  60. struct address_space *mapping = dentry->d_inode->i_mapping;
  61. page = read_mapping_page(mapping, 0, NULL);
  62. if (IS_ERR(page))
  63. goto sync_fail;
  64. *ppage = page;
  65. return kmap(page);
  66. sync_fail:
  67. return (char*)page;
  68. }
  69. static char *ocfs2_fast_symlink_getlink(struct inode *inode,
  70. struct buffer_head **bh)
  71. {
  72. int status;
  73. char *link = NULL;
  74. struct ocfs2_dinode *fe;
  75. mlog_entry_void();
  76. status = ocfs2_read_block(OCFS2_SB(inode->i_sb),
  77. OCFS2_I(inode)->ip_blkno,
  78. bh,
  79. OCFS2_BH_CACHED,
  80. inode);
  81. if (status < 0) {
  82. mlog_errno(status);
  83. link = ERR_PTR(status);
  84. goto bail;
  85. }
  86. fe = (struct ocfs2_dinode *) (*bh)->b_data;
  87. link = (char *) fe->id2.i_symlink;
  88. bail:
  89. mlog_exit(status);
  90. return link;
  91. }
  92. static int ocfs2_readlink(struct dentry *dentry,
  93. char __user *buffer,
  94. int buflen)
  95. {
  96. int ret;
  97. char *link;
  98. struct buffer_head *bh = NULL;
  99. struct inode *inode = dentry->d_inode;
  100. mlog_entry_void();
  101. link = ocfs2_fast_symlink_getlink(inode, &bh);
  102. if (IS_ERR(link)) {
  103. ret = PTR_ERR(link);
  104. goto out;
  105. }
  106. /*
  107. * Without vfsmount we can't update atime now,
  108. * but we will update atime here ultimately.
  109. */
  110. ret = vfs_readlink(dentry, buffer, buflen, link);
  111. brelse(bh);
  112. out:
  113. mlog_exit(ret);
  114. return ret;
  115. }
  116. static void *ocfs2_follow_link(struct dentry *dentry,
  117. struct nameidata *nd)
  118. {
  119. int status;
  120. char *link;
  121. struct inode *inode = dentry->d_inode;
  122. struct page *page = NULL;
  123. struct buffer_head *bh = NULL;
  124. if (ocfs2_inode_is_fast_symlink(inode))
  125. link = ocfs2_fast_symlink_getlink(inode, &bh);
  126. else
  127. link = ocfs2_page_getlink(dentry, &page);
  128. if (IS_ERR(link)) {
  129. status = PTR_ERR(link);
  130. mlog_errno(status);
  131. goto bail;
  132. }
  133. status = vfs_follow_link(nd, link);
  134. bail:
  135. if (page) {
  136. kunmap(page);
  137. page_cache_release(page);
  138. }
  139. brelse(bh);
  140. return ERR_PTR(status);
  141. }
  142. const struct inode_operations ocfs2_symlink_inode_operations = {
  143. .readlink = page_readlink,
  144. .follow_link = ocfs2_follow_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. };
  152. const struct inode_operations ocfs2_fast_symlink_inode_operations = {
  153. .readlink = ocfs2_readlink,
  154. .follow_link = ocfs2_follow_link,
  155. .getattr = ocfs2_getattr,
  156. .setattr = ocfs2_setattr,
  157. .setxattr = generic_setxattr,
  158. .getxattr = generic_getxattr,
  159. .listxattr = ocfs2_listxattr,
  160. .removexattr = generic_removexattr,
  161. };