2023-03-25 22:23:51 +00:00
|
|
|
package fusefs
|
2023-03-25 22:24:46 +00:00
|
|
|
|
2023-03-25 22:23:51 +00:00
|
|
|
import (
|
|
|
|
"syscall"
|
2023-03-25 22:24:46 +00:00
|
|
|
|
2024-04-14 04:20:12 +00:00
|
|
|
"go.elara.ws/itd/internal/fsproto"
|
2023-03-25 22:23:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func syscallErr(err error) syscall.Errno {
|
|
|
|
if err == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-03-25 23:03:56 +00:00
|
|
|
switch err := err.(type) {
|
2024-04-14 04:20:12 +00:00
|
|
|
case fsproto.Error:
|
2023-03-25 23:03:56 +00:00
|
|
|
switch err.Code {
|
|
|
|
case 0x02: // filesystem error
|
2024-04-14 04:20:12 +00:00
|
|
|
return syscall.EIO
|
2023-03-25 23:03:56 +00:00
|
|
|
case 0x05: // read-only filesystem
|
|
|
|
return syscall.EROFS
|
|
|
|
case 0x03: // no such file
|
|
|
|
return syscall.ENOENT
|
|
|
|
case 0x04: // protocol error
|
|
|
|
return syscall.EPROTO
|
|
|
|
case -5: // input/output error
|
|
|
|
return syscall.EIO
|
|
|
|
case -84: // filesystem is corrupted
|
2024-04-14 04:20:12 +00:00
|
|
|
return syscall.ENOTRECOVERABLE
|
2023-03-25 23:03:56 +00:00
|
|
|
case -2: // no such directory entry
|
|
|
|
return syscall.ENOENT
|
|
|
|
case -17: // entry already exists
|
|
|
|
return syscall.EEXIST
|
|
|
|
case -20: // entry is not a directory
|
|
|
|
return syscall.ENOTDIR
|
|
|
|
case -39: // directory is not empty
|
|
|
|
return syscall.ENOTEMPTY
|
|
|
|
case -9: // bad file number
|
|
|
|
return syscall.EBADF
|
|
|
|
case -27: // file is too large
|
|
|
|
return syscall.EFBIG
|
|
|
|
case -22: // invalid parameter
|
|
|
|
return syscall.EINVAL
|
|
|
|
case -28: // no space left on device
|
|
|
|
return syscall.ENOSPC
|
|
|
|
case -12: // no more memory available
|
|
|
|
return syscall.ENOMEM
|
|
|
|
case -61: // no attr available
|
2024-04-14 04:20:12 +00:00
|
|
|
return syscall.ENODATA
|
2023-03-25 23:03:56 +00:00
|
|
|
case -36: // file name is too long
|
|
|
|
return syscall.ENAMETOOLONG
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
switch err {
|
2024-04-14 04:20:12 +00:00
|
|
|
case fsproto.ErrFileNotExists: // file does not exist
|
2023-03-25 23:03:56 +00:00
|
|
|
return syscall.ENOENT
|
2024-04-14 04:20:12 +00:00
|
|
|
case fsproto.ErrFileReadOnly: // file is read only
|
2023-03-25 23:03:56 +00:00
|
|
|
return syscall.EACCES
|
2024-04-14 04:20:12 +00:00
|
|
|
case fsproto.ErrFileWriteOnly: // file is write only
|
2023-03-25 23:03:56 +00:00
|
|
|
return syscall.EACCES
|
2024-04-14 04:20:12 +00:00
|
|
|
case fsproto.ErrInvalidOffset: // invalid file offset
|
2023-03-26 20:01:25 +00:00
|
|
|
return syscall.EINVAL
|
2024-04-14 04:20:12 +00:00
|
|
|
case fsproto.ErrNoRemoveRoot: // refusing to remove root directory
|
2023-03-25 23:03:56 +00:00
|
|
|
return syscall.EPERM
|
2024-04-14 04:20:12 +00:00
|
|
|
default:
|
|
|
|
return syscall.EINVAL
|
2023-03-25 23:03:56 +00:00
|
|
|
}
|
2023-03-25 22:23:51 +00:00
|
|
|
}
|
|
|
|
|
2023-03-25 23:03:56 +00:00
|
|
|
return syscall.EIO
|
2023-03-25 22:23:51 +00:00
|
|
|
}
|