在虚拟文件系统中实现符号链接

发布于 2024-08-15 21:52:35 字数 360 浏览 2 评论 0原文

我正在开发一个不基于磁盘的虚拟文件系统,有点像/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

睡美人的小仙女 2024-08-22 21:52:35

大概您正在使用 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.

つ可否回来 2024-08-22 21:52:35

我终于能够完成它了。这是我所做的(一些细节可能会有所不同,具体取决于文件系统想要实现的目标):

  1. 使用 S_IFLNK 模式创建符号链接的 inode 并将目标添加到 i_private 字段。

  2. 实现 follow_link 因为 generic_readlink 要求它存在

static void *sample_follow_link (struct dentry *dentry, struct nameidata *nd)
{
    nd->depth = 0;
    nd_set_link(nd, (char *)dentry->d_inode->i_private);
    return NULL;
}

static struct inode_operations sample_inode_ops = {
    .readlink = generic_readlink,
    .follow_link = sample_follow_link,
};

.....
//in the function for the dentry and inode creation 
inode->i_op = sample_inode_ops

I was able to accomplish it finally. Here is what I did (some details may differ depending on what the filesystem wants to achieve):

  1. Create inode of the symlink with the S_IFLNK mode and add the target to the i_private field.

  2. Implement follow_link because generic_readlink requires it to be present

static void *sample_follow_link (struct dentry *dentry, struct nameidata *nd)
{
    nd->depth = 0;
    nd_set_link(nd, (char *)dentry->d_inode->i_private);
    return NULL;
}

static struct inode_operations sample_inode_ops = {
    .readlink = generic_readlink,
    .follow_link = sample_follow_link,
};

.....
//in the function for the dentry and inode creation 
inode->i_op = sample_inode_ops

只是在用心讲痛 2024-08-22 21:52:35

我建议看一下 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文