打开文件

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

go-fuse Open file

问题

使用go-fuse创建了一个FUSE文件系统:nodefs。除了文件无法打开之外,一切都正常工作。

基本上,文件节点的结构如下:

  1. type SomeFileNode struct {
  2. nodefs.Node
  3. content string
  4. }
  5. func (this *SomeFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
  6. return nodefs.NewDataFile([]byte(this.content)), fuse.OK
  7. }

我期望使用cat命令来查看该文件,但是没有任何内容打印到标准输出。

我漏掉了什么?

完整的复现代码如下:

  1. func main() {
  2. mountPoint := "/some/mountpoint"
  3. fs := &SomeFs{Root: &SomeRootNode{nodefs.NewDefaultNode()}}
  4. server, _, err := nodefs.MountRoot(mountPoint, fs.Root, nil)
  5. if err != nil {
  6. log.Fatalln("Mount fail")
  7. os.Exit(1)
  8. }
  9. server.Serve()
  10. }
  11. type SomeFs struct {
  12. Root *SomeRootNode
  13. }
  14. type SomeRootNode struct {
  15. nodefs.Node
  16. }
  17. type SomeFileNode struct {
  18. nodefs.Node
  19. content string
  20. }
  21. func (this *SomeRootNode) OnMount(c *nodefs.FileSystemConnector) {
  22. this.Inode().NewChild("leaf", false, &SomeFileNode{Node: nodefs.NewDefaultNode(), content: "hello"})
  23. }
  24. func (this *SomeFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
  25. return nodefs.NewDataFile([]byte(this.content)), fuse.OK
  26. }
英文:

Created a FUSE filesystem using go-fuse : nodefs. Everything works except files are not opened.

Basically the file node is like:

  1. type SomeFileNode struct {
  2. nodefs.Node
  3. content string
  4. }
  5. func (this *SomeFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
  6. return nodefs.NewDataFile([]byte(this.content)), fuse.OK
  7. }

I expect to cat that file, but nothing is printed to stdout.

What am I missing?

Full repro code:

  1. func main() {
  2. mountPoint := "/some/mountpoint"
  3. fs := &SomeFs{Root: &SomeRootNode{nodefs.NewDefaultNode()}}
  4. server, _, err := nodefs.MountRoot(mountPoint, fs.Root, nil)
  5. if err != nil {
  6. log.Fatalln("Mount fail")
  7. os.Exit(1)
  8. }
  9. server.Serve()
  10. }
  11. type SomeFs struct {
  12. Root *SomeRootNode
  13. }
  14. type SomeRootNode struct {
  15. nodefs.Node
  16. }
  17. type SomeFileNode struct {
  18. nodefs.Node
  19. content string
  20. }
  21. func (this *SomeRootNode) OnMount(c *nodefs.FileSystemConnector) {
  22. this.Inode().NewChild("leaf", false, &SomeFileNode{Node: nodefs.NewDefaultNode(), content: "hello"})
  23. }
  24. func (this *SomeFileNode) Open(flags uint32, context *fuse.Context) (nodefs.File, fuse.Status) {
  25. return nodefs.NewDataFile([]byte(this.content)), fuse.OK
  26. }

答案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:

确定