简体   繁体   中英

lookup a directory in kernel module

I am writing a stackable file system which would rename unlinked files to a particular folder say abc by default. So as any file /xyz is unlinked its renamed to /abc/xyz. I want to do this by overriding the unlink function of stackable file system. I am using wrapfs so I am modifying wrapfs_unlink for this. I have dentry of the unlinked file also I have inode of parent directory , now I need to have inode of /abc and dentry of /abc/xyz to call vfs_rename instead of vfs_unlink. I could find the dentry and vfsmount for the / so I have a dentry for / but I don't know how to get the dentry/inode of /abc I know I can get inode from dentry but I cannot get dentry also. I tried using lookup_one_len /abc is created but still it returns a negative inode , also I tried to use vfs_path_lookup to find the directory /abc it also returns an error. Am I using wrong functions? Or these methods see cache only not the actual directory structure ? Please help.

You can use the following code to move an object into the trash at unlink.

static int move_to_trash(struct dentry * trash, struct dentry * object)
{
    int result;
    char name[32];
    struct dentry * de;

    sprintf(name, "XX-%lu", object->d_inode->i_ino);

    de = d_alloc_name(trash, name);
    if (!de)
        return -ENOMEM;

    trash->d_inode->i_op->lookup(trash->d_inode, de, NULL);

    mutex_lock(&trash->d_inode->i_mutex);
    result = trash->d_inode->i_op->link(object, trash->d_inode, de);
    mutex_unlock(&trash->d_inode->i_mutex);

    dput(de);

    return result;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM