forked from Elara6331/itd
Compare commits
No commits in common. "b28c386c4ebd36ca5c814e134d15f784b50f2b82" and "955e1323ce970dc33a17d91f29eab638d0c7d0a1" have entirely different histories.
b28c386c4e
...
955e1323ce
@ -126,7 +126,8 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
files, err := myfs.ReadDir(n.path)
|
files, err := myfs.ReadDir(n.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
|
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
|
||||||
return nil, syscallErr(err)
|
// TODO we probably should figure out why it failed
|
||||||
|
return nil, syscall.ENOENT
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("FUSE ReadDir succeeded").Str("path", n.path).Int("objects", len(files)).Send()
|
log.Debug("FUSE ReadDir succeeded").Str("path", n.path).Int("objects", len(files)).Send()
|
||||||
@ -136,7 +137,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
info, err := entry.Info()
|
info, err := entry.Info()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Info failed").Str("path", n.path).Err(err).Send()
|
log.Error("FUSE Info failed").Str("path", n.path).Err(err).Send()
|
||||||
return nil, syscallErr(err)
|
return nil, syscall.ENOENT
|
||||||
}
|
}
|
||||||
name := info.Name()
|
name := info.Name()
|
||||||
|
|
||||||
@ -306,7 +307,7 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
|
|||||||
fp, err := myfs.Create(fh.path, uint32(len(fh.content)))
|
fp, err := myfs.Create(fh.path, uint32(len(fh.content)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Flush failed: create").Str("path", fh.path).Err(err).Send()
|
log.Error("FUSE Flush failed: create").Str("path", fh.path).Err(err).Send()
|
||||||
return syscallErr(err)
|
return syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -321,7 +322,7 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Flush failed during write").Str("path", fh.path).Err(err).Send()
|
log.Error("FUSE Flush failed during write").Str("path", fh.path).Err(err).Send()
|
||||||
fp.Close()
|
fp.Close()
|
||||||
return syscallErr(err)
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
if int(nread) != len(fh.content) {
|
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()
|
log.Error("FUSE Flush failed during write").Str("path", fh.path).Int("expect", len(fh.content)).Int("got", int(nread)).Send()
|
||||||
@ -331,7 +332,7 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
|
|||||||
err = fp.Close()
|
err = fp.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Flush failed during close").Str("path", fh.path).Err(err).Send()
|
log.Error("FUSE Flush failed during close").Str("path", fh.path).Err(err).Send()
|
||||||
return syscallErr(err)
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
log.Debug("FUSE Flush done").Str("path", fh.path).Int("size", len(fh.content)).Send()
|
log.Debug("FUSE Flush done").Str("path", fh.path).Int("size", len(fh.content)).Send()
|
||||||
|
|
||||||
@ -382,8 +383,9 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
log.Debug("FUSE Opening for read").Str("path", f.path).Send()
|
log.Debug("FUSE Opening for read").Str("path", f.path).Send()
|
||||||
fp, err := myfs.Open(f.path)
|
fp, err := myfs.Open(f.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// TODO we probably should figure out why it failed
|
||||||
log.Error("FUSE: Opening failed").Str("path", f.path).Err(err).Send()
|
log.Error("FUSE: Opening failed").Str("path", f.path).Err(err).Send()
|
||||||
return nil, 0, syscallErr(err)
|
return nil, 0, syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
defer fp.Close()
|
defer fp.Close()
|
||||||
@ -401,7 +403,7 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE Read failed").Str("path", f.path).Err(err).Send()
|
log.Error("FUSE Read failed").Str("path", f.path).Err(err).Send()
|
||||||
fp.Close()
|
fp.Close()
|
||||||
return nil, 0, syscallErr(err)
|
return nil, 0, syscall.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
fh = &bytesFileReadHandle{
|
fh = &bytesFileReadHandle{
|
||||||
@ -423,7 +425,8 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
sub_ctx, cancel := context.WithCancel(ctx)
|
sub_ctx, cancel := context.WithCancel(ctx)
|
||||||
ans, err := value.gen(sub_ctx)
|
ans, err := value.gen(sub_ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, syscallErr(err)
|
// TODO we probably should figure out why it failed
|
||||||
|
return nil, 0, syscall.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
fh = &sensorFileReadHandle{
|
fh = &sensorFileReadHandle{
|
||||||
@ -481,7 +484,8 @@ func (f *ITNode) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.
|
|||||||
Str("path", path).
|
Str("path", path).
|
||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
return nil, syscallErr(err)
|
// TODO we probably should figure out why it failed
|
||||||
|
return nil, syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
ino := uint64(len(inodemap)) + 11
|
ino := uint64(len(inodemap)) + 11
|
||||||
@ -521,7 +525,8 @@ func (f *ITNode) Rename(ctx context.Context, name string, newParent fs.InodeEmbe
|
|||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
|
|
||||||
return syscallErr(err)
|
// TODO we probably should figure out why it failed
|
||||||
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
log.Debug("FUSE Rename sucess").
|
log.Debug("FUSE Rename sucess").
|
||||||
Str("src", p1).
|
Str("src", p1).
|
||||||
@ -549,7 +554,8 @@ func (f *ITNode) Unlink(ctx context.Context, name string) syscall.Errno {
|
|||||||
Err(err).
|
Err(err).
|
||||||
Send()
|
Send()
|
||||||
|
|
||||||
return syscallErr(err)
|
// TODO we probably should figure out why it failed
|
||||||
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("FUSE Unlink success").
|
log.Debug("FUSE Unlink success").
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
package fusefs
|
|
||||||
import (
|
|
||||||
"go.arsenm.dev/infinitime/blefs"
|
|
||||||
"syscall"
|
|
||||||
)
|
|
||||||
|
|
||||||
func syscallErr(err error) syscall.Errno {
|
|
||||||
if err == nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
switch err {
|
|
||||||
case blefs.FSError{0x02}: // filesystem error
|
|
||||||
return syscall.EIO // TODO
|
|
||||||
case blefs.FSError{0x05}: // read-only filesystem
|
|
||||||
return syscall.EROFS
|
|
||||||
case blefs.FSError{0x03}: // no such file
|
|
||||||
return syscall.ENOENT
|
|
||||||
case blefs.FSError{0x04}: // protocol error
|
|
||||||
return syscall.EPROTO
|
|
||||||
case blefs.FSError{-5}: // input/output error
|
|
||||||
return syscall.EIO
|
|
||||||
case blefs.FSError{-84}: // filesystem is corrupted
|
|
||||||
return syscall.ENOTRECOVERABLE // TODO
|
|
||||||
case blefs.FSError{-2}: // no such directory entry
|
|
||||||
return syscall.ENOENT
|
|
||||||
case blefs.FSError{-17}: // entry already exists
|
|
||||||
return syscall.EEXIST
|
|
||||||
case blefs.FSError{-20}: // entry is not a directory
|
|
||||||
return syscall.ENOTDIR
|
|
||||||
case blefs.FSError{-39}: // directory is not empty
|
|
||||||
return syscall.ENOTEMPTY
|
|
||||||
case blefs.FSError{-9}: // bad file number
|
|
||||||
return syscall.EBADF
|
|
||||||
case blefs.FSError{-27}: // file is too large
|
|
||||||
return syscall.EFBIG
|
|
||||||
case blefs.FSError{-22}: // invalid parameter
|
|
||||||
return syscall.EINVAL
|
|
||||||
case blefs.FSError{-28}: // no space left on device
|
|
||||||
return syscall.ENOSPC
|
|
||||||
case blefs.FSError{-12}: // no more memory available
|
|
||||||
return syscall.ENOMEM
|
|
||||||
case blefs.FSError{-61}: // no attr available
|
|
||||||
return syscall.ENODATA // TODO
|
|
||||||
case blefs.FSError{-36}: // file name is too long
|
|
||||||
return syscall.ENAMETOOLONG
|
|
||||||
case blefs.ErrFileNotExists: // file does not exist
|
|
||||||
return syscall.ENOENT
|
|
||||||
case blefs.ErrFileReadOnly: // file is read only
|
|
||||||
return syscall.EACCES
|
|
||||||
case blefs.ErrFileWriteOnly: // file is write only
|
|
||||||
return syscall.EACCES
|
|
||||||
case blefs.ErrInvalidOffset: // invalid file offset
|
|
||||||
return syscall.EFAULT // TODO
|
|
||||||
case blefs.ErrOffsetChanged: // offset has already been changed
|
|
||||||
return syscall.ESPIPE
|
|
||||||
case blefs.ErrReadOpen: // only one file can be opened for reading at a time
|
|
||||||
return syscall.ENFILE
|
|
||||||
case blefs.ErrWriteOpen: // only one file can be opened for writing at a time
|
|
||||||
return syscall.ENFILE
|
|
||||||
case blefs.ErrNoRemoveRoot: // refusing to remove root directory
|
|
||||||
return syscall.EPERM
|
|
||||||
}
|
|
||||||
|
|
||||||
return syscall.EIO // TODO
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user