diff --git a/HISTORY b/HISTORY index 2f52a0e0..1ef436a1 100644 --- a/HISTORY +++ b/HISTORY @@ -1,8 +1,12 @@ SnapRAID HISTORY ================ -8.0 2015/01 BETA +8.0 2015/02 BETA ================ + * Changes the log handling. If no log file is specified, all the + log goes to stderr. If a log file is specified, only the most + serious errors are printed on the screen. + This applies to all commands. * Adds new "smart" command to print a SMART report of the array. * Adds new "up" and "down" commands to spin up and down the disks of the array. Note that "down" is available only in Linux. diff --git a/cmdline/check.c b/cmdline/check.c index e7de94d5..f1d4ac72 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -112,7 +112,7 @@ static int is_hash_matching(struct snapraid_state* state, int rehash, unsigned d ) { /* if a hash doesn't match, fail the check */ if (blockcmp(state, rehash, failed[failed_map[j]].block, buffer[failed[failed_map[j]].index], buffer_zero) != 0) { - fprintf(stdlog, "hash_error: Hash mismatch on entry %u\n", failed_map[j]); + ftag("hash_error: Hash mismatch on entry %u\n", failed_map[j]); return 0; } @@ -223,13 +223,13 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u return 0; /* log */ - fprintf(stdlog, "parity_error:%u:", pos); + ftag("parity_error:%u:", pos); for (i = 0; i < r; ++i) { if (i != 0) - fprintf(stdlog, "/"); - fprintf(stdlog, "%s", lev_config_name(ip[i])); + ftag("/"); + ftag("%s", lev_config_name(ip[i])); } - fprintf(stdlog, ":parity: Parity mismatch\n"); + ftag(":parity: Parity mismatch\n"); ++error; } while (combination_next(r, n, ip)); } @@ -263,13 +263,13 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u return 0; /* log */ - fprintf(stdlog, "parity_error:%u:", pos); + ftag("parity_error:%u:", pos); for (i = 0; i < r; ++i) { if (i != 0) - fprintf(stdlog, "/"); - fprintf(stdlog, "%s", lev_config_name(ip[i])); + ftag("/"); + ftag("%s", lev_config_name(ip[i])); } - fprintf(stdlog, ":hash: Hash mismatch\n"); + ftag(":hash: Hash mismatch\n"); ++error; } while (combination_next(r, n, ip)); } @@ -278,7 +278,7 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u if (error) return error; - fprintf(stdlog, "strategy_error:%u: No strategy to recover from %u failures with %u parity %s hash\n", + ftag("strategy_error:%u: No strategy to recover from %u failures with %u parity %s hash\n", pos, failed_count, n, has_hash ? "with" : "without"); return -1; } @@ -338,9 +338,9 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign disk = handle->disk->name; sub = block_file_get(block)->sub; - fprintf(stdlog, "entry:%u:%s:%s:%s:%s:%s:%u:\n", j, state, hash, data, disk, sub, block_file_pos(block)); + ftag("entry:%u:%s:%s:%s:%s:%s:%u:\n", j, state, hash, data, disk, sub, block_file_pos(block)); } else { - fprintf(stdlog, "entry:%u:%s:%s:%s:\n", j, state, hash, data); + ftag("entry:%u:%s:%s:%s:\n", j, state, hash, data); } } @@ -375,7 +375,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign || state_search_fetch(state, rehash, failed[j].block, buffer[failed[j].index]) == 0) ) { /* we already have corrected it! */ - fprintf(stdlog, "hash_import: Fixed entry %u\n", j); + ftag("hash_import: Fixed entry %u\n", j); } else { /* otherwise try to recover it */ failed_map[n] = j; @@ -389,7 +389,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* if nothing to fix */ if (!something_to_recover) { - fprintf(stdlog, "recover_sync:%u:%u: Skipped for already recovered\n", pos, n); + ftag("recover_sync:%u:%u: Skipped for already recovered\n", pos, n); /* recompute only the parity */ raid_gen(diskmax, state->level, state->block_size, buffer); @@ -423,7 +423,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* it may contain garbage */ failed[j].is_outofdate = 1; - fprintf(stdlog, "hash_unknown: Unknown hash on entry %u\n", j); + ftag("hash_unknown: Unknown hash on entry %u\n", j); } else if (hash_is_zero(failed[j].block->hash)) { /* if the block is not filled with 0, we are sure to have */ /* restored it to the state after the 'sync' */ @@ -434,7 +434,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* it may contain garbage */ failed[j].is_outofdate = 1; - fprintf(stdlog, "hash_unknown: Maybe old zero on entry %u\n", j); + ftag("hash_unknown: Maybe old zero on entry %u\n", j); } } else { /* if the hash is different than the previous one, we are sure to have */ @@ -446,7 +446,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* it may contain garbage */ failed[j].is_outofdate = 1; - fprintf(stdlog, "hash_unknown: Maybe old data on entry %u\n", j); + ftag("hash_unknown: Maybe old data on entry %u\n", j); } } } @@ -458,9 +458,9 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign error += ret; if (ret < 0) - fprintf(stdlog, "recover_sync:%u:%u: Failed with no attempts\n", pos, n); + ftag("recover_sync:%u:%u: Failed with no attempts\n", pos, n); else - fprintf(stdlog, "recover_sync:%u:%u: Failed with %d attempts\n", pos, n, ret); + ftag("recover_sync:%u:%u: Failed with %d attempts\n", pos, n, ret); /* Now assume that the parity IS NOT updated at the current state, */ /* but still represent the state before the last 'sync' process. */ @@ -556,7 +556,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* and we don't want to write it to the disk */ failed[j].is_outofdate = 1; - fprintf(stdlog, "hash_unknown: Surely old data on entry %u\n", j); + ftag("hash_unknown: Surely old data on entry %u\n", j); } } } @@ -567,11 +567,11 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign error += ret; if (ret < 0) - fprintf(stdlog, "recover_unsync:%u:%u: Failed with no attempts\n", pos, n); + ftag("recover_unsync:%u:%u: Failed with no attempts\n", pos, n); else - fprintf(stdlog, "recover_unsync:%u:%u: Failed with %d attempts\n", pos, n, ret); + ftag("recover_unsync:%u:%u: Failed with %d attempts\n", pos, n, ret); } else { - fprintf(stdlog, "recover_unsync:%u:%u: Skipped for%s%s\n", pos, n, + ftag("recover_unsync:%u:%u: Skipped for%s%s\n", pos, n, !something_to_recover ? " nothing to recover" : "", !something_unsynced ? " nothing unsynched" : "" ); @@ -636,7 +636,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s /* or at least pointing to NULL, in case it cannot be opened. */ if (handle[j].file != 0 && handle[j].file != file) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in opened file for block %u\n", block->parity_pos); + ferr("Internal inconsistency in opened file for block %u\n", block->parity_pos); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -658,8 +658,8 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = handle_close(&handle[j]); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing '%s'. %s.\n", path, strerror(errno)); - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("Error closing '%s'. %s.\n", path, strerror(errno)); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); return -1; /* LCOV_EXCL_STOP */ } @@ -667,13 +667,13 @@ 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 */ - fprintf(stderr, "Error renaming '%s' to '%s'. %s.\n", path, path_to, strerror(errno)); - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("Error renaming '%s' to '%s'. %s.\n", path, path_to, strerror(errno)); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); return -1; /* LCOV_EXCL_STOP */ } - fprintf(stdlog, "status:unrecoverable:%s:%s\n", disk->name, file->sub); + ftag("status:unrecoverable:%s:%s\n", disk->name, file->sub); if (!state->opt.quiet) { printf("unrecoverable %s\n", path); } @@ -688,7 +688,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s goto close_and_continue; } - fprintf(stdlog, "status:recovered:%s:%s\n", disk->name, file->sub); + ftag("status:recovered:%s:%s\n", disk->name, file->sub); if (!state->opt.quiet) { printf("recovered %s\n", path); } @@ -718,35 +718,35 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s /* LCOV_EXCL_START */ /* mark the file as damaged */ file_flag_set(file, FILE_IS_DAMAGED); - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); return -1; /* LCOV_EXCL_STOP */ } } else { - fprintf(stdlog, "collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", disk->name, file->sub, collide_file->sub); + ftag("collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", disk->name, file->sub, collide_file->sub); } } else { /* we are not fixing, but only checking */ /* print just the final status */ if (file_flag_has(file, FILE_IS_DAMAGED)) { if (state->opt.auditonly) { - fprintf(stdlog, "status:damaged:%s:%s\n", disk->name, file->sub); + ftag("status:damaged:%s:%s\n", disk->name, file->sub); if (!state->opt.quiet) { printf("damaged %s\n", path); } } else { - fprintf(stdlog, "status:unrecoverable:%s:%s\n", disk->name, file->sub); + ftag("status:unrecoverable:%s:%s\n", disk->name, file->sub); if (!state->opt.quiet) { printf("unrecoverable %s\n", path); } } } else if (file_flag_has(file, FILE_IS_FIXED)) { - fprintf(stdlog, "status:recoverable:%s:%s\n", disk->name, file->sub); + ftag("status:recoverable:%s:%s\n", disk->name, file->sub); if (!state->opt.quiet) { printf("recoverable %s\n", path); } } else { - fprintf(stdlog, "status:correct:%s:%s\n", disk->name, file->sub); + ftag("status:correct:%s:%s\n", disk->name, file->sub); if (state->opt.verbose) { printf("correct %s\n", path); } @@ -762,8 +762,8 @@ close_and_continue: ret = handle_close(&handle[j]); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing '%s'. %s.\n", path, strerror(errno)); - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("Error closing '%s'. %s.\n", path, strerror(errno)); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); return -1; /* LCOV_EXCL_STOP */ } @@ -977,7 +977,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected close error in a data disk, it isn't possible to check.\n"); + ferr("DANGER! Unexpected close error in a data disk, it isn't possible to check.\n"); printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; @@ -991,9 +991,9 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { /* LCOV_EXCL_START */ if (errno == EACCES) { - fprintf(stderr, "WARNING! Please give write permission to the file.\n"); + ferr("WARNING! Please give write permission to the file.\n"); } else { - fprintf(stderr, "DANGER! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("DANGER! Without a working data disk, it isn't possible to fix errors on it.\n"); } printf("Stopping at block %u\n", i); ++unrecoverable_error; @@ -1009,7 +1009,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } } else { /* otherwise, open the file only for reading */ - ret = handle_open(&handle[j], file, state->file_mode, stdlog); + ret = handle_open(&handle[j], file, state->file_mode, flog); if (ret == -1) { /* save the failed block for the check/fix */ failed[failed_count].is_bad = 1; @@ -1019,7 +1019,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna failed[failed_count].handle = &handle[j]; ++failed_count; - fprintf(stdlog, "error:%u:%s:%s: Open error at position %u\n", i, disk->name, file->sub, block_file_pos(block)); + ftag("error:%u:%s:%s: Open error at position %u\n", i, disk->name, file->sub, block_file_pos(block)); ++error; continue; } @@ -1046,22 +1046,22 @@ 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 ) { - fprintf(stdlog, "File '%s' is larger than expected.\n", handle[j].path); - fprintf(stdlog, "error:%u:%s:%s: Size error\n", i, disk->name, file->sub); + flog("File '%s' is larger than expected.\n", handle[j].path); + ftag("error:%u:%s:%s: Size error\n", i, disk->name, file->sub); ++error; if (fix) { ret = handle_truncate(&handle[j], file); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected truncate error in a data disk, it isn't possible to fix.\n"); + ferr("DANGER! Unexpected truncate error in a data disk, it isn't possible to fix.\n"); printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ } - fprintf(stdlog, "fixed:%u:%s:%s: Fixed size\n", i, disk->name, file->sub); + ftag("fixed:%u:%s:%s: Fixed size\n", i, disk->name, file->sub); ++recovered_error; } } @@ -1073,7 +1073,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } /* read from the file */ - read_size = handle_read(&handle[j], block, buffer[j], state->block_size, stdlog); + read_size = handle_read(&handle[j], block, buffer[j], state->block_size, flog); if (read_size == -1) { /* save the failed block for the check/fix */ failed[failed_count].is_bad = 1; /* it's bad because we cannot read it */ @@ -1083,7 +1083,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna failed[failed_count].handle = &handle[j]; ++failed_count; - fprintf(stdlog, "error:%u:%s:%s: Read error at position %u\n", i, disk->name, file->sub, block_file_pos(block)); + ftag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, file->sub, block_file_pos(block)); ++error; continue; } @@ -1124,7 +1124,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna failed[failed_count].handle = &handle[j]; ++failed_count; - fprintf(stdlog, "error:%u:%s:%s: Data error at position %u\n", i, disk->name, file->sub, block_file_pos(block)); + ftag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, file->sub, block_file_pos(block)); ++error; continue; } @@ -1160,11 +1160,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* read the parity */ for (l = 0; l < state->level; ++l) { if (parity[l]) { - ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, stdlog); + ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, flog); if (ret == -1) { buffer_recov[l] = 0; /* no parity to use */ - fprintf(stdlog, "parity_error:%u:%s: Read error\n", i, lev_config_name(l)); + ftag("parity_error:%u:%s: Read error\n", i, lev_config_name(l)); ++error; } } else { @@ -1183,7 +1183,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* print a list of all the errors in files */ for (j = 0; j < failed_count; ++j) { if (failed[j].is_bad) - fprintf(stdlog, "unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); + ftag("unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); } /* keep track of damaged files */ @@ -1201,7 +1201,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna for (j = 0; j < failed_count; ++j) { if (failed[j].is_bad && failed[j].is_outofdate) { ++partial_recover_error; - fprintf(stdlog, "unrecoverable:%u:%s:%s: Unrecoverable unsynced error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); + ftag("unrecoverable:%u:%s:%s: Unrecoverable unsynced error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); } } if (partial_recover_error != 0) { @@ -1218,7 +1218,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (buffer_recov[l] != 0 && memcmp(buffer_recov[l], buffer[diskmax + l], state->block_size) != 0) { buffer_recov[l] = 0; - fprintf(stdlog, "parity_error:%u:%s: Data error\n", i, lev_config_name(l)); + ftag("parity_error:%u:%s: Data error\n", i, lev_config_name(l)); ++error; } } @@ -1244,10 +1244,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna file_flag_set(block_file_get(failed[j].block), FILE_IS_DAMAGED); if (errno == EACCES) { - fprintf(stderr, "WARNING! Please give write permission to the file.\n"); + ferr("WARNING! Please give write permission to the file.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } printf("Stopping at block %u\n", i); ++unrecoverable_error; @@ -1266,7 +1266,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* note that it could be also marked as damaged in other iterations */ file_flag_set(block_file_get(failed[j].block), FILE_IS_FIXED); - fprintf(stdlog, "fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); + ftag("fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); ++recovered_error; } @@ -1281,14 +1281,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { /* LCOV_EXCL_START */ /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - fprintf(stderr, "WARNING! Without a working %s disk, it isn't possible to fix errors on it.\n", lev_name(l)); + ferr("WARNING! Without a working %s disk, it isn't possible to fix errors on it.\n", lev_name(l)); printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ } - fprintf(stdlog, "parity_fixed:%u:%s: Fixed data error\n", i, lev_config_name(l)); + ftag("parity_fixed:%u:%s: Fixed data error\n", i, lev_config_name(l)); ++recovered_error; } } @@ -1368,18 +1368,18 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { unsuccesful = 1; - fprintf(stdlog, "Error stating empty file '%s'. %s.\n", path, strerror(errno)); - fprintf(stdlog, "error:%s:%s: Empty file stat error\n", disk->name, file->sub); + flog("Error stating empty file '%s'. %s.\n", path, strerror(errno)); + ftag("error:%s:%s: Empty file stat error\n", disk->name, file->sub); ++error; } else if (!S_ISREG(st.st_mode)) { unsuccesful = 1; - fprintf(stdlog, "error:%s:%s: Empty file error for not regular file\n", disk->name, file->sub); + ftag("error:%s:%s: Empty file error for not regular file\n", disk->name, file->sub); ++error; } else if (st.st_size != 0) { unsuccesful = 1; - fprintf(stdlog, "error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, file->sub, st.st_size); + ftag("error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, file->sub, st.st_size); ++error; } @@ -1390,7 +1390,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkancestor(path); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); printf("Stopping\n"); ++unrecoverable_error; goto bail; @@ -1402,12 +1402,12 @@ 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 */ - fprintf(stderr, "Error creating empty file '%s'. %s.\n", path, strerror(errno)); + ferr("Error creating empty file '%s'. %s.\n", path, strerror(errno)); if (errno == EACCES) { - fprintf(stderr, "WARNING! Please give write permission to the file.\n"); + ferr("WARNING! Please give write permission to the file.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } printf("Stopping\n"); ++unrecoverable_error; @@ -1421,8 +1421,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_START */ close(f); - fprintf(stderr, "Error timing file '%s'. %s.\n", file->sub, strerror(errno)); - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("Error timing file '%s'. %s.\n", file->sub, strerror(errno)); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); printf("Stopping\n"); ++unrecoverable_error; goto bail; @@ -1433,17 +1433,17 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); printf("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ } - fprintf(stdlog, "fixed:%s:%s: Fixed empty file\n", disk->name, file->sub); + ftag("fixed:%s:%s: Fixed empty file\n", disk->name, file->sub); ++recovered_error; - fprintf(stdlog, "status:recovered:%s:%s\n", disk->name, file->sub); + ftag("status:recovered:%s:%s\n", disk->name, file->sub); if (!state->opt.quiet) { printf("recovered %s%s\n", disk->dir, file->sub); } @@ -1478,13 +1478,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { unsuccesful = 1; - fprintf(stdlog, "Error stating hardlink '%s'. %s.\n", path, strerror(errno)); - fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink stat error\n", disk->name, link->sub, link->linkto); + flog("Error stating hardlink '%s'. %s.\n", path, strerror(errno)); + ftag("hardlinkerror:%s:%s:%s: Hardlink stat error\n", disk->name, link->sub, link->linkto); ++error; } else if (!S_ISREG(st.st_mode)) { unsuccesful = 1; - fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink error for not regular file\n", disk->name, link->sub, link->linkto); + ftag("hardlinkerror:%s:%s:%s: Hardlink error for not regular file\n", disk->name, link->sub, link->linkto); ++error; } @@ -1508,19 +1508,19 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } } - fprintf(stdlog, "Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno)); - fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink to stat error\n", disk->name, link->sub, link->linkto); + flog("Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno)); + ftag("hardlinkerror:%s:%s:%s: Hardlink to stat error\n", disk->name, link->sub, link->linkto); ++error; } else if (!S_ISREG(stto.st_mode)) { unsuccesful = 1; - fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, link->sub, link->linkto); + ftag("hardlinkerror:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, link->sub, link->linkto); ++error; } else if (!unsuccesful && st.st_ino != stto.st_ino) { unsuccesful = 1; - fprintf(stdlog, "Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto); - fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, link->sub, link->linkto); + flog("Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto); + ftag("hardlinkerror:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, link->sub, link->linkto); ++error; } } else { @@ -1530,14 +1530,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret < 0) { unsuccesful = 1; - fprintf(stdlog, "Error reading symlink '%s'. %s.\n", path, strerror(errno)); - fprintf(stdlog, "symlinkerror:%s:%s: Symlink read error\n", disk->name, link->sub); + flog("Error reading symlink '%s'. %s.\n", path, strerror(errno)); + ftag("symlinkerror:%s:%s: Symlink read error\n", disk->name, link->sub); ++error; } else if (ret >= PATH_MAX) { unsuccesful = 1; - fprintf(stdlog, "Error reading symlink '%s'. Symlink too long.\n", path); - fprintf(stdlog, "symlinkerror:%s:%s: Symlink read error\n", disk->name, link->sub); + flog("Error reading symlink '%s'. Symlink too long.\n", path); + ftag("symlinkerror:%s:%s: Symlink read error\n", disk->name, link->sub); ++error; } else { linkto[ret] = 0; @@ -1545,7 +1545,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (strcmp(linkto, link->linkto) != 0) { unsuccesful = 1; - fprintf(stdlog, "symlinkerror:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, link->sub, linkto, link->linkto); + ftag("symlinkerror:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, link->sub, linkto, link->linkto); ++error; } } @@ -1556,7 +1556,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkancestor(path); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); printf("Stopping\n"); ++unrecoverable_error; goto bail; @@ -1567,8 +1567,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = remove(path); if (ret != 0 && errno != ENOENT) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error removing '%s'. %s.\n", path, strerror(errno)); - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("Error removing '%s'. %s.\n", path, strerror(errno)); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); printf("Stopping\n"); ++unrecoverable_error; goto bail; @@ -1580,12 +1580,12 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = hardlink(pathto, path); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno)); + ferr("Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno)); if (errno == EACCES) { - fprintf(stderr, "WARNING! Please give write permission to the hardlink.\n"); + ferr("WARNING! Please give write permission to the hardlink.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } printf("Stopping\n"); ++unrecoverable_error; @@ -1593,18 +1593,18 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_STOP */ } - fprintf(stdlog, "hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, link->sub); + ftag("hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, link->sub); ++recovered_error; } else { ret = symlink(link->linkto, path); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing symlink '%s' to '%s'. %s.\n", path, link->linkto, strerror(errno)); + ferr("Error writing symlink '%s' to '%s'. %s.\n", path, link->linkto, strerror(errno)); if (errno == EACCES) { - fprintf(stderr, "WARNING! Please give write permission to the symlink.\n"); + ferr("WARNING! Please give write permission to the symlink.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } printf("Stopping\n"); ++unrecoverable_error; @@ -1612,11 +1612,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_STOP */ } - fprintf(stdlog, "symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, link->sub); + ftag("symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, link->sub); ++recovered_error; } - fprintf(stdlog, "status:recovered:%s:%s\n", disk->name, link->sub); + ftag("status:recovered:%s:%s\n", disk->name, link->sub); if (!state->opt.quiet) { printf("recovered %s%s\n", disk->dir, link->sub); } @@ -1646,13 +1646,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { unsuccesful = 1; - fprintf(stdlog, "Error stating dir '%s'. %s.\n", path, strerror(errno)); - fprintf(stdlog, "dir_error:%s:%s: Dir stat error\n", disk->name, dir->sub); + flog("Error stating dir '%s'. %s.\n", path, strerror(errno)); + ftag("dir_error:%s:%s: Dir stat error\n", disk->name, dir->sub); ++error; } else if (!S_ISDIR(st.st_mode)) { unsuccesful = 1; - fprintf(stdlog, "dir_error:%s:%s: Dir error for not directory\n", disk->name, dir->sub); + ftag("dir_error:%s:%s: Dir error for not directory\n", disk->name, dir->sub); ++error; } @@ -1661,7 +1661,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkancestor(path); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); printf("Stopping\n"); ++unrecoverable_error; goto bail; @@ -1672,12 +1672,12 @@ 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 */ - fprintf(stderr, "Error creating dir '%s'. %s.\n", path, strerror(errno)); + ferr("Error creating dir '%s'. %s.\n", path, strerror(errno)); if (errno == EACCES) { - fprintf(stderr, "WARNING! Please give write permission to the dir.\n"); + ferr("WARNING! Please give write permission to the dir.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } printf("Stopping\n"); ++unrecoverable_error; @@ -1685,10 +1685,10 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_STOP */ } - fprintf(stdlog, "dir_fixed:%s:%s: Fixed dir error\n", disk->name, dir->sub); + ftag("dir_fixed:%s:%s: Fixed dir error\n", disk->name, dir->sub); ++recovered_error; - fprintf(stdlog, "status:recovered:%s:%s\n", disk->name, dir->sub); + ftag("status:recovered:%s:%s\n", disk->name, dir->sub); if (!state->opt.quiet) { printf("recovered %s%s\n", disk->dir, dir->sub); } @@ -1704,7 +1704,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected close error in a data disk.\n"); + ferr("DANGER! Unexpected close error in a data disk.\n"); ++unrecoverable_error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -1752,8 +1752,8 @@ bail: ret = remove(path); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error removing '%s'. %s.\n", path, strerror(errno)); - fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + ferr("Error removing '%s'. %s.\n", path, strerror(errno)); + ferr("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); ++unrecoverable_error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -1784,30 +1784,30 @@ bail: printf("Everything OK\n"); } - fprintf(stdlog, "summary:error:%u\n", error); + ftag("summary:error:%u\n", error); if (fix) - fprintf(stdlog, "summary:error_recovered:%u\n", recovered_error); + ftag("summary:error_recovered:%u\n", recovered_error); if (!state->opt.auditonly) - fprintf(stdlog, "summary:error_unrecoverable:%u\n", unrecoverable_error); + ftag("summary:error_unrecoverable:%u\n", unrecoverable_error); if (fix) { if (error + recovered_error + unrecoverable_error == 0) - fprintf(stdlog, "summary:exit:ok\n"); + ftag("summary:exit:ok\n"); else if (unrecoverable_error == 0) - fprintf(stdlog, "summary:exit:recovered\n"); + ftag("summary:exit:recovered\n"); else - fprintf(stdlog, "summary:exit:unrecoverable\n"); + ftag("summary:exit:unrecoverable\n"); } else if (!state->opt.auditonly) { if (error + unrecoverable_error == 0) - fprintf(stdlog, "summary:exit:ok\n"); + ftag("summary:exit:ok\n"); else if (unrecoverable_error == 0) - fprintf(stdlog, "summary:exit:recoverable\n"); + ftag("summary:exit:recoverable\n"); else - fprintf(stdlog, "summary:exit:unrecoverable\n"); + ftag("summary:exit:unrecoverable\n"); } else { /* audit only */ if (error == 0) - fprintf(stdlog, "summary:exit:ok\n"); + ftag("summary:exit:ok\n"); else - fprintf(stdlog, "summary:exit:error\n"); + ftag("summary:exit:error\n"); } fflush(stdlog); @@ -1860,7 +1860,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b if (blockstart > blockmax) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); + ferr("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1878,7 +1878,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b ret = parity_create(parity_ptr[l], state->parity[l].path, &out_size, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "WARNING! Without an accessible %s file, it isn't possible to fix any error.\n", lev_name(l)); + ferr("WARNING! Without an accessible %s file, it isn't possible to fix any error.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1886,7 +1886,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b ret = parity_chsize(parity_ptr[l], size, &out_size, state->opt.skip_fallocate); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); + ferr("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1935,7 +1935,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b ret = parity_close(parity_ptr[l]); /* LCOV_EXCL_START */ if (ret == -1) { - fprintf(stderr, "DANGER! Unexpected close error in %s disk.\n", lev_name(l)); + ferr("DANGER! Unexpected close error in %s disk.\n", lev_name(l)); ++error; /* continue, as we are already exiting */ } diff --git a/cmdline/device.c b/cmdline/device.c index 0b03d1b2..2f4efe99 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -449,17 +449,17 @@ static void state_smart(int verbose, unsigned n, tommy_list* low) printf("\n"); - fprintf(stdlog, "smart:%s:%s:%s:%g\n", devinfo->file, devinfo->name, devinfo->smart_serial, afr); + ftag("smart:%s:%s:%s:%g\n", devinfo->file, devinfo->name, devinfo->smart_serial, afr); for (j = 0; j < 256; ++j) { if (devinfo->smart[j] != SMART_UNASSIGNED) - fprintf(stdlog, "attr:%s:%u:%" PRIu64 "\n", devinfo->file, j, devinfo->smart[j]); + ftag("attr:%s:%u:%" PRIu64 "\n", devinfo->file, j, devinfo->smart[j]); } if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED) - fprintf(stdlog, "attr:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->smart[SMART_SIZE]); + ftag("attr:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->smart[SMART_SIZE]); if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED) - fprintf(stdlog, "attr:%s:error:%" PRIu64 "\n", devinfo->file, devinfo->smart[SMART_ERROR]); + ftag("attr:%s:error:%" PRIu64 "\n", devinfo->file, devinfo->smart[SMART_ERROR]); if (devinfo->smart[SMART_ROTATION_RATE] != SMART_UNASSIGNED) - fprintf(stdlog, "attr:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->smart[SMART_ROTATION_RATE]); + ftag("attr:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->smart[SMART_ROTATION_RATE]); } printf("\n"); @@ -470,7 +470,7 @@ static void state_smart(int verbose, unsigned n, tommy_list* low) */ p_at_least_one_failure = poisson_prob_n_or_more_failures(array_failure_rate, 1); - fprintf(stdlog, "summary:array_failure:%g:%g\n", array_failure_rate, p_at_least_one_failure); + ftag("summary:array_failure:%g:%g\n", array_failure_rate, p_at_least_one_failure); /* |<##################################################################72>|####80>| */ printf("The FP column is the estimated probability (in percentage) that the disk\n"); @@ -564,12 +564,12 @@ void state_device(struct snapraid_state* state, int operation) if (devquery(&high, &low, operation) != 0) { switch (operation) { - case DEVICE_UP : fprintf(stderr, "Spinup"); break; - case DEVICE_DOWN : fprintf(stderr, "Spindown"); break; - case DEVICE_LIST : fprintf(stderr, "List"); break; - case DEVICE_SMART : fprintf(stderr, "SMART"); break; + case DEVICE_UP : ferr("Spinup"); break; + case DEVICE_DOWN : ferr("Spindown"); break; + case DEVICE_LIST : ferr("List"); break; + case DEVICE_SMART : ferr("SMART"); break; } - fprintf(stderr, " unsupported in this platform.\n"); + ferr(" unsupported in this platform.\n"); } else { #ifndef _WIN32 diff --git a/cmdline/dry.c b/cmdline/dry.c index 0f915b6e..b94455e7 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -82,7 +82,7 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected close error in a data disk, it isn't possible to dry.\n"); + ferr("DANGER! Unexpected close error in a data disk, it isn't possible to dry.\n"); printf("Stopping at block %u\n", i); ++error; goto bail; @@ -90,10 +90,10 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit } /* open the file only for reading */ - ret = handle_open(&handle[j], block_file_get(block), state->file_mode, stdlog); + ret = handle_open(&handle[j], block_file_get(block), state->file_mode, ferr); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected open error in a data disk, it isn't possible to dry.\n"); + ferr("DANGER! Unexpected open error in a data disk, it isn't possible to dry.\n"); printf("Stopping at block %u\n", i); ++error; goto bail; @@ -102,9 +102,9 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit } /* read from the file */ - read_size = handle_read(&handle[j], block, buffer_aligned, state->block_size, stdlog); + read_size = handle_read(&handle[j], block, buffer_aligned, state->block_size, flog); if (read_size == -1) { - fprintf(stdlog, "error:%u:%s:%s: Read error at position %u\n", i, disk->name, block_file_get(block)->sub, block_file_pos(block)); + ftag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, block_file_get(block)->sub, block_file_pos(block)); ++error; continue; } @@ -121,9 +121,9 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit /* until now is CPU */ state_usage_cpu(state); - ret = parity_read(parity[l], i, buffer_aligned, state->block_size, stdlog); + ret = parity_read(parity[l], i, buffer_aligned, state->block_size, flog); if (ret == -1) { - fprintf(stdlog, "parity_error:%u:%s: Read error\n", i, lev_config_name(l)); + ftag("parity_error:%u:%s: Read error\n", i, lev_config_name(l)); ++error; } @@ -153,7 +153,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected close error in a data disk.\n"); + ferr("DANGER! Unexpected close error in a data disk.\n"); ++error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -191,7 +191,7 @@ void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t if (blockstart > blockmax) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); + ferr("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/dup.c b/cmdline/dup.c index dc4d2e10..9ee4bfa7 100644 --- a/cmdline/dup.c +++ b/cmdline/dup.c @@ -125,7 +125,7 @@ void state_dup(struct snapraid_state* state) if (dup) { ++count; size += dup->file->size; - fprintf(stdlog, "dup:%s:%s:%s:%s:%" PRIu64 ": dup\n", disk->name, file->sub, dup->disk->name, dup->file->sub, dup->file->size); + ftag("dup:%s:%s:%s:%s:%" PRIu64 ": dup\n", disk->name, file->sub, dup->disk->name, dup->file->sub, dup->file->size); printf("%12" PRIu64 " %s%s = %s%s\n", file->size, disk->dir, file->sub, dup->disk->dir, dup->file->sub); hash_free(hash); } else { @@ -144,12 +144,12 @@ void state_dup(struct snapraid_state* state) else printf("No duplicates\n"); - fprintf(stdlog, "summary:dup_count:%u\n", count); - fprintf(stdlog, "summary:dup_size:%" PRIu64 "\n", size); + ftag("summary:dup_count:%u\n", count); + ftag("summary:dup_size:%" PRIu64 "\n", size); if (count == 0) { - fprintf(stdlog, "summary:exit:unique\n"); + ftag("summary:exit:unique\n"); } else { - fprintf(stdlog, "summary:exit:dup\n"); + ftag("summary:exit:dup\n"); } fflush(stdlog); } diff --git a/cmdline/elem.c b/cmdline/elem.c index 0e0ea18c..53884f29 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -277,7 +277,7 @@ int filter_existence(int filter_missing, const char* dir, const char* sub) if (errno == ENOENT) return 0; /* LCOV_EXCL_START */ - fprintf(stderr, "Error in stat file '%s'. %s.\n", path, strerror(errno)); + ferr("Error in stat file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -342,7 +342,7 @@ block_off_t block_file_pos(struct snapraid_block* block) if (block < file->blockvec || block >= file->blockvec + file->blockmax) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in block %u ownership\n", block->parity_pos); + ferr("Internal inconsistency in block %u ownership\n", block->parity_pos); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -456,21 +456,21 @@ void file_copy(struct snapraid_file* src_file, struct snapraid_file* dst_file) if (src_file->size != dst_file->size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in copy file with different size\n"); + ferr("Internal inconsistency in copy file with different size\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (src_file->mtime_sec != dst_file->mtime_sec) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in copy file with different mtime_sec\n"); + ferr("Internal inconsistency in copy file with different mtime_sec\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (src_file->mtime_nsec != dst_file->mtime_nsec) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in copy file with different mtime_nsec\n"); + ferr("Internal inconsistency in copy file with different mtime_nsec\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -747,7 +747,7 @@ int disk_is_empty(struct snapraid_disk* disk, block_off_t blockmax) return 0; default : /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for used block in disk '%s' without files\n", disk->name); + ferr("Internal inconsistency for used block in disk '%s' without files\n", disk->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/handle.c b/cmdline/handle.c index 11958248..db1a3d36 100644 --- a/cmdline/handle.c +++ b/cmdline/handle.c @@ -90,7 +90,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in handle->f = -1; handle->valid_size = 0; - fprintf(stderr, "Error opening file '%s'. %s.\n", handle->path, strerror(errno)); + ferr("Error opening file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -102,7 +102,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 */ - fprintf(stderr, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); + ferr("Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -116,7 +116,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in ret = posix_fadvise(handle->f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error advising file '%s'. %s.\n", handle->path, strerror(ret)); + ferr("Error advising file '%s'. %s.\n", handle->path, strerror(ret)); return -1; /* LCOV_EXCL_STOP */ } @@ -134,9 +134,9 @@ int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file) if (ret != 0) { /* LCOV_EXCL_START */ if (errno == EACCES) { - fprintf(stderr, "Failed to truncate file '%s' for missing write permission.\n", handle->path); + ferr("Failed to truncate file '%s' for missing write permission.\n", handle->path); } else { - fprintf(stderr, "Error truncating file '%s'. %s.\n", handle->path, strerror(errno)); + ferr("Error truncating file '%s'. %s.\n", handle->path, strerror(errno)); } return -1; /* LCOV_EXCL_STOP */ @@ -148,7 +148,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, FILE* out) +int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out) { int ret; int flags; @@ -179,7 +179,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int handle->f = -1; handle->valid_size = 0; - fprintf(out, "Error opening file '%s'. %s.\n", handle->path, strerror(errno)); + out("Error opening file '%s'. %s.\n", handle->path, strerror(errno)); return -1; } @@ -190,7 +190,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 */ - fprintf(out, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); + out("Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -204,7 +204,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int ret = posix_fadvise(handle->f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(out, "Error advising file '%s'. %s.\n", handle->path, strerror(ret)); + out("Error advising file '%s'. %s.\n", handle->path, strerror(ret)); return -1; /* LCOV_EXCL_STOP */ } @@ -223,7 +223,7 @@ int handle_close(struct snapraid_handle* handle) ret = close(handle->f); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file '%s'. %s.\n", handle->file->sub, strerror(errno)); + ferr("Error closing file '%s'. %s.\n", handle->file->sub, strerror(errno)); /* invalidate for error */ handle->file = 0; @@ -242,7 +242,7 @@ int handle_close(struct snapraid_handle* handle) return 0; } -int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, FILE* out) +int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, fptr* out) { ssize_t read_ret; data_off_t offset; @@ -253,7 +253,7 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un /* check if we are going to read only not initialized data */ if (offset >= handle->valid_size) { - fprintf(out, "Reading missing data from file '%s' at offset %" PRIu64 ".\n", handle->path, offset); + out("Reading missing data from file '%s' at offset %" PRIu64 ".\n", handle->path, offset); return -1; } @@ -262,7 +262,7 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un #if !HAVE_PREAD if (lseek(handle->f, offset, SEEK_SET) != offset) { /* LCOV_EXCL_START */ - fprintf(out, "Error seeking file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno)); + out("Error seeking file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -279,12 +279,12 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un if (read_ret < 0) { /* LCOV_EXCL_START */ - fprintf(out, "Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", handle->path, offset + count, read_size - count, strerror(errno)); + out("Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", handle->path, offset + count, read_size - count, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } if (read_ret == 0) { - fprintf(out, "Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno)); + out("Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno)); return -1; } @@ -325,7 +325,7 @@ int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, u #else if (lseek(handle->f, offset, SEEK_SET) != offset) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error seeking file '%s'. %s.\n", handle->path, strerror(errno)); + ferr("Error seeking file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -334,7 +334,7 @@ int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, u #endif if (write_ret != (ssize_t)write_size) { /* conversion is safe because block_size is always small */ /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing file '%s'. %s.\n", handle->path, strerror(errno)); + ferr("Error writing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -362,7 +362,7 @@ int handle_utime(struct snapraid_handle* handle) if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error timing file '%s'. %s.\n", handle->file->sub, strerror(errno)); + ferr("Error timing file '%s'. %s.\n", handle->file->sub, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -410,7 +410,7 @@ struct snapraid_handle* handle_map(struct snapraid_state* state, unsigned* handl } if (k == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal error for inconsistent disk mapping.\n"); + ferr("Internal error for inconsistent disk mapping.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/handle.h b/cmdline/handle.h index 379b3d80..75f724cc 100644 --- a/cmdline/handle.h +++ b/cmdline/handle.h @@ -19,6 +19,7 @@ #define __HANDLE_H #include "state.h" +#include "support.h" /****************************************************************************/ /* handle */ @@ -52,7 +53,7 @@ int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file); * Opens a file. * The file is opened for reading. */ -int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, FILE* out); +int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int mode, fptr* out); /** * Closes a file. @@ -63,7 +64,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, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, FILE* out); +int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, fptr* out); /** * Writes a block to a file. diff --git a/cmdline/import.c b/cmdline/import.c index fe85404c..42eda474 100644 --- a/cmdline/import.c +++ b/cmdline/import.c @@ -78,7 +78,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t f = open(path, flags); if (f == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening file '%s'. %s.\n", path, strerror(errno)); + ferr("Error opening file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -89,7 +89,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t ret = posix_fadvise(f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error advising file '%s'. %s.\n", path, strerror(ret)); + ferr("Error advising file '%s'. %s.\n", path, strerror(ret)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -106,7 +106,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 */ - fprintf(stderr, "Error reading file '%s'. %s.\n", path, strerror(errno)); + ferr("Error reading file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -132,7 +132,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file '%s'. %s.\n", path, strerror(errno)); + ferr("Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -174,14 +174,14 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid f = open(path, O_RDONLY | O_BINARY); if (f == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening file '%s'. %s.\n", path, strerror(errno)); + ferr("Error opening file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, block->offset, SEEK_SET) != block->offset) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error seeking file '%s'. %s.\n", path, strerror(errno)); + ferr("Error seeking file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -189,7 +189,7 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid ret = read(f, buffer, read_size); if (ret < 0 || (unsigned)ret != read_size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading file '%s'. %s.\n", path, strerror(errno)); + ferr("Error reading file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -197,7 +197,7 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file '%s'. %s.\n", path, strerror(errno)); + ferr("Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -215,8 +215,8 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid if (memcmp(buffer_hash, hash, HASH_SIZE) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in data reading file '%s'.\n", path); - fprintf(stderr, "Please don't change imported files while running.\n"); + ferr("Error in data reading file '%s'.\n", path); + ferr("Please don't change imported files while running.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -231,7 +231,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error opening directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -247,7 +247,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error reading directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -274,7 +274,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 */ - fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -283,7 +283,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 */ - fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -299,7 +299,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) if (closedir(d) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error closing directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/list.c b/cmdline/list.c index b3a1009e..6b9e2d3e 100644 --- a/cmdline/list.c +++ b/cmdline/list.c @@ -59,7 +59,7 @@ void state_list(struct snapraid_state* state) ++file_count; file_size += file->size; - fprintf(stdlog, "file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIi64 "\n", disk->name, file->sub, file->size, file->mtime_sec, file->mtime_nsec, file->inode); + ftag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIi64 "\n", disk->name, file->sub, file->size, file->mtime_sec, file->mtime_nsec, file->inode); t = file->mtime_sec; #if HAVE_LOCALTIME_R @@ -99,7 +99,7 @@ void state_list(struct snapraid_state* state) ++link_count; - fprintf(stdlog, "link_%s:%s:%s:%s\n", type, disk->name, link->sub, link->linkto); + ftag("link_%s:%s:%s:%s\n", type, disk->name, link->sub, link->linkto); printf("%12s ", type); printf(" "); @@ -113,10 +113,10 @@ void state_list(struct snapraid_state* state) printf("%8u files, for %" PRIu64 " GiB\n", file_count, file_size / (1024 * 1024 * 1024)); printf("%8u links\n", link_count); - fprintf(stdlog, "summary:file_count:%u\n", file_count); - fprintf(stdlog, "summary:file_size:%" PRIu64 "\n", file_size); - fprintf(stdlog, "summary:link_count:%u\n", link_count); - fprintf(stdlog, "summary:exit:ok\n"); + ftag("summary:file_count:%u\n", file_count); + ftag("summary:file_size:%" PRIu64 "\n", file_size); + ftag("summary:link_count:%u\n", link_count); + ftag("summary:exit:ok\n"); fflush(stdlog); } diff --git a/cmdline/mingw.c b/cmdline/mingw.c index 3cd99fc9..1a4827b9 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -137,19 +137,19 @@ void os_init(int opt) ntdll = GetModuleHandle("NTDLL.DLL"); if (!ntdll) { - fprintf(stderr, "Error loading the NTDLL module.\n"); + ferr("Error loading the NTDLL module.\n"); exit(EXIT_FAILURE); } kernel32 = GetModuleHandle("KERNEL32.DLL"); if (!kernel32) { - fprintf(stderr, "Error loading the KERNEL32 module.\n"); + ferr("Error loading the KERNEL32 module.\n"); exit(EXIT_FAILURE); } dll_advapi32 = LoadLibrary("ADVAPI32.DLL"); if (!dll_advapi32) { - fprintf(stderr, "Error loading the ADVAPI32 module.\n"); + ferr("Error loading the ADVAPI32 module.\n"); exit(EXIT_FAILURE); } @@ -162,7 +162,7 @@ void os_init(int opt) ptr_RtlGenRandom = (void*)GetProcAddress(dll_advapi32, "SystemFunction036"); if (!ptr_RtlGenRandom) { - fprintf(stderr, "Error loading RtlGenRandom() from the ADVAPI32 module.\n"); + ferr("Error loading RtlGenRandom() from the ADVAPI32 module.\n"); exit(EXIT_FAILURE); } @@ -216,7 +216,7 @@ static wchar_t* u8tou16(const char* src) ret = MultiByteToWideChar(CP_UTF8, 0, src, -1, conv_utf16_buffer[conv_utf16], sizeof(conv_utf16_buffer[0]) / sizeof(wchar_t)); if (ret <= 0) { - fprintf(stderr, "Error converting name '%s' from UTF-8 to UTF-16\n", src); + ferr("Error converting name '%s' from UTF-8 to UTF-16\n", src); exit(EXIT_FAILURE); } @@ -235,7 +235,7 @@ static char* u16tou8(const wchar_t* src, size_t number_of_wchar, size_t* result_ ret = WideCharToMultiByte(CP_UTF8, 0, src, number_of_wchar, conv_utf8_buffer[conv_utf8], sizeof(conv_utf8_buffer[0]), 0, 0); if (ret <= 0) { - fprintf(stderr, "Error converting from UTF-16 to UTF-8\n"); + ferr("Error converting from UTF-16 to UTF-8\n"); exit(EXIT_FAILURE); } @@ -322,7 +322,7 @@ static wchar_t* convert_arg(const char* src, int only_if_required) ret = MultiByteToWideChar(CP_UTF8, 0, src, -1, dst, sizeof(conv_utf16_buffer[0]) / sizeof(wchar_t) - count); if (ret <= 0) { - fprintf(stderr, "Error converting name '%s' from UTF-8 to UTF-16\n", src); + ferr("Error converting name '%s' from UTF-8 to UTF-16\n", src); exit(EXIT_FAILURE); } @@ -556,7 +556,7 @@ static void windows_finddata2dirent(const WIN32_FIND_DATAW* info, struct windows name = u16tou8(info->cFileName, wcslen(info->cFileName), &len); if (len + 1 >= sizeof(dirent->d_name)) { - fprintf(stderr, "Name too long\n"); + ferr("Name too long\n"); exit(EXIT_FAILURE); } @@ -574,7 +574,7 @@ static void windows_stream2dirent(const BY_HANDLE_FILE_INFORMATION* info, const name = u16tou8(stream->FileName, stream->FileNameLength / 2, &len); if (len + 1 >= sizeof(dirent->d_name)) { - fprintf(stderr, "Name too long\n"); + ferr("Name too long\n"); exit(EXIT_FAILURE); } @@ -625,7 +625,7 @@ static void windows_errno(DWORD error) errno = EPERM; break; default : - fprintf(stderr, "Unexpected Windows error %d.\n", (int)error); + ferr("Unexpected Windows error %d.\n", (int)error); errno = EIO; break; } @@ -924,8 +924,8 @@ int windows_fsync(int fd) * this error, but not enough sure to ignore it. * So, we use now an extended error reporting. */ - fprintf(stderr, "Unexpected Windows INVALID_HANDLE error in FlushFileBuffers().\n"); - fprintf(stderr, "Are you using ATA-over-Ethernet ? Please report it.\n"); + ferr("Unexpected Windows INVALID_HANDLE error in FlushFileBuffers().\n"); + ferr("Are you using ATA-over-Ethernet ? Please report it.\n"); /* normal error processing */ windows_errno(error); @@ -1056,7 +1056,7 @@ static windows_dir* windows_opendir_find(const char* dir) dirstream = malloc(sizeof(windows_dir)); if (!dirstream) { - fprintf(stderr, "Low memory\n"); + ferr("Low memory\n"); exit(EXIT_FAILURE); } @@ -1193,7 +1193,7 @@ static windows_dir* windows_opendir_stream(const char* dir) dirstream = malloc(sizeof(windows_dir)); if (!dirstream) { - fprintf(stderr, "Low memory\n"); + ferr("Low memory\n"); exit(EXIT_FAILURE); } @@ -1203,7 +1203,7 @@ static windows_dir* windows_opendir_stream(const char* dir) dirstream->buffer_size = 64 * 1024; dirstream->buffer = malloc(dirstream->buffer_size); if (!dirstream->buffer) { - fprintf(stderr, "Low memory\n"); + ferr("Low memory\n"); exit(EXIT_FAILURE); } @@ -1680,7 +1680,7 @@ retry: * https://sourceforge.net/p/snapraid/discussion/1677233/thread/a7c25ba9/ */ if (err == ERROR_NO_SYSTEM_RESOURCES) { - fprintf(stderr, "Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pread(), retrying...\n"); + ferr("Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pread(), retrying...\n"); Sleep(50); goto retry; } @@ -1720,7 +1720,7 @@ retry: DWORD err = GetLastError(); /* See windows_pread() for comments on this error management */ if (err == ERROR_NO_SYSTEM_RESOURCES) { - fprintf(stderr, "Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pwrite(), retrying...\n"); + ferr("Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pwrite(), retrying...\n"); Sleep(50); goto retry; } @@ -1787,7 +1787,7 @@ static int devscan(tommy_list* list) f = popen(cmd, "r"); if (!f) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run smartctl --scan-open (from popen).\n"); + ferr("Failed to run smartctl --scan-open (from popen).\n"); return -1; /* LCOV_EXCL_STOP */ } @@ -1802,13 +1802,13 @@ static int devscan(tommy_list* list) ret = pclose(f); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run smartctl --scan-open (from pclose).\n"); + ferr("Failed to run smartctl --scan-open (from pclose).\n"); return -1; /* LCOV_EXCL_STOP */ } if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run smartctl --scan-open with return code %xh.\n", ret); + ferr("Failed to run smartctl --scan-open with return code %xh.\n", ret); return -1; /* LCOV_EXCL_STOP */ } @@ -1830,7 +1830,7 @@ static int devsmart(const char* file, uint64_t* smart, char* serial) f = popen(cmd, "r"); if (!f) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run smartctl -a on device '%s' (from open).\n", file); + ferr("Failed to run smartctl -a on device '%s' (from open).\n", file); return -1; /* LCOV_EXCL_STOP */ } @@ -1845,7 +1845,7 @@ static int devsmart(const char* file, uint64_t* smart, char* serial) ret = pclose(f); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run smartctl -a on device '%s' (from pclose).\n", file); + ferr("Failed to run smartctl -a on device '%s' (from pclose).\n", file); return -1; /* LCOV_EXCL_STOP */ } @@ -1882,7 +1882,7 @@ static void* thread_spinup(void* arg) if (lstat(devinfo->mount, &st) != 0) { /* LCOV_EXCL_START */ pthread_mutex_lock(&io_lock); - fprintf(stderr, "Failed to stat devinfo '%s'. %s.\n", devinfo->mount, strerror(errno)); + ferr("Failed to stat devinfo '%s'. %s.\n", devinfo->mount, strerror(errno)); pthread_mutex_unlock(&io_lock); return (void*)-1; /* LCOV_EXCL_STOP */ @@ -1940,7 +1940,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) if (pthread_create(&devinfo->thread, 0, func, devinfo) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to create thread.\n"); + ferr("Failed to create thread.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1953,7 +1953,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) if (pthread_join(devinfo->thread, &retval) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to join thread.\n"); + ferr("Failed to join thread.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/mktest.c b/cmdline/mktest.c index 828c857e..314e5568 100644 --- a/cmdline/mktest.c +++ b/cmdline/mktest.c @@ -17,6 +17,8 @@ #include "portable.h" +#include "support.h" + /****************************************************************************/ /* random */ @@ -147,7 +149,7 @@ void cmd_generate_file(const char* path, int size) if (remove(path) != 0) { if (errno != ENOENT) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error removing file %s\n", path); + ferr("Error removing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -169,21 +171,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 */ - fprintf(stderr, "Error creating file %s\n", path); + ferr("Error creating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing file %s\n", path); + ferr("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file %s\n", path); + ferr("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -201,7 +203,7 @@ void cmd_generate_symlink(const char* path, const char* linkto) if (remove(path) != 0) { if (errno != ENOENT) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error removing file %s\n", path); + ferr("Error removing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -209,7 +211,7 @@ void cmd_generate_symlink(const char* path, const char* linkto) if (symlink(linkto, path) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing symlink %s\n", path); + ferr("Error writing symlink %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -234,7 +236,7 @@ void cmd_generate(int disk, int size) if (mkdir(path, 0777) != 0) { if (errno != EEXIST) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error creating directory %s\n", path); + ferr("Error creating directory %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -292,7 +294,7 @@ void cmd_write(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing %s\n", path); + ferr("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -319,28 +321,28 @@ void cmd_write(const char* path, int size) f = open(path, O_WRONLY | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error creating file %s\n", path); + ferr("Error creating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, off, SEEK_SET) != off) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error seeking file %s\n", path); + ferr("Error seeking file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing file %s\n", path); + ferr("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file %s\n", path); + ferr("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -368,7 +370,7 @@ void cmd_damage(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing %s\n", path); + ferr("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -396,21 +398,21 @@ void cmd_damage(const char* path, int size) f = open(path, O_RDWR | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error creating file %s\n", path); + ferr("Error creating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, off, SEEK_SET) != off) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error seeking file %s\n", path); + ferr("Error seeking file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (read(f, data, size) != size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing file %s\n", path); + ferr("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -419,28 +421,28 @@ void cmd_damage(const char* path, int size) if (lseek(f, off, SEEK_SET) != off) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error seeking file %s\n", path); + ferr("Error seeking file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing file %s\n", path); + ferr("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (fallback(f, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error setting time for file %s\n", path); + ferr("Error setting time for file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file %s\n", path); + ferr("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -460,7 +462,7 @@ void cmd_append(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing %s\n", path); + ferr("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -476,21 +478,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 */ - fprintf(stderr, "Error opening file %s\n", path); + ferr("Error opening file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing file %s\n", path); + ferr("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file %s\n", path); + ferr("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -511,7 +513,7 @@ void cmd_truncate(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing %s\n", path); + ferr("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -534,21 +536,21 @@ void cmd_truncate(const char* path, int size) f = open(path, O_WRONLY | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening file %s\n", path); + ferr("Error opening file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (ftruncate(f, off) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error truncating file %s\n", path); + ferr("Error truncating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file %s\n", path); + ferr("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -563,7 +565,7 @@ void cmd_delete(const char* path) { if (remove(path) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error removing %s\n", path); + ferr("Error removing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -582,7 +584,7 @@ void cmd_change(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing %s\n", path); + ferr("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -593,7 +595,7 @@ void cmd_change(const char* path, int size) /* delete */ if (remove(path) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error removing %s\n", path); + ferr("Error removing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -603,7 +605,7 @@ void cmd_change(const char* path, int size) if (remove(path) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error removing %s\n", path); + ferr("Error removing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/nano.c b/cmdline/nano.c index 80e795ff..cefa0a57 100644 --- a/cmdline/nano.c +++ b/cmdline/nano.c @@ -56,7 +56,7 @@ void state_nano(struct snapraid_state* state) /* get a random nanosecond value */ if (randomize(&nano, sizeof(nano)) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to get random values.\n"); + ferr("Failed to get random values.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -69,7 +69,7 @@ void state_nano(struct snapraid_state* state) f = open(path, O_RDONLY | O_BINARY | O_NOFOLLOW); if (f == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening file '%s'. %s.\n", path, strerror(errno)); + ferr("Error opening file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -80,7 +80,7 @@ void state_nano(struct snapraid_state* state) if (ret == -1) { /* LCOV_EXCL_START */ close(f); - fprintf(stderr, "Error accessing file '%s'. %s.\n", path, strerror(errno)); + ferr("Error accessing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -90,7 +90,7 @@ void state_nano(struct snapraid_state* state) if (ret != 0) { /* LCOV_EXCL_START */ close(f); - fprintf(stderr, "Error timing file '%s'. %s.\n", path, strerror(errno)); + ferr("Error timing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -102,7 +102,7 @@ void state_nano(struct snapraid_state* state) if (ret == -1) { /* LCOV_EXCL_START */ close(f); - fprintf(stderr, "Error accessing file '%s'. %s.\n", path, strerror(errno)); + ferr("Error accessing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -111,7 +111,7 @@ void state_nano(struct snapraid_state* state) ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file '%s'. %s.\n", path, strerror(errno)); + ferr("Error closing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -125,7 +125,7 @@ void state_nano(struct snapraid_state* state) /* state changed, we need to update it */ state->need_write = 1; - fprintf(stdlog, "nano:%s:%s\n", disk->name, file->sub); + ftag("nano:%s:%s\n", disk->name, file->sub); printf("nano %s%s\n", disk->dir, file->sub); } } diff --git a/cmdline/parity.c b/cmdline/parity.c index c7df2c62..838161bb 100644 --- a/cmdline/parity.c +++ b/cmdline/parity.c @@ -102,7 +102,7 @@ void parity_overflow(struct snapraid_state* state, data_off_t size) if (file->blockmax > 0) { if (file->blockvec[file->blockmax - 1].parity_pos >= blockalloc) { - fprintf(stdlog, "outofparity:%s:%s\n", disk->name, file->sub); + ftag("outofparity:%s:%s\n", disk->name, file->sub); fflush(stdlog); if (first) { first = 0; @@ -131,7 +131,7 @@ int parity_create(struct snapraid_parity_handle* parity, const char* path, data_ parity->f = open(parity->path, flags, 0600); if (parity->f == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening parity file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error opening parity file '%s'. %s.\n", parity->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -140,7 +140,7 @@ int parity_create(struct snapraid_parity_handle* parity, const char* path, data_ ret = fstat(parity->f, &parity->st); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -151,7 +151,7 @@ int parity_create(struct snapraid_parity_handle* parity, const char* path, data_ ret = posix_fadvise(parity->f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error advising parity file '%s'. %s.\n", parity->path, strerror(ret)); + ferr("Error advising parity file '%s'. %s.\n", parity->path, strerror(ret)); goto bail; /* LCOV_EXCL_STOP */ } @@ -227,7 +227,7 @@ int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_o ret = fstat(parity->f, &parity->st); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -239,9 +239,9 @@ int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_o if (f_ret != 0) { /* LCOV_EXCL_START */ if (f_errno == ENOSPC) { - fprintf(stderr, "Failed to grow parity file '%s' to size %" PRIu64 " using %s due lack of space.\n", parity->path, size, call); + ferr("Failed to grow parity file '%s' to size %" PRIu64 " using %s due lack of space.\n", parity->path, size, call); } else { - fprintf(stderr, "Error growing parity file '%s' to size %" PRIu64 " using %s. Do you have enough space? %s.\n", parity->path, size, call, strerror(f_errno)); + ferr("Error growing parity file '%s' to size %" PRIu64 " using %s. Do you have enough space? %s.\n", parity->path, size, call, strerror(f_errno)); } goto bail; /* LCOV_EXCL_STOP */ @@ -261,7 +261,7 @@ int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_o ret = fstat(parity->f, &parity->st); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -272,7 +272,7 @@ int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_o /* now check the error */ if (f_ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error truncating parity file '%s' to size %" PRIu64 ". %s.\n", parity->path, size, strerror(f_errno)); + ferr("Error truncating parity file '%s' to size %" PRIu64 ". %s.\n", parity->path, size, strerror(f_errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -305,7 +305,7 @@ int parity_open(struct snapraid_parity_handle* parity, const char* path, int mod flags |= O_SEQUENTIAL; parity->f = open_noatime(parity->path, flags); if (parity->f == -1) { - fprintf(stderr, "Error opening parity file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error opening parity file '%s'. %s.\n", parity->path, strerror(errno)); return -1; } @@ -313,7 +313,7 @@ int parity_open(struct snapraid_parity_handle* parity, const char* path, int mod ret = fstat(parity->f, &parity->st); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -327,7 +327,7 @@ int parity_open(struct snapraid_parity_handle* parity, const char* path, int mod ret = posix_fadvise(parity->f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error advising parity file '%s'. %s.\n", parity->path, strerror(ret)); + ferr("Error advising parity file '%s'. %s.\n", parity->path, strerror(ret)); goto bail; /* LCOV_EXCL_STOP */ } @@ -356,7 +356,7 @@ int parity_sync(struct snapraid_parity_handle* parity) ret = fsync(parity->f); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error synching parity file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error synching parity file '%s'. %s.\n", parity->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -379,7 +379,7 @@ int parity_close(struct snapraid_parity_handle* parity) /* This is a serious error, as it may be the result of a failed write */ /* identified at later time. */ /* In a normal filesystem (not NFS) it should never happen */ - fprintf(stderr, "Error closing parity file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error closing parity file '%s'. %s.\n", parity->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -404,9 +404,9 @@ int parity_write(struct snapraid_parity_handle* parity, block_off_t pos, unsigne if (lseek(parity->f, offset, SEEK_SET) != offset) { /* LCOV_EXCL_START */ if (errno == ENOSPC) { - fprintf(stderr, "Failed to grow parity file '%s' using lseek due lack of space.\n", parity->path); + ferr("Failed to grow parity file '%s' using lseek due lack of space.\n", parity->path); } else { - fprintf(stderr, "Error seeking file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error seeking file '%s'. %s.\n", parity->path, strerror(errno)); } return -1; /* LCOV_EXCL_STOP */ @@ -417,9 +417,9 @@ int parity_write(struct snapraid_parity_handle* parity, block_off_t pos, unsigne if (write_ret != (ssize_t)block_size) { /* conversion is safe because block_size is always small */ /* LCOV_EXCL_START */ if (errno == ENOSPC) { - fprintf(stderr, "Failed to grow parity file '%s' using write due lack of space.\n", parity->path); + ferr("Failed to grow parity file '%s' using write due lack of space.\n", parity->path); } else { - fprintf(stderr, "Error writing file '%s'. %s.\n", parity->path, strerror(errno)); + ferr("Error writing file '%s'. %s.\n", parity->path, strerror(errno)); } return -1; /* LCOV_EXCL_STOP */ @@ -436,7 +436,7 @@ int parity_write(struct snapraid_parity_handle* parity, block_off_t pos, unsigne return 0; } -int parity_read(struct snapraid_parity_handle* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size, FILE* out) +int parity_read(struct snapraid_parity_handle* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size, fptr* out) { ssize_t read_ret; data_off_t offset; @@ -446,14 +446,14 @@ int parity_read(struct snapraid_parity_handle* parity, block_off_t pos, unsigned /* check if we are going to read only not initialized data */ if (offset >= parity->valid_size) { - fprintf(out, "Reading missing data from file '%s' at offset %" PRIu64 ".\n", parity->path, offset); + out("Reading missing data from file '%s' at offset %" PRIu64 ".\n", parity->path, offset); return -1; } #if !HAVE_PREAD if (lseek(parity->f, offset, SEEK_SET) != offset) { /* LCOV_EXCL_START */ - fprintf(out, "Error seeking file '%s' at offset %" PRIu64 ". %s.\n", parity->path, offset, strerror(errno)); + out("Error seeking file '%s' at offset %" PRIu64 ". %s.\n", parity->path, offset, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -469,13 +469,13 @@ int parity_read(struct snapraid_parity_handle* parity, block_off_t pos, unsigned #endif if (read_ret < 0) { /* LCOV_EXCL_START */ - fprintf(out, "Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", parity->path, offset + count, block_size - count, strerror(errno)); + out("Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", parity->path, offset + count, block_size - count, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } if (read_ret == 0) { /* LCOV_EXCL_START */ - fprintf(out, "Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", parity->path, offset, strerror(errno)); + out("Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", parity->path, offset, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } diff --git a/cmdline/parity.h b/cmdline/parity.h index 3f7a7377..39f75b31 100644 --- a/cmdline/parity.h +++ b/cmdline/parity.h @@ -18,6 +18,8 @@ #ifndef __PARITY_H #define __PARITY_H +#include "support.h" + /****************************************************************************/ /* parity */ @@ -84,7 +86,7 @@ int parity_close(struct snapraid_parity_handle* parity); /** * Read a block from the parity file. */ -int parity_read(struct snapraid_parity_handle* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size, FILE* out); +int parity_read(struct snapraid_parity_handle* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size, fptr* out); /** * Writes a block in the parity file. diff --git a/cmdline/pool.c b/cmdline/pool.c index 48de6c4e..ae78ab5e 100644 --- a/cmdline/pool.c +++ b/cmdline/pool.c @@ -33,7 +33,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening pool directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error opening pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -49,7 +49,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading pool directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error reading pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -73,7 +73,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) if (st.st_mode == 0) { if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -82,7 +82,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) /* get lstat info about the file */ if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -95,7 +95,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) ret = remove(path_next); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error removing symlink '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error removing symlink '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -113,13 +113,13 @@ static int clean_dir(struct snapraid_state* state, 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 */ - fprintf(stderr, "Directory '%s' not removed because it's in use.\n", path_next); + ferr("Directory '%s' not removed because it's in use.\n", path_next); ignored = 1; } else #endif { /* LCOV_EXCL_START */ - fprintf(stderr, "Error removing pool directory '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error removing pool directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -138,7 +138,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) if (closedir(d) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing pool directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error closing pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -183,17 +183,17 @@ static void make_link(const char* pool_dir, const char* share_dir, struct snapra ret = symlink(linkto_exported, path); if (ret != 0) { if (errno == EEXIST) { - fprintf(stderr, "WARNING! Duplicate pooling for '%s'\n", path); + ferr("WARNING! Duplicate pooling for '%s'\n", path); #ifdef _WIN32 } else if (errno == EPERM) { /* LCOV_EXCL_START */ - fprintf(stderr, "You must run as Adminstrator to be able to create symlinks.\n"); + ferr("You must run as Adminstrator to be able to create symlinks.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ #endif } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing symlink '%s'. %s.\n", path, strerror(errno)); + ferr("Error writing symlink '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -209,7 +209,7 @@ void state_pool(struct snapraid_state* state) if (state->pool[0] == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "To use the 'pool' command you must set the pool directory in the configuration file\n"); + ferr("To use the 'pool' command you must set the pool directory in the configuration file\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -257,8 +257,8 @@ void state_pool(struct snapraid_state* state) else printf("No link created\n"); - fprintf(stdlog, "summary:link_count::%u\n", count); - fprintf(stdlog, "summary:exit:ok\n"); + ftag("summary:link_count::%u\n", count); + ftag("summary:exit:ok\n"); fflush(stdlog); } diff --git a/cmdline/rehash.c b/cmdline/rehash.c index 6151cb09..ea84ec9d 100644 --- a/cmdline/rehash.c +++ b/cmdline/rehash.c @@ -38,14 +38,14 @@ void state_rehash(struct snapraid_state* state) /* check if a rehash is already in progress */ if (state->prevhash != HASH_UNDEFINED) { /* LCOV_EXCL_START */ - fprintf(stderr, "You already have a rehash in progress.\n"); + ferr("You already have a rehash in progress.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (state->hash == state->besthash) { /* LCOV_EXCL_START */ - fprintf(stderr, "You are already using the best hash for your platform.\n"); + ferr("You are already using the best hash for your platform.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -58,7 +58,7 @@ void state_rehash(struct snapraid_state* state) state->hash = state->besthash; if (randomize(state->hashseed, HASH_SIZE) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to get random values.\n"); + ferr("Failed to get random values.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -76,7 +76,7 @@ void state_rehash(struct snapraid_state* state) if (info_get_rehash(info)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for a rehash already in progress\n"); + ferr("Internal inconsistency for a rehash already in progress\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/scan.c b/cmdline/scan.c index 61a72a65..ca1c84ce 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -94,7 +94,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(link, FILE_IS_PRESENT)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for link '%s%s'\n", disk->dir, sub); + ferr("Internal inconsistency for link '%s%s'\n", disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -108,7 +108,7 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_equal; if (state->opt.gui) { - fprintf(stdlog, "scan:equal:%s:%s\n", disk->name, link->sub); + ftag("scan:equal:%s:%s\n", disk->name, link->sub); } } else { /* it's an update */ @@ -118,7 +118,7 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_change; - fprintf(stdlog, "scan:update:%s:%s\n", disk->name, link->sub); + ftag("scan:update:%s:%s\n", disk->name, link->sub); if (is_diff) { printf("update %s%s\n", disk->dir, link->sub); } @@ -135,7 +135,7 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, /* create the new link */ ++scan->count_insert; - fprintf(stdlog, "scan:add:%s:%s\n", disk->name, sub); + ftag("scan:add:%s:%s\n", disk->name, sub); if (is_diff) { printf("add %s%s\n", disk->dir, sub); } @@ -213,7 +213,7 @@ static void scan_file_deallocate(struct snapraid_scan* scan, struct snapraid_fil break; default : /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in deallocating for block %u state %u\n", block->parity_pos, block_state); + ferr("Internal inconsistency in deallocating for block %u state %u\n", block->parity_pos, block_state); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -305,7 +305,7 @@ static void scan_file_delayed_insert(struct snapraid_scan* scan, struct snapraid if (filephy(path_next, file->size, &file->physical) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in getting the physical offset of file '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in getting the physical offset of file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -347,7 +347,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 */ - fprintf(stderr, "Error in stat file '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in stat file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -365,8 +365,8 @@ 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 */ - fprintf(stderr, "WARNING! Detected uncached time change for file '%s'\n", sub); - fprintf(stderr, "It's better if you run SnapRAID without other processes running.\n"); + ferr("WARNING! Detected uncached time change for file '%s'\n", sub); + ferr("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; @@ -374,15 +374,15 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc if (st->st_size != synced_st.st_size) { #ifndef _WIN32 - fprintf(stderr, "WARNING! Detected uncached size change for file '%s'\n", sub); - fprintf(stderr, "It's better if you run SnapRAID without other processes running.\n"); + ferr("WARNING! Detected uncached size change for file '%s'\n", sub); + ferr("It's better if you run SnapRAID without other processes running.\n"); #endif st->st_size = synced_st.st_size; } if (st->st_ino != synced_st.st_ino) { - fprintf(stderr, "DANGER! Detected uncached inode change for file '%s'\n", sub); - fprintf(stderr, "Please ensure to run SnapRAID without other processes running.\n"); + ferr("DANGER! Detected uncached inode change for file '%s'\n", sub); + ferr("Please ensure to 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 */ @@ -610,7 +610,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, #if HAVE_STRUCT_STAT_ST_NLINK if (st->st_nlink <= 1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inode '%" PRIu64 "' inconsistency for file '%s%s' already present\n", (uint64_t)st->st_ino, disk->dir, sub); + ferr("Internal inode '%" PRIu64 "' inconsistency for file '%s%s' already present\n", (uint64_t)st->st_ino, disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -638,7 +638,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* if the path is different, it means a moved file with the same inode */ ++scan->count_move; - fprintf(stdlog, "scan:move:%s:%s:%s\n", disk->name, file->sub, sub); + ftag("scan:move:%s:%s:%s\n", disk->name, file->sub, sub); if (is_diff) { printf("move %s%s -> %s%s\n", disk->dir, file->sub, disk->dir, sub); } @@ -659,7 +659,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_equal; if (state->opt.gui) { - fprintf(stdlog, "scan:equal:%s:%s\n", disk->name, file->sub); + ftag("scan:equal:%s:%s\n", disk->name, file->sub); } } @@ -678,7 +678,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 */ - fprintf(stderr, "Internal inode '%" PRIu64 "' inconsistency for files '%s%s' and '%s%s' matching and already present but different\n", file->inode, disk->dir, sub, disk->dir, file->sub); + ferr("Internal inode '%" PRIu64 "' inconsistency for files '%s%s' and '%s%s' matching and already present but different\n", file->inode, disk->dir, sub, disk->dir, file->sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -728,7 +728,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 */ - fprintf(stderr, "Internal inconsistency in inode '%" PRIu64 "' for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub); + ferr("Internal inconsistency in inode '%" PRIu64 "' for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -737,7 +737,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 */ - fprintf(stderr, "Internal inconsistency in path for file '%s%s' matching and already present\n", disk->dir, sub); + ferr("Internal inconsistency in path for file '%s%s' matching and already present\n", disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -775,7 +775,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* like when restoring a backup that restores also the timestamp */ ++scan->count_restore; - fprintf(stdlog, "scan:restore:%s:%s\n", disk->name, sub); + ftag("scan:restore:%s:%s\n", disk->name, sub); if (is_diff) { printf("restore %s%s\n", disk->dir, sub); } @@ -798,7 +798,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_equal; if (state->opt.gui) { - fprintf(stdlog, "scan:equal:%s:%s\n", disk->name, file->sub); + ftag("scan:equal:%s:%s\n", disk->name, file->sub); } } @@ -830,11 +830,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 */ - fprintf(stderr, "The file '%s%s' has unexpected zero size!\n", disk->dir, sub); - fprintf(stderr, "It's possible that after a kernel crash this file was lost,\n"); - fprintf(stderr, "and you can use 'snapraid --filter %s fix' to recover it.\n", sub); + ferr("The file '%s%s' has unexpected zero size!\n", disk->dir, sub); + ferr("It's possible that after a kernel crash this file was lost,\n"); + ferr("and you can use 'snapraid --filter %s fix' to recover it.\n", sub); if (!is_diff) { - fprintf(stderr, "If this an expected condition you can '%s' anyway using 'snapraid --force-zero %s'\n", state->command, state->command); + ferr("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 */ @@ -875,7 +875,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* revert old counter and use the copy one */ ++scan->count_copy; - fprintf(stdlog, "scan:copy:%s:%s:%s:%s\n", other_disk->name, other_file->sub, disk->name, file->sub); + ftag("scan:copy:%s:%s:%s:%s\n", other_disk->name, other_file->sub, disk->name, file->sub); if (is_diff) { printf("copy %s%s -> %s%s\n", other_disk->dir, other_file->sub, disk->dir, file->sub); } @@ -894,14 +894,14 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, if (is_file_already_present) { ++scan->count_change; - fprintf(stdlog, "scan:update:%s:%s\n", disk->name, sub); + ftag("scan:update:%s:%s\n", disk->name, sub); if (is_diff) { printf("update %s%s\n", disk->dir, sub); } } else { ++scan->count_insert; - fprintf(stdlog, "scan:add:%s:%s\n", disk->name, sub); + ftag("scan:add:%s:%s\n", disk->name, sub); if (is_diff) { printf("add %s%s\n", disk->dir, sub); } @@ -966,7 +966,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 */ - fprintf(stderr, "Internal inconsistency for dir '%s%s'\n", disk->dir, sub); + ferr("Internal inconsistency for dir '%s%s'\n", disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1044,7 +1044,7 @@ struct stat* dstat(const char* file, struct stat* st) { if (lstat(file, st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", file, strerror(errno)); + ferr("Error in stat file/directory '%s'. %s.\n", file, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1070,8 +1070,8 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening directory '%s'. %s.\n", dir, strerror(errno)); - fprintf(stderr, "You can exclude it in the config file with:\n\texclude /%s\n", sub); + ferr("Error opening directory '%s'. %s.\n", dir, strerror(errno)); + ferr("You can exclude it in the config file with:\n\texclude /%s\n", sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1090,8 +1090,8 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading directory '%s'. %s.\n", dir, strerror(errno)); - fprintf(stderr, "You can exclude it in the config file with:\n\texclude /%s\n", sub); + ferr("Error reading directory '%s'. %s.\n", dir, strerror(errno)); + ferr("You can exclude it in the config file with:\n\texclude /%s\n", sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1110,7 +1110,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co /* check for not supported file names */ if (name[0] == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Unsupported name '%s' in file '%s'.\n", name, path_next); + ferr("Unsupported name '%s' in file '%s'.\n", name, path_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1155,7 +1155,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co if (closedir(d) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error closing directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1222,7 +1222,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co if (st->st_mode == 0) { if (lstat(path_next, st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1252,7 +1252,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co if (st->st_ino == 0) { if (lstat_sync(path_next, st, 0) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in stat file '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in stat file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1274,13 +1274,13 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co ret = readlink(path_next, subnew, sizeof(subnew)); if (ret >= PATH_MAX) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in readlink file '%s'. Symlink too long.\n", path_next); + ferr("Error in readlink file '%s'. Symlink too long.\n", path_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in readlink file '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in readlink file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1306,7 +1306,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co /* 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) { - fprintf(stderr, "WARNING! Ignoring mount point '%s' because it appears to be in a different device\n", path_next); + ferr("WARNING! Ignoring mount point '%s' because it appears to be in a different device\n", path_next); } else #endif { @@ -1334,7 +1334,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co if (!st) st = DSTAT(path_next, dd, &st_buf); - fprintf(stderr, "WARNING! Ignoring special '%s' file '%s'\n", stat_desc(st), path_next); + ferr("WARNING! Ignoring special '%s' file '%s'\n", stat_desc(st), path_next); } else { if (state->opt.verbose) { printf("Excluding special file '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out))); @@ -1395,7 +1395,7 @@ void state_scan(struct snapraid_state* state, int is_diff) ret = fsinfo(disk->dir, &has_persistent_inode, 0, 0); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno)); + ferr("Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1455,7 +1455,7 @@ void state_scan(struct snapraid_state* state, int is_diff) if (!file_flag_has(file, FILE_IS_PRESENT)) { ++scan->count_remove; - fprintf(stdlog, "scan:remove:%s:%s\n", disk->name, file->sub); + ftag("scan:remove:%s:%s\n", disk->name, file->sub); if (is_diff) { printf("remove %s%s\n", disk->dir, file->sub); } @@ -1476,7 +1476,7 @@ void state_scan(struct snapraid_state* state, int is_diff) if (!link_flag_has(link, FILE_IS_PRESENT)) { ++scan->count_remove; - fprintf(stdlog, "scan:remove:%s:%s\n", disk->name, link->sub); + ftag("scan:remove:%s:%s\n", disk->name, link->sub); if (is_diff) { printf("remove %s%s\n", disk->dir, link->sub); } @@ -1537,7 +1537,7 @@ void state_scan(struct snapraid_state* state, int is_diff) /* if verbose, prints 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 (state->opt.verbose && phy_last >= FILEPHY_REAL_OFFSET) { - fprintf(stderr, "WARNING! Files '%s%s' and '%s%s' have the same physical offset %" PRId64 ".\n", disk->dir, phy_file_last->sub, disk->dir, file->sub, phy_last); + ferr("WARNING! Files '%s%s' and '%s%s' have the same physical offset %" PRId64 ".\n", disk->dir, phy_file_last->sub, disk->dir, file->sub, phy_last); } ++phy_dup; } @@ -1594,20 +1594,20 @@ void state_scan(struct snapraid_state* state, int is_diff) if (scan->count_equal == 0 && scan->count_move == 0 && scan->count_restore == 0 && (scan->count_remove != 0 || scan->count_change != 0)) { if (!done) { done = 1; - fprintf(stderr, "WARNING! All the files previously present in disk '%s' at dir '%s'", disk->name, disk->dir); + ferr("WARNING! All the files previously present in disk '%s' at dir '%s'", disk->name, disk->dir); } else { - fprintf(stderr, ", disk '%s' at dir '%s'", disk->name, disk->dir); + ferr(", disk '%s' at dir '%s'", disk->name, disk->dir); } } } if (done) { - fprintf(stderr, "\nare now missing or rewritten!\n"); - fprintf(stderr, "This could happen when deleting all the files from a disk,\n"); - fprintf(stderr, "and restoring them with a program that it's not setting\n"); - fprintf(stderr, "correctly the timestamps.\n"); - fprintf(stderr, "It's also possible that you have some disks not mounted.\n"); + ferr("\nare now missing or rewritten!\n"); + ferr("This could happen when deleting all the files from a disk,\n"); + ferr("and restoring them with a program that it's not setting\n"); + ferr("correctly the timestamps.\n"); + ferr("It's also possible that you have some disks not mounted.\n"); if (!is_diff) { - fprintf(stderr, "If you want to '%s' anyway, use 'snapraid --force-empty %s'.", state->command, state->command); + ferr("If you want to '%s' anyway, use 'snapraid --force-empty %s'.", state->command, state->command); exit(EXIT_FAILURE); } } @@ -1622,14 +1622,14 @@ void state_scan(struct snapraid_state* state, int is_diff) if (disk->has_unreliable_physical) { if (!done) { done = 1; - fprintf(stderr, "WARNING! Physical offsets not supported for disk '%s'", disk->name); + ferr("WARNING! Physical offsets not supported for disk '%s'", disk->name); } else { - fprintf(stderr, ", '%s'", disk->name); + ferr(", '%s'", disk->name); } } } if (done) { - fprintf(stderr, ". Files order won't be optimal.\n"); + ferr(". Files order won't be optimal.\n"); } } @@ -1641,14 +1641,14 @@ void state_scan(struct snapraid_state* state, int is_diff) if (disk->has_volatile_inodes) { if (!done) { done = 1; - fprintf(stderr, "WARNING! Inodes are not persistent for disks: '%s'", disk->name); + ferr("WARNING! Inodes are not persistent for disks: '%s'", disk->name); } else { - fprintf(stderr, ", '%s'", disk->name); + ferr(", '%s'", disk->name); } } } if (done) { - fprintf(stderr, ". Move operations won't be optimal.\n"); + ferr(". Move operations won't be optimal.\n"); } /* checks for disks with changed UUID */ @@ -1663,14 +1663,14 @@ void state_scan(struct snapraid_state* state, int is_diff) if (disk->has_different_uuid && !disk->had_empty_uuid) { if (!done) { done = 1; - fprintf(stderr, "WARNING! UUID is changed for disks: '%s'", disk->name); + ferr("WARNING! UUID is changed for disks: '%s'", disk->name); } else { - fprintf(stderr, ", '%s'", disk->name); + ferr(", '%s'", disk->name); } } } if (done) { - fprintf(stderr, ". Move operations won't be optimal.\n"); + ferr(". Move operations won't be optimal.\n"); } /* checks for disks with unsupported UUID */ @@ -1681,14 +1681,14 @@ void state_scan(struct snapraid_state* state, int is_diff) if (disk->has_unsupported_uuid) { if (!done) { done = 1; - fprintf(stderr, "WARNING! UUID is unsupported for disks: '%s'", disk->name); + ferr("WARNING! UUID is unsupported for disks: '%s'", disk->name); } else { - fprintf(stderr, ", '%s'", disk->name); + ferr(", '%s'", disk->name); } } } if (done) { - fprintf(stderr, ". Move operations won't be optimal.\n"); + ferr(". Move operations won't be optimal.\n"); } if (state->opt.verbose || is_diff) { @@ -1726,13 +1726,13 @@ void state_scan(struct snapraid_state* state, int is_diff) printf("%8u added\n", total.count_insert); } - fprintf(stdlog, "summary:equal:%u\n", total.count_equal); - fprintf(stdlog, "summary:moved:%u\n", total.count_move); - fprintf(stdlog, "summary:copied:%u\n", total.count_copy); - fprintf(stdlog, "summary:restored:%u\n", total.count_restore); - fprintf(stdlog, "summary:updated:%u\n", total.count_change); - fprintf(stdlog, "summary:removed:%u\n", total.count_remove); - fprintf(stdlog, "summary:added:%u\n", total.count_insert); + ftag("summary:equal:%u\n", total.count_equal); + ftag("summary:moved:%u\n", total.count_move); + ftag("summary:copied:%u\n", total.count_copy); + ftag("summary:restored:%u\n", total.count_restore); + ftag("summary:updated:%u\n", total.count_change); + ftag("summary:removed:%u\n", total.count_remove); + ftag("summary:added:%u\n", total.count_insert); no_difference = !total.count_move && !total.count_copy && !total.count_restore && !total.count_change && !total.count_remove && !total.count_insert; @@ -1746,9 +1746,9 @@ void state_scan(struct snapraid_state* state, int is_diff) } if (no_difference) { - fprintf(stdlog, "summary:exit:equal\n"); + ftag("summary:exit:equal\n"); } else { - fprintf(stdlog, "summary:exit:diff\n"); + ftag("summary:exit:diff\n"); } fflush(stdlog); } diff --git a/cmdline/scrub.c b/cmdline/scrub.c index 3b042744..f6db1fa9 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -228,17 +228,17 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ if (errno == EIO) { - fprintf(stdlog, "error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "DANGER! Unexpected input/output close error in a data disk, it isn't possible to scrub.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + ftag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("DANGER! Unexpected input/output close error in a data disk, it isn't possible to scrub.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", i); ++io_error; goto bail; } - fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "WARNING! Unexpected close error in a data disk, it isn't possible to scrub.\n"); - fprintf(stderr, "Ensure that file '%s' can be accessed.\n", handle[j].path); + ftag("error:%u:%s:%s: Close error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("WARNING! Unexpected close error in a data disk, it isn't possible to scrub.\n"); + ferr("Ensure that file '%s' can be accessed.\n", handle[j].path); printf("Stopping at block %u\n", i); ++error; goto bail; @@ -246,22 +246,22 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par } } - ret = handle_open(&handle[j], block_file_get(block), state->file_mode, stderr); + ret = handle_open(&handle[j], block_file_get(block), state->file_mode, flog); if (ret == -1) { /* file we have tried to open for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { /* LCOV_EXCL_START */ - fprintf(stdlog, "error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "DANGER! Unexpected input/output open error in a data disk, it isn't possible to scrub.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + ftag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("DANGER! Unexpected input/output open error in a data disk, it isn't possible to scrub.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", i); ++io_error; goto bail; /* LCOV_EXCL_STOP */ } - fprintf(stdlog, "error:%u:%s:%s: Open error. %s\n", i, disk->name, file->sub, strerror(errno)); + ftag("error:%u:%s:%s: Open error. %s\n", i, disk->name, file->sub, strerror(errno)); ++error; error_on_this_block = 1; continue; @@ -283,29 +283,29 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* from the last sync, as we are expected to return errors if running */ /* in an unsynced array. This is just like the check command. */ - read_size = handle_read(&handle[j], block, buffer[j], state->block_size, stderr); + read_size = handle_read(&handle[j], block, buffer[j], state->block_size, flog); if (read_size == -1) { /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { - fprintf(stdlog, "error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); + ftag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected input/output read error in a data disk, it isn't possible to scrub.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + ferr("DANGER! Unexpected input/output read error in a data disk, it isn't possible to scrub.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", i); ++io_error; goto bail; /* LCOV_EXCL_STOP */ } - fprintf(stderr, "Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + ferr("Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); ++io_error; io_error_on_this_block = 1; continue; } - fprintf(stdlog, "error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); + ftag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); ++error; error_on_this_block = 1; continue; @@ -330,14 +330,14 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par if (block_has_updated_hash(block)) { /* compare the hash */ if (memcmp(hash, block->hash, HASH_SIZE) != 0) { - fprintf(stdlog, "error:%u:%s:%s: Data error at position %u\n", i, disk->name, handle[j].file->sub, block_file_pos(block)); + ftag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, handle[j].file->sub, block_file_pos(block)); /* it's a silent error only if we are dealing with synced files */ if (file_is_unsynced) { ++error; error_on_this_block = 1; } else { - fprintf(stderr, "Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + ferr("Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); ++silent_error; silent_error_on_this_block = 1; } @@ -361,29 +361,29 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* read the parity */ for (l = 0; l < state->level; ++l) { - ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, stdlog); + ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, flog); if (ret == -1) { buffer_recov[l] = 0; if (errno == EIO) { - fprintf(stdlog, "parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno)); + ftag("parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno)); if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected input/output read error in the %s disk, it isn't possible to scrub.\n", lev_name(l)); - fprintf(stderr, "Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l)); + ferr("DANGER! Unexpected input/output read error in the %s disk, it isn't possible to scrub.\n", lev_name(l)); + ferr("Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l)); printf("Stopping at block %u\n", i); ++io_error; goto bail; /* LCOV_EXCL_STOP */ } - fprintf(stderr, "Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); + ferr("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); ++io_error; io_error_on_this_block = 1; continue; } - fprintf(stdlog, "parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno)); + ftag("parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno)); ++error; error_on_this_block = 1; continue; @@ -399,14 +399,14 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* compare the parity */ for (l = 0; l < state->level; ++l) { if (buffer_recov[l] && memcmp(buffer[diskmax + l], buffer_recov[l], state->block_size) != 0) { - fprintf(stdlog, "parity_error:%u:%s: Data error\n", i, lev_config_name(l)); + ftag("parity_error:%u:%s: Data error\n", i, lev_config_name(l)); /* it's a silent error only if we are dealing with synced blocks */ if (block_is_unsynced) { ++error; error_on_this_block = 1; } else { - fprintf(stderr, "Data error in parity '%s' at position '%u'\n", lev_config_name(l), i); + ferr("Data error in parity '%s' at position '%u'\n", lev_config_name(l), i); ++silent_error; silent_error_on_this_block = 1; } @@ -475,12 +475,12 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par state_usage_print(state); if (io_error) - fprintf(stderr, "WARNING! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); + ferr("WARNING! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); if (silent_error) - fprintf(stderr, "WARNING! Unexpected data errors! The failing blocks are now marked as bad!\n"); + ferr("WARNING! Unexpected data errors! The failing blocks are now marked as bad!\n"); if (io_error || silent_error) { - fprintf(stderr, "Use 'snapraid status' to list the bad blocks.\n"); - fprintf(stderr, "Use 'snapraid -e fix' to recover.\n"); + ferr("Use 'snapraid status' to list the bad blocks.\n"); + ferr("Use 'snapraid -e fix' to recover.\n"); } if (error || silent_error || io_error) { @@ -495,13 +495,13 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par printf("Everything OK\n"); } - fprintf(stdlog, "summary:error_file:%u\n", error); - fprintf(stdlog, "summary:error_io:%u\n", io_error); - fprintf(stdlog, "summary:error_data:%u\n", silent_error); + ftag("summary:error_file:%u\n", error); + ftag("summary:error_io:%u\n", io_error); + ftag("summary:error_data:%u\n", silent_error); if (error + silent_error + io_error == 0) - fprintf(stdlog, "summary:exit:ok\n"); + ftag("summary:exit:ok\n"); else - fprintf(stdlog, "summary:exit:error\n"); + ftag("summary:exit:error\n"); fflush(stdlog); bail: @@ -509,7 +509,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected close error in a data disk.\n"); + ferr("DANGER! Unexpected close error in a data disk.\n"); ++error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -598,7 +598,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) /* copy the info in the temp vector */ count = 0; - fprintf(stdlog, "block_count:%u\n", blockmax); + ftag("block_count:%u\n", blockmax); for (i = 0; i < blockmax; ++i) { snapraid_info info = info_get(&state->infoarr, i); @@ -611,7 +611,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) if (!count) { /* LCOV_EXCL_START */ - fprintf(stderr, "The array appears to be empty.\n"); + ferr("The array appears to be empty.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -621,12 +621,12 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) /* output the info map */ i = 0; - fprintf(stdlog, "info_count:%u\n", count); + ftag("info_count:%u\n", count); while (i < count) { unsigned j = i + 1; while (j < count && info_get_time(infomap[i]) == info_get_time(infomap[j])) ++j; - fprintf(stdlog, "info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); + ftag("info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); i = j; } @@ -654,9 +654,9 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) lastlimit = 0; } - fprintf(stdlog, "count_limit:%u\n", countlimit); - fprintf(stdlog, "time_limit:%" PRIu64 "\n", (uint64_t)timelimit); - fprintf(stdlog, "last_limit:%u\n", lastlimit); + ftag("count_limit:%u\n", countlimit); + ftag("time_limit:%" PRIu64 "\n", (uint64_t)timelimit); + ftag("last_limit:%u\n", lastlimit); /* free the temp vector */ free(infomap); @@ -667,7 +667,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) ret = parity_open(parity_ptr[l], state->parity[l].path, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "WARNING! Without an accessible %s file, it isn't possible to scrub.\n", lev_name(l)); + ferr("WARNING! Without an accessible %s file, it isn't possible to scrub.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -687,7 +687,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) ret = parity_close(parity_ptr[l]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected close error in %s disk.\n", lev_name(l)); + ferr("DANGER! Unexpected close error in %s disk.\n", lev_name(l)); ++error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ diff --git a/cmdline/search.c b/cmdline/search.c index 1dbba244..164b8e3c 100644 --- a/cmdline/search.c +++ b/cmdline/search.c @@ -79,14 +79,14 @@ int search_file_compare(const void* void_arg, const void* void_data) f = open(path, O_RDONLY | O_BINARY); if (f == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening file '%s'. %s.\n", path, strerror(errno)); + ferr("Error opening file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, arg->offset, SEEK_SET) != arg->offset) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error seeking file '%s'. %s.\n", path, strerror(errno)); + ferr("Error seeking file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -94,7 +94,7 @@ int search_file_compare(const void* void_arg, const void* void_data) ret = read(f, arg->buffer, arg->read_size); if (ret < 0 || (unsigned)ret != arg->read_size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading file '%s'. %s.\n", path, strerror(errno)); + ferr("Error reading file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -102,7 +102,7 @@ int search_file_compare(const void* void_arg, const void* void_data) ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing file '%s'. %s.\n", path, strerror(errno)); + ferr("Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -157,7 +157,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error opening directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -176,7 +176,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error reading directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -220,7 +220,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 */ - fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -229,7 +229,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 */ - fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + ferr("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -258,7 +258,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, if (closedir(d) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing directory '%s'. %s.\n", dir, strerror(errno)); + ferr("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 04d8bc69..81b3b8d6 100644 --- a/cmdline/selftest.c +++ b/cmdline/selftest.c @@ -26,6 +26,7 @@ #include "raid/test.h" #include "elem.h" #include "state.h" +#include "support.h" #include "tommyds/tommyhash.h" #include "tommyds/tommyarray.h" #include "tommyds/tommyarrayblk.h" @@ -159,7 +160,7 @@ static void test_hash(void) digest = tommy_hash_u32(seed32, buffer_aligned, TEST_MURMUR3[i].len); if (digest != TEST_HASH32[i].digest) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed hash32 test\n"); + ferr("Failed hash32 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -171,7 +172,7 @@ static void test_hash(void) digest = tommy_hash_u64(seed64, buffer_aligned, TEST_MURMUR3[i].len); if (digest != TEST_HASH64[i].digest) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed hash64 test\n"); + ferr("Failed hash64 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -184,7 +185,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_SIZE) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed Murmur3 test\n"); + ferr("Failed Murmur3 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -196,7 +197,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_SIZE) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed Spooky2 test\n"); + ferr("Failed Spooky2 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -245,7 +246,7 @@ static void test_crc32c(void) digest = crc32c(0, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len); if (digest != TEST_CRC32C[i].digest) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed CRC32C test\n"); + ferr("Failed CRC32C test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -372,14 +373,14 @@ static void test_tommy(void) return; bail: /* LCOV_EXCL_START */ - fprintf(stderr, "Failed tommy test\n"); + ferr("Failed tommy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } void selftest(void) { - fprintf(stdlog, "selftest:\n"); + ftag("selftest:\n"); fflush(stdlog); printf("Self test...\n"); @@ -387,7 +388,7 @@ void selftest(void) /* large file check */ if (sizeof(off_t) < sizeof(uint64_t)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Missing support for large files\n"); + ferr("Missing support for large files\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -397,55 +398,55 @@ void selftest(void) test_tommy(); if (raid_selftest() != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed SELF test\n"); + ferr("Failed SELF test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_sort() != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed SORT test\n"); + ferr("Failed SORT test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_insert() != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed INSERT test\n"); + ferr("Failed INSERT test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_combo() != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed COMBO test\n"); + ferr("Failed COMBO test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_VANDERMONDE, 32, 256) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed GEN Vandermonde test\n"); + ferr("Failed GEN Vandermonde test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_rec(RAID_MODE_VANDERMONDE, 12, 256) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed REC Vandermonde test\n"); + ferr("Failed REC Vandermonde test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_CAUCHY, 32, 256) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed GEN Cauchy test\n"); + ferr("Failed GEN Cauchy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_rec(RAID_MODE_CAUCHY, 12, 256) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed REC Cauchy test\n"); + ferr("Failed REC Cauchy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_CAUCHY, 1, 256) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed GEN Cauchy test sigle data disk\n"); + ferr("Failed GEN Cauchy test sigle data disk\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index fd3e90ee..49452865 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -76,7 +76,7 @@ void usage(void) void memory(void) { - fprintf(stdlog, "memory:used:%" PRIu64 "\n", (uint64_t)malloc_counter()); + ftag("memory:used:%" PRIu64 "\n", (uint64_t)malloc_counter()); printf("Using %u MiB of memory.\n", (unsigned)(malloc_counter() / 1024 / 1024)); } @@ -151,7 +151,7 @@ void log_open(const char* log) break; default : /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid type specifier '%c' in the log file.\n", *log); + ferr("Invalid type specifier '%c' in the log file.\n", *log); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -166,7 +166,7 @@ void log_open(const char* log) stdlog = fopen(path, mode); if (!stdlog) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening the log file '%s'. %s.\n", path, strerror(errno)); + ferr("Error opening the log file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -177,7 +177,7 @@ void log_close(const char* log) if (stdlog != stdout && stdlog != stderr) { if (fclose(stdlog) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing the log file '%s'. %s.\n", log, strerror(errno)); + ferr("Error closing the log file '%s'. %s.\n", log, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -454,7 +454,7 @@ int main(int argc, char* argv[]) struct snapraid_filter* filter = filter_alloc_file(1, optarg); if (!filter) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid filter specification '%s'\n", optarg); + ferr("Invalid filter specification '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -464,7 +464,7 @@ int main(int argc, char* argv[]) struct snapraid_filter* filter = filter_alloc_disk(1, optarg); if (!filter) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid filter specification '%s'\n", optarg); + ferr("Invalid filter specification '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -484,7 +484,7 @@ int main(int argc, char* argv[]) percentage = strtoul(optarg, &e, 10); if (!e || *e || percentage > 100) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid percentage '%s'\n", optarg); + ferr("Invalid percentage '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -493,7 +493,7 @@ int main(int argc, char* argv[]) olderthan = strtoul(optarg, &e, 10); if (!e || *e || olderthan > 1000) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid number of days '%s'\n", optarg); + ferr("Invalid number of days '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -502,7 +502,7 @@ int main(int argc, char* argv[]) blockstart = strtoul(optarg, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid start position '%s'\n", optarg); + ferr("Invalid start position '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -511,7 +511,7 @@ int main(int argc, char* argv[]) blockcount = strtoul(optarg, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid count number '%s'\n", optarg); + ferr("Invalid count number '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -520,7 +520,7 @@ int main(int argc, char* argv[]) opt.io_error_limit = strtoul(optarg, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid error limit number '%s'\n", optarg); + ferr("Invalid error limit number '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -528,7 +528,7 @@ int main(int argc, char* argv[]) case 'i' : if (import_timestamp) { /* LCOV_EXCL_START */ - fprintf(stderr, "Import directory '%s' already specified as '%s'\n", optarg, import_timestamp); + ferr("Import directory '%s' already specified as '%s'\n", optarg, import_timestamp); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -537,7 +537,7 @@ int main(int argc, char* argv[]) case OPT_TEST_IMPORT_CONTENT : if (import_content) { /* LCOV_EXCL_START */ - fprintf(stderr, "Import directory '%s' already specified as '%s'\n", optarg, import_content); + ferr("Import directory '%s' already specified as '%s'\n", optarg, import_content); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -546,7 +546,7 @@ int main(int argc, char* argv[]) case 'l' : if (log) { /* LCOV_EXCL_START */ - fprintf(stderr, "Log file '%s' already specified as '%s'\n", optarg, log); + ferr("Log file '%s' already specified as '%s'\n", optarg, log); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -683,7 +683,7 @@ int main(int argc, char* argv[]) break; default : /* LCOV_EXCL_START */ - fprintf(stderr, "Unknown option '%c'\n", (char)c); + ferr("Unknown option '%c'\n", (char)c); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -749,7 +749,7 @@ int main(int argc, char* argv[]) operation = OPERATION_SMART; } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Unknown command '%s'\n", argv[optind]); + ferr("Unknown command '%s'\n", argv[optind]); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -761,7 +761,7 @@ int main(int argc, char* argv[]) default : if (opt.auditonly) { /* LCOV_EXCL_START */ - fprintf(stderr, "You cannot use -a, --audit-only with the '%s' command\n", command); + ferr("You cannot use -a, --audit-only with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -775,7 +775,7 @@ int main(int argc, char* argv[]) default : if (opt.force_nocopy) { /* LCOV_EXCL_START */ - fprintf(stderr, "You cannot use -N, --force-nocopy with the '%s' command\n", command); + ferr("You cannot use -N, --force-nocopy with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -787,14 +787,14 @@ int main(int argc, char* argv[]) default : if (opt.prehash) { /* LCOV_EXCL_START */ - fprintf(stderr, "You cannot use -h, --pre-hash with the '%s' command\n", command); + ferr("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 */ - fprintf(stderr, "You cannot use -F, --force-full with the '%s' command\n", command); + ferr("You cannot use -F, --force-full with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -802,14 +802,14 @@ int main(int argc, char* argv[]) if (opt.force_full && opt.force_nocopy) { /* LCOV_EXCL_START */ - fprintf(stderr, "You cannot use the -F, --force-full and -N, --force-nocopy options at the same time\n"); + ferr("You cannot use the -F, --force-full and -N, --force-nocopy options at the same time\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (opt.prehash && opt.force_nocopy) { /* LCOV_EXCL_START */ - fprintf(stderr, "You cannot use the -h, --pre-hash and -N, --force-nocopy options at the same time\n"); + ferr("You cannot use the -h, --pre-hash and -N, --force-nocopy options at the same time\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -822,25 +822,25 @@ int main(int argc, char* argv[]) default : if (!tommy_list_empty(&filterlist_file)) { /* LCOV_EXCL_START */ - fprintf(stderr, "You cannot use -f, --filter with the '%s' command\n", command); + ferr("You cannot use -f, --filter with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!tommy_list_empty(&filterlist_disk)) { /* LCOV_EXCL_START */ - fprintf(stderr, "You cannot use -d, --filter-disk with the '%s' command\n", command); + ferr("You cannot use -d, --filter-disk with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (filter_missing != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "You cannot use -m, --filter-missing with the '%s' command\n", command); + ferr("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 */ - fprintf(stderr, "You cannot use -e, --filter-error with the '%s' command\n", command); + ferr("You cannot use -e, --filter-error with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -853,7 +853,7 @@ int main(int argc, char* argv[]) default : if (import_timestamp != 0 || import_content != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "You cannot import with the '%s' command\n", command); + ferr("You cannot import with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -914,16 +914,16 @@ int main(int argc, char* argv[]) /* print generic info into the log */ t = time(0); tm = localtime(&t); - fprintf(stdlog, "version:%s\n", PACKAGE_VERSION); - fprintf(stdlog, "unixtime:%" PRIi64 "\n", (int64_t)t); + ftag("version:%s\n", PACKAGE_VERSION); + ftag("unixtime:%" PRIi64 "\n", (int64_t)t); if (tm) { char datetime[64]; strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tm); - fprintf(stdlog, "time:%s\n", datetime); + ftag("time:%s\n", datetime); } - fprintf(stdlog, "command:%s\n", command); + ftag("command:%s\n", command); for (i = 0; i < argc; ++i) - fprintf(stdlog, "argv:%u:%s\n", i, argv[i]); + ftag("argv:%u:%s\n", i, argv[i]); fflush(stdlog); if (!opt.skip_self) @@ -944,10 +944,10 @@ int main(int argc, char* argv[]) if (lock == -1) { /* LCOV_EXCL_START */ if (errno != EWOULDBLOCK) { - fprintf(stderr, "Error creating the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); + ferr("Error creating the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); } else { - fprintf(stderr, "The lock file '%s' is already locked!\n", state.lockfile); - fprintf(stderr, "SnapRAID is already in use!\n"); + ferr("The lock file '%s' is already locked!\n", state.lockfile); + ferr("SnapRAID is already in use!\n"); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1005,7 +1005,7 @@ int main(int argc, char* argv[]) ret = system(run); /* ignore error */ if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in running command '%s'.\n", run); + ferr("Error in running command '%s'.\n", run); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1161,7 +1161,7 @@ int main(int argc, char* argv[]) if (!opt.skip_lock) { if (lock_unlock(lock) == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); + ferr("Error closing 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 c8389efb..1e1d2df6 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -139,7 +139,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 */ - fprintf(stderr, "If you use the z-parity you cannot have more than 3 parities.\n"); + ferr("If you use the z-parity you cannot have more than 3 parities.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STIO */ } @@ -148,7 +148,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].path[0] == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "No '%s' specification in '%s'\n", lev_config_name(l), path); + ferr("No '%s' specification in '%s'\n", lev_config_name(l), path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -156,7 +156,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (tommy_list_empty(&state->contentlist)) { /* LCOV_EXCL_START */ - fprintf(stderr, "No 'content' specification in '%s'\n", path); + ferr("No 'content' specification in '%s'\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -168,7 +168,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (pathcmp(state->parity[l].path, content->content) == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Same path used for '%s' and 'content' as '%s'\n", lev_config_name(l), content->content); + ferr("Same path used for '%s' and 'content' as '%s'\n", lev_config_name(l), content->content); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -184,10 +184,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t #ifdef _WIN32 if (disk->device == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Disk '%s' has a zero serial number.\n", disk->dir); - fprintf(stderr, "This is not necessarely wrong, but for using SnapRAID\n"); - fprintf(stderr, "it's better to change the serial number of the disk.\n"); - fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); + ferr("Disk '%s' has a zero serial number.\n", disk->dir); + ferr("This is not necessarely wrong, but for using SnapRAID\n"); + ferr("it's better to change the serial number of the disk.\n"); + ferr("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -198,15 +198,15 @@ static void state_config_check(struct snapraid_state* state, const char* path, t struct snapraid_disk* other = j->data; if (disk->device == other->device) { /* LCOV_EXCL_START */ - fprintf(stderr, "Disks '%s' and '%s' are on the same device.\n", disk->dir, other->dir); + ferr("Disks '%s' and '%s' are on the same device.\n", disk->dir, other->dir); #ifdef _WIN32 - fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", disk->device); - fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - fprintf(stderr, "to change one of the disk serial.\n"); + ferr("Both have the serial number '%" PRIx64 "'.\n", disk->device); + ferr("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + ferr("to change one of the disk serial.\n"); #endif /* in "fix" we allow to continue anyway */ if (strcmp(state->command, "fix") == 0) { - fprintf(stderr, "You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); + ferr("You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -218,11 +218,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (disk->device == state->parity[l].device) { /* LCOV_EXCL_START */ - fprintf(stderr, "Disk '%s' and %s '%s' are on the same device.\n", disk->dir, lev_name(l), state->parity[l].path); + ferr("Disk '%s' and %s '%s' are on the same device.\n", disk->dir, lev_name(l), state->parity[l].path); #ifdef _WIN32 - fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", disk->device); - fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - fprintf(stderr, "to change one of the disk serial.\n"); + ferr("Both have the serial number '%" PRIx64 "'.\n", disk->device); + ferr("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + ferr("to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -232,11 +232,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 */ - fprintf(stderr, "Disk '%s' and pool '%s' are on the same device.\n", disk->dir, state->pool); + ferr("Disk '%s' and pool '%s' are on the same device.\n", disk->dir, state->pool); #ifdef _WIN32 - fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", disk->device); - fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - fprintf(stderr, "to change one of the disk serial.\n"); + ferr("Both have the serial number '%" PRIx64 "'.\n", disk->device); + ferr("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + ferr("to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -250,10 +250,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (state->parity[l].device == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Disk '%s' has a zero serial number.\n", state->parity[l].path); - fprintf(stderr, "This is not necessarely wrong, but for using SnapRAID\n"); - fprintf(stderr, "it's better to change the serial number of the disk.\n"); - fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); + ferr("Disk '%s' has a zero serial number.\n", state->parity[l].path); + ferr("This is not necessarely wrong, but for using SnapRAID\n"); + ferr("it's better to change the serial number of the disk.\n"); + ferr("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -265,11 +265,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (j = l + 1; j < state->level; ++j) { if (state->parity[l].device == state->parity[j].device) { /* LCOV_EXCL_START */ - fprintf(stderr, "Parity '%s' and '%s' are on the same device.\n", state->parity[l].path, state->parity[j].path); + ferr("Parity '%s' and '%s' are on the same device.\n", state->parity[l].path, state->parity[j].path); #ifdef _WIN32 - fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", state->parity[l].device); - fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - fprintf(stderr, "to change one of the disk serial.\n"); + ferr("Both have the serial number '%" PRIx64 "'.\n", state->parity[l].device); + ferr("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + ferr("to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -280,11 +280,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (state->pool[0] != 0 && state->pool_device == state->parity[l].device) { /* LCOV_EXCL_START */ - fprintf(stderr, "Pool '%s' and parity '%s' are on the same device.\n", state->pool, state->parity[l].path); + ferr("Pool '%s' and parity '%s' are on the same device.\n", state->pool, state->parity[l].path); #ifdef _WIN32 - fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", state->pool_device); - fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - fprintf(stderr, "to change one of the disk serial.\n"); + ferr("Both have the serial number '%" PRIx64 "'.\n", state->pool_device); + ferr("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + ferr("to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -297,10 +297,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 */ - fprintf(stderr, "Disk '%s' has a zero serial number.\n", state->pool); - fprintf(stderr, "This is not necessarely wrong, but for using SnapRAID\n"); - fprintf(stderr, "it's better to change the serial number of the disk.\n"); - fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); + ferr("Disk '%s' has a zero serial number.\n", state->pool); + ferr("This is not necessarely wrong, but for using SnapRAID\n"); + ferr("it's better to change the serial number of the disk.\n"); + ferr("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -333,7 +333,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (content_count < state->level + 1) { /* LCOV_EXCL_START */ - fprintf(stderr, "You must have at least %d 'content' files in different disks.\n", state->level + 1); + ferr("You must have at least %d 'content' files in different disks.\n", state->level + 1); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -345,11 +345,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t #endif if (state->raid_mode == RAID_MODE_CAUCHY) { if (state->level == 3) { - fprintf(stderr, "WARNING! Your CPU doesn't have a fast implementation for triple parity.\n"); - fprintf(stderr, "WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'.\n"); + ferr("WARNING! Your CPU doesn't have a fast implementation for triple parity.\n"); + ferr("WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'.\n"); } else if (state->level > 3) { - fprintf(stderr, "WARNING! Your CPU doesn't have a fast implementation beyond triple parity.\n"); - fprintf(stderr, "WARNING! It's recommended to reduce the parity levels to triple parity.\n"); + ferr("WARNING! Your CPU doesn't have a fast implementation beyond triple parity.\n"); + ferr("WARNING! It's recommended to reduce the parity levels to triple parity.\n"); } } @@ -364,7 +364,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } if (j == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Option -d, --filter-disk %s doesn't match any disk.\n", filter->pattern); + ferr("Option -d, --filter-disk %s doesn't match any disk.\n", filter->pattern); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -392,17 +392,17 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* store current command */ state->command = command; - fprintf(stdlog, "conf:%s\n", path); + ftag("conf:%s\n", path); f = sopen_read(path); if (!f) { /* LCOV_EXCL_START */ if (errno == ENOENT) { - fprintf(stderr, "No configuration file found at '%s'\n", path); + ferr("No configuration file found at '%s'\n", path); } else if (errno == EACCES) { - fprintf(stderr, "You do not have rights to access the configuration file '%s'\n", path); + ferr("You do not have rights to access the configuration file '%s'\n", path); } else { - fprintf(stderr, "Error opening the configuration file '%s'. %s.\n", path, strerror(errno)); + ferr("Error opening the configuration file '%s'. %s.\n", path, strerror(errno)); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -422,7 +422,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 */ - fprintf(stderr, "Error reading the configuration file '%s' at line %u\n", path, line); + ferr("Error reading the configuration file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -437,26 +437,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 */ - fprintf(stderr, "Invalid 'blocksize' specification in '%s' at line %u\n", path, line); + ferr("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 */ - fprintf(stderr, "Too small 'blocksize' specification in '%s' at line %u\n", path, line); + ferr("Too small 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (state->block_size > 16 * 1024) { /* LCOV_EXCL_START */ - fprintf(stderr, "Too big 'blocksize' specification in '%s' at line %u\n", path, line); + ferr("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 */ - fprintf(stderr, "Not power of 2 'blocksize' specification in '%s' at line %u\n", path, line); + ferr("Not power of 2 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -492,14 +492,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co break; default : /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (*state->parity[level].path) { /* LCOV_EXCL_START */ - fprintf(stderr, "Multiple '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Multiple '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -507,14 +507,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 */ - fprintf(stderr, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - fprintf(stderr, "Empty '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Empty '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -533,7 +533,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co pathcpy(device, sizeof(device), "."); if (stat(device, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing 'parity' dir '%s' specification in '%s' at line %u\n", device, path, line); + ferr("Error accessing 'parity' dir '%s' specification in '%s' at line %u\n", device, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -550,7 +550,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 */ - fprintf(stderr, "Multiple 'share' specification in '%s' at line %u\n", path, line); + ferr("Multiple 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -558,14 +558,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 */ - fprintf(stderr, "Invalid 'share' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - fprintf(stderr, "Empty 'share' specification in '%s' at line %u\n", path, line); + ferr("Empty 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -576,7 +576,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (*state->pool) { /* LCOV_EXCL_START */ - fprintf(stderr, "Multiple 'pool' specification in '%s' at line %u\n", path, line); + ferr("Multiple 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -584,14 +584,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 */ - fprintf(stderr, "Invalid 'pool' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - fprintf(stderr, "Empty 'pool' specification in '%s' at line %u\n", path, line); + ferr("Empty 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -601,7 +601,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 */ - fprintf(stderr, "Error accessing 'pool' dir '%s' specification in '%s' at line %u\n", buffer, path, line); + ferr("Error accessing 'pool' dir '%s' specification in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -616,21 +616,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 */ - fprintf(stderr, "Invalid 'content' specification in '%s' at line %u\n", path, line); + ferr("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 */ - fprintf(stderr, "You cannot use the null device as 'content' specification in '%s' at line %u\n", path, line); + ferr("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 */ - fprintf(stderr, "Empty 'content' specification in '%s' at line %u\n", path, line); + ferr("Empty 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -643,7 +643,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (i) { /* LCOV_EXCL_START */ - fprintf(stderr, "Duplicate 'content' specification in '%s' at line %u\n", path, line); + ferr("Duplicate 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -657,7 +657,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co pathcpy(device, sizeof(device), "."); if (stat(device, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing 'content' dir '%s' specification in '%s' at line %u\n", device, path, line); + ferr("Error accessing 'content' dir '%s' specification in '%s' at line %u\n", device, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -680,14 +680,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 */ - fprintf(stderr, "Invalid 'disk' name specification in '%s' at line %u\n", path, line); + ferr("Invalid 'disk' name specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - fprintf(stderr, "Empty 'disk' name specification in '%s' at line %u\n", path, line); + ferr("Empty 'disk' name specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -697,14 +697,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 */ - fprintf(stderr, "Invalid 'disk' dir specification in '%s' at line %u\n", path, line); + ferr("Invalid 'disk' dir specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*dir) { /* LCOV_EXCL_START */ - fprintf(stderr, "Empty 'disk' dir specification in '%s' at line %u\n", path, line); + ferr("Empty 'disk' dir specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -720,7 +720,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (i) { /* LCOV_EXCL_START */ - fprintf(stderr, "Duplicate disk name '%s' at line %u\n", buffer, line); + ferr("Duplicate disk name '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -730,7 +730,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (stat(device, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing 'disk' '%s' specification in '%s' at line %u\n", dir, device, line); + ferr("Error accessing 'disk' '%s' specification in '%s' at line %u\n", dir, device, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -752,14 +752,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 */ - fprintf(stderr, "Invalid 'exclude' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'exclude' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - fprintf(stderr, "Empty 'exclude' specification in '%s' at line %u\n", path, line); + ferr("Empty 'exclude' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -767,7 +767,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 */ - fprintf(stderr, "Invalid 'exclude' specification '%s' in '%s' at line %u\n", buffer, path, line); + ferr("Invalid 'exclude' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -778,14 +778,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 */ - fprintf(stderr, "Invalid 'include' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'include' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - fprintf(stderr, "Empty 'include' specification in '%s' at line %u\n", path, line); + ferr("Empty 'include' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -793,7 +793,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 */ - fprintf(stderr, "Invalid 'include' specification '%s' in '%s' at line %u\n", buffer, path, line); + ferr("Invalid 'include' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -804,14 +804,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 */ - fprintf(stderr, "Invalid 'autosave' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - fprintf(stderr, "Empty 'autosave' specification in '%s' at line %u\n", path, line); + ferr("Empty 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -820,7 +820,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (!e || *e) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'autosave' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -833,13 +833,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 */ - fprintf(stderr, "Invalid comment in '%s' at line %u\n", path, line); + ferr("Invalid comment in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid command '%s' in '%s' at line %u\n", tag, path, line); + ferr("Invalid command '%s' in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -854,7 +854,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (c != '\n') { /* LCOV_EXCL_START */ - fprintf(stderr, "Extra data in '%s' at line %u\n", path, line); + ferr("Extra data in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -863,7 +863,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading the configuration file '%s' at line %u\n", path, line); + ferr("Error reading the configuration file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -897,7 +897,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_SIZE) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to get random values.\n"); + ferr("Failed to get random values.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -907,28 +907,28 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* intentionally not set the prevhashseed, if used valgrind will warn about it */ - fprintf(stdlog, "blocksize:%u\n", state->block_size); + ftag("blocksize:%u\n", state->block_size); for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; - fprintf(stdlog, "disk:%s:%s\n", disk->name, disk->dir); + ftag("disk:%s:%s\n", disk->name, disk->dir); } - fprintf(stdlog, "mode:%s\n", lev_raid_name(state->raid_mode, state->level)); + ftag("mode:%s\n", lev_raid_name(state->raid_mode, state->level)); for (l = 0; l < state->level; ++l) - fprintf(stdlog, "%s:%s\n", lev_config_name(l), state->parity[l].path); + ftag("%s:%s\n", lev_config_name(l), state->parity[l].path); if (state->pool[0] != 0) - fprintf(stdlog, "pool:%s\n", state->pool); + ftag("pool:%s\n", state->pool); if (state->share[0] != 0) - fprintf(stdlog, "share:%s\n", state->share); + ftag("share:%s\n", state->share); if (state->autosave != 0) - fprintf(stdlog, "autosave:%" PRIu64 "\n", state->autosave); + ftag("autosave:%" PRIu64 "\n", state->autosave); for (i = tommy_list_head(&state->filterlist); i != 0; i = i->next) { char out[PATH_MAX]; struct snapraid_filter* filter = i->data; - fprintf(stdlog, "filter:%s\n", filter_type(filter, out, sizeof(out))); + ftag("filter:%s\n", filter_type(filter, out, sizeof(out))); } if (state->filter_hidden) - fprintf(stdlog, "filter:nohidden:\n"); + ftag("filter:nohidden:\n"); fflush(stdlog); } @@ -1056,7 +1056,7 @@ static void state_map(struct snapraid_state* state) disk = find_disk(state, map->name); if (disk == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for mapping '%s'\n", map->name); + ferr("Internal inconsistency for mapping '%s'\n", map->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1077,7 +1077,7 @@ static void state_map(struct snapraid_state* state) if (map->uuid[0] != 0) { /* count the number of uuid change */ ++uuid_mismatch; - fprintf(stderr, "UUID change for disk '%s' from '%s' to '%s'\n", disk->name, map->uuid, uuid); + ferr("UUID change for disk '%s' from '%s' to '%s'\n", disk->name, map->uuid, uuid); } else { /* no message here, because having a disk without */ /* UUID is the normal state of an empty disk */ @@ -1111,7 +1111,7 @@ static void state_map(struct snapraid_state* state) if (state->parity[l].uuid[0] != 0) { /* count the number of uuid change */ ++uuid_mismatch; - fprintf(stderr, "UUID change for parity '%s' from '%s' to '%s'\n", lev_config_name(l), state->parity[l].uuid, uuid); + ferr("UUID change for parity '%s' from '%s' to '%s'\n", lev_config_name(l), state->parity[l].uuid, uuid); } /* update the uuid */ @@ -1125,11 +1125,11 @@ static void state_map(struct snapraid_state* state) if (!state->opt.force_uuid && uuid_mismatch > state->level) { /* LCOV_EXCL_START */ - fprintf(stderr, "Too many disks have UUID changed from the latest 'sync'.\n"); - fprintf(stderr, "If this happens because you really replaced them,\n"); - fprintf(stderr, "you can '%s' anyway, using 'snapraid --force-uuid %s'.\n", state->command, state->command); - fprintf(stderr, "Instead, it's possible that you messed up the disk mount points,\n"); - fprintf(stderr, "and you have to restore the mount points at the state of the latest sync.\n"); + ferr("Too many disks have UUID changed from the latest 'sync'.\n"); + ferr("If this happens because you really replaced them,\n"); + ferr("you can '%s' anyway, using 'snapraid --force-uuid %s'.\n", state->command, state->command); + ferr("Instead, it's possible that you messed up the disk mount points,\n"); + ferr("and you have to restore the mount points at the state of the latest sync.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1146,7 +1146,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 */ - fprintf(stderr, "Too many data disks. No more than %u.\n", RAID_DATA_MAX); + ferr("Too many data disks. No more than %u.\n", RAID_DATA_MAX); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1156,15 +1156,15 @@ static void state_map(struct snapraid_state* state) /* recommend number of parities */ if (diskcount >= 36 && state->level < 6) { - fprintf(stderr, "WARNING! With %u disks it's recommended to use six parity levels.\n", diskcount); + ferr("WARNING! With %u disks it's recommended to use six parity levels.\n", diskcount); } else if (diskcount >= 29 && state->level < 5) { - fprintf(stderr, "WARNING! With %u disks it's recommended to use five parity levels.\n", diskcount); + ferr("WARNING! With %u disks it's recommended to use five parity levels.\n", diskcount); } else if (diskcount >= 22 && state->level < 4) { - fprintf(stderr, "WARNING! With %u disks it's recommended to use four parity levels.\n", diskcount); + ferr("WARNING! With %u disks it's recommended to use four parity levels.\n", diskcount); } else if (diskcount >= 15 && state->level < 3) { - fprintf(stderr, "WARNING! With %u disks it's recommended to use three parity levels.\n", diskcount); + ferr("WARNING! With %u disks it's recommended to use three parity levels.\n", diskcount); } else if (diskcount >= 5 && state->level < 2) { - fprintf(stderr, "WARNING! With %u disks it's recommended to use two parity levels.\n", diskcount); + ferr("WARNING! With %u disks it's recommended to use two parity levels.\n", diskcount); } } @@ -1184,7 +1184,7 @@ void state_refresh(struct snapraid_state* state) disk = find_disk(state, map->name); if (disk == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for mapping '%s'\n", map->name); + ferr("Internal inconsistency for mapping '%s'\n", map->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1192,7 +1192,7 @@ void state_refresh(struct snapraid_state* state) ret = fsinfo(disk->dir, 0, &total_space, &free_space); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno)); + ferr("Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1215,7 +1215,7 @@ void state_refresh(struct snapraid_state* state) ret = fsinfo(state->parity[l].path, 0, &total_space, &free_space); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing file '%s' to get filesystem info. %s.\n", state->parity[l].path, strerror(errno)); + ferr("Error accessing file '%s' to get filesystem info. %s.\n", state->parity[l].path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1244,13 +1244,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 */ - fprintf(stderr, "Colliding 'map' disk specification in '%s'\n", path); + ferr("Colliding 'map' disk specification in '%s'\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (map->position == other->position) { /* LCOV_EXCL_START */ - fprintf(stderr, "Colliding 'map' index specification in '%s'\n", path); + ferr("Colliding 'map' index specification in '%s'\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1369,7 +1369,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, tag, sizeof(tag)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading the configuration file '%s' at line %u\n", path, line); + ferr("Error reading the configuration file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1389,7 +1389,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (!file) { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Unexpected '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1397,14 +1397,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_pos); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (blockidx >= file->blockmax) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1413,7 +1413,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (block->parity_pos != POS_INVALID) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1446,7 +1446,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1454,7 +1454,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgethex(f, block->hash, HASH_SIZE); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1499,7 +1499,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* we must not overwrite existing blocks */ if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for '%s' specification in '%s' at line %u\n", tag, path, line); + ferr("Internal inconsistency for '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1525,14 +1525,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_pos); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'inf' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (v_pos >= blockmax) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in position for 'inf' specification in '%s' at line %u\n", path, line); + ferr("Internal inconsistency in position for 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1540,7 +1540,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'inf' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1548,7 +1548,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &t); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'inf' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1561,7 +1561,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'inf' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1573,13 +1573,13 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (state->prevhash == HASH_UNDEFINED) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for missing previous checksum in '%s' at line %u\n", path, line); + ferr("Internal inconsistency for missing previous checksum in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'inf' specification '%s' in '%s' at line %u\n", buffer, path, line); + ferr("Invalid 'inf' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1599,7 +1599,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (!disk) { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected 'off' specification in '%s' at line %u\n", path, line); + ferr("Unexpected 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1610,7 +1610,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_pos); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'off' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1621,7 +1621,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'off' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1630,7 +1630,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgethex(f, deleted->block.hash, HASH_SIZE); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'off' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1644,7 +1644,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* we must not overwrite existing blocks */ if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for 'off' specification in '%s' at line %u\n", path, line); + ferr("Internal inconsistency for 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1665,7 +1665,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (file) { /* LCOV_EXCL_START */ - fprintf(stderr, "Missing 'blk' specification in '%s' at line %u\n", path, line); + ferr("Missing 'blk' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1673,7 +1673,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1681,7 +1681,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1689,7 +1689,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu64(f, &v_size); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1697,7 +1697,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1705,7 +1705,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu64(f, &v_mtime_sec); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1715,7 +1715,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_mtime_nsec); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1728,7 +1728,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1736,7 +1736,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu64(f, &v_inode); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1744,7 +1744,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1752,14 +1752,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, sub, sizeof(sub)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*sub) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1768,7 +1768,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - fprintf(stderr, "Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + ferr("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1798,7 +1798,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (file) { /* LCOV_EXCL_START */ - fprintf(stderr, "Missing 'blk' specification in '%s' at line %u\n", path, line); + ferr("Missing 'blk' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1806,7 +1806,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hole' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hole' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1815,7 +1815,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - fprintf(stderr, "Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + ferr("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1829,7 +1829,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1837,7 +1837,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1845,7 +1845,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, sub, sizeof(sub)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1853,7 +1853,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgeteol(f); if (c != '\n') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1862,13 +1862,13 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, tokento, sizeof(tokento)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (strcmp(tokento, "to") != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1876,7 +1876,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1884,14 +1884,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, linkto, sizeof(linkto)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*sub || !*linkto) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1900,7 +1900,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - fprintf(stderr, "Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + ferr("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1924,7 +1924,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1932,7 +1932,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1940,7 +1940,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, sub, sizeof(sub)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1948,7 +1948,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgeteol(f); if (c != '\n') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1957,13 +1957,13 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, tokento, sizeof(tokento)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (strcmp(tokento, "to") != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1971,7 +1971,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1979,14 +1979,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, linkto, sizeof(linkto)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*sub || !*linkto) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1995,7 +1995,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - fprintf(stderr, "Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + ferr("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2017,7 +2017,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'dir' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2025,7 +2025,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'dir' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2033,14 +2033,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, sub, sizeof(sub)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'dir' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*sub) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'dir' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2049,7 +2049,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - fprintf(stderr, "Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + ferr("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2068,7 +2068,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'checksum' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'checksum' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2079,7 +2079,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE state->hash = HASH_SPOOKY2; } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'checksum' specification '%s' in '%s' at line %u\n", buffer, path, line); + ferr("Invalid 'checksum' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2090,7 +2090,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgethex(f, state->hashseed, HASH_SIZE); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'seed' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'seed' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2103,7 +2103,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'prevchecksum' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'prevchecksum' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2114,7 +2114,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE state->prevhash = HASH_SPOOKY2; } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); + ferr("Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2122,7 +2122,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); + ferr("Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2131,7 +2131,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgethex(f, state->prevhashseed, HASH_SIZE); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'seed' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'seed' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2141,7 +2141,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &blksize); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'blksize' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'blksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2153,8 +2153,8 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (blksize != state->block_size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Mismatching 'blksize' and 'blocksize' specification in '%s' at line %u\n", path, line); - fprintf(stderr, "Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024); + ferr("Mismatching 'blksize' and 'blocksize' specification in '%s' at line %u\n", path, line); + ferr("Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2168,7 +2168,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2176,7 +2176,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2184,7 +2184,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_pos); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2194,7 +2194,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2202,7 +2202,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_total_blocks); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2210,7 +2210,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2218,7 +2218,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_free_blocks); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2238,7 +2238,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, uuid, sizeof(uuid)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2257,7 +2257,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_level); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'parity' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2265,7 +2265,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'parity' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2273,7 +2273,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_total_blocks); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'parity' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2281,7 +2281,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'parity' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2289,7 +2289,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_free_blocks); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'parity' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2305,7 +2305,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, uuid, sizeof(uuid)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2328,7 +2328,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &sign); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid 'sign' specification in '%s' at line %u\n", path, line); + ferr("Invalid 'sign' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2341,13 +2341,13 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid comment in '%s' at line %u\n", path, line); + ferr("Invalid comment in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid command '%s' in '%s' at line %u\n", tag, path, line); + ferr("Invalid command '%s' in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2359,7 +2359,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE } if (c != '\n') { /* LCOV_EXCL_START */ - fprintf(stderr, "Extra data in '%s' at line %u\n", path, line); + ferr("Extra data in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2368,14 +2368,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading the content file '%s' at line %u\n", path, line); + ferr("Error reading the content file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (file) { /* LCOV_EXCL_START */ - fprintf(stderr, "Missing 'blk' specification in '%s' at line %u\n", path, line); + ferr("Missing 'blk' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2383,7 +2383,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* check that the stored parity size matches the loaded state */ if (blockmax != parity_allocated_size(state)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in parity size in '%s' at line %u\n", path, line); + ferr("Internal inconsistency in parity size in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2463,7 +2463,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2474,7 +2474,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputsl("checksum spooky2", f); } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); + ferr("Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2483,7 +2483,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2498,7 +2498,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputsl("prevchecksum spooky2", f); } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); + ferr("Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2507,7 +2507,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2523,7 +2523,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) disk = find_disk(state, map->name); if (!disk) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for unmapped disk '%s'\n", map->name); + ferr("Internal inconsistency for unmapped disk '%s'\n", map->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2548,7 +2548,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2579,7 +2579,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2624,7 +2624,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2637,7 +2637,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) /* consistency check */ if (block != disk_block_get(disk, block->parity_pos)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub); + ferr("Internal inconsistency mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2654,7 +2654,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) break; default : /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in state for block %u state %u\n", block->parity_pos, block_state); + ferr("Internal inconsistency in state for block %u state %u\n", block->parity_pos, block_state); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2667,7 +2667,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2700,7 +2700,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2717,7 +2717,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2731,7 +2731,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2742,7 +2742,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) /* consistency check */ if (block->parity_pos != b) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in delete position %u instead of %u\n", block->parity_pos, b); + ferr("Internal inconsistency in delete position %u instead of %u\n", block->parity_pos, b); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2754,7 +2754,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2782,7 +2782,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2791,7 +2791,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2816,20 +2816,20 @@ static void decoding_error(const char* path, STREAM* f) if (seof(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected end of content file '%s' at offset %" PRIi64 "\n", path, stell(f)); - fprintf(stderr, "This content file is truncated. Use an alternate copy.\n"); + ferr("Unexpected end of content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + ferr("This content file is truncated. Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + ferr("Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - fprintf(stderr, "Decoding error in '%s' at offset %" PRIi64 "\n", path, stell(f)); + ferr("Decoding error in '%s' at offset %" PRIi64 "\n", path, stell(f)); buf[0] = 0; buf[1] = 0; @@ -2852,7 +2852,7 @@ static void decoding_error(const char* path, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error flushing the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + ferr("Error flushing the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2867,11 +2867,11 @@ static void decoding_error(const char* path, STREAM* f) crc_stored = crc32c(crc_stored, buf, 4); if (crc_computed != crc_stored) { - fprintf(stderr, "Mismatching CRC in '%s'\n", path); - fprintf(stderr, "This content file is damaged! Use an alternate copy.\n"); + ferr("Mismatching CRC in '%s'\n", path); + ferr("This content file is damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); } else { - fprintf(stderr, "The file CRC is correct!\n"); + ferr("The file CRC is correct!\n"); } } @@ -2901,7 +2901,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Invalid header!\n"); + ferr("Invalid header!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2918,9 +2918,9 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* LCOV_EXCL_START */ if (memcmp(buffer, "SNAPCNT", 7) != 0) { decoding_error(path, f); - fprintf(stderr, "Invalid header!\n"); + ferr("Invalid header!\n"); } else { - fprintf(stderr, "The content file '%s' was generated with a newer version of SnapRAID!\n", path); + ferr("The content file '%s' was generated with a newer version of SnapRAID!\n", path); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -2951,7 +2951,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in mapping index!\n"); + ferr("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2969,7 +2969,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (v_size / state->block_size > blockmax) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in file size too big!\n"); + ferr("Internal inconsistency in file size too big!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3055,16 +3055,16 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (v_idx + v_count > file->blockmax) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in block number!\n"); + ferr("Internal inconsistency in block number!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (v_pos + v_count > blockmax) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in block size!\n"); + ferr("Internal inconsistency in block size!\n"); if (state->opt.skip_content_check) { - fprintf(stderr, "Overriding from %u to %u.\n", blockmax, v_pos + v_count); + ferr("Overriding from %u to %u.\n", blockmax, v_pos + v_count); blockmax = v_pos + v_count; } else { decoding_error(path, f); @@ -3083,7 +3083,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (block->parity_pos != POS_INVALID) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in block position!\n"); + ferr("Internal inconsistency in block position!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3105,7 +3105,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST default : /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Invalid block type!\n"); + ferr("Invalid block type!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3163,7 +3163,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in block existence!\n"); + ferr("Internal inconsistency in block existence!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3212,9 +3212,9 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (v_pos + v_count > blockmax) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in info size!\n"); + ferr("Internal inconsistency in info size!\n"); if (state->opt.skip_content_check) { - fprintf(stderr, "Overriding from %u to %u.\n", blockmax, v_pos + v_count); + ferr("Overriding from %u to %u.\n", blockmax, v_pos + v_count); blockmax = v_pos + v_count; } else { decoding_error(path, f); @@ -3249,7 +3249,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (rehash && state->prevhash == HASH_UNDEFINED) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency for missing previous checksum!\n"); + ferr("Internal inconsistency for missing previous checksum!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3268,7 +3268,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (!info) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency for missing info!\n"); + ferr("Internal inconsistency for missing info!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3292,7 +3292,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in mapping index!\n"); + ferr("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3312,9 +3312,9 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (v_pos + v_count > blockmax) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in hole size!\n"); + ferr("Internal inconsistency in hole size!\n"); if (state->opt.skip_content_check) { - fprintf(stderr, "Overriding from %u to %u.\n", blockmax, v_pos + v_count); + ferr("Overriding from %u to %u.\n", blockmax, v_pos + v_count); blockmax = v_pos + v_count; } else { decoding_error(path, f); @@ -3359,9 +3359,9 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* we must not overwrite existing blocks */ if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for used hole!\n"); + ferr("Internal inconsistency for used hole!\n"); if (state->opt.skip_content_check) { - fprintf(stderr, "Overriding as used.\n"); + ferr("Overriding as used.\n"); deleted_free(deleted); } else { decoding_error(path, f); @@ -3388,7 +3388,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST default : /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Invalid hole type!\n"); + ferr("Invalid hole type!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3405,7 +3405,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in mapping index!\n"); + ferr("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3455,7 +3455,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in mapping index!\n"); + ferr("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3504,7 +3504,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in mapping index!\n"); + ferr("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3548,7 +3548,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST default : /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Invalid checksum!\n"); + ferr("Invalid checksum!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3575,7 +3575,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST default : /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Invalid checksum!\n"); + ferr("Invalid checksum!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3607,8 +3607,8 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (blksize != state->block_size) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Mismatching 'blksize' and 'blocksize' specification!\n"); - fprintf(stderr, "Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024); + ferr("Mismatching 'blksize' and 'blocksize' specification!\n"); + ferr("Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3684,8 +3684,8 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (!disk) { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Disk named '%s' not present in the configuration file!\n", buffer); - fprintf(stderr, "If you have removed it from the configuration file, please restore it\n"); + ferr("Disk named '%s' not present in the configuration file!\n", buffer); + ferr("If you have removed it from the configuration file, please restore it\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3755,8 +3755,8 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0) { /* LCOV_EXCL_START */ /* here don't call decoding_error() because it's too late to get the crc */ - fprintf(stderr, "Error reading the CRC in '%s' at offset %" PRIi64 "\n", path, stell(f)); - fprintf(stderr, "This content file is damaged! Use an alternate copy.\n"); + ferr("Error reading the CRC in '%s' at offset %" PRIi64 "\n", path, stell(f)); + ferr("This content file is damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3764,8 +3764,8 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (crc_stored != crc_computed) { /* LCOV_EXCL_START */ /* here don't call decoding_error() because it's too late to get the crc */ - fprintf(stderr, "Mismatching CRC in '%s'\n", path); - fprintf(stderr, "This content file is damaged! Use an alternate copy.\n"); + ferr("Mismatching CRC in '%s'\n", path); + ferr("This content file is damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3774,7 +3774,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST } else { /* LCOV_EXCL_START */ decoding_error(path, f); - fprintf(stderr, "Invalid command '%c'!\n", (char)c); + ferr("Invalid command '%c'!\n", (char)c); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3784,15 +3784,15 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + ferr("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 */ - fprintf(stderr, "Finished reading '%s' without finding the CRC\n", path); - fprintf(stderr, "This content file is truncated or damaged! Use an alternate copy.\n"); + ferr("Finished reading '%s' without finding the CRC\n", path); + ferr("This content file is truncated or damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3800,9 +3800,9 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* check that the stored parity size matches the loaded state */ if (blockmax != parity_allocated_size(state)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in parity size in '%s' at offset %" PRIi64 "\n", path, stell(f)); + ferr("Internal inconsistency in parity size in '%s' at offset %" PRIi64 "\n", path, stell(f)); if (state->opt.skip_content_check) { - fprintf(stderr, "Overriding from %u to %u.\n", blockmax, parity_allocated_size(state)); + ferr("Overriding from %u to %u.\n", blockmax, parity_allocated_size(state)); blockmax = parity_allocated_size(state); } else { exit(EXIT_FAILURE); @@ -3879,7 +3879,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputb32(blockmax, f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3891,14 +3891,14 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputc('k', f); } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); + ferr("Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } swrite(state->hashseed, HASH_SIZE, f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3914,14 +3914,14 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputc('k', f); } else { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); + ferr("Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } swrite(state->prevhashseed, HASH_SIZE, f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3938,7 +3938,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) disk = find_disk(state, map->name); if (!disk) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency for unmapped disk '%s'\n", map->name); + ferr("Internal inconsistency for unmapped disk '%s'\n", map->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3953,7 +3953,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(map->uuid, f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3976,7 +3976,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(state->parity[l].uuid, f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4018,7 +4018,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(file->sub, f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4053,7 +4053,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) break; default : /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in state for block %u state %u\n", v_pos, block_state); + ferr("Internal inconsistency in state for block %u state %u\n", v_pos, block_state); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4070,7 +4070,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* consistency check */ if (block != disk_block_get(disk, block->parity_pos)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub); + ferr("Internal inconsistency in mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4080,7 +4080,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4112,7 +4112,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(link->linkto, f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4127,7 +4127,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(dir->sub, f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4140,7 +4140,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputb32(disk->mapping_idx, f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4172,7 +4172,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* consistency check */ if (block->parity_pos != begin) { /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in delete position %u instead of %u\n", block->parity_pos, begin); + ferr("Internal inconsistency in delete position %u instead of %u\n", block->parity_pos, begin); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4192,7 +4192,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4240,7 +4240,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4253,7 +4253,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputble32(scrc(f), f); if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4283,7 +4283,7 @@ void state_read(struct snapraid_state* state) pathcpy(path, sizeof(path), content->content); if (!state->no_conf) { - fprintf(stdlog, "content:%s\n", path); + ftag("content:%s\n", path); fflush(stdlog); } printf("Loading state from %s...\n", path); @@ -4296,14 +4296,14 @@ void state_read(struct snapraid_state* state) /* if it's real error of an existing file, abort */ if (errno != ENOENT) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening the content file '%s'. %s.\n", path, strerror(errno)); + ferr("Error opening the content file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } /* otherwise continue */ if (node->next) { - fprintf(stderr, "WARNING! Content file '%s' not found, trying with another copy...\n", path); + ferr("WARNING! Content file '%s' not found, trying with another copy...\n", path); /* ensure to rewrite all the content files */ state->need_write = 1; @@ -4316,7 +4316,7 @@ void state_read(struct snapraid_state* state) /* if not found, assume empty */ if (!f) { - fprintf(stderr, "No content file found. Assuming empty.\n"); + ferr("No content file found. Assuming empty.\n"); /* create the initial mapping */ state_map(state); @@ -4327,7 +4327,7 @@ void state_read(struct snapraid_state* state) ret = fstat(shandle(f), &st); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error stating the content file '%s'. %s.\n", path, strerror(errno)); + ferr("Error stating the content file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4344,7 +4344,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 */ - fprintf(stderr, "Error stating the content file '%s'. %s.\n", other_path, strerror(errno)); + ferr("Error stating the content file '%s'. %s.\n", other_path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4354,8 +4354,8 @@ void state_read(struct snapraid_state* state) } else { /* if the size is different */ if (other_st.st_size != st.st_size) { - fprintf(stderr, "WARNING! Content files '%s' and '%s' have a different size!\n", path, other_path); - fprintf(stderr, "Likely one of the two is broken!\n"); + ferr("WARNING! Content files '%s' and '%s' have a different size!\n", path, other_path); + ferr("Likely one of the two is broken!\n"); /* ensure to rewrite all the content files */ state->need_write = 1; @@ -4396,10 +4396,10 @@ void state_read(struct snapraid_state* state) if (state->hash == HASH_UNDEFINED) { /* LCOV_EXCL_START */ - fprintf(stderr, "The checksum to use is not specified.\n"); - fprintf(stderr, "This happens because you are likely upgrading from SnapRAID 1.0.\n"); - fprintf(stderr, "To use a new SnapRAID you must restart from scratch,\n"); - fprintf(stderr, "deleting all the content and parity files.\n"); + ferr("The checksum to use is not specified.\n"); + ferr("This happens because you are likely upgrading from SnapRAID 1.0.\n"); + ferr("To use a new SnapRAID you must restart from scratch,\n"); + ferr("deleting all the content and parity files.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4434,7 +4434,7 @@ void state_write(struct snapraid_state* state) f = sopen_multi_write(count_content); if (!f) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening the content files.\n"); + ferr("Error opening the content files.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4447,7 +4447,7 @@ void state_write(struct snapraid_state* state) pathprint(tmp, sizeof(tmp), "%s.tmp", content->content); if (sopen_multi_file(f, k, tmp) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error opening the content file '%s'. %s.\n", tmp, strerror(errno)); + ferr("Error opening the content file '%s'. %s.\n", tmp, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4465,7 +4465,7 @@ void state_write(struct snapraid_state* state) if (sflush(f) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4473,7 +4473,7 @@ void state_write(struct snapraid_state* state) #if HAVE_FSYNC if (ssync(f) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error writing the content file '%s' in sync(). %s.\n", serrorfile(f), strerror(errno)); + ferr("Error writing the content file '%s' in sync(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4481,7 +4481,7 @@ void state_write(struct snapraid_state* state) if (sclose(f) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error closing the content files in close(). %s.\n", strerror(errno)); + ferr("Error closing the content files in close(). %s.\n", strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4495,7 +4495,7 @@ void state_write(struct snapraid_state* state) pathprint(tmp, sizeof(tmp), "%s.tmp", content->content); if (rename(tmp, content->content) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error renaming the content file '%s' to '%s' in rename(). %s.\n", tmp, content->content, strerror(errno)); + ferr("Error renaming the content file '%s' to '%s' in rename(). %s.\n", tmp, content->content, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4592,7 +4592,7 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b time_t now; if (state->opt.gui) { - fprintf(stdlog, "run:begin:%u:%u:%u\n", blockstart, blockmax, countmax); + ftag("run:begin:%u:%u:%u\n", blockstart, blockmax, countmax); fflush(stdlog); } @@ -4610,7 +4610,7 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b if (!state->opt.gui) { printf("Not starting for interruption\n"); } - fprintf(stdlog, "sigint:0: SIGINT received\n"); + ftag("sigint:0: SIGINT received\n"); fflush(stdlog); return 0; /* LCOV_EXCL_STOP */ @@ -4622,7 +4622,7 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize) { if (state->opt.gui) { - fprintf(stdlog, "run:end\n"); + ftag("run:end\n"); fflush(stdlog); } else { time_t now; @@ -4757,7 +4757,7 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off } if (state->opt.gui) { - fprintf(stdlog, "run:pos:%u:%u:%" PRIu64 ":%u:%u:%u:%u:%" PRIu64 "\n", blockpos, countpos, countsize, out_perc, out_eta, out_speed, out_cpu, (uint64_t)elapsed); + ftag("run:pos:%u:%u:%" PRIu64 ":%u:%u:%u:%u:%" PRIu64 "\n", blockpos, countpos, countsize, out_perc, out_eta, out_speed, out_cpu, (uint64_t)elapsed); fflush(stdlog); } else { printf("%u%%, %u MiB", out_perc, (unsigned)(countsize / (1024 * 1024))); @@ -4794,7 +4794,7 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off printf("\n"); printf("Stopping for interruption at block %u\n", blockpos); } - fprintf(stdlog, "sigint:%u: SIGINT received\n", blockpos); + ftag("sigint:%u: SIGINT received\n", blockpos); fflush(stdlog); return 1; /* LCOV_EXCL_STOP */ diff --git a/cmdline/status.c b/cmdline/status.c index 64d5a90f..0e8e2cac 100644 --- a/cmdline/status.c +++ b/cmdline/status.c @@ -82,20 +82,20 @@ int state_status(struct snapraid_state* state) blockmax = parity_allocated_size(state); - fprintf(stdlog, "summary:block_size:%u\n", state->block_size); - fprintf(stdlog, "summary:parity_block_count:%u\n", blockmax); + ftag("summary:block_size:%u\n", state->block_size); + ftag("summary:parity_block_count:%u\n", blockmax); /* get the minimum parity free space */ parity_block_free = state->parity[0].free_blocks; for (l = 0; l < state->level; ++l) { - fprintf(stdlog, "summary:parity_block_total:%s:%u\n", lev_config_name(l), state->parity[l].total_blocks); - fprintf(stdlog, "summary:parity_block_free:%s:%u\n", lev_config_name(l), state->parity[l].free_blocks); + ftag("summary:parity_block_total:%s:%u\n", lev_config_name(l), state->parity[l].total_blocks); + ftag("summary:parity_block_free:%s:%u\n", lev_config_name(l), state->parity[l].free_blocks); if (state->parity[l].free_blocks < parity_block_free) parity_block_free = state->parity[l].free_blocks; if (state->parity[l].free_blocks != 0) free_not_zero = 1; } - fprintf(stdlog, "summary:parity_block_free_min:%u\n", parity_block_free); + ftag("summary:parity_block_free_min:%u\n", parity_block_free); printf("SnapRAID status report:\n"); printf("\n"); @@ -204,17 +204,17 @@ int state_status(struct snapraid_state* state) printf(" %3u%%", perc(disk_block_count, disk_block_max)); printf(" %s\n", disk->name); - fprintf(stdlog, "summary:disk_file_count:%s:%u\n", disk->name, disk_file_count); - fprintf(stdlog, "summary:disk_block_count:%s:%u\n", disk->name, disk_block_count); - fprintf(stdlog, "summary:disk_fragmented_file_count:%s:%u\n", disk->name, disk_file_fragmented); - fprintf(stdlog, "summary:disk_excess_fragment_count:%s:%u\n", disk->name, disk_extra_fragment); - fprintf(stdlog, "summary:disk_file_size:%s:%" PRIu64 "\n", disk->name, disk_file_size); - fprintf(stdlog, "summary:disk_block_allocated:%s:%u\n", disk->name, disk_block_latest_used + 1); - fprintf(stdlog, "summary:disk_block_total:%s:%u\n", disk->name, disk->total_blocks); - fprintf(stdlog, "summary:disk_block_free:%s:%u\n", disk->name, disk->free_blocks); - fprintf(stdlog, "summary:disk_block_max_by_space:%s:%u\n", disk->name, disk_block_max_by_space); - fprintf(stdlog, "summary:disk_block_max_by_parity:%s:%u\n", disk->name, disk_block_max_by_parity); - fprintf(stdlog, "summary:disk_block_max:%s:%u\n", disk->name, disk_block_max); + ftag("summary:disk_file_count:%s:%u\n", disk->name, disk_file_count); + ftag("summary:disk_block_count:%s:%u\n", disk->name, disk_block_count); + ftag("summary:disk_fragmented_file_count:%s:%u\n", disk->name, disk_file_fragmented); + ftag("summary:disk_excess_fragment_count:%s:%u\n", disk->name, disk_extra_fragment); + ftag("summary:disk_file_size:%s:%" PRIu64 "\n", disk->name, disk_file_size); + ftag("summary:disk_block_allocated:%s:%u\n", disk->name, disk_block_latest_used + 1); + ftag("summary:disk_block_total:%s:%u\n", disk->name, disk->total_blocks); + ftag("summary:disk_block_free:%s:%u\n", disk->name, disk->free_blocks); + ftag("summary:disk_block_max_by_space:%s:%u\n", disk->name, disk_block_max_by_space); + ftag("summary:disk_block_max_by_parity:%s:%u\n", disk->name, disk_block_max_by_parity); + ftag("summary:disk_block_max:%s:%u\n", disk->name, disk_block_max); } /* totals */ @@ -232,16 +232,16 @@ int state_status(struct snapraid_state* state) if (!free_not_zero) printf("\nWARNING! Free space info will be valid after the first sync.\n"); - fprintf(stdlog, "summary:file_count:%u\n", file_count); - fprintf(stdlog, "summary:file_block_count:%" PRIu64 "\n", file_block_count); - fprintf(stdlog, "summary:fragmented_file_count:%u\n", file_fragmented); - fprintf(stdlog, "summary:excess_fragment_count:%u\n", extra_fragment); - fprintf(stdlog, "summary:file_size:%" PRIu64 "\n", file_size); - fprintf(stdlog, "summary:parity_size:%" PRIu64 "\n", blockmax * (uint64_t)state->block_size); - fprintf(stdlog, "summary:parity_size_max:%" PRIu64 "\n", (blockmax + parity_block_free) * (uint64_t)state->block_size); - fprintf(stdlog, "summary:hash:%s\n", hash_config_name(state->hash)); - fprintf(stdlog, "summary:prev_hash:%s\n", hash_config_name(state->prevhash)); - fprintf(stdlog, "summary:best_hash:%s\n", hash_config_name(state->besthash)); + ftag("summary:file_count:%u\n", file_count); + ftag("summary:file_block_count:%" PRIu64 "\n", file_block_count); + ftag("summary:fragmented_file_count:%u\n", file_fragmented); + ftag("summary:excess_fragment_count:%u\n", extra_fragment); + ftag("summary:file_size:%" PRIu64 "\n", file_size); + ftag("summary:parity_size:%" PRIu64 "\n", blockmax * (uint64_t)state->block_size); + ftag("summary:parity_size_max:%" PRIu64 "\n", (blockmax + parity_block_free) * (uint64_t)state->block_size); + ftag("summary:hash:%s\n", hash_config_name(state->hash)); + ftag("summary:prev_hash:%s\n", hash_config_name(state->prevhash)); + ftag("summary:best_hash:%s\n", hash_config_name(state->besthash)); fflush(stdlog); /* copy the info a temp vector, and count bad/rehash/unsynced blocks */ @@ -252,7 +252,7 @@ int state_status(struct snapraid_state* state) count = 0; rehash = 0; unsynced_blocks = 0; - fprintf(stdlog, "block_count:%u\n", blockmax); + ftag("block_count:%u\n", blockmax); for (i = 0; i < blockmax; ++i) { int one_invalid; int one_valid; @@ -294,19 +294,19 @@ int state_status(struct snapraid_state* state) if (state->opt.gui) { if (info != 0) - fprintf(stdlog, "block:%u:%" PRIu64 ":%s:%s:%s:%s\n", i, (uint64_t)info_get_time(info), one_valid ? "used" : "", one_invalid ? "unsynced" : "", info_get_bad(info) ? "bad" : "", info_get_rehash(info) ? "rehash" : ""); + ftag("block:%u:%" PRIu64 ":%s:%s:%s:%s\n", i, (uint64_t)info_get_time(info), one_valid ? "used" : "", one_invalid ? "unsynced" : "", info_get_bad(info) ? "bad" : "", info_get_rehash(info) ? "rehash" : ""); else - fprintf(stdlog, "block_noinfo:%u:%s:%s\n", i, one_valid ? "used" : "", one_invalid ? "unsynced" : ""); + ftag("block_noinfo:%u:%s:%s\n", i, one_valid ? "used" : "", one_invalid ? "unsynced" : ""); } } - fprintf(stdlog, "summary:has_unsynced:%u\n", unsynced_blocks); - fprintf(stdlog, "summary:has_rehash:%u\n", rehash); - fprintf(stdlog, "summary:has_bad:%u:%u:%u\n", bad, bad_first, bad_last); + ftag("summary:has_unsynced:%u\n", unsynced_blocks); + ftag("summary:has_rehash:%u\n", rehash); + ftag("summary:has_bad:%u:%u:%u\n", bad, bad_first, bad_last); fflush(stdlog); if (!count) { - fprintf(stderr, "The array is empty.\n"); + ferr("The array is empty.\n"); free(infomap); return 0; } @@ -316,12 +316,12 @@ int state_status(struct snapraid_state* state) /* output the info map */ i = 0; - fprintf(stdlog, "info_count:%u\n", count); + ftag("info_count:%u\n", count); while (i < count) { unsigned j = i + 1; while (j < count && info_get_time(infomap[i]) == info_get_time(infomap[j])) ++j; - fprintf(stdlog, "info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); + ftag("info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); i = j; } diff --git a/cmdline/support.c b/cmdline/support.c index b4fb4c3b..687d7eb6 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -19,6 +19,55 @@ #include "support.h" +/****************************************************************************/ +/* print */ + +void fout(const char* format, ...) +{ + va_list ap; + + va_start(ap, format); + vfprintf(stdout, format, ap); + va_end(ap); +} + +void ferr(const char* format, ...) +{ + va_list ap; + + va_start(ap, format); + vfprintf(stderr, format, ap); + if (stdlog) { + fprintf(stdlog, "msg: "); + vfprintf(stdlog, format, ap); + } + va_end(ap); +} + +void flog(const char* format, ...) +{ + va_list ap; + + va_start(ap, format); + if (stdlog) { + fprintf(stdlog, "msg: "); + vfprintf(stdlog, format, ap); + } else { + vfprintf(stderr, format, ap); + } + va_end(ap); +} + +void ftag(const char* format, ...) +{ + va_list ap; + + va_start(ap, format); + if (stdlog) + vfprintf(stdlog, format, ap); + va_end(ap); +} + /****************************************************************************/ /* path */ @@ -28,7 +77,7 @@ void pathcpy(char* dst, size_t size, const char* src) if (len + 1 > size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Path too long\n"); + ferr("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -43,7 +92,7 @@ void pathcat(char* dst, size_t size, const char* src) if (dst_len + src_len + 1 > size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Path too long\n"); + ferr("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -57,7 +106,7 @@ void pathcatc(char* dst, size_t size, char c) if (dst_len + 2 > size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Path too long\n"); + ferr("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -105,7 +154,7 @@ void pathprint(char* dst, size_t size, const char* format, ...) if (len >= size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Path too long\n"); + ferr("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -118,7 +167,7 @@ void pathslash(char* dst, size_t size) if (len > 0 && dst[len - 1] != '/') { if (len + 2 >= size) { /* LCOV_EXCL_START */ - fprintf(stderr, "Path too long\n"); + ferr("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -213,7 +262,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 */ - fprintf(stderr, "Error creating directory '%s'. %s.\n", dir, strerror(errno)); + ferr("Error creating directory '%s'. %s.\n", dir, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -469,14 +518,14 @@ int smartctl_attribute(FILE* f, uint64_t* smart, char* serial) } else if (inside) { if (sscanf(s, "%u %*s %*s %*u %*u %*u %*s %*s %*s %" SCNu64, &id, &raw) != 2) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid smartctl line '%s'.\n", buf); + ferr("Invalid smartctl line '%s'.\n", buf); return -1; /* LCOV_EXCL_STOP */ } if (id >= 256) { /* LCOV_EXCL_START */ - fprintf(stderr, "Invalid SMART id '%u'.\n", id); + ferr("Invalid SMART id '%u'.\n", id); return -1; /* LCOV_EXCL_STOP */ } diff --git a/cmdline/support.h b/cmdline/support.h index 3e5d92f7..c79bfbdf 100644 --- a/cmdline/support.h +++ b/cmdline/support.h @@ -18,6 +18,50 @@ #ifndef __SUPPORT_H #define __SUPPORT_H +/****************************************************************************/ +/* log */ + +/** + * Output message targgeted for the screen. + * + * Messages are in human readable format. + * + * These messages go in stdout. + */ +void fout(const char* format, ...) __attribute__((format(printf, 1, 2))); + +/** + * Error message printed before an early termination. + * + * Messages are in human readable format. + * + * These messages go in the log file and in stderr. + */ +void ferr(const char* format, ...) __attribute__((format(printf, 1, 2))); + +/** + * Log message printed after an error. + * + * Messages are in human readable format. + * + * These messages go in the log file if specified, otherwise in stderr. + */ +void flog(const char* format, ...) __attribute__((format(printf, 1, 2))); + +/** + * Tag message. + * + * Messages are in tag format, like "tag:entry:...". + * + * These messages go in the log file. + */ +void ftag(const char* format, ...) __attribute__((format(printf, 1, 2))); + +/** + * Pointer to log function. + */ +typedef void fptr(const char* format, ...); + /****************************************************************************/ /* path */ @@ -57,7 +101,7 @@ void pathexport(char* dst, size_t size, const char* src); * Prints a path. * Aborts if too long. */ -void pathprint(char* dst, size_t size, const char* format, ...); +void pathprint(char* dst, size_t size, const char* format, ...) __attribute__((format(printf, 3, 4))); /** * Ensures the presence of a terminating slash, if it isn't empty. diff --git a/cmdline/sync.c b/cmdline/sync.c index 5452adca..709068d3 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -132,17 +132,17 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ if (errno == EIO) { - fprintf(stdlog, "error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + ftag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", i); ++io_error; goto bail; } - fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that file '%s' can be accessed.\n", handle[j].path); + ftag("error:%u:%s:%s: Close error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that file '%s' can be accessed.\n", handle[j].path); printf("Stopping at block %u\n", i); ++error; goto bail; @@ -150,15 +150,15 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta } } - ret = handle_open(&handle[j], block_file_get(block), state->file_mode, stderr); + ret = handle_open(&handle[j], block_file_get(block), state->file_mode, flog); if (ret == -1) { /* file we have tried to open for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { /* LCOV_EXCL_START */ - fprintf(stdlog, "error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + ftag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", i); ++io_error; goto bail; @@ -166,10 +166,10 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta } if (errno == ENOENT) { - fprintf(stdlog, "error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "Missing file '%s'.\n", handle[j].path); - fprintf(stderr, "WARNING! You cannot modify data disk during a sync.\n"); - fprintf(stderr, "Rerun the sync command when finished.\n"); + ftag("error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, file->sub, strerror(errno)); + flog("Missing file '%s'.\n", handle[j].path); + flog("WARNING! You cannot modify data disk during a sync.\n"); + flog("Rerun the sync command when finished.\n"); ++error; /* if the file is missing, it means that it was removed during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ @@ -177,19 +177,19 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta } if (errno == EACCES) { - fprintf(stdlog, "error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "No access at file '%s'.\n", handle[j].path); - fprintf(stderr, "WARNING! Please fix the access permission in the data disk.\n"); - fprintf(stderr, "Rerun the sync command when finished.\n"); + ftag("error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, file->sub, strerror(errno)); + flog("No access at file '%s'.\n", handle[j].path); + flog("WARNING! Please fix the access permission in the data disk.\n"); + flog("Rerun the sync command when finished.\n"); ++error; /* this isn't a serious error, so we skip this block, and continue with others */ continue; } /* LCOV_EXCL_START */ - fprintf(stdlog, "error:%u:%s:%s: Open error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that file '%s' can be accessed.\n", handle[j].path); + ftag("error:%u:%s:%s: Open error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that file '%s' can be accessed.\n", handle[j].path); printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); ++error; goto bail; @@ -204,40 +204,40 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta ) { /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); - fprintf(stdlog, "error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, file->sub); + ftag("error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, file->sub); if (handle[j].st.st_size != file->size) { - fprintf(stderr, "Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); + flog("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); } else if (handle[j].st.st_mtime != file->mtime_sec || STAT_NSEC(&handle[j].st) != file->mtime_nsec) { - fprintf(stderr, "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, (uint32_t)STAT_NSEC(&handle[j].st)); + flog("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, (uint32_t)STAT_NSEC(&handle[j].st)); } else { - fprintf(stderr, "Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); + flog("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); } - fprintf(stderr, "WARNING! You cannot modify files during a sync.\n"); - fprintf(stderr, "Rerun the sync command when finished.\n"); + flog("WARNING! You cannot modify files during a sync.\n"); + flog("Rerun the sync command when finished.\n"); ++error; /* if the file is changed, it means that it was modified during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ continue; } - read_size = handle_read(&handle[j], block, buffer, state->block_size, stderr); + read_size = handle_read(&handle[j], block, buffer, state->block_size, ferr); if (read_size == -1) { /* LCOV_EXCL_START */ /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { - fprintf(stdlog, "error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); - fprintf(stderr, "DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path); + ftag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); + ferr("DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", i); ++io_error; goto bail; } - fprintf(stdlog, "error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); - fprintf(stderr, "WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that file '%s' can be read.\n", handle[j].path); + ftag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); + ferr("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that file '%s' can be read.\n", handle[j].path); printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); ++error; goto bail; @@ -287,17 +287,17 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ if (errno == EIO) { - fprintf(stdlog, "error:%u:%s:%s: Close EIO error. %s\n", blockmax, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + ftag("error:%u:%s:%s: Close EIO error. %s\n", blockmax, disk->name, file->sub, strerror(errno)); + ferr("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", blockmax); ++io_error; goto bail; } - fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", blockmax, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that file '%s' can be accessed.\n", handle[j].path); + ftag("error:%u:%s:%s: Close error. %s\n", blockmax, disk->name, file->sub, strerror(errno)); + ferr("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that file '%s' can be accessed.\n", handle[j].path); printf("Stopping at block %u\n", blockmax); ++error; goto bail; @@ -320,7 +320,7 @@ end: printf("Everything OK\n"); } - fprintf(stdlog, "hash_summary:error_readwrite:%u\n", error); + ftag("hash_summary:error_readwrite:%u\n", error); /* proceed without bailing out */ goto finish; @@ -333,7 +333,7 @@ bail: for (j = 0; j < diskmax; ++j) { ret = handle_close(&handle[j]); if (ret == -1) { - fprintf(stderr, "DANGER! Unexpected close error in a data disk.\n"); + ferr("DANGER! Unexpected close error in a data disk.\n"); ++error; /* continue, as we are already exiting */ } @@ -598,17 +598,17 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ if (errno == EIO) { - fprintf(stdlog, "error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + ftag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", i); ++io_error; goto bail; } - fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that file '%s' can be accessed.\n", handle[j].path); + ftag("error:%u:%s:%s: Close error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that file '%s' can be accessed.\n", handle[j].path); printf("Stopping at block %u\n", i); ++error; goto bail; @@ -616,15 +616,15 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } } - ret = handle_open(&handle[j], block_file_get(block), state->file_mode, stderr); + ret = handle_open(&handle[j], block_file_get(block), state->file_mode, flog); if (ret == -1) { /* file we have tried to open for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { /* LCOV_EXCL_START */ - fprintf(stdlog, "error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + ftag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", i); ++io_error; goto bail; @@ -632,10 +632,10 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } if (errno == ENOENT) { - fprintf(stdlog, "error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "Missing file '%s'.\n", handle[j].path); - fprintf(stderr, "WARNING! You cannot modify data disk during a sync.\n"); - fprintf(stderr, "Rerun the sync command when finished.\n"); + ftag("error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, file->sub, strerror(errno)); + flog("Missing file '%s'.\n", handle[j].path); + flog("WARNING! You cannot modify data disk during a sync.\n"); + flog("Rerun the sync command when finished.\n"); ++error; /* if the file is missing, it means that it was removed during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ @@ -644,10 +644,10 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } if (errno == EACCES) { - fprintf(stdlog, "error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "No access at file '%s'.\n", handle[j].path); - fprintf(stderr, "WARNING! Please fix the access permission in the data disk.\n"); - fprintf(stderr, "Rerun the sync command when finished.\n"); + ftag("error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, file->sub, strerror(errno)); + flog("No access at file '%s'.\n", handle[j].path); + flog("WARNING! Please fix the access permission in the data disk.\n"); + flog("Rerun the sync command when finished.\n"); ++error; /* this isn't a serious error, so we skip this block, and continue with others */ error_on_this_block = 1; @@ -655,9 +655,9 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } /* LCOV_EXCL_START */ - fprintf(stdlog, "error:%u:%s:%s: Open error. %s\n", i, disk->name, file->sub, strerror(errno)); - fprintf(stderr, "WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that file '%s' can be accessed.\n", handle[j].path); + ftag("error:%u:%s:%s: Open error. %s\n", i, disk->name, file->sub, strerror(errno)); + ferr("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that file '%s' can be accessed.\n", handle[j].path); printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); ++error; goto bail; @@ -672,17 +672,17 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari ) { /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); - fprintf(stdlog, "error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, file->sub); + ftag("error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, file->sub); if (handle[j].st.st_size != file->size) { - fprintf(stderr, "Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); + flog("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); } else if (handle[j].st.st_mtime != file->mtime_sec || STAT_NSEC(&handle[j].st) != file->mtime_nsec) { - fprintf(stderr, "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, (uint32_t)STAT_NSEC(&handle[j].st)); + flog("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, (uint32_t)STAT_NSEC(&handle[j].st)); } else { - fprintf(stderr, "Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); + flog("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); } - fprintf(stderr, "WARNING! You cannot modify files during a sync.\n"); - fprintf(stderr, "Rerun the sync command when finished.\n"); + flog("WARNING! You cannot modify files during a sync.\n"); + flog("Rerun the sync command when finished.\n"); ++error; /* if the file is changed, it means that it was modified during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ @@ -690,30 +690,30 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari continue; } - read_size = handle_read(&handle[j], block, buffer[j], state->block_size, stderr); + read_size = handle_read(&handle[j], block, buffer[j], state->block_size, flog); if (read_size == -1) { /* LCOV_EXCL_START */ /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { - fprintf(stdlog, "error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); + ftag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); if (io_error >= state->opt.io_error_limit) { - fprintf(stderr, "DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path); + ferr("DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path); printf("Stopping at block %u\n", i); ++io_error; goto bail; } - fprintf(stderr, "Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + flog("Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); ++io_error; io_error_on_this_block = 1; continue; } - fprintf(stdlog, "error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); - fprintf(stderr, "WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); - fprintf(stderr, "Ensure that file '%s' can be read.\n", handle[j].path); + ftag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, file->sub, block_file_pos(block), strerror(errno)); + ferr("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); + ferr("Ensure that file '%s' can be read.\n", handle[j].path); printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); ++error; goto bail; @@ -744,17 +744,17 @@ 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)) { - fprintf(stdlog, "error:%u:%s:%s: Unexpected data change\n", i, disk->name, file->sub); - fprintf(stderr, "Data change at file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); - fprintf(stderr, "WARNING! Unexpected data modification of a file without parity!\n"); + ftag("error:%u:%s:%s: Unexpected data change\n", i, disk->name, file->sub); + flog("Data change at file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + flog("WARNING! Unexpected data modification of a file without parity!\n"); if (file_flag_has(file, FILE_IS_COPY)) { - fprintf(stderr, "This file was detected as a copy of another file with the same name, size,\n"); - fprintf(stderr, "and timestamp, but the file data isn't matching the assumed copy.\n"); - fprintf(stderr, "If this is a false positive, and the files are expected to be different,\n"); - fprintf(stderr, "you can 'sync' anyway using 'snapraid --force-nocopy sync'\n"); + flog("This file was detected as a copy of another file with the same name, size,\n"); + flog("and timestamp, but the file data isn't matching the assumed copy.\n"); + flog("If this is a false positive, and the files are expected to be different,\n"); + flog("you can 'sync' anyway using 'snapraid --force-nocopy sync'\n"); } else { - fprintf(stderr, "Try removing the file from the array and rerun the 'sync' command!\n"); + flog("Try removing the file from the array and rerun the 'sync' command!\n"); } ++error; @@ -764,8 +764,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari error_on_this_block = 1; continue; } else { /* otherwise it's a BLK with silent error */ - fprintf(stdlog, "error:%u:%s:%s: Data error at position %u\n", i, disk->name, file->sub, block_file_pos(block)); - fprintf(stderr, "Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + ftag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, file->sub, block_file_pos(block)); + flog("Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); /* save the failed block for the fix */ failed[failed_count].index = j; @@ -858,28 +858,28 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* we are sure that parity exists because */ /* we have at least one BLK block */ for (l = 0; l < state->level; ++l) { - ret = parity_read(parity[l], i, buffer[diskmax + l], state->block_size, stdlog); + ret = parity_read(parity[l], i, buffer[diskmax + l], state->block_size, flog); if (ret == -1) { /* LCOV_EXCL_START */ if (errno == EIO) { - fprintf(stdlog, "parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno)); + ftag("parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno)); if (io_error >= state->opt.io_error_limit) { - fprintf(stderr, "DANGER! Unexpected input/output read error in the %s disk, it isn't possible to sync.\n", lev_name(l)); - fprintf(stderr, "Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l)); + ferr("DANGER! Unexpected input/output read error in the %s disk, it isn't possible to sync.\n", lev_name(l)); + ferr("Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l)); printf("Stopping at block %u\n", i); ++io_error; goto bail; } - fprintf(stderr, "Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); + flog("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); ++io_error; io_error_on_this_block = 1; continue; } - fprintf(stdlog, "parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno)); - fprintf(stderr, "WARNING! Unexpected read error in the %s disk, it isn't possible to sync.\n", lev_name(l)); - fprintf(stderr, "Ensure that disk '%s' can be read.\n", lev_config_name(l)); + ftag("parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno)); + ferr("WARNING! Unexpected read error in the %s disk, it isn't possible to sync.\n", lev_name(l)); + ferr("Ensure that disk '%s' can be read.\n", lev_config_name(l)); printf("Stopping at block %u\n", i); ++error; goto bail; @@ -957,24 +957,24 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari if (ret == -1) { /* LCOV_EXCL_START */ if (errno == EIO) { - fprintf(stdlog, "parity_error:%u:%s: Write EIO error. %s\n", i, lev_config_name(l), strerror(errno)); + ftag("parity_error:%u:%s: Write EIO error. %s\n", i, lev_config_name(l), strerror(errno)); if (io_error >= state->opt.io_error_limit) { - fprintf(stderr, "DANGER! Unexpected input/output write error in the %s disk, it isn't possible to sync.\n", lev_name(l)); - fprintf(stderr, "Ensure that disk '%s' is sane and can be written.\n", lev_config_name(l)); + ferr("DANGER! Unexpected input/output write error in the %s disk, it isn't possible to sync.\n", lev_name(l)); + ferr("Ensure that disk '%s' is sane and can be written.\n", lev_config_name(l)); printf("Stopping at block %u\n", i); ++io_error; goto bail; } - fprintf(stderr, "Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); + flog("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); ++io_error; io_error_on_this_block = 1; continue; } - fprintf(stdlog, "parity_error:%u:%s: Write error. %s\n", i, lev_config_name(l), strerror(errno)); - fprintf(stderr, "WARNING! Unexpected write error in the %s disk, it isn't possible to sync.\n", lev_name(l)); - fprintf(stderr, "Ensure that disk '%s' has some free space available.\n", lev_config_name(l)); + ftag("parity_error:%u:%s: Write error. %s\n", i, lev_config_name(l), strerror(errno)); + ferr("WARNING! Unexpected write error in the %s disk, it isn't possible to sync.\n", lev_name(l)); + ferr("Ensure that disk '%s' has some free space available.\n", lev_config_name(l)); printf("Stopping at block %u\n", i); ++error; goto bail; @@ -1078,9 +1078,9 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari ret = parity_sync(parity[l]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stdlog, "parity_error:%u:%s: Sync error\n", i, lev_config_name(l)); - fprintf(stderr, "DANGER! Unexpected sync error in %s disk.\n", lev_name(l)); - fprintf(stderr, "Ensure that disk '%s' is sane.\n", lev_config_name(l)); + ftag("parity_error:%u:%s: Sync error\n", i, lev_config_name(l)); + ferr("DANGER! Unexpected sync error in %s disk.\n", lev_name(l)); + ferr("Ensure that disk '%s' is sane.\n", lev_config_name(l)); printf("Stopping at block %u\n", i); ++error; goto bail; @@ -1109,9 +1109,9 @@ end: ret = parity_sync(parity[l]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stdlog, "parity_error:%u:%s: Sync error\n", i, lev_config_name(l)); - fprintf(stderr, "DANGER! Unexpected sync error in %s disk.\n", lev_name(l)); - fprintf(stderr, "Ensure that disk '%s' is sane.\n", lev_config_name(l)); + ftag("parity_error:%u:%s: Sync error\n", i, lev_config_name(l)); + ferr("DANGER! Unexpected sync error in %s disk.\n", lev_name(l)); + ferr("Ensure that disk '%s' is sane.\n", lev_config_name(l)); printf("Stopping at block %u\n", i); ++error; goto bail; @@ -1120,12 +1120,12 @@ end: } if (io_error) - fprintf(stderr, "WARNING! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); + ferr("WARNING! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); if (silent_error) - fprintf(stderr, "WARNING! Unexpected data errors! The failing blocks are now marked as bad!\n"); + ferr("WARNING! Unexpected data errors! The failing blocks are now marked as bad!\n"); if (io_error || silent_error) { - fprintf(stderr, "Use 'snapraid status' to list the bad blocks.\n"); - fprintf(stderr, "Use 'snapraid -e fix' to recover.\n"); + ferr("Use 'snapraid status' to list the bad blocks.\n"); + ferr("Use 'snapraid -e fix' to recover.\n"); } if (error || silent_error || io_error) { @@ -1140,13 +1140,13 @@ end: printf("Everything OK\n"); } - fprintf(stdlog, "summary:error_file:%u\n", error); - fprintf(stdlog, "summary:error_io:%u\n", io_error); - fprintf(stdlog, "summary:error_data:%u\n", silent_error); + ftag("summary:error_file:%u\n", error); + ftag("summary:error_io:%u\n", io_error); + ftag("summary:error_data:%u\n", silent_error); if (error + silent_error + io_error == 0) - fprintf(stdlog, "summary:exit:ok\n"); + ftag("summary:exit:ok\n"); else - fprintf(stdlog, "summary:exit:error\n"); + ftag("summary:exit:error\n"); fflush(stdlog); bail: @@ -1154,7 +1154,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected close error in a data disk.\n"); + ferr("DANGER! Unexpected close error in a data disk.\n"); ++error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -1207,7 +1207,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t if (blockstart > blockmax) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error in the starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); + ferr("Error in the starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1225,7 +1225,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t ret = parity_create(parity_ptr[l], state->parity[l].path, &out_size, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); + ferr("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1235,7 +1235,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) { - fprintf(stderr, "WARNING! The %s file %s has data only %u blocks instead of %u.\n", lev_name(l), state->parity[l].path, parityblocks, used_paritymax); + ferr("WARNING! The %s file %s has data only %u blocks instead of %u.\n", lev_name(l), state->parity[l].path, parityblocks, used_paritymax); } /* keep the smallest parity number of blocks */ @@ -1248,15 +1248,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 */ - fprintf(stderr, "DANGER! One or more the parity files are smaller than expected!\n"); + ferr("DANGER! One or more the parity files are smaller than expected!\n"); if (file_paritymax != 0) { - fprintf(stderr, "If this happens because you are using an old content file,\n"); - fprintf(stderr, "you can 'sync' anyway using 'snapraid --force-full sync'\n"); - fprintf(stderr, "to force a full rebuild of the parity.\n"); + ferr("If this happens because you are using an old content file,\n"); + ferr("you can 'sync' anyway using 'snapraid --force-full sync'\n"); + ferr("to force a full rebuild of the parity.\n"); } else { - fprintf(stderr, "It's possible that the parity disks are not mounted.\n"); - fprintf(stderr, "If instead you are adding a new parity level, you can 'sync' using\n"); - fprintf(stderr, "'snapraid --force-full sync' to force a full rebuild of the parity.\n"); + ferr("It's possible that the parity disks are not mounted.\n"); + ferr("If instead you are adding a new parity level, you can 'sync' using\n"); + ferr("'snapraid --force-full sync' to force a full rebuild of the parity.\n"); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1272,7 +1272,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t if (ret == -1) { /* LCOV_EXCL_START */ parity_overflow(state, out_size); - fprintf(stderr, "WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); + ferr("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1319,7 +1319,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t ret = parity_close(parity_ptr[l]); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Unexpected close error in %s disk.\n", lev_name(l)); + ferr("DANGER! Unexpected close error in %s disk.\n", lev_name(l)); ++unrecoverable_error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ diff --git a/cmdline/unix.c b/cmdline/unix.c index 62a879ab..0d995a7b 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -341,7 +341,7 @@ static dev_t devread(const char* path) f = open(path, O_RDONLY); if (f == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to open '%s'.\n", path); + ferr("Failed to open '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } @@ -350,14 +350,14 @@ static dev_t devread(const char* path) if (ret < 0) { /* LCOV_EXCL_START */ close(f); - fprintf(stderr, "Failed to read '%s'.\n", path); + ferr("Failed to read '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } if (ret == sizeof(buf)) { /* LCOV_EXCL_START */ close(f); - fprintf(stderr, "Too long read '%s'.\n", path); + ferr("Too long read '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } @@ -368,7 +368,7 @@ static dev_t devread(const char* path) if (*e != ':') { /* LCOV_EXCL_START */ close(f); - fprintf(stderr, "Invalid format in '%s' for '%s'.\n", path, buf); + ferr("Invalid format in '%s' for '%s'.\n", path, buf); return 0; /* LCOV_EXCL_STOP */ } @@ -377,7 +377,7 @@ static dev_t devread(const char* path) if (*e != 0 && !isspace(*e)) { /* LCOV_EXCL_START */ close(f); - fprintf(stderr, "Invalid format in '%s' for '%s'.\n", path, buf); + ferr("Invalid format in '%s' for '%s'.\n", path, buf); return 0; /* LCOV_EXCL_STOP */ } @@ -385,7 +385,7 @@ static dev_t devread(const char* path) ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to close '%s'.\n", path); + ferr("Failed to close '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } @@ -408,13 +408,13 @@ static int devresolve(dev_t device, char* path, size_t path_size) ret = readlink(path, buf, sizeof(buf)); if (ret < 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to readlink '%s'.\n", path); + ferr("Failed to readlink '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } if (ret == sizeof(buf)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Too long readlink '%s'.\n", path); + ferr("Too long readlink '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } @@ -423,7 +423,7 @@ static int devresolve(dev_t device, char* path, size_t path_size) if (buf[0] != '.' || buf[1] != '.' || buf[2] != '/') { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected link '%s' at '%s'.\n", buf, path); + ferr("Unexpected link '%s' at '%s'.\n", buf, path); return -1; /* LCOV_EXCL_STOP */ } @@ -434,13 +434,13 @@ static int devresolve(dev_t device, char* path, size_t path_size) /* check the device */ if (stat(path, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to stat '%s'.\n", path); + ferr("Failed to stat '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } if (st.st_rdev != device) { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected device '%u:%u' instead of '%u:%u' for '%s'.\n", major(st.st_rdev), minor(st.st_rdev), major(device), minor(device), path); + ferr("Unexpected device '%u:%u' instead of '%u:%u' for '%s'.\n", major(st.st_rdev), minor(st.st_rdev), major(device), minor(device), path); return -1; /* LCOV_EXCL_STOP */ } @@ -552,7 +552,7 @@ static int devscan(tommy_list* list) d = opendir(dir); if (d == 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to open dir '%s'.\n", dir); + ferr("Failed to open dir '%s'.\n", dir); return -1; /* LCOV_EXCL_STOP */ } @@ -628,7 +628,7 @@ static int devsmart(dev_t device, uint64_t* smart, char* serial) f = popen(cmd, "r"); if (!f) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run smartctl -a on device '%u:%u' (from popen).\n", major(device), minor(device)); + ferr("Failed to run smartctl -a on device '%u:%u' (from popen).\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -643,13 +643,13 @@ static int devsmart(dev_t device, uint64_t* smart, char* serial) ret = pclose(f); if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run smartctl -a on device '%u:%u' (not exited).\n", major(device), minor(device)); + ferr("Failed to run smartctl -a on device '%u:%u' (not exited).\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run smartctl -a on device '%u:%u' (from sh).\n", major(device), minor(device)); + ferr("Failed to run smartctl -a on device '%u:%u' (from sh).\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } @@ -674,25 +674,25 @@ static int devdown(dev_t device) ret = system(cmd); if (ret == -1) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run hdparm -y on device '%u:%u' (from system).\n", major(device), minor(device)); + ferr("Failed to run hdparm -y on device '%u:%u' (from system).\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run hdparm -y on device '%u:%u' (not exited).\n", major(device), minor(device)); + ferr("Failed to run hdparm -y on device '%u:%u' (not exited).\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run hdparm -y on device '%u:%u' (from sh).\n", major(device), minor(device)); + ferr("Failed to run hdparm -y on device '%u:%u' (from sh).\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to run hdparm -y on device '%u:%u' with return code %xh.\n", major(device), minor(device), WEXITSTATUS(ret)); + ferr("Failed to run hdparm -y on device '%u:%u' with return code %xh.\n", major(device), minor(device), WEXITSTATUS(ret)); return -1; /* LCOV_EXCL_STOP */ } @@ -721,7 +721,7 @@ static int devup(dev_t device, const char* mount) ret = mkdir(path, 0); if (ret != 0 && errno != EEXIST) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to create dir '%s'.\n", path); + ferr("Failed to create dir '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } @@ -750,7 +750,7 @@ static void* thread_spinup(void* arg) /* first get the device number, this usually doesn't trigger a thread_spinup */ if (stat(devinfo->mount, &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to stat device '%s'.\n", devinfo->mount); + ferr("Failed to stat device '%s'.\n", devinfo->mount); return (void*)-1; /* LCOV_EXCL_STOP */ } @@ -830,7 +830,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) if (pthread_create(&devinfo->thread, 0, func, devinfo) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to create thread.\n"); + ferr("Failed to create thread.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -843,7 +843,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) if (pthread_join(devinfo->thread, &retval) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to join thread.\n"); + ferr("Failed to join thread.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -879,13 +879,13 @@ int devquery(tommy_list* high, tommy_list* low, int operation) /* sysfs and devfs interfaces are required */ if (stat("/sys/dev/block", &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Missing interface /sys/dev/block.\n"); + ferr("Missing interface /sys/dev/block.\n"); return -1; /* LCOV_EXCL_STOP */ } if (stat("/dev/block", &st) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Missing interface /dev/block.\n"); + ferr("Missing interface /dev/block.\n"); return -1; /* LCOV_EXCL_STOP */ } @@ -897,7 +897,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) /* get the device file */ if (devresolve(devinfo->device, devinfo->file, sizeof(devinfo->file)) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to resolve device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device)); + ferr("Failed to resolve device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device)); return -1; /* LCOV_EXCL_STOP */ } @@ -905,7 +905,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) /* expand the tree of devices */ if (devtree(devinfo->name, devinfo->device, devinfo, low) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to expand device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device)); + ferr("Failed to expand device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device)); return -1; /* LCOV_EXCL_STOP */ } @@ -935,7 +935,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) if (operation == DEVICE_SMART) { if (devscan(low) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Failed to list other devices.\n"); + ferr("Failed to list other devices.\n"); return -1; /* LCOV_EXCL_STOP */ } diff --git a/cmdline/util.c b/cmdline/util.c index 1d737c84..ef6d67e9 100644 --- a/cmdline/util.c +++ b/cmdline/util.c @@ -926,8 +926,8 @@ void mtest_vector(int n, size_t size, void** vv) { if (raid_mtest_vector(n, size, vv) != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); - fprintf(stderr, "Try running a memory test like http://www.memtest86.com/\n"); + ferr("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); + ferr("Try running a memory test like http://www.memtest86.com/\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1347,7 +1347,7 @@ void memhash(unsigned kind, const unsigned char* seed, void* digest, const void* break; default : /* LCOV_EXCL_START */ - fprintf(stderr, "Internal inconsistency in hash function %u\n", kind); + ferr("Internal inconsistency in hash function %u\n", kind); exit(EXIT_FAILURE); break; /* LCOV_EXCL_STOP */ diff --git a/snapraid.1 b/snapraid.1 index abf6f00b..8f661161 100644 --- a/snapraid.1 +++ b/snapraid.1 @@ -998,14 +998,10 @@ the old content file and the parity data you have. This option can be used only with \[dq]sync\[dq]. .TP .B \-l, \-\-log FILE -Write a detailed log of errors found in check and fix. -This log contains the exact specification of which block of -any file is not recoverable and why. -If this option is not specified, no detailed log is printed, -and you\'ll get only a summary at the end of the operations. -When checking and fixing this allows to keep separated -the possible huge list of errors from the human readable -output. +Write a detailed log of errors encoutered. +If this option is not specified, the errors are printed on +the screen, likely resulting in too much output in case +of many errors. If the specified path starts with \'>>\' the file is opened in append mode. Occurrences of \'%D\' and \'%T\' in the name are replaced with the date and time in the format YYYYMMDD and diff --git a/snapraid.d b/snapraid.d index 1f4e276a..4deeab51 100644 --- a/snapraid.d +++ b/snapraid.d @@ -739,14 +739,10 @@ Options This option can be used only with "sync". -l, --log FILE - Write a detailed log of errors found in check and fix. - This log contains the exact specification of which block of - any file is not recoverable and why. - If this option is not specified, no detailed log is printed, - and you'll get only a summary at the end of the operations. - When checking and fixing this allows to keep separated - the possible huge list of errors from the human readable - output. + Write a detailed log of errors encoutered. + If this option is not specified, the errors are printed on + the screen, likely resulting in too much output in case + of many errors. If the specified path starts with '>>' the file is opened in append mode. Occurrences of '%D' and '%T' in the name are replaced with the date and time in the format YYYYMMDD and diff --git a/snapraid.txt b/snapraid.txt index 9743372e..3c344e17 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -796,14 +796,10 @@ SnapRAID provides the following options: This option can be used only with "sync". -l, --log FILE - Write a detailed log of errors found in check and fix. - This log contains the exact specification of which block of - any file is not recoverable and why. - If this option is not specified, no detailed log is printed, - and you'll get only a summary at the end of the operations. - When checking and fixing this allows to keep separated - the possible huge list of errors from the human readable - output. + Write a detailed log of errors encoutered. + If this option is not specified, the errors are printed on + the screen, likely resulting in too much output in case + of many errors. If the specified path starts with '>>' the file is opened in append mode. Occurrences of '%D' and '%T' in the name are replaced with the date and time in the format YYYYMMDD and