symlink.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_inode_block(inode, bh);
  77. if (status < 0) {
  78. mlog_errno(status);
  79. link = ERR_PTR(status);
  80. goto bail;
  81. }
  82. fe = (struct ocfs2_dinode *) (*bh)->b_data;
  83. link = (char *) fe->id2.i_symlink;
  84. bail:
  85. mlog_exit(status);
  86. return link;
  87. }
  88. static int ocfs2_readlink(struct dentry *dentry,
  89. char __user *buffer,
  90. int buflen)
  91. {
  92. int ret;
  93. char *link;
  94. struct buffer_head *bh = NULL;
  95. struct inode *inode = dentry->d_inode;
  96. mlog_entry_void();
  97. link = ocfs2_fast_symlink_getlink(inode, &bh);
  98. if (IS_ERR(link)) {
  99. ret = PTR_ERR(link);
  100. goto out;
  101. }
  102. /*
  103. * Without vfsmount we can't update atime now,
  104. * but we will update atime here ultimately.
  105. */
  106. ret = vfs_readlink(dentry, buffer, buflen, link);
  107. brelse(bh);
  108. out:
  109. mlog_exit(ret);
  110. return ret;
  111. }
  112. static void *ocfs2_follow_link(struct dentry *dentry,
  113. struct nameidata *nd)
  114. {
  115. int status;
  116. char *link;
  117. struct inode *inode = dentry->d_inode;
  118. struct page *page = NULL;
  119. struct buffer_head *bh = NULL;
  120. if (ocfs2_inode_is_fast_symlink(inode))
  121. link = ocfs2_fast_symlink_getlink(inode, &bh);
  122. else
  123. link = ocfs2_page_getlink(dentry, &page);
  124. if (IS_ERR(link)) {
  125. status = PTR_ERR(link);
  126. mlog_errno(status);
  127. goto bail;
  128. }
  129. status = vfs_follow_link(nd, link);
  130. bail:
  131. if (page) {
  132. kunmap(page);
  133. page_cache_release(page);
  134. }
  135. brelse(bh);
  136. return ERR_PTR(status);
  137. }
  138. const struct inode_operations ocfs2_symlink_inode_operations = {
  139. .readlink = page_readlink,
  140. .follow_link = ocfs2_follow_link,
  141. .getattr = ocfs2_getattr,
  142. .setattr = ocfs2_setattr,
  143. .setxattr = generic_setxattr,
  144. .getxattr = generic_getxattr,
  145. .listxattr = ocfs2_listxattr,
  146. .removexattr = generic_removexattr,
  147. };
  148. const struct inode_operations ocfs2_fast_symlink_inode_operations = {
  149. .readlink = ocfs2_readlink,
  150. .follow_link = ocfs2_follow_link,
  151. .getattr = ocfs2_getattr,
  152. .setattr = ocfs2_setattr,
  153. .setxattr = generic_setxattr,
  154. .getxattr = generic_getxattr,
  155. .listxattr = ocfs2_listxattr,
  156. .removexattr = generic_removexattr,
  157. };