Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 使用FUSE以目录形式命名管道_Go_Fuse - Fatal编程技术网

Go 使用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

我想创建一个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 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
的文件的写操作。这意味着在您的用例中,您只会发出写请求,而不会回读。利昂:没错。文件系统在内部使用所有写请求,但不需要读回任何内容。