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