get filesystem mount point in kernel module

2019-02-24 09:02发布

I want to get the filesystem mount point for a file system in my kernel module, which is a stackable filesystem. Eg. if /home/ab/abc is a file and /home is mounted on a different filesystem I want to have a dentry or path struct to /home. I want to do this in a module without modifying kernel code. e.g. there is a file in /home/user/ and now I want to know in which partition this file is. For example this file might be in the partition same as "/" or this file might be in another partition mounted on /home or /home/user.

2条回答
乱世女痞
2楼-- · 2019-02-24 09:36

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.

查看更多
Evening l夕情丶
3楼-- · 2019-02-24 09:46

you can get pointer to the vfsmount structure from this code

http://copilotco.com/mail-archives/security-module.2003/msg00627.html

查看更多
登录 后发表回答