mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-29 03:16:59 -05:00
More consistent in error reporting for files with garbage at the end.
This commit is contained in:
parent
46fb4a311a
commit
8b3075a023
3 changed files with 21 additions and 13 deletions
21
check.c
21
check.c
|
|
@ -278,7 +278,7 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keep track if at least one hashed block has no parity */
|
/* keep track if at least one hashed block has no parity */
|
||||||
/* if at least one block has no parity, doesn't make sense to check/fix it */
|
/* if at least one block has no parity, doesn't make sense to check/fix the parity */
|
||||||
/* as errors are the normal condition */
|
/* as errors are the normal condition */
|
||||||
if (!block_flag_has(block, BLOCK_HAS_PARITY))
|
if (!block_flag_has(block, BLOCK_HAS_PARITY))
|
||||||
all_parity = 0;
|
all_parity = 0;
|
||||||
|
|
@ -305,11 +305,15 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* notify the warning condition of a file larger than expected */
|
/* check if the file was larger and now truncated */
|
||||||
if (ret > 0) {
|
if (ret == 1) {
|
||||||
error += ret;
|
fprintf(stderr, "File '%s' is larger than expected.\n", handle[j].path);
|
||||||
/* this is always a recovered error */
|
fprintf(stderr, "%u: Size error for file %s\n", i, block_file_get(block)->sub);
|
||||||
recovered_error += ret;
|
++error;
|
||||||
|
|
||||||
|
/* this is already a recovered error */
|
||||||
|
fprintf(stderr, "%u: Fixed size for file %s\n", i, block_file_get(block)->sub);
|
||||||
|
++recovered_error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* if checking, open the file for reading */
|
/* if checking, open the file for reading */
|
||||||
|
|
@ -331,13 +335,12 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
||||||
&& handle[j].st.st_size > block_file_get(block)->size
|
&& handle[j].st.st_size > block_file_get(block)->size
|
||||||
) {
|
) {
|
||||||
fprintf(stderr, "File '%s' is larger than expected.\n", handle[j].path);
|
fprintf(stderr, "File '%s' is larger than expected.\n", handle[j].path);
|
||||||
|
fprintf(stderr, "%u: Size error for file %s\n", i, block_file_get(block)->sub);
|
||||||
|
++error;
|
||||||
|
|
||||||
/* if fragmented, it may be reopened, so store the notification */
|
/* if fragmented, it may be reopened, so store the notification */
|
||||||
/* to prevent to signal and count the error more than one time */
|
/* to prevent to signal and count the error more than one time */
|
||||||
file_flag_set(block_file_get(block), FILE_IS_LARGER);
|
file_flag_set(block_file_get(block), FILE_IS_LARGER);
|
||||||
|
|
||||||
/* this is always a recoverable error */
|
|
||||||
++error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
9
handle.c
9
handle.c
|
|
@ -177,9 +177,8 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* return the warning condition of a larger file */
|
/* return if the file size was truncated */
|
||||||
if (handle->st.st_size > file->size) {
|
if (handle->st.st_size > file->size) {
|
||||||
fprintf(stderr, "File '%s' truncated to size %"PRIu64".\n", handle->path, file->size);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,10 +271,14 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un
|
||||||
|
|
||||||
read_ret = read(handle->f, block_buffer, read_size);
|
read_ret = read(handle->f, block_buffer, read_size);
|
||||||
#endif
|
#endif
|
||||||
if (read_ret != (ssize_t)read_size) { /* conversion is safe because block_size is always small */
|
if (read_ret < 0) {
|
||||||
fprintf(stderr, "Error reading file '%s'. %s.\n", handle->path, strerror(errno));
|
fprintf(stderr, "Error reading file '%s'. %s.\n", handle->path, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (read_ret != (ssize_t)read_size) {
|
||||||
|
fprintf(stderr, "File '%s' is smaller than expected.\n", handle->path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* pad with 0 */
|
/* pad with 0 */
|
||||||
if (read_size < block_size) {
|
if (read_size < block_size) {
|
||||||
|
|
|
||||||
4
handle.h
4
handle.h
|
|
@ -37,7 +37,9 @@ int handle_close_if_different(struct snapraid_handle* handle, struct snapraid_fi
|
||||||
/**
|
/**
|
||||||
* Creates a file.
|
* Creates a file.
|
||||||
* The file is created if missing, and opened with write access.
|
* The file is created if missing, and opened with write access.
|
||||||
* If the file is larger than expected, the value 1 is returned, and the file is truncated to the correct size.
|
* If the file has a different size than expected, it's enlarged or truncated to the correct size.
|
||||||
|
* If the file is truncated 1 is returned.
|
||||||
|
* The initial size of the file is stored in the file->st struct.
|
||||||
* If the file cannot be opened for write access, it's opened with read-only access.
|
* If the file cannot be opened for write access, it's opened with read-only access.
|
||||||
* The read-only access works only if the file has already the correct size and doesn't need to be modified.
|
* The read-only access works only if the file has already the correct size and doesn't need to be modified.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue