From b7f006eecd456214d36db9e901d979d5f998e813 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 5 Jun 2008 21:44:42 +0200 Subject: [PATCH] Fix fsck error codes. --- error.h | 1 + fsck.c | 43 +++++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/error.h b/error.h index 5652e9a..f28c39d 100644 --- 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 d800017..ef068d3 100644 --- a/fsck.c +++ b/fsck.c @@ -40,12 +40,28 @@ 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", -- 2.39.2