Adds a new -l, --log option.

This commit is contained in:
Andrea Mazzoleni 2013-03-01 20:13:56 +01:00
parent 7f8551fccb
commit 0200a2b7fa
19 changed files with 280 additions and 193 deletions

View file

@ -109,7 +109,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file)
return 0;
}
int handle_open(struct snapraid_handle* handle, struct snapraid_file* file)
int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, FILE* stdout)
{
int ret;
@ -131,7 +131,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file)
handle->f = -1;
handle->valid_size = 0;
fprintf(stderr, "Error opening file '%s'. %s.\n", handle->path, strerror(errno));
fprintf(stdout, "Error opening file '%s'. %s.\n", handle->path, strerror(errno));
return -1;
}
@ -141,7 +141,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file)
/* get the stat info */
ret = fstat(handle->f, &handle->st);
if (ret != 0) {
fprintf(stderr, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno));
fprintf(stdout, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno));
return -1;
}
@ -152,7 +152,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file)
/* advise sequential access */
ret = posix_fadvise(handle->f, 0, 0, POSIX_FADV_SEQUENTIAL);
if (ret != 0) {
fprintf(stderr, "Error advising file '%s'. %s.\n", handle->path, strerror(ret));
fprintf(stdout, "Error advising file '%s'. %s.\n", handle->path, strerror(ret));
return -1;
}
#endif
@ -186,7 +186,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)
int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, FILE* stdout)
{
ssize_t read_ret;
data_off_t offset;
@ -197,7 +197,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(stderr, "Reading missing data from file '%s' at offset %"PRIu64".\n", handle->path, offset);
fprintf(stdout, "Reading missing data from file '%s' at offset %"PRIu64".\n", handle->path, offset);
return -1;
}
@ -205,7 +205,7 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un
#if !HAVE_PREAD
if (lseek(handle->f, offset, SEEK_SET) != offset) {
fprintf(stderr, "Error seeking file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno));
fprintf(stdout, "Error seeking file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno));
return -1;
}
#endif
@ -220,11 +220,11 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un
#endif
if (read_ret < 0) {
fprintf(stderr, "Error reading file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno));
fprintf(stdout, "Error reading file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno));
return -1;
}
if (read_ret == 0) {
fprintf(stderr, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno));
fprintf(stdout, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno));
return -1;
}