home | list info | list archive | date index | thread index

[OCLUG-Tech] LKM: redirect file operations

Dear,

I would like to create a Loadable Kernel Module that redirects the file
operations of a given filename
to the functions defined in the module such that whenever any process calls
a redirected file
operation the module's function is called instead of the one defined by the
fs.

Is this possible? any drawbacks or better ways?

I am currently reading about linux filesystems and trying to understand how
an inode is
populated with the file operations (i_fop pointer to file_operations
struct).

My understanding is that when the filesystem is mounted, somehow,
the file_operations structure
i_fop of the inodes created in memory are set, and whenever a process calls
a file operation the
filesystem will use the function defined in i_fop.

The idea is to create a loadable module that modifies the file operations of
a given file to point
to the functions defined in the module.

One of my concerns (and there are many for now) is to know when the i_fop of
an in-memory
inode is set and if it is refreshed while it is in-memory, or is it
guaranteed that the f_iop is
set only once at inode create time.

If the given file is not used by any process I think there will be no inode
for that file in the cache,
but if there is at least one process that opened the file then is it
guaranteed that the i_fop will be
set only once at the time of the inode cache creation, as long as there is
at least one process that
has the file open?

A sample program showing how to find the inode of a given filename and how
to modify the i_fop
structure is welcome.

Kind regards
Taoufik