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