diff --git a/cmdline/check.c b/cmdline/check.c index a3f3a4db..d336b206 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -1194,7 +1194,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } /* read from the file */ - read_size = handle_read(&handle[j], file_pos, buffer[j], state->block_size, log_error, state->opt.expected_missing ? log_expected : 0); + if (file_flag_has(file, FILE_IS_MISSING)) { + /* if the file is reported missing, don't even try to read it */ + errno = ENOENT; + read_size = -1; + } else { + read_size = handle_read(&handle[j], file_pos, buffer[j], state->block_size, log_error, state->opt.expected_missing ? log_expected : 0); + } 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 */ @@ -1214,6 +1220,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } else { ++soft_error; } + + /* if we are reading at the end, mark the file as missing to avoid to try to read it again at the next block */ + if (errno == ENOENT) { + file_flag_set(file, FILE_IS_MISSING); + } continue; } diff --git a/cmdline/handle.c b/cmdline/handle.c index fc6a7bb1..b1a25064 100644 --- a/cmdline/handle.c +++ b/cmdline/handle.c @@ -253,7 +253,11 @@ int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned c if (offset >= handle->valid_size) { /* if the file is missing, it's at 0 size, or it's rebuilt while reading */ if (offset == handle->valid_size || handle->valid_size == 0) { - out_missing("Reading missing file '%s' at offset %" PRIu64 ".\n", handle->path, offset); + if (offset == 0) { + out_missing("Missing file '%s'.\n", handle->path); + } else { + out_missing("Missing data in file '%s' at offset %" PRIu64 ".\n", handle->path, offset); + } errno = ENOENT; } else { out("Reading over the end from file '%s' at offset %" PRIu64 ".\n", handle->path, offset);