From 24fd5ab318c7f1f234ff0497b9541ce9f6dbcfcc Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 3 Feb 2014 22:40:51 +0100 Subject: [PATCH] Excludes handling of error condition from the coverage test. --- TEST | 5 + check.c | 56 ++++++ dry.c | 19 ++- elem.c | 6 + elem.h | 4 + handle.c | 5 +- import.c | 26 +++ list.c | 2 + mktest.c | 50 ++++++ pool.c | 20 +++ rehash.c | 6 + scan.c | 37 +++- scrub.c | 12 ++ selftest.c | 26 +++ snapraid.c | 44 ++++- state.c | 492 +++++++++++++++++++++++++++++++++++++++++++++++++++++ sync.c | 36 ++++ 17 files changed, 841 insertions(+), 5 deletions(-) diff --git a/TEST b/TEST index d0e947a9..3672dbf5 100644 --- a/TEST +++ b/TEST @@ -20,6 +20,11 @@ To run a coverage test you should use: and open the file ./cov/index.html in your browser to see the results. +Please note that in the coverage analysis we exclude the handling of all +the error conditions that result in an immediate termination of the program. +You can recognize this excluded code because it's enclosed between +the LCOV_EXCL_START and LCOV_EXCL_STOP keywords. + To test with the clang static anlayzer use: scan-build ./configure diff --git a/check.c b/check.c index 84868592..ad4d366f 100644 --- a/check.c +++ b/check.c @@ -660,10 +660,12 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* close the old one, if any */ 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"); printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } /* if fixing, and the file is not excluded, we must open for writing */ @@ -671,6 +673,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* if fixing, create the file, open for writing and resize if required */ ret = handle_create(&handle[j], block_file_get(block), state->opt.skip_sequential); if (ret == -1) { + /* LCOV_EXCL_START */ if (errno == EACCES) { fprintf(stderr, "WARNING! Please give write permission to the file.\n"); } else { @@ -679,6 +682,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } /* check if the file was larger and now truncated */ @@ -896,6 +900,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, ret = handle_write(failed[j].handle, failed[j].block, buffer[failed[j].index], state->block_size); if (ret == -1) { + /* LCOV_EXCL_START */ /* mark the file as damaged */ file_flag_set(block_file_get(failed[j].block), FILE_IS_DAMAGED); @@ -908,6 +913,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } /* if we are not sure that the recovered content is uptodate */ @@ -933,11 +939,13 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (buffer_recov[l] == 0 && parity[l] != 0) { ret = parity_write(parity[l], i, buffer[diskmax + l], state->block_size); 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)); 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)); @@ -989,8 +997,10 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* A typical case is if the file is missing, */ /* and the read-only open failed before. */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* if it isn't the last block in the file */ @@ -1020,20 +1030,24 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* ensure to close the file before renaming */ 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"); printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } 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"); printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } fprintf(stdlog, "status:unrecoverable:%s:%s\n", handle[j].disk->name, file->sub); @@ -1078,12 +1092,14 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* set the original modification time */ ret = handle_utime(&handle[j]); if (ret == -1) { + /* 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"); printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } } else { fprintf(stdlog, "collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", handle[j].disk->name, block_file_get(block)->sub, collide_file->sub); @@ -1120,11 +1136,13 @@ close_and_continue: /* ensure to close the file just after finishing with it */ 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"); printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } } @@ -1133,7 +1151,9 @@ close_and_continue: /* progress */ if (state_progress(state, i, countpos, countmax, countsize)) { + /* LCOV_EXCL_START */ break; + /* LCOV_EXCL_STOP */ } } @@ -1194,16 +1214,19 @@ close_and_continue: /* create the ancestor directories */ 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"); printf("Stopping\n"); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } /* create it */ /* O_NOFOLLOW: do not follow links to ensure to open the real file */ 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)); if (errno == EACCES) { fprintf(stderr, "WARNING! Please give write permission to the file.\n"); @@ -1214,26 +1237,31 @@ close_and_continue: printf("Stopping\n"); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } /* set the original modification time */ ret = file_utime(file, f); if (ret != 0) { + /* LCOV_EXCL_START */ close(f); fprintf(stderr, "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 */ } /* close it */ 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"); printf("Stopping\n"); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } fprintf(stdlog, "fixed:%s:%s: Fixed empty file\n", disk->name, file->sub); @@ -1351,26 +1379,31 @@ close_and_continue: /* create the ancestor directories */ 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"); printf("Stopping\n"); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } /* if it exists, it must be deleted before recreating */ 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"); printf("Stopping\n"); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } /* create it */ if (link_flag_has(link, FILE_IS_HARDLINK)) { ret = hardlink(pathto, path); if (ret != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "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"); @@ -1381,6 +1414,7 @@ close_and_continue: printf("Stopping\n"); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } fprintf(stdlog, "hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, link->sub); @@ -1388,6 +1422,7 @@ close_and_continue: } 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)); if (errno == EACCES) { fprintf(stderr, "WARNING! Please give write permission to the symlink.\n"); @@ -1398,6 +1433,7 @@ close_and_continue: printf("Stopping\n"); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } fprintf(stdlog, "symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, link->sub); @@ -1448,15 +1484,18 @@ close_and_continue: /* create the ancestor directories */ 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"); printf("Stopping\n"); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } /* create it */ 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)); if (errno == EACCES) { fprintf(stderr, "WARNING! Please give write permission to the dir.\n"); @@ -1467,6 +1506,7 @@ close_and_continue: printf("Stopping\n"); ++unrecoverable_error; goto bail; + /* LCOV_EXCL_STOP */ } fprintf(stdlog, "dir_fixed:%s:%s: Fixed dir error\n", disk->name, dir->sub); @@ -1487,9 +1527,11 @@ bail: for(j=0;jblock_size; 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* adjust the number of block to process */ @@ -1660,14 +1708,18 @@ int state_check(struct snapraid_state* state, int check, int fix, block_off_t bl parity_ptr[l] = &parity[l]; ret = parity_create(parity_ptr[l], state->parity_path[l], &out_size, state->opt.skip_sequential); 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } else if (check) { @@ -1701,8 +1753,10 @@ int state_check(struct snapraid_state* state, int check, int fix, block_off_t bl if (blockstart < blockmax) { ret = state_check_process(state, check, fix, parity_ptr, blockstart, blockmax); if (ret == -1) { + /* LCOV_EXCL_START */ ++error; /* continue, as we are already exiting */ + /* LCOV_EXCL_STOP */ } } @@ -1710,11 +1764,13 @@ int state_check(struct snapraid_state* state, int check, int fix, block_off_t bl for(l=0;llevel;++l) { if (parity_ptr[l]) { 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)); ++error; /* continue, as we are already exiting */ } + /* LCOV_EXCL_STOP */ } } diff --git a/dry.c b/dry.c index 9746c975..6c7dadc5 100644 --- a/dry.c +++ b/dry.c @@ -71,19 +71,23 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit /* close the old one, if any */ 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"); printf("Stopping at block %u\n", i); ++error; goto bail; + /* LCOV_EXCL_STOP */ } /* open the file only for reading */ ret = handle_open(&handle[j], block_file_get(block), state->opt.skip_sequential, stdlog); if (ret == -1) { + /* LCOV_EXCL_START */ fprintf(stderr, "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; + /* LCOV_EXCL_STOP */ } } @@ -114,7 +118,9 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit /* progress */ if (state_progress(state, i, countpos, countmax, countsize)) { + /* LCOV_EXCL_START */ break; + /* LCOV_EXCL_STOP */ } } @@ -125,9 +131,11 @@ bail: for(j=0;j blockmax) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* adjust the number of block to process */ @@ -186,8 +196,10 @@ void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t if (blockstart < blockmax) { ret = state_dry_process(state, parity_ptr, blockstart, blockmax); if (ret == -1) { + /* LCOV_EXCL_START */ ++error; /* continue, as we are already exiting */ + /* LCOV_EXCL_STOP */ } } @@ -196,14 +208,19 @@ void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t if (parity_ptr[l]) { ret = parity_close(parity_ptr[l]); if (ret == -1) { + /* LCOV_EXCL_START */ ++error; /* continue, as we are already exiting */ + /* LCOV_EXCL_STOP */ } } } /* abort if required */ - if (error != 0) + if (error != 0) { + /* LCOV_EXCL_START */ exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } } diff --git a/elem.c b/elem.c index 90086965..46152faa 100644 --- a/elem.c +++ b/elem.c @@ -244,8 +244,10 @@ int filter_existence(int filter_missing, const char* dir, const char* sub) /* if the file doesn't exist, we don't filter it out */ if (errno == ENOENT) return 0; + /* LCOV_EXCL_START */ fprintf(stderr, "Error in stat file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* the file is present, so we filter it out */ @@ -302,8 +304,10 @@ block_off_t block_file_pos(struct snapraid_block* block) struct snapraid_file* file = block_file_get(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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } return block - file->blockvec; @@ -599,8 +603,10 @@ int disk_is_empty(struct snapraid_disk* disk, block_off_t blockmax) /* if there is a deleted block, the disk is not empty */ return 0; default: + /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency for used block in disk '%s' without files\n", disk->name); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } diff --git a/elem.h b/elem.h index 4c023a12..f8f468fd 100644 --- a/elem.h +++ b/elem.h @@ -440,8 +440,10 @@ static inline void block_file_set(struct snapraid_block* block, struct snapraid_ /* ensure that the pointer doesn't use the flag space */ if ((ptr & (uintptr_t)BLOCK_STATE_MASK) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Internal error for pointer not aligned\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } block->file_mixed = (block->file_mixed & ~(uintptr_t)BLOCK_STATE_MASK) | ptr; @@ -465,8 +467,10 @@ static inline void block_state_set(struct snapraid_block* block, unsigned state) { /* ensure that the state can be stored inside the file pointer */ if ((state & BLOCK_STATE_MASK) != state) { + /* LCOV_EXCL_START */ fprintf(stderr, "Internal error when setting the block state %u\n", state); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } block->file_mixed &= ~(uintptr_t)BLOCK_STATE_MASK; diff --git a/handle.c b/handle.c index e3de6bc6..19f6c7b1 100644 --- a/handle.c +++ b/handle.c @@ -428,9 +428,10 @@ struct snapraid_handle* handle_map(struct snapraid_state* state, unsigned* handl break; } if (k==0) { - fprintf(stderr, "Inconsistent disk mapping.\n"); + /* LCOV_EXCL_START */ + fprintf(stderr, "Internal error for inconsistent disk mapping.\n"); exit(EXIT_FAILURE); - continue; + /* LCOV_EXCL_STOP */ } handle[map->position].disk = disk; diff --git a/import.c b/import.c index 03ca4caf..a3d4ffbe 100644 --- a/import.c +++ b/import.c @@ -74,8 +74,10 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t flags |= O_SEQUENTIAL; f = open(path, flags); if (f == -1) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error opening file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } #if HAVE_POSIX_FADVISE @@ -83,8 +85,10 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t /* advise sequential access */ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } #endif @@ -98,8 +102,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } block->file = file; @@ -122,8 +128,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } tommy_list_insert_tail(&state->importlist, &file->nodelist, file); @@ -161,25 +169,33 @@ int state_import_fetch(struct snapraid_state* state, int rehash, const unsigned f = open(path, O_RDONLY | O_BINARY); if (f == -1) { + /* LCOV_EXCL_START */ fprintf(stderr, "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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = close(f); if (ret != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (read_size != block_size) { @@ -194,9 +210,11 @@ int state_import_fetch(struct snapraid_state* state, int rehash, const unsigned memhash(state->hash, state->hashseed, buffer_hash, buffer, read_size); 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } return 0; @@ -208,8 +226,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } while (1) { @@ -222,8 +242,10 @@ static void import_dir(struct snapraid_state* state, const char* dir) errno = 0; dd = readdir(d); if (dd == 0 && errno != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error reading directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (dd == 0) { break; /* finished */ @@ -244,8 +266,10 @@ static void import_dir(struct snapraid_state* state, const char* dir) #else /* get lstat info about the file */ if (lstat(path, &st) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error in stat file/directory '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } #endif @@ -257,8 +281,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } diff --git a/list.c b/list.c index 26815da2..2c97af0c 100644 --- a/list.c +++ b/list.c @@ -92,7 +92,9 @@ void state_list(struct snapraid_state* state) case FILE_IS_SYMLINK : type = "symlink"; break; case FILE_IS_SYMDIR : type = "symdir"; break; case FILE_IS_JUNCTION : type = "junction"; break; + /* LCOV_EXCL_START */ default: type = "unknown"; break; + /* LCOV_EXCL_STOP */ } ++link_count; diff --git a/mktest.c b/mktest.c index 8bb766c8..52ff7d12 100644 --- a/mktest.c +++ b/mktest.c @@ -58,8 +58,10 @@ void create_file(const char* path, int size) /* remove the existing file if any */ if (remove(path) != 0) { if (errno != ENOENT) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error removing file %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else { /* don't recreate a 0 file to avoid ZERO protection */ @@ -68,8 +70,10 @@ void create_file(const char* path, int size) f = fopen(path, "wb"); if (!f) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing file %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } count = size; @@ -92,14 +96,18 @@ void create_symlink(const char* path, const char* linkto) /* remove the existing file if any */ if (remove(path) != 0) { if (errno != ENOENT) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error removing file %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } if (symlink(linkto, path) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing symlink %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -118,8 +126,10 @@ void generate(int disk, int size) /* create it */ if (mkdir(path, 0777) != 0) { if (errno != EEXIST) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error creating directory %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -205,8 +215,10 @@ void fallback(int f, struct stat* st) #error No function available to set file timestamps #endif if (ret != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error restoring time\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -232,8 +244,10 @@ void writ(const char* path, int size, int silent_error) if (lstat(path, &st) != 0) { if (errno == ENOENT) return; /* it may be already deleted */ + /* LCOV_EXCL_START */ fprintf(stderr, "Error accessing %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (S_ISREG(st.st_mode)) { @@ -244,8 +258,10 @@ void writ(const char* path, int size, int silent_error) f = fopen(path, "r+b"); if (!f) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* start at random position inside the file */ @@ -254,8 +270,10 @@ void writ(const char* path, int size, int silent_error) else start = 0; if (fseek(f, start, SEEK_SET) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error seeking %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* write garbage, in case also over the end */ @@ -286,8 +304,10 @@ void append(const char* path, int size) if (lstat(path, &st) != 0) { if (errno == ENOENT) return; /* it may be already deleted */ + /* LCOV_EXCL_START */ fprintf(stderr, "Error accessing %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (S_ISREG(st.st_mode)) { @@ -296,8 +316,10 @@ void append(const char* path, int size) f = fopen(path, "ab"); if (!f) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error appending %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* write garbage, in case also over the end */ @@ -321,8 +343,10 @@ void truncat(const char* path, int size) if (lstat(path, &st) != 0) { if (errno == ENOENT) return; /* it may be already deleted */ + /* LCOV_EXCL_START */ fprintf(stderr, "Error accessing %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (S_ISREG(st.st_mode)) { @@ -332,8 +356,10 @@ void truncat(const char* path, int size) f = fopen(path, "r+b"); if (!f) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* truncate at random position inside the file */ @@ -347,8 +373,10 @@ void truncat(const char* path, int size) start = 1; if (ftruncate(fileno(f), start) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error truncating %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } fclose(f); @@ -365,8 +393,10 @@ void change(const char* path, int size) if (lstat(path, &st) != 0) { if (errno == ENOENT) return; /* it may be already deleted */ + /* LCOV_EXCL_START */ fprintf(stderr, "Error accessing %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (S_ISLNK(st.st_mode)) { @@ -374,16 +404,20 @@ void change(const char* path, int size) if (rnd(2) == 0) { /* delete */ if (remove(path) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error removing %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else { /* recreate */ char linkto[PATH_MAX]; if (remove(path) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error removing %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } rnd_name(linkto); @@ -407,8 +441,10 @@ void change(const char* path, int size) } else { /* delete */ if (remove(path) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error removing %s\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -436,16 +472,20 @@ int main(int argc, char* argv[]) int i, j, b; if (argc < 2) { + /* LCOV_EXCL_START */ help(); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (strcmp(argv[1], "generate") == 0) { int disk, file, size; if (argc != 6) { + /* LCOV_EXCL_START */ help(); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } seed = atoi(argv[2]); @@ -468,8 +508,10 @@ int main(int argc, char* argv[]) int silent_error = strcmp(argv[1], "damage") == 0; if (argc < 6) { + /* LCOV_EXCL_START */ help(); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } seed = atoi(argv[2]); @@ -489,8 +531,10 @@ int main(int argc, char* argv[]) int size; if (argc < 5) { + /* LCOV_EXCL_START */ help(); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } seed = atoi(argv[2]); @@ -507,8 +551,10 @@ int main(int argc, char* argv[]) int size; if (argc < 5) { + /* LCOV_EXCL_START */ help(); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } seed = atoi(argv[2]); @@ -525,8 +571,10 @@ int main(int argc, char* argv[]) int size; if (argc < 5) { + /* LCOV_EXCL_START */ help(); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } seed = atoi(argv[2]); @@ -540,8 +588,10 @@ int main(int argc, char* argv[]) change(argv[i], rnd(size)); } } else { + /* LCOV_EXCL_START */ help(); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } return 0; diff --git a/pool.c b/pool.c index b86c3118..c697c489 100644 --- a/pool.c +++ b/pool.c @@ -32,8 +32,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } while (1) { @@ -46,8 +48,10 @@ static int clean_dir(struct snapraid_state* state, const char* dir) errno = 0; dd = readdir(d); if (dd == 0 && errno != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error reading pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (dd == 0 && errno == 0) { break; /* finished */ @@ -66,8 +70,10 @@ static int clean_dir(struct snapraid_state* state, const char* dir) #else /* 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } #endif @@ -77,8 +83,10 @@ static int clean_dir(struct snapraid_state* state, const char* dir) /* delete the link */ ret = remove(path_next); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error removing symlink '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else if (S_ISDIR(st.st_mode)) { /* recurse */ @@ -99,8 +107,10 @@ static int clean_dir(struct snapraid_state* state, const char* dir) } else #endif { + /* LCOV_EXCL_START */ fprintf(stderr, "Error removing pool directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } else { @@ -116,8 +126,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } return ignored; @@ -148,7 +160,9 @@ static void make_link(const char* pool_dir, const char* share_dir, struct snapra /* create the ancestor directories */ ret = mkancestor(path); if (ret != 0) { + /* LCOV_EXCL_START */ exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* convert back slashes */ @@ -161,12 +175,16 @@ static void make_link(const char* pool_dir, const char* share_dir, struct snapra fprintf(stderr, "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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ #endif } else { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing symlink '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -179,8 +197,10 @@ void state_pool(struct snapraid_state* state) unsigned count; 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } printf("Cleaning...\n"); diff --git a/rehash.c b/rehash.c index 199d19cc..96b335f1 100644 --- a/rehash.c +++ b/rehash.c @@ -37,13 +37,17 @@ 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"); 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* copy the present hash as previous one */ @@ -66,8 +70,10 @@ 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* enable the rehash */ diff --git a/scan.c b/scan.c index 0b1f0129..39ee278e 100644 --- a/scan.c +++ b/scan.c @@ -81,8 +81,10 @@ static void scan_link(struct snapraid_scan* scan, struct snapraid_state* state, if (link) { /* 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* mark as present */ @@ -195,8 +197,10 @@ static void scan_file_deallocate(struct snapraid_state* state, struct snapraid_d hash_invalid_set(deleted->block.hash); break; default: + /* LCOV_EXCL_START */ fprintf(stderr, "Internal state inconsistency in scanning for block %u state %u\n", block->parity_pos, block_state); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* insert it in the list of deleted blocks */ @@ -430,8 +434,10 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, scan_link(scan, state, output, disk, sub, file->sub, FILE_IS_HARDLINK); return; } else { + /* LCOV_EXCL_START */ fprintf(stderr, "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 */ } } @@ -492,8 +498,10 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, /* 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* assume a previously used inode, it's the worst case */ @@ -532,16 +540,19 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, } else { /* 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 inode '%"PRIu64"' inconsistency for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub); - exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } /* for sure it cannot be already present */ if (file_flag_has(file, FILE_IS_PRESENT)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Internal path inconsistency for file '%s%s' matching and already present\n", disk->dir, sub); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* check if the file is not changed */ @@ -617,11 +628,13 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, /* the size of a file after a crash doesn't propagate to the backup */ if (file->size != 0 && st->st_size == 0) { if (!state->opt.force_zero) { + /* LCOV_EXCL_START */ fprintf(stderr, "The file '%s%s' has unexpected zero size! If this an expected state\n", disk->dir, sub); fprintf(stderr, "you can '%s' anyway usinge 'snapraid --force-zero %s'\n", state->command, state->command); fprintf(stderr, "Instead, 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -707,8 +720,10 @@ static void scan_emptydir(struct snapraid_scan* scan, struct snapraid_disk* disk if (dir) { /* 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* mark as present */ @@ -775,8 +790,10 @@ struct stat* dstat(struct dirent_sorted* dd) 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } return st; } @@ -797,9 +814,11 @@ static int scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, in 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* read the full directory */ @@ -815,9 +834,11 @@ static int scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, in errno = 0; 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (dd == 0) { break; /* finished */ @@ -833,8 +854,10 @@ static int scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, in /* 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* exclude hidden files even before calling lstat() */ @@ -874,8 +897,10 @@ static int scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, in } if (closedir(d) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error closing directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } #if HAVE_STRUCT_DIRENT_D_INO @@ -943,14 +968,18 @@ static int scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, in /* get inode info about the file, Windows needs an additional step */ /* also for hardlink, the real size of the file is read here */ if (lstat_ex(path_next, st) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error in stat_inode file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } #endif if (state->opt.force_order == SORT_PHYSICAL) { if (filephy(path_next, st, &physical) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error in getting the physical offset of file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else { physical = 0; @@ -970,12 +999,16 @@ static int scan_dir(struct snapraid_scan* scan, struct snapraid_state* state, in 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); 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* readlink doesn't put the final 0 */ @@ -1084,8 +1117,10 @@ void state_scan(struct snapraid_state* state, int output) /* check if the disk supports persistent inodes */ ret = fsinfo(disk->dir, &has_persistent_inode); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!has_persistent_inode) { disk->has_volatile_inodes = 1; diff --git a/scrub.c b/scrub.c index 1cfe2e74..19c5b2b3 100644 --- a/scrub.c +++ b/scrub.c @@ -232,6 +232,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par struct snapraid_file* file = handle[j].file; ret = handle_close(&handle[j]); if (ret == -1) { + /* LCOV_EXCL_START */ /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", i, handle[j].disk->name, file->sub, strerror(errno)); @@ -239,6 +240,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par printf("Stopping at block %u\n", i); ++error; goto bail; + /* LCOV_EXCL_STOP */ } } @@ -384,7 +386,9 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* progress */ if (state_progress(state, i, countpos, countmax, countsize)) { + /* LCOV_EXCL_START */ break; + /* LCOV_EXCL_STOP */ } /* autosave */ @@ -428,9 +432,11 @@ bail: for(j=0;jparity_path[l], state->opt.skip_sequential); if (ret == -1) { + /* LCOV_EXCL_START */ fprintf(stderr, "WARNING! Without an accessible %s file, it isn't possible to scrub.\n", lev_name(l)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -565,9 +575,11 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) for(l=0;llevel;++l) { 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)); ++error; /* continue, as we are already exiting */ + /* LCOV_EXCL_STOP */ } } diff --git a/selftest.c b/selftest.c index fb3a497e..7c08d8ac 100644 --- a/selftest.c +++ b/selftest.c @@ -84,8 +84,10 @@ static void test_hash(void) memcpy(buffer_aligned, TEST_MURMUR3[i].data, TEST_MURMUR3[i].len); 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -94,8 +96,10 @@ static void test_hash(void) memcpy(buffer_aligned, TEST_SPOOKY2[i].data, TEST_SPOOKY2[i].len); 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -141,8 +145,10 @@ static void test_crc32c(void) uint32_t digest; 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -156,47 +162,67 @@ void selftest(void) /* large file check */ if (sizeof(off_t) < sizeof(uint64_t)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Missing support for large files\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } test_hash(); test_crc32c(); if (raid_selftest() != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Failed SELF test\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (raid_test_sort() != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Failed SORT test\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (raid_test_insert() != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Failed INSERT test\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (raid_test_combo() != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "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"); 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"); 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"); 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"); 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } diff --git a/snapraid.c b/snapraid.c index ab5c44b3..8dbba314 100644 --- a/snapraid.c +++ b/snapraid.c @@ -197,6 +197,7 @@ struct option long_options[] = { volatile int global_interrupt = 0; +/* LCOV_EXCL_START */ void signal_handler(int signal) { switch (signal) { @@ -205,6 +206,7 @@ void signal_handler(int signal) break; } } +/* LCOV_EXCL_STOP */ #define OPERATION_DIFF 0 #define OPERATION_SYNC 1 @@ -281,16 +283,20 @@ int main(int argc, char* argv[]) case 'f' : { struct snapraid_filter* filter = filter_alloc_file(1, optarg); if (!filter) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid filter specification '%s'\n", optarg); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } tommy_list_insert_tail(&filterlist_file, &filter->node, filter); } break; case 'd' : { struct snapraid_filter* filter = filter_alloc_disk(1, optarg); if (!filter) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid filter specification '%s'\n", optarg); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } tommy_list_insert_tail(&filterlist_disk, &filter->node, filter); } break; @@ -303,42 +309,54 @@ int main(int argc, char* argv[]) case 'p' : percentage = strtoul(optarg, &e, 10); if (!e || *e || percentage > 100) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid percentage '%s'\n", optarg); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } break; case 'o' : olderthan = strtoul(optarg, &e, 10); if (!e || *e || olderthan > 1000) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid number of days '%s'\n", optarg); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } break; case 's' : blockstart = strtoul(optarg, &e, 0); if (!e || *e) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid start position '%s'\n", optarg); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } break; case 't' : blockcount = strtoul(optarg, &e, 0); if (!e || *e) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid count number '%s'\n", optarg); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } break; case 'i' : if (import) { + /* LCOV_EXCL_START */ fprintf(stderr, "Import directory '%s' already specified as '%s'\n", optarg, import); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } import = optarg; break; case 'l' : if (log) { + /* LCOV_EXCL_START */ fprintf(stderr, "Log file '%s' already specified as '%s'\n", optarg, log); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } log = optarg; break; @@ -443,8 +461,10 @@ int main(int argc, char* argv[]) opt.rawsync = 1; break; default: + /* LCOV_EXCL_START */ fprintf(stderr, "Unknown option '%c'\n", (char)c); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -485,8 +505,10 @@ int main(int argc, char* argv[]) } else if (strcmp(argv[optind], "test-rewrite") == 0) { operation = OPERATION_REWRITE; } else { + /* LCOV_EXCL_START */ fprintf(stderr, "Unknown command '%s'\n", argv[optind]); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* check options compatibility */ @@ -495,8 +517,10 @@ int main(int argc, char* argv[]) break; default: if (audit_only) { + /* LCOV_EXCL_START */ fprintf(stderr, "You cannot use -A, --audit-only with the '%s' command\n", command); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -507,16 +531,22 @@ int main(int argc, char* argv[]) break; default: if (!tommy_list_empty(&filterlist_file)) { + /* LCOV_EXCL_START */ fprintf(stderr, "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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -526,8 +556,10 @@ int main(int argc, char* argv[]) break; default: if (filter_error != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "You cannot use -e, --filter-error with the '%s' command\n", command); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -537,8 +569,10 @@ int main(int argc, char* argv[]) break; default: if (import != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "You cannot import with the '%s' command\n", command); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -557,8 +591,10 @@ int main(int argc, char* argv[]) } else { stdlog = fopen(log, "wt"); if (!stdlog) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error opening the log file '%s'. %s.\n", log, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -578,6 +614,7 @@ int main(int argc, char* argv[]) if (!opt.skip_lock) { lock = lock_lock(state.lockfile); if (lock == -1) { + /* LCOV_EXCL_START */ if (errno != EWOULDBLOCK) { fprintf(stderr, "Error creating the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); } else { @@ -585,6 +622,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "SnapRAID is already in use!\n"); } exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } #else @@ -648,7 +686,7 @@ int main(int argc, char* argv[]) state_write(&state); /* abort if required */ - if (ret == -1) + if (ret != 0) exit(EXIT_FAILURE); } else if (operation == OPERATION_DRY) { state_read(&state); @@ -742,16 +780,20 @@ int main(int argc, char* argv[]) /* close log file */ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } #if HAVE_LOCKFILE 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } #endif diff --git a/state.c b/state.c index 342e720d..534419e9 100644 --- a/state.c +++ b/state.c @@ -126,21 +126,27 @@ static void state_config_check(struct snapraid_state* state, const char* path, t /* check for parity level */ 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STIO */ } } for(l=0;llevel;++l) { if (state->parity_path[l][0] == 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "No '%s' specification in '%s'\n", lev_config_name(l), path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } if (tommy_list_empty(&state->contentlist)) { + /* LCOV_EXCL_START */ fprintf(stderr, "No 'content' specification in '%s'\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* checks for equal paths */ @@ -149,8 +155,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for(l=0;llevel;++l) { if (pathcmp(state->parity_path[l], content->content) == 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Same path used for '%s' and 'content' as '%s'\n", lev_config_name(l), content->content); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -163,11 +171,13 @@ 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } #endif @@ -175,6 +185,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for(j=i->next;j!=0;j=j->next) { 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); #ifdef _WIN32 fprintf(stderr, "Both have the serial number '%"PRIx64"'.\n", disk->device); @@ -184,46 +195,55 @@ static void state_config_check(struct snapraid_state* state, const char* path, t fprintf(stderr, "You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); } exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } for(l=0;llevel;++l) { if (disk->device == state->parity_device[l]) { + /* LCOV_EXCL_START */ fprintf(stderr, "Disk '%s' and %s '%s' are on the same device.\n", disk->dir, lev_name(l), state->parity_path[l]); #ifdef _WIN32 fprintf(stderr, "Both have the serial number '%"PRIx64"'.\n", disk->device); #endif exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } 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); #ifdef _WIN32 fprintf(stderr, "Both have the serial number '%"PRIx64"'.\n", disk->device); #endif exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } #ifdef _WIN32 for(l=0;llevel;++l) { if (state->parity_device[l] == 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Disk '%s' has a zero serial number.\n", state->parity_path[l]); 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } #endif @@ -231,22 +251,26 @@ static void state_config_check(struct snapraid_state* state, const char* path, t unsigned j; for(j=l+1;jlevel;++j) { if (state->parity_device[l] == state->parity_device[j]) { + /* LCOV_EXCL_START */ fprintf(stderr, "Parity '%s' and '%s' are on the same device.\n", state->parity_path[l], state->parity_path[j]); #ifdef _WIN32 fprintf(stderr, "Both have the serial number '%"PRIx64"'.\n", state->parity_device[l]); #endif exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } for(l=0;llevel;++l) { if (state->pool[0] != 0 && state->pool_device == state->parity_device[l]) { + /* LCOV_EXCL_START */ fprintf(stderr, "Pool '%s' and parity '%s' are on the same device.\n", state->pool, state->parity_path[l]); #ifdef _WIN32 fprintf(stderr, "Both have the serial number '%"PRIx64"'.\n", state->pool_device); #endif exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -276,8 +300,10 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -305,8 +331,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t break; } if (j == 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Option -d, --filter-disk %s doesn't match any disk.\n", filter->pattern); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -335,6 +363,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co f = sopen_read(path); if (!f) { + /* LCOV_EXCL_START */ if (errno == ENOENT) { fprintf(stderr, "No configuration file found at '%s'\n", path); } else if (errno == EACCES) { @@ -343,6 +372,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co fprintf(stderr, "Error opening the configuration file '%s'. %s.\n", path, strerror(errno)); } exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } line = 1; @@ -358,8 +388,10 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* read the command */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* skip spaces after the command */ @@ -368,21 +400,29 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (strcmp(tag, "block_size") == 0) { ret = sgetu32(f, &state->block_size); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'block_size' 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 'block_size' 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 'block_size' 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 'block_size' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } state->block_size *= 1024; } else if (strcmp(tag, "parity") == 0 @@ -416,24 +456,32 @@ void state_config(struct snapraid_state* state, const char* path, const char* co state->raid_mode = RAID_MODE_VANDERMONDE; break; default: + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (*state->parity_path[l]) { + /* LCOV_EXCL_START */ fprintf(stderr, "Multiple '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } pathimport(state->parity_path[l], sizeof(state->parity_path[l]), buffer); @@ -446,8 +494,10 @@ void state_config(struct snapraid_state* state, const char* path, const char* co else 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } state->parity_device[l] = st.st_dev; @@ -463,19 +513,25 @@ void state_config(struct snapraid_state* state, const char* path, const char* co state->level = l + 1; } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*buffer) { + /* LCOV_EXCL_START */ fprintf(stderr, "Empty 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } pathimport(state->share, sizeof(state->share), buffer); @@ -483,27 +539,35 @@ void state_config(struct snapraid_state* state, const char* path, const char* co struct stat st; if (*state->pool) { + /* LCOV_EXCL_START */ fprintf(stderr, "Multiple 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*buffer) { + /* LCOV_EXCL_START */ fprintf(stderr, "Empty 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } pathimport(state->pool, sizeof(state->pool), buffer); /* 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } state->pool_device = st.st_dev; @@ -515,18 +579,24 @@ 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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*buffer) { + /* LCOV_EXCL_START */ fprintf(stderr, "Empty 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* get the device of the directory containing the content file */ @@ -537,8 +607,10 @@ void state_config(struct snapraid_state* state, const char* path, const char* co else 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } content = content_alloc(buffer, st.st_dev); @@ -552,33 +624,43 @@ 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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } sgetspace(f); 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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* get the device of the dir */ pathimport(device, sizeof(device), dir); if (stat(device, &st) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error accessing 'disk' '%s' specification in '%s' at line %u\n", dir, device, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* check if the disk name already exists */ @@ -588,8 +670,10 @@ void state_config(struct snapraid_state* state, const char* path, const char* co break; } if (i) { + /* LCOV_EXCL_START */ fprintf(stderr, "Duplicate disk name '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } disk = disk_alloc(buffer, dir, st.st_dev); @@ -604,19 +688,25 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*buffer) { + /* LCOV_EXCL_START */ fprintf(stderr, "Empty 'exclude' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } tommy_list_insert_tail(&state->filterlist, &filter->node, filter); } else if (strcmp(tag, "include") == 0) { @@ -624,19 +714,25 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*buffer) { + /* LCOV_EXCL_START */ fprintf(stderr, "Empty 'include' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } tommy_list_insert_tail(&state->filterlist, &filter->node, filter); } else if (strcmp(tag, "autosave") == 0) { @@ -644,20 +740,26 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*buffer) { + /* LCOV_EXCL_START */ fprintf(stderr, "Empty 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } state->autosave = strtoul(buffer, &e, 0); if (!e || *e) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* convert to GiB */ @@ -667,12 +769,16 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } else if (tag[0] == '#') { ret = sgetline(f, buffer, sizeof(buffer)); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* skip final spaces */ @@ -684,15 +790,19 @@ void state_config(struct snapraid_state* state, const char* path, const char* co break; } if (c != '\n') { + /* LCOV_EXCL_START */ fprintf(stderr, "Extra data in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ++line; } if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error reading the configuration file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } sclose(f); @@ -845,8 +955,10 @@ static void state_map(struct snapraid_state* state) } if (j==0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency for mapping '%s'\n", map->name); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = devuuid(disk->device, uuid, sizeof(uuid)); @@ -879,12 +991,14 @@ 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* count the number of data disks, including holes left after removing some */ @@ -896,8 +1010,10 @@ static void state_map(struct snapraid_state* state) diskcount = map->position + 1; } if (diskcount > RAID_DATA_MAX) { + /* LCOV_EXCL_START */ fprintf(stderr, "Too many data disks. No more than %u.\n", RAID_DATA_MAX); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* recommend number of parities */ @@ -928,12 +1044,16 @@ static void state_content_check(struct snapraid_state* state, const char* path) for(j=i->next;j!=0;j=j->next) { 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (map->position == other->position) { + /* LCOV_EXCL_START */ fprintf(stderr, "Colliding 'map' index specification in '%s'\n", path); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -1080,8 +1200,10 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* read the command */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* skip only one space if present */ @@ -1098,26 +1220,34 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE struct snapraid_block* block; if (!file) { + /* LCOV_EXCL_START */ fprintf(stderr, "Unexpected '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } block = &file->blockvec[blockidx]; 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* set the parity only if present */ @@ -1151,14 +1281,18 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (tag[0] != 'n') { c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else { /* set the ZERO hash for deprecated NEW blocks */ @@ -1176,8 +1310,10 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* insert the block in the block array */ @@ -1203,25 +1339,33 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (v_pos >= blockmax) { + /* LCOV_EXCL_START */ fprintf(stderr, "Internal position inconsistency in 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetu32(f, &t); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* read extra tags if present */ @@ -1231,8 +1375,10 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE while (c == ' ') { 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (strcmp(buffer, "bad") == 0) { @@ -1241,12 +1387,16 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE rehash = 1; if (state->prevhash == HASH_UNDEFINED) { + /* LCOV_EXCL_START */ fprintf(stderr, "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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); @@ -1263,8 +1413,10 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE struct snapraid_deleted* deleted; if (!disk) { + /* LCOV_EXCL_START */ fprintf(stderr, "Unexpected 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* allocate a new deleted block */ @@ -1275,8 +1427,10 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } deleted->block.parity_pos = v_pos; @@ -1284,15 +1438,19 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* read the hash */ c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* set the hash only if present */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* if we are clearing undeterminated hashes */ @@ -1303,8 +1461,10 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* insert the block in the block array */ @@ -1319,46 +1479,60 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE uint64_t v_inode; if (file) { + /* LCOV_EXCL_START */ fprintf(stderr, "Missing 'blk' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetu64(f, &v_size); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c == '.') { /* the nanosecond field is present only from version 1.14 */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); @@ -1368,38 +1542,50 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetu64(f, &v_inode); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*sub) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* find the disk */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* allocate the file */ @@ -1425,21 +1611,27 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* hole */ if (file) { + /* LCOV_EXCL_START */ fprintf(stderr, "Missing 'blk' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* find the disk */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else if (strcmp(tag, "symlink") == 0) { /* symlink */ @@ -1450,61 +1642,81 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgeteol(f); if (c != '\n') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ++line; 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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* find the disk */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* allocate the link as symbolic link */ @@ -1525,61 +1737,81 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgeteol(f); if (c != '\n') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ++line; 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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* find the disk */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* allocate the link as hard link */ @@ -1598,32 +1830,42 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*sub) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* find the disk */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* allocate the dir */ @@ -1639,8 +1881,10 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (strcmp(buffer, "murmur3") == 0) { @@ -1648,8 +1892,10 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE } else if (strcmp(buffer, "spooky2") == 0) { state->hash = HASH_SPOOKY2; } else { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'checksum' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); @@ -1657,8 +1903,10 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* read the seed if present */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else { sungetc(c, f); @@ -1668,8 +1916,10 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (strcmp(buffer, "murmur3") == 0) { @@ -1677,29 +1927,37 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE } else if (strcmp(buffer, "spooky2") == 0) { state->prevhash = HASH_SPOOKY2; } else { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* read the seed */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else if (strcmp(tag, "blksize") == 0) { block_off_t blksize; ret = sgetu32(f, &blksize); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'blksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* without configuration, auto assign the block size */ @@ -1708,9 +1966,11 @@ 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 'block_size' specification in '%s' at line %u\n", path, line); fprintf(stderr, "Please restore the 'block_size' value in the configuration file to '%u'\n", blksize / 1024); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else if (strcmp(tag, "map") == 0) { struct snapraid_map* map; @@ -1719,20 +1979,26 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); if (c != ' ') { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetu32(f, &v_pos); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } c = sgetc(f); @@ -1743,8 +2009,10 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* read the uuid */ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -1756,8 +2024,10 @@ 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* sign check not supported anymore for the text content file */ @@ -1767,12 +2037,16 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE } else if (tag[0] == '#') { ret = sgetline(f, buffer, sizeof(buffer)); if (ret < 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* next line */ @@ -1781,26 +2055,34 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE break; } if (c != '\n') { + /* LCOV_EXCL_START */ fprintf(stderr, "Extra data in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ++line; } if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* check that the stored parity size matches the loaded state */ if (blockmax != parity_size(state)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency in parity size in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* to be backward compatible with old context files without info */ @@ -1880,8 +2162,10 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputu32(state->block_size, f); sputeol(f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (state->hash == HASH_MURMUR3) { @@ -1889,15 +2173,19 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) } else if (state->hash == HASH_SPOOKY2) { sputsl("checksum spooky2", f); } else { + /* LCOV_EXCL_START */ fprintf(stderr, "Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } sputc(' ', f); sputhex(state->hashseed, HASH_SIZE, f); sputeol(f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* previous hash only present */ @@ -1909,15 +2197,19 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) } else if (state->prevhash == HASH_SPOOKY2) { sputsl("prevchecksum spooky2", f); } else { + /* LCOV_EXCL_START */ fprintf(stderr, "Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } sputc(' ', f); sputhex(state->prevhashseed, HASH_SIZE, f); sputeol(f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -1930,8 +2222,10 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) /* find the disk for this mapping */ disk = find_disk(state, map->name); if (!disk) { + /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency for unmapped disk '%s'\n", map->name); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* save the mapping only for not empty disks */ @@ -1948,8 +2242,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* mark the disk as with mapping */ @@ -1998,8 +2294,10 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputs(file->sub, f); sputeol(f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* for each block in the file */ @@ -2019,8 +2317,10 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputsl("rep ", f); break; default: + /* LCOV_EXCL_START */ fprintf(stderr, "Internal state inconsistency in saving for block %u state %u\n", block->parity_pos, block_state); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } sputu32(block->parity_pos, f); @@ -2030,8 +2330,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ++count_block; @@ -2063,8 +2365,10 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputs(link->linkto, f); sputeol(f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -2078,8 +2382,10 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputs(dir->sub, f); sputeol(f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ++count_dir; @@ -2090,8 +2396,10 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputs(disk->name, f); sputeol(f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } for(b=0;bhash, HASH_SIZE, f); sputeol(f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -2129,15 +2439,19 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (state->opt.verbose) { @@ -2160,14 +2474,18 @@ static void decoding_error(const char* path, STREAM* f) uint32_t crc_computed; 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"); 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } fprintf(stderr, "Decoding error in '%s' at offset %"PRIi64"\n", path, stell(f)); @@ -2192,8 +2510,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* get the stored crc from the last four bytes */ @@ -2206,9 +2526,11 @@ static void decoding_error(const char* path, STREAM* f) crc_stored = crc32c(crc_stored, buf, 4); if (crc_computed != crc_stored) { + /* LCOV_EXCL_START */ fprintf(stderr, "Mismatching CRC in '%s'\n", path); fprintf(stderr, "This content file is damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } else { fprintf(stderr, "The file CRC is correct!\n"); } @@ -2242,11 +2564,14 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sread(f, buffer, 12); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid header!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (memcmp(buffer, "SNAPCNT1\n\3\0\0", 12) != 0) { + /* LCOV_EXCL_START */ if (memcmp(buffer, "SNAPCNT", 7) != 0) { decoding_error(path, f); fprintf(stderr, "Invalid header!\n"); @@ -2254,6 +2579,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST fprintf(stderr, "The content file '%s' was generated with a newer version of SnapRAID!\n", path); } exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } while (1) { @@ -2280,35 +2606,45 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb32(f, &mapping); if (ret < 0 || mapping >= mapping_max) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } disk = tommy_array_get(&disk_mapping, mapping); ret = sgetb64(f, &v_size); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* check for impossible file size to avoid to crash for a too big allocation */ if (v_size / state->block_size > blockmax) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in file size!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetb64(f, &v_mtime_sec); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetb32(f, &v_mtime_nsec); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* STAT_NSEC_INVALID is encoded as 0 */ @@ -2319,18 +2655,24 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb64(f, &v_inode); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetbs(f, sub, sizeof(sub)); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*sub) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* allocate the file */ @@ -2352,26 +2694,34 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb32(f, &v_pos); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetb32(f, &v_count); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (v_idx + v_count > file->blockmax) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in block number!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (v_pos + v_count > blockmax) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in block size!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* grow the array */ @@ -2382,9 +2732,11 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST struct snapraid_block* block = &file->blockvec[v_idx]; if (block->parity_pos != POS_INVALID) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in block position!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } switch (c) { @@ -2406,9 +2758,11 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST block_state_set(block, BLOCK_STATE_REP); break; default: + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid block type!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } block->parity_pos = v_pos; @@ -2417,8 +2771,10 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (c != 'n') { ret = sread(f, block->hash, HASH_SIZE); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else { /* set the ZERO hash for deprecated NEW blocks */ @@ -2436,9 +2792,11 @@ 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 */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in block existence!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* insert the block in the block array */ @@ -2464,8 +2822,10 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb32(f, &v_oldest); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } v_pos = 0; @@ -2478,20 +2838,26 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb32(f, &v_count); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (v_pos + v_count > blockmax) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in info size!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetb32(f, &flag); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* if there is an info */ @@ -2499,8 +2865,10 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* read the time */ ret = sgetb32(f, &t); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* analyze the flags */ @@ -2508,9 +2876,11 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST rehash = (flag & 4) != 0; if (rehash && state->prevhash == HASH_UNDEFINED) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency for missing previous checksum!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } info = info_make(t + v_oldest, bad, rehash); @@ -2525,9 +2895,11 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* ensure that an info is present only for used positions */ if (info_is_required(state, v_pos)) { if (!info) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency for missing info!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else { /* extra info are accepted for backward compatibility */ @@ -2547,9 +2919,11 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb32(f, &mapping); if (ret < 0 || mapping >= mapping_max) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } disk = tommy_array_get(&disk_mapping, mapping); @@ -2559,14 +2933,18 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb32(f, &v_count); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (v_pos + v_count > blockmax) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in hole size!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* get the subcommand */ @@ -2593,8 +2971,10 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* read the hash */ ret = sread(f, deleted->block.hash, HASH_SIZE); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* if we are clearing undeterminated hashes */ @@ -2605,9 +2985,11 @@ 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 */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency for used hole!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* insert the block in the block array */ @@ -2623,9 +3005,11 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST v_pos += v_count; break; default: + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid hole type!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } else if (c == 's') { @@ -2638,27 +3022,35 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb32(f, &mapping); if (ret < 0 || mapping >= mapping_max) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } disk = tommy_array_get(&disk_mapping, mapping); ret = sgetbs(f, sub, sizeof(sub)); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetbs(f, linkto, sizeof(linkto)); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*sub || !*linkto) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* allocate the link as symbolic link */ @@ -2680,27 +3072,35 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb32(f, &mapping); if (ret < 0 || mapping >= mapping_max) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } disk = tommy_array_get(&disk_mapping, mapping); ret = sgetbs(f, sub, sizeof(sub)); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetbs(f, linkto, sizeof(linkto)); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*sub || !*linkto) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* allocate the link as hard link */ @@ -2721,21 +3121,27 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetb32(f, &mapping); if (ret < 0 || mapping >= mapping_max) { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } disk = tommy_array_get(&disk_mapping, mapping); ret = sgetbs(f, sub, sizeof(sub)); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (!*sub) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* allocate the dir */ @@ -2759,16 +3165,20 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST state->hash = HASH_SPOOKY2; break; default: + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid checksum!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* read the seed */ ret = sread(f, state->hashseed, HASH_SIZE); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else if (c == 'C') { /* get the subcommand */ @@ -2782,24 +3192,30 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST state->prevhash = HASH_SPOOKY2; break; default: + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid checksum!\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* read the seed */ ret = sread(f, state->prevhashseed, HASH_SIZE); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else if (c == 'z') { block_off_t blksize; ret = sgetb32(f, &blksize); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* without configuration, auto assign the block size */ @@ -2808,16 +3224,20 @@ 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 'block_size' specification!\n"); fprintf(stderr, "Please restore the 'block_size' value in the configuration file to '%u'\n", blksize / 1024); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else if (c == 'x') { ret = sgetb32(f, &blockmax); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } else if (c == 'm') { struct snapraid_map* map; @@ -2827,21 +3247,27 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetbs(f, buffer, sizeof(buffer)); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ret = sgetb32(f, &v_pos); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* read the uuid */ ret = sgetbs(f, uuid, sizeof(uuid)); if (ret < 0) { + /* LCOV_EXCL_START */ decoding_error(path, f); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } map = map_alloc(buffer, v_pos, uuid); @@ -2851,10 +3277,12 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* find the disk */ disk = find_disk(state, buffer); 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* insert in the mapping vector */ @@ -2870,44 +3298,56 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST ret = sgetble32(f, &crc_stored); 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } crc_checked = 1; } else { + /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid command '%c'!\n", (char)c); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } tommy_array_done(&disk_mapping); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* check that the stored parity size matches the loaded state */ if (blockmax != parity_size(state)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency in parity size in '%s' at offset %"PRIi64"\n", path, stell(f)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* set the required parity size */ @@ -2983,8 +3423,10 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputc('x', f); sputb32(blockmax, f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } sputc('c', f); @@ -2993,13 +3435,17 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) } else if (state->hash == HASH_SPOOKY2) { sputc('k', f); } else { + /* LCOV_EXCL_START */ fprintf(stderr, "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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* previous hash only present */ @@ -3012,13 +3458,17 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) } else if (state->prevhash == HASH_SPOOKY2) { sputc('k', f); } else { + /* LCOV_EXCL_START */ fprintf(stderr, "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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -3032,8 +3482,10 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* find the disk for this mapping */ disk = find_disk(state, map->name); if (!disk) { + /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency for unmapped disk '%s'\n", map->name); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* save the mapping only for not empty disks */ @@ -3043,8 +3495,10 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputb32(map->position, 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* assign the mapping index used to identify disks */ @@ -3091,8 +3545,10 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputb64(inode, 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* for all the blocks of the file */ @@ -3124,8 +3580,10 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputc('p', f); break; default: + /* LCOV_EXCL_START */ fprintf(stderr, "Internal state inconsistency in saving for block %u state %u\n", v_pos, block_state); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } sputb32(v_pos, f); @@ -3138,8 +3596,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } count_block += v_count; @@ -3170,8 +3630,10 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(link->sub, 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -3183,8 +3645,10 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputb32(disk->mapping, 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ++count_dir; @@ -3194,8 +3658,10 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputc('h', f); sputb32(disk->mapping, f); if (serror(f)) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } begin = 0; while (begin < blockmax) { @@ -3236,8 +3702,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } } @@ -3282,8 +3750,10 @@ 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* next begin position */ @@ -3293,8 +3763,10 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputc('N', 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } if (state->opt.verbose) { @@ -3335,8 +3807,10 @@ void state_read(struct snapraid_state* state) } else { /* 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* otherwise continue */ @@ -3364,8 +3838,10 @@ void state_read(struct snapraid_state* state) /* get the stat of the content file */ ret = fstat(shandle(f), &st); if (ret != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error stating the content file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* go further to check other content files */ @@ -3379,8 +3855,10 @@ void state_read(struct snapraid_state* state) if (ret != 0) { /* 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* ensure to rewrite all the content files */ @@ -3429,11 +3907,13 @@ void state_read(struct snapraid_state* state) sclose(f); 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"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* update the mapping */ @@ -3462,8 +3942,10 @@ void state_write(struct snapraid_state* state) /* open all the content files */ f = sopen_multi_write(count_content); if (!f) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error opening the content files.\n"); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } k = 0; @@ -3473,8 +3955,10 @@ void state_write(struct snapraid_state* state) char tmp[PATH_MAX]; 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } ++k; i = i->next; @@ -3489,20 +3973,26 @@ void state_write(struct snapraid_state* state) /* than even in a system crash event we have one valid copy of the file. */ if (sflush(f) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } #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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } #endif if (sclose(f) != 0) { + /* LCOV_EXCL_START */ fprintf(stderr, "Error writing the content file '%s' in close(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } i = tommy_list_head(&state->contentlist); @@ -3511,8 +4001,10 @@ void state_write(struct snapraid_state* state) char tmp[PATH_MAX]; 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } i = i->next; } diff --git a/sync.c b/sync.c index 7b4d22d7..8e46d6d7 100644 --- a/sync.c +++ b/sync.c @@ -119,6 +119,7 @@ static void state_hash_process(struct snapraid_state* state, block_off_t blockst struct snapraid_file* file = handle[j].file; ret = handle_close(&handle[j]); if (ret == -1) { + /* LCOV_EXCL_START */ /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", i, handle[j].disk->name, file->sub, strerror(errno)); @@ -127,6 +128,7 @@ static void state_hash_process(struct snapraid_state* state, block_off_t blockst printf("Stopping at block %u\n", i); ++error; goto bail; + /* LCOV_EXCL_STOP */ } } @@ -162,8 +164,10 @@ static void state_hash_process(struct snapraid_state* state, block_off_t blockst printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); } + /* LCOV_EXCL_START */ ++error; goto bail; + /* LCOV_EXCL_STOP */ } /* check if the file is changed */ @@ -193,12 +197,14 @@ static void state_hash_process(struct snapraid_state* state, block_off_t blockst read_size = handle_read(&handle[j], block, buffer, state->block_size, stderr); if (read_size == -1) { + /* LCOV_EXCL_START */ fprintf(stdlog, "error:%u:%s:%s: Read error at position %u\n", i, handle[j].disk->name, handle[j].file->sub, block_file_pos(block)); fprintf(stderr, "DANGER! Unexpected 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", handle[j].disk->dir, handle[j].path); printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", handle[j].file->sub); ++error; goto bail; + /* LCOV_EXCL_STOP */ } countsize += read_size; @@ -224,7 +230,9 @@ static void state_hash_process(struct snapraid_state* state, block_off_t blockst /* progress */ if (state_progress(state, i, countpos, countmax, countsize)) { + /* LCOV_EXCL_START */ break; + /* LCOV_EXCL_STOP */ } } @@ -235,6 +243,7 @@ static void state_hash_process(struct snapraid_state* state, block_off_t blockst ret = handle_close(&handle[j]); if (ret == -1) { + /* LCOV_EXCL_START */ /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", blockmax, handle[j].disk->name, file->sub, strerror(errno)); @@ -243,6 +252,7 @@ static void state_hash_process(struct snapraid_state* state, block_off_t blockst printf("Stopping at block %u\n", blockmax); ++error; goto bail; + /* LCOV_EXCL_STOP */ } } } @@ -516,6 +526,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari struct snapraid_file* file = handle[j].file; ret = handle_close(&handle[j]); if (ret == -1) { + /* LCOV_EXCL_START */ /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ fprintf(stdlog, "error:%u:%s:%s: Close error. %s\n", i, handle[j].disk->name, file->sub, strerror(errno)); @@ -524,6 +535,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari printf("Stopping at block %u\n", i); ++error; goto bail; + /* LCOV_EXCL_STOP */ } } @@ -561,8 +573,10 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); } + /* LCOV_EXCL_START */ ++error; goto bail; + /* LCOV_EXCL_STOP */ } /* check if the file is changed */ @@ -593,12 +607,14 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari read_size = handle_read(&handle[j], block, buffer[j], state->block_size, stderr); if (read_size == -1) { + /* LCOV_EXCL_START */ fprintf(stdlog, "error:%u:%s:%s: Read error at position %u\n", i, handle[j].disk->name, handle[j].file->sub, block_file_pos(block)); fprintf(stderr, "DANGER! Unexpected 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", handle[j].disk->dir, handle[j].path); printf("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", handle[j].file->sub); ++error; goto bail; + /* LCOV_EXCL_STOP */ } countsize += read_size; @@ -723,12 +739,14 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari for(l=0;llevel;++l) { ret = parity_read(parity[l], i, buffer[diskmax+l], state->block_size, stdlog); if (ret == -1) { + /* LCOV_EXCL_START */ fprintf(stdlog, "parity_error:%u:%s: Read error\n", i, lev_config_name(l)); fprintf(stderr, "DANGER! Read error in the %s disk, it isn't possible to sync.\n", lev_name(l)); fprintf(stderr, "Ensure that disk '%s' is sane.\n", lev_config_name(l)); printf("Stopping at block %u\n", i); ++error; goto bail; + /* LCOV_EXCL_STOP */ } } @@ -788,12 +806,14 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari for(l=0;llevel;++l) { ret = parity_write(parity[l], i, buffer[diskmax+l], state->block_size); if (ret == -1) { + /* LCOV_EXCL_START */ fprintf(stdlog, "parity_error:%u:%s: Write error\n", i, lev_config_name(l)); fprintf(stderr, "DANGER! Write error in the %s disk, it isn't possible to sync.\n", lev_name(l)); fprintf(stderr, "Ensure that disk '%s' is sane.\n", lev_config_name(l)); printf("Stopping at block %u\n", i); ++error; goto bail; + /* LCOV_EXCL_STOP */ } } } @@ -859,7 +879,9 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* progress */ if (state_progress(state, i, countpos, countmax, countsize)) { + /* LCOV_EXCL_START */ break; + /* LCOV_EXCL_STOP */ } /* autosave */ @@ -945,8 +967,10 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t loaded_size = state->loaded_paritymax * (data_off_t)state->block_size; 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); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* adjust the number of block to process */ @@ -959,14 +983,18 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t parity_ptr[l] = &parity[l]; ret = parity_create(parity_ptr[l], state->parity_path[l], &out_size, state->opt.skip_sequential); if (ret == -1) { + /* LCOV_EXCL_START */ fprintf(stderr, "WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* if the file is too small */ if (out_size < loaded_size) { + /* LCOV_EXCL_START */ fprintf(stderr, "DANGER! The %s file %s is smaller than the expected %" PRId64 ".\n", lev_name(l), state->parity_path[l], loaded_size); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } /* change the size of the parity file, truncating or extending it */ @@ -974,9 +1002,11 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t /* and they are automatically removed when we save the new content file */ ret = parity_chsize(parity_ptr[l], size, &out_size, state->opt.skip_fallocate); 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)); exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ } } @@ -997,8 +1027,10 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t if (blockstart < blockmax) { ret = state_sync_process(state, parity_ptr, blockstart, blockmax); if (ret == -1) { + /* LCOV_EXCL_START */ ++unrecoverable_error; /* continue, as we are already exiting */ + /* LCOV_EXCL_STOP */ } } else { printf("Nothing to do\n"); @@ -1007,16 +1039,20 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t for(l=0;llevel;++l) { ret = parity_sync(parity_ptr[l]); if (ret == -1) { + /* LCOV_EXCL_START */ fprintf(stderr, "DANGER! Unexpected sync error in %s disk.\n", lev_name(l)); ++unrecoverable_error; /* continue, as we are already exiting */ + /* LCOV_EXCL_STOP */ } 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)); ++unrecoverable_error; /* continue, as we are already exiting */ + /* LCOV_EXCL_STOP */ } }