]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/errcode.c
Update bcachefs sources to f9c612bbf82d bcachefs: Fixes for building in userspace
[bcachefs-tools-debian] / libbcachefs / errcode.c
index 9da8a5973af06ceaf7624d929b9a86c0ee387be1..d260ff9bbfeb7b9121f222a4362f37f95c927977 100644 (file)
@@ -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);
+}