From d3f7bf64c1eb21af9dfe6885964b1ccb6dcd34a0 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 1 Feb 2026 20:21:28 +0100 Subject: [PATCH] Differentiate messages in the log files if they are caused by an hardware issue --- cmdline/check.c | 102 +++++---- cmdline/device.c | 2 +- cmdline/dry.c | 32 +-- cmdline/elem.c | 46 ++-- cmdline/elem.h | 6 +- cmdline/handle.c | 54 ++--- cmdline/handle.h | 4 +- cmdline/import.c | 34 +-- cmdline/mingw.c | 76 +++--- cmdline/mktest.c | 64 +++--- cmdline/parity.c | 87 +++---- cmdline/parity.h | 2 +- cmdline/pool.c | 40 ++-- cmdline/portable.h | 11 + cmdline/rehash.c | 8 +- cmdline/scan.c | 124 +++++----- cmdline/scrub.c | 46 ++-- cmdline/search.c | 20 +- cmdline/selftest.c | 42 ++-- cmdline/snapraid.c | 82 +++---- cmdline/state.c | 534 +++++++++++++++++++++---------------------- cmdline/status.c | 2 +- cmdline/stream.c | 2 +- cmdline/support.c | 69 +++--- cmdline/support.h | 21 +- cmdline/sync.c | 142 ++++++------ cmdline/thermal.c | 4 +- cmdline/touch.c | 12 +- cmdline/unix.c | 88 +++---- cmdline/util.c | 6 +- doc/snapraid_log.1 | 22 +- doc/snapraid_log.d | 18 +- doc/snapraid_log.txt | 18 +- 33 files changed, 934 insertions(+), 886 deletions(-) diff --git a/cmdline/check.c b/cmdline/check.c index d336b206..bb76f9c5 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -42,13 +42,13 @@ static const char* es(int err) static void log_fatal_errno(int err, const char* name) { if (err == EIO) { - log_fatal("DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", name); } else if (err == EACCES) { - log_fatal("WARNING! Grant permission in the disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Grant permission in the disk %s. It isn't possible to continue.\n", name); } else if (err == ENOSPC) { - log_fatal("WARNING! Ensure there is free space on the disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Ensure there is free space on the disk %s. It isn't possible to continue.\n", name); } else { - log_fatal("WARNING! Without a working %s disk, it isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Without a working %s disk, it isn't possible to continue.\n", name); } } @@ -691,7 +691,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = rename(path, path_to); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error renaming '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); + log_fatal(errno, "Error renaming '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); log_tag("%s:%u:%s:%s: Rename error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; @@ -1080,7 +1080,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_START */ log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", i); + log_fatal(errno, "Stopping at block %u\n", i); ++unrecoverable_error; goto bail; @@ -1095,7 +1095,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_START */ log_tag("%s:%u:%s:%s: Create error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", i); + log_fatal(errno, "Stopping at block %u\n", i); ++unrecoverable_error; goto bail; @@ -1165,7 +1165,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna && !(state->opt.syncedonly && file_flag_has(file, FILE_IS_UNSYNCED)) && handle[j].st.st_size > file->size ) { - log_error("File '%s' is larger than expected.\n", handle[j].path); + log_error(ESOFT, "File '%s' is larger than expected.\n", handle[j].path); log_tag("error:%u:%s:%s: Size error\n", i, disk->name, esc_tag(file->sub, esc_buffer)); ++soft_error; @@ -1175,7 +1175,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_START */ log_tag("%s:%u:%s:%s: Truncate error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", i); + log_fatal(errno, "Stopping at block %u\n", i); ++unrecoverable_error; goto bail; @@ -1407,7 +1407,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_START */ log_tag("%s:%u:%s:%s: Write error. %s.\n", es(errno), i, failed[j].disk->name, esc_tag(failed[j].file->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, failed[j].disk->name); - log_fatal("Stopping at block %u\n", i); + log_fatal(errno, "Stopping at block %u\n", i); /* mark the file as damaged */ file_flag_set(failed[j].file, FILE_IS_DAMAGED); @@ -1457,7 +1457,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_START */ log_tag("%s:%u:%s: Write error. %s.\n", es(errno), i, lev_config_name(l), strerror(errno)); log_fatal_errno(errno, lev_config_name(l)); - log_fatal("Stopping at block %u\n", i); + log_fatal(errno, "Stopping at block %u\n", i); ++unrecoverable_error; goto bail; @@ -1493,7 +1493,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = file_post(state, fix, i, handle, diskmax); if (ret == -1) { /* LCOV_EXCL_START */ - log_fatal("Stopping at block %u\n", i); + log_fatal(errno, "Stopping at block %u\n", i); ++unrecoverable_error; goto bail; @@ -1562,7 +1562,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { unsuccessful = 1; - log_error("Error stating empty file '%s'. %s.\n", path, strerror(errno)); + log_error(errno, "Error stating empty file '%s'. %s.\n", path, strerror(errno)); log_tag("empty_%s:%s:%s: Empty file stat error\n", es(errno), disk->name, esc_tag(file->sub, esc_buffer)); if (errno == EIO) { @@ -1573,13 +1573,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } else if (!S_ISREG(st.st_mode)) { unsuccessful = 1; - log_error("Error stating empty file '%s' for not regular file.\n", path); + log_error(ESOFT, "Error stating empty file '%s' for not regular file.\n", path); log_tag("empty_error:%s:%s: Empty file error for not regular file\n", disk->name, esc_tag(file->sub, esc_buffer)); ++soft_error; } else if (st.st_size != 0) { unsuccessful = 1; - log_error("Error stating empty file '%s' for not empty file.\n", path); + log_error(ESOFT, "Error stating empty file '%s' for not empty file.\n", path); log_tag("empty_error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc_tag(file->sub, esc_buffer), (uint64_t)st.st_size); ++soft_error; } @@ -1591,10 +1591,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkancestor(path); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error creating ancestor '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); + log_fatal(errno, "Error creating ancestor '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); log_tag("empty_%s:%u:%s:%s: Create ancestor error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); ++unrecoverable_error; goto bail; @@ -1606,10 +1606,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna f = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_NOFOLLOW, 0600); if (f == -1) { /* LCOV_EXCL_START */ - log_fatal("Error creating '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); + log_fatal(errno, "Error creating '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); log_tag("empty_%s:%u:%s:%s: Create error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); ++unrecoverable_error; goto bail; @@ -1620,10 +1620,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = fmtime(f, file->mtime_sec, file->mtime_nsec); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error timing '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); + log_fatal(errno, "Error timing '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); log_tag("empty_%s:%u:%s:%s: Time error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); close(f); @@ -1636,10 +1636,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); + log_fatal(errno, "Error closing '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); log_tag("empty_%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); ++unrecoverable_error; goto bail; @@ -1682,7 +1682,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { unsuccessful = 1; - log_error("Error stating hardlink '%s'. %s.\n", path, strerror(errno)); + log_error(errno, "Error stating hardlink '%s'. %s.\n", path, strerror(errno)); log_tag("hardlink_%s:%s:%s:%s: Hardlink stat error. %s.\n", es(errno), disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt), strerror(errno)); if (errno == EIO) { @@ -1693,7 +1693,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } else if (!S_ISREG(st.st_mode)) { unsuccessful = 1; - log_error("Error stating hardlink '%s' for not regular file.\n", path); + log_error(ESOFT, "Error stating hardlink '%s' for not regular file.\n", path); log_tag("hardlink_error:%s:%s:%s: Hardlink error for not regular file\n", disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt)); ++soft_error; } @@ -1716,7 +1716,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } } - log_error("Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno)); + log_error(errno, "Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno)); log_tag("hardlink_%s:%s:%s:%s: Hardlink to stat error. %s.\n", es(errno), disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt), strerror(errno)); if (errno == EIO) { @@ -1727,13 +1727,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } else if (!S_ISREG(stto.st_mode)) { unsuccessful = 1; - log_error("Error stating hardlink-to '%s' for not regular file.\n", path); + log_error(ESOFT, "Error stating hardlink-to '%s' for not regular file.\n", path); log_tag("hardlink_error:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt)); ++soft_error; } else if (!unsuccessful && st.st_ino != stto.st_ino) { unsuccessful = 1; - log_error("Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto); + log_error(ESOFT, "Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto); log_tag("hardlink_error:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt)); ++soft_error; } @@ -1744,7 +1744,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret < 0) { unsuccessful = 1; - log_error("Error reading symlink '%s'. %s.\n", path, strerror(errno)); + log_error(errno, "Error reading symlink '%s'. %s.\n", path, strerror(errno)); log_tag("symlink_%s:%s:%s: Symlink read error. %s.\n", es(errno), disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); if (errno == EIO) { @@ -1755,7 +1755,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } else if (ret >= PATH_MAX) { unsuccessful = 1; - log_error("Error reading symlink '%s'. Symlink too long.\n", path); + log_error(ESOFT, "Error reading symlink '%s'. Symlink too long.\n", path); log_tag("symlink_error:%s:%s: Symlink too long\n", disk->name, esc_tag(slink->sub, esc_buffer)); ++soft_error; } else { @@ -1777,10 +1777,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkancestor(path); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error creating ancestor '%s%s'. %s.\n", disk->dir, slink->sub, strerror(errno)); + log_fatal(errno, "Error creating ancestor '%s%s'. %s.\n", disk->dir, slink->sub, strerror(errno)); log_tag("%slink_%s:%u:%s:%s: Create ancestor error. %s.\n", link, es(errno), i, disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); ++unrecoverable_error; goto bail; @@ -1791,10 +1791,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = remove(path); if (ret != 0 && errno != ENOENT) { /* LCOV_EXCL_START */ - log_fatal("Error removing '%s%s'. %s.\n", disk->dir, slink->sub, strerror(errno)); + log_fatal(errno, "Error removing '%s%s'. %s.\n", disk->dir, slink->sub, strerror(errno)); log_tag("%slink_%s:%u:%s:%s: Remove error. %s.\n", link, es(errno), i, disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); ++unrecoverable_error; goto bail; @@ -1806,10 +1806,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = hardlink(pathto, path); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno)); + log_fatal(errno, "Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno)); log_tag("hardlink_%s:%u:%s:%s: Hardlink error. %s.\n", es(errno), i, disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); ++unrecoverable_error; goto bail; @@ -1822,10 +1822,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = symlink(slink->linkto, path); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error writing symlink '%s' to '%s'. %s.\n", path, slink->linkto, strerror(errno)); + log_fatal(errno, "Error writing symlink '%s' to '%s'. %s.\n", path, slink->linkto, strerror(errno)); log_tag("symlink_%s:%u:%s:%s: Hardlink error. %s.\n", es(errno), i, disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); ++unrecoverable_error; goto bail; @@ -1864,7 +1864,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { unsuccessful = 1; - log_error("Error stating dir '%s'. %s.\n", path, strerror(errno)); + log_error(errno, "Error stating dir '%s'. %s.\n", path, strerror(errno)); log_tag("dir_%s:%s:%s: Dir stat error. %s.\n", es(errno), disk->name, esc_tag(dir->sub, esc_buffer), strerror(errno)); if (errno == EIO) { @@ -1884,10 +1884,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkancestor(path); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error creating ancestor '%s%s'. %s.\n", disk->dir, dir->sub, strerror(errno)); + log_fatal(errno, "Error creating ancestor '%s%s'. %s.\n", disk->dir, dir->sub, strerror(errno)); log_tag("dir_%s:%u:%s:%s: Create ancestor error. %s.\n", es(errno), i, disk->name, esc_tag(dir->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); ++unrecoverable_error; goto bail; @@ -1898,10 +1898,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error creating directory '%s%s'. %s.\n", disk->dir, dir->sub, strerror(errno)); + log_fatal(errno, "Error creating directory '%s%s'. %s.\n", disk->dir, dir->sub, strerror(errno)); log_tag("dir_%s:%u:%s:%s: Create directory error. %s.\n", es(errno), i, disk->name, esc_tag(dir->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping\n"); + log_fatal(errno, "Stopping\n"); ++unrecoverable_error; goto bail; @@ -1978,7 +1978,7 @@ bail: ret = remove(path); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error removing '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error removing '%s'. %s.\n", path, strerror(errno)); log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockmax, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); @@ -2011,10 +2011,16 @@ bail: msg_status("Everything OK\n"); } - if ((soft_error || io_error || silent_error) && !fix) - log_fatal("WARNING! There are errors!\n"); + if ((soft_error || io_error || silent_error) && !fix) { + if (soft_error) + log_fatal(ESOFT, "WARNING! There are soft errors!\n"); + if (io_error) + log_fatal(EIO, "DANGER! Unexpected input/output errors!\n"); + if (silent_error) + log_fatal(EDATA, "DANGER! Unexpected silent data errors!\n"); + } if (unrecoverable_error) - log_fatal("DANGER! Unrecoverable errors detected!\n"); + log_fatal(ESOFT, "DANGER! Unrecoverable errors detected!\n"); log_tag("summary:error_soft:%u\n", soft_error); log_tag("summary:error_io:%u\n", io_error); @@ -2100,7 +2106,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b if (blockstart > blockmax) { /* LCOV_EXCL_START */ - log_fatal("Error in the specified starting block %u. It's larger than the parity size %u.\n", blockstart, blockmax); + log_fatal(EUSER, "Error in the specified starting block %u. It's larger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/device.c b/cmdline/device.c index 8aa55887..7dbc98a6 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -1013,7 +1013,7 @@ void state_device(struct snapraid_state* state, int operation, tommy_list* filte case DEVICE_PROBE : ope = "Probe"; break; case DEVICE_DOWNIFUP : ope = "Spindown"; break; } - log_fatal("%s is unsupported in this platform.\n", ope); + log_fatal(ESOFT, "%s is unsupported in this platform.\n", ope); } else { if (operation == DEVICE_LIST) { for (i = tommy_list_head(&low); i != 0; i = i->next) { diff --git a/cmdline/dry.c b/cmdline/dry.c index bd4669d1..1c62701d 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -39,20 +39,20 @@ static const char* es(int err) static void log_fatal_errno(int err, const char* name) { if (err == EIO) { - log_fatal("DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", name); } else if (err == EACCES) { - log_fatal("WARNING! Grant permission in the disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Grant permission in the disk %s. It isn't possible to continue.\n", name); } else if (err == ENOSPC) { - log_fatal("WARNING! Ensure there is free space on the disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Ensure there is free space on the disk %s. It isn't possible to continue.\n", name); } else { - log_fatal("WARNING! Without a working %s disk, it isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Without a working %s disk, it isn't possible to continue.\n", name); } } static void log_error_errno(int err, const char* name) { if (err == EIO) { - log_fatal("DANGER! Unexpected input/output error in disk %s.\n", name); + log_fatal(err, "DANGER! Unexpected input/output error in disk %s.\n", name); } } @@ -100,7 +100,7 @@ static void dry_data_reader(struct snapraid_worker* worker, struct snapraid_task /* and closing a descriptor should never fail */ log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); if (errno == EIO) { task->state = TASK_STATE_IOERROR; @@ -118,7 +118,7 @@ static void dry_data_reader(struct snapraid_worker* worker, struct snapraid_task if (errno == EIO) { /* LCOV_EXCL_START */ log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); task->state = TASK_STATE_IOERROR; return; /* LCOV_EXCL_STOP */ @@ -290,8 +290,8 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit ++io_error; if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", disk->dir); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(EIO, "DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", disk->dir); + log_fatal(EIO, "Stopping at block %u\n", blockcur); goto bail; /* LCOV_EXCL_STOP */ } @@ -301,7 +301,7 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit } if (task->state != TASK_STATE_DONE) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in task state\n"); + log_fatal(EINTERNAL, "Internal inconsistency in task state\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -343,8 +343,8 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit ++io_error; if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", lev_name(levcur)); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(EIO, "DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", lev_name(levcur)); + log_fatal(EIO, "Stopping at block %u\n", blockcur); goto bail; /* LCOV_EXCL_STOP */ } @@ -352,7 +352,7 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit } if (task->state != TASK_STATE_DONE) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in task state\n"); + log_fatal(EINTERNAL, "Internal inconsistency in task state\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -421,9 +421,9 @@ bail: } if (soft_error) - log_fatal("DANGER! Unexpected errors!\n"); + log_fatal(ESOFT, "DANGER! Unexpected errors!\n"); if (io_error) - log_fatal("DANGER! Unexpected input/output errors!\n"); + log_fatal(EIO, "DANGER! Unexpected input/output errors!\n"); log_tag("summary:error_soft:%u\n", soft_error); log_tag("summary:error_io:%u\n", io_error); @@ -456,7 +456,7 @@ int state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t if (blockstart > blockmax) { /* LCOV_EXCL_START */ - log_fatal("Error in the specified starting block %u. It's larger than the parity size %u.\n", blockstart, blockmax); + log_fatal(EUSER, "Error in the specified starting block %u. It's larger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/elem.c b/cmdline/elem.c index 3c801872..2abaa5f3 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -293,7 +293,7 @@ int filter_existence(int filter_missing, const char* dir, const char* sub) if (errno == ENOENT) return 0; /* LCOV_EXCL_START */ - log_fatal("Error in stat file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error in stat file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -420,21 +420,21 @@ void file_copy(struct snapraid_file* src_file, struct snapraid_file* dst_file) if (src_file->size != dst_file->size) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Copy file with different size\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Copy file with different size\n"); os_abort(); /* LCOV_EXCL_STOP */ } if (src_file->mtime_sec != dst_file->mtime_sec) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Copy file with different mtime_sec\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Copy file with different mtime_sec\n"); os_abort(); /* LCOV_EXCL_STOP */ } if (src_file->mtime_nsec != dst_file->mtime_nsec) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Copy file with different mtime_nsec\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Copy file with different mtime_nsec\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -484,7 +484,7 @@ int file_block_is_last(struct snapraid_file* file, block_off_t file_pos) if (file_pos >= file->blockmax) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: File block position over the max\n"); + log_fatal(EINTERNAL, "Internal inconsistency: File block position over the max\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -605,13 +605,13 @@ struct snapraid_extent* extent_alloc(block_off_t parity_pos, struct snapraid_fil if (count == 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Allocating empty extent for file '%s' at position '%u/%u'\n", file->sub, file_pos, file->blockmax); + log_fatal(EINTERNAL, "Internal inconsistency: Allocating empty extent for file '%s' at position '%u/%u'\n", file->sub, file_pos, file->blockmax); os_abort(); /* LCOV_EXCL_STOP */ } if (file_pos + count > file->blockmax) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Allocating overflowing extent for file '%s' at position '%u:%u/%u'\n", file->sub, file_pos, count, file->blockmax); + log_fatal(EINTERNAL, "Internal inconsistency: Allocating overflowing extent for file '%s' at position '%u:%u/%u'\n", file->sub, file_pos, count, file->blockmax); os_abort(); /* LCOV_EXCL_STOP */ } @@ -928,7 +928,7 @@ static void extent_parity_check_foreach_unlock(void* void_arg, void* void_obj) if (obj->count == 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Parity count zero for file '%s' at '%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: Parity count zero for file '%s' at '%u'\n", obj->file->sub, obj->parity_pos); ++arg->result; return; @@ -942,7 +942,7 @@ static void extent_parity_check_foreach_unlock(void* void_arg, void* void_obj) /* check the order */ if (prev->parity_pos >= obj->parity_pos) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Parity order for files '%s' at '%u:%u' and '%s' at '%u:%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: Parity order for files '%s' at '%u:%u' and '%s' at '%u:%u'\n", prev->file->sub, prev->parity_pos, prev->count, obj->file->sub, obj->parity_pos, obj->count); ++arg->result; return; @@ -952,7 +952,7 @@ static void extent_parity_check_foreach_unlock(void* void_arg, void* void_obj) /* check that the extents don't overlap */ if (prev->parity_pos + prev->count > obj->parity_pos) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Parity overlap for files '%s' at '%u:%u' and '%s' at '%u:%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: Parity overlap for files '%s' at '%u:%u' and '%s' at '%u:%u'\n", prev->file->sub, prev->parity_pos, prev->count, obj->file->sub, obj->parity_pos, obj->count); ++arg->result; return; @@ -978,7 +978,7 @@ static void extent_file_check_foreach_unlock(void* void_arg, void* void_obj) if (obj->count == 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: File count zero for file '%s' at '%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: File count zero for file '%s' at '%u'\n", obj->file->sub, obj->file_pos); ++arg->result; return; @@ -994,7 +994,7 @@ static void extent_file_check_foreach_unlock(void* void_arg, void* void_obj) /* check that the extent doesn't overflow the file */ if (prev->file_pos + prev->count > prev->file->blockmax) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Delete end for file '%s' at '%u:%u' overflowing size '%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: Delete end for file '%s' at '%u:%u' overflowing size '%u'\n", prev->file->sub, prev->file_pos, prev->count, prev->file->blockmax); ++arg->result; return; @@ -1004,7 +1004,7 @@ static void extent_file_check_foreach_unlock(void* void_arg, void* void_obj) /* check that the extent ends the file */ if (prev->file_pos + prev->count != prev->file->blockmax) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: File end for file '%s' at '%u:%u' instead of size '%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: File end for file '%s' at '%u:%u' instead of size '%u'\n", prev->file->sub, prev->file_pos, prev->count, prev->file->blockmax); ++arg->result; return; @@ -1017,7 +1017,7 @@ static void extent_file_check_foreach_unlock(void* void_arg, void* void_obj) /* check that the extent doesn't overflow the file */ if (obj->file_pos + obj->count > obj->file->blockmax) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Delete start for file '%s' at '%u:%u' overflowing size '%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: Delete start for file '%s' at '%u:%u' overflowing size '%u'\n", obj->file->sub, obj->file_pos, obj->count, obj->file->blockmax); ++arg->result; return; @@ -1027,7 +1027,7 @@ static void extent_file_check_foreach_unlock(void* void_arg, void* void_obj) /* check that the extent starts the file */ if (obj->file_pos != 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: File start for file '%s' at '%u:%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: File start for file '%s' at '%u:%u'\n", obj->file->sub, obj->file_pos, obj->count); ++arg->result; return; @@ -1038,7 +1038,7 @@ static void extent_file_check_foreach_unlock(void* void_arg, void* void_obj) /* check the order */ if (prev->file_pos >= obj->file_pos) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: File order for file '%s' at '%u:%u' and at '%u:%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: File order for file '%s' at '%u:%u' and at '%u:%u'\n", prev->file->sub, prev->file_pos, prev->count, obj->file_pos, obj->count); ++arg->result; return; @@ -1049,7 +1049,7 @@ static void extent_file_check_foreach_unlock(void* void_arg, void* void_obj) /* check that the extents don't overlap */ if (prev->file_pos + prev->count > obj->file_pos) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Delete sequence for file '%s' at '%u:%u' and at '%u:%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: Delete sequence for file '%s' at '%u:%u' and at '%u:%u'\n", prev->file->sub, prev->file_pos, prev->count, obj->file_pos, obj->count); ++arg->result; return; @@ -1059,7 +1059,7 @@ static void extent_file_check_foreach_unlock(void* void_arg, void* void_obj) /* check that the extents are sequential */ if (prev->file_pos + prev->count != obj->file_pos) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: File sequence for file '%s' at '%u:%u' and at '%u:%u'\n", + log_fatal(EINTERNAL, "Internal inconsistency: File sequence for file '%s' at '%u:%u' and at '%u:%u'\n", prev->file->sub, prev->file_pos, prev->count, obj->file_pos, obj->count); ++arg->result; return; @@ -1257,7 +1257,7 @@ void fs_allocate(struct snapraid_disk* disk, block_off_t parity_pos, struct snap /* ensure that we are extending the extent at the end */ if (file_pos != extent->file_pos + extent->count) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Allocating file '%s' at position '%u/%u' in the middle of extent '%u:%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, extent->file_pos, extent->count, disk->name); + log_fatal(EINTERNAL, "Internal inconsistency: Allocating file '%s' at position '%u/%u' in the middle of extent '%u:%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, extent->file_pos, extent->count, disk->name); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1279,7 +1279,7 @@ void fs_allocate(struct snapraid_disk* disk, block_off_t parity_pos, struct snap if (parity_extent != extent || file_extent != extent) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Allocating file '%s' at position '%u/%u' for existing extent '%u:%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, extent->file_pos, extent->count, disk->name); + log_fatal(EINTERNAL, "Internal inconsistency: Allocating file '%s' at position '%u/%u' for existing extent '%u:%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, extent->file_pos, extent->count, disk->name); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1303,7 +1303,7 @@ void fs_deallocate(struct snapraid_disk* disk, block_off_t parity_pos) extent = fs_par2extent_get_unlock(disk, &disk->fs_last, parity_pos); if (!extent) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Deallocating parity position '%u' for not existing extent in disk '%s'\n", parity_pos, disk->name); + log_fatal(EINTERNAL, "Internal inconsistency: Deallocating parity position '%u' for not existing extent in disk '%s'\n", parity_pos, disk->name); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1358,7 +1358,7 @@ void fs_deallocate(struct snapraid_disk* disk, block_off_t parity_pos) if (parity_extent != second_extent || file_extent != second_extent) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Deallocating parity position '%u' for splitting extent '%u:%u' in disk '%s'\n", parity_pos, second_extent->file_pos, second_extent->count, disk->name); + log_fatal(EINTERNAL, "Internal inconsistency: Deallocating parity position '%u' for splitting extent '%u:%u' in disk '%s'\n", parity_pos, second_extent->file_pos, second_extent->count, disk->name); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1373,7 +1373,7 @@ struct snapraid_block* fs_file2block_get(struct snapraid_file* file, block_off_t { if (file_pos >= file->blockmax) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Dereferencing file '%s' at position '%u/%u'\n", file->sub, file_pos, file->blockmax); + log_fatal(EINTERNAL, "Internal inconsistency: Dereferencing file '%s' at position '%u/%u'\n", file->sub, file_pos, file->blockmax); os_abort(); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/elem.h b/cmdline/elem.h index 697f71a1..f8381aa5 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -1062,7 +1062,7 @@ static inline struct snapraid_file* fs_par2file_get(struct snapraid_disk* disk, ret = fs_par2file_find(disk, parity_pos, file_pos); if (ret == 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Deresolving parity to file at position '%u' in disk '%s'\n", parity_pos, disk->name); + log_fatal(EINTERNAL, "Internal inconsistency: Deresolving parity to file at position '%u' in disk '%s'\n", parity_pos, disk->name); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1086,7 +1086,7 @@ static inline block_off_t fs_file2par_get(struct snapraid_disk* disk, struct sna ret = fs_file2par_find(disk, file, file_pos); if (ret == POS_NULL) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Resolving file '%s' at position '%u/%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, disk->name); + log_fatal(EINTERNAL, "Internal inconsistency: Resolving file '%s' at position '%u/%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, disk->name); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1110,7 +1110,7 @@ static inline struct snapraid_block* fs_par2block_get(struct snapraid_disk* disk ret = fs_par2block_find(disk, parity_pos); if (ret == BLOCK_NULL) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Deresolving parity to block at position '%u' in disk '%s'\n", parity_pos, disk->name); + log_fatal(EINTERNAL, "Internal inconsistency: Deresolving parity to block at position '%u' in disk '%s'\n", parity_pos, disk->name); os_abort(); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/handle.c b/cmdline/handle.c index b1a25064..bc36eeaa 100644 --- a/cmdline/handle.c +++ b/cmdline/handle.c @@ -88,7 +88,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in handle->f = -1; handle->valid_size = 0; - log_fatal("Error opening file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal(errno, "Error opening file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -100,7 +100,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in ret = fstat(handle->f, &handle->st); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal(errno, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -111,7 +111,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in ret = advise_open(&handle->advise, handle->f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error advising file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal(errno, "Error advising file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -127,9 +127,9 @@ int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file) if (ret != 0) { /* LCOV_EXCL_START */ if (errno == EACCES) { - log_fatal("Failed to truncate file '%s' for missing write permission.\n", handle->path); + log_fatal(errno, "Failed to truncate file '%s' for missing write permission.\n", handle->path); } else { - log_fatal("Error truncating file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal(errno, "Error truncating file '%s'. %s.\n", handle->path, strerror(errno)); } return -1; /* LCOV_EXCL_STOP */ @@ -141,7 +141,7 @@ int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file) return 0; } -int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out, fptr* out_missing) +int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, log_ptr* out, log_ptr* out_missing) { int ret; int flags; @@ -174,11 +174,11 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int handle->valid_size = 0; if (errno == ENOENT) - out_missing("Missing file '%s'.\n", handle->path); + out_missing(errno, "Missing file '%s'.\n", handle->path); else if (errno == EACCES) - out("Permission denied for file '%s'.\n", handle->path); + out(errno, "Permission denied for file '%s'.\n", handle->path); else - out("Error opening file '%s'. %s.\n", handle->path, strerror(errno)); + out(errno, "Error opening file '%s'. %s.\n", handle->path, strerror(errno)); return -1; } @@ -189,7 +189,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int ret = fstat(handle->f, &handle->st); if (ret != 0) { /* LCOV_EXCL_START */ - out("Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); + out(errno, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -200,7 +200,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int ret = advise_open(&handle->advise, handle->f); if (ret != 0) { /* LCOV_EXCL_START */ - out("Error advising file '%s'. %s.\n", handle->path, strerror(errno)); + out(errno, "Error advising file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -217,7 +217,7 @@ int handle_close(struct snapraid_handle* handle) ret = close(handle->f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file '%s'. %s.\n", handle->file->sub, strerror(errno)); + log_fatal(errno, "Error closing file '%s'. %s.\n", handle->file->sub, strerror(errno)); /* invalidate for error */ handle->file = 0; @@ -236,7 +236,7 @@ int handle_close(struct snapraid_handle* handle) return 0; } -int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, fptr* out, fptr* out_missing) +int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, log_ptr* out, log_ptr* out_missing) { ssize_t read_ret; data_off_t offset; @@ -253,15 +253,15 @@ int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned c if (offset >= handle->valid_size) { /* if the file is missing, it's at 0 size, or it's rebuilt while reading */ if (offset == handle->valid_size || handle->valid_size == 0) { - if (offset == 0) { - out_missing("Missing file '%s'.\n", handle->path); - } else { - out_missing("Missing data in file '%s' at offset %" PRIu64 ".\n", handle->path, offset); - } errno = ENOENT; + if (offset == 0) { + out_missing(errno, "Missing file '%s'.\n", handle->path); + } else { + out_missing(errno, "Missing data in file '%s' at offset %" PRIu64 ".\n", handle->path, offset); + } } else { - out("Reading over the end from file '%s' at offset %" PRIu64 ".\n", handle->path, offset); errno = ENXIO; + out(errno, "Reading over the end from file '%s' at offset %" PRIu64 ".\n", handle->path, offset); } return -1; } @@ -276,15 +276,15 @@ int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned c read_ret = pread(handle->f, block_buffer + count, block_size - count, offset + count); if (read_ret == -1) { /* LCOV_EXCL_START */ - out("Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", handle->path, offset + count, block_size - count, strerror(errno)); + out(errno, "Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", handle->path, offset + count, block_size - count, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } if (read_ret == 0) { /* LCOV_EXCL_START */ - out("Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno)); if (errno == 0) errno = ENXIO; + out(errno, "Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -300,7 +300,7 @@ int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned c ret = advise_read(&handle->advise, handle->f, offset, block_size); if (ret != 0) { /* LCOV_EXCL_START */ - out("Error advising file '%s'. %s.\n", handle->path, strerror(errno)); + out(errno, "Error advising file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -327,14 +327,14 @@ int handle_write(struct snapraid_handle* handle, block_off_t file_pos, unsigned write_ret = pwrite(handle->f, block_buffer + count, write_size - count, offset + count); if (write_ret == -1) { /* LCOV_EXCL_START */ - log_fatal("Error writing file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal(errno, "Error writing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } if (write_ret == 0) { /* LCOV_EXCL_START */ - log_fatal("Unexpected 0 write to file '%s'. %s.\n", handle->path, strerror(errno)); errno = ENXIO; + log_fatal(errno, "Unexpected 0 write to file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -350,7 +350,7 @@ int handle_write(struct snapraid_handle* handle, block_off_t file_pos, unsigned ret = advise_write(&handle->advise, handle->f, offset, block_size); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error advising file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal(errno, "Error advising file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -370,7 +370,7 @@ int handle_utime(struct snapraid_handle* handle) if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error timing file '%s'. %s.\n", handle->file->sub, strerror(errno)); + log_fatal(errno, "Error timing file '%s'. %s.\n", handle->file->sub, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -420,7 +420,7 @@ struct snapraid_handle* handle_mapping(struct snapraid_state* state, unsigned* h } if (!map) { /* LCOV_EXCL_START */ - log_fatal("Internal error for inconsistent disk mapping.\n"); + log_fatal(EINTERNAL, "Internal error for inconsistent disk mapping.\n"); os_abort(); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/handle.h b/cmdline/handle.h index 570e5f5f..a69f7258 100644 --- a/cmdline/handle.h +++ b/cmdline/handle.h @@ -56,7 +56,7 @@ int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file); * Open a file. * The file is opened for reading. */ -int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out, fptr* out_missing); +int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, log_ptr* out, log_ptr* out_missing); /** * Close a file. @@ -67,7 +67,7 @@ int handle_close(struct snapraid_handle* handle); * Read a block from a file. * If the read block is shorter, it's padded with 0. */ -int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, fptr* out, fptr* out_missing); +int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, log_ptr* out, log_ptr* out_missing); /** * Write a block to a file. diff --git a/cmdline/import.c b/cmdline/import.c index 91d42c51..cb42d7d0 100644 --- a/cmdline/import.c +++ b/cmdline/import.c @@ -79,7 +79,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t f = open(path, flags); if (f == -1) { /* LCOV_EXCL_START */ - log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error opening file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -87,7 +87,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t ret = advise_open(&advise, f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error advising file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error advising file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -102,7 +102,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t ret = read(f, buffer, read_size); if (ret < 0 || (unsigned)ret != read_size) { /* LCOV_EXCL_START */ - log_fatal("Error reading file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error reading file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -128,7 +128,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -171,10 +171,10 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid if (f == -1) { /* LCOV_EXCL_START */ if (errno == ENOENT) { - log_fatal("DANGER! file '%s' disappeared.\n", path); - log_fatal("If you moved it, please rerun the same command.\n"); + log_fatal(errno, "DANGER! file '%s' disappeared.\n", path); + log_fatal(errno, "If you moved it, please rerun the same command.\n"); } else { - log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error opening file '%s'. %s.\n", path, strerror(errno)); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -183,7 +183,7 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid ret = pread(f, buffer, read_size, block->offset); if (ret < 0 || (unsigned)ret != read_size) { /* LCOV_EXCL_START */ - log_fatal("Error reading file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error reading file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -191,7 +191,7 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -209,8 +209,8 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid if (memcmp(buffer_hash, hash, BLOCK_HASH_SIZE) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in data reading file '%s'.\n", path); - log_fatal("Please don't change imported files while running.\n"); + log_fatal(EUSER, "Mismatch in data reading file '%s'.\n", path); + log_fatal(EUSER, "Please don't change imported files while running.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -225,7 +225,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - log_fatal("Error opening directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error opening directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -241,7 +241,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - log_fatal("Error reading directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error reading directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -268,7 +268,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) if (st.st_mode == 0) { if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -277,7 +277,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) /* get lstat info about the file */ if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -293,7 +293,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) if (closedir(d) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error closing directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -308,7 +308,7 @@ void state_import(struct snapraid_state* state, const char* dir) /* if the hash is not full */ if (BLOCK_HASH_SIZE != HASH_MAX) { /* LCOV_EXCL_START */ - log_fatal("You cannot import files when using a reduced hash.\n"); + log_fatal(EUSER, "You cannot import files when using a reduced hash.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/mingw.c b/cmdline/mingw.c index 9cf8a886..8f866cc7 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -132,31 +132,31 @@ void os_init(int opt) /* initialize the thread local storage for strerror(), using free() as destructor */ if (windows_key_create(&last_error, free) != 0) { - log_fatal("Error calling windows_key_create().\n"); + log_fatal(EEXTERNAL, "Error calling windows_key_create().\n"); exit(EXIT_FAILURE); } tick_last = 0; if (windows_mutex_init(&tick_lock, 0) != 0) { - log_fatal("Error calling windows_mutex_init().\n"); + log_fatal(EEXTERNAL, "Error calling windows_mutex_init().\n"); exit(EXIT_FAILURE); } ntdll = GetModuleHandle("NTDLL.DLL"); if (!ntdll) { - log_fatal("Error loading the NTDLL module.\n"); + log_fatal(EEXTERNAL, "Error loading the NTDLL module.\n"); exit(EXIT_FAILURE); } kernel32 = GetModuleHandle("KERNEL32.DLL"); if (!kernel32) { - log_fatal("Error loading the KERNEL32 module.\n"); + log_fatal(EEXTERNAL, "Error loading the KERNEL32 module.\n"); exit(EXIT_FAILURE); } dll_advapi32 = LoadLibrary("ADVAPI32.DLL"); if (!dll_advapi32) { - log_fatal("Error loading the ADVAPI32 module.\n"); + log_fatal(EEXTERNAL, "Error loading the ADVAPI32 module.\n"); exit(EXIT_FAILURE); } @@ -260,7 +260,7 @@ static wchar_t* u8tou16(wchar_t* conv_buf, const char* src) ret = MultiByteToWideChar(CP_UTF8, 0, src, -1, conv_buf, CONV_MAX); if (ret <= 0) { - log_fatal("Error converting name '%s' from UTF-8 to UTF-16\n", src); + log_fatal(EINTERNAL, "Error converting name '%s' from UTF-8 to UTF-16\n", src); exit(EXIT_FAILURE); } @@ -276,7 +276,7 @@ static char* u16tou8ex(char* conv_buf, const wchar_t* src, size_t number_of_wcha ret = WideCharToMultiByte(CP_UTF8, 0, src, number_of_wchar, conv_buf, CONV_MAX, 0, 0); if (ret <= 0) { - log_fatal("Error converting from UTF-16 to UTF-8\n"); + log_fatal(EINTERNAL, "Error converting from UTF-16 to UTF-8\n"); exit(EXIT_FAILURE); } @@ -368,7 +368,7 @@ static wchar_t* convert_arg(wchar_t* conv_buf, const char* src, int only_if_requ ret = MultiByteToWideChar(CP_UTF8, 0, src, -1, dst, CONV_MAX - count); if (ret <= 0) { - log_fatal("Error converting name '%s' from UTF-8 to UTF-16\n", src); + log_fatal(EINTERNAL, "Error converting name '%s' from UTF-8 to UTF-16\n", src); exit(EXIT_FAILURE); } @@ -528,8 +528,8 @@ static int windows_info2stat(const BY_HANDLE_FILE_INFORMATION* info, const FILE_ * "FILE_INVALID_FILE_ID, the identifier may only be described in 128 bit form." */ if (st->st_ino == (uint64_t)FILE_INVALID_FILE_ID) { - log_fatal("Invalid inode number! Is this ReFS?\n"); errno = EINVAL; + log_fatal(errno, "Invalid inode number! Is this ReFS?\n"); return -1; } @@ -573,8 +573,8 @@ static int windows_stream2stat(const BY_HANDLE_FILE_INFORMATION* info, const FIL /* in ReFS the IDs are 128 bit, and the 64 bit interface may fail */ if (st->st_ino == (uint64_t)FILE_INVALID_FILE_ID) { - log_fatal("Invalid inode number! Is this ReFS?\n"); errno = EINVAL; + log_fatal(errno, "Invalid inode number! Is this ReFS?\n"); return -1; } @@ -630,7 +630,7 @@ static void windows_finddata2dirent(const WIN32_FIND_DATAW* info, struct windows name = u16tou8ex(conv_buf, info->cFileName, wcslen(info->cFileName), &len); if (len + 1 >= sizeof(dirent->d_name)) { - log_fatal("Name too long\n"); + log_fatal(EINTERNAL, "Name too long\n"); exit(EXIT_FAILURE); } @@ -649,7 +649,7 @@ static int windows_stream2dirent(const BY_HANDLE_FILE_INFORMATION* info, const F name = u16tou8ex(conv_buf, stream->FileName, stream->FileNameLength / 2, &len); if (len + 1 >= sizeof(dirent->d_name)) { - log_fatal("Name too long\n"); + log_fatal(EINTERNAL, "Name too long\n"); exit(EXIT_FAILURE); } @@ -707,8 +707,8 @@ static void windows_errno(DWORD error) errno = EIO; break; default : - log_fatal("Unexpected Windows error %lu.\n", error); - errno = EIO; + errno = ENXIO; + log_fatal(errno, "Unexpected Windows error %lu.\n", error); break; } } @@ -1021,11 +1021,9 @@ int windows_fsync(int fd) * this error, but not enough sure to ignore it. * So, we use now an extended error reporting. */ - log_fatal("Unexpected Windows INVALID_HANDLE error in FlushFileBuffers().\n"); - log_fatal("Are you using ATA-over-Ethernet ? Please report it.\n"); - - /* normal error processing */ windows_errno(error); + log_fatal(errno, "Unexpected Windows INVALID_HANDLE error in FlushFileBuffers().\n"); + log_fatal(errno, "Are you using ATA-over-Ethernet ? Please report it.\n"); return -1; case ERROR_ACCESS_DENIED : @@ -1080,11 +1078,9 @@ static int windows_vsync(const wchar_t* volume) * this error, but not enough sure to ignore it. * So, we use now an extended error reporting. */ - log_fatal("Unexpected Windows INVALID_HANDLE error in FlushFileBuffers().\n"); - log_fatal("Are you using ATA-over-Ethernet ? Please report it.\n"); - - /* normal error processing */ windows_errno(error); + log_fatal(errno, "Unexpected Windows INVALID_HANDLE error in FlushFileBuffers().\n"); + log_fatal(errno, "Are you using ATA-over-Ethernet ? Please report it.\n"); return -1; case ERROR_ACCESS_DENIED : @@ -1443,7 +1439,7 @@ static windows_dir* windows_opendir_find(const char* dir) dirstream = malloc(sizeof(windows_dir)); if (!dirstream) { - log_fatal("Low memory\n"); + log_fatal(EFAULT, "Low memory\n"); exit(EXIT_FAILURE); } @@ -1577,7 +1573,7 @@ static windows_dir* windows_opendir_stream(const char* dir) dirstream = malloc(sizeof(windows_dir)); if (!dirstream) { - log_fatal("Low memory\n"); + log_fatal(EFAULT, "Low memory\n"); exit(EXIT_FAILURE); } @@ -1587,7 +1583,7 @@ static windows_dir* windows_opendir_stream(const char* dir) dirstream->buffer_size = 64 * 1024; dirstream->buffer = malloc(dirstream->buffer_size); if (!dirstream->buffer) { - log_fatal("Low memory\n"); + log_fatal(EFAULT, "Low memory\n"); exit(EXIT_FAILURE); } @@ -2148,7 +2144,7 @@ retry: * https://sourceforge.net/p/snapraid/discussion/1677233/thread/a7c25ba9/ */ if (err == ERROR_NO_SYSTEM_RESOURCES) { - log_fatal("Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pread(), retrying...\n"); + log_fatal(EEXTERNAL, "Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pread(), retrying...\n"); Sleep(50); goto retry; } @@ -2186,7 +2182,7 @@ retry: DWORD err = GetLastError(); /* See windows_pread() for comments on this error management */ if (err == ERROR_NO_SYSTEM_RESOURCES) { - log_fatal("Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pwrite(), retrying...\n"); + log_fatal(EEXTERNAL, "Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pwrite(), retrying...\n"); Sleep(50); goto retry; } @@ -2475,7 +2471,7 @@ static int devscan(tommy_list* list) f = _wpopen(cmd, L"rt"); if (!f) { /* LCOV_EXCL_START */ - log_fatal("Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); + log_fatal(errno, "Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2493,13 +2489,13 @@ static int devscan(tommy_list* list) if (ret == -1) { /* LCOV_EXCL_START */ - log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); + log_fatal(errno, "Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to run '%s' with return code %xh.\n", u16tou8(conv_buf, cmd), ret); + log_fatal(errno, "Failed to run '%s' with return code %xh.\n", u16tou8(conv_buf, cmd), ret); return -1; /* LCOV_EXCL_STOP */ } @@ -2539,7 +2535,7 @@ retry: if (!f) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); + log_fatal(errno, "Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2559,7 +2555,7 @@ retry: if (ret == -1) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); + log_fatal(errno, "Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2771,7 +2767,7 @@ retry: if (!f) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); + log_fatal(errno, "Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2791,7 +2787,7 @@ retry: if (ret == -1) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); + log_fatal(errno, "Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2861,7 +2857,7 @@ retry: if (!f) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); + log_fatal(errno, "Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2881,7 +2877,7 @@ retry: if (ret == -1) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); + log_fatal(errno, "Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2908,7 +2904,7 @@ retry: if (ret != 0) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:exit:%d\n", file, name, ret); - log_fatal("Failed to run '%s' with return code %xh.\n", u16tou8(conv_buf, cmd), ret); + log_fatal(errno, "Failed to run '%s' with return code %xh.\n", u16tou8(conv_buf, cmd), ret); return -1; /* LCOV_EXCL_STOP */ } @@ -3157,7 +3153,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation, int others) if (devresolve(devinfo->mount, devinfo->file, sizeof(devinfo->file), devinfo->wfile, sizeof(devinfo->wfile)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to resolve path '%s'.\n", devinfo->mount); + log_fatal(EEXTERNAL, "Failed to resolve path '%s'.\n", devinfo->mount); return -1; /* LCOV_EXCL_STOP */ } @@ -3165,7 +3161,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation, int others) /* expand the tree of devices */ if (devtree(devinfo, low) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to expand device '%s'.\n", devinfo->file); + log_fatal(EEXTERNAL, "Failed to expand device '%s'.\n", devinfo->file); return -1; /* LCOV_EXCL_STOP */ } @@ -3175,7 +3171,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation, int others) if (others) { if (devscan(low) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to list other devices.\n"); + log_fatal(EEXTERNAL, "Failed to list other devices.\n"); return -1; /* LCOV_EXCL_STOP */ } diff --git a/cmdline/mktest.c b/cmdline/mktest.c index c83807bf..f062057a 100644 --- a/cmdline/mktest.c +++ b/cmdline/mktest.c @@ -151,7 +151,7 @@ void cmd_generate_file(const char* path, int size) if (remove(path) != 0) { if (errno != ENOENT) { /* LCOV_EXCL_START */ - log_fatal("Error removing file %s\n", path); + log_fatal(errno, "Error removing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -173,21 +173,21 @@ void cmd_generate_file(const char* path, int size) f = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_NOFOLLOW, 0600); if (f < 0) { /* LCOV_EXCL_START */ - log_fatal("Error creating file %s\n", path); + log_fatal(errno, "Error creating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - log_fatal("Error writing file %s\n", path); + log_fatal(errno, "Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file %s\n", path); + log_fatal(errno, "Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -205,7 +205,7 @@ void cmd_generate_symlink(const char* path, const char* linkto) if (remove(path) != 0) { if (errno != ENOENT) { /* LCOV_EXCL_START */ - log_fatal("Error removing file %s\n", path); + log_fatal(errno, "Error removing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -213,7 +213,7 @@ void cmd_generate_symlink(const char* path, const char* linkto) if (symlink(linkto, path) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error writing symlink %s\n", path); + log_fatal(errno, "Error writing symlink %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -238,7 +238,7 @@ void cmd_generate(int disk, int size) if (mkdir(path, 0777) != 0) { if (errno != EEXIST) { /* LCOV_EXCL_START */ - log_fatal("Error creating directory %s\n", path); + log_fatal(errno, "Error creating directory %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -296,7 +296,7 @@ void cmd_write(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing %s\n", path); + log_fatal(errno, "Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -323,28 +323,28 @@ void cmd_write(const char* path, int size) f = open(path, O_WRONLY | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - log_fatal("Error creating file %s\n", path); + log_fatal(errno, "Error creating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, off, SEEK_SET) != off) { /* LCOV_EXCL_START */ - log_fatal("Error seeking file %s\n", path); + log_fatal(errno, "Error seeking file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - log_fatal("Error writing file %s\n", path); + log_fatal(errno, "Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file %s\n", path); + log_fatal(errno, "Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -372,7 +372,7 @@ void cmd_damage(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing %s\n", path); + log_fatal(errno, "Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -400,21 +400,21 @@ void cmd_damage(const char* path, int size) f = open(path, O_RDWR | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - log_fatal("Error creating file %s\n", path); + log_fatal(errno, "Error creating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, off, SEEK_SET) != off) { /* LCOV_EXCL_START */ - log_fatal("Error seeking file %s\n", path); + log_fatal(errno, "Error seeking file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (read(f, data, size) != size) { /* LCOV_EXCL_START */ - log_fatal("Error writing file %s\n", path); + log_fatal(errno, "Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -423,28 +423,28 @@ void cmd_damage(const char* path, int size) if (lseek(f, off, SEEK_SET) != off) { /* LCOV_EXCL_START */ - log_fatal("Error seeking file %s\n", path); + log_fatal(errno, "Error seeking file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - log_fatal("Error writing file %s\n", path); + log_fatal(errno, "Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (fallback(f, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error setting time for file %s\n", path); + log_fatal(errno, "Error setting time for file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file %s\n", path); + log_fatal(errno, "Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -464,7 +464,7 @@ void cmd_append(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing %s\n", path); + log_fatal(errno, "Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -480,21 +480,21 @@ void cmd_append(const char* path, int size) f = open(path, O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - log_fatal("Error opening file %s\n", path); + log_fatal(errno, "Error opening file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - log_fatal("Error writing file %s\n", path); + log_fatal(errno, "Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file %s\n", path); + log_fatal(errno, "Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -515,7 +515,7 @@ void cmd_truncate(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing %s\n", path); + log_fatal(errno, "Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -538,21 +538,21 @@ void cmd_truncate(const char* path, int size) f = open(path, O_WRONLY | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - log_fatal("Error opening file %s\n", path); + log_fatal(errno, "Error opening file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (ftruncate(f, off) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error truncating file %s\n", path); + log_fatal(errno, "Error truncating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file %s\n", path); + log_fatal(errno, "Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -567,7 +567,7 @@ void cmd_delete(const char* path) { if (remove(path) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error removing %s\n", path); + log_fatal(errno, "Error removing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -586,7 +586,7 @@ void cmd_change(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing %s\n", path); + log_fatal(errno, "Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -597,7 +597,7 @@ void cmd_change(const char* path, int size) /* delete */ if (remove(path) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error removing %s\n", path); + log_fatal(errno, "Error removing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -607,7 +607,7 @@ void cmd_change(const char* path, int size) if (remove(path) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error removing %s\n", path); + log_fatal(errno, "Error removing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/parity.c b/cmdline/parity.c index f7282c0c..15e94f9a 100644 --- a/cmdline/parity.c +++ b/cmdline/parity.c @@ -145,15 +145,15 @@ void parity_overflow(struct snapraid_state* state, data_off_t size) if (parity_pos >= blockalloc) { found = 1; log_tag("outofparity:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); - log_fatal("outofparity %s%s\n", disk->dir, file->sub); + log_fatal(ESOFT, "outofparity %s%s\n", disk->dir, file->sub); } } } } if (found) { - log_fatal("\nInsufficient parity space. Data requires more parity than available.\n"); - log_fatal("Move the 'outofparity' files to a larger disk.\n"); + log_fatal(ESOFT, "\nInsufficient parity space. Data requires more parity than available.\n"); + log_fatal(ESOFT, "Move the 'outofparity' files to a larger disk.\n"); } } @@ -200,7 +200,7 @@ int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_p split->f = open(split->path, flags, 0600); if (split->f == -1) { /* LCOV_EXCL_START */ - log_fatal("Error opening parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error opening parity file '%s'. %s.\n", split->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -212,7 +212,7 @@ int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_p ret = fstat(split->f, &split->st); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error accessing parity file '%s'. %s.\n", split->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -231,7 +231,7 @@ int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_p /* ensure that the resulting size if block aligned */ if ((split->size & block_mask) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in preallocated size of parity file '%s' with size %" PRIu64 " and block %u .\n", split->path, split->size, block_size); + log_fatal(ESOFT, "Error in preallocated size of parity file '%s' with size %" PRIu64 " and block %u .\n", split->path, split->size, block_size); goto bail; /* LCOV_EXCL_STOP */ } @@ -240,7 +240,7 @@ int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_p ret = advise_open(&split->advise, split->f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error advising parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error advising parity file '%s'. %s.\n", split->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -397,28 +397,28 @@ static int parity_handle_fill(struct snapraid_split_handle* split, data_off_t si spaceholder_f = open(spaceholder_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0600); if (spaceholder_f == -1) { - log_fatal("Failed to create space holder file '%s'.\n", spaceholder_path); + log_fatal(errno, "Failed to create space holder file '%s'.\n", spaceholder_path); return -1; } /* note that in Windows ftruncate is really allocating space */ if (ftruncate(spaceholder_f, WINDOWS_SPACEHOLDER_SIZE) != 0) { - log_fatal("WARNING Failed to resize the space holder file '%s' to %u bytes.\n", spaceholder_path, WINDOWS_SPACEHOLDER_SIZE); - log_fatal("Assuming that no more space is available.\n"); + log_fatal(errno, "WARNING Failed to resize the space holder file '%s' to %u bytes.\n", spaceholder_path, WINDOWS_SPACEHOLDER_SIZE); + log_fatal(errno, "Assuming that no more space is available.\n"); close(spaceholder_f); remove(spaceholder_path); return 0; } if (fsync(spaceholder_f) != 0) { - log_fatal("Failed to sync the space holder file '%s'.\n", spaceholder_path); + log_fatal(errno, "Failed to sync the space holder file '%s'.\n", spaceholder_path); close(spaceholder_f); remove(spaceholder_path); return -1; } if (close(spaceholder_f) != 0) { - log_fatal("Failed to close the space holder file '%s'.\n", spaceholder_path); + log_fatal(errno, "Failed to close the space holder file '%s'.\n", spaceholder_path); remove(spaceholder_path); return -1; } @@ -468,7 +468,7 @@ static int parity_handle_fill(struct snapraid_split_handle* split, data_off_t si /* ensure that the resulting size if block aligned */ if ((base & block_mask) != 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in requested parity size %" PRIu64 " with block %u\n", base, block_size); + log_fatal(EINTERNAL, "Internal inconsistency in requested parity size %" PRIu64 " with block %u\n", base, block_size); os_abort(); /* LCOV_EXCL_STOP */ } @@ -476,8 +476,8 @@ static int parity_handle_fill(struct snapraid_split_handle* split, data_off_t si #ifdef _WIN32 /* now delete the spaceholder file */ if (remove(spaceholder_path) != 0) { - log_fatal("WARNING Failed to remove the space holder file '%s'.\n", spaceholder_path); - log_fatal("Continuing anyway.\n"); + log_error(errno, "WARNING Failed to remove the space holder file '%s'.\n", spaceholder_path); + log_error(errno, "Continuing anyway.\n"); } #endif @@ -511,7 +511,7 @@ static int parity_handle_chsize(struct snapraid_split_handle* split, data_off_t ret = fstat(split->f, &split->st); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error accessing parity file '%s'. %s.\n", split->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -521,12 +521,12 @@ static int parity_handle_chsize(struct snapraid_split_handle* split, data_off_t /* LCOV_EXCL_START */ if (f_dir > 0) { if (f_errno == ENOSPC) { - log_fatal("Failed to grow parity file '%s' to size %" PRIu64 " due lack of space.\n", split->path, size); + log_fatal(errno, "Failed to grow parity file '%s' to size %" PRIu64 " due lack of space.\n", split->path, size); } else { - log_fatal("Error growing parity file '%s' to size %" PRIu64 ". Do you have enough space? %s.\n", split->path, size, strerror(f_errno)); + log_fatal(errno, "Error growing parity file '%s' to size %" PRIu64 ". Do you have enough space? %s.\n", split->path, size, strerror(f_errno)); } } else { - log_fatal("Error truncating parity file '%s' to size %" PRIu64 ". %s.\n", split->path, size, strerror(f_errno)); + log_fatal(errno, "Error truncating parity file '%s' to size %" PRIu64 ". %s.\n", split->path, size, strerror(f_errno)); } return -1; /* LCOV_EXCL_STOP */ @@ -590,8 +590,8 @@ int parity_chsize(struct snapraid_parity_handle* handle, struct snapraid_parity* if ((run & block_mask) != 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in split '%s' size with extra '%" PRIu64 "' bytes.\n", split->path, run & block_mask); errno = ENXIO; + log_fatal(EINTERNAL, "Internal inconsistency in split '%s' size with extra '%" PRIu64 "' bytes.\n", split->path, run & block_mask); return -1; /* LCOV_EXCL_STOP */ } @@ -610,14 +610,14 @@ int parity_chsize(struct snapraid_parity_handle* handle, struct snapraid_parity* if (split->st.st_size > run) { /* LCOV_EXCL_START */ - log_fatal("Unexpected over resizing parity file '%s' to size %" PRIu64 " resulting in size %" PRIu64 ".\n", split->path, run, (uint64_t)split->st.st_size); errno = ENXIO; + log_fatal(errno, "Unexpected over resizing parity file '%s' to size %" PRIu64 " resulting in size %" PRIu64 ".\n", split->path, run, (uint64_t)split->st.st_size); return -1; /* LCOV_EXCL_STOP */ } else if (is_fixed && split->st.st_size < run) { /* LCOV_EXCL_START */ - log_fatal("Failed restoring parity file '%s' to size %" PRIu64 " resulting in size %" PRIu64 ".\n", split->path, run, (uint64_t)split->st.st_size); errno = ENXIO; + log_fatal(errno, "Failed restoring parity file '%s' to size %" PRIu64 " resulting in size %" PRIu64 ".\n", split->path, run, (uint64_t)split->st.st_size); return -1; /* LCOV_EXCL_STOP */ } else { @@ -626,7 +626,7 @@ int parity_chsize(struct snapraid_parity_handle* handle, struct snapraid_parity* if ((run & block_mask) != 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in final parity size %" PRIu64 " with block size %u\n", run, block_size); + log_fatal(EINTERNAL, "Internal inconsistency in final parity size %" PRIu64 " with block size %u\n", run, block_size); os_abort(); /* LCOV_EXCL_STOP */ } @@ -642,8 +642,8 @@ int parity_chsize(struct snapraid_parity_handle* handle, struct snapraid_parity* /* if we cannot allocate all the space */ if (size != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to allocate all the required parity space. You miss %" PRIu64 " bytes.\n", size); errno = ENXIO; + log_fatal(errno, "Failed to allocate all the required parity space. You miss %" PRIu64 " bytes.\n", size); return -1; /* LCOV_EXCL_STOP */ } @@ -693,7 +693,7 @@ int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_par split->f = open_noatime(split->path, flags); if (split->f == -1) { /* LCOV_EXCL_START */ - log_fatal("Error opening parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error opening parity file '%s'. %s.\n", split->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -705,7 +705,7 @@ int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_par ret = fstat(split->f, &split->st); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error accessing parity file '%s'. %s.\n", split->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -724,7 +724,7 @@ int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_par /* ensure that the resulting size if block aligned */ if ((split->size & block_mask) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in preallocated size of parity file '%s' with size %" PRIu64 " and block %u .\n", split->path, split->size, block_size); + log_fatal(ESOFT, "Error in preallocated size of parity file '%s' with size %" PRIu64 " and block %u .\n", split->path, split->size, block_size); goto bail; /* LCOV_EXCL_STOP */ } @@ -733,7 +733,7 @@ int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_par ret = advise_open(&split->advise, split->f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error advising parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error advising parity file '%s'. %s.\n", split->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -767,7 +767,7 @@ int parity_sync(struct snapraid_parity_handle* handle) ret = fsync(split->f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error syncing parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error syncing parity file '%s'. %s.\n", split->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -790,7 +790,7 @@ int parity_truncate(struct snapraid_parity_handle* handle) ret = ftruncate(split->f, split->valid_size); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error truncating the parity file '%s' to size %" PRIu64 ". %s.\n", split->path, split->valid_size, strerror(errno)); + log_fatal(errno, "Error truncating the parity file '%s' to size %" PRIu64 ". %s.\n", split->path, split->valid_size, strerror(errno)); f_ret = -1; /* LCOV_EXCL_STOP */ @@ -816,7 +816,7 @@ int parity_close(struct snapraid_parity_handle* handle) /* This is a serious error, as it may be the result of a failed write */ /* identified at later time. */ /* In a normal file-system (not NFS) it should never happen */ - log_fatal("Error closing parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error closing parity file '%s'. %s.\n", split->path, strerror(errno)); f_ret = -1; /* LCOV_EXCL_STOP */ @@ -862,7 +862,8 @@ int parity_write(struct snapraid_parity_handle* handle, block_off_t pos, unsigne split = parity_split_find(handle, &offset); if (!split) { /* LCOV_EXCL_START */ - log_fatal("Writing parity data outside range at extra offset %" PRIu64 ".\n", offset); + errno = ENXIO; + log_fatal(errno, "Writing parity data outside range at extra offset %" PRIu64 ".\n", offset); return -1; /* LCOV_EXCL_STOP */ } @@ -879,17 +880,17 @@ int parity_write(struct snapraid_parity_handle* handle, block_off_t pos, unsigne if (write_ret == -1) { /* LCOV_EXCL_START */ if (errno == ENOSPC) { - log_fatal("Failed to grow parity file '%s' using write due lack of space.\n", split->path); + log_fatal(errno, "Failed to grow parity file '%s' using write due lack of space.\n", split->path); } else { - log_fatal("Error writing parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error writing parity file '%s'. %s.\n", split->path, strerror(errno)); } return -1; /* LCOV_EXCL_STOP */ } if (write_ret == 0) { /* LCOV_EXCL_START */ - log_fatal("Unexpected 0 write to file '%s'. %s.\n", split->path, strerror(errno)); errno = ENXIO; + log_fatal(errno, "Unexpected 0 write to file '%s'. %s.\n", split->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -900,7 +901,7 @@ int parity_write(struct snapraid_parity_handle* handle, block_off_t pos, unsigne ret = advise_write(&split->advise, split->f, offset, block_size); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error advising parity file '%s'. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error advising parity file '%s'. %s.\n", split->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -908,7 +909,7 @@ int parity_write(struct snapraid_parity_handle* handle, block_off_t pos, unsigne return 0; } -int parity_read(struct snapraid_parity_handle* handle, block_off_t pos, unsigned char* block_buffer, unsigned block_size, fptr* out) +int parity_read(struct snapraid_parity_handle* handle, block_off_t pos, unsigned char* block_buffer, unsigned block_size, log_ptr* out) { ssize_t read_ret; data_off_t offset; @@ -921,7 +922,8 @@ int parity_read(struct snapraid_parity_handle* handle, block_off_t pos, unsigned split = parity_split_find(handle, &offset); if (!split) { /* LCOV_EXCL_START */ - out("Reading parity data outside range at extra offset %" PRIu64 ".\n", offset); + errno = ENXIO; + out(errno, "Reading parity data outside range at extra offset %" PRIu64 ".\n", offset); return -1; /* LCOV_EXCL_STOP */ } @@ -929,7 +931,8 @@ int parity_read(struct snapraid_parity_handle* handle, block_off_t pos, unsigned /* if read is completely out of the valid range */ if (offset >= split->valid_size) { /* LCOV_EXCL_START */ - out("Reading over the end from parity file '%s' at offset %" PRIu64 " for size %u.\n", split->path, offset, block_size); + errno = ENXIO; + out(errno, "Reading over the end from parity file '%s' at offset %" PRIu64 " for size %u.\n", split->path, offset, block_size); return -1; /* LCOV_EXCL_STOP */ } @@ -942,15 +945,15 @@ int parity_read(struct snapraid_parity_handle* handle, block_off_t pos, unsigned read_ret = pread(split->f, block_buffer + count, block_size - count, offset + count); if (read_ret == -1) { /* LCOV_EXCL_START */ - out("Error reading parity file '%s' at offset %" PRIu64 " for size %u. %s.\n", split->path, offset + count, block_size - count, strerror(errno)); + out(errno, "Error reading parity file '%s' at offset %" PRIu64 " for size %u. %s.\n", split->path, offset + count, block_size - count, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } if (read_ret == 0) { /* LCOV_EXCL_START */ - out("Unexpected end of parity file '%s' at offset %" PRIu64 ". %s.\n", split->path, offset, strerror(errno)); if (errno == 0) errno = ENXIO; + out(errno, "Unexpected end of parity file '%s' at offset %" PRIu64 ". %s.\n", split->path, offset, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -961,7 +964,7 @@ int parity_read(struct snapraid_parity_handle* handle, block_off_t pos, unsigned ret = advise_read(&split->advise, split->f, offset, block_size); if (ret != 0) { /* LCOV_EXCL_START */ - out("Error advising parity file '%s'. %s.\n", split->path, strerror(errno)); + out(errno, "Error advising parity file '%s'. %s.\n", split->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } diff --git a/cmdline/parity.h b/cmdline/parity.h index 678ca780..cfe12651 100644 --- a/cmdline/parity.h +++ b/cmdline/parity.h @@ -140,7 +140,7 @@ int parity_close(struct snapraid_parity_handle* handle); /** * Read a block from the parity file. */ -int parity_read(struct snapraid_parity_handle* handle, block_off_t pos, unsigned char* block_buffer, unsigned block_size, fptr* out); +int parity_read(struct snapraid_parity_handle* handle, block_off_t pos, unsigned char* block_buffer, unsigned block_size, log_ptr* out); /** * Write a block in the parity file. diff --git a/cmdline/pool.c b/cmdline/pool.c index 85cfc40a..87fcc112 100644 --- a/cmdline/pool.c +++ b/cmdline/pool.c @@ -74,7 +74,7 @@ static int clean_dir(const char* dir) d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - log_fatal("Error opening pool directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error opening pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -90,7 +90,7 @@ static int clean_dir(const char* dir) dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - log_fatal("Error reading pool directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error reading pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -114,7 +114,7 @@ static int clean_dir(const char* dir) if (st.st_mode == 0) { if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -123,7 +123,7 @@ static int clean_dir(const char* dir) /* get lstat info about the file */ if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -143,13 +143,13 @@ static int clean_dir(const char* dir) /* in Windows just ignore EACCES errors removing directories */ /* because it could happen that the directory is in use */ /* and it cannot be removed */ - log_fatal("Directory '%s' not removed because it's in use.\n", path_next); + log_fatal(errno, "Directory '%s' not removed because it's in use.\n", path_next); full = 1; } else #endif { /* LCOV_EXCL_START */ - log_fatal("Error removing pool directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error removing pool directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -166,7 +166,7 @@ static int clean_dir(const char* dir) if (closedir(d) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing pool directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error closing pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -186,7 +186,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - log_fatal("Error opening pool directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error opening pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -202,7 +202,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - log_fatal("Error reading pool directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error reading pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -226,7 +226,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s if (st.st_mode == 0) { if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -235,7 +235,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s /* get lstat info about the file */ if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -249,7 +249,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s ret = readlink(path_next, linkto, sizeof(linkto)); if (ret < 0 || ret >= PATH_MAX) { /* LCOV_EXCL_START */ - log_fatal("Error in readlink symlink '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in readlink symlink '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -271,7 +271,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s if (closedir(d) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing pool directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error closing pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -293,7 +293,7 @@ static void remove_link(void* void_arg, void* void_pool) ret = remove(path); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Error removing symlink '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error removing symlink '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -342,7 +342,7 @@ static void make_link(tommy_hashdyn* poolset, const char* pool_dir, const char* ret = remove(path); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Error removing symlink '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error removing symlink '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -365,17 +365,17 @@ static void make_link(tommy_hashdyn* poolset, const char* pool_dir, const char* ret = symlink(linkto_exported, path); if (ret != 0) { if (errno == EEXIST) { - log_fatal("WARNING! Duplicate pooling for '%s'\n", path); + log_fatal(errno, "WARNING! Duplicate pooling for '%s'\n", path); #ifdef _WIN32 } else if (errno == EPERM) { /* LCOV_EXCL_START */ - log_fatal("You must run as Administrator to be able to create symlinks.\n"); + log_fatal(errno, "You must run as Administrator to be able to create symlinks.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ #endif } else { /* LCOV_EXCL_START */ - log_fatal("Error writing symlink '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error writing symlink '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -385,7 +385,7 @@ static void make_link(tommy_hashdyn* poolset, const char* pool_dir, const char* ret = lmtime(path, mtime_sec, mtime_nsec); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error setting time to symlink '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error setting time to symlink '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -404,7 +404,7 @@ void state_pool(struct snapraid_state* state) if (state->pool[0] == 0) { /* LCOV_EXCL_START */ - log_fatal("To use the 'pool' command you must set the pool directory in the configuration file\n"); + log_fatal(EUSER, "To use the 'pool' command you must set the pool directory in the configuration file\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/portable.h b/cmdline/portable.h index eefdd80a..61f593ae 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -578,5 +578,16 @@ extern volatile int global_interrupt; */ #define WINDOWS_SPACEHOLDER_SIZE (256 * 1024 * 1024) +/** + * Generic errors + */ +#define EINTERNAL EFAULT /**< Internal assertion failed. */ +#define EDATA EIO /**< Silent data corruption. */ +#define ESOFT EINVAL /**< Software error, like permission denied. */ +#define EUSER EINVAL /**< Invalid value specified by the user. */ +#define EEXTERNAL EINVAL /**< Invalid external interface behaviour. */ +#define ECONTENT EINVAL /**< Invalid content file. */ +#define EENVIRONMENT EINVAL /**< Invalid physical environment, like temperature too high. */ + #endif diff --git a/cmdline/rehash.c b/cmdline/rehash.c index 9a8a6a37..3803ce9b 100644 --- a/cmdline/rehash.c +++ b/cmdline/rehash.c @@ -39,7 +39,7 @@ void state_rehash(struct snapraid_state* state) if (state->prevhash != HASH_UNDEFINED) { /* LCOV_EXCL_START */ log_tag("summary:exit:already_in_progress\n"); - log_fatal("You already have a rehash in progress.\n"); + log_fatal(EUSER, "You already have a rehash in progress.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -47,7 +47,7 @@ void state_rehash(struct snapraid_state* state) if (state->hash == state->besthash) { /* LCOV_EXCL_START */ log_tag("summary:exit:not_required\n"); - log_fatal("You are already using the best hash for your platform.\n"); + log_fatal(EUSER, "You are already using the best hash for your platform.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -60,7 +60,7 @@ void state_rehash(struct snapraid_state* state) state->hash = state->besthash; if (randomize(state->hashseed, HASH_MAX) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to get random values.\n"); + log_fatal(errno, "Failed to get random values.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -78,7 +78,7 @@ void state_rehash(struct snapraid_state* state) if (info_get_rehash(info)) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency for a rehash already in progress\n"); + log_fatal(EINTERNAL, "Internal inconsistency for a rehash already in progress\n"); os_abort(); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/scan.c b/cmdline/scan.c index 97cfb375..4cda10cb 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -161,7 +161,7 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, /* check if multiple files have the same name */ if (link_flag_has(slink, FILE_IS_PRESENT)) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency for link '%s%s'\n", disk->dir, sub); + log_fatal(EINTERNAL, "Internal inconsistency for link '%s%s'\n", disk->dir, sub); os_abort(); /* LCOV_EXCL_STOP */ } @@ -340,7 +340,7 @@ static void scan_file_deallocate(struct snapraid_scan* scan, struct snapraid_fil /* so at this point ::first_free_block is always at 0, and we don't need to update it */ if (disk->first_free_block != 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency for first free position at '%u' deallocating file '%s'\n", disk->first_free_block, file->sub); + log_fatal(EINTERNAL, "Internal inconsistency for first free position at '%u' deallocating file '%s'\n", disk->first_free_block, file->sub); os_abort(); /* LCOV_EXCL_STOP */ } @@ -380,7 +380,7 @@ static void scan_file_deallocate(struct snapraid_scan* scan, struct snapraid_fil break; default : /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in file '%s' deallocating block '%u:%u' state %u\n", file->sub, i, file->blockmax, block_state); + log_fatal(EINTERNAL, "Internal inconsistency in file '%s' deallocating block '%u:%u' state %u\n", file->sub, i, file->blockmax, block_state); os_abort(); /* LCOV_EXCL_STOP */ } @@ -411,7 +411,7 @@ static void scan_file_delayed_allocate(struct snapraid_scan* scan, struct snapra if (filephy(path_next, file->size, &file->physical) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in getting the physical offset of file '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in getting the physical offset of file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -552,7 +552,7 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc if (lstat_sync(path_next, &synced_st, physical) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -574,9 +574,9 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc * Why is the file size reported incorrectly for files that are still being written to? * http://blogs.msdn.com/b/oldnewthing/archive/2011/12/26/10251026.aspx */ - log_fatal("WARNING! Detected uncached time change from %" PRIu64 ".%09u to %" PRIu64 ".%09u for file '%s'\n", + log_fatal(ESOFT, "WARNING! Detected uncached time change from %" PRIu64 ".%09u to %" PRIu64 ".%09u for file '%s'\n", (uint64_t)st->st_mtime, (uint32_t)st->st_mtimensec, (uint64_t)synced_st.st_mtime, (uint32_t)synced_st.st_mtimensec, sub); - log_fatal("It's better if you run SnapRAID without other processes running.\n"); + log_fatal(ESOFT, "It's better if you run SnapRAID without other processes running.\n"); #endif st->st_mtime = synced_st.st_mtime; st->st_mtimensec = synced_st.st_mtimensec; @@ -584,26 +584,26 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc if (st->st_size != synced_st.st_size) { #ifndef _WIN32 - log_fatal("WARNING! Detected uncached size change from %" PRIu64 " to %" PRIu64 " for file '%s'\n", + log_fatal(ESOFT, "WARNING! Detected uncached size change from %" PRIu64 " to %" PRIu64 " for file '%s'\n", (uint64_t)st->st_size, (uint64_t)synced_st.st_size, sub); - log_fatal("It's better if you run SnapRAID without other processes running.\n"); + log_fatal(ESOFT, "It's better if you run SnapRAID without other processes running.\n"); #endif st->st_size = synced_st.st_size; } if (st->st_nlink != synced_st.st_nlink) { #ifndef _WIN32 - log_fatal("WARNING! Detected uncached nlink change from %u to %u for file '%s'\n", + log_fatal(ESOFT, "WARNING! Detected uncached nlink change from %u to %u for file '%s'\n", (uint32_t)st->st_nlink, (uint32_t)synced_st.st_nlink, sub); - log_fatal("It's better if you run SnapRAID without other processes running.\n"); + log_fatal(ESOFT, "It's better if you run SnapRAID without other processes running.\n"); #endif st->st_nlink = synced_st.st_nlink; } if (st->st_ino != synced_st.st_ino) { - log_fatal("DANGER! Detected uncached inode change from %" PRIu64 " to %" PRIu64 " for file '%s'\n", + log_fatal(ESOFT, "DANGER! Detected uncached inode change from %" PRIu64 " to %" PRIu64 " for file '%s'\n", (uint64_t)st->st_ino, (uint64_t)synced_st.st_ino, sub); - log_fatal("It's better if you run SnapRAID without other processes running.\n"); + log_fatal(ESOFT, "It's better if you run SnapRAID without other processes running.\n"); /* at this point, it's too late to change inode */ /* and having inconsistent inodes may result to internal failures */ /* so, it's better to abort */ @@ -756,7 +756,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* if has_volatile_hardlinks is true, the nlink value is not reliable */ if (!disk->has_volatile_hardlinks && st->st_nlink == 1) { /* LCOV_EXCL_START */ - log_fatal("Internal inode '%" PRIu64 "' inconsistency for file '%s%s' already present\n", (uint64_t)st->st_ino, disk->dir, sub); + log_fatal(EINTERNAL, "Internal inode '%" PRIu64 "' inconsistency for file '%s%s' already present\n", (uint64_t)st->st_ino, disk->dir, sub); os_abort(); /* LCOV_EXCL_STOP */ } @@ -839,7 +839,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* if has_volatile_hardlinks is true, the nlink value is not reliable */ if (!disk->has_volatile_hardlinks && st->st_nlink == 1) { /* LCOV_EXCL_START */ - log_fatal("Internal inode '%" PRIu64 "' inconsistency for files '%s%s' and '%s%s' with same inode but different attributes: size %" PRIu64 "?%" PRIu64 ", sec %" PRIu64 "?%" PRIu64 ", nsec %d?%d\n", + log_fatal(EINTERNAL, "Internal inode '%" PRIu64 "' inconsistency for files '%s%s' and '%s%s' with same inode but different attributes: size %" PRIu64 "?%" PRIu64 ", sec %" PRIu64 "?%" PRIu64 ", nsec %d?%d\n", file->inode, disk->dir, sub, disk->dir, file->sub, file->size, (uint64_t)st->st_size, file->mtime_sec, (uint64_t)st->st_mtime, @@ -900,7 +900,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* here the inode has to be different, otherwise we would have found it before */ if (file->inode == st->st_ino) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in inode '%" PRIu64 "' for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub); + log_fatal(EINTERNAL, "Internal inconsistency in inode '%" PRIu64 "' for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub); os_abort(); /* LCOV_EXCL_STOP */ } @@ -909,7 +909,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* for sure it cannot be already present */ if (file_flag_has(file, FILE_IS_PRESENT)) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in path for file '%s%s' matching and already present\n", disk->dir, sub); + log_fatal(EINTERNAL, "Internal inconsistency in path for file '%s%s' matching and already present\n", disk->dir, sub); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1013,11 +1013,11 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, if (is_original_file_size_different_than_zero && st->st_size == 0) { if (!state->opt.force_zero) { /* LCOV_EXCL_START */ - log_fatal("The file '%s%s' has unexpected zero size!\n", disk->dir, sub); - log_fatal("It's possible that after a kernel crash this file was lost,\n"); - log_fatal("and you can use 'snapraid fix -f /%s' to recover it.\n", fmt_poll(disk, sub, esc_buffer)); + log_fatal(ESOFT, "The file '%s%s' has unexpected zero size!\n", disk->dir, sub); + log_fatal(ESOFT, "It's possible that after a kernel crash this file was lost,\n"); + log_fatal(ESOFT, "and you can use 'snapraid fix -f /%s' to recover it.\n", fmt_poll(disk, sub, esc_buffer)); if (!is_diff) { - log_fatal("If this an expected condition you can '%s' anyway using 'snapraid --force-zero %s'\n", state->command, state->command); + log_fatal(ESOFT, "If this an expected condition you can '%s' anyway using 'snapraid --force-zero %s'\n", state->command, state->command); exit(EXIT_FAILURE); } /* LCOV_EXCL_STOP */ @@ -1153,7 +1153,7 @@ static void scan_emptydir(struct snapraid_scan* scan, const char* sub) /* check if multiple files have the same name */ if (dir_flag_has(dir, FILE_IS_PRESENT)) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency for dir '%s%s'\n", disk->dir, sub); + log_fatal(EINTERNAL, "Internal inconsistency for dir '%s%s'\n", disk->dir, sub); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1231,7 +1231,7 @@ struct stat* dstat(const char* file, struct stat* st) { if (lstat(file, st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", file, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", file, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1262,11 +1262,11 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa d = opendir(path_next); if (!d) { /* LCOV_EXCL_START */ - log_fatal("Error opening directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error opening directory '%s'. %s.\n", path_next, strerror(errno)); if (level == 0) - log_fatal("If this is the disk mount point, remember to create it manually\n"); + log_fatal(errno, "If this is the disk mount point, remember to create it manually\n"); else - log_fatal("If it's a permission problem, you can exclude it in the config file with:\n\texclude /%s\n", sub_next); + log_fatal(errno, "If it's a permission problem, you can exclude it in the config file with:\n\texclude /%s\n", sub_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1292,8 +1292,8 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa /* restore removing additions */ path_next[path_len] = 0; sub_next[sub_len] = 0; - log_fatal("Error reading directory '%s'. %s.\n", path_next, strerror(errno)); - log_fatal("You can exclude it in the config file with:\n\texclude /%s\n", sub_next); + log_fatal(errno, "Error reading directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "You can exclude it in the config file with:\n\texclude /%s\n", sub_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1311,7 +1311,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa /* check for not supported file names */ if (name[0] == 0) { /* LCOV_EXCL_START */ - log_fatal("Unsupported name '%s' in file '%s'.\n", name, path_next); + log_fatal(ESOFT, "Unsupported name '%s' in file '%s'.\n", name, path_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1358,7 +1358,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa /* LCOV_EXCL_START */ /* restore removing additions */ path_next[path_len] = 0; - log_fatal("Error closing directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error closing directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1422,7 +1422,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa if (st->st_mode == 0) { if (lstat(path_next, st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1453,7 +1453,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa if (st->st_ino == 0 || st->st_nlink == 0) { if (lstat_sync(path_next, st, 0) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1473,18 +1473,18 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa ret = readlink(path_next, tmp, PATH_MAX); if (ret >= PATH_MAX) { /* LCOV_EXCL_START */ - log_fatal("Error in readlink file '%s'. Symlink too long.\n", path_next); + log_fatal(EINTERNAL, "Error in readlink file '%s'. Symlink too long.\n", path_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Error in readlink file '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in readlink file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (ret == 0) - log_fatal("WARNING! Empty symbolic link '%s'.\n", path_next); + log_fatal(ESOFT, "WARNING! Empty symbolic link '%s'.\n", path_next); /* readlink doesn't put the final 0 */ tmp[ret] = 0; @@ -1506,7 +1506,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa /* in Unix don't follow mount points in different devices */ /* in Windows we are already skipping them reporting them as special files */ if ((uint64_t)st->st_dev != disk->device) { - log_fatal("WARNING! Ignoring mount point '%s' because it appears to be in a different device\n", path_next); + log_fatal(ESOFT, "WARNING! Ignoring mount point '%s' because it appears to be in a different device\n", path_next); } else #endif { @@ -1532,7 +1532,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa if (!st) st = DSTAT(path_next, dd, &st_buf); - log_fatal("WARNING! Ignoring special '%s' file '%s'\n", stat_desc(st), path_next); + log_fatal(ESOFT, "WARNING! Ignoring special '%s' file '%s'\n", stat_desc(st), path_next); } else { msg_verbose("Excluding special file '%s' for rule '%s'\n", path_next, filter_type(reason, tmp, PATH_MAX)); } @@ -1578,7 +1578,7 @@ static void* scan_disk(void* arg) ret = fsinfo(disk->dir, &has_persistent_inodes, &has_syncronized_hardlinks, 0, 0, 0, 0, 0, 0); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing disk '%s' to get file-system info. %s.\n", disk->dir, strerror(errno)); + log_fatal(errno, "Error accessing disk '%s' to get file-system info. %s.\n", disk->dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1628,7 +1628,7 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) tommy_node* j; tommy_list scanlist; int done; - fptr* msg; + msg_ptr* msg; struct snapraid_scan total; int no_difference; char esc_buffer[ESC_MAX]; @@ -1781,7 +1781,7 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) /* if verbose, print the list of duplicates real offsets */ /* other cases are for offsets not supported, so we don't need to report them file by file */ if (phy_last >= FILEPHY_REAL_OFFSET) { - log_fatal("WARNING! Files '%s%s' and '%s%s' share the same physical offset %" PRId64 ".\n", disk->dir, phy_file_last->sub, disk->dir, file->sub, phy_last); + log_fatal(ESOFT, "WARNING! Files '%s%s' and '%s%s' share the same physical offset %" PRId64 ".\n", disk->dir, phy_file_last->sub, disk->dir, file->sub, phy_last); } ++phy_dup; } @@ -1851,9 +1851,9 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) ) { if (!done) { done = 1; - log_fatal("WARNING! All the files previously present in disk '%s' at dir '%s'", disk->name, disk->dir); + log_fatal(ESOFT, "WARNING! All the files previously present in disk '%s' at dir '%s'", disk->name, disk->dir); } else { - log_fatal(", disk '%s' at dir '%s'", disk->name, disk->dir); + log_fatal(ESOFT, ", disk '%s' at dir '%s'", disk->name, disk->dir); } /* detect the special condition of all files missing */ @@ -1866,17 +1866,17 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) } } if (done) { - log_fatal("\nare now missing or have been rewritten!\n"); + log_fatal(ESOFT, "\nare now missing or have been rewritten!\n"); if (all_rewritten) { - log_fatal("This could occur when restoring a disk from a backup\n"); - log_fatal("program that is not setting correctly the timestamps.\n"); + log_fatal(ESOFT, "This could occur when restoring a disk from a backup\n"); + log_fatal(ESOFT, "program that is not setting correctly the timestamps.\n"); } if (all_missing) { - log_fatal("This could occur when some disks are not mounted\n"); - log_fatal("in the expected directory.\n"); + log_fatal(ESOFT, "This could occur when some disks are not mounted\n"); + log_fatal(ESOFT, "in the expected directory.\n"); } if (!is_diff) { - log_fatal("If you want to '%s' anyway, use 'snapraid --force-empty %s'.\n", state->command, state->command); + log_fatal(ESOFT, "If you want to '%s' anyway, use 'snapraid --force-empty %s'.\n", state->command, state->command); exit(EXIT_FAILURE); } } @@ -1891,14 +1891,14 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (disk->has_unreliable_physical) { if (!done) { done = 1; - log_fatal("WARNING! Physical offsets not supported for disk '%s'", disk->name); + log_fatal(ESOFT, "WARNING! Physical offsets not supported for disk '%s'", disk->name); } else { - log_fatal(", '%s'", disk->name); + log_fatal(ESOFT, ", '%s'", disk->name); } } } if (done) { - log_fatal(". The order of files won't be optimal.\n"); + log_fatal(ESOFT, ". The order of files won't be optimal.\n"); } } @@ -1910,14 +1910,14 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (disk->has_volatile_inodes) { if (!done) { done = 1; - log_fatal("WARNING! Inodes are not persistent for disks: '%s'", disk->name); + log_fatal(ESOFT, "WARNING! Inodes are not persistent for disks: '%s'", disk->name); } else { - log_fatal(", '%s'", disk->name); + log_fatal(ESOFT, ", '%s'", disk->name); } } } if (done) { - log_fatal(". Inodes are not used to detect move operations.\n"); + log_fatal(ESOFT, ". Inodes are not used to detect move operations.\n"); } /* check for disks with changed UUID */ @@ -1932,14 +1932,14 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (disk->has_different_uuid && !disk->had_empty_uuid) { if (!done) { done = 1; - log_fatal("WARNING! UUID is changed for disks: '%s'", disk->name); + log_fatal(ESOFT, "WARNING! UUID is changed for disks: '%s'", disk->name); } else { - log_fatal(", '%s'", disk->name); + log_fatal(ESOFT, ", '%s'", disk->name); } } } if (done) { - log_fatal(". Inodes are not used to detect move operations.\n"); + log_fatal(ESOFT, ". Inodes are not used to detect move operations.\n"); } /* check for disks with unsupported UUID */ @@ -1950,17 +1950,17 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (disk->has_unsupported_uuid) { if (!done) { done = 1; - log_fatal("WARNING! UUID is unsupported for disks: '%s'", disk->name); + log_fatal(ESOFT, "WARNING! UUID is unsupported for disks: '%s'", disk->name); } else { - log_fatal(", '%s'", disk->name); + log_fatal(ESOFT, ", '%s'", disk->name); } } } if (done) { - log_fatal(". Not using inodes to detect move operations.\n"); + log_fatal(ESOFT, ". Not using inodes to detect move operations.\n"); #if defined(_linux) && !HAVE_BLKID - log_fatal("The 'blkid' library is not linked in SnapRAID!\n"); - log_fatal("Try rebuilding it after installing the libblkid-dev or libblkid-devel package.\n"); + log_fatal(ESOFT, "The 'blkid' library is not linked in SnapRAID!\n"); + log_fatal(ESOFT, "Try rebuilding it after installing the libblkid-dev or libblkid-devel package.\n"); #endif } diff --git a/cmdline/scrub.c b/cmdline/scrub.c index e4a064f6..89c0afaf 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -39,20 +39,20 @@ static const char* es(int err) static void log_fatal_errno(int err, const char* name) { if (err == EIO) { - log_fatal("DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", name); } else if (err == EACCES) { - log_fatal("WARNING! Grant permission in the disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Grant permission in the disk %s. It isn't possible to continue.\n", name); } else if (err == ENOSPC) { - log_fatal("WARNING! Ensure there is free space on the disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Ensure there is free space on the disk %s. It isn't possible to continue.\n", name); } else { - log_fatal("WARNING! Without a working %s disk, it isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Without a working %s disk, it isn't possible to continue.\n", name); } } static void log_error_errno(int err, const char* name) { if (err == EIO) { - log_fatal("DANGER! Unexpected input/output error in disk %s.\n", name); + log_fatal(err, "DANGER! Unexpected input/output error in disk %s.\n", name); } } @@ -172,7 +172,7 @@ static void scrub_data_reader(struct snapraid_worker* worker, struct snapraid_ta /* and closing a descriptor should never fail */ log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); if (errno == EIO) { task->state = TASK_STATE_IOERROR; @@ -190,7 +190,7 @@ static void scrub_data_reader(struct snapraid_worker* worker, struct snapraid_ta if (errno == EIO) { /* LCOV_EXCL_START */ log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); task->state = TASK_STATE_IOERROR; return; /* LCOV_EXCL_STOP */ @@ -466,8 +466,8 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par ++io_error; if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", disk->dir); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(EIO, "DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", disk->dir); + log_fatal(EIO, "Stopping at block %u\n", blockcur); goto bail; /* LCOV_EXCL_STOP */ } @@ -478,7 +478,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par } if (task->state != TASK_STATE_DONE) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in task state\n"); + log_fatal(EINTERNAL, "Internal inconsistency in task state\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -511,7 +511,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par error_on_this_block = 1; } else { log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer), file_pos, diff, BLOCK_HASH_SIZE * 8); - log_error("Data error in file '%s' at position '%u', diff hash bits %u/%u\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8); + log_error(EDATA, "Data error in file '%s' at position '%u', diff hash bits %u/%u\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8); ++silent_error; silent_error_on_this_block = 1; } @@ -564,8 +564,8 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par ++io_error; if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", lev_name(levcur)); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(EIO, "DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", lev_name(levcur)); + log_fatal(EIO, "Stopping at block %u\n", blockcur); goto bail; /* LCOV_EXCL_STOP */ } @@ -579,7 +579,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par } if (task->state != TASK_STATE_DONE) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in task state\n"); + log_fatal(EINTERNAL, "Internal inconsistency in task state\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -603,7 +603,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par error_on_this_block = 1; } else { log_tag("parity_error_data:%u:%s: Data error, diff parity bits %u/%u\n", blockcur, lev_config_name(l), diff, state->block_size * 8); - log_error("Data error in parity '%s' at position '%u', diff parity bits %u/%u\n", lev_config_name(l), blockcur, diff, state->block_size * 8); + log_error(EDATA, "Data error in parity '%s' at position '%u', diff parity bits %u/%u\n", lev_config_name(l), blockcur, diff, state->block_size * 8); ++silent_error; silent_error_on_this_block = 1; } @@ -706,15 +706,15 @@ end: } if (soft_error) - log_fatal("WARNING! Unexpected soft errors!\n"); + log_fatal(ESOFT, "WARNING! Unexpected soft errors!\n"); if (io_error) - log_fatal("DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); + log_fatal(EIO, "DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); if (silent_error) - log_fatal("DANGER! Unexpected data errors! The failing blocks are now marked as bad!\n"); + log_fatal(EDATA, "DANGER! Unexpected data errors! The failing blocks are now marked as bad!\n"); if (io_error || silent_error) { - log_fatal("Use 'snapraid status' to list the bad blocks.\n"); - log_fatal("Use 'snapraid -e fix' to recover them.\n"); - log_fatal("Use 'snapraid -p bad scrub' to recheck after fixing to clear the bad state.\n"); + log_fatal(ESOFT, "Use 'snapraid status' to list the bad blocks.\n"); + log_fatal(ESOFT, "Use 'snapraid -e fix' to recover them.\n"); + log_fatal(ESOFT, "Use 'snapraid -p bad scrub' to recheck after fixing to clear the bad state.\n"); } log_tag("summary:error_soft:%u\n", soft_error); @@ -804,7 +804,7 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan) if ((plan == SCRUB_BAD || plan == SCRUB_NEW || plan == SCRUB_FULL) && olderthan >= 0) { /* LCOV_EXCL_START */ - log_fatal("You can specify -o, --older-than only with a numeric percentage.\n"); + log_fatal(EUSER, "You can specify -o, --older-than only with a numeric percentage.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -881,7 +881,7 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan) if (!count) { /* LCOV_EXCL_START */ - log_fatal("The array appears to be empty.\n"); + log_fatal(EUSER, "The array is empty.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/search.c b/cmdline/search.c index 3d543faf..e73ede0b 100644 --- a/cmdline/search.c +++ b/cmdline/search.c @@ -80,10 +80,10 @@ int search_file_compare(const void* void_arg, const void* void_data) if (f == -1) { /* LCOV_EXCL_START */ if (errno == ENOENT) { - log_fatal("DANGER! file '%s' disappeared.\n", path); - log_fatal("If you moved it, please rerun the same command.\n"); + log_fatal(EUSER, "DANGER! file '%s' disappeared.\n", path); + log_fatal(EUSER, "If you moved it, please rerun the same command.\n"); } else { - log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error opening file '%s'. %s.\n", path, strerror(errno)); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -92,7 +92,7 @@ int search_file_compare(const void* void_arg, const void* void_data) ret = pread(f, arg->buffer, arg->read_size, arg->offset); if (ret < 0 || (unsigned)ret != arg->read_size) { /* LCOV_EXCL_START */ - log_fatal("Error reading file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error reading file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -100,7 +100,7 @@ int search_file_compare(const void* void_arg, const void* void_data) ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -155,7 +155,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - log_fatal("Error opening directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error opening directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -174,7 +174,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - log_fatal("Error reading directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error reading directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -214,7 +214,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, if (st.st_mode == 0) { if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -223,7 +223,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, /* get lstat info about the file */ if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -248,7 +248,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, if (closedir(d) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error closing directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/selftest.c b/cmdline/selftest.c index 93c77fb2..6a8bb1df 100644 --- a/cmdline/selftest.c +++ b/cmdline/selftest.c @@ -192,7 +192,7 @@ static void test_hash(void) digest = tommy_hash_u32(TEST_HASH32[i].seed, buffer_aligned, TEST_HASH32[i].len); if (digest != TEST_HASH32[i].digest) { /* LCOV_EXCL_START */ - log_fatal("Failed hash32 test\n"); + log_fatal(EINTERNAL, "Failed hash32 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -204,7 +204,7 @@ static void test_hash(void) digest = tommy_strhash_u32(TEST_STRHASH32[i].seed, buffer_aligned); if (digest != TEST_STRHASH32[i].digest) { /* LCOV_EXCL_START */ - log_fatal("Failed strhash32 test\n"); + log_fatal(EINTERNAL, "Failed strhash32 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -216,7 +216,7 @@ static void test_hash(void) digest = tommy_hash_u64(TEST_HASH64[i].seed, buffer_aligned, TEST_HASH64[i].len); if (digest != TEST_HASH64[i].digest) { /* LCOV_EXCL_START */ - log_fatal("Failed hash64 test\n"); + log_fatal(EINTERNAL, "Failed hash64 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -230,7 +230,7 @@ static void test_hash(void) memhash(HASH_MURMUR3, seed_aligned, digest, buffer_aligned, TEST_MURMUR3[i].len); if (memcmp(digest, TEST_MURMUR3[i].digest, HASH_MAX) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed Murmur3 test\n"); + log_fatal(EINTERNAL, "Failed Murmur3 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -243,7 +243,7 @@ static void test_hash(void) memhash(HASH_SPOOKY2, seed_aligned, digest, buffer_aligned, TEST_SPOOKY2[i].len); if (memcmp(digest, TEST_SPOOKY2[i].digest, HASH_MAX) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed Spooky2 test\n"); + log_fatal(EINTERNAL, "Failed Spooky2 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -256,7 +256,7 @@ static void test_hash(void) memhash(HASH_METRO, seed_aligned, digest, buffer_aligned, TEST_METRO[i].len); if (memcmp(digest, TEST_METRO[i].digest, HASH_MAX) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed Metro test\n"); + log_fatal(EINTERNAL, "Failed Metro test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -269,7 +269,7 @@ static void test_hash(void) memhash(HASH_MUSEAIR, seed_aligned, digest, buffer_aligned, TEST_MUSEAIR[i].len); if (memcmp(digest, TEST_MUSEAIR[i].digest, HASH_MAX) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed MuseAir test\n"); + log_fatal(EINTERNAL, "Failed MuseAir test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -322,7 +322,7 @@ static void test_crc32c(void) if (digest != TEST_CRC32C[i].digest || digest_gen != TEST_CRC32C[i].digest) { /* LCOV_EXCL_START */ - log_fatal("Failed CRC32C test\n"); + log_fatal(EINTERNAL, "Failed CRC32C test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -585,7 +585,7 @@ static void test_tommy(void) return; bail: /* LCOV_EXCL_START */ - log_fatal("Failed tommy test\n"); + log_fatal(EINTERNAL, "Failed tommy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -848,7 +848,7 @@ static void test_wnmatch(void) for (int i = 0; WNMATCH_TEST[i].pattern; ++i) { if (wnmatch(WNMATCH_TEST[i].pattern, WNMATCH_TEST[i].text) != WNMATCH_TEST[i].result) { /* LCOV_EXCL_START */ - log_fatal("Failed wnmatch test %s %s, expected %d\n", WNMATCH_TEST[i].pattern, WNMATCH_TEST[i].text, WNMATCH_TEST[i].result); + log_fatal(EINTERNAL, "Failed wnmatch test %s %s, expected %d\n", WNMATCH_TEST[i].pattern, WNMATCH_TEST[i].text, WNMATCH_TEST[i].result); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -865,14 +865,14 @@ void selftest(void) /* large file check */ if (sizeof(off_t) < sizeof(uint64_t)) { /* LCOV_EXCL_START */ - log_fatal("Missing support for large files\n"); + log_fatal(EINTERNAL, "Missing support for large files\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (util_selftest() != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed UTIL test\n"); + log_fatal(EINTERNAL, "Failed UTIL test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -882,55 +882,55 @@ void selftest(void) test_wnmatch(); if (raid_selftest() != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed SELF test\n"); + log_fatal(EINTERNAL, "Failed SELF test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_sort() != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed SORT test\n"); + log_fatal(EINTERNAL, "Failed SORT test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_insert() != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed INSERT test\n"); + log_fatal(EINTERNAL, "Failed INSERT test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_combo() != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed COMBO test\n"); + log_fatal(EINTERNAL, "Failed COMBO test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_VANDERMONDE, 32, 256) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed GEN Vandermonde test\n"); + log_fatal(EINTERNAL, "Failed GEN Vandermonde test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_rec(RAID_MODE_VANDERMONDE, 12, 256) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed REC Vandermonde test\n"); + log_fatal(EINTERNAL, "Failed REC Vandermonde test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_CAUCHY, 32, 256) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed GEN Cauchy test\n"); + log_fatal(EINTERNAL, "Failed GEN Cauchy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_rec(RAID_MODE_CAUCHY, 12, 256) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed REC Cauchy test\n"); + log_fatal(EINTERNAL, "Failed REC Cauchy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_CAUCHY, 1, 256) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed GEN Cauchy test single data disk\n"); + log_fatal(EINTERNAL, "Failed GEN Cauchy test single data disk\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 29c4d8aa..5c5b1330 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -564,7 +564,7 @@ void log_open(const char* file) break; default : /* LCOV_EXCL_START */ - log_fatal("Invalid type specifier '%c' in the log file.\n", *file); + log_fatal(EUSER, "Invalid type specifier '%c' in the log file.\n", *file); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -579,7 +579,7 @@ void log_open(const char* file) stdlog = fopen(path, mode); if (!stdlog) { /* LCOV_EXCL_START */ - log_fatal("Error opening the log file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error opening the log file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -590,7 +590,7 @@ void log_close(const char* file) if (stdlog != stdout && stdlog != stderr && stdlog != 0) { if (fclose(stdlog) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing the log file '%s'. %s.\n", file, strerror(errno)); + log_fatal(errno, "Error closing the log file '%s'. %s.\n", file, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1005,7 +1005,7 @@ int snapraid_main(int argc, char* argv[]) struct snapraid_filter* filter = filter_alloc_file(1, "", optarg); if (!filter) { /* LCOV_EXCL_START */ - log_fatal("Invalid filter specification '%s'\n", optarg); + log_fatal(EUSER, "Invalid filter specification '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1015,7 +1015,7 @@ int snapraid_main(int argc, char* argv[]) struct snapraid_filter* filter = filter_alloc_disk(1, optarg); if (!filter) { /* LCOV_EXCL_START */ - log_fatal("Invalid filter specification '%s'\n", optarg); + log_fatal(EUSER, "Invalid filter specification '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1051,7 +1051,7 @@ int snapraid_main(int argc, char* argv[]) plan = strtoul(optarg, &e, 10); if (!e || *e || plan > 100) { /* LCOV_EXCL_START */ - log_fatal("Invalid plan/percentage '%s'\n", optarg); + log_fatal(EUSER, "Invalid plan/percentage '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1061,7 +1061,7 @@ int snapraid_main(int argc, char* argv[]) olderthan = strtoul(optarg, &e, 10); if (!e || *e || olderthan > 1000) { /* LCOV_EXCL_START */ - log_fatal("Invalid number of days '%s'\n", optarg); + log_fatal(EUSER, "Invalid number of days '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1069,7 +1069,7 @@ int snapraid_main(int argc, char* argv[]) case 'w' : /* --bw-limit */ if (optarg == 0) { /* LCOV_EXCL_START */ - log_fatal("Missing bandwidth limit\n"); + log_fatal(EUSER, "Missing bandwidth limit\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1078,7 +1078,7 @@ int snapraid_main(int argc, char* argv[]) opt.bwlimit = strtoul(optarg, &e, 10); if (!e || e == optarg) { /* LCOV_EXCL_START */ - log_fatal("Invalid bandwidth limit '%s'\n", optarg); + log_fatal(EUSER, "Invalid bandwidth limit '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1092,7 +1092,7 @@ int snapraid_main(int argc, char* argv[]) opt.bwlimit *= 1000 * 1000 * 1000; } else if (e[0] != '\0') { /* LCOV_EXCL_START */ - log_fatal("Invalid bandwidth limit suffix '%s'\n", e); + log_fatal(EUSER, "Invalid bandwidth limit suffix '%s'\n", e); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1101,7 +1101,7 @@ int snapraid_main(int argc, char* argv[]) blockstart = strtoul(optarg, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ - log_fatal("Invalid start position '%s'\n", optarg); + log_fatal(EUSER, "Invalid start position '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1110,7 +1110,7 @@ int snapraid_main(int argc, char* argv[]) blockcount = strtoul(optarg, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ - log_fatal("Invalid count number '%s'\n", optarg); + log_fatal(EUSER, "Invalid count number '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1119,7 +1119,7 @@ int snapraid_main(int argc, char* argv[]) opt.io_error_limit = strtoul(optarg, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ - log_fatal("Invalid error limit number '%s'\n", optarg); + log_fatal(EUSER, "Invalid error limit number '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1127,7 +1127,7 @@ int snapraid_main(int argc, char* argv[]) case 'i' : if (import_timestamp) { /* LCOV_EXCL_START */ - log_fatal("Import directory '%s' already specified as '%s'\n", optarg, import_timestamp); + log_fatal(EUSER, "Import directory '%s' already specified as '%s'\n", optarg, import_timestamp); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1136,7 +1136,7 @@ int snapraid_main(int argc, char* argv[]) case OPT_TEST_IMPORT_CONTENT : if (import_content) { /* LCOV_EXCL_START */ - log_fatal("Import directory '%s' already specified as '%s'\n", optarg, import_content); + log_fatal(EUSER, "Import directory '%s' already specified as '%s'\n", optarg, import_content); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1145,7 +1145,7 @@ int snapraid_main(int argc, char* argv[]) case 'l' : if (log_file) { /* LCOV_EXCL_START */ - log_fatal("Log file '%s' already specified as '%s'\n", optarg, log_file); + log_fatal(EUSER, "Log file '%s' already specified as '%s'\n", optarg, log_file); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1317,7 +1317,7 @@ int snapraid_main(int argc, char* argv[]) opt.io_cache = atoi(optarg); if (opt.io_cache != 1 && (opt.io_cache < IO_MIN || opt.io_cache > IO_MAX)) { /* LCOV_EXCL_START */ - log_fatal("The IO cache should be between %u and %u.\n", IO_MIN, IO_MAX); + log_fatal(EUSER, "The IO cache should be between %u and %u.\n", IO_MIN, IO_MAX); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1369,7 +1369,7 @@ int snapraid_main(int argc, char* argv[]) FMT_MODE = FMT_PATH; else { /* LCOV_EXCL_START */ - log_fatal("Unknown format '%s'\n", optarg); + log_fatal(EUSER, "Unknown format '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1379,7 +1379,7 @@ int snapraid_main(int argc, char* argv[]) break; default : /* LCOV_EXCL_START */ - log_fatal("Unknown option '%c'\n", (char)c); + log_fatal(EUSER, "Unknown option '%c'\n", (char)c); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1450,7 +1450,7 @@ int snapraid_main(int argc, char* argv[]) operation = OPERATION_PROBE; } else { /* LCOV_EXCL_START */ - log_fatal("Unknown command '%s'\n", argv[optind]); + log_fatal(EUSER, "Unknown command '%s'\n", argv[optind]); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1462,7 +1462,7 @@ int snapraid_main(int argc, char* argv[]) default : if (opt.auditonly) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -a, --audit-only with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -a, --audit-only with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1480,7 +1480,7 @@ int snapraid_main(int argc, char* argv[]) default : if (opt.force_device) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -D, --force-device with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -D, --force-device with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1494,7 +1494,7 @@ int snapraid_main(int argc, char* argv[]) default : if (opt.force_nocopy) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -N, --force-nocopy with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -N, --force-nocopy with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1506,21 +1506,21 @@ int snapraid_main(int argc, char* argv[]) default : if (opt.prehash) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -h, --pre-hash with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -h, --pre-hash with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (opt.force_full) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -F, --force-full with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -F, --force-full with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (opt.force_realloc) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -R, --force-realloc with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -R, --force-realloc with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1528,28 +1528,28 @@ int snapraid_main(int argc, char* argv[]) if (opt.force_full && opt.force_nocopy) { /* LCOV_EXCL_START */ - log_fatal("You cannot use the -F, --force-full and -N, --force-nocopy options simultaneously\n"); + log_fatal(EUSER, "You cannot use the -F, --force-full and -N, --force-nocopy options simultaneously\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (opt.force_realloc && opt.force_nocopy) { /* LCOV_EXCL_START */ - log_fatal("You cannot use the -R, --force-realloc and -N, --force-nocopy options simultaneously\n"); + log_fatal(EUSER, "You cannot use the -R, --force-realloc and -N, --force-nocopy options simultaneously\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (opt.force_realloc && opt.force_full) { /* LCOV_EXCL_START */ - log_fatal("You cannot use the -R, --force-realloc and -F, --force-full options simultaneously\n"); + log_fatal(EUSER, "You cannot use the -R, --force-realloc and -F, --force-full options simultaneously\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (opt.prehash && opt.force_nocopy) { /* LCOV_EXCL_START */ - log_fatal("You cannot use the -h, --pre-hash and -N, --force-nocopy options simultaneously\n"); + log_fatal(EUSER, "You cannot use the -h, --pre-hash and -N, --force-nocopy options simultaneously\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1562,7 +1562,7 @@ int snapraid_main(int argc, char* argv[]) default : if (!tommy_list_empty(&filterlist_disk)) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -d, --filter-disk with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -d, --filter-disk with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1571,19 +1571,19 @@ int snapraid_main(int argc, char* argv[]) case OPERATION_SPINDOWN : if (!tommy_list_empty(&filterlist_file)) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -f, --filter with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -f, --filter with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (filter_missing != 0) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -m, --filter-missing with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -m, --filter-missing with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (filter_error != 0) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -e, --filter-error with the '%s' command\n", command); + log_fatal(EUSER, "You cannot use -e, --filter-error with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1593,7 +1593,7 @@ int snapraid_main(int argc, char* argv[]) /* because we don't keep the information on what disk is the error */ if (filter_error != 0 && !tommy_list_empty(&filterlist_disk)) { /* LCOV_EXCL_START */ - log_fatal("You cannot use -e, --filter-error and -d, --filter-disk simultaneously\n"); + log_fatal(EUSER, "You cannot use -e, --filter-error and -d, --filter-disk simultaneously\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1605,7 +1605,7 @@ int snapraid_main(int argc, char* argv[]) default : if (import_timestamp != 0 || import_content != 0) { /* LCOV_EXCL_START */ - log_fatal("Import not allowed with the '%s' command\n", command); + log_fatal(EUSER, "Import not allowed with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1732,10 +1732,10 @@ int snapraid_main(int argc, char* argv[]) if (lock == -1) { /* LCOV_EXCL_START */ if (errno != EWOULDBLOCK) { - log_fatal("Failed to create the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); + log_fatal(errno, "Failed to create the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); } else { - log_fatal("The lock file '%s' is already in use!\n", state.lockfile); - log_fatal("SnapRAID is already in use!\n"); + log_fatal(errno, "The lock file '%s' is already in use!\n", state.lockfile); + log_fatal(errno, "SnapRAID is already in use!\n"); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1804,7 +1804,7 @@ int snapraid_main(int argc, char* argv[]) ret = system(run); /* ignore error */ if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error executing command '%s'.\n", run); + log_fatal(errno, "Error executing command '%s'.\n", run); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1951,7 +1951,7 @@ int snapraid_main(int argc, char* argv[]) if (!opt.skip_lock && state.lockfile[0]) { if (lock_unlock(lock) == -1) { /* LCOV_EXCL_START */ - log_fatal("Failed to close the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); + log_fatal(errno, "Failed to close the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/state.c b/cmdline/state.c index 8c855a9d..d432b612 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -228,7 +228,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (state->raid_mode == RAID_MODE_VANDERMONDE) { if (state->level > 3) { /* LCOV_EXCL_START */ - log_fatal("Using z-parity limits you to a maximum of 3 parities.\n"); + log_fatal(EUSER, "Using z-parity limits you to a maximum of 3 parities.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STIO */ } @@ -237,7 +237,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (state->parity[l].split_mac == 0) { /* LCOV_EXCL_START */ - log_fatal("Missing '%s' specification in '%s'\n", lev_config_name(l), path); + log_fatal(EUSER, "Missing '%s' specification in '%s'\n", lev_config_name(l), path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -245,7 +245,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (tommy_list_empty(&state->contentlist)) { /* LCOV_EXCL_START */ - log_fatal("Missing 'content' specification in '%s'\n", path); + log_fatal(EUSER, "Missing 'content' specification in '%s'\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -258,7 +258,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (s = 0; s < state->parity[l].split_mac; ++s) { if (pathcmp(state->parity[l].split_map[s].path, content->content) == 0) { /* LCOV_EXCL_START */ - log_fatal("Same path used for '%s' and 'content' as '%s'\n", lev_config_name(l), content->content); + log_fatal(EUSER, "Same path used for '%s' and 'content' as '%s'\n", lev_config_name(l), content->content); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -279,10 +279,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t #ifdef _WIN32 if (disk->device == 0) { /* LCOV_EXCL_START */ - log_fatal("Disk '%s' has a zero serial number.\n", disk->dir); - log_fatal("This is not necessarily wrong, but for using SnapRAID\n"); - log_fatal("it's better to change the serial number of the disk.\n"); - log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); + log_fatal(ESOFT, "Disk '%s' has a zero serial number.\n", disk->dir); + log_fatal(ESOFT, "This is not necessarily wrong, but for using SnapRAID\n"); + log_fatal(ESOFT, "it's better to change the serial number of the disk.\n"); + log_fatal(ESOFT, "Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -296,18 +296,18 @@ static void state_config_check(struct snapraid_state* state, const char* path, t /* and we DON'T mark the disk to be skipped */ /* because we want to use these disks */ if (!state->opt.no_warnings) - log_fatal("DANGER! Ignoring that disks '%s' and '%s' are on the same device\n", disk->name, other->name); + log_fatal(EUSER, "DANGER! Ignoring that disks '%s' and '%s' are on the same device\n", disk->name, other->name); } else { /* LCOV_EXCL_START */ - log_fatal("Disks '%s' and '%s' are on the same device.\n", disk->dir, other->dir); + log_fatal(ESOFT, "Disks '%s' and '%s' are on the same device.\n", disk->dir, other->dir); #ifdef _WIN32 - log_fatal("Both have the serial number '%" PRIx64 "'.\n", disk->device); - log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - log_fatal("to change one of the disk serial.\n"); + log_fatal(ESOFT, "Both have the serial number '%" PRIx64 "'.\n", disk->device); + log_fatal(ESOFT, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal(ESOFT, "to change one of the disk serial.\n"); #endif /* in "fix" we allow to continue anyway */ if (strcmp(state->command, "fix") == 0) { - log_fatal("You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); + log_fatal(ESOFT, "You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -328,14 +328,14 @@ static void state_config_check(struct snapraid_state* state, const char* path, t /* and we DON'T mark the disk to be skipped */ /* because we want to use these disks */ if (!state->opt.no_warnings) - log_fatal("DANGER! Ignoring that disks '%s' and %s '%s' are on the same device\n", disk->dir, lev_name(l), state->parity[l].split_map[s].path); + log_fatal(EUSER, "DANGER! Ignoring that disks '%s' and %s '%s' are on the same device\n", disk->dir, lev_name(l), state->parity[l].split_map[s].path); } else { /* LCOV_EXCL_START */ - log_fatal("Disk '%s' and %s '%s' are on the same device.\n", disk->dir, lev_name(l), state->parity[l].split_map[s].path); + log_fatal(ESOFT, "Disk '%s' and %s '%s' are on the same device.\n", disk->dir, lev_name(l), state->parity[l].split_map[s].path); #ifdef _WIN32 - log_fatal("Both have the serial number '%" PRIx64 "'.\n", disk->device); - log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - log_fatal("to change one of the disk serial.\n"); + log_fatal(ESOFT, "Both have the serial number '%" PRIx64 "'.\n", disk->device); + log_fatal(ESOFT, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal(ESOFT, "to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -347,11 +347,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (state->pool[0] != 0 && disk->device == state->pool_device) { /* LCOV_EXCL_START */ - log_fatal("Disk '%s' and pool '%s' are on the same device.\n", disk->dir, state->pool); + log_fatal(ESOFT, "Disk '%s' and pool '%s' are on the same device.\n", disk->dir, state->pool); #ifdef _WIN32 - log_fatal("Both have the serial number '%" PRIx64 "'.\n", disk->device); - log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - log_fatal("to change one of the disk serial.\n"); + log_fatal(ESOFT, "Both have the serial number '%" PRIx64 "'.\n", disk->device); + log_fatal(ESOFT, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal(ESOFT, "to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -372,10 +372,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t #ifdef _WIN32 if (state->parity[l].split_map[s].device == 0) { /* LCOV_EXCL_START */ - log_fatal("Disk '%s' has a zero serial number.\n", state->parity[l].split_map[s].path); - log_fatal("This is not necessarily wrong, but for using SnapRAID\n"); - log_fatal("it's better to change the serial number of the disk.\n"); - log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); + log_fatal(ESOFT, "Disk '%s' has a zero serial number.\n", state->parity[l].split_map[s].path); + log_fatal(ESOFT, "This is not necessarily wrong, but for using SnapRAID\n"); + log_fatal(ESOFT, "it's better to change the serial number of the disk.\n"); + log_fatal(ESOFT, "Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -389,18 +389,18 @@ static void state_config_check(struct snapraid_state* state, const char* path, t /* and we DON'T mark the disk to be skipped */ /* because we want to use these disks */ if (!state->opt.no_warnings) - log_fatal("DANGER! Skipping parities '%s' and '%s' on the same device\n", lev_config_name(l), lev_config_name(j)); + log_fatal(EUSER, "DANGER! Skipping parities '%s' and '%s' on the same device\n", lev_config_name(l), lev_config_name(j)); } else { /* LCOV_EXCL_START */ - log_fatal("Parity '%s' and '%s' are on the same device.\n", state->parity[l].split_map[s].path, state->parity[j].split_map[t].path); + log_fatal(ESOFT, "Parity '%s' and '%s' are on the same device.\n", state->parity[l].split_map[s].path, state->parity[j].split_map[t].path); #ifdef _WIN32 - log_fatal("Both have the serial number '%" PRIx64 "'.\n", state->parity[l].split_map[s].device); - log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - log_fatal("to change one of the disk serial.\n"); + log_fatal(ESOFT, "Both have the serial number '%" PRIx64 "'.\n", state->parity[l].split_map[s].device); + log_fatal(ESOFT, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal(ESOFT, "to change one of the disk serial.\n"); #endif /* in "fix" we allow to continue anyway */ if (strcmp(state->command, "fix") == 0) { - log_fatal("You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); + log_fatal(ESOFT, "You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -411,11 +411,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (state->pool[0] != 0 && state->pool_device == state->parity[l].split_map[s].device) { /* LCOV_EXCL_START */ - log_fatal("Pool '%s' and parity '%s' are on the same device.\n", state->pool, state->parity[l].split_map[s].path); + log_fatal(ESOFT, "Pool '%s' and parity '%s' are on the same device.\n", state->pool, state->parity[l].split_map[s].path); #ifdef _WIN32 - log_fatal("Both have the serial number '%" PRIx64 "'.\n", state->pool_device); - log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - log_fatal("to change one of the disk serial.\n"); + log_fatal(ESOFT, "Both have the serial number '%" PRIx64 "'.\n", state->pool_device); + log_fatal(ESOFT, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal(ESOFT, "to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -429,10 +429,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (!state->opt.skip_device) { if (state->pool[0] != 0 && state->pool_device == 0) { /* LCOV_EXCL_START */ - log_fatal("Disk '%s' has a zero serial number.\n", state->pool); - log_fatal("This is not necessarily wrong, but for using SnapRAID\n"); - log_fatal("it's better to change the serial number of the disk.\n"); - log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); + log_fatal(ESOFT, "Disk '%s' has a zero serial number.\n", state->pool); + log_fatal(ESOFT, "This is not necessarily wrong, but for using SnapRAID\n"); + log_fatal(ESOFT, "it's better to change the serial number of the disk.\n"); + log_fatal(ESOFT, "Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -452,7 +452,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (j = i->next; j != 0; j = j->next) { struct snapraid_content* other = j->data; if (content->device == other->device) { - log_fatal("WARNING! Content files on the same disk: '%s' and '%s'.\n", content->content, other->content); + log_fatal(ESOFT, "WARNING! Content files on the same disk: '%s' and '%s'.\n", content->content, other->content); break; } } @@ -466,7 +466,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (content_count < state->level + 1) { /* LCOV_EXCL_START */ - log_fatal("You must have at least %d 'content' files in different disks.\n", state->level + 1); + log_fatal(EUSER, "You must have at least %d 'content' files in different disks.\n", state->level + 1); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -478,11 +478,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t #endif if (state->raid_mode == RAID_MODE_CAUCHY && !state->opt.no_warnings) { if (state->level == 3) { - log_fatal("WARNING! Your CPU doesn't have a fast implementation for triple parity.\n"); - log_fatal("WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'.\n"); + log_fatal(ESOFT, "WARNING! Your CPU doesn't have a fast implementation for triple parity.\n"); + log_fatal(ESOFT, "WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'.\n"); } else if (state->level > 3) { - log_fatal("WARNING! Your CPU doesn't have a fast implementation beyond triple parity.\n"); - log_fatal("WARNING! It's recommended to reduce the parity levels to triple parity.\n"); + log_fatal(ESOFT, "WARNING! Your CPU doesn't have a fast implementation beyond triple parity.\n"); + log_fatal(ESOFT, "WARNING! It's recommended to reduce the parity levels to triple parity.\n"); } } @@ -502,7 +502,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t break; if (l == state->level) { /* LCOV_EXCL_START */ - log_fatal("Option -d, --filter-disk %s doesn't match any data or parity disk.\n", filter->pattern); + log_fatal(EUSER, "Option -d, --filter-disk %s doesn't match any data or parity disk.\n", filter->pattern); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -579,11 +579,11 @@ void state_config(struct snapraid_state* state, const char* path, const char* co return; } - log_fatal("No configuration file found at '%s'\n", path); + log_fatal(errno, "No configuration file found at '%s'\n", path); } else if (errno == EACCES) { - log_fatal("You do not have rights to access the configuration file '%s'\n", path); + log_fatal(errno, "You do not have rights to access the configuration file '%s'\n", path); } else { - log_fatal("Error opening the configuration file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error opening the configuration file '%s'. %s.\n", path, strerror(errno)); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -604,7 +604,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgettok(f, tag, sizeof(tag)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Error reading the configuration file '%s' at line %u\n", path, line); + log_fatal(EUSER, "Error reading the configuration file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -619,26 +619,26 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetu32(f, &state->block_size); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'blocksize' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (state->block_size < 1) { /* LCOV_EXCL_START */ - log_fatal("Too small 'blocksize' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Too small 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (state->block_size > 16 * KIBI) { /* LCOV_EXCL_START */ - log_fatal("Too big 'blocksize' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Too big 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } /* check if it's a power of 2 */ if ((state->block_size & (state->block_size - 1)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Not power of 2 'blocksize' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Not power of 2 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -651,26 +651,26 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetu32(f, &hash_size); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'hashsize' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'hashsize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (hash_size < 2) { /* LCOV_EXCL_START */ - log_fatal("Too small 'hashsize' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Too small 'hashsize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (hash_size > HASH_MAX) { /* LCOV_EXCL_START */ - log_fatal("Too big 'hashsize' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Too big 'hashsize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } /* check if it's a power of 2 */ if ((hash_size & (hash_size - 1)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Not power of 2 'hashsize' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Not power of 2 'hashsize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -686,7 +686,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (state->parity[level].split_mac != 0) { /* LCOV_EXCL_START */ - log_fatal("Multiple '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal(EUSER, "Multiple '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -694,14 +694,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal(EUSER, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal(EUSER, "Empty '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -710,7 +710,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (split_mac > SPLIT_MAX) { /* LCOV_EXCL_START */ - log_fatal("Too many files in '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal(EUSER, "Too many files in '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -746,14 +746,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co dev = 0; *uuid = 0; skip_access = 1; - log_fatal("DANGER! Skipping inaccessible parity disk '%s'...\n", tag); + log_fatal(errno, "DANGER! Skipping inaccessible parity disk '%s'...\n", tag); } else { /* LCOV_EXCL_START */ - log_fatal("Error accessing 'parity' dir '%s' specification in '%s' at line %u\n", device, path, line); + log_fatal(errno, "Error accessing 'parity' dir '%s' specification in '%s' at line %u\n", device, path, line); /* in "fix" we allow to continue anyway */ if (strcmp(state->command, "fix") == 0) { - log_fatal("You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); + log_fatal(errno, "You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -778,7 +778,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } else if (strcmp(tag, "share") == 0) { if (*state->share) { /* LCOV_EXCL_START */ - log_fatal("Multiple 'share' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Multiple 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -786,14 +786,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'share' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty 'share' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -804,7 +804,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (*state->pool) { /* LCOV_EXCL_START */ - log_fatal("Multiple 'pool' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Multiple 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -812,14 +812,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'pool' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty 'pool' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -829,7 +829,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* get the device of the directory containing the pool tree */ if (stat(buffer, &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing 'pool' dir '%s' specification in '%s' at line %u\n", buffer, path, line); + log_fatal(errno, "Error accessing 'pool' dir '%s' specification in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -845,21 +845,21 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'content' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (pathcmp(buffer, "/dev/null") == 0 || pathcmp(buffer, "NUL") == 0) { /* LCOV_EXCL_START */ - log_fatal("You cannot use the null device as 'content' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "You cannot use the null device as 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty 'content' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -872,7 +872,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (i) { /* LCOV_EXCL_START */ - log_fatal("Duplicate 'content' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Duplicate 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -890,10 +890,10 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (state->opt.skip_content_access) { /* use a fake device */ dev = 0; - log_fatal("WARNING! Skipping inaccessible content file '%s'...\n", buffer); + log_fatal(errno, "WARNING! Skipping inaccessible content file '%s'...\n", buffer); } else { /* LCOV_EXCL_START */ - log_fatal("Error accessing 'content' dir '%s' specification in '%s' at line %u\n", device, path, line); + log_fatal(errno, "Error accessing 'content' dir '%s' specification in '%s' at line %u\n", device, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -920,14 +920,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'data' name specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'data' name specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty 'data' name specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'data' name specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -937,14 +937,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, dir, sizeof(dir)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'data' dir specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'data' dir specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*dir) { /* LCOV_EXCL_START */ - log_fatal("Empty 'data' dir specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'data' dir specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -960,7 +960,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (i) { /* LCOV_EXCL_START */ - log_fatal("Duplicate 'data' name '%s' at line %u\n", buffer, line); + log_fatal(EUSER, "Duplicate 'data' name '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -990,14 +990,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co dev = 0; *uuid = 0; skip_access = 1; - log_fatal("DANGER! Skipping inaccessible data disk '%s'...\n", buffer); + log_fatal(errno, "DANGER! Skipping inaccessible data disk '%s'...\n", buffer); } else { /* LCOV_EXCL_START */ - log_fatal("Error accessing 'disk' '%s' specification in '%s' at line %u\n", dir, device, line); + log_fatal(errno, "Error accessing 'disk' '%s' specification in '%s' at line %u\n", dir, device, line); /* in "fix" we allow to continue anyway */ if (strcmp(state->command, "fix") == 0) { - log_fatal("You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); + log_fatal(errno, "You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1018,14 +1018,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'smartctl' name in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'smartctl' name in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty 'smartctl' name in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'smartctl' name in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1035,21 +1035,21 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, custom, sizeof(custom)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'smartctl' option in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'smartctl' option in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*custom) { /* LCOV_EXCL_START */ - log_fatal("Empty 'smartctl' option in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'smartctl' option in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (validate_smartctl(custom) != 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'smartctl' option in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'smartctl' option in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1058,7 +1058,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (lev_config_scan(buffer, &level, 0) == 0) { if (state->parity[level].smartctl[0] != 0) { /* LCOV_EXCL_START */ - log_fatal("Duplicate parity 'smartctl' '%s' at line %u\n", buffer, line); + log_fatal(EUSER, "Duplicate parity 'smartctl' '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1076,13 +1076,13 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (!disk) { /* LCOV_EXCL_START */ - log_fatal("Missing disk 'smartctl' '%s' at line %u\n", buffer, line); + log_fatal(EUSER, "Missing disk 'smartctl' '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (disk->smartctl[0] != 0) { /* LCOV_EXCL_START */ - log_fatal("Duplicate disk name '%s' at line %u\n", buffer, line); + log_fatal(EUSER, "Duplicate disk name '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1095,14 +1095,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'smartignore' name in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'smartignore' name in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty 'smartignore' name in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'smartignore' name in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1125,7 +1125,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (!disk) { /* LCOV_EXCL_START */ - log_fatal("Missing disk 'smartctl' '%s' at line %u\n", buffer, line); + log_fatal(EUSER, "Missing disk 'smartctl' '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1141,7 +1141,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'smartignore' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'smartignore' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1151,7 +1151,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (si == SMART_IGNORE_MAX) { /* LCOV_EXCL_START */ - log_fatal("Too many 'smartignore' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Too many 'smartignore' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1160,7 +1160,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (!e || *e) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'smartignore' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'smartignore' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1172,7 +1172,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (si == 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'smartignore' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'smartignore' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1182,13 +1182,13 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetu32(f, &temp); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'temp_limit' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'temp_limit' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (temp < 40 || temp > 70) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'temp_limit' temperature specification in '%s' at line %u. It must be between 40 and 70\n", path, line); + log_fatal(EUSER, "Invalid 'temp_limit' temperature specification in '%s' at line %u. It must be between 40 and 70\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1200,13 +1200,13 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetu32(f, &time); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'temp_sleep' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'temp_sleep' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (time < 3 || time > 120) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'temp_sleep' temperature specification in '%s' at line %u. It must be between 3 and 120\n", path, line); + log_fatal(EUSER, "Invalid 'temp_sleep' temperature specification in '%s' at line %u. It must be between 3 and 120\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1220,14 +1220,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'exclude' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'exclude' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty 'exclude' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'exclude' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1235,7 +1235,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co filter = filter_alloc_file(-1, "", buffer); if (!filter) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'exclude' specification '%s' in '%s' at line %u\n", buffer, path, line); + log_fatal(EUSER, "Invalid 'exclude' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1246,14 +1246,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'include' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'include' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty 'include' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'include' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1261,7 +1261,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co filter = filter_alloc_file(1, "", buffer); if (!filter) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'include' specification '%s' in '%s' at line %u\n", buffer, path, line); + log_fatal(EUSER, "Invalid 'include' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1272,14 +1272,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'autosave' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - log_fatal("Empty 'autosave' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Empty 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1288,7 +1288,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (!e || *e) { /* LCOV_EXCL_START */ - log_fatal("Invalid 'autosave' specification in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1301,13 +1301,13 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetline(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Invalid comment in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Invalid comment in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } } else { /* LCOV_EXCL_START */ - log_fatal("Invalid command '%s' in '%s' at line %u\n", tag, path, line); + log_fatal(EUSER, "Invalid command '%s' in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1322,7 +1322,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (c != '\n') { /* LCOV_EXCL_START */ - log_fatal("Extra data in '%s' at line %u\n", path, line); + log_fatal(EUSER, "Extra data in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1331,7 +1331,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error reading the configuration file '%s' at line %u\n", path, line); + log_fatal(errno, "Error reading the configuration file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1355,7 +1355,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* by default use a random hash seed */ if (randomize(state->hashseed, HASH_MAX) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to retrieve random values.\n"); + log_fatal(errno, "Failed to retrieve random values.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1548,7 +1548,7 @@ static void state_map(struct snapraid_state* state) disk = find_disk_by_name(state, map->name); if (disk == 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Mapping not found for '%s'\n", map->name); + log_fatal(EINTERNAL, "Internal inconsistency: Mapping not found for '%s'\n", map->name); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1567,7 +1567,7 @@ static void state_map(struct snapraid_state* state) if (map->uuid[0] != 0) { /* count the number of uuid change */ ++uuid_mismatch; - log_fatal("UUID change for disk '%s' from '%s' to '%s'\n", disk->name, map->uuid, disk->uuid); + log_fatal(ESOFT, "UUID change for disk '%s' from '%s' to '%s'\n", disk->name, map->uuid, disk->uuid); } else { /* no message here, because having a disk without */ /* UUID is the normal state of an empty disk */ @@ -1603,7 +1603,7 @@ static void state_map(struct snapraid_state* state) if (state->parity[l].split_map[s].uuid[0] != 0) { /* count the number of uuid change */ ++uuid_mismatch; - log_fatal("UUID change for parity '%s/%u' from '%s' to '%s'\n", lev_config_name(l), s, state->parity[l].split_map[s].uuid, uuid); + log_fatal(ESOFT, "UUID change for parity '%s/%u' from '%s' to '%s'\n", lev_config_name(l), s, state->parity[l].split_map[s].uuid, uuid); } /* update the uuid */ @@ -1618,11 +1618,11 @@ static void state_map(struct snapraid_state* state) if (!state->opt.force_uuid && uuid_mismatch > state->level) { /* LCOV_EXCL_START */ - log_fatal("Too many disks have changed UUIDs since the last 'sync'.\n"); - log_fatal("If this happened because you actually replaced them,\n"); - log_fatal("you can still '%s', using 'snapraid --force-uuid %s'.\n", state->command, state->command); - log_fatal("Alternatively, you may have misconfigured the disk mount points,\n"); - log_fatal("and you need to restore the mount points to the state of the latest sync.\n"); + log_fatal(ESOFT, "Too many disks have changed UUIDs since the last 'sync'.\n"); + log_fatal(ESOFT, "If this happened because you actually replaced them,\n"); + log_fatal(ESOFT, "you can still '%s', using 'snapraid --force-uuid %s'.\n", state->command, state->command); + log_fatal(ESOFT, "Alternatively, you may have misconfigured the disk mount points,\n"); + log_fatal(ESOFT, "and you need to restore the mount points to the state of the latest sync.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1639,7 +1639,7 @@ static void state_map(struct snapraid_state* state) /* ensure to don't go over the limit of the RAID engine */ if (diskcount > RAID_DATA_MAX) { /* LCOV_EXCL_START */ - log_fatal("Too many data disks. Maximum allowed is %u.\n", RAID_DATA_MAX); + log_fatal(ESOFT, "Too many data disks. Maximum allowed is %u.\n", RAID_DATA_MAX); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1651,15 +1651,15 @@ static void state_map(struct snapraid_state* state) if (!state->opt.no_warnings) { /* intentionally use log_fatal() instead of log_error() to give more visibility at the warning */ if (diskcount >= 36 && state->level < 6) { - log_fatal("WARNING! For %u disks, it's recommended to use six parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %u disks, it's recommended to use six parity levels.\n", diskcount); } else if (diskcount >= 29 && state->level < 5) { - log_fatal("WARNING! For %u disks, it's recommended to use five parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %u disks, it's recommended to use five parity levels.\n", diskcount); } else if (diskcount >= 22 && state->level < 4) { - log_fatal("WARNING! For %u disks, it's recommended to use four parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %u disks, it's recommended to use four parity levels.\n", diskcount); } else if (diskcount >= 15 && state->level < 3) { - log_fatal("WARNING! For %u disks, it's recommended to use three parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %u disks, it's recommended to use three parity levels.\n", diskcount); } else if (diskcount >= 5 && state->level < 2) { - log_fatal("WARNING! For %u disks, it's recommended to use two parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %u disks, it's recommended to use two parity levels.\n", diskcount); } } } @@ -1681,7 +1681,7 @@ void state_refresh(struct snapraid_state* state) disk = find_disk_by_name(state, map->name); if (disk == 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Mapping not found for '%s'\n", map->name); + log_fatal(EINTERNAL, "Internal inconsistency: Mapping not found for '%s'\n", map->name); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1689,7 +1689,7 @@ void state_refresh(struct snapraid_state* state) ret = fsinfo(disk->dir, 0, 0, &total_space, &free_space, disk->fstype, sizeof(disk->fstype), disk->fslabel, sizeof(disk->fslabel)); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing disk '%s' to retrieve file-system info. %s.\n", disk->dir, strerror(errno)); + log_fatal(errno, "Error accessing disk '%s' to retrieve file-system info. %s.\n", disk->dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1721,7 +1721,7 @@ void state_refresh(struct snapraid_state* state) ret = fsinfo(split->path, 0, 0, &total_space, &free_space, split->fstype, sizeof(split->fstype), split->fslabel, sizeof(split->fslabel)); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error accessing file '%s' to retrieve file-system info. %s.\n", split->path, strerror(errno)); + log_fatal(errno, "Error accessing file '%s' to retrieve file-system info. %s.\n", split->path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1772,13 +1772,13 @@ static void state_content_check(struct snapraid_state* state, const char* path) struct snapraid_map* other = j->data; if (strcmp(map->name, other->name) == 0) { /* LCOV_EXCL_START */ - log_fatal("Conflicting 'map' disk specification in '%s'\n", path); + log_fatal(ECONTENT, "Conflicting 'map' disk specification in '%s'\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (map->position == other->position) { /* LCOV_EXCL_START */ - log_fatal("Conflicting 'map' index specification in '%s'\n", path); + log_fatal(ECONTENT, "Conflicting 'map' index specification in '%s'\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1876,24 +1876,24 @@ static void decoding_error(const char* path, STREAM* f) if (seof(f)) { /* LCOV_EXCL_START */ - log_fatal("Unexpected end of content file '%s' at offset %" PRIi64 "\n", path, stell(f)); - log_fatal("This content file is truncated. Please use an alternate copy.\n"); + log_fatal(ECONTENT, "Unexpected end of content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal(ECONTENT, "This content file is truncated. Please use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal(errno, "Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - log_fatal("Error decoding '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal(ECONTENT, "Error decoding '%s' at offset %" PRIi64 "\n", path, stell(f)); if (sdeplete(f, buf) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to flush content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal(errno, "Failed to flush content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1908,11 +1908,11 @@ static void decoding_error(const char* path, STREAM* f) crc_stored = crc32c(crc_stored, buf, 4); if (crc_computed != crc_stored) { - log_fatal("CRC mismatch in '%s'\n", path); - log_fatal("This content file is damaged! Please use an alternate copy.\n"); + log_fatal(ECONTENT, "CRC mismatch in '%s'\n", path); + log_fatal(ECONTENT, "This content file is damaged! Please use an alternate copy.\n"); exit(EXIT_FAILURE); } else { - log_fatal("The CRC of the file is correct!\n"); + log_fatal(ECONTENT, "The CRC of the file is correct!\n"); } } @@ -1946,7 +1946,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (ret < 0) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Invalid header!\n"); + log_fatal(ECONTENT, "Invalid header!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1968,10 +1968,10 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_START */ if (memcmp(buffer, "SNAPCNT", 7) != 0) { decoding_error(path, f); - log_fatal("Invalid header!\n"); + log_fatal(ECONTENT, "Invalid header!\n"); os_abort(); } else { - log_fatal("The content file '%s' was generated with a newer version of SnapRAID!\n", path); + log_fatal(ECONTENT, "The content file '%s' was generated with a newer version of SnapRAID!\n", path); exit(EXIT_FAILURE); } /* LCOV_EXCL_STOP */ @@ -2002,7 +2002,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: File mapping index out of range\n"); + log_fatal(EINTERNAL, "Internal inconsistency: File mapping index out of range\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2019,7 +2019,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (state->block_size == 0) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Zero blocksize\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Zero blocksize\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2028,7 +2028,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (v_size / state->block_size > blockmax) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: File size too big!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: File size too big!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2073,7 +2073,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (!*sub) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Null file!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Null file!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2115,7 +2115,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (v_idx + v_count > file->blockmax) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Block number out of range\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Block number out of range\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2123,7 +2123,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (v_pos + v_count > blockmax) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Block size %u/%u!\n", blockmax, v_pos + v_count); + log_fatal(EINTERNAL, "Internal inconsistency: Block size %u/%u!\n", blockmax, v_pos + v_count); os_abort(); /* LCOV_EXCL_START */ } @@ -2149,7 +2149,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S default : /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Invalid block type!\n"); + log_fatal(ECONTENT, "Invalid block type!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2247,7 +2247,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (v_pos + v_count > blockmax) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Info size %u/%u!\n", blockmax, v_pos + v_count); + log_fatal(EINTERNAL, "Internal inconsistency: Info size %u/%u!\n", blockmax, v_pos + v_count); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2284,7 +2284,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (rehash && state->prevhash == HASH_UNDEFINED) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Missing previous checksum!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Missing previous checksum!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2303,7 +2303,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (!info) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Missing info!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Missing info!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2327,7 +2327,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Hole mapping index out of range\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Hole mapping index out of range\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2350,7 +2350,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (v_pos + v_count > blockmax) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Hole size %u/%u!\n", blockmax, v_pos + v_count); + log_fatal(EINTERNAL, "Internal inconsistency: Hole size %u/%u!\n", blockmax, v_pos + v_count); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2410,7 +2410,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S default : /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Invalid hole type!\n"); + log_fatal(ECONTENT, "Invalid hole type!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2427,7 +2427,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Symlink mapping index out of range\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Symlink mapping index out of range\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2444,7 +2444,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (!*sub) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Null symlink!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Null symlink!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2478,7 +2478,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Hardlink mapping index out of range!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Hardlink mapping index out of range!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2495,7 +2495,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (!*sub) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Null hardlink!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Null hardlink!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2511,7 +2511,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (!*linkto) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Empty hardlink '%s'!\n", sub); + log_fatal(EINTERNAL, "Internal inconsistency: Empty hardlink '%s'!\n", sub); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2536,7 +2536,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Dir mapping index ouf of range!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Dir mapping index ouf of range!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2553,7 +2553,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (!*sub) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Internal inconsistency: Null dir!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Null dir!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2584,7 +2584,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S default : /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Invalid checksum!\n"); + log_fatal(ECONTENT, "Invalid checksum!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2614,7 +2614,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S default : /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Invalid checksum!\n"); + log_fatal(ECONTENT, "Invalid checksum!\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2641,7 +2641,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (block_size == 0) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Zero 'blocksize' specification in the content file!\n"); + log_fatal(ECONTENT, "Zero 'blocksize' specification in the content file!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2654,8 +2654,8 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (block_size != state->block_size) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Mismatching 'blocksize' specification in the content file!\n"); - log_fatal("Please restore the 'blocksize' value in the configuration file to '%u'\n", block_size / KIBI); + log_fatal(EUSER, "Mismatching 'blocksize' specification in the content file!\n"); + log_fatal(EUSER, "Please restore the 'blocksize' value in the configuration file to '%u'\n", block_size / KIBI); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2673,7 +2673,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (hash_size < 2 || hash_size > HASH_MAX) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Invalid 'hashsize' specification in the content file!\n"); + log_fatal(ECONTENT, "Invalid 'hashsize' specification in the content file!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2686,8 +2686,8 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if ((int)hash_size != BLOCK_HASH_SIZE) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Mismatching 'hashsize' specification in the content file!\n"); - log_fatal("Please restore the 'hashsize' value in the configuration file to '%u'\n", hash_size); + log_fatal(EUSER, "Mismatching 'hashsize' specification in the content file!\n"); + log_fatal(EUSER, "Please restore the 'hashsize' value in the configuration file to '%u'\n", hash_size); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2769,7 +2769,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* search by UUID if renamed */ disk = find_disk_by_uuid(state, uuid); if (disk) { - log_fatal("WARNING! Renaming disk '%s' to '%s'\n", buffer, disk->name); + log_fatal(EUSER, "WARNING! Renaming disk '%s' to '%s'\n", buffer, disk->name); /* write the new state with the new name */ state->need_write = 1; @@ -2778,11 +2778,11 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (!disk) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Disk '%s' with uuid '%s' not present in the configuration file!\n", buffer, uuid); - log_fatal("If you have removed it from the configuration file, please restore it\n"); + log_fatal(EUSER, "Disk '%s' with uuid '%s' not present in the configuration file!\n", buffer, uuid); + log_fatal(EUSER, "If you have removed it from the configuration file, please restore it\n"); /* if it's a command without UUID, it cannot autorename using UUID */ if (state->opt.skip_disk_access) - log_fatal("If you have renamed it, run 'sync' to update the new name\n"); + log_fatal(EUSER, "If you have renamed it, run 'sync' to update the new name\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2838,7 +2838,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (v_level >= LEV_MAX) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Invalid parity level '%u' in the configuration file!\n", v_level); + log_fatal(ECONTENT, "Invalid parity level '%u' in the configuration file!\n", v_level); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2913,7 +2913,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (v_level >= LEV_MAX) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Invalid parity level '%u' in the configuration file!\n", v_level); + log_fatal(ECONTENT, "Invalid parity level '%u' in the configuration file!\n", v_level); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2975,14 +2975,14 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (v_size != 0) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Parity '%s' misses used file '%u'!\n", lev_config_name(v_level), s); - log_fatal("If you have removed it from the configuration file, please restore it\n"); + log_fatal(EUSER, "Parity '%s' misses used file '%u'!\n", lev_config_name(v_level), s); + log_fatal(EUSER, "If you have removed it from the configuration file, please restore it\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } /* otherwise we can drop it */ - log_fatal("WARNING! Dropping from '%s' unused split '%u'\n", lev_config_name(v_level), s); + log_fatal(EUSER, "WARNING! Dropping from '%s' unused split '%u'\n", lev_config_name(v_level), s); } else { char parity_name[64]; @@ -3017,8 +3017,8 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (ret < 0) { /* LCOV_EXCL_START */ /* here don't call decoding_error() because it's too late to get the crc */ - log_fatal("Error reading the CRC in '%s' at offset %" PRIi64 "\n", path, stell(f)); - log_fatal("This content file is damaged! Use an alternate copy.\n"); + log_fatal(errno, "Error reading the CRC in '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal(errno, "This content file is damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3026,8 +3026,8 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (crc_stored != crc_computed) { /* LCOV_EXCL_START */ /* here don't call decoding_error() because it's too late to get the crc */ - log_fatal("CRC mismatch in '%s'\n", path); - log_fatal("The content file is damaged! Please use an alternate copy.\n"); + log_fatal(ECONTENT, "CRC mismatch in '%s'\n", path); + log_fatal(ECONTENT, "The content file is damaged! Please use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3036,7 +3036,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S } else { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal("Invalid command '%c'!\n", (char)c); + log_fatal(ECONTENT, "Invalid command '%c'!\n", (char)c); os_abort(); /* LCOV_EXCL_STOP */ } @@ -3046,15 +3046,15 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal(errno, "Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!crc_checked) { /* LCOV_EXCL_START */ - log_fatal("Reached the end of '%s' without finding the expected CRC\n", path); - log_fatal("This content file is truncated or damaged! Use an alternate copy.\n"); + log_fatal(ECONTENT, "Reached the end of '%s' without finding the expected CRC\n", path); + log_fatal(ECONTENT, "This content file is truncated or damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3065,9 +3065,9 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* check that the stored parity size matches the loaded state */ if (blockmax != parity_allocated_size(state)) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Parity size %u/%u in '%s' at offset %" PRIi64 "\n", blockmax, parity_allocated_size(state), path, stell(f)); + log_fatal(EINTERNAL, "Internal inconsistency: Parity size %u/%u in '%s' at offset %" PRIi64 "\n", blockmax, parity_allocated_size(state), path, stell(f)); if (state->opt.skip_content_check) { - log_fatal("Overriding.\n"); + log_fatal(ECONTENT, "Overriding.\n"); blockmax = parity_allocated_size(state); } else { exit(EXIT_FAILURE); @@ -3156,7 +3156,7 @@ static void* state_write_thread(void* arg) if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3170,14 +3170,14 @@ static void* state_write_thread(void* arg) sputc('m', f); } else { /* LCOV_EXCL_START */ - log_fatal("Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); + log_fatal(EINTERNAL, "Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); return context; /* LCOV_EXCL_STOP */ } swrite(state->hashseed, HASH_MAX, f); if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3195,14 +3195,14 @@ static void* state_write_thread(void* arg) sputc('m', f); } else { /* LCOV_EXCL_START */ - log_fatal("Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); + log_fatal(EINTERNAL, "Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); return context; /* LCOV_EXCL_STOP */ } swrite(state->prevhashseed, HASH_MAX, f); if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3218,7 +3218,7 @@ static void* state_write_thread(void* arg) disk = find_disk_by_name(state, map->name); if (!disk) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Unmapped disk '%s'\n", map->name); + log_fatal(EINTERNAL, "Internal inconsistency: Unmapped disk '%s'\n", map->name); return context; /* LCOV_EXCL_STOP */ } @@ -3242,7 +3242,7 @@ static void* state_write_thread(void* arg) } if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3281,7 +3281,7 @@ static void* state_write_thread(void* arg) } if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3322,7 +3322,7 @@ static void* state_write_thread(void* arg) sputbs(file->sub, f); if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3358,7 +3358,7 @@ static void* state_write_thread(void* arg) break; default : /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: State for block %u state %u\n", v_pos, v_state); + log_fatal(EINTERNAL, "Internal inconsistency: State for block %u state %u\n", v_pos, v_state); return context; /* LCOV_EXCL_STOP */ } @@ -3377,7 +3377,7 @@ static void* state_write_thread(void* arg) if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3409,7 +3409,7 @@ static void* state_write_thread(void* arg) sputbs(slink->linkto, f); if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3424,7 +3424,7 @@ static void* state_write_thread(void* arg) sputbs(dir->sub, f); if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3437,7 +3437,7 @@ static void* state_write_thread(void* arg) sputb32(disk->mapping_idx, f); if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3481,7 +3481,7 @@ static void* state_write_thread(void* arg) if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3550,7 +3550,7 @@ static void* state_write_thread(void* arg) if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3564,7 +3564,7 @@ static void* state_write_thread(void* arg) /* flush data written to the disk */ if (sflush(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s' (in flush before crc). %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s' (in flush before crc). %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3576,9 +3576,9 @@ static void* state_write_thread(void* arg) /* with the one of the data written to the stream */ if (crc != scrc_stream(f)) { /* LCOV_EXCL_START */ - log_fatal("CRC mismatch while writing the content stream.\n"); - log_fatal("DANGER! Your RAM memory is faulty! DO NOT PROCEED UNTIL FIXED!\n"); - log_fatal("Try running a memory test like http://www.memtest86.com/\n"); + log_fatal(ECONTENT, "CRC mismatch while writing the content stream.\n"); + log_fatal(ECONTENT, "DANGER! Your RAM memory is faulty! DO NOT PROCEED UNTIL FIXED!\n"); + log_fatal(ECONTENT, "Try running a memory test like http://www.memtest86.com/\n"); return context; /* LCOV_EXCL_STOP */ } @@ -3586,7 +3586,7 @@ static void* state_write_thread(void* arg) sputble32(crc, f); if (serror(f)) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -3675,7 +3675,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) disk = find_disk_by_name(state, map->name); if (!disk) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: Unmapped disk '%s'\n", map->name); + log_fatal(EINTERNAL, "Internal inconsistency: Unmapped disk '%s'\n", map->name); os_abort(); /* LCOV_EXCL_STOP */ } @@ -3711,7 +3711,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) if (remove(tmp) != 0) { if (errno != ENOENT) { /* LCOV_EXCL_START */ - log_fatal("Error removing the stale content file '%s'. %s.\n", tmp, strerror(errno)); + log_fatal(errno, "Error removing the stale content file '%s'. %s.\n", tmp, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3720,7 +3720,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) f = sopen_write(tmp); if (f == 0) { /* LCOV_EXCL_START */ - log_fatal("Error opening the temporary content file '%s'. %s.\n", tmp, strerror(errno)); + log_fatal(errno, "Error opening the temporary content file '%s'. %s.\n", tmp, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3773,7 +3773,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) /* than even in a system crash event we have one valid copy of the file. */ if (sflush(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3781,7 +3781,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) #if HAVE_FSYNC if (ssync(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s' in sync(). %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s' in sync(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3789,7 +3789,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) if (sclose(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing the content file. %s.\n", strerror(errno)); + log_fatal(errno, "Error closing the content file. %s.\n", strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3806,9 +3806,9 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) } else { if (crc != context->crc) { /* LCOV_EXCL_START */ - log_fatal("Different CRCs writing content streams.\n"); - log_fatal("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); - log_fatal("Try running a memory test like http://www.memtest86.com/\n"); + log_fatal(ECONTENT, "Different CRCs writing content streams.\n"); + log_fatal(ECONTENT, "DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); + log_fatal(ECONTENT, "Try running a memory test like http://www.memtest86.com/\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3841,7 +3841,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) f = sopen_multi_write(count_content, STREAM_FLAGS_SEQUENTIAL | STREAM_FLAGS_CRC); if (!f) { /* LCOV_EXCL_START */ - log_fatal("Error opening the content files.\n"); + log_fatal(errno, "Error opening the content files.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3857,7 +3857,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) if (remove(tmp) != 0) { if (errno != ENOENT) { /* LCOV_EXCL_START */ - log_fatal("Error removing the stale content file '%s'. %s.\n", tmp, strerror(errno)); + log_fatal(errno, "Error removing the stale content file '%s'. %s.\n", tmp, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3865,7 +3865,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) if (sopen_multi_file(f, k, tmp) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error opening the temporary content file '%s'. %s.\n", tmp, strerror(errno)); + log_fatal(errno, "Error opening the temporary content file '%s'. %s.\n", tmp, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3899,7 +3899,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) /* than even in a system crash event we have one valid copy of the file. */ if (sflush(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3907,7 +3907,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) #if HAVE_FSYNC if (ssync(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error writing the content file '%s' in sync(). %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Error writing the content file '%s' in sync(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3915,7 +3915,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) if (sclose(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing the content file. %s.\n", strerror(errno)); + log_fatal(errno, "Error closing the content file. %s.\n", strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3978,14 +3978,14 @@ void state_read(struct snapraid_state* state) /* if it's real error of an existing file, abort */ if (errno != ENOENT) { /* LCOV_EXCL_START */ - log_fatal("Error opening the content file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error opening the content file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } /* otherwise continue */ if (node->next) { - log_fatal("WARNING! Content file '%s' not found, attempting with another copy...\n", path); + log_fatal(errno, "WARNING! Content file '%s' not found, attempting with another copy...\n", path); /* ensure to rewrite all the content files */ state->need_write = 1; @@ -3998,7 +3998,7 @@ void state_read(struct snapraid_state* state) /* if not found, assume empty */ if (!f) { - log_fatal("No content file found. Assuming empty.\n"); + log_fatal(EUSER, "No content file found. Assuming empty.\n"); /* create the initial mapping */ state_map(state); @@ -4009,7 +4009,7 @@ void state_read(struct snapraid_state* state) ret = fstat(shandle(f), &st); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error stating the content file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error stating the content file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4026,7 +4026,7 @@ void state_read(struct snapraid_state* state) /* allow missing content files, but not any other kind of error */ if (errno != ENOENT) { /* LCOV_EXCL_START */ - log_fatal("Error stating the content file '%s'. %s.\n", other_path, strerror(errno)); + log_fatal(errno, "Error stating the content file '%s'. %s.\n", other_path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4036,8 +4036,8 @@ void state_read(struct snapraid_state* state) } else { /* if the size is different */ if (other_st.st_size != st.st_size) { - log_fatal("WARNING! Content files '%s' and '%s' have a different size!\n", path, other_path); - log_fatal("Likely one of the two is broken!\n"); + log_fatal(ECONTENT, "WARNING! Content files '%s' and '%s' have a different size!\n", path, other_path); + log_fatal(ECONTENT, "Likely one of the two is broken!\n"); /* ensure to rewrite all the content files */ state->need_write = 1; @@ -4069,8 +4069,8 @@ void state_read(struct snapraid_state* state) state_read_content(state, path, f); } else { /* LCOV_EXCL_START */ - log_fatal("From SnapRAID v9.0 the text content file is not supported anymore.\n"); - log_fatal("You have first to upgrade to SnapRAID v8.1 to convert it to binary format.\n"); + log_fatal(EUSER, "From SnapRAID v9.0 the text content file is not supported anymore.\n"); + log_fatal(EUSER, "You have first to upgrade to SnapRAID v8.1 to convert it to binary format.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4079,10 +4079,10 @@ void state_read(struct snapraid_state* state) if (state->hash == HASH_UNDEFINED) { /* LCOV_EXCL_START */ - log_fatal("The checksum to use is not specified.\n"); - log_fatal("This happens because you are likely upgrading from SnapRAID 1.0.\n"); - log_fatal("To use a new SnapRAID you must restart from scratch,\n"); - log_fatal("deleting all the content and parity files.\n"); + log_fatal(EUSER, "The checksum to use is not specified.\n"); + log_fatal(EUSER, "This happens because you are likely upgrading from SnapRAID 1.0.\n"); + log_fatal(EUSER, "To use a new SnapRAID you must restart from scratch,\n"); + log_fatal(EUSER, "deleting all the content and parity files.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4123,7 +4123,7 @@ static void* state_verify_thread(void* arg) if (sdeplete(f, buf) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to flush content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal(errno, "Failed to flush content file '%s'. %s.\n", serrorfile(f), strerror(errno)); return context; /* LCOV_EXCL_STOP */ } @@ -4133,7 +4133,7 @@ static void* state_verify_thread(void* arg) if (crc_stored != context->crc) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Wrong stored CRC in '%s'\n", serrorfile(f)); + log_fatal(ECONTENT, "DANGER! Wrong stored CRC in '%s'\n", serrorfile(f)); return context; /* LCOV_EXCL_STOP */ } @@ -4146,7 +4146,7 @@ static void* state_verify_thread(void* arg) if (crc_computed != crc_stored) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Wrong file CRC in '%s'\n", serrorfile(f)); + log_fatal(ECONTENT, "DANGER! Wrong file CRC in '%s'\n", serrorfile(f)); return context; /* LCOV_EXCL_STOP */ } @@ -4175,7 +4175,7 @@ static void state_verify_content(struct snapraid_state* state, uint32_t crc) f = sopen_read(tmp, STREAM_FLAGS_SEQUENTIAL | STREAM_FLAGS_CRC); if (f == 0) { /* LCOV_EXCL_START */ - log_fatal("Error reopening the temporary content file '%s'. %s.\n", tmp, strerror(errno)); + log_fatal(errno, "Error reopening the temporary content file '%s'. %s.\n", tmp, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4221,7 +4221,7 @@ static void state_verify_content(struct snapraid_state* state, uint32_t crc) if (sclose(f) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing the content file. %s.\n", strerror(errno)); + log_fatal(errno, "Error closing the content file. %s.\n", strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4265,7 +4265,7 @@ static void state_rename_content(struct snapraid_state* state) handle = open(dir, O_RDONLY | O_DIRECTORY); if (handle < 0) { /* LCOV_EXCL_START */ - log_fatal("Error opening the directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error opening the directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4274,7 +4274,7 @@ static void state_rename_content(struct snapraid_state* state) pathprint(tmp, sizeof(tmp), "%s.tmp", content->content); if (rename(tmp, content->content) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error renaming the content file '%s' to '%s'. %s.\n", tmp, content->content, strerror(errno)); + log_fatal(errno, "Error renaming the content file '%s' to '%s'. %s.\n", tmp, content->content, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4282,14 +4282,14 @@ static void state_rename_content(struct snapraid_state* state) /* sync the directory */ if (fsync(handle) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error syncing the directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error syncing the directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(handle) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing the directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error closing the directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4306,7 +4306,7 @@ static void state_rename_content(struct snapraid_state* state) pathprint(tmp, sizeof(tmp), "%s.tmp", content->content); if (rename(tmp, content->content) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error renaming the content file '%s' to '%s' in rename(). %s.\n", tmp, content->content, strerror(errno)); + log_fatal(errno, "Error renaming the content file '%s' to '%s' in rename(). %s.\n", tmp, content->content, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4974,8 +4974,8 @@ int state_progress(struct snapraid_state* state, struct snapraid_io* io, block_o if (global_interrupt) { /* LCOV_EXCL_START */ if (!state->opt.gui) { - log_fatal("\n"); - log_fatal("Stopping for interruption at block %u\n", blockpos); + log_fatal(EUSER, "\n"); + log_fatal(EUSER, "Stopping for interruption at block %u\n", blockpos); } log_tag("sigint:%u: SIGINT received\n", blockpos); log_flush(); @@ -5100,7 +5100,7 @@ void state_fscheck(struct snapraid_state* state, const char* ope) if (fs_check(disk) != 0) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency: File-system check for disk '%s' %s\n", disk->name, ope); + log_fatal(EINTERNAL, "Internal inconsistency: File-system check for disk '%s' %s\n", disk->name, ope); os_abort(); /* LCOV_EXCL_STOP */ } @@ -5205,8 +5205,8 @@ int state_flush(struct snapraid_state* state, struct snapraid_io* io, struct sna int ret = parity_sync(&parity_handle[l]); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("parity_error_io:%u:%s: Sync error\n", blockcur, lev_config_name(l)); - log_fatal("DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", lev_config_name(l)); + log_tag("parity_error_io:%u:%s: Sync error. %s.\n", blockcur, lev_config_name(l), strerror(errno)); + log_fatal(errno, "DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", lev_config_name(l)); return -1; /* LCOV_EXCL_STOP */ } @@ -5223,7 +5223,7 @@ void state_load_ignore_file(tommy_list* filter_list, const char* path, const cha f = sopen_read(path, 0); if (!f) { /* LCOV_EXCL_START */ - log_error("Error opening the ignore file '%s'. %s.\n", path, strerror(errno)); + log_error(errno, "Error opening the ignore file '%s'. %s.\n", path, strerror(errno)); return; /* LCOV_EXCL_STOP */ } @@ -5241,7 +5241,7 @@ void state_load_ignore_file(tommy_list* filter_list, const char* path, const cha ret = sgetline(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - log_error("Too long line in '%s' at line %u\n", path, line); + log_error(EUSER, "Too long line in '%s' at line %u\n", path, line); break; /* LCOV_EXCL_STOP */ } @@ -5256,7 +5256,7 @@ void state_load_ignore_file(tommy_list* filter_list, const char* path, const cha filter = filter_alloc_file(-1, sub, buffer); if (!filter) { /* LCOV_EXCL_START */ - log_error("Invalid ignore specification '%s' in '%s' at line %u\n", buffer, path, line); + log_error(EUSER, "Invalid ignore specification '%s' in '%s' at line %u\n", buffer, path, line); break; /* LCOV_EXCL_STOP */ } @@ -5271,7 +5271,7 @@ void state_load_ignore_file(tommy_list* filter_list, const char* path, const cha } if (c != '\n') { /* LCOV_EXCL_START */ - log_error("Extra data in '%s' at line %u\n", path, line); + log_error(EUSER, "Extra data in '%s' at line %u\n", path, line); break; /* LCOV_EXCL_STOP */ } @@ -5280,7 +5280,7 @@ void state_load_ignore_file(tommy_list* filter_list, const char* path, const cha if (serror(f)) { /* LCOV_EXCL_START */ - log_error("Error reading the ignore file '%s' at line %u\n", path, line); + log_error(errno, "Error reading the ignore file '%s' at line %u\n", path, line); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/status.c b/cmdline/status.c index 944d4c48..aac63ffd 100644 --- a/cmdline/status.c +++ b/cmdline/status.c @@ -365,7 +365,7 @@ int state_status(struct snapraid_state* state) log_flush(); if (!count) { - log_fatal("The array is empty.\n"); + log_fatal(EUSER, "The array is empty.\n"); free(timemap); return 0; } diff --git a/cmdline/stream.c b/cmdline/stream.c index 391382a3..999ac913 100644 --- a/cmdline/stream.c +++ b/cmdline/stream.c @@ -65,7 +65,7 @@ STREAM* sopen_read(const char* file, int flags) /* advise sequential access */ ret = posix_fadvise(s->handle[0].f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret == ENOSYS) { - log_fatal("WARNING! fadvise() is not supported in this platform. Performance may not be optimal!\n"); + log_fatal(errno, "WARNING! fadvise() is not supported in this platform. Performance may not be optimal!\n"); /* call is not supported, like in armhf, see posix_fadvise manpage */ ret = 0; } diff --git a/cmdline/support.c b/cmdline/support.c index 4d9262b0..b1d466b4 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -204,14 +204,17 @@ static void vmsg(FILE* out, const char* format, va_list ap) free(dup); } -void log_fatal(const char* format, ...) +void log_fatal(int err, const char* format, ...) { va_list ap; lock_msg(); if (stdlog) { - fprintf(stdlog, "msg:fatal: "); + if (err == EIO) + fprintf(stdlog, "msg:fatal_hardware: "); + else + fprintf(stdlog, "msg:fatal: "); va_start(ap, format); vfprintf(stdlog, format, ap); @@ -229,14 +232,17 @@ void log_fatal(const char* format, ...) unlock_msg(); } -void log_error(const char* format, ...) +void log_error(int err, const char* format, ...) { va_list ap; lock_msg(); if (stdlog) { - fprintf(stdlog, "msg:error: "); + if (err == EIO) + fprintf(stdlog, "msg:error_hardware: "); + else + fprintf(stdlog, "msg:error: "); va_start(ap, format); vfprintf(stdlog, format, ap); @@ -254,14 +260,17 @@ void log_error(const char* format, ...) unlock_msg(); } -void log_expected(const char* format, ...) +void log_expected(int err, const char* format, ...) { va_list ap; lock_msg(); if (stdlog) { - fprintf(stdlog, "msg:expected: "); + if (err == EIO) + fprintf(stdlog, "msg:error_hardware: "); /* we never expect an hardware error */ + else + fprintf(stdlog, "msg:expected: "); va_start(ap, format); vfprintf(stdlog, format, ap); @@ -557,7 +566,7 @@ const char* esc_tag(const char* str, char* buffer) bail: /* LCOV_EXCL_START */ - log_fatal("Escape for log is too long\n"); + log_fatal(EINTERNAL, "Escape for log is too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -674,7 +683,7 @@ const char* esc_shell_multi(const char** str_map, unsigned str_max, char* buffer bail: /* LCOV_EXCL_START */ - log_fatal("Escape for shell is too long\n"); + log_fatal(EINTERNAL, "Escape for shell is too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -746,7 +755,7 @@ const char* esc_shell_multi(const char** str_map, unsigned str_max, char* buffer bail: /* LCOV_EXCL_START */ - log_fatal("Escape for shell is too long\n"); + log_fatal(EINTERNAL, "Escape for shell is too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -855,7 +864,7 @@ void pathcpy(char* dst, size_t size, const char* src) if (len + 1 > size) { /* LCOV_EXCL_START */ - log_fatal("Path too long '%s'\n", src); + log_fatal(EINTERNAL, "Path too long '%s'\n", src); os_abort(); /* LCOV_EXCL_STOP */ } @@ -870,7 +879,7 @@ void pathcat(char* dst, size_t size, const char* src) if (dst_len + src_len + 1 > size) { /* LCOV_EXCL_START */ - log_fatal("Path too long '%s%s'\n", dst, src); + log_fatal(EINTERNAL, "Path too long '%s%s'\n", dst, src); os_abort(); /* LCOV_EXCL_STOP */ } @@ -884,7 +893,7 @@ void pathcatl(char* dst, size_t dst_len, size_t size, const char* src) if (dst_len + src_len + 1 > size) { /* LCOV_EXCL_START */ - log_fatal("Path too long '%s%s'\n", dst, src); + log_fatal(EINTERNAL, "Path too long '%s%s'\n", dst, src); os_abort(); /* LCOV_EXCL_STOP */ } @@ -898,7 +907,7 @@ void pathcatc(char* dst, size_t size, char c) if (dst_len + 2 > size) { /* LCOV_EXCL_START */ - log_fatal("Path too long '%s%c'\n", dst, c); + log_fatal(EINTERNAL, "Path too long '%s%c'\n", dst, c); os_abort(); /* LCOV_EXCL_STOP */ } @@ -961,9 +970,9 @@ void pathprint(char* dst, size_t size, const char* format, ...) /* LCOV_EXCL_START */ if (size > 0) { dst[size - 1] = 0; - log_fatal("Path too long '%s...'\n", dst); + log_fatal(EINTERNAL, "Path too long '%s...'\n", dst); } else { - log_fatal("Path too long for empty size'\n"); + log_fatal(EINTERNAL, "Path too long for empty size'\n"); } os_abort(); /* LCOV_EXCL_STOP */ @@ -977,7 +986,7 @@ void pathslash(char* dst, size_t size) if (len > 0 && dst[len - 1] != '/') { if (len + 2 >= size) { /* LCOV_EXCL_START */ - log_fatal("Path too long '%s/'\n", dst); + log_fatal(EINTERNAL, "Path too long '%s/'\n", dst); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1097,7 +1106,7 @@ int mkancestor(const char* file) /* create it */ if (mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) { /* LCOV_EXCL_START */ - log_fatal("Error creating directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal(errno, "Error creating directory '%s'. %s.\n", dir, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -1839,13 +1848,13 @@ int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* sm inside = 1; } else if (inside) { if (sscanf(s, "%u %*s %*s %" SCNu64 " %*s %*s %*s %*s %*s %" SCNu64, &id, &normalized, &raw) != 3) { - log_fatal("Invalid smartctl line '%s'.\n", s); + log_fatal(EEXTERNAL, "Invalid smartctl line '%s'.\n", s); return -1; } if (id >= 256) { /* LCOV_EXCL_START */ - log_fatal("Invalid SMART id '%u'.\n", id); + log_fatal(EEXTERNAL, "Invalid SMART id '%u'.\n", id); return -1; /* LCOV_EXCL_STOP */ } @@ -1901,7 +1910,7 @@ void thread_mutex_init(thread_mutex_t* mutex) { if (pthread_mutex_init(mutex, 0) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_mutex_init().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_mutex_init().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1911,7 +1920,7 @@ void thread_mutex_destroy(thread_mutex_t* mutex) { if (pthread_mutex_destroy(mutex) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_mutex_destroy().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_mutex_destroy().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1921,7 +1930,7 @@ void thread_mutex_lock(thread_mutex_t* mutex) { if (pthread_mutex_lock(mutex) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_mutex_lock().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_mutex_lock().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1931,7 +1940,7 @@ void thread_mutex_unlock(thread_mutex_t* mutex) { if (pthread_mutex_unlock(mutex) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_mutex_unlock().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_mutex_unlock().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1941,7 +1950,7 @@ void thread_cond_init(thread_cond_t* cond) { if (pthread_cond_init(cond, 0) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_cond_init().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_cond_init().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1951,7 +1960,7 @@ void thread_cond_destroy(thread_cond_t* cond) { if (pthread_cond_destroy(cond) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_cond_destroy().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_cond_destroy().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1961,7 +1970,7 @@ void thread_cond_signal(thread_cond_t* cond) { if (pthread_cond_signal(cond) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_cond_signal().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_cond_signal().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1971,7 +1980,7 @@ void thread_cond_broadcast(thread_cond_t* cond) { if (pthread_cond_broadcast(cond) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_cond_broadcast().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_cond_broadcast().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -1981,7 +1990,7 @@ void thread_cond_wait(thread_cond_t* cond, thread_mutex_t* mutex) { if (pthread_cond_wait(cond, mutex) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_cond_wait().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_cond_wait().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2054,7 +2063,7 @@ void thread_create(thread_id_t* thread, void* (*func)(void*), void *arg) { if (pthread_create(thread, 0, func, arg) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_create().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_create().\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -2064,7 +2073,7 @@ void thread_join(thread_id_t thread, void** retval) { if (pthread_join(thread, retval) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed call to pthread_join().\n"); + log_fatal(EINTERNAL, "Failed call to pthread_join().\n"); os_abort(); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/support.h b/cmdline/support.h index 8312e891..7c481407 100644 --- a/cmdline/support.h +++ b/cmdline/support.h @@ -73,6 +73,11 @@ uint64_t random_u64(void); /****************************************************************************/ /* log */ +/** + * Pointer to log function. + */ +typedef void log_ptr(int err, const char* format, ...) __attribute__((format(attribute_printf, 2, 3))); + /** * Fatal error messages. * @@ -80,7 +85,7 @@ uint64_t random_u64(void); * * These messages go in the log file and in stderr unconditionally. */ -void log_fatal(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); +void log_fatal(int err, const char* format, ...) __attribute__((format(attribute_printf, 2, 3))); /** * Unexpected error messages. @@ -93,7 +98,7 @@ void log_fatal(const char* format, ...) __attribute__((format(attribute_printf, * * These messages go in the log file if specified, otherwise they go in stderr. */ -void log_error(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); +void log_error(int err, const char* format, ...) __attribute__((format(attribute_printf, 2, 3))); /** * Expected error messages, without fallback to stderr. @@ -104,7 +109,7 @@ void log_error(const char* format, ...) __attribute__((format(attribute_printf, * * These messages go in the log file if specified, otherwise they are lost. */ -void log_expected(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); +void log_expected(int err, const char* format, ...) __attribute__((format(attribute_printf, 2, 3))); /** * Tag messages. @@ -124,14 +129,14 @@ void log_tag(const char* format, ...) __attribute__((format(attribute_printf, 1, */ void log_flush(void); -/** - * Pointer to log function. - */ -typedef void fptr(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); - /****************************************************************************/ /* message */ +/** + * Pointer to msg function. + */ +typedef void msg_ptr(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); + /** * Message levels. * diff --git a/cmdline/sync.c b/cmdline/sync.c index 34ddd409..d607f2be 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -39,28 +39,28 @@ static const char* es(int err) static void log_fatal_errno(int err, const char* name) { if (err == EIO) { - log_fatal("DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "DANGER! Unexpected input/output error in disk %s. It isn't possible to continue.\n", name); } else if (err == EACCES) { - log_fatal("WARNING! Grant permission in the disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Grant permission in the disk %s. It isn't possible to continue.\n", name); } else if (err == ENOSPC) { - log_fatal("WARNING! Ensure there is free space on the disk %s. It isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Ensure there is free space on the disk %s. It isn't possible to continue.\n", name); } else { - log_fatal("WARNING! Without a working %s disk, it isn't possible to continue.\n", name); + log_fatal(err, "WARNING! Without a working %s disk, it isn't possible to continue.\n", name); } } static void log_error_errno(int err, const char* name) { if (err == EIO) { - log_fatal("DANGER! Unexpected input/output error in disk %s.\n", name); + log_fatal(err, "DANGER! Unexpected input/output error in disk %s.\n", name); } else if (err == EACCES) { - log_error("WARNING! Grant permission in the disk %s.\n", name); - log_error("Rerun the sync command when finished.\n"); + log_error(err, "WARNING! Grant permission in the disk %s.\n", name); + log_error(err, "Rerun the sync command when finished.\n"); } else if (err == ENOSPC) { - log_error("WARNING! Ensure there is free space on the disk %s.\n", name); + log_error(err, "WARNING! Ensure there is free space on the disk %s.\n", name); } else if (err == ENOENT) { - log_error("WARNING! You cannot modify files during a sync.\n"); - log_error("Rerun the sync command when finished.\n"); + log_error(err, "WARNING! You cannot modify files during a sync.\n"); + log_error(err, "Rerun the sync command when finished.\n"); } } @@ -176,7 +176,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* and closing a descriptor should never fail */ log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", i); + log_fatal(errno, "Stopping at block %u\n", i); if (errno == EIO) { ++io_error; @@ -212,10 +212,10 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta log_fatal_errno(errno, disk->name); if (errno == EIO) { - log_fatal("Stopping at block %u\n", i); + log_fatal(errno, "Stopping at block %u\n", i); ++io_error; } else { - log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, file->sub, esc_buffer)); + log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, file->sub, esc_buffer)); ++soft_error; } goto bail; @@ -230,14 +230,14 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta ) { if (handle[j].st.st_size != file->size) { log_tag("error:%u:%s:%s: Unexpected size change\n", i, disk->name, esc_tag(file->sub, esc_buffer)); - log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, (uint64_t)handle[j].st.st_size); + log_error(ESOFT, "Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, (uint64_t)handle[j].st.st_size); } else if (handle[j].st.st_mtime != file->mtime_sec || STAT_NSEC(&handle[j].st) != file->mtime_nsec) { log_tag("error:%u:%s:%s: Unexpected time change\n", i, disk->name, esc_tag(file->sub, esc_buffer)); - log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, STAT_NSEC(&handle[j].st)); + log_error(ESOFT, "Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, STAT_NSEC(&handle[j].st)); } else { log_tag("error:%u:%s:%s: Unexpected inode change\n", i, disk->name, esc_tag(file->sub, esc_buffer)); - log_error("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); + log_error(ESOFT, "Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); } log_error_errno(ENOENT, disk->name); /* same message for ENOENT */ @@ -255,10 +255,10 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta log_fatal_errno(errno, disk->name); if (errno == EIO) { - log_fatal("Stopping at block %u\n", i); + log_fatal(errno, "Stopping at block %u\n", i); ++io_error; } else { - log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, file->sub, esc_buffer)); + log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, file->sub, esc_buffer)); ++soft_error; } goto bail; @@ -286,16 +286,16 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* compare the hash */ if (memcmp(hash, block->hash, BLOCK_HASH_SIZE) != 0) { log_tag("error_data:%u:%s:%s: Unexpected data change\n", i, disk->name, esc_tag(file->sub, esc_buffer)); - log_error("Data change at file '%s' at position '%u'\n", handle[j].path, file_pos); - log_error("WARNING! Unexpected data modification of a file without parity!\n"); + log_error(EDATA, "Data change at file '%s' at position '%u'\n", handle[j].path, file_pos); + log_error(EDATA, "WARNING! Unexpected data modification of a file without parity!\n"); if (file_flag_has(file, FILE_IS_COPY)) { - log_error("This file was detected as a copy of another file with the same name, size,\n"); - log_error("and timestamp, but the file data isn't matching the assumed copy.\n"); - log_error("If this is a false positive, and the files are expected to be different,\n"); - log_error("you can 'sync' anyway using 'snapraid --force-nocopy sync'\n"); + log_error(EDATA, "This file was detected as a copy of another file with the same name, size,\n"); + log_error(EDATA, "and timestamp, but the file data isn't matching the assumed copy.\n"); + log_error(EDATA, "If this is a false positive, and the files are expected to be different,\n"); + log_error(EDATA, "you can 'sync' anyway using 'snapraid --force-nocopy sync'\n"); } else { - log_error("Try removing the file from the array and rerun the 'sync' command!\n"); + log_error(EDATA, "Try removing the file from the array and rerun the 'sync' command!\n"); } /* block sync to allow a recovery before overwriting */ @@ -342,7 +342,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* and closing a descriptor should never fail */ log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockmax, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", blockmax); + log_fatal(errno, "Stopping at block %u\n", blockmax); if (errno == EIO) { ++io_error; @@ -374,7 +374,7 @@ end: } if (soft_error) - log_fatal("WARNING! Unexpected soft errors!\n"); + log_fatal(ESOFT, "WARNING! Unexpected soft errors!\n"); log_tag("hash_summary:error_soft:%u\n", soft_error); @@ -540,7 +540,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas /* and closing a descriptor should never fail */ log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); log_fatal_errno(errno, disk->name); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); if (errno == EIO) { task->state = TASK_STATE_IOERROR; @@ -576,10 +576,10 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas log_fatal_errno(errno, disk->name); if (errno == EIO) { - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); task->state = TASK_STATE_IOERROR; } else { - log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, task->file->sub, esc_buffer)); + log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, task->file->sub, esc_buffer)); task->state = TASK_STATE_ERROR; } return; @@ -594,12 +594,12 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas ) { log_tag("error:%u:%s:%s: Unexpected attribute change\n", blockcur, disk->name, esc_tag(task->file->sub, esc_buffer)); if (handle->st.st_size != task->file->size) { - log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle->path, task->file->size, (uint64_t)handle->st.st_size); + log_error(ESOFT, "Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle->path, task->file->size, (uint64_t)handle->st.st_size); } else if (handle->st.st_mtime != task->file->mtime_sec || STAT_NSEC(&handle->st) != task->file->mtime_nsec) { - log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle->path, task->file->mtime_sec, task->file->mtime_nsec, (uint64_t)handle->st.st_mtime, STAT_NSEC(&handle->st)); + log_error(ESOFT, "Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle->path, task->file->mtime_sec, task->file->mtime_nsec, (uint64_t)handle->st.st_mtime, STAT_NSEC(&handle->st)); } else { - log_error("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", task->file->inode, (uint64_t)handle->st.st_ino, handle->path); + log_error(ESOFT, "Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", task->file->inode, (uint64_t)handle->st.st_ino, handle->path); } log_error_errno(ENOENT, disk->name); /* same message for ENOENT */ @@ -620,7 +620,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas task->state = TASK_STATE_IOERROR_CONTINUE; } else { log_fatal_errno(errno, disk->name); - log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, task->file->sub, esc_buffer)); + log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, task->file->sub, esc_buffer)); task->state = TASK_STATE_ERROR; } return; @@ -655,7 +655,7 @@ static void sync_parity_writer(struct snapraid_worker* worker, struct snapraid_t task->state = TASK_STATE_IOERROR_CONTINUE; } else { log_fatal_errno(errno, lev_config_name(level)); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); task->state = TASK_STATE_ERROR; } return; @@ -919,8 +919,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari ++io_error; if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", disk->dir); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(EIO, "DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", disk->dir); + log_fatal(EIO, "Stopping at block %u\n", blockcur); goto bail; /* LCOV_EXCL_STOP */ } @@ -931,7 +931,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } if (task->state != TASK_STATE_DONE) { /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in task state\n"); + log_fatal(EINTERNAL, "Internal inconsistency in task state\n"); os_abort(); /* LCOV_EXCL_STOP */ } @@ -958,16 +958,16 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* if the file has invalid parity, it's a REP changed during the sync */ if (block_has_invalid_parity(block)) { log_tag("error:%u:%s:%s: Unexpected data change\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer)); - log_error("Data change at file '%s' at position '%u'\n", task->path, file_pos); - log_error("WARNING! Unexpected data modification of a file without parity!\n"); + log_error(ESOFT, "Data change at file '%s' at position '%u'\n", task->path, file_pos); + log_error(ESOFT, "WARNING! Unexpected data modification of a file without parity!\n"); if (file_flag_has(file, FILE_IS_COPY)) { - log_error("This file was detected as a copy of another file with the same name, size,\n"); - log_error("and timestamp, but the file data isn't matching the assumed copy.\n"); - log_error("If this is a false positive, and the files are expected to be different,\n"); - log_error("you can 'sync' anyway using 'snapraid --force-nocopy sync'\n"); + log_error(ESOFT, "This file was detected as a copy of another file with the same name, size,\n"); + log_error(ESOFT, "and timestamp, but the file data isn't matching the assumed copy.\n"); + log_error(ESOFT, "If this is a false positive, and the files are expected to be different,\n"); + log_error(ESOFT, "you can 'sync' anyway using 'snapraid --force-nocopy sync'\n"); } else { - log_error("Try removing the file from the array and rerun the 'sync' command!\n"); + log_error(ESOFT, "Try removing the file from the array and rerun the 'sync' command!\n"); } ++soft_error; @@ -979,7 +979,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } else { /* otherwise it's a BLK with silent error */ unsigned diff = memdiff(hash, block->hash, BLOCK_HASH_SIZE); log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer), file_pos, diff, BLOCK_HASH_SIZE * 8); - log_error("Data error in file '%s' at position '%u', diff hash bits %u/%u\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8); + log_error(EDATA, "Data error in file '%s' at position '%u', diff hash bits %u/%u\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8); /* save the failed block for the fix */ failed[failed_count].index = diskcur; @@ -1084,8 +1084,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari if (errno == EIO) { log_error_errno(errno, lev_config_name(l)); if (io_error >= state->opt.io_error_limit) { - log_fatal("DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", lev_config_name(l)); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "DANGER! Too many input/output errors in the %s disk. It isn't possible to continue.\n", lev_config_name(l)); + log_fatal(errno, "Stopping at block %u\n", blockcur); ++io_error; goto bail; } @@ -1096,7 +1096,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } log_fatal_errno(errno, lev_config_name(l)); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); ++soft_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1263,8 +1263,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari ++io_error; if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Too many input/output errors in a parity disk. It isn't possible to continue.\n"); - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(EIO, "DANGER! Too many input/output errors in a parity disk. It isn't possible to continue.\n"); + log_fatal(EIO, "Stopping at block %u\n", blockcur); goto bail; /* LCOV_EXCL_STOP */ } @@ -1310,7 +1310,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari ret = state_flush(state, &io, parity_handle, blockcur); if (ret == -1) { /* LCOV_EXCL_START */ - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); ++io_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1345,7 +1345,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari ret = state_flush(state, &io, parity_handle, blockcur); if (ret == -1) { /* LCOV_EXCL_START */ - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(EIO, "Stopping at block %u\n", blockcur); ++io_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1369,7 +1369,7 @@ end: ret = state_flush(state, &io, parity_handle, blockcur); if (ret == -1) { /* LCOV_EXCL_START */ - log_fatal("Stopping at block %u\n", blockcur); + log_fatal(errno, "Stopping at block %u\n", blockcur); ++io_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1380,7 +1380,7 @@ end: if ((state->need_write || state->opt.force_content_write)) state_write(state); } else { - log_fatal("WARNING! Skipped writing state due to --test-kill-after-sync option.\n"); + log_fatal(EUSER, "WARNING! Skipped writing state due to --test-kill-after-sync option.\n"); } state_usage_print(state); @@ -1397,14 +1397,14 @@ end: } if (soft_error) - log_fatal("WARNING! Unexpected soft errors!\n"); + log_fatal(ESOFT, "WARNING! Unexpected soft errors!\n"); if (io_error) - log_fatal("DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); + log_fatal(EIO, "DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); if (silent_error) - log_fatal("DANGER! Unexpected silent data errors! The failing blocks are now marked as bad!\n"); + log_fatal(EDATA, "DANGER! Unexpected silent data errors! The failing blocks are now marked as bad!\n"); if (io_error || silent_error) { - log_fatal("Use 'snapraid status' to list the bad blocks.\n"); - log_fatal("Use 'snapraid -e fix' to recover.\n"); + log_fatal(ESOFT, "Use 'snapraid status' to list the bad blocks.\n"); + log_fatal(ESOFT, "Use 'snapraid -e fix' to recover.\n"); } log_tag("summary:error_soft:%u\n", soft_error); @@ -1487,7 +1487,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t if (blockstart > blockmax) { /* LCOV_EXCL_START */ - log_fatal("Error in the starting block %u. It is larger than the parity size %u.\n", blockstart, blockmax); + log_fatal(EUSER, "Error in the starting block %u. It is larger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1517,7 +1517,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t /* if the file is too small */ if (parityblocks < used_paritymax) { - log_fatal("WARNING! The %s parity has only %u blocks instead of %u.\n", lev_name(l), parityblocks, used_paritymax); + log_fatal(ESOFT, "WARNING! The %s parity has only %u blocks instead of %u.\n", lev_name(l), parityblocks, used_paritymax); } /* keep the smallest parity number of blocks */ @@ -1530,15 +1530,15 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t /* if the parities are too small */ if (file_paritymax < used_paritymax) { /* LCOV_EXCL_START */ - log_fatal("DANGER! One or more the parity files are smaller than expected!\n"); + log_fatal(ESOFT, "DANGER! One or more the parity files are smaller than expected!\n"); if (file_paritymax != 0) { - log_fatal("If this happens because you are using an old content file,\n"); - log_fatal("you can 'sync' anyway using 'snapraid --force-full sync'\n"); - log_fatal("to force a full rebuild of the parity.\n"); + log_fatal(ESOFT, "If this happens because you are using an old content file,\n"); + log_fatal(ESOFT, "you can 'sync' anyway using 'snapraid --force-full sync'\n"); + log_fatal(ESOFT, "to force a full rebuild of the parity.\n"); } else { - log_fatal("It's possible that the parity disks are not mounted.\n"); - log_fatal("If instead you are adding a new parity level, you can 'sync' using\n"); - log_fatal("'snapraid --force-full sync' to force a full rebuild of the parity.\n"); + log_fatal(ESOFT, "It's possible that the parity disks are not mounted.\n"); + log_fatal(ESOFT, "If instead you are adding a new parity level, you can 'sync' using\n"); + log_fatal(ESOFT, "'snapraid --force-full sync' to force a full rebuild of the parity.\n"); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1575,7 +1575,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t data_off_t out_size; parity_size(&parity_handle[l], &out_size); parity_overflow(state, out_size); - log_fatal("WARNING! Without a usable %s file, it isn't possible to sync.\n", lev_name(l)); + log_fatal(errno, "WARNING! Without a usable %s file, it isn't possible to sync.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1611,7 +1611,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t if (state->need_write) state_write(state); } else { - log_fatal("WARNING! Skipped state write for --test-skip-content-write option.\n"); + log_fatal(EUSER, "WARNING! Skipped state write for --test-skip-content-write option.\n"); } /* skip degenerated cases of empty parity, or skipping all */ diff --git a/cmdline/thermal.c b/cmdline/thermal.c index e1629e17..ffa3e0d3 100644 --- a/cmdline/thermal.c +++ b/cmdline/thermal.c @@ -376,7 +376,7 @@ int state_thermal_begin(struct snapraid_state* state, time_t now) if (state->thermal_temperature_limit != 0 && state->thermal_temperature_limit <= state->thermal_ambient_temperature) { /* LCOV_EXCL_START */ - log_fatal("DANGER! System temperature of %d degrees is higher than the temperature limit of %d degrees. Unable to proceed!\n", state->thermal_ambient_temperature, state->thermal_temperature_limit); + log_fatal(EENVIRONMENT, "DANGER! System temperature of %d degrees is higher than the temperature limit of %d degrees. Unable to proceed!\n", state->thermal_ambient_temperature, state->thermal_temperature_limit); log_flush(); return 0; /* LCOV_EXCL_STOP */ @@ -385,7 +385,7 @@ int state_thermal_begin(struct snapraid_state* state, time_t now) if (state_thermal_alarm(state)) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Hard disk temperature of %d degrees is already outside the operating range. Unable to proceed!\n", state->thermal_highest_temperature); + log_fatal(EENVIRONMENT, "DANGER! Hard disk temperature of %d degrees is already outside the operating range. Unable to proceed!\n", state->thermal_highest_temperature); log_flush(); return 0; /* LCOV_EXCL_STOP */ diff --git a/cmdline/touch.c b/cmdline/touch.c index cb54edc7..8381217d 100644 --- a/cmdline/touch.c +++ b/cmdline/touch.c @@ -58,7 +58,7 @@ void state_touch(struct snapraid_state* state) /* get a random nanosecond value */ if (randomize(&nano, sizeof(nano)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to retrieve random values.\n"); + log_fatal(errno, "Failed to retrieve random values.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -81,7 +81,7 @@ void state_touch(struct snapraid_state* state) f = open(path, flags); if (f == -1) { /* LCOV_EXCL_START */ - log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error opening file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -92,7 +92,7 @@ void state_touch(struct snapraid_state* state) if (ret == -1) { /* LCOV_EXCL_START */ close(f); - log_fatal("Error accessing file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error accessing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -102,7 +102,7 @@ void state_touch(struct snapraid_state* state) if (ret != 0) { /* LCOV_EXCL_START */ close(f); - log_fatal("Error timing file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error timing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -114,7 +114,7 @@ void state_touch(struct snapraid_state* state) if (ret == -1) { /* LCOV_EXCL_START */ close(f); - log_fatal("Error accessing file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error accessing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -123,7 +123,7 @@ void state_touch(struct snapraid_state* state) ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno)); + log_fatal(errno, "Error closing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } diff --git a/cmdline/unix.c b/cmdline/unix.c index a3867995..459c6593 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -353,13 +353,13 @@ static int tagread(const char* path, const char* tag, char* value, size_t value_ ret = sysread(path, buf, sizeof(buf)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to read '%s'.\n", path); + log_fatal(errno, "Failed to read '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } if ((size_t)ret + 1 > sizeof(buf)) { /* LCOV_EXCL_START */ - log_fatal("Too long read '%s'.\n", path); + log_fatal(EEXTERNAL, "Too long read '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } @@ -394,7 +394,7 @@ static int tagread(const char* path, const char* tag, char* value, size_t value_ } if (!*i) { /* LCOV_EXCL_START */ - log_fatal("Missing tag '%s' for '%s'.\n", tag, path); + log_fatal(EEXTERNAL, "Missing tag '%s' for '%s'.\n", tag, path); return -1; /* LCOV_EXCL_STOP */ } @@ -407,7 +407,7 @@ static int tagread(const char* path, const char* tag, char* value, size_t value_ if (!*i) { /* LCOV_EXCL_START */ - log_fatal("Empty tag '%s' for '%s'.\n", tag, path); + log_fatal(EEXTERNAL, "Empty tag '%s' for '%s'.\n", tag, path); return -1; /* LCOV_EXCL_STOP */ } @@ -1253,7 +1253,7 @@ static dev_t devread(const char* path) f = open(path, O_RDONLY); if (f == -1) { /* LCOV_EXCL_START */ - log_fatal("Failed to open '%s'.\n", path); + log_fatal(errno, "Failed to open '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } @@ -1262,14 +1262,14 @@ static dev_t devread(const char* path) if (len < 0) { /* LCOV_EXCL_START */ close(f); - log_fatal("Failed to read '%s'.\n", path); + log_fatal(errno, "Failed to read '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } if (len == sizeof(buf)) { /* LCOV_EXCL_START */ close(f); - log_fatal("Too long read '%s'.\n", path); + log_fatal(EEXTERNAL, "Too long read '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } @@ -1277,7 +1277,7 @@ static dev_t devread(const char* path) ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to close '%s'.\n", path); + log_fatal(errno, "Failed to close '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } @@ -1287,7 +1287,7 @@ static dev_t devread(const char* path) ma = strtoul(buf, &e, 10); if (*e != ':') { /* LCOV_EXCL_START */ - log_fatal("Invalid format in '%s' for '%s'.\n", path, buf); + log_fatal(EEXTERNAL, "Invalid format in '%s' for '%s'.\n", path, buf); return 0; /* LCOV_EXCL_STOP */ } @@ -1295,7 +1295,7 @@ static dev_t devread(const char* path) mi = strtoul(e + 1, &e, 10); if (*e != 0 && !isspace(*e)) { /* LCOV_EXCL_START */ - log_fatal("Invalid format in '%s' for '%s'.\n", path, buf); + log_fatal(EEXTERNAL, "Invalid format in '%s' for '%s'.\n", path, buf); return 0; /* LCOV_EXCL_STOP */ } @@ -1372,7 +1372,7 @@ static int devtree(devinfo_t* parent, dev_t device, tommy_list* list) /* get the device file */ if (devresolve(device, path, sizeof(path)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to resolve device '%u:%u'.\n", major(device), minor(device)); + log_fatal(EEXTERNAL, "Failed to resolve device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1412,7 +1412,7 @@ static int devscan(tommy_list* list) d = opendir(dir); if (d == 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to open dir '%s'.\n", dir); + log_fatal(errno, "Failed to open dir '%s'.\n", dir); return -1; /* LCOV_EXCL_STOP */ } @@ -1490,14 +1490,14 @@ static int devsmart(dev_t device, const char* name, const char* smartctl, uint64 x = find_smartctl(); if (!x) { /* LCOV_EXCL_START */ - log_fatal("Cannot find smartctl.\n"); + log_fatal(EEXTERNAL, "Cannot find smartctl.\n"); return -1; /* LCOV_EXCL_STOP */ } if (devresolve(device, file, sizeof(file)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to resolve device '%u:%u'.\n", major(device), minor(device)); + log_fatal(EEXTERNAL, "Failed to resolve device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1517,7 +1517,7 @@ static int devsmart(dev_t device, const char* name, const char* smartctl, uint64 if (!f) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from popen).\n", cmd); + log_fatal(EEXTERNAL, "Failed to run '%s' (from popen).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } @@ -1537,14 +1537,14 @@ static int devsmart(dev_t device, const char* name, const char* smartctl, uint64 if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:abort\n", file, name); - log_fatal("Failed to run '%s' (not exited).\n", cmd); + log_fatal(EEXTERNAL, "Failed to run '%s' (not exited).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from sh).\n", cmd); + log_fatal(EEXTERNAL, "Failed to run '%s' (from sh).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } @@ -1575,13 +1575,13 @@ static int devstat(dev_t device, uint64_t* count) ret = sysread(path, buf, sizeof(buf)); if (ret < 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to read '%s'.\n", path); + log_fatal(errno, "Failed to read '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } if ((size_t)ret + 1 > sizeof(buf)) { /* LCOV_EXCL_START */ - log_fatal("Too long read '%s'.\n", path); + log_fatal(EEXTERNAL, "Too long read '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } @@ -1728,14 +1728,14 @@ static int devprobe(dev_t device, const char* name, const char* smartctl, int* p x = find_smartctl(); if (!x) { /* LCOV_EXCL_START */ - log_fatal("Cannot find smartctl.\n"); + log_fatal(EEXTERNAL, "Cannot find smartctl.\n"); return -1; /* LCOV_EXCL_STOP */ } if (devresolve(device, file, sizeof(file)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to resolve device '%u:%u'.\n", major(device), minor(device)); + log_fatal(EEXTERNAL, "Failed to resolve device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1755,7 +1755,7 @@ static int devprobe(dev_t device, const char* name, const char* smartctl, int* p if (!f) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from popen).\n", cmd); + log_fatal(EEXTERNAL, "Failed to run '%s' (from popen).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } @@ -1775,14 +1775,14 @@ static int devprobe(dev_t device, const char* name, const char* smartctl, int* p if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:abort\n", file, name); - log_fatal("Failed to run '%s' (not exited).\n", cmd); + log_fatal(EEXTERNAL, "Failed to run '%s' (not exited).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from sh).\n", cmd); + log_fatal(EEXTERNAL, "Failed to run '%s' (from sh).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } @@ -1817,14 +1817,14 @@ static int devdown(dev_t device, const char* name, const char* smartctl) x = find_smartctl(); if (!x) { /* LCOV_EXCL_START */ - log_fatal("Cannot find smartctl.\n"); + log_fatal(EEXTERNAL, "Cannot find smartctl.\n"); return -1; /* LCOV_EXCL_STOP */ } if (devresolve(device, file, sizeof(file)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to resolve device '%u:%u'.\n", major(device), minor(device)); + log_fatal(EEXTERNAL, "Failed to resolve device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1844,7 +1844,7 @@ static int devdown(dev_t device, const char* name, const char* smartctl) if (!f) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from popen).\n", cmd); + log_fatal(EEXTERNAL, "Failed to run '%s' (from popen).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } @@ -1864,21 +1864,21 @@ static int devdown(dev_t device, const char* name, const char* smartctl) if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:abort\n", file, name); - log_fatal("Failed to run '%s' (not exited).\n", cmd); + log_fatal(EEXTERNAL, "Failed to run '%s' (not exited).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:shell\n", file, name); - log_fatal("Failed to run '%s' (from sh).\n", cmd); + log_fatal(EEXTERNAL, "Failed to run '%s' (from sh).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) != 0) { /* LCOV_EXCL_START */ log_tag("device:%s:%s:exit:%d\n", file, name, WEXITSTATUS(ret)); - log_fatal("Failed to run '%s' with return code %xh.\n", cmd, WEXITSTATUS(ret)); + log_fatal(EEXTERNAL, "Failed to run '%s' with return code %xh.\n", cmd, WEXITSTATUS(ret)); return -1; /* LCOV_EXCL_STOP */ } @@ -1922,7 +1922,7 @@ static int devup(dev_t device, const char* name) if (devresolve(device, file, sizeof(file)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to resolve device '%u:%u'.\n", major(device), minor(device)); + log_fatal(EEXTERNAL, "Failed to resolve device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1930,7 +1930,7 @@ static int devup(dev_t device, const char* name) /* O_DIRECT requires memory aligned to the block size */ if (posix_memalign(&buf, 4096, 4096) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to allocate aligned memory for device '%u:%u'.\n", major(device), minor(device)); + log_fatal(errno, "Failed to allocate aligned memory for device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1940,7 +1940,7 @@ static int devup(dev_t device, const char* name) /* LCOV_EXCL_START */ free(buf); log_tag("device:%s:%s:error:%d\n", file, name, errno); - log_fatal("Failed to open device '%u:%u'.\n", major(device), minor(device)); + log_fatal(errno, "Failed to open device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1950,7 +1950,7 @@ static int devup(dev_t device, const char* name) close(f); free(buf); log_tag("device:%s:%s:error:%d\n", file, name, errno); - log_fatal("Failed to get device size '%u:%u'.\n", major(device), minor(device)); + log_fatal(errno, "Failed to get device size '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1966,7 +1966,7 @@ static int devup(dev_t device, const char* name) close(f); free(buf); log_tag("device:%s:%s:error:%d\n", file, name, errno); - log_fatal("Failed to advise device '%u:%u'.\n", major(device), minor(device)); + log_fatal(errno, "Failed to advise device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1978,7 +1978,7 @@ static int devup(dev_t device, const char* name) close(f); free(buf); log_tag("device:%s:%s:error:%d\n", file, name, errno); - log_fatal("Failed to read device '%u:%u'.\n", major(device), minor(device)); + log_fatal(errno, "Failed to read device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -1988,7 +1988,7 @@ static int devup(dev_t device, const char* name) /* LCOV_EXCL_START */ free(buf); log_tag("device:%s:%s:error:%d\n", file, name, errno); - log_fatal("Failed to close device '%u:%u'.\n", major(device), minor(device)); + log_fatal(errno, "Failed to close device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -2193,7 +2193,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation, int others) /* sysfs interface is required */ if (stat("/sys/dev/block", &st) != 0) { /* LCOV_EXCL_START */ - log_fatal("Missing interface /sys/dev/block.\n"); + log_fatal(EEXTERNAL, "Missing interface /sys/dev/block.\n"); return -1; /* LCOV_EXCL_STOP */ } @@ -2220,7 +2220,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation, int others) /* obtain the real device */ if (devdereference(device, &device) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to dereference device '%u:%u'.\n", major(device), minor(device)); + log_fatal(EEXTERNAL, "Failed to dereference device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -2238,7 +2238,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation, int others) /* get the device file */ if (devresolve(device, devinfo->file, sizeof(devinfo->file)) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to resolve device '%u:%u'.\n", major(device), minor(device)); + log_fatal(EEXTERNAL, "Failed to resolve device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -2246,7 +2246,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation, int others) /* expand the tree of devices */ if (devtree(devinfo, device, low) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to expand device '%u:%u'.\n", major(device), minor(device)); + log_fatal(EEXTERNAL, "Failed to expand device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -2256,7 +2256,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation, int others) if (others) { if (devscan(low) != 0) { /* LCOV_EXCL_START */ - log_fatal("Failed to list other devices.\n"); + log_fatal(EEXTERNAL, "Failed to list other devices.\n"); return -1; /* LCOV_EXCL_STOP */ } @@ -2287,7 +2287,7 @@ void os_init(int opt) ret = blkid_get_cache(&cache, NULL); if (ret != 0) { /* LCOV_EXCL_START */ - log_fatal("WARNING Failed to get blkid cache\n"); + log_fatal(EEXTERNAL, "WARNING Failed to get blkid cache\n"); /* LCOV_EXCL_STOP */ } #endif @@ -2379,7 +2379,7 @@ size_t direct_size(void) if (size == -1) { /* LCOV_EXCL_START */ - log_fatal("No page size\n"); + log_fatal(EEXTERNAL, "No page size\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/util.c b/cmdline/util.c index 6f418033..8f5e4779 100644 --- a/cmdline/util.c +++ b/cmdline/util.c @@ -134,8 +134,8 @@ void mtest_vector(int n, size_t size, void** vv) { if (fast_mtest_vector(n, size, vv) != 0) { /* LCOV_EXCL_START */ - log_fatal("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); - log_fatal("Try running a memory test like http://www.memtest86.com/\n"); + log_fatal(EINTERNAL, "DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); + log_fatal(EINTERNAL, "Try running a memory test like http://www.memtest86.com/\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -750,7 +750,7 @@ void memhash(unsigned kind, const unsigned char* seed, void* digest, const void* break; default : /* LCOV_EXCL_START */ - log_fatal("Internal inconsistency in hash function %u\n", kind); + log_fatal(EINTERNAL, "Internal inconsistency in hash function %u\n", kind); exit(EXIT_FAILURE); break; /* LCOV_EXCL_STOP */ diff --git a/doc/snapraid_log.1 b/doc/snapraid_log.1 index 7d8619a1..5fdd5af4 100644 --- a/doc/snapraid_log.1 +++ b/doc/snapraid_log.1 @@ -537,16 +537,22 @@ Messages printed to the screen. .PD 0 .HP 4 .I -One of \`fatal\`, \`error\`, \`expected\`, \`status\`, -\`progress\` or \`verbose\`. +One of \`fatal\`, \`fatal_hardware\`, \`error\`, \`error_hardware\`, +\`expected\`, \`status\`, \`progress\` or \`verbose\`. .HP 4 -.I fatal -A fatal error occurred. Program will abort after this -message. +.I fatal, fatal_hardware +A fatal error occurred. Program will +abort after this message. +The \`hardware\` one means that the problem was caused +by a hardware failure, like an Input/Output error +or a silent data error. .HP 4 -.I error -A generic error condition that doesn\'t prevent the -program to continue. +.I error, error_hardware +A generic error condition that doesn\'t +prevent the program to continue. +The \`hardware\` one means that the problem was caused +by a hardware failure, like an Input/Output error +or a silent data error. .HP 4 .I expected An expected error condition. At present it diff --git a/doc/snapraid_log.d b/doc/snapraid_log.d index 29a04015..a8efc34a 100644 --- a/doc/snapraid_log.d +++ b/doc/snapraid_log.d @@ -358,12 +358,18 @@ General Progress and Execution Tags =msg:: Messages printed to the screen. - - One of `fatal`, `error`, `expected`, `status`, - `progress` or `verbose`. - fatal - A fatal error occurred. Program will abort after this - message. - error - A generic error condition that doesn't prevent the - program to continue. + - One of `fatal`, `fatal_hardware`, `error`, `error_hardware`, + `expected`, `status`, `progress` or `verbose`. + fatal, fatal_hardware - A fatal error occurred. Program will + abort after this message. + The `hardware` one means that the problem was caused + by a hardware failure, like an Input/Output error + or a silent data error. + error, error_hardware - A generic error condition that doesn't + prevent the program to continue. + The `hardware` one means that the problem was caused + by a hardware failure, like an Input/Output error + or a silent data error. expected - An expected error condition. At present it happens only when using the `-m` option with files expected missing. diff --git a/doc/snapraid_log.txt b/doc/snapraid_log.txt index c36db7c1..d792f54f 100644 --- a/doc/snapraid_log.txt +++ b/doc/snapraid_log.txt @@ -377,12 +377,18 @@ Only produced when `--gui` option is used. msg:: Messages printed to the screen. - - One of `fatal`, `error`, `expected`, `status`, - `progress` or `verbose`. - fatal - A fatal error occurred. Program will abort after this - message. - error - A generic error condition that doesn't prevent the - program to continue. + - One of `fatal`, `fatal_hardware`, `error`, `error_hardware`, + `expected`, `status`, `progress` or `verbose`. + fatal, fatal_hardware - A fatal error occurred. Program will + abort after this message. + The `hardware` one means that the problem was caused + by a hardware failure, like an Input/Output error + or a silent data error. + error, error_hardware - A generic error condition that doesn't + prevent the program to continue. + The `hardware` one means that the problem was caused + by a hardware failure, like an Input/Output error + or a silent data error. expected - An expected error condition. At present it happens only when using the `-m` option with files expected missing.