symlink.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * linux/fs/nfs/symlink.c
  3. *
  4. * Copyright (C) 1992 Rick Sladkey
  5. *
  6. * Optimization changes Copyright (C) 1994 Florian La Roche
  7. *
  8. * Jun 7 1999, cache symlink lookups in the page cache. -DaveM
  9. *
  10. * nfs symlink handling code
  11. */
  12. #include <linux/time.h>
  13. #include <linux/errno.h>
  14. #include <linux/sunrpc/clnt.h>
  15. #include <linux/nfs.h>
  16. #include <linux/nfs2.h>
  17. #include <linux/nfs_fs.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/stat.h>
  20. #include <linux/mm.h>
  21. #include <linux/slab.h>
  22. #include <linux/string.h>
  23. #include <linux/namei.h>
  24. /* Symlink caching in the page cache is even more simplistic
  25. * and straight-forward than readdir caching.
  26. */
  27. static int nfs_symlink_filler(struct inode *inode, struct page *page)
  28. {
  29. int error;
  30. error = NFS_PROTO(inode)->readlink(inode, page, 0, PAGE_SIZE);
  31. if (error < 0)
  32. goto error;
  33. SetPageUptodate(page);
  34. unlock_page(page);
  35. return 0;
  36. error:
  37. SetPageError(page);
  38. unlock_page(page);
  39. return -EIO;
  40. }
  41. static void *nfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  42. {
  43. struct inode *inode = dentry->d_inode;
  44. struct page *page;
  45. void *err;
  46. err = ERR_PTR(nfs_revalidate_mapping_nolock(inode, inode->i_mapping));
  47. if (err)
  48. goto read_failed;
  49. page = read_cache_page(&inode->i_data, 0,
  50. (filler_t *)nfs_symlink_filler, inode);
  51. if (IS_ERR(page)) {
  52. err = page;
  53. goto read_failed;
  54. }
  55. nd_set_link(nd, kmap(page));
  56. return page;
  57. read_failed:
  58. nd_set_link(nd, err);
  59. return NULL;
  60. }
  61. /*
  62. * symlinks can't do much...
  63. */
  64. const struct inode_operations nfs_symlink_inode_operations = {
  65. .readlink = generic_readlink,
  66. .follow_link = nfs_follow_link,
  67. .put_link = page_put_link,
  68. .getattr = nfs_getattr,
  69. .setattr = nfs_setattr,
  70. };