symlink.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright © 2001-2007 Red Hat, Inc.
  5. *
  6. * Created by David Woodhouse <dwmw2@infradead.org>
  7. *
  8. * For licensing information, see the file 'LICENCE' in this directory.
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/fs.h>
  13. #include <linux/namei.h>
  14. #include "nodelist.h"
  15. static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd);
  16. const struct inode_operations jffs2_symlink_inode_operations =
  17. {
  18. .readlink = generic_readlink,
  19. .follow_link = jffs2_follow_link,
  20. .get_acl = jffs2_get_acl,
  21. .setattr = jffs2_setattr,
  22. .setxattr = jffs2_setxattr,
  23. .getxattr = jffs2_getxattr,
  24. .listxattr = jffs2_listxattr,
  25. .removexattr = jffs2_removexattr
  26. };
  27. static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
  28. {
  29. struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
  30. char *p = (char *)f->target;
  31. /*
  32. * We don't acquire the f->sem mutex here since the only data we
  33. * use is f->target.
  34. *
  35. * 1. If we are here the inode has already built and f->target has
  36. * to point to the target path.
  37. * 2. Nobody uses f->target (if the inode is symlink's inode). The
  38. * exception is inode freeing function which frees f->target. But
  39. * it can't be called while we are here and before VFS has
  40. * stopped using our f->target string which we provide by means of
  41. * nd_set_link() call.
  42. */
  43. if (!p) {
  44. printk(KERN_ERR "jffs2_follow_link(): can't find symlink target\n");
  45. p = ERR_PTR(-EIO);
  46. }
  47. D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->target));
  48. nd_set_link(nd, p);
  49. /*
  50. * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe
  51. * since the only way that may cause f->target to be changed is iput() operation.
  52. * But VFS will not use f->target after iput() has been called.
  53. */
  54. return NULL;
  55. }