| 1 | package btrfs |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | ) |
| 7 | |
| 8 | type ErrNotBtrfs struct { |
| 9 | Path string |
| 10 | } |
| 11 | |
| 12 | func (e ErrNotBtrfs) Error() string { |
| 13 | return fmt.Sprintf("not a btrfs filesystem: %s", e.Path) |
| 14 | } |
| 15 | |
| 16 | // Error codes as returned by the kernel |
| 17 | type ErrCode int |
| 18 | |
| 19 | func (e ErrCode) Error() string { |
| 20 | s, ok := errorString[e] |
| 21 | if ok { |
| 22 | return s |
| 23 | } |
| 24 | return fmt.Sprintf("error %d", int(e)) |
| 25 | } |
| 26 | |
| 27 | const ( |
| 28 | ErrDevRAID1MinNotMet = ErrCode(iota + 1) |
| 29 | ErrDevRAID10MinNotMet |
| 30 | ErrDevRAID5MinNotMet |
| 31 | ErrDevRAID6MinNotMet |
| 32 | ErrDevTargetReplace |
| 33 | ErrDevMissingNotFound |
| 34 | ErrDevOnlyWritable |
| 35 | ErrDevExclRunInProgress |
| 36 | ) |
| 37 | |
| 38 | var errorString = map[ErrCode]string{ |
| 39 | ErrDevRAID1MinNotMet: "unable to go below two devices on raid1", |
| 40 | ErrDevRAID10MinNotMet: "unable to go below four devices on raid10", |
| 41 | ErrDevRAID5MinNotMet: "unable to go below two devices on raid5", |
| 42 | ErrDevRAID6MinNotMet: "unable to go below three devices on raid6", |
| 43 | ErrDevTargetReplace: "unable to remove the dev_replace target dev", |
| 44 | ErrDevMissingNotFound: "no missing devices found to remove", |
| 45 | ErrDevOnlyWritable: "unable to remove the only writeable device", |
| 46 | ErrDevExclRunInProgress: "add/delete/balance/replace/resize operation in progress", |
| 47 | } |
| 48 | |
| 49 | var ( |
| 50 | ErrNotFound = errors.New("not found") |
| 51 | errNotImplemented = errors.New("not implemented") |
| 52 | ) |