[英]lookup a directory in kernel module
我正在編寫一個可堆疊的文件系統,默認情況下會將未鏈接的文件重命名為一個特定的文件夾,例如abc。 因此,當任何文件/ xyz取消鏈接時,其重命名為/ abc / xyz。 我想通過重寫可堆疊文件系統的取消鏈接功能來做到這一點。 我正在使用wrapfs,所以我為此修改了wrapfs_unlink。 我有未鏈接文件的dentry,也有父目錄的inode,現在我需要/ abc的inode和/ abc / xyz的dentry來調用vfs_rename而不是vfs_unlink。 我可以找到/的dentry和vfsmount,所以我有一個for / dentry,但我不知道如何獲取/ abc的dentry / inode,我知道我可以從dentry獲取inode,但我也無法獲得dentry。 我嘗試使用lookup_one_len / abc創建,但仍返回負的inode,我也嘗試使用vfs_path_lookup查找目錄/ abc,它也返回錯誤。 我使用了錯誤的功能嗎? 還是這些方法只看到緩存而不看到實際的目錄結構? 請幫忙。
您可以使用以下代碼在取消鏈接時將對象移至垃圾箱。
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.