[Help] How to Replace File Operations in File System?
freeman
freeman.zhang1992 at gmail.com
Wed Feb 12 21:10:59 EST 2014
Hi list,
I am a newbie in linux kernel programming. Recently I got stuck in a
problem when doing
practice in file system programming. I hope this list is the right place
I can turn to.
I want to replace some file operations of files in a certain
directory,so that data can be
decrypted/encrypted through read/write system call. So I:
#1: Find the directory inode, save its original inode operation
table,then replace
the table:
kern_path(pathname, LOOKUP_FOLLOW, &target_dir_path);
lower_iops = target_dir_path.dentry->d_inode->i_op;
target_dir_path.dentry->d_inode->i_op = &my_iops;
#2: In my_iops, I mainly changed ".lookup" function like this to achive
my goal --
replace the file operation table of all files in the directory.
static struct dentry *my_inode_lookup(struct inode *dir, struct dentry
*dentry,
struct nameidata *nd)
{
struct dentry *ret_dentry;
ret_dentry = lower_iops->lookup(dir,dentry,nd);
if (!ret_dentry)
goto out;
ret_dentry->d_inode->i_fop = &my_fops;
out:
return ret_dentry;
}
Things turns out that replacement of inode operation table of directory
is successful
but the changes in file operations are not functional: system works as
it used to,
totally ignore my_fops!
I have no idea how to fix it. Can anybody help?
Thanks for your attention!
Regards
Freeman Zhang
More information about the Kernelnewbies
mailing list