Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * eCryptfs: Linux filesystem encryption layer
0004  *
0005  * Copyright (C) 1997-2003 Erez Zadok
0006  * Copyright (C) 2001-2003 Stony Brook University
0007  * Copyright (C) 2004-2006 International Business Machines Corp.
0008  *   Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
0009  */
0010 
0011 #include <linux/dcache.h>
0012 #include <linux/namei.h>
0013 #include <linux/mount.h>
0014 #include <linux/fs_stack.h>
0015 #include <linux/slab.h>
0016 #include "ecryptfs_kernel.h"
0017 
0018 /**
0019  * ecryptfs_d_revalidate - revalidate an ecryptfs dentry
0020  * @dentry: The ecryptfs dentry
0021  * @flags: lookup flags
0022  *
0023  * Called when the VFS needs to revalidate a dentry. This
0024  * is called whenever a name lookup finds a dentry in the
0025  * dcache. Most filesystems leave this as NULL, because all their
0026  * dentries in the dcache are valid.
0027  *
0028  * Returns 1 if valid, 0 otherwise.
0029  *
0030  */
0031 static int ecryptfs_d_revalidate(struct dentry *dentry, unsigned int flags)
0032 {
0033     struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
0034     int rc = 1;
0035 
0036     if (flags & LOOKUP_RCU)
0037         return -ECHILD;
0038 
0039     if (lower_dentry->d_flags & DCACHE_OP_REVALIDATE)
0040         rc = lower_dentry->d_op->d_revalidate(lower_dentry, flags);
0041 
0042     if (d_really_is_positive(dentry)) {
0043         struct inode *inode = d_inode(dentry);
0044 
0045         fsstack_copy_attr_all(inode, ecryptfs_inode_to_lower(inode));
0046         if (!inode->i_nlink)
0047             return 0;
0048     }
0049     return rc;
0050 }
0051 
0052 struct kmem_cache *ecryptfs_dentry_info_cache;
0053 
0054 static void ecryptfs_dentry_free_rcu(struct rcu_head *head)
0055 {
0056     kmem_cache_free(ecryptfs_dentry_info_cache,
0057         container_of(head, struct ecryptfs_dentry_info, rcu));
0058 }
0059 
0060 /**
0061  * ecryptfs_d_release
0062  * @dentry: The ecryptfs dentry
0063  *
0064  * Called when a dentry is really deallocated.
0065  */
0066 static void ecryptfs_d_release(struct dentry *dentry)
0067 {
0068     struct ecryptfs_dentry_info *p = dentry->d_fsdata;
0069     if (p) {
0070         path_put(&p->lower_path);
0071         call_rcu(&p->rcu, ecryptfs_dentry_free_rcu);
0072     }
0073 }
0074 
0075 const struct dentry_operations ecryptfs_dops = {
0076     .d_revalidate = ecryptfs_d_revalidate,
0077     .d_release = ecryptfs_d_release,
0078 };