symlink.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * JFFS2 -- Journalling Flash File System, Version 2.
  3. *
  4. * Copyright (C) 2001, 2002 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. * $Id: symlink.c,v 1.19 2005/11/07 11:14:42 gleixner Exp $
  11. *
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/slab.h>
  15. #include <linux/fs.h>
  16. #include <linux/namei.h>
  17. #include "nodelist.h"
  18. static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd);
  19. struct inode_operations jffs2_symlink_inode_operations =
  20. {
  21. .readlink = generic_readlink,
  22. .follow_link = jffs2_follow_link,
  23. .setattr = jffs2_setattr
  24. };
  25. static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
  26. {
  27. struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
  28. char *p = (char *)f->target;
  29. /*
  30. * We don't acquire the f->sem mutex here since the only data we
  31. * use is f->target.
  32. *
  33. * 1. If we are here the inode has already built and f->target has
  34. * to point to the target path.
  35. * 2. Nobody uses f->target (if the inode is symlink's inode). The
  36. * exception is inode freeing function which frees f->target. But
  37. * it can't be called while we are here and before VFS has
  38. * stopped using our f->target string which we provide by means of
  39. * nd_set_link() call.
  40. */
  41. if (!p) {
  42. printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n");
  43. p = ERR_PTR(-EIO);
  44. }
  45. D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->target));
  46. nd_set_link(nd, p);
  47. /*
  48. * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe
  49. * since the only way that may cause f->target to be changed is iput() operation.
  50. * But VFS will not use f->target after iput() has been called.
  51. */
  52. return NULL;
  53. }