12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- 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
- 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) GetFsDescription() string {
- return fmt.Sprintf("%s (mid=0x%08X)", e.fstype, e.mountid)
- }
- func NewAMNTFSError(emsg AMNTFSErrNo, rawErr error) *AMNTFSError {
- return &AMNTFSError{
- etype: emsg,
- rawErr: rawErr,
- fstype: "",
- mountid: 0,
- }
- }
- func NewAMNTFSChildFsError(fsent *MountNode, rawErr error) *AMNTFSError {
- return &AMNTFSError{
- etype: ErrChildFsError,
- rawErr: rawErr,
- fstype: fsent.FsType(),
- mountid: fsent.MountId(),
- }
- }
- 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
- }
- }
|