[Help] How to Replace File Operations in File System?

Rishi Agrawal rishi.b.agrawal at gmail.com
Thu Feb 13 06:47:08 EST 2014


Hi,


On Thu, Feb 13, 2014 at 12:14 PM, Abhijit Chandrakant Pawar <
abhi.c.pawar at gmail.com> wrote:

> Hi,
>
> On Thursday 13 February 2014 07:40 AM, freeman wrote:
> > 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;
> >
> I assume that you are writing your own stackable filesystem.
> Take a look at WRAPFS[1] and ecryptfs[2]. As a matter of fact, ecryptfs
> does what you are expecting.
>
> To do this, you need to set your superblock operations for the lower
> directory inode so the VFS use your filesystem instead of the original
> filesystem.
> Important steps to look are:
> 1. get lower superblock from the lower directory inode
> 2. assign this superblock as an overlay for your own superblock.
> 3. Set your own superblock operations for the new superblock
> 4. get a root inode for your superblock using the lower directory inode
> 5. While you are getting the inode, you can set the file operations on
> this inode which will help you achieve your case.
>
> The point to note that you need to interpose the inodes with VFS so that
> everything would be routed to your filesystem.
>
> --
> Abhijit.
> [1]http://wrapfs.filesystems.org/
> [2]http://ecryptfs.org/
>
>
> > #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
> >
> >
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>


Freeman - What you are doing seems to be correct - you may have missed some
pointer some where.

Which file system are you using, are you writing a layer on an existing
file system or changing the code of a file system

Try adding some debug messages whenever you change the operations which
prints the dentry->name of the file, you will get an idea that the correct
file's operations are getting modified.


-- 
Regards,
Rishi Agrawal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140213/ca8b5afc/attachment.html 


More information about the Kernelnewbies mailing list