Go 使用FUSE以目录形式命名管道
我想创建一个FUSE文件系统,它接受对文件系统内任何路径的任何类型的写入操作。有点像命名管道,但以目录的形式Go 使用FUSE以目录形式命名管道,go,fuse,Go,Fuse,我想创建一个FUSE文件系统,它接受对文件系统内任何路径的任何类型的写入操作。有点像命名管道,但以目录的形式 echo test > bar # consumes "test" echo test > bar/foo # consumes "test", even though the directory "bar" hasn't been created echo test > x/y/z/test # consumes "test", even t
echo test > bar # consumes "test"
echo test > bar/foo # consumes "test", even though the directory "bar" hasn't been created
echo test > x/y/z/test # consumes "test", even though the directories "x/y/z" haven't been created
我正在使用它来实现。我面临的问题是,当应用程序要在我的文件系统中写入foo/bar
时,它会检查foo
是否为目录,然后检查bar
是否为文件。不幸的是,我无法预先知道foo
应该是文件还是目录
echo test > bar # consumes "test"
echo test > bar/foo # consumes "test", even though the directory "bar" hasn't been created
echo test > x/y/z/test # consumes "test", even though the directories "x/y/z" haven't been created
我的Attr
函数如下所示:
func (d *Dir) Attr(ctx context.Context, a *fuse.Attr) error {
a.Inode = 1
a.Mode = os.ModeDir | 0755
}
由于os.ModeDir
,此代码特定于目录节点类型。我想这是工作的目录或文件
有没有办法实现我想要的
我面临的问题是,当应用程序要在我的文件系统中写入foo/bar
时,它会检查foo
是否为目录,然后检查bar
是否为文件。不幸的是,我无法预先知道foo
应该是文件还是目录
echo test > bar # consumes "test"
echo test > bar/foo # consumes "test", even though the directory "bar" hasn't been created
echo test > x/y/z/test # consumes "test", even though the directories "x/y/z" haven't been created
考虑到这些限制,解决您的问题是不可能的
文件系统节点可以是文件或目录;有时两者都不存在,但决不能同时存在。因为FUSE驱动程序无法预先知道执行getattr
请求的应用程序是否意味着在节点内部递归,直到它实际尝试为止,所以您无法知道它应该假装是文件还是目录
echo test > bar # consumes "test"
echo test > bar/foo # consumes "test", even though the directory "bar" hasn't been created
echo test > x/y/z/test # consumes "test", even though the directories "x/y/z" haven't been created
您的最佳选择似乎是:
- 将特定于应用程序的虚拟目录结构硬编码到FUSE驱动程序中
- 在FUSE驱动程序中实现特定于应用程序的启发式
- 让FUSE驱动程序记住
请求,并通过反复试验构建虚拟目录树(并继续重新运行应用程序,直到它工作为止)getattr
echo test>foo/bar;回声测试>foo
?另一种方法是什么:回声测试>foo;echo test>foo/bar
?@Leon:这两个命令都应该正常执行,在这两种情况下,FUSE文件系统应该分别接受对名为foo
或foo/bar
的文件的写操作。这意味着在您的用例中,您只会发出写请求,而不会回读。利昂:没错。文件系统在内部使用所有写请求,但不需要读回任何内容。