Added FUSE support #55
@ -265,18 +265,20 @@ func (fh *bytesFileReadHandle) Read(ctx context.Context, dest []byte, off int64)
|
||||
}
|
||||
|
||||
type sensorFileReadHandle struct {
|
||||
ch <-chan []byte
|
||||
cancel context.CancelFunc
|
||||
content []byte
|
||||
}
|
||||
var _ fs.FileReader = (*sensorFileReadHandle)(nil)
|
||||
func (fh *sensorFileReadHandle) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) {
|
||||
content := <-fh.ch
|
||||
return fuse.ReadResultData(content), 0
|
||||
log.Info("Executing Read").Int("size", len(fh.content)).Send()
|
||||
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.FileFlusher = (*sensorFileReadHandle)(nil)
|
||||
func (fh *sensorFileReadHandle) Flush(ctx context.Context) (errno syscall.Errno) {
|
||||
fh.cancel()
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -428,15 +430,13 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
||||
|
||||
for _, value := range properties {
|
||||
if value.Ino == f.Ino {
|
||||
sub_ctx, cancel := context.WithCancel(ctx)
|
||||
ans, err := value.gen(sub_ctx)
|
||||
ans, err := value.gen()
|
||||
if err != nil {
|
||||
return nil, 0, syscallErr(err)
|
||||
}
|
||||
|
||||
fh = &sensorFileReadHandle{
|
||||
ch: ans,
|
||||
cancel : cancel,
|
||||
content : ans,
|
||||
}
|
||||
return fh, fuse.FOPEN_DIRECT_IO, 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user