2017-05-03 05:35:07 +08:00
|
|
|
// Cross platform errors
|
|
|
|
|
2017-10-29 03:01:34 +08:00
|
|
|
package vfs
|
2017-05-03 05:35:07 +08:00
|
|
|
|
2017-10-29 03:16:03 +08:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
2017-05-03 05:35:07 +08:00
|
|
|
|
2017-11-03 19:35:36 +08:00
|
|
|
// Error describes low level errors in a cross platform way.
|
2017-05-03 05:35:07 +08:00
|
|
|
type Error byte
|
|
|
|
|
2017-10-29 03:16:03 +08:00
|
|
|
// NB if changing errors translateError in cmd/mount/fs.go, cmd/cmount/fs.go
|
2017-05-11 20:15:51 +08:00
|
|
|
|
2017-05-03 05:35:07 +08:00
|
|
|
// Low level errors
|
|
|
|
const (
|
|
|
|
OK Error = iota
|
|
|
|
ENOTEMPTY
|
|
|
|
ESPIPE
|
|
|
|
EBADF
|
2017-05-11 20:15:51 +08:00
|
|
|
EROFS
|
2017-10-30 05:11:17 +08:00
|
|
|
ENOSYS
|
2017-05-03 05:35:07 +08:00
|
|
|
)
|
|
|
|
|
2017-10-29 03:16:03 +08:00
|
|
|
// Errors which have exact counterparts in os
|
|
|
|
var (
|
|
|
|
ENOENT = os.ErrNotExist
|
|
|
|
EEXIST = os.ErrExist
|
2017-10-31 23:33:08 +08:00
|
|
|
EPERM = os.ErrPermission
|
2018-02-24 06:39:28 +08:00
|
|
|
EINVAL = os.ErrInvalid
|
2017-11-03 19:35:36 +08:00
|
|
|
// ECLOSED see errors_{old,new}.go
|
2017-10-29 03:16:03 +08:00
|
|
|
)
|
|
|
|
|
2017-05-03 05:35:07 +08:00
|
|
|
var errorNames = []string{
|
|
|
|
OK: "Success",
|
|
|
|
ENOTEMPTY: "Directory not empty",
|
|
|
|
ESPIPE: "Illegal seek",
|
|
|
|
EBADF: "Bad file descriptor",
|
2017-05-11 20:15:51 +08:00
|
|
|
EROFS: "Read only file system",
|
2017-10-30 05:11:17 +08:00
|
|
|
ENOSYS: "Function not implemented",
|
2017-05-03 05:35:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Error renders the error as a string
|
|
|
|
func (e Error) Error() string {
|
|
|
|
if int(e) >= len(errorNames) {
|
|
|
|
return fmt.Sprintf("Low level error %d", e)
|
|
|
|
}
|
|
|
|
return errorNames[e]
|
|
|
|
}
|