制作新的文件系统
我正在寻找为我正在开发的项目制作一个自定义文件系统。目前我正在考虑用Python结合fusepy来编写它,但这让我想知道如何在Linux中创建编译的非用户空间文件系统。是否需要使用特定的库或需要实现的函数才能使 mount 命令正常工作。总的来说,我不确定整个过程是如何进行的。
I'm looking to make a custom filesystem for a project I'm working on. Currently I am looking at writing it in Python combined with fusepy, but it got me wondering how a compiled non-userspace filesystem is made in Linux. Are there specific libraries that you need to work with or functions you need to implement for the mount command to work properly. Overall I'm not sure how the entire process works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您需要对内核接口进行编程,特别是
VFS层
至少。 编辑 更好的链接 [ 1]“完整”文档位于内核树中:http://www.mjmwired.net/kernel/Documentation/filesystems/vfs.txt。当然,fuse 内核模块被编程为完全相同的接口
,但这不是您所说的库。它是一个内核组件,本质上就在那里,因此内核不必知道文件系统是如何实现的来与它一起工作。
[1] 谷歌错了:第一次点击并不是最好的:)
Yup you'd be programming to the kernel interfaces, specifically
the VFS layer
at a minimum. Edit Better link [1]'Full' documentation is in the kernel tree: http://www.mjmwired.net/kernel/Documentation/filesystems/vfs.txt. Of course, the fuse kernel module is programmed to exactly the same interface
This, however, is not what you'd call a library. It is a kernel component and intrinsically there, so the kernel doesn't have to know how a filesystem is implemented to work with one.
[1] google was wrong: the first hit wasn't the best :)
如果你想用 Python 编写它,fuse 是一个不错的选择。有很多关于此的教程,例如这里的教程: http:// /sourceforge.net/apps/mediawiki/fuse/index.php?title=FUSE_Python_tutorial
If you'd like to write it in Python, fuse is a good option. There are lots of tutorials for this, such as the one here: http://sourceforge.net/apps/mediawiki/fuse/index.php?title=FUSE_Python_tutorial
简而言之:Linux 是一个具有一些模块加载功能的整体内核。这意味着每个内核功能(文件系统、调度程序、驱动程序、内存管理等)都是 Linux 这个大程序的一部分。可加载模块只是一种专门的运行时链接方式,它允许用户根据需要选择这些功能,但它们仍然主要作为单个程序开发。
因此,要创建新的文件系统,只需将新的 C 源代码文件添加到内核代码中,定义文件系统必须执行的操作。然后,创建一个初始化函数,该函数分配 VFS 结构的新实例,用适当的函数指针填充它并向 VFS 注册。
请注意,FUSE 只不过是执行相同操作的用户级可访问 API,因此 FUSE 挂钩(大致)对应于 VFS 操作。
In short: Linux is a monolithic kernel with some module-loading capabilities. That means that every kernel feature (filesystems, scheduler, drivers, memory management, etc.) is part of the one big program called Linux. Loadable modules are just a specialized way of run-time linking, which allows the user to pick those features as needed, but they're all still developed mostly as a single program.
So, to create a new filesystem, you just add new C source code files to the kernel code, defining the operations your filesystem has to perform. Then, create an initialization function that allocates a new instance of the VFS structure, fills it with the appropriate function pointers and registers with the VFS.
Note that FUSE is nothing more than a userlevel accessible API to do the same, so the FUSE hooks correspond (roughly) to the VFS operations.