dentry.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * @dentry: The ecryptfs dentry
  19. * @flags: lookup flags
  20. *
  21. * Called when the VFS needs to revalidate a dentry. This
  22. * is called whenever a name lookup finds a dentry in the
  23. * dcache. Most filesystems leave this as NULL, because all their
  24. * dentries in the dcache are valid.
  25. *
  26. * Returns 1 if valid, 0 otherwise.
  27. *
  28. */
  29. static int ecryptfs_d_revalidate(struct dentry *dentry, unsigned int flags)
  30. {
  31. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  32. int rc = 1;
  33. if (flags & LOOKUP_RCU)
  34. return -ECHILD;
  35. if (lower_dentry->d_flags & DCACHE_OP_REVALIDATE)
  36. rc = lower_dentry->d_op->d_revalidate(lower_dentry, flags);
  37. if (d_really_is_positive(dentry)) {
  38. struct inode *inode = d_inode(dentry);
  39. fsstack_copy_attr_all(inode, ecryptfs_inode_to_lower(inode));
  40. if (!inode->i_nlink)
  41. return 0;
  42. }
  43. return rc;
  44. }
  45. struct kmem_cache *ecryptfs_dentry_info_cache;
  46. static void ecryptfs_dentry_free_rcu(struct rcu_head *head)
  47. {
  48. kmem_cache_free(ecryptfs_dentry_info_cache,
  49. container_of(head, struct ecryptfs_dentry_info, rcu));
  50. }
  51. /**
  52. * ecryptfs_d_release
  53. * @dentry: The ecryptfs dentry
  54. *
  55. * Called when a dentry is really deallocated.
  56. */
  57. static void ecryptfs_d_release(struct dentry *dentry)
  58. {
  59. struct ecryptfs_dentry_info *p = dentry->d_fsdata;
  60. if (p) {
  61. path_put(&p->lower_path);
  62. call_rcu(&p->rcu, ecryptfs_dentry_free_rcu);
  63. }
  64. }
  65. const struct dentry_operations ecryptfs_dops = {
  66. .d_revalidate = ecryptfs_d_revalidate,
  67. .d_release = ecryptfs_d_release,
  68. };