Get Filesystem Mount Point in Kernel Module

Get all mount points in kernel module

There are flags for it in the dentry struct. d_flags. and there is a flag DCACHED_MOUNTED. Get the current pointer. The fs_struct in there. then the root. this gives you the root of the current filesystem. from there loop though all the subdirs and if d_flags & DCACHE_MOUNTED passes then it is a mount point.

ssize_t read_proc(struct file *filp, char *buf, size_t len, loff_t *offp )
{
struct dentry *curdentry;

list_for_each_entry(curdentry, ¤t->fs->root.mnt->mnt_root->d_subdirs, d_child)
{
if ( curdentry->d_flags & DCACHE_MOUNTED)
printk("%s is mounted", curdentry->d_name.name);
}
return 0;
}

get filesystem mount point in kernel module

You can get the list of file systems from current->namespace. By iterating current->namespace->list (items being struct vfsmount) you can get all mounted file systems. vfsmount->mnt_mountpoint is the directory entry you want.

You can follow the code that prints /proc/mounts (e.g. base.c/mountstats_open, namespace.c/m_start) to get more details (e.g. some locking is needed).

I don't know if you can do it in a kernel module, however.



Related Topics



Leave a reply



Submit