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
|
||||
|
Elara6331 marked this conversation as resolved
Outdated
|
||||
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
Elara6331
commented
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. 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.
yannickulrich
commented
Done in Done in b5328ec
|
||||
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()
|
||||
|
yannickulrich marked this conversation as resolved
Outdated
Elara6331
commented
Minor typo, it's "success" Minor typo, it's "success"
yannickulrich
commented
Done in Done in b5328ec
|
||||
// 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").
|
||||
|
||||
Reference in New Issue
Block a user
How would you recommend doing this? I suppose it could fail for all sorts of reasons such as
ENOENTEIOEINVALECONNABORTEDECONNREFUSEDECONNRESETEISNAMIn other places such as when we open a file, we could have
EISDIREEXISTAgain, I'm sorry but I'm not a Go expert and don't really now how to do this properly.. especially when dealing with
FSErrorThe
errcan be several different kinds of errors, andFSErroris just one of them. It's actually a type I made. You can see it here: https://gitea.arsenm.dev/Arsen6331/infinitime/src/commit/512d48bc2469/blefs/error.go#L20. It contains an error code you can check to see what went wrong, and you can scroll down to see the meaning of each code.In this case, I'd use a Go type switch to check which error type actually occurred and then check the code or do whatever else needs to be done. Maybe there could be a function like
syscallErr()that takes anerrorand returns the proper syscall error?If you don't feel comfortable doing that, I can merge this and then implement it myself and send you the commit so you can see how I did it, or you can just try it yourself, whatever you feel would be better.
Something like in 4c59561a99? There are a few
TODOwhere I'm not sure what the correct POSIX error would be and improvised. If you have a better idea, feel free to change them thoughThat looks good, thanks