forked from Elara6331/itd
Implemented Read
This commit is contained in:
parent
d04af07dbe
commit
a8dc017a48
24
fuse/main.go
24
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user