symlink.c 1.9 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/slab.h>
  13. #include <linux/fs.h>
  14. #include <linux/namei.h>
  15. #include "nodelist.h"
  16. static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd);
  17. const struct inode_operations jffs2_symlink_inode_operations =
  18. {
  19. .readlink = generic_readlink,
  20. .follow_link = jffs2_follow_link,
  21. .permission = jffs2_permission,
  22. .setattr = jffs2_setattr,
  23. .setxattr = jffs2_setxattr,
  24. .getxattr = jffs2_getxattr,
  25. .listxattr = jffs2_listxattr,
  26. .removexattr = jffs2_removexattr
  27. };
  28. static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
  29. {
  30. struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
  31. char *p = (char *)f->target;
  32. /*
  33. * We don't acquire the f->sem mutex here since the only data we
  34. * use is f->target.
  35. *
  36. * 1. If we are here the inode has already built and f->target has
  37. * to point to the target path.
  38. * 2. Nobody uses f->target (if the inode is symlink's inode). The
  39. * exception is inode freeing function which frees f->target. But
  40. * it can't be called while we are here and before VFS has
  41. * stopped using our f->target string which we provide by means of
  42. * nd_set_link() call.
  43. */
  44. if (!p) {
  45. printk(KERN_ERR "jffs2_follow_link(): can't find symlink target\n");
  46. p = ERR_PTR(-EIO);
  47. }
  48. D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (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. }