From: abhi.c.pawar@gmail.com (Abhijit Chandrakant Pawar)
To: kernelnewbies@lists.kernelnewbies.org
Subject: [Help] How to Replace File Operations in File System?
Date: Thu, 13 Feb 2014 12:14:23 +0530 [thread overview]
Message-ID: <52FC69C7.7010705@gmail.com> (raw)
In-Reply-To: <52FC29B3.10201@gmail.com>
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
>
next prev parent reply other threads:[~2014-02-13 6:44 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-13 2:10 [Help] How to Replace File Operations in File System? freeman
2014-02-13 6:44 ` Abhijit Chandrakant Pawar [this message]
2014-02-13 6:59 ` Saket Sinha
2014-02-13 11:47 ` Rishi Agrawal
2014-02-13 13:28 ` freeman
2014-02-17 8:06 ` Rishi Agrawal
2014-02-18 4:34 ` freeman
[not found] ` <CADDndfPhe=iHKtB0_eTYpoAAUJDTkOchUakbOyKveVdkAOLrMQ@mail.gmail.com>
2014-02-20 1:32 ` freeman
2014-02-20 7:31 ` Rishi Agrawal
2014-02-20 8:57 ` freeman
2014-02-20 9:10 ` SandeepKsinha
2014-02-20 9:48 ` freeman
2014-02-20 9:51 ` SandeepKsinha
2014-02-20 15:32 ` Valdis.Kletnieks at vt.edu
2014-02-24 1:52 ` Freeman Zhang
2014-02-13 13:26 ` freeman
2014-02-14 22:49 ` Valdis.Kletnieks at vt.edu
2014-02-17 0:59 ` freeman
2014-02-17 2:50 ` Saket Sinha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52FC69C7.7010705@gmail.com \
--to=abhi.c.pawar@gmail.com \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).