[英]Creating a Virtual FS from a Shared Memory in Heterogeneous Linux System
I'm developing a measurement device, with 2 CPUs and a shared memory:我正在开发一个测量设备,有 2 个 CPU 和一个共享的 memory:
=>[ CPU:0 RTOS/Measurements ] [ CPU: 1 Linux/User]
\ / |
\[ Shared Memory ]/ |
struct HotData /measure
{ int x; -> /x
char[20] y; -> /y
long z; }; -> /z
Currently, I have a shared memory, where CPU-0 measures some data and cyclically updates the structure "HotData".目前,我有一个共享的 memory,其中 CPU-0 测量一些数据并循环更新结构“HotData”。 I do not want to touch the code on CPU-0 for real-time limitations.
我不想因为实时限制而触及 CPU-0 上的代码。 On the other hand, the Linux kernel can access this shared space and read the latest data.
另一方面,Linux kernel 可以访问此共享空间并读取最新数据。
Next, I want to create a "super lightweight" virtual filesystem on Linux to map those data fields, each to a file.接下来,我想在 Linux 到 map 这些数据字段上创建一个“超轻量级”虚拟文件系统,每个字段到一个文件。 So any user app/script can easily access "/measure/x" for example and get the latest measurement.
因此,任何用户应用程序/脚本都可以轻松访问“/measure/x”并获得最新的测量结果。
You may wish to look at FUSE (Filesystem in User Space).您可能希望查看FUSE (用户空间中的文件系统)。 It's a filesystem driver (shipped by default with many Linux distributions) that allows you to
mount
a virtual filesystem provided by normal unprivileged application/process.它是一个文件系统驱动程序(默认情况下与许多 Linux 发行版一起提供),允许您
mount
由普通非特权应用程序/进程提供的虚拟文件系统。
(Think NFS, but local - and it's not restricted to the NFS protocol. There are existing FUSE solutions for mounting an remote SFTP servers, and even one presenting Wikipedia as a file/directory structure, if I recall...) (想想 NFS,但它是本地的——而且它不限于 NFS 协议。现有的 FUSE 解决方案用于安装远程 SFTP 服务器,如果我记得的话,甚至还有一个将 Wikipedia 呈现为文件/目录结构的解决方案......)
There's bindings and libraries for loads of languages - there's an example in Python which shows just how easy it is to implement a virtual filesystem with it.有用于加载多种语言的绑定和库 - Python 中有一个示例,它显示了使用它实现虚拟文件系统是多么容易。
Sounds like you might be working in C/C++, in which case you probably want libfuse
(official example code linked).听起来您可能正在使用 C/C++ 工作,在这种情况下,您可能需要
libfuse
(链接的官方示例代码)。 There's what appears to be a straightforward C tutorial over on Medium . 在 Medium 上似乎有一个简单的 C 教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.