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.
Asked
Active
Viewed 1,035 times
2
-
2(*Yet another* union/stack filesystem? Sigh.) – jørgensen Jan 15 '12 at 09:33
-
1I'm not sure that altering that much the semantics of the `unlink` syscall makes sense in kernel space. Why don't you use `fuse` for your bizarre goals http://fuse.sourceforge.net/ – Basile Starynkevitch Jan 15 '12 at 10:48
-
@jørgensen : Could you explain me your comment a bit. – gaurav Jan 15 '12 at 11:17
-
@BasileStarynkevitch : I will have a look at fuse. – gaurav Jan 15 '12 at 11:18
1 Answers
0
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;
}

Ilya Matveychikov
- 3,936
- 2
- 27
- 42