1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * eCryptfs: Linux filesystem encryption layer
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>
11 #include <linux/dcache.h>
12 #include <linux/namei.h>
13 #include <linux/mount.h>
14 #include <linux/fs_stack.h>
15 #include <linux/slab.h>
16 #include "ecryptfs_kernel.h"
19 * ecryptfs_d_revalidate - revalidate an ecryptfs dentry
20 * @dentry: The ecryptfs dentry
21 * @flags: lookup flags
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.
28 * Returns 1 if valid, 0 otherwise.
31 static int ecryptfs_d_revalidate(struct dentry *dentry, unsigned int flags)
33 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
36 if (flags & LOOKUP_RCU)
39 if (lower_dentry->d_flags & DCACHE_OP_REVALIDATE)
40 rc = lower_dentry->d_op->d_revalidate(lower_dentry, flags);
42 if (d_really_is_positive(dentry)) {
43 struct inode *inode = d_inode(dentry);
45 fsstack_copy_attr_all(inode, ecryptfs_inode_to_lower(inode));
52 struct kmem_cache *ecryptfs_dentry_info_cache;
54 static void ecryptfs_dentry_free_rcu(struct rcu_head *head)
56 kmem_cache_free(ecryptfs_dentry_info_cache,
57 container_of(head, struct ecryptfs_dentry_info, rcu));
62 * @dentry: The ecryptfs dentry
64 * Called when a dentry is really deallocated.
66 static void ecryptfs_d_release(struct dentry *dentry)
68 struct ecryptfs_dentry_info *p = dentry->d_fsdata;
70 path_put(&p->lower_path);
71 call_rcu(&p->rcu, ecryptfs_dentry_free_rcu);
75 const struct dentry_operations ecryptfs_dops = {
76 .d_revalidate = ecryptfs_d_revalidate,
77 .d_release = ecryptfs_d_release,