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

@ -76,8 +76,8 @@ void parity_overflow(struct snapraid_state* state, data_off_t size)
if (file->blockmax > 0) {
if (file->blockvec[0].parity_pos > blockalloc) {
if (state->gui) {
fprintf(stderr, "outofparity:%s:%s\n", disk->name, file->sub);
fflush(stderr);
fprintf(stdlog, "outofparity:%s:%s\n", disk->name, file->sub);
fflush(stdlog);
}
if (first) {
first = 0;
@ -363,7 +363,7 @@ int parity_write(struct snapraid_parity* parity, block_off_t pos, unsigned char*
return 0;
}
int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size)
int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size, FILE* stdout)
{
ssize_t read_ret;
data_off_t offset;
@ -373,13 +373,13 @@ int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char*
/* check if we are going to read only not initialized data */
if (offset >= parity->valid_size) {
fprintf(stderr, "Reading missing data from file '%s' at offset %"PRIu64".\n", parity->path, offset);
fprintf(stdout, "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) {
fprintf(stderr, "Error seeking file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno));
fprintf(stdout, "Error seeking file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno));
return -1;
}
#endif
@ -393,11 +393,11 @@ int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char*
read_ret = read(parity->f, block_buffer + count, block_size - count);
#endif
if (read_ret < 0) {
fprintf(stderr, "Error reading file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno));
fprintf(stdout, "Error reading file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno));
return -1;
}
if (read_ret == 0) {
fprintf(stderr, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno));
fprintf(stdout, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno));
return -1;
}