打开文件

huangapple go评论75阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2017年9月15日 02:20:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/46225887.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定