From a8dc017a48d73b89b3b9716082f62b50253048f3 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 19 Feb 2023 16:54:19 +0000 Subject: [PATCH] Implemented Read --- fuse/main.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/fuse/main.go b/fuse/main.go index c5e60c5..769f593 100644 --- a/fuse/main.go +++ b/fuse/main.go @@ -49,6 +49,7 @@ type ITNode struct { Ino uint64 lst []DirEntry + self DirEntry path string } @@ -188,7 +189,10 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (* Mode: fuse.S_IFREG, Ino: inodemap[file.path], } - operations := &ITNode{kind: 2, path: file.path} + operations := &ITNode{ + kind: 2, path: file.path, + self: file, + } child := n.NewInode(ctx, operations, stable) return child, 0 } @@ -214,6 +218,24 @@ func (fh *bytesFileHandle) Read(ctx context.Context, dest []byte, off int64) (fu var _ = (fs.NodeOpener)((*ITNode)(nil)) func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno) { switch f.kind { + case 2: + // FS file + fp, err := myfs.Open(f.path) + if err != nil { + return nil, 0, syscall.EROFS + } + + buf := make([]byte, f.self.size); + nread, err := fp.Read(buf) + if err != nil || nread != int(f.self.size) { + return nil, 0, syscall.EROFS + } + + fh = &bytesFileHandle{ + content: buf, + } + return fh, fuse.FOPEN_DIRECT_IO, 0 + case 3: // Device file