1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/errname.h>
8 static const char * const bch2_errcode_strs[] = {
9 #define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = #err,
17 static unsigned bch2_errcode_parents[] = {
18 #define x(class, err) [BCH_ERR_##err - BCH_ERR_START] = class,
23 const char *bch2_err_str(int err)
29 BUG_ON(err >= BCH_ERR_MAX);
31 if (err >= BCH_ERR_START)
32 errstr = bch2_errcode_strs[err - BCH_ERR_START];
34 errstr = errname(err);
36 errstr = "(No error)";
37 return errstr ?: "(Invalid error)";
40 bool __bch2_err_matches(int err, int class)
45 BUG_ON(err >= BCH_ERR_MAX);
46 BUG_ON(class >= BCH_ERR_MAX);
48 while (err >= BCH_ERR_START && err != class)
49 err = bch2_errcode_parents[err - BCH_ERR_START];
54 int __bch2_err_class(int err)
57 BUG_ON((unsigned) err >= BCH_ERR_MAX);
59 while (err >= BCH_ERR_START && bch2_errcode_parents[err - BCH_ERR_START])
60 err = bch2_errcode_parents[err - BCH_ERR_START];