英文:
go-fuse Open file
问题
使用go-fuse创建了一个FUSE文件系统:nodefs。除了文件无法打开之外,一切都正常工作。
基本上,文件节点的结构如下:
type SomeFileNode struct {
nodefs.Node
content string
}
func (this *SomeFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
return nodefs.NewDataFile([]byte(this.content)), fuse.OK
}
我期望使用cat
命令来查看该文件,但是没有任何内容打印到标准输出。
我漏掉了什么?
完整的复现代码如下:
func main() {
mountPoint := "/some/mountpoint"
fs := &SomeFs{Root: &SomeRootNode{nodefs.NewDefaultNode()}}
server, _, err := nodefs.MountRoot(mountPoint, fs.Root, nil)
if err != nil {
log.Fatalln("Mount fail")
os.Exit(1)
}
server.Serve()
}
type SomeFs struct {
Root *SomeRootNode
}
type SomeRootNode struct {
nodefs.Node
}
type SomeFileNode struct {
nodefs.Node
content string
}
func (this *SomeRootNode) OnMount(c *nodefs.FileSystemConnector) {
this.Inode().NewChild("leaf", false, &SomeFileNode{Node: nodefs.NewDefaultNode(), content: "hello"})
}
func (this *SomeFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
return nodefs.NewDataFile([]byte(this.content)), fuse.OK
}
英文:
Created a FUSE filesystem using go-fuse : nodefs. Everything works except files are not opened.
Basically the file node is like:
type SomeFileNode struct {
nodefs.Node
content string
}
func (this *SomeFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
return nodefs.NewDataFile([]byte(this.content)), fuse.OK
}
I expect to cat
that file, but nothing is printed to stdout.
What am I missing?
Full repro code:
func main() {
mountPoint := "/some/mountpoint"
fs := &SomeFs{Root: &SomeRootNode{nodefs.NewDefaultNode()}}
server, _, err := nodefs.MountRoot(mountPoint, fs.Root, nil)
if err != nil {
log.Fatalln("Mount fail")
os.Exit(1)
}
server.Serve()
}
type SomeFs struct {
Root *SomeRootNode
}
type SomeRootNode struct {
nodefs.Node
}
type SomeFileNode struct {
nodefs.Node
content string
}
func (this *SomeRootNode) OnMount(c *nodefs.FileSystemConnector) {
this.Inode().NewChild("leaf", false, &SomeFileNode{Node: nodefs.NewDefaultNode(), content: "hello"})
}
func (this *SomeFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
return nodefs.NewDataFile([]byte(this.content)), fuse.OK
}
答案1
得分: 0
这里有答案:https://github.com/hanwen/go-fuse/issues/186
需要实现GetAttr并报告Size。
英文:
Was answered here: https://github.com/hanwen/go-fuse/issues/186
need to implement GetAttr and report Size.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论