Added FUSE support #55
@ -126,6 +126,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
||||
files, err := myfs.ReadDir(n.path)
|
||||
if err != nil {
|
||||
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
|
||||
// TODO we probably should figure out why it failed
|
||||
return nil, syscall.ENOENT
|
||||
}
|
||||
|
||||
@ -209,7 +210,6 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
|
||||
return child, 0
|
||||
}
|
||||
}
|
||||
return nil, syscall.ENOENT
|
||||
|
||||
case 2:
|
||||
// FS object
|
||||
@ -290,6 +290,8 @@ var _ fs.FileWriter = (*bytesFileWriteHandle)(nil)
|
||||
func (fh *bytesFileWriteHandle) Write(ctx context.Context, data []byte, off int64) (written uint32, errno syscall.Errno) {
|
||||
log.Info("Executing Write").Str("path", fh.path).Int("prev_size", len(fh.content)).Int("next_size", len(data)).Send()
|
||||
if off != int64(len(fh.content)) {
|
||||
log.Error("FUSE Write file size changed unexpectedly").Int("expect", int(off)).Int("received", len(fh.content)).Send()
|
||||
return 0, syscall.ENXIO
|
||||
}
|
||||
fh.content = append(fh.content[:], data[:]...)
|
||||
return uint32(len(data)), 0
|
||||
@ -320,17 +322,17 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
|
||||
if err != nil {
|
||||
log.Error("FUSE Flush failed during write").Str("path", fh.path).Err(err).Send()
|
||||
fp.Close()
|
||||
return syscall.EROFS
|
||||
return syscall.EIO
|
||||
}
|
||||
if int(nread) != len(fh.content) {
|
||||
log.Error("FUSE Flush failed during write").Str("path", fh.path).Int("expect", len(fh.content)).Int("got", int(nread)).Send()
|
||||
fp.Close()
|
||||
return syscall.EROFS
|
||||
return syscall.EIO
|
||||
}
|
||||
err = fp.Close()
|
||||
if err != nil {
|
||||
yannickulrich marked this conversation as resolved
|
||||
log.Error("FUSE Flush failed during close").Str("path", fh.path).Err(err).Send()
|
||||
return syscall.EROFS
|
||||
return syscall.EIO
|
||||
}
|
||||
log.Debug("FUSE Flush done").Str("path", fh.path).Int("size", len(fh.content)).Send()
|
||||
|
||||
@ -381,6 +383,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
||||
log.Debug("FUSE Opening for read").Str("path", f.path).Send()
|
||||
fp, err := myfs.Open(f.path)
|
||||
if err != nil {
|
||||
// TODO we probably should figure out why it failed
|
||||
log.Error("FUSE: Opening failed").Str("path", f.path).Err(err).Send()
|
||||
return nil, 0, syscall.EROFS
|
||||
}
|
||||
@ -400,7 +403,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
||||
if err != nil {
|
||||
log.Error("FUSE Read failed").Str("path", f.path).Err(err).Send()
|
||||
fp.Close()
|
||||
return nil, 0, syscall.EROFS
|
||||
return nil, 0, syscall.EIO
|
||||
}
|
||||
|
||||
fh = &bytesFileReadHandle{
|
||||
@ -422,7 +425,8 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
||||
sub_ctx, cancel := context.WithCancel(ctx)
|
||||
ans, err := value.gen(sub_ctx)
|
||||
if err != nil {
|
||||
return nil, 0, syscall.EROFS
|
||||
// TODO we probably should figure out why it failed
|
||||
return nil, 0, syscall.EIO
|
||||
}
|
||||
|
||||
fh = &sensorFileReadHandle{
|
||||
@ -433,7 +437,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, 0, syscall.EROFS
|
||||
return nil, 0, syscall.EINVAL
|
||||
}
|
||||
|
||||
var _ fs.NodeCreater = (*ITNode)(nil)
|
||||
@ -480,6 +484,7 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
|
||||
Str("path", path).
|
||||
Err(err).
|
||||
Send()
|
||||
// TODO we probably should figure out why it failed
|
||||
return nil, syscall.EROFS
|
||||
}
|
||||
|
||||
@ -505,6 +510,10 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
|
||||
|
||||
var _ fs.NodeRenamer = (*ITNode)(nil)
|
||||
func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbedder, newName string, flags uint32) syscall.Errno {
|
||||
if f.kind != 2 {
|
||||
return syscall.EROFS
|
||||
}
|
||||
|
||||
p1 := f.path + "/" + name
|
||||
p2 := newParent.EmbeddedInode().Path(nil)[2:] + "/" + newName
|
||||
|
||||
@ -516,7 +525,8 @@ func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbe
|
||||
Err(err).
|
||||
Send()
|
||||
|
||||
return syscall.EROFS
|
||||
// TODO we probably should figure out why it failed
|
||||
return syscall.EIO
|
||||
}
|
||||
log.Debug("FUSE Rename sucess").
|
||||
Str("src", p1).
|
||||
@ -532,6 +542,10 @@ func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbe
|
||||
|
||||
var _ fs.NodeUnlinker = (*ITNode)(nil)
|
||||
func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
|
||||
if f.kind != 2 {
|
||||
return syscall.EROFS
|
||||
}
|
||||
|
||||
delete(inodemap, f.path + "/" + name)
|
||||
err := myfs.Remove(f.path + "/" + name)
|
||||
if err != nil {
|
||||
@ -540,7 +554,8 @@ func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
|
||||
Err(err).
|
||||
Send()
|
||||
|
||||
return syscall.EROFS
|
||||
// TODO we probably should figure out why it failed
|
||||
return syscall.EIO
|
||||
}
|
||||
|
||||
log.Debug("FUSE Unlink success").
|
||||
|
Loading…
Reference in New Issue
Block a user
These should be debug logs rather than info logs. Also, the message should be a bit more specific, something like "FUSE getattr". Same for all the similar logs.
Done in
b5328ec