go-fuse 打开文件

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
}

在这里回答:https://github.com/hanwen/go-fuse/issues/186

需要实现 GetAttr 并报告大小。