在虚拟文件系统中实现符号链接
我正在开发一个不基于磁盘的虚拟文件系统,有点像/proc。现在我想在其中创建一个指向 ext3 文件系统上的目标的符号链接。我还没有找到任何关于实现此目标的方法的标准文档。到目前为止我的猜测是我必须编写一个函数来放入struct inode_operations
中的symlink
。但坦率地说,即使函数参数我也不知所措。
如果重要的话,我从 LWN 上的本教程开始: http://lwn.net/Articles/13325/编辑
:我目前正在使用 libfs,而不是 FUSE
I'm working on a virtual file system which isn't disk based, kind of like /proc. Now I want to create a symlink within it to a target on a ext3 file system. I haven't found any standard documentation on ways to achieve this. What I've guessed so far is that I have to write a function to put in for symlink
in struct inode_operations
. But frankly I'm at a loss even with the function parameters.
If it matters, I started off with this tutorial on LWN: http://lwn.net/Articles/13325/
EDIT: I'm working with libfs, not FUSE at the moment
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大概您正在使用 fuse,如果您没有,请执行:)
您所要做的就是实施getattr函数告诉内核该对象是一个符号链接,然后实现readlink函数并返回该链接应该链接到的路径;内核将完成剩下的工作。
Presumably you're using fuse, if you're not, do :)
All you have to do is implement the getattr function to tell the kernel that the object is a symlink, then implement the readlink function and return the path that the link should link to; the kernel will do the rest.
我终于能够完成它了。这是我所做的(一些细节可能会有所不同,具体取决于文件系统想要实现的目标):
使用 S_IFLNK 模式创建符号链接的 inode 并将目标添加到 i_private 字段。
实现 follow_link 因为 generic_readlink 要求它存在
I was able to accomplish it finally. Here is what I did (some details may differ depending on what the filesystem wants to achieve):
Create inode of the symlink with the S_IFLNK mode and add the target to the i_private field.
Implement follow_link because generic_readlink requires it to be present
我建议看一下 linux/fs/ext2/ 源代码。文件 symlink.c、inode.c、namei.c 以及其他一些文件。您将会了解需要做什么。与预期相反,各个文件系统的文件系统代码实际上非常短且易于阅读。
但也许您不会创建新的虚拟文件系统,而是会问自己另一个问题,在我的情况下,融合用户级文件系统还不够吗?他们有稍微更好的创建虚拟文件系统的文档和更多示例。
I would suggest to take a look at linux/fs/ext2/ source code. Files symlink.c, inode.c, namei.c and probably few others. You will get some idea as of what needs to be done. Contrary to expectation, filesystem code of the individual filesystems is actually very short and easy to read.
But maybe instead of creating new virtual filesystem, you might ask yourself another question, wouldn't fuse user level filesystem be enough in my case? They have slightly better documentation to creating virtual filesystems and a few more examples.