symlink.c 1.6 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/string.h>
  22. #include <linux/namei.h>
  23. /* Symlink caching in the page cache is even more simplistic
  24. * and straight-forward than readdir caching.
  25. */
  26. static int nfs_symlink_filler(struct inode *inode, struct page *page)
  27. {
  28. int error;
  29. error = NFS_PROTO(inode)->readlink(inode, page, 0, PAGE_SIZE);
  30. if (error < 0)
  31. goto error;
  32. SetPageUptodate(page);
  33. unlock_page(page);
  34. return 0;
  35. error:
  36. SetPageError(page);
  37. unlock_page(page);
  38. return -EIO;
  39. }
  40. static void *nfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  41. {
  42. struct inode *inode = dentry->d_inode;
  43. struct page *page;
  44. void *err;
  45. err = ERR_PTR(nfs_revalidate_mapping(inode, inode->i_mapping));
  46. if (err)
  47. goto read_failed;
  48. page = read_cache_page(&inode->i_data, 0,
  49. (filler_t *)nfs_symlink_filler, inode);
  50. if (IS_ERR(page)) {
  51. err = page;
  52. goto read_failed;
  53. }
  54. nd_set_link(nd, kmap(page));
  55. return page;
  56. read_failed:
  57. nd_set_link(nd, err);
  58. return NULL;
  59. }
  60. /*
  61. * symlinks can't do much...
  62. */
  63. const struct inode_operations nfs_symlink_inode_operations = {
  64. .readlink = generic_readlink,
  65. .follow_link = nfs_follow_link,
  66. .put_link = page_put_link,
  67. .getattr = nfs_getattr,
  68. .setattr = nfs_setattr,
  69. };