Use type switch for syscallErr
This commit is contained in:
parent
8fb430a359
commit
948678790a
@ -11,41 +11,46 @@ func syscallErr(err error) syscall.Errno {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
switch err {
|
switch err := err.(type) {
|
||||||
case blefs.FSError{0x02}: // filesystem error
|
case blefs.FSError:
|
||||||
|
switch err.Code {
|
||||||
|
case 0x02: // filesystem error
|
||||||
return syscall.EIO // TODO
|
return syscall.EIO // TODO
|
||||||
case blefs.FSError{0x05}: // read-only filesystem
|
case 0x05: // read-only filesystem
|
||||||
return syscall.EROFS
|
return syscall.EROFS
|
||||||
case blefs.FSError{0x03}: // no such file
|
case 0x03: // no such file
|
||||||
return syscall.ENOENT
|
return syscall.ENOENT
|
||||||
case blefs.FSError{0x04}: // protocol error
|
case 0x04: // protocol error
|
||||||
return syscall.EPROTO
|
return syscall.EPROTO
|
||||||
case blefs.FSError{-5}: // input/output error
|
case -5: // input/output error
|
||||||
return syscall.EIO
|
return syscall.EIO
|
||||||
case blefs.FSError{-84}: // filesystem is corrupted
|
case -84: // filesystem is corrupted
|
||||||
return syscall.ENOTRECOVERABLE // TODO
|
return syscall.ENOTRECOVERABLE // TODO
|
||||||
case blefs.FSError{-2}: // no such directory entry
|
case -2: // no such directory entry
|
||||||
return syscall.ENOENT
|
return syscall.ENOENT
|
||||||
case blefs.FSError{-17}: // entry already exists
|
case -17: // entry already exists
|
||||||
return syscall.EEXIST
|
return syscall.EEXIST
|
||||||
case blefs.FSError{-20}: // entry is not a directory
|
case -20: // entry is not a directory
|
||||||
return syscall.ENOTDIR
|
return syscall.ENOTDIR
|
||||||
case blefs.FSError{-39}: // directory is not empty
|
case -39: // directory is not empty
|
||||||
return syscall.ENOTEMPTY
|
return syscall.ENOTEMPTY
|
||||||
case blefs.FSError{-9}: // bad file number
|
case -9: // bad file number
|
||||||
return syscall.EBADF
|
return syscall.EBADF
|
||||||
case blefs.FSError{-27}: // file is too large
|
case -27: // file is too large
|
||||||
return syscall.EFBIG
|
return syscall.EFBIG
|
||||||
case blefs.FSError{-22}: // invalid parameter
|
case -22: // invalid parameter
|
||||||
return syscall.EINVAL
|
return syscall.EINVAL
|
||||||
case blefs.FSError{-28}: // no space left on device
|
case -28: // no space left on device
|
||||||
return syscall.ENOSPC
|
return syscall.ENOSPC
|
||||||
case blefs.FSError{-12}: // no more memory available
|
case -12: // no more memory available
|
||||||
return syscall.ENOMEM
|
return syscall.ENOMEM
|
||||||
case blefs.FSError{-61}: // no attr available
|
case -61: // no attr available
|
||||||
return syscall.ENODATA // TODO
|
return syscall.ENODATA // TODO
|
||||||
case blefs.FSError{-36}: // file name is too long
|
case -36: // file name is too long
|
||||||
return syscall.ENAMETOOLONG
|
return syscall.ENAMETOOLONG
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
switch err {
|
||||||
case blefs.ErrFileNotExists: // file does not exist
|
case blefs.ErrFileNotExists: // file does not exist
|
||||||
return syscall.ENOENT
|
return syscall.ENOENT
|
||||||
case blefs.ErrFileReadOnly: // file is read only
|
case blefs.ErrFileReadOnly: // file is read only
|
||||||
@ -63,6 +68,7 @@ func syscallErr(err error) syscall.Errno {
|
|||||||
case blefs.ErrNoRemoveRoot: // refusing to remove root directory
|
case blefs.ErrNoRemoveRoot: // refusing to remove root directory
|
||||||
return syscall.EPERM
|
return syscall.EPERM
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return syscall.EIO // TODO
|
return syscall.EIO
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user