Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
237fead6 MH |
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> | |
237fead6 MH |
9 | */ |
10 | ||
11 | #include <linux/dcache.h> | |
12 | #include <linux/namei.h> | |
45ec4aba | 13 | #include <linux/mount.h> |
0cc72dc7 | 14 | #include <linux/fs_stack.h> |
5a0e3ad6 | 15 | #include <linux/slab.h> |
237fead6 MH |
16 | #include "ecryptfs_kernel.h" |
17 | ||
18 | /** | |
19 | * ecryptfs_d_revalidate - revalidate an ecryptfs dentry | |
20 | * @dentry: The ecryptfs dentry | |
0b728e19 | 21 | * @flags: lookup flags |
237fead6 MH |
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 | */ | |
0b728e19 | 31 | static int ecryptfs_d_revalidate(struct dentry *dentry, unsigned int flags) |
237fead6 | 32 | { |
2edbfbf1 | 33 | struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); |
5556e7e6 | 34 | int rc = 1; |
237fead6 | 35 | |
0b728e19 | 36 | if (flags & LOOKUP_RCU) |
34286d66 NP |
37 | return -ECHILD; |
38 | ||
5556e7e6 TH |
39 | if (lower_dentry->d_flags & DCACHE_OP_REVALIDATE) |
40 | rc = lower_dentry->d_op->d_revalidate(lower_dentry, flags); | |
41 | ||
2b0143b5 | 42 | if (d_really_is_positive(dentry)) { |
5556e7e6 | 43 | struct inode *inode = d_inode(dentry); |
ae56fb16 | 44 | |
5556e7e6 TH |
45 | fsstack_copy_attr_all(inode, ecryptfs_inode_to_lower(inode)); |
46 | if (!inode->i_nlink) | |
47 | return 0; | |
ae56fb16 | 48 | } |
237fead6 MH |
49 | return rc; |
50 | } | |
51 | ||
52 | struct kmem_cache *ecryptfs_dentry_info_cache; | |
53 | ||
2edbfbf1 AV |
54 | static void ecryptfs_dentry_free_rcu(struct rcu_head *head) |
55 | { | |
56 | kmem_cache_free(ecryptfs_dentry_info_cache, | |
57 | container_of(head, struct ecryptfs_dentry_info, rcu)); | |
58 | } | |
59 | ||
237fead6 MH |
60 | /** |
61 | * ecryptfs_d_release | |
62 | * @dentry: The ecryptfs dentry | |
63 | * | |
64 | * Called when a dentry is really deallocated. | |
65 | */ | |
66 | static void ecryptfs_d_release(struct dentry *dentry) | |
67 | { | |
2edbfbf1 AV |
68 | struct ecryptfs_dentry_info *p = dentry->d_fsdata; |
69 | if (p) { | |
cbe9c085 | 70 | path_put(&p->lower_path); |
2edbfbf1 | 71 | call_rcu(&p->rcu, ecryptfs_dentry_free_rcu); |
45ec4aba | 72 | } |
237fead6 MH |
73 | } |
74 | ||
5a3fd05a | 75 | const struct dentry_operations ecryptfs_dops = { |
237fead6 MH |
76 | .d_revalidate = ecryptfs_d_revalidate, |
77 | .d_release = ecryptfs_d_release, | |
78 | }; |