symlink.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. pr_err("%s(): can't find symlink target\n", __func__);
  45. p = ERR_PTR(-EIO);
  46. }
  47. jffs2_dbg(1, "%s(): target path is '%s'\n",
  48. __func__, (char *)f->target);
  49. nd_set_link(nd, p);
  50. /*
  51. * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe
  52. * since the only way that may cause f->target to be changed is iput() operation.
  53. * But VFS will not use f->target after iput() has been called.
  54. */
  55. return NULL;
  56. }