在内核模块中获取文件系统挂载点 [英] get filesystem mount point in kernel module

查看:200
本文介绍了在内核模块中获取文件系统挂载点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的内核模块中获得文件系统的文件系统挂载点,这是一个可堆叠的文件系统。
例如。如果/ home / ab / abc是一个文件,/ home被安装在不同的文件系统上,我想要一个dentry或路径结构到/ home。
我想在模块中做这个,而不用修改内核代码。
例如/ home / user /中有一个文件,现在我想知道这个文件在哪个分区中。例如,该文件可能位于与/相同的分区中,或者该文件可能位于/ home或/ home / user上的另一个分区中。你可以从 current->命名空间获得文件系统列表 C>。通过迭代 current->命名空间 - >列表(项目是 struct vfsmount ),您可以获得所有挂载的文件系统。 vfsmount-> mnt_mountpoint 是您想要的目录条目。 您可以按照打印/ proc / mounts (例如 base.c / mountstats_open namespace.c / m_start

我不知道你是否可以在内核模块中执行它。

p>

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.

解决方案

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.

这篇关于在内核模块中获取文件系统挂载点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆