]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/errcode.c
Update bcachefs sources to 90a9c61e2b bcachefs: Switch bch2_btree_delete_range()...
[bcachefs-tools-debian] / libbcachefs / errcode.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 #include "bcachefs.h"
4 #include "errcode.h"
5
6 #include <linux/errname.h>
7
8 static const char * const bch2_errcode_strs[] = {
9 #define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = #err,
10         BCH_ERRCODES()
11 #undef x
12         NULL
13 };
14
15 #define BCH_ERR_0       0
16
17 static unsigned bch2_errcode_parents[] = {
18 #define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = BCH_ERR_##class,
19         BCH_ERRCODES()
20 #undef x
21 };
22
23 const char *bch2_err_str(int err)
24 {
25         const char *errstr;
26         err = abs(err);
27
28         BUG_ON(err >= BCH_ERR_MAX);
29
30         if (err >= BCH_ERR_START)
31                 errstr = bch2_errcode_strs[err - BCH_ERR_START];
32         else if (err)
33                 errstr = errname(err);
34         else
35                 errstr = "(No error)";
36         return errstr ?: "(Invalid error)";
37 }
38
39 bool __bch2_err_matches(int err, int class)
40 {
41         err     = abs(err);
42         class   = abs(class);
43
44         BUG_ON(err      >= BCH_ERR_MAX);
45         BUG_ON(class    >= BCH_ERR_MAX);
46
47         while (err >= BCH_ERR_START && err != class)
48                 err = bch2_errcode_parents[err - BCH_ERR_START];
49
50         return err == class;
51 }