symlink.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.16 2005/03/01 10:50:48 dedekind 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->dents;
  29. /*
  30. * We don't acquire the f->sem mutex here since the only data we
  31. * use is f->dents which in case of the symlink inode points to the
  32. * symlink's target path.
  33. *
  34. * 1. If we are here the inode has already built and f->dents has
  35. * to point to the target path.
  36. * 2. Nobody uses f->dents (if the inode is symlink's inode). The
  37. * exception is inode freeing function which frees f->dents. But
  38. * it can't be called while we are here and before VFS has
  39. * stopped using our f->dents string which we provide by means of
  40. * nd_set_link() call.
  41. */
  42. if (!p) {
  43. printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n");
  44. p = ERR_PTR(-EIO);
  45. } else {
  46. D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->dents));
  47. }
  48. nd_set_link(nd, p);
  49. /*
  50. * We unlock the f->sem mutex but VFS will use the f->dents string. This is safe
  51. * since the only way that may cause f->dents to be changed is iput() operation.
  52. * But VFS will not use f->dents after iput() has been called.
  53. */
  54. return NULL;
  55. }