123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package amntfs
- import "fmt"
- type AMNTFSErrNo uint8
- const (
- ErrChildFsError AMNTFSErrNo = iota
- ErrUnknownInternalError AMNTFSErrNo = iota
- ErrMountPointAlreadyMounted AMNTFSErrNo = iota
- ErrNoAvailableMountPointForThisPath AMNTFSErrNo = iota
- )
- func (e AMNTFSErrNo) Message() string {
- switch e {
- case ErrMountPointAlreadyMounted:
- return "mount point already mounted"
- case ErrUnknownInternalError:
- return "unknown internal error"
- case ErrNoAvailableMountPointForThisPath:
- return "no available mount point for this path"
- case ErrChildFsError:
- return "child filesystem error"
- default:
- return "unknown error"
- }
- }
- var _ error = (*AMNTFSError)(nil)
- type AMNTFSError struct {
- etype AMNTFSErrNo
- fstype string
- mountid int64
- mountPoint string
- rawErr error
- }
- func (e AMNTFSError) Error() string {
- if e.etype == ErrChildFsError {
- return fmt.Sprintf("%s [mid=0x%08X]: %s", e.fstype, e.mountid, e.rawErr.Error())
- }
- if e.rawErr == nil {
- return fmt.Sprintf("amntfs: %s", e.etype.Message())
- } else {
- return fmt.Sprintf("amntfs: %s: %s", e.etype.Message(), e.rawErr.Error())
- }
- }
- func (e AMNTFSError) GetRawError() error {
- return e.rawErr
- }
- func (e AMNTFSError) GetErrNo() AMNTFSErrNo {
- return e.etype
- }
- func (e AMNTFSError) GetFsType() string {
- return e.fstype
- }
- func (e AMNTFSError) GetMountId() int64 {
- return e.mountid
- }
- func (e AMNTFSError) GetMountPoint() string {
- return e.mountPoint
- }
- func (e AMNTFSError) GetFsDescription() string {
- return fmt.Sprintf("%s (mid=0x%08X, mnt='%s')", e.fstype, e.mountid, e.mountPoint)
- }
- func NewAMNTFSError(emsg AMNTFSErrNo, rawErr error) *AMNTFSError {
- return &AMNTFSError{
- etype: emsg,
- rawErr: rawErr,
- fstype: "",
- mountPoint: "",
- mountid: 0,
- }
- }
- func NewAMNTFSChildFsError(fsent *MountNode, rawErr error) *AMNTFSError {
- return &AMNTFSError{
- etype: ErrChildFsError,
- rawErr: rawErr,
- fstype: fsent.FsType(),
- mountid: fsent.MountId(),
- mountPoint: fsent.mountPoint,
- }
- }
- func CheckErrorType(err error, errNo AMNTFSErrNo) bool {
- if err == nil {
- return false
- }
- switch err.(type) {
- case AMNTFSError:
- return err.(AMNTFSError).GetErrNo() == errNo
- default:
- return false
- }
- }
|