X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libbcachefs%2Ferrcode.c;h=d260ff9bbfeb7b9121f222a4362f37f95c927977;hb=a053ebfb8c89e023a44c365e369f4053cfc53376;hp=9da8a5973af06ceaf7624d929b9a86c0ee387be1;hpb=ddac1641ee1e2686c2211a8d671ea723634dfc89;p=bcachefs-tools-debian diff --git a/libbcachefs/errcode.c b/libbcachefs/errcode.c index 9da8a59..d260ff9 100644 --- a/libbcachefs/errcode.c +++ b/libbcachefs/errcode.c @@ -12,10 +12,8 @@ static const char * const bch2_errcode_strs[] = { NULL }; -#define BCH_ERR_0 0 - static unsigned bch2_errcode_parents[] = { -#define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = BCH_ERR_##class, +#define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = class, BCH_ERRCODES() #undef x }; @@ -23,6 +21,7 @@ static unsigned bch2_errcode_parents[] = { const char *bch2_err_str(int err) { const char *errstr; + err = abs(err); BUG_ON(err >= BCH_ERR_MAX); @@ -49,3 +48,21 @@ bool __bch2_err_matches(int err, int class) return err == class; } + +int __bch2_err_class(int err) +{ + err = -err; + BUG_ON((unsigned) err >= BCH_ERR_MAX); + + while (err >= BCH_ERR_START && bch2_errcode_parents[err - BCH_ERR_START]) + err = bch2_errcode_parents[err - BCH_ERR_START]; + + return -err; +} + +const char *bch2_blk_status_to_str(blk_status_t status) +{ + if (status == BLK_STS_REMOVED) + return "device removed"; + return blk_status_to_str(status); +}