]> git.tue.mpg.de Git - osl.git/commitdiff
Fix fsck error codes.
authorAndre Noll <maan@systemlinux.org>
Thu, 5 Jun 2008 19:44:42 +0000 (21:44 +0200)
committerAndre Noll <maan@systemlinux.org>
Thu, 5 Jun 2008 19:44:42 +0000 (21:44 +0200)
error.h
fsck.c

diff --git a/error.h b/error.h
index 5652e9a4556241ab4d9090f7e6797b2c0fdf2001..f28c39de2dcc00efc2ae8aa29bcba3f59fd7748e 100644 (file)
--- a/error.h
+++ b/error.h
@@ -1,3 +1,4 @@
+#define FSCK_ERROR_BIT 29
 /**
  * This bit indicates whether a number is considered a system error number
  * If yes, the system errno is just the result of clearing this bit from
diff --git a/fsck.c b/fsck.c
index d800017c4ba002b61751fe1ff7e298878d00b5fc..ef068d369a879c160f2569f282777765b2497371 100644 (file)
--- a/fsck.c
+++ b/fsck.c
 
 static struct fsck_args_info conf;
 
-enum fsck_errors {
-       E_RANGE_VIOLATION,
-       E_INVALID_OBJECT,
-       E_NOT_A_REGULAR_FILE,
-       E_FSCK_SYNTAX,
+#define FSCK_ERRORS \
+       FSCK_ERROR(RANGE_VIOLATION, "range violation detected, very bad"), \
+       FSCK_ERROR(NOT_A_REGULAR_FILE, "not a regular file"), \
+       FSCK_ERROR(SYNTAX, "fsck syntax error"),
+
+#define FSCK_ERROR(num, txt) E_FSCK_ ## num
+enum {
+       FSCK_DUMMY = (1 << FSCK_ERROR_BIT) - 1,
+       FSCK_ERRORS
 };
+#undef FSCK_ERROR
+#define FSCK_ERROR(num, txt) txt
+const char const *fsck_errors[] = {
+       FSCK_ERRORS
+};
+
+static const char *fsck_strerror(int num)
+{
+       if (num & (1 << FSCK_ERROR_BIT))
+               return fsck_errors[num & ((1 << FSCK_ERROR_BIT) - 1)];
+       return osl_strerror(num);
+}
 
 __printf_2_3 void para_log(int ll, const char* fmt,...)
 {
@@ -308,7 +324,7 @@ static int check_range(struct osl_table *t, uint32_t row_num, uint32_t col_num)
        if (obj_start < map_start || obj_start + obj.size > map_start + col->data_map.size) {
                CRIT_LOG("range violation in row %u, col %u\n", row_num,
                        col_num);
-               return -E_RANGE_VIOLATION;
+               return -E_FSCK_RANGE_VIOLATION;
        }
        DEBUG_LOG("col %u: ok\n", col_num);
        return 1;
@@ -336,10 +352,10 @@ static int check_index_ranges(struct osl_table *t)
                                continue;
                        ret = check_range(t, i, j);
                        if (ret < 0) {
-                               if (ret != -E_INVALID_OBJECT &&
-                                               ret != -E_RANGE_VIOLATION)
+                               if (ret != -E_OSL_INVALID_OBJECT &&
+                                               ret != -E_FSCK_RANGE_VIOLATION)
                                        goto err;
-                               if (ret == -E_INVALID_OBJECT) {
+                               if (ret == -E_OSL_INVALID_OBJECT) {
                                        CRIT_LOG("row %d, col %d maps to an "
                                                "invalid object\n", i, j);
                                }
@@ -450,7 +466,7 @@ static int check_for_invalid_objects(struct osl_table *t, uint32_t **lost_bytes)
                                loss[i] -= obj.size + 1; /* add one for header byte */
                                continue;
                        }
-                       if (ret != -E_INVALID_OBJECT)
+                       if (ret != -E_OSL_INVALID_OBJECT)
                                goto err;
                        CRIT_LOG("row %d, col %d points to an invalid "
                                "mapped object, bad\n", j, i);
@@ -544,7 +560,7 @@ static int prune_objects(struct osl_table *t, uint32_t *lost_bytes)
                ret = osl_rename(new_col_filenames[i], col_filenames[i]);
                if (ret < 0) { /* we're kinda screwed here */
                        CRIT_LOG("rename of col %i failed: %s\n", i,
-                               strerror(errno));
+                               osl_strerror(errno));
                        goto out_free;
                }
        }
@@ -623,7 +639,7 @@ out:
        free(path);
        if (ret < 0)
                return ret;
-       ret = -E_NOT_A_REGULAR_FILE;
+       ret = -E_FSCK_NOT_A_REGULAR_FILE;
        if (!(S_IFREG & statbuf.st_mode))
                return ret;
        return 1;
@@ -1171,11 +1187,10 @@ int main(int argc, char **argv)
        }
 out:
        if (ret < 0) {
-               /* FIXME: osl_strerror() is BAD!!! */
                ERROR_LOG("%s%s: %s\n",
                        base_dir? "base_dir: " : "",
                        base_dir? base_dir : "",
-                       osl_strerror(-ret)
+                       fsck_strerror(-ret)
                );
                if (conf.loglevel_arg > 1)
                        EMERG_LOG("re-run with \"--loglevel %d\" to increase verbosity\n",