Search code examples
gofuse

go-fuse Open file


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
}

Solution

  • Was answered here: https://github.com/hanwen/go-fuse/issues/186

    need to implement GetAttr and report Size.