/**1* eCryptfs: Linux filesystem encryption layer2*3* Copyright (C) 1997-2003 Erez Zadok4* Copyright (C) 2001-2003 Stony Brook University5* Copyright (C) 2004-2006 International Business Machines Corp.6* Author(s): Michael A. Halcrow <[email protected]>7*8* This program is free software; you can redistribute it and/or9* modify it under the terms of the GNU General Public License as10* published by the Free Software Foundation; either version 2 of the11* License, or (at your option) any later version.12*13* This program is distributed in the hope that it will be useful, but14* WITHOUT ANY WARRANTY; without even the implied warranty of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU16* General Public License for more details.17*18* You should have received a copy of the GNU General Public License19* along with this program; if not, write to the Free Software20* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA21* 02111-1307, USA.22*/2324#include <linux/dcache.h>25#include <linux/namei.h>26#include <linux/mount.h>27#include <linux/fs_stack.h>28#include <linux/slab.h>29#include "ecryptfs_kernel.h"3031/**32* ecryptfs_d_revalidate - revalidate an ecryptfs dentry33* @dentry: The ecryptfs dentry34* @nd: The associated nameidata35*36* Called when the VFS needs to revalidate a dentry. This37* is called whenever a name lookup finds a dentry in the38* dcache. Most filesystems leave this as NULL, because all their39* dentries in the dcache are valid.40*41* Returns 1 if valid, 0 otherwise.42*43*/44static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd)45{46struct dentry *lower_dentry;47struct vfsmount *lower_mnt;48struct dentry *dentry_save = NULL;49struct vfsmount *vfsmount_save = NULL;50int rc = 1;5152if (nd && nd->flags & LOOKUP_RCU)53return -ECHILD;5455lower_dentry = ecryptfs_dentry_to_lower(dentry);56lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);57if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate)58goto out;59if (nd) {60dentry_save = nd->path.dentry;61vfsmount_save = nd->path.mnt;62nd->path.dentry = lower_dentry;63nd->path.mnt = lower_mnt;64}65rc = lower_dentry->d_op->d_revalidate(lower_dentry, nd);66if (nd) {67nd->path.dentry = dentry_save;68nd->path.mnt = vfsmount_save;69}70if (dentry->d_inode) {71struct inode *lower_inode =72ecryptfs_inode_to_lower(dentry->d_inode);7374fsstack_copy_attr_all(dentry->d_inode, lower_inode);75}76out:77return rc;78}7980struct kmem_cache *ecryptfs_dentry_info_cache;8182/**83* ecryptfs_d_release84* @dentry: The ecryptfs dentry85*86* Called when a dentry is really deallocated.87*/88static void ecryptfs_d_release(struct dentry *dentry)89{90if (ecryptfs_dentry_to_private(dentry)) {91if (ecryptfs_dentry_to_lower(dentry)) {92dput(ecryptfs_dentry_to_lower(dentry));93mntput(ecryptfs_dentry_to_lower_mnt(dentry));94}95kmem_cache_free(ecryptfs_dentry_info_cache,96ecryptfs_dentry_to_private(dentry));97}98return;99}100101const struct dentry_operations ecryptfs_dops = {102.d_revalidate = ecryptfs_d_revalidate,103.d_release = ecryptfs_d_release,104};105106107