Added FUSE support #55

Merged
Elara6331 merged 65 commits from yannickulrich/itd:fuse into master 2023-03-25 22:23:52 +00:00
Showing only changes of commit 5008cdd4f4 - Show all commits

View File

@ -106,6 +106,41 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
return nil, syscall.ENOENT
}
type bytesFileHandle struct {
content []byte
}
var _ = (fs.FileReader)((*bytesFileHandle)(nil))
func (fh *bytesFileHandle) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) {
end := off + int64(len(dest))
if end > int64(len(fh.content)) {
end = int64(len(fh.content))
}
return fuse.ReadResultData(fh.content[off:end]), 0
}
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 3:
// Device file
// disallow writes
if fuseFlags&(syscall.O_RDWR|syscall.O_WRONLY) != 0 {
return nil, 0, syscall.EROFS
}
for _, value := range properties {
if value.Ino == f.Ino {
fh = &bytesFileHandle{
content: []byte(value.name),
}
return fh, fuse.FOPEN_DIRECT_IO, 0
}
}
}
return nil, 0, syscall.EROFS
}
func main() {
// This is where we'll mount the FS