symlink.c 1.5 KB

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