Linux - 将用户空间文件系统(模仿一个:-))安装为文件系统
我有一段 C 代码,它带有一块内存(静态数组)可以模拟文件操作(它具有类似于 fopen
/fclose
等的 API)。因此,使用此模仿文件系统编译的任何代码都可以使用这些 API 作为文件系统来满足其所有需求:)
但我想知道,是否可以以某种方式向 Linux 系统注册这些 API/安装此文件系统,从而启用任何客户端通过使用普通的文件系统调用来使用此 FS(无需将其与 My_FileSystem 静态链接)。
在寻找解决方案时,我遇到了将 my_FileSystem 作为驱动程序的想法! => 是否可以将我的代码编译为设备驱动程序(使用驱动程序中的内存块)并挂载此 File_system @ say "/mnt/MyFs"
,并像 USB 驱动程序那样转移 FileSystem 调用? (如果可以做到这一点,您能否解释一下它是如何完成的,或者指出我可以阅读相关内容的地方)。
我不想将这些添加为新的系统调用并重新编译内核(并使想要使用它的人的生活变得困难)。
这主要针对运行Linux的嵌入式系统...但也欢迎其他建议。 :)
谢谢你,
MicroKernel :)
I have a piece of C code which with a chunk of memory(static array) can mimic file operations (It has APIs similar to fopen
/fclose
etc). So, any code that is compiled with this mimicking FileSystem can use these APIs as a FileSystem for all their needs :)
But I was wondering, if its possible somehow to register these APIs with Linux system/mouning this File system, and hence enabling any client to use this FS by using normal FileSystem calls (without any need of statically linking it with the My_FileSystem).
While searching for a solution, I came across this idea of making my_FileSystem as a Driver!!! =>
Is it possible to compile my code as a device driver (with the memory chunk in the driver) and mount this File_system @ say "/mnt/MyFs"
, and divert FileSystem calls like USB drivers do? (If this can be done, can you please explain how its done or point me to somewhere I can read about this).
I don't want to add these as new System calls and recompile the kernel (And making life of ppl wanting to use this difficult).
This is mainly for embedded systems running Linux... But other suggestions are also welcome. :)
Thank You,
MicroKernel :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 FUSE(用户空间中的文件系统),尤其是示例。这很容易...
Look at FUSE (Filesystem in Userspace), especially on examples. Its quite easy...
查看tmpfs 和 ramfs。这些已经随 Linux 一起提供,可以完成您想要做的所有事情,甚至更多。我认为对于嵌入式系统来说它们都不会太昂贵。
Take a look at tmpfs and ramfs. These already ship with Linux and do all that you're trying to do and more. I don't think either of them would be too expensive for an embedded system.
我会考虑 PlasticFS,但只有当一切都使用系统 C 库(即没有静态链接的二进制文件)时,它才会可靠地工作)。
I would consider PlasticFS, but that will work reliably only if everything uses system C library (i.e. no statically linked binaries).