dentry.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * eCryptfs: Linux filesystem encryption layer
  4. *
  5. * Copyright (C) 1997-2003 Erez Zadok
  6. * Copyright (C) 2001-2003 Stony Brook University
  7. * Copyright (C) 2004-2006 International Business Machines Corp.
  8. * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
  9. */
  10. #include <linux/dcache.h>
  11. #include <linux/namei.h>
  12. #include <linux/mount.h>
  13. #include <linux/fs_stack.h>
  14. #include <linux/slab.h>
  15. #include "ecryptfs_kernel.h"
  16. /**
  17. * ecryptfs_d_revalidate - revalidate an ecryptfs dentry
  18. * @dir: inode of expected parent
  19. * @name: expected name
  20. * @dentry: dentry to revalidate
  21. * @flags: lookup flags
  22. *
  23. * Called when the VFS needs to revalidate a dentry. This
  24. * is called whenever a name lookup finds a dentry in the
  25. * dcache. Most filesystems leave this as NULL, because all their
  26. * dentries in the dcache are valid.
  27. *
  28. * Returns 1 if valid, 0 otherwise.
  29. *
  30. */
  31. static int ecryptfs_d_revalidate(struct inode *dir, const struct qstr *name,
  32. struct dentry *dentry, unsigned int flags)
  33. {
  34. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  35. int rc = 1;
  36. if (flags & LOOKUP_RCU)
  37. return -ECHILD;
  38. if (lower_dentry->d_flags & DCACHE_OP_REVALIDATE) {
  39. struct inode *lower_dir = ecryptfs_inode_to_lower(dir);
  40. struct name_snapshot n;
  41. take_dentry_name_snapshot(&n, lower_dentry);
  42. rc = lower_dentry->d_op->d_revalidate(lower_dir, &n.name,
  43. lower_dentry, flags);
  44. release_dentry_name_snapshot(&n);
  45. }
  46. if (d_really_is_positive(dentry)) {
  47. struct inode *inode = d_inode(dentry);
  48. fsstack_copy_attr_all(inode, ecryptfs_inode_to_lower(inode));
  49. if (!inode->i_nlink)
  50. return 0;
  51. }
  52. return rc;
  53. }
  54. /**
  55. * ecryptfs_d_release
  56. * @dentry: The ecryptfs dentry
  57. *
  58. * Called when a dentry is really deallocated.
  59. */
  60. static void ecryptfs_d_release(struct dentry *dentry)
  61. {
  62. dput(dentry->d_fsdata);
  63. }
  64. const struct dentry_operations ecryptfs_dops = {
  65. .d_revalidate = ecryptfs_d_revalidate,
  66. .d_release = ecryptfs_d_release,
  67. };