diff --git a/cmdline/check.c b/cmdline/check.c index deb364bc..848699de 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -102,10 +102,10 @@ static int is_hash_matching(struct snapraid_state* state, int rehash, unsigned d hash_checked = 0; /* keep track if we check at least one block */ /* check if the recovered blocks are OK */ - for(j=0;jblock_size, buffer); /* if the recovered parity block matches */ - if (memcmp(buffer[diskmax+i], buffer_recov[i], state->block_size) == 0) { + if (memcmp(buffer[diskmax + i], buffer_recov[i], state->block_size) == 0) { /* recompute all the redundancy information */ raid_gen(diskmax, state->level, state->block_size, buffer); return 1; @@ -177,16 +177,16 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u error = 0; /* setup vector of failed disk indexes */ - for(i=0;iblock_size); + for (i = 0; i < r - 1; ++i) + memcpy(buffer[diskmax + ip[i]], buffer_recov[ip[i]], state->block_size); /* recover using one less parity, the ip[r-1] one */ - raid_rec_dataonly(r-1, id, ip, diskmax, state->block_size, buffer); + raid_rec_dataonly(r - 1, id, ip, diskmax, state->block_size, buffer); /* use the remaining ip[r-1] parity to check the result */ - if (is_parity_matching(state, diskmax, ip[r-1], buffer, buffer_recov)) + if (is_parity_matching(state, diskmax, ip[r - 1], buffer, buffer_recov)) return 0; /* log */ fprintf(stdlog, "parity_error:%u:", pos); - for(i=0;iblock_size); + for (i = 0; i < r; ++i) + memcpy(buffer[diskmax + ip[i]], buffer_recov[ip[i]], state->block_size); /* recover */ raid_rec_dataonly(r, id, ip, diskmax, state->block_size, buffer); @@ -262,7 +262,7 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u /* log */ fprintf(stdlog, "parity_error:%u:", pos); - for(i=0;ihash)) { @@ -360,7 +360,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign n = 0; something_to_recover = 0; /* keep track if there is at least one block to fix */ - for(j=0;jhash, buffer[failed[j].index]) == 0 ) { /* we already have corrected it! */ @@ -399,7 +399,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* if they were BAD we have to use some euristics to ensure that we have recovered */ /* the state after the sync. If unsure, we assume the worst case */ - for(j=0;jblock_size, buffer); /* fill up the zero buffer */ - memset(buffer[buffermax-1], 0, state->block_size); - raid_zero(buffer[buffermax-1]); + memset(buffer[buffermax - 1], 0, state->block_size); + raid_zero(buffer[buffermax - 1]); failed = malloc_nofail(diskmax * sizeof(struct failed_struct)); failed_map = malloc_nofail(diskmax * sizeof(unsigned)); @@ -623,12 +623,12 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* first count the number of blocks to process */ countmax = 0; - for(i=blockstart;ilevel;++l) + for (l = 0; l < state->level; ++l) buffer_recov[l] = buffer[diskmax + state->level + l]; - for(;llevel;++l) { + for (l = 0; l < state->level; ++l) { if (parity[l]) { ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, stdlog); if (ret == -1) { @@ -945,13 +945,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ++unrecoverable_error; /* print a list of all the errors in files */ - for(j=0;jdisk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); } /* keep track of damaged files */ - for(j=0;jdisk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); @@ -978,7 +978,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* and doesn't make sense to try to fix it */ if (valid_parity) { /* check the parity */ - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { if (buffer_recov[l] != 0 && memcmp(buffer_recov[l], buffer[diskmax + l], state->block_size) != 0) { buffer_recov[l] = 0; @@ -991,7 +991,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* now writes recovered files */ if (fix) { /* update the fixed files */ - for(j=0;jlevel;++l) { + for (l = 0; l < state->level; ++l) { if (buffer_recov[l] == 0 && parity[l] != 0) { ret = parity_write(parity[l], i, buffer[diskmax + l], state->block_size); if (ret == -1) { @@ -1057,7 +1057,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } } else { /* if we are not fixing, we just set the FIXED flag */ - for(j=0;jname, file->sub, st.st_size); + fprintf(stdlog, "error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, file->sub, st.st_size); ++error; } @@ -1627,7 +1627,7 @@ close_and_continue: bail: /* close all the files left open */ - for(j=0;jlevel;++l) { + for (l = 0; l < state->level; ++l) { parity_ptr[l] = &parity[l]; ret = parity_create(parity_ptr[l], state->parity_path[l], &out_size, state->file_mode); if (ret == -1) { @@ -1821,7 +1821,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b } else if (!state->opt.auditonly) { /* if checking, open the file for reading */ /* it may fail if the file doesn't exist, in this case we continue to check the files */ - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { parity_ptr[l] = &parity[l]; ret = parity_open(parity_ptr[l], state->parity_path[l], state->file_mode); if (ret == -1) { @@ -1832,7 +1832,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b } } else { /* otherwise don't use any parity */ - for(l=0;llevel;++l) + for (l = 0; l < state->level; ++l) parity_ptr[l] = 0; } @@ -1857,7 +1857,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b } /* try to close only if opened */ - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { if (parity_ptr[l]) { ret = parity_close(parity_ptr[l]); /* LCOV_EXCL_START */ diff --git a/cmdline/dry.c b/cmdline/dry.c index f7b2f316..16759ed4 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -54,9 +54,9 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit countsize = 0; countpos = 0; state_progress_begin(state, blockstart, blockmax, countmax); - for(i=blockstart;ilevel;++l) { + for (l = 0; l < state->level; ++l) { if (parity[l]) { /* until now is CPU */ state_usage_cpu(state); @@ -145,7 +145,7 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit bail: /* close all the files left open */ - for(j=0;jlevel;++l) { + for (l = 0; l < state->level; ++l) { parity_ptr[l] = &parity[l]; ret = parity_open(parity_ptr[l], state->parity_path[l], state->file_mode); if (ret == -1) { @@ -223,7 +223,7 @@ void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t } /* try to close only if opened */ - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { if (parity_ptr[l]) { ret = parity_close(parity_ptr[l]); if (ret == -1) { diff --git a/cmdline/dup.c b/cmdline/dup.c index 0693300e..45bb37af 100644 --- a/cmdline/dup.c +++ b/cmdline/dup.c @@ -49,7 +49,7 @@ struct snapraid_hash* hash_alloc(struct snapraid_state* state, struct snapraid_d buf = malloc_nofail(file->blockmax * HASH_SIZE); /* set the back pointer */ - for(i=0;iblockmax;++i) { + for (i = 0; i < file->blockmax; ++i) { memcpy(buf + i * HASH_SIZE, file->blockvec[i].hash, HASH_SIZE); if (!block_has_updated_hash(&file->blockvec[i])) { @@ -80,6 +80,7 @@ int hash_compare(const void* void_arg, const void* void_data) { const char* arg = void_arg; const struct snapraid_hash* hash = void_data; + return memcmp(arg, hash->hash, HASH_SIZE); } @@ -100,12 +101,12 @@ void state_dup(struct snapraid_state* state) printf("Comparing...\n"); /* for each disk */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { tommy_node* j; struct snapraid_disk* disk = i->data; /* for each file */ - for(j=disk->filelist;j!=0;j=j->next) { + for (j = disk->filelist; j != 0; j = j->next) { struct snapraid_file* file = j->data; struct snapraid_hash* hash; tommy_hash_t hash32; @@ -126,8 +127,8 @@ void state_dup(struct snapraid_state* state) if (dup) { ++count; size += dup->file->size; - fprintf(stdlog, "dup:%s:%s:%s:%s:%"PRIu64": dup\n", disk->name, file->sub, dup->disk->name, dup->file->sub, dup->file->size); - printf("%12"PRIu64" %s%s = %s%s\n", file->size, disk->dir, file->sub, dup->disk->dir, dup->file->sub); + fprintf(stdlog, "dup:%s:%s:%s:%s:%" PRIu64 ": dup\n", disk->name, file->sub, dup->disk->name, dup->file->sub, dup->file->size); + printf("%12" PRIu64 " %s%s = %s%s\n", file->size, disk->dir, file->sub, dup->disk->dir, dup->file->sub); hash_free(hash); } else { tommy_hashdyn_insert(&hashset, &hash->nodeset, hash, hash32); @@ -140,14 +141,14 @@ void state_dup(struct snapraid_state* state) tommy_hashdyn_done(&hashset); printf("\n"); - printf("%8u duplicates, for %"PRIu64" MiB\n", count, size / (1024*1024)); + printf("%8u duplicates, for %" PRIu64 " MiB\n", count, size / (1024 * 1024)); if (count) printf("There are duplicates!\n"); else printf("No duplicates\n"); fprintf(stdlog, "summary:dup_count:%u\n", count); - fprintf(stdlog, "summary:dup_size:%"PRIu64"\n", size); + fprintf(stdlog, "summary:dup_size:%" PRIu64 "\n", size); if (count == 0) { fprintf(stdlog, "summary:exit:unique\n"); } else { diff --git a/cmdline/elem.c b/cmdline/elem.c index 3651aeb4..07f65ea0 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -53,7 +53,7 @@ struct snapraid_filter* filter_alloc_file(int direction, const char* pattern) /* find first and last slash */ first = 0; last = 0; - for(i=filter->pattern;*i;++i) { + for (i = filter->pattern; *i; ++i) { if (*i == '/') { if (!first) first = i; @@ -154,7 +154,7 @@ static int filter_recurse(struct snapraid_filter* filter, const char* const_path /* filter for all the directories */ name = path; - for(i=0;path[i] != 0;++i) { + for (i = 0; path[i] != 0; ++i) { if (path[i] == '/') { /* set a terminator */ path[i] = 0; @@ -185,7 +185,7 @@ static int filter_element(tommy_list* filterlist, const char* disk, const char* int direction = 1; /* by default include all */ /* for each filter */ - for(i=tommy_list_head(filterlist);i!=0;i=i->next) { + for (i = tommy_list_head(filterlist); i != 0; i = i->next) { int ret; struct snapraid_filter* filter = i->data; @@ -243,7 +243,7 @@ int filter_existence(int filter_missing, const char* dir, const char* sub) /* we directly check if in the disk the file is present or not */ pathprint(path, sizeof(path), "%s%s", dir, sub); - + if (lstat(path, &st) != 0) { /* if the file doesn't exist, we don't filter it out */ if (errno == ENOENT) @@ -266,12 +266,12 @@ int filter_correctness(int filter_error, tommy_arrayblkof* infoarr, struct snapr return 0; /* check each block of the file */ - for(i=0;iblockmax;++i) { + for (i = 0; i < file->blockmax; ++i) { struct snapraid_block* block; snapraid_info info; block = &file->blockvec[i]; - + info = info_get(infoarr, block->parity_pos); /* if the file has a bad block, don't exclude it */ @@ -287,7 +287,7 @@ int filter_content(tommy_list* contentlist, const char* path) { tommy_node* i; - for(i=tommy_list_head(contentlist);i!=0;i=i->next) { + for (i = tommy_list_head(contentlist); i != 0; i = i->next) { struct snapraid_content* content = i->data; char tmp[PATH_MAX]; @@ -394,7 +394,7 @@ struct snapraid_file* file_alloc(unsigned block_size, const char* sub, uint64_t file->blockvec = malloc_nofail(file->blockmax * sizeof(struct snapraid_block)); /* set the back pointer */ - for(i=0;iblockmax;++i) { + for (i = 0; i < file->blockmax; ++i) { file->blockvec[i].parity_pos = POS_INVALID; file->blockvec[i].file_mixed = 0; @@ -447,7 +447,7 @@ void file_copy(struct snapraid_file* src_file, struct snapraid_file* dst_file) /* LCOV_EXCL_STOP */ } - for(i=0;iblockmax;++i) { + for (i = 0; i < dst_file->blockmax; ++i) { /* set a block with hash computed but without parity */ block_state_set(&dst_file->blockvec[i], BLOCK_STATE_REP); @@ -461,6 +461,7 @@ void file_copy(struct snapraid_file* src_file, struct snapraid_file* dst_file) const char* file_name(const struct snapraid_file* file) { const char* r = strrchr(file->sub, '/'); + if (!r) r = file->sub; else @@ -472,6 +473,7 @@ int file_inode_compare_to_arg(const void* void_arg, const void* void_data) { const uint64_t* arg = void_arg; const struct snapraid_file* file = void_data; + if (*arg < file->inode) return -1; if (*arg > file->inode) @@ -483,6 +485,7 @@ int file_inode_compare(const void* void_a, const void* void_b) { const struct snapraid_file* file_a = void_a; const struct snapraid_file* file_b = void_b; + if (file_a->inode < file_b->inode) return -1; if (file_a->inode > file_b->inode) @@ -494,6 +497,7 @@ int file_path_compare(const void* void_a, const void* void_b) { const struct snapraid_file* file_a = void_a; const struct snapraid_file* file_b = void_b; + return strcmp(file_a->sub, file_b->sub); } @@ -501,6 +505,7 @@ int file_physical_compare(const void* void_a, const void* void_b) { const struct snapraid_file* file_a = void_a; const struct snapraid_file* file_b = void_b; + if (file_a->physical < file_b->physical) return -1; if (file_a->physical > file_b->physical) @@ -512,6 +517,7 @@ int file_path_compare_to_arg(const void* void_arg, const void* void_data) { const char* arg = void_arg; const struct snapraid_file* file = void_data; + return strcmp(arg, file->sub); } @@ -593,6 +599,7 @@ int link_name_compare_to_arg(const void* void_arg, const void* void_data) { const char* arg = void_arg; const struct snapraid_link* link = void_data; + return strcmp(arg, link->sub); } @@ -600,6 +607,7 @@ int link_alpha_compare(const void* void_a, const void* void_b) { const struct snapraid_link* link_a = void_a; const struct snapraid_link* link_b = void_b; + return strcmp(link_a->sub, link_b->sub); } @@ -624,6 +632,7 @@ int dir_name_compare(const void* void_arg, const void* void_data) { const char* arg = void_arg; const struct snapraid_dir* dir = void_data; + return strcmp(arg, dir->sub); } @@ -695,7 +704,7 @@ int disk_is_empty(struct snapraid_disk* disk, block_off_t blockmax) /* checks all the blocks to search for deleted ones */ /* this search is slow, but it's done only if no file is present */ - for(i=0;iblockarr, i); unsigned block_state = block_state_get(block); @@ -706,7 +715,7 @@ int disk_is_empty(struct snapraid_disk* disk, block_off_t blockmax) case BLOCK_STATE_DELETED : /* if there is a deleted block, the disk is not empty */ return 0; - default: + default : /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency for used block in disk '%s' without files\n", disk->name); exit(EXIT_FAILURE); @@ -741,6 +750,7 @@ int info_time_compare(const void* void_a, const void* void_b) const snapraid_info* info_b = void_b; time_t time_a = info_get_time(*info_a); time_t time_b = info_get_time(*info_b); + if (time_a < time_b) return -1; if (time_a > time_b) diff --git a/cmdline/elem.h b/cmdline/elem.h index 48121cea..5d3f1629 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -192,7 +192,7 @@ struct snapraid_block { * meaning that they don't have any previous content. * This is important because it means that deleting them, you are not going * to lose something that cannot be recovered. - * Note that excluded files won't ever get this flag. + * Note that excluded files won't ever get this flag. */ #define FILE_IS_CREATED 0x20 @@ -256,7 +256,7 @@ struct snapraid_link { /* nodes for data structures */ tommy_node nodelist; tommy_hashdyn_node nodeset; -}; +}; /** * Dir. @@ -268,7 +268,7 @@ struct snapraid_dir { /* nodes for data structures */ tommy_node nodelist; tommy_hashdyn_node nodeset; -}; +}; /** * Deleted entry. @@ -521,7 +521,7 @@ static inline int hash_is_invalid(const unsigned char* hash) { unsigned i; - for(i=0;i= tommy_arrayblkof_size(array)) return 0; diff --git a/cmdline/handle.c b/cmdline/handle.c index d2c4d2b7..70076c8b 100644 --- a/cmdline/handle.c +++ b/cmdline/handle.c @@ -69,7 +69,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in char path_from[PATH_MAX]; /* check if exists a .unrecoverable copy, and rename to the real one */ - pathprint(path_from , sizeof(path_from), "%s.unrecoverable", handle->path); + pathprint(path_from, sizeof(path_from), "%s.unrecoverable", handle->path); if (rename(path_from, handle->path) == 0) { /* open for read write */ @@ -136,7 +136,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in #if HAVE_POSIX_FADVISE if ((mode & MODE_SEQUENTIAL) != 0) { - /* advise sequential access */ + /* advise sequential access */ ret = posix_fadvise(handle->f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ @@ -256,7 +256,7 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un /* check if we are going to read only not initialized data */ if (offset >= handle->valid_size) { - fprintf(out, "Reading missing data from file '%s' at offset %"PRIu64".\n", handle->path, offset); + fprintf(out, "Reading missing data from file '%s' at offset %" PRIu64 ".\n", handle->path, offset); return -1; } @@ -265,7 +265,7 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un #if !HAVE_PREAD if (lseek(handle->f, offset, SEEK_SET) != offset) { /* LCOV_EXCL_START */ - fprintf(out, "Error seeking file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno)); + fprintf(out, "Error seeking file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -282,12 +282,12 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un if (read_ret < 0) { /* LCOV_EXCL_START */ - fprintf(out, "Error reading file '%s' at offset %"PRIu64" for size %u. %s.\n", handle->path, offset + count, read_size - count, strerror(errno)); + fprintf(out, "Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", handle->path, offset + count, read_size - count, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } if (read_ret == 0) { - fprintf(out, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno)); + fprintf(out, "Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno)); return -1; } @@ -382,7 +382,7 @@ struct snapraid_handle* handle_map(struct snapraid_state* state, unsigned* handl /* get the size of the mapping */ size = 0; - for(i=state->maplist;i!=0;i=i->next) { + for (i = state->maplist; i != 0; i = i->next) { struct snapraid_map* map = i->data; if (map->position > size) size = map->position; @@ -391,7 +391,7 @@ struct snapraid_handle* handle_map(struct snapraid_state* state, unsigned* handl handle = malloc_nofail(size * sizeof(struct snapraid_handle)); - for(j=0;jdisklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_map* map; struct snapraid_disk* disk = i->data; tommy_node* k; /* search the mapping for this disk */ - for(k=state->maplist;k!=0;k=k->next) { + for (k = state->maplist; k != 0; k = k->next) { map = k->data; if (strcmp(disk->name, map->name) == 0) break; } - if (k==0) { + if (k == 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Internal error for inconsistent disk mapping.\n"); exit(EXIT_FAILURE); diff --git a/cmdline/import.c b/cmdline/import.c index 308569eb..328a1f22 100644 --- a/cmdline/import.c +++ b/cmdline/import.c @@ -29,6 +29,7 @@ int import_block_hash_compare(const void* void_arg, const void* void_data) { const unsigned char* arg = void_arg; const struct snapraid_import_block* block = void_data; + return memcmp(arg, block->hash, HASH_SIZE); } @@ -36,6 +37,7 @@ int import_block_prevhash_compare(const void* void_arg, const void* void_data) { const unsigned char* arg = void_arg; const struct snapraid_import_block* block = void_data; + return memcmp(arg, block->prevhash, HASH_SIZE); } @@ -94,7 +96,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t #endif offset = 0; - for(i=0;iblockmax;++i) { + for (i = 0; i < file->blockmax; ++i) { struct snapraid_import_block* block = &file->blockvec[i]; unsigned read_size = block_size; if (read_size > size) @@ -231,8 +233,8 @@ static void import_dir(struct snapraid_state* state, const char* dir) exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - - while (1) { + + while (1) { char path[PATH_MAX]; struct stat st; const char* name; diff --git a/cmdline/list.c b/cmdline/list.c index 5e392482..b3a1009e 100644 --- a/cmdline/list.c +++ b/cmdline/list.c @@ -40,7 +40,7 @@ void state_list(struct snapraid_state* state) printf("Listing...\n"); /* for each disk */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { tommy_node* j; struct snapraid_disk* disk = i->data; @@ -48,7 +48,7 @@ void state_list(struct snapraid_state* state) tommy_list_sort(&disk->filelist, file_path_compare); /* for each file */ - for(j=disk->filelist;j!=0;j=j->next) { + for (j = disk->filelist; j != 0; j = j->next) { struct snapraid_file* file = j->data; #if HAVE_LOCALTIME_R struct tm tm_res; @@ -59,7 +59,7 @@ void state_list(struct snapraid_state* state) ++file_count; file_size += file->size; - fprintf(stdlog, "file:%s:%s:%"PRIu64":%"PRIi64":%u:%"PRIi64"\n", disk->name, file->sub, file->size, file->mtime_sec, file->mtime_nsec, file->inode); + fprintf(stdlog, "file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIi64 "\n", disk->name, file->sub, file->size, file->mtime_sec, file->mtime_nsec, file->inode); t = file->mtime_sec; #if HAVE_LOCALTIME_R @@ -68,7 +68,7 @@ void state_list(struct snapraid_state* state) tm = localtime(&t); #endif - printf("%12"PRIu64" ", file->size); + printf("%12" PRIu64 " ", file->size); if (tm) { printf("%04u/%02u/%02u %02u:%02u", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min); if (state->opt.verbose) { @@ -83,7 +83,7 @@ void state_list(struct snapraid_state* state) tommy_list_sort(&disk->linklist, link_alpha_compare); /* for each link */ - for(j=disk->linklist;j!=0;j=j->next) { + for (j = disk->linklist; j != 0; j = j->next) { struct snapraid_link* link = j->data; const char* type; @@ -93,8 +93,8 @@ void state_list(struct snapraid_state* state) case FILE_IS_SYMDIR : type = "symdir"; break; case FILE_IS_JUNCTION : type = "junction"; break; /* LCOV_EXCL_START */ - default: type = "unknown"; break; - /* LCOV_EXCL_STOP */ + default : type = "unknown"; break; + /* LCOV_EXCL_STOP */ } ++link_count; @@ -110,11 +110,11 @@ void state_list(struct snapraid_state* state) } } printf("\n"); - printf("%8u files, for %"PRIu64" GiB\n", file_count, file_size / (1024*1024*1024)); + printf("%8u files, for %" PRIu64 " GiB\n", file_count, file_size / (1024 * 1024 * 1024)); printf("%8u links\n", link_count); fprintf(stdlog, "summary:file_count:%u\n", file_count); - fprintf(stdlog, "summary:file_size:%"PRIu64"\n", file_size); + fprintf(stdlog, "summary:file_size:%" PRIu64 "\n", file_size); fprintf(stdlog, "summary:link_count:%u\n", link_count); fprintf(stdlog, "summary:exit:ok\n"); fflush(stdlog); diff --git a/cmdline/mingw.c b/cmdline/mingw.c index b0b0f844..48a1c2e6 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -113,7 +113,7 @@ void os_init(void) if (!ntdll) { fprintf(stderr, "Error loading the NTDLL module.\n"); exit(EXIT_FAILURE); - } + } /* load functions not always available */ ptr_SetThreadExecutionState = (void*)GetProcAddress(kernel32, "SetThreadExecutionState"); @@ -386,7 +386,7 @@ static void windows_info2stat(const BY_HANDLE_FILE_INFORMATION* info, const FILE st->st_mode = S_IFCHR; st->st_desc = "reparse-point-nfs"; break; - default: + default : st->st_mode = S_IFCHR; st->st_desc = "reparse-point"; break; @@ -486,7 +486,7 @@ static void windows_finddata2stat(const WIN32_FIND_DATAW* info, struct windows_s st->st_mode = S_IFCHR; st->st_desc = "reparse-point-nfs"; break; - default: + default : st->st_mode = S_IFCHR; st->st_desc = "reparse-point"; break; @@ -546,9 +546,9 @@ static void windows_finddata2dirent(const WIN32_FIND_DATAW* info, struct windows size_t len; name = u16tou8(info->cFileName); - + len = strlen(name); - + if (len + 1 >= sizeof(dirent->d_name)) { fprintf(stderr, "Name too long\n"); exit(EXIT_FAILURE); @@ -600,7 +600,7 @@ static void windows_errno(DWORD error) case ERROR_PRIVILEGE_NOT_HELD : /* in CreateSymlinkW if no SeCreateSymbolicLinkPrivilige permission */ errno = EPERM; break; - default: + default : fprintf(stderr, "Unexpected Windows error %d.\n", (int)error); errno = EIO; break; @@ -619,7 +619,7 @@ int windows_fstat(int fd, struct windows_stat* st) return -1; } - if (!GetFileInformationByHandle(h, &info)) { + if (!GetFileInformationByHandle(h, &info)) { windows_errno(GetLastError()); return -1; } @@ -699,7 +699,7 @@ int lstat_ex(const char* file, struct windows_stat* st) return -1; } - if (!GetFileInformationByHandle(h, &info)) { + if (!GetFileInformationByHandle(h, &info)) { DWORD error = GetLastError(); CloseHandle(h); windows_errno(error); @@ -740,7 +740,7 @@ int windows_stat(const char* file, struct windows_stat* st) return -1; } - if (!GetFileInformationByHandle(h, &info)) { + if (!GetFileInformationByHandle(h, &info)) { DWORD error = GetLastError(); CloseHandle(h); windows_errno(error); @@ -830,7 +830,7 @@ int windows_fsync(int fd) */ return 0; - default: + default : windows_errno(error); return -1; } @@ -941,7 +941,7 @@ windows_dir* windows_opendir(const char* dir) /* add final / and * */ len = wcslen(wdir); - if (len!= 0 && wdir[len-1] != '\\') + if (len != 0 && wdir[len - 1] != '\\') wdir[len++] = L'\\'; wdir[len++] = L'*'; wdir[len++] = 0; @@ -1063,27 +1063,27 @@ int windows_symlink(const char* existing, const char* file) #endif #ifndef REPARSE_DATA_BUFFER_HEADER_SIZE typedef struct _REPARSE_DATA_BUFFER { - DWORD ReparseTag; - WORD ReparseDataLength; - WORD Reserved; + DWORD ReparseTag; + WORD ReparseDataLength; + WORD Reserved; _ANONYMOUS_UNION union { struct { - WORD SubstituteNameOffset; - WORD SubstituteNameLength; - WORD PrintNameOffset; - WORD PrintNameLength; - ULONG Flags; + WORD SubstituteNameOffset; + WORD SubstituteNameLength; + WORD PrintNameOffset; + WORD PrintNameLength; + ULONG Flags; WCHAR PathBuffer[1]; } SymbolicLinkReparseBuffer; struct { - WORD SubstituteNameOffset; - WORD SubstituteNameLength; - WORD PrintNameOffset; - WORD PrintNameLength; + WORD SubstituteNameOffset; + WORD SubstituteNameLength; + WORD PrintNameOffset; + WORD PrintNameLength; WCHAR PathBuffer[1]; } MountPointReparseBuffer; struct { - BYTE DataBuffer[1]; + BYTE DataBuffer[1]; } GenericReparseBuffer; } DUMMYUNIONNAME; } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER; @@ -1129,7 +1129,7 @@ int windows_readlink(const char* file, char* buffer, size_t size) /* convert the name to UTF-8 */ name = u16tou8n(rdb->SymbolicLinkReparseBuffer.PathBuffer + rdb->SymbolicLinkReparseBuffer.PrintNameOffset, - rdb->SymbolicLinkReparseBuffer.PrintNameLength / 2, &len); + rdb->SymbolicLinkReparseBuffer.PrintNameLength / 2, &len); /* check for overflow */ if (len > size) { diff --git a/cmdline/mktest.c b/cmdline/mktest.c index 1d8f1b7e..6017d88b 100644 --- a/cmdline/mktest.c +++ b/cmdline/mktest.c @@ -25,7 +25,7 @@ */ unsigned long long seed = 0; -unsigned rnd(unsigned max) +unsigned rnd(unsigned max) { seed = seed * 6364136223846793005LL + 1442695040888963407LL; @@ -43,7 +43,8 @@ unsigned rndnz(unsigned max) void rndnz_range(unsigned char* data, int size) { int i; - for(i=0;i .cpp - k1 *= c1; --> .asm - 152: 8d 14 80 lea (%eax,%eax,4),%edx - 155: 8d 14 90 lea (%eax,%edx,4),%edx - 158: c1 e2 03 shl $0x3,%edx - 15b: 29 c2 sub %eax,%edx - 15d: 8d 14 d2 lea (%edx,%edx,8),%edx - 160: 8d 14 90 lea (%eax,%edx,4),%edx - 163: 8d 14 d0 lea (%eax,%edx,8),%edx - 166: 8d 14 90 lea (%eax,%edx,4),%edx - 169: 8d 14 50 lea (%eax,%edx,2),%edx - 16c: 8d 14 90 lea (%eax,%edx,4),%edx - 16f: 8d 14 92 lea (%edx,%edx,4),%edx - 172: 8d 14 50 lea (%eax,%edx,2),%edx - 175: 8d 04 d0 lea (%eax,%edx,8),%eax - 178: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx - 17f: 29 d0 sub %edx,%eax + + -> .cpp + k1 *= c1; + -> .asm + 152: 8d 14 80 lea (%eax,%eax,4),%edx + 155: 8d 14 90 lea (%eax,%edx,4),%edx + 158: c1 e2 03 shl $0x3,%edx + 15b: 29 c2 sub %eax,%edx + 15d: 8d 14 d2 lea (%edx,%edx,8),%edx + 160: 8d 14 90 lea (%eax,%edx,4),%edx + 163: 8d 14 d0 lea (%eax,%edx,8),%edx + 166: 8d 14 90 lea (%eax,%edx,4),%edx + 169: 8d 14 50 lea (%eax,%edx,2),%edx + 16c: 8d 14 90 lea (%eax,%edx,4),%edx + 16f: 8d 14 92 lea (%edx,%edx,4),%edx + 172: 8d 14 50 lea (%eax,%edx,2),%edx + 175: 8d 04 d0 lea (%eax,%edx,8),%eax + 178: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx + 17f: 29 d0 sub %edx,%eax * resulting in speeds of 500 MB/s instead of 3000 MB/s. * @@ -98,7 +98,7 @@ void MurmurHash3_x86_128(const void* key, unsigned len, const uint8_t* seed, voi /* body */ - for(i=0;idisklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; tommy_node* j; /* for all files */ - for(j=disk->filelist;j!=0;j=j->next) { + for (j = disk->filelist; j != 0; j = j->next) { struct snapraid_file* file = j->data; /* if the file has a zero nanosecond timestamp */ diff --git a/cmdline/parity.c b/cmdline/parity.c index cceb6daa..1d4cc02a 100644 --- a/cmdline/parity.c +++ b/cmdline/parity.c @@ -32,7 +32,7 @@ block_off_t parity_size(struct snapraid_state* state) /* compute the size of the parity file */ parity_block = 0; - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; /* start from the declared size */ @@ -66,12 +66,12 @@ void parity_overflow(struct snapraid_state* state, data_off_t size) blockalloc = size / state->block_size; /* for all disks */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; tommy_node* j; /* for all files */ - for(j=disk->filelist;j!=0;j=j->next) { + for (j = disk->filelist; j != 0; j = j->next) { struct snapraid_file* file = j->data; if (file->blockmax > 0) { @@ -212,9 +212,9 @@ int parity_chsize(struct snapraid_parity* parity, data_off_t size, data_off_t* o if (f_ret != 0) { /* LCOV_EXCL_START */ if (f_errno == ENOSPC) { - fprintf(stderr, "Failed to grow parity file '%s' to size %"PRIu64" using %s due lack of space.\n", parity->path, size, call); + fprintf(stderr, "Failed to grow parity file '%s' to size %" PRIu64 " using %s due lack of space.\n", parity->path, size, call); } else { - fprintf(stderr, "Error growing parity file '%s' to size %"PRIu64" using %s. Do you have enough space? %s.\n", parity->path, size, call, strerror(f_errno)); + fprintf(stderr, "Error growing parity file '%s' to size %" PRIu64 " using %s. Do you have enough space? %s.\n", parity->path, size, call, strerror(f_errno)); } goto bail; /* LCOV_EXCL_STOP */ @@ -245,7 +245,7 @@ int parity_chsize(struct snapraid_parity* parity, data_off_t size, data_off_t* o /* now check the error */ if (f_ret != 0) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error truncating parity file '%s' to size %"PRIu64". %s.\n", parity->path, size, strerror(f_errno)); + fprintf(stderr, "Error truncating parity file '%s' to size %" PRIu64 ". %s.\n", parity->path, size, strerror(f_errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -419,14 +419,14 @@ int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* /* check if we are going to read only not initialized data */ if (offset >= parity->valid_size) { - fprintf(out, "Reading missing data from file '%s' at offset %"PRIu64".\n", parity->path, offset); + fprintf(out, "Reading missing data from file '%s' at offset %" PRIu64 ".\n", parity->path, offset); return -1; } #if !HAVE_PREAD if (lseek(parity->f, offset, SEEK_SET) != offset) { /* LCOV_EXCL_START */ - fprintf(out, "Error seeking file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno)); + fprintf(out, "Error seeking file '%s' at offset %" PRIu64 ". %s.\n", parity->path, offset, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -442,13 +442,13 @@ int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* #endif if (read_ret < 0) { /* LCOV_EXCL_START */ - fprintf(out, "Error reading file '%s' at offset %"PRIu64" for size %u. %s.\n", parity->path, offset + count, block_size - count, strerror(errno)); + fprintf(out, "Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", parity->path, offset + count, block_size - count, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } if (read_ret == 0) { /* LCOV_EXCL_START */ - fprintf(out, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno)); + fprintf(out, "Unexpected end of file '%s' at offset %" PRIu64 ". %s.\n", parity->path, offset, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -464,4 +464,3 @@ int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* return block_size; } - diff --git a/cmdline/pool.c b/cmdline/pool.c index c697c489..b327d5d8 100644 --- a/cmdline/pool.c +++ b/cmdline/pool.c @@ -37,8 +37,8 @@ static int clean_dir(struct snapraid_state* state, const char* dir) exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - - while (1) { + + while (1) { char path_next[PATH_MAX]; struct stat st; const char* name; @@ -220,19 +220,19 @@ void state_pool(struct snapraid_state* state) /* for each disk */ count = 0; - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { tommy_node* j; struct snapraid_disk* disk = i->data; /* for each file */ - for(j=disk->filelist;j!=0;j=j->next) { + for (j = disk->filelist; j != 0; j = j->next) { struct snapraid_file* file = j->data; make_link(pool_dir, share_dir, disk, file->sub); ++count; } /* for each link */ - for(j=disk->linklist;j!=0;j=j->next) { + for (j = disk->linklist; j != 0; j = j->next) { struct snapraid_link* link = j->data; make_link(pool_dir, share_dir, disk, link->sub); ++count; diff --git a/cmdline/portable.h b/cmdline/portable.h index 7b904a4d..4af2e761 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -176,9 +176,9 @@ #endif #if HAVE_GETOPT_LONG -#define SWITCH_GETOPT_LONG(a,b) a +#define SWITCH_GETOPT_LONG(a, b) a #else -#define SWITCH_GETOPT_LONG(a,b) b +#define SWITCH_GETOPT_LONG(a, b) b #endif /** diff --git a/cmdline/rehash.c b/cmdline/rehash.c index 96b335f1..672c89ec 100644 --- a/cmdline/rehash.c +++ b/cmdline/rehash.c @@ -59,7 +59,7 @@ void state_rehash(struct snapraid_state* state) randomize(state->hashseed, HASH_SIZE); /* mark all the block for rehashing */ - for(i=0;ineed_write = 1; /* free all the blocks of the file */ - for(i=0;iblockmax;++i) { + for (i = 0; i < file->blockmax; ++i) { struct snapraid_block* block = &file->blockvec[i]; block_off_t block_pos = block->parity_pos; unsigned block_state; @@ -211,7 +211,7 @@ static void scan_file_deallocate(struct snapraid_scan* scan, struct snapraid_fil /* we just don't know the old hash, and then we set it to invalid */ hash_invalid_set(deleted->block.hash); break; - default: + default : /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency in deallocating for block %u state %u\n", block->parity_pos, block_state); exit(EXIT_FAILURE); @@ -239,7 +239,7 @@ static int file_is_full_invalid_parity_and_stable(struct snapraid_state* state, return 0; /* check all blocks */ - for(i=0;iblockmax;++i) { + for (i = 0; i < file->blockmax; ++i) { struct snapraid_block* block = &file->blockvec[i]; snapraid_info info; @@ -271,7 +271,7 @@ static int file_is_full_hashed_and_stable(struct snapraid_state* state, struct s return 0; /* check all blocks */ - for(i=0;iblockmax;++i) { + for (i = 0; i < file->blockmax; ++i) { struct snapraid_block* block = &file->blockvec[i]; snapraid_info info; @@ -357,7 +357,7 @@ static void scan_file_insert(struct snapraid_scan* scan, struct snapraid_file* f /* allocate the blocks of the file */ block_pos = disk->first_free_block; block_max = tommy_arrayblk_size(&disk->blockarr); - for(i=0;iblockmax;++i) { + for (i = 0; i < file->blockmax; ++i) { snapraid_info info; struct snapraid_block* block = &file->blockvec[i]; @@ -381,7 +381,7 @@ static void scan_file_insert(struct snapraid_scan* scan, struct snapraid_file* f if (block_has_updated_hash(block) && !info_get_rehash(info)) { /* the only possible case is for REP blocks */ assert(block_state_get(block) == BLOCK_STATE_REP); - + /* convert to a REP block */ block_state_set(&file->blockvec[i], BLOCK_STATE_REP); @@ -482,6 +482,7 @@ static void scan_file(struct snapraid_scan* scan, int output, const char* sub, c /* always search with the new inode, in the all new inodes found until now, */ /* with the eventual presence of also the past inodes */ uint64_t inode = st->st_ino; + file = tommy_hashdyn_search(&disk->inodeset, file_inode_compare_to_arg, &inode, file_inode_hash(inode)); /* identify moved files with past inodes and hardlinks with the new inodes */ @@ -490,10 +491,10 @@ static void scan_file(struct snapraid_scan* scan, int output, const char* sub, c if (file->size == st->st_size && file->mtime_sec == st->st_mtime && (file->mtime_nsec == STAT_NSEC(st) - /* always accept the stored value if it's STAT_NSEC_INVALID */ - /* it happens when upgrading from an old version of SnapRAID */ - /* not yet supporting the nanosecond field */ - || file->mtime_nsec == STAT_NSEC_INVALID + /* always accept the stored value if it's STAT_NSEC_INVALID */ + /* it happens when upgrading from an old version of SnapRAID */ + /* not yet supporting the nanosecond field */ + || file->mtime_nsec == STAT_NSEC_INVALID ) ) { /* check if multiple files have the same inode */ @@ -504,7 +505,7 @@ static void scan_file(struct snapraid_scan* scan, int output, const char* sub, c 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); + 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 */ } @@ -568,7 +569,7 @@ static void scan_file(struct snapraid_scan* scan, int output, const char* sub, c /* 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); + 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 */ } @@ -613,7 +614,7 @@ static void scan_file(struct snapraid_scan* scan, int output, const char* sub, c /* 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 inconsistency in inode '%"PRIu64"' for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub); + fprintf(stderr, "Internal inconsistency in inode '%" PRIu64 "' for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -631,10 +632,10 @@ static void scan_file(struct snapraid_scan* scan, int output, const char* sub, c if (file->size == st->st_size && file->mtime_sec == st->st_mtime && (file->mtime_nsec == STAT_NSEC(st) - /* always accept the stored value if it's STAT_NSEC_INVALID */ - /* it happens when upgrading from an old version of SnapRAID */ - /* not yet supporting the nanosecond field */ - || file->mtime_nsec == STAT_NSEC_INVALID + /* always accept the stored value if it's STAT_NSEC_INVALID */ + /* it happens when upgrading from an old version of SnapRAID */ + /* not yet supporting the nanosecond field */ + || file->mtime_nsec == STAT_NSEC_INVALID ) ) { /* mark as present */ @@ -695,7 +696,7 @@ static void scan_file(struct snapraid_scan* scan, int output, const char* sub, c } /* here if the file is changed but with the correct name */ - + /* do a safety check to ensure that the common ext4 case of zeroing */ /* the size of a file after a crash doesn't propagate to the backup */ if (file->size != 0 && st->st_size == 0) { @@ -745,7 +746,7 @@ static void scan_file(struct snapraid_scan* scan, int output, const char* sub, c tommy_uint32_t hash = file_stamp_hash(file->size, file->mtime_sec, file->mtime_nsec); /* search for a file with the same name and stamp in all the disks */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* other_disk = i->data; struct snapraid_file* other_file; @@ -1048,7 +1049,7 @@ static int scan_dir(struct snapraid_scan* scan, int output, const char* dir, con /* process the sorted dir entries */ node = list; - while (node!=0) { + while (node != 0) { char path_next[PATH_MAX]; char sub_next[PATH_MAX]; struct dirent_sorted* dd = node->data; @@ -1192,7 +1193,7 @@ static int scan_dir(struct snapraid_scan* scan, int output, const char* dir, con if (filter_path(&state->filterlist, disk->name, sub_next) == 0) { /* late stat */ if (!st) st = DSTAT(path_next, dd, &st_buf); - + fprintf(stderr, "WARNING! Ignoring special '%s' file '%s'\n", stat_desc(st), path_next); } else { if (state->opt.verbose) { @@ -1224,7 +1225,7 @@ void state_scan(struct snapraid_state* state, int output) printf("Comparing...\n"); /* first scan all the directory and find new and deleted files */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; struct snapraid_scan* scan; tommy_node* node; @@ -1293,7 +1294,7 @@ void state_scan(struct snapraid_state* state, int output) /* only when all disks have all the new files found */ /* now process all the new and deleted files */ - for(i=scanlist;i!=0;i=i->next) { + for (i = scanlist; i != 0; i = i->next) { struct snapraid_scan* scan = i->data; struct snapraid_disk* disk = scan->disk; tommy_node* node; @@ -1392,7 +1393,7 @@ void state_scan(struct snapraid_state* state, int output) /* if verbose, prints the list of duplicates */ /* if they are supposed real offsets */ if (state->opt.verbose && phy_last != FILEPHY_UNREPORTED_OFFSET) { - fprintf(stderr, "WARNING! Files '%s%s' and '%s%s' have the same physical offset %"PRId64".\n", disk->dir, phy_file_last->sub, disk->dir, file->sub, phy_last); + fprintf(stderr, "WARNING! Files '%s%s' and '%s%s' have the same physical offset %" PRId64 ".\n", disk->dir, phy_file_last->sub, disk->dir, file->sub, phy_last); } ++phy_dup; } @@ -1442,7 +1443,7 @@ void state_scan(struct snapraid_state* state, int output) /* checks for disks where all the previously existing files where removed */ if (!state->opt.force_empty) { done = 0; - for(i=state->disklist,j=scanlist;i!=0;i=i->next,j=j->next) { + for (i = state->disklist, j = scanlist; i != 0; i = i->next, j = j->next) { struct snapraid_disk* disk = i->data; struct snapraid_scan* scan = j->data; @@ -1469,7 +1470,7 @@ void state_scan(struct snapraid_state* state, int output) /* checks for disks without the physical offset support */ if (state->opt.force_order == SORT_PHYSICAL) { done = 0; - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; if (disk->has_unreliable_physical) { @@ -1488,7 +1489,7 @@ void state_scan(struct snapraid_state* state, int output) /* checks for disks without persistent inodes */ done = 0; - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; if (disk->has_volatile_inodes) { @@ -1506,7 +1507,7 @@ void state_scan(struct snapraid_state* state, int output) /* checks for disks with changed UUID */ done = 0; - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; /* don't print the message if the UUID changed because before */ @@ -1528,7 +1529,7 @@ void state_scan(struct snapraid_state* state, int output) /* checks for disks with unsupported UUID */ done = 0; - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; if (disk->has_unsupported_uuid) { @@ -1557,7 +1558,7 @@ void state_scan(struct snapraid_state* state, int output) total.count_remove = 0; total.count_insert = 0; - for(i=scanlist;i!=0;i=i->next) { + for (i = scanlist; i != 0; i = i->next) { struct snapraid_scan* scan = i->data; total.count_equal += scan->count_equal; total.count_move += scan->count_move; diff --git a/cmdline/scrub.c b/cmdline/scrub.c index 48e3480b..2dc00f15 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -77,7 +77,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* first count the number of blocks to process */ countmax = 0; countlast = 0; - for(i=blockstart;ilevel;++l) + for (l = 0; l < state->level; ++l) buffer_recov[l] = buffer[diskmax + state->level + l]; - for(;llevel;++l) { + for (l = 0; l < state->level; ++l) { ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, stdlog); if (ret == -1) { buffer_recov[l] = 0; @@ -359,7 +359,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par raid_gen(diskmax, state->level, state->block_size, buffer); /* compare the parity */ - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { if (buffer_recov[l] && memcmp(buffer[diskmax + l], buffer_recov[l], state->block_size) != 0) { fprintf(stdlog, "parity_error:%u:%s: Data error\n", i, lev_config_name(l)); @@ -389,7 +389,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* if rehash is needed */ if (rehash) { /* store all the new hash already computed */ - for(j=0;jhash, rehandle[j].hash, HASH_SIZE); } @@ -459,7 +459,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par fflush(stdlog); bail: - for(j=0;jinfoarr, i); /* skip unused blocks */ @@ -580,7 +580,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) unsigned j = i + 1; while (j < count && info_get_time(infomap[i]) == info_get_time(infomap[j])) ++j; - fprintf(stdlog, "info_time:%"PRIu64":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); + fprintf(stdlog, "info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); i = j; } @@ -609,14 +609,14 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) } fprintf(stdlog, "count_limit:%u\n", countlimit); - fprintf(stdlog, "time_limit:%"PRIu64"\n", (uint64_t)timelimit); + fprintf(stdlog, "time_limit:%" PRIu64 "\n", (uint64_t)timelimit); fprintf(stdlog, "last_limit:%u\n", lastlimit); /* free the temp vector */ free(infomap); /* open the file for reading */ - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { parity_ptr[l] = &parity[l]; ret = parity_open(parity_ptr[l], state->parity_path[l], state->file_mode); if (ret == -1) { @@ -637,7 +637,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) /* continue, as we are already exiting */ } - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { ret = parity_close(parity_ptr[l]); if (ret == -1) { /* LCOV_EXCL_START */ diff --git a/cmdline/selftest.c b/cmdline/selftest.c index 24f6daf7..316db8fb 100644 --- a/cmdline/selftest.c +++ b/cmdline/selftest.c @@ -54,52 +54,52 @@ struct hash_test_vector { * Test vectors for tommy_hash32 */ static struct hash32_test_vector TEST_HASH32[] = { -{ "", 0, 0x8614384c }, -{ "a", 1, 0x12c16c36 }, -{ "abc", 3, 0xc58e8af5 }, -{ "message digest", 14, 0x006b32f1 }, -{ "abcdefghijklmnopqrstuvwxyz", 26, 0x7e6fcfe0 }, -{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x8604adf8 }, -{ "The quick brown fox jumps over the lazy dog", 43, 0xdeba3d3a }, -{ "\x00", 1, 0x4a7d1c33 }, -{ "\x16\x27", 2, 0x8b50899b }, -{ "\xe2\x56\xb4", 3, 0x60406493 }, -{ "\xc9\x4d\x9c\xda", 4, 0xa049144a }, -{ "\x79\xf1\x29\x69\x5d", 5, 0x4da2c2f1 }, -{ "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x59de30cf }, -{ "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x219e149c }, -{ "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x25067520 }, -{ "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0xa1f368d8 }, -{ "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x805fc63d }, -{ "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0x7f75dd0f }, -{ "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0xb9154382 }, -{ 0, 0, 0 } + { "", 0, 0x8614384c }, + { "a", 1, 0x12c16c36 }, + { "abc", 3, 0xc58e8af5 }, + { "message digest", 14, 0x006b32f1 }, + { "abcdefghijklmnopqrstuvwxyz", 26, 0x7e6fcfe0 }, + { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x8604adf8 }, + { "The quick brown fox jumps over the lazy dog", 43, 0xdeba3d3a }, + { "\x00", 1, 0x4a7d1c33 }, + { "\x16\x27", 2, 0x8b50899b }, + { "\xe2\x56\xb4", 3, 0x60406493 }, + { "\xc9\x4d\x9c\xda", 4, 0xa049144a }, + { "\x79\xf1\x29\x69\x5d", 5, 0x4da2c2f1 }, + { "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x59de30cf }, + { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x219e149c }, + { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x25067520 }, + { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0xa1f368d8 }, + { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x805fc63d }, + { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0x7f75dd0f }, + { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0xb9154382 }, + { 0, 0, 0 } }; /** * Test vectors for tommy_hash64 */ static struct hash64_test_vector TEST_HASH64[] = { -{ "", 0, 0x8614384cb5165fbfULL }, -{ "a", 1, 0x1a2e0298a8e94a3dULL }, -{ "abc", 3, 0x7555796b7a7d21ebULL }, -{ "message digest", 14, 0x9411a57d04b92fb4ULL }, -{ "abcdefghijklmnopqrstuvwxyz", 26, 0x3ca3f8d2b4e69832ULL }, -{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x6dae542ba0015a4dULL }, -{ "The quick brown fox jumps over the lazy dog", 43, 0xe06d8cbb3d2ea1a6ULL }, -{ "\x00", 1, 0x201e664fb5f2c021ULL }, -{ "\x16\x27", 2, 0xef42fa8032c4b775ULL }, -{ "\xe2\x56\xb4", 3, 0x6e6c498a6688466cULL }, -{ "\xc9\x4d\x9c\xda", 4, 0x5195005419905423ULL }, -{ "\x79\xf1\x29\x69\x5d", 5, 0x221235b48afee7c1ULL }, -{ "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x1b1f18b9266f095bULL }, -{ "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x2cbafa8e741d49caULL }, -{ "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x4677f04c06e0758dULL }, -{ "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0x5afe09e8214e2163ULL }, -{ "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x115b6276d209fab6ULL }, -{ "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0xd0636d2f01cf3a3eULL }, -{ "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0x6d259f5fef74f93eULL }, -{ 0, 0, 0 } + { "", 0, 0x8614384cb5165fbfULL }, + { "a", 1, 0x1a2e0298a8e94a3dULL }, + { "abc", 3, 0x7555796b7a7d21ebULL }, + { "message digest", 14, 0x9411a57d04b92fb4ULL }, + { "abcdefghijklmnopqrstuvwxyz", 26, 0x3ca3f8d2b4e69832ULL }, + { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 62, 0x6dae542ba0015a4dULL }, + { "The quick brown fox jumps over the lazy dog", 43, 0xe06d8cbb3d2ea1a6ULL }, + { "\x00", 1, 0x201e664fb5f2c021ULL }, + { "\x16\x27", 2, 0xef42fa8032c4b775ULL }, + { "\xe2\x56\xb4", 3, 0x6e6c498a6688466cULL }, + { "\xc9\x4d\x9c\xda", 4, 0x5195005419905423ULL }, + { "\x79\xf1\x29\x69\x5d", 5, 0x221235b48afee7c1ULL }, + { "\x00\x7e\xdf\x1e\x31\x1c", 6, 0x1b1f18b9266f095bULL }, + { "\x2a\x4c\xe1\xff\x9e\x6f\x53", 7, 0x2cbafa8e741d49caULL }, + { "\xba\x02\xab\x18\x30\xc5\x0e\x8a", 8, 0x4677f04c06e0758dULL }, + { "\xec\x4e\x7a\x72\x1e\x71\x2a\xc9\x33", 9, 0x5afe09e8214e2163ULL }, + { "\xfd\xe2\x9c\x0f\x72\xb7\x08\xea\xd0\x78", 10, 0x115b6276d209fab6ULL }, + { "\x65\xc4\x8a\xb8\x80\x86\x9a\x79\x00\xb7\xae", 11, 0xd0636d2f01cf3a3eULL }, + { "\x77\xe9\xd7\x80\x0e\x3f\x5c\x43\xc8\xc2\x46\x39", 12, 0x6d259f5fef74f93eULL }, + { 0, 0, 0 } }; /** @@ -107,7 +107,7 @@ static struct hash64_test_vector TEST_HASH64[] = { */ static struct hash_test_vector TEST_MURMUR3[] = { #include "murmur3test.c" -{ 0, 0, { 0 } } + { 0, 0, { 0 } } }; /** @@ -115,7 +115,7 @@ static struct hash_test_vector TEST_MURMUR3[] = { */ static struct hash_test_vector TEST_SPOOKY2[] = { #include "spooky2test.c" -{ 0, 0, { 0 } } + { 0, 0, { 0 } } }; #define HASH_TEST_MAX 512 /* tests are never longer than 512 bytes */ @@ -153,7 +153,7 @@ static void test_hash(void) seed_aligned[14] = 0x9e; seed_aligned[15] = 0x43; - for(i=0;TEST_HASH32[i].data;++i) { + for (i = 0; TEST_HASH32[i].data; ++i) { uint32_t digest; memcpy(buffer_aligned, TEST_HASH32[i].data, TEST_HASH32[i].len); digest = tommy_hash_u32(seed32, buffer_aligned, TEST_MURMUR3[i].len); @@ -165,7 +165,7 @@ static void test_hash(void) } } - for(i=0;TEST_HASH64[i].data;++i) { + for (i = 0; TEST_HASH64[i].data; ++i) { uint64_t digest; memcpy(buffer_aligned, TEST_HASH64[i].data, TEST_HASH64[i].len); digest = tommy_hash_u64(seed64, buffer_aligned, TEST_MURMUR3[i].len); @@ -178,7 +178,7 @@ static void test_hash(void) } - for(i=0;TEST_MURMUR3[i].data;++i) { + for (i = 0; TEST_MURMUR3[i].data; ++i) { unsigned char digest[HASH_SIZE]; memcpy(buffer_aligned, TEST_MURMUR3[i].data, TEST_MURMUR3[i].len); memhash(HASH_MURMUR3, seed_aligned, digest, buffer_aligned, TEST_MURMUR3[i].len); @@ -190,7 +190,7 @@ static void test_hash(void) } } - for(i=0;TEST_SPOOKY2[i].data;++i) { + for (i = 0; TEST_SPOOKY2[i].data; ++i) { unsigned char digest[HASH_SIZE]; memcpy(buffer_aligned, TEST_SPOOKY2[i].data, TEST_SPOOKY2[i].len); memhash(HASH_SPOOKY2, seed_aligned, digest, buffer_aligned, TEST_SPOOKY2[i].len); @@ -216,31 +216,31 @@ struct crc_test_vector { * Test vectors for CRC32C (Castagnoli) */ static struct crc_test_vector TEST_CRC32C[] = { -{ "", 0, 0 }, -{ "\x61", 1, 0xc1d04330 }, -{ "\x66\x6f\x6f", 3, 0xcfc4ae1d }, -{ "\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64", 11, 0xc99465aa }, -{ "\x68\x65\x6c\x6c\x6f\x20", 6, 0x7e627e58 }, -{ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32, 0x8a9136aa }, -{ "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 32, 0x62a8ab43 }, -{ "\x1f\x1e\x1d\x1c\x1b\x1a\x19\x18\x17\x16\x15\x14\x13\x12\x11\x10\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00", 32, 0x113fdb5c }, -{ "\x01\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x14\x00\x00\x00\x18\x28\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 48, 0xd9963a56 }, -{ "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 32, 0x46dd794e }, -{ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28", 40, 0x0e2c157f }, -{ "\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50", 40, 0xe980ebf6 }, -{ "\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78", 40, 0xde74bded }, -{ "\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0", 40, 0xd579c862 }, -{ "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8", 40, 0xba979ad0 }, -{ "\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0", 40, 0x2b29d913 }, -{ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0", 240, 0x24c5d375 }, -{ 0, 0, 0 } + { "", 0, 0 }, + { "\x61", 1, 0xc1d04330 }, + { "\x66\x6f\x6f", 3, 0xcfc4ae1d }, + { "\x68\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64", 11, 0xc99465aa }, + { "\x68\x65\x6c\x6c\x6f\x20", 6, 0x7e627e58 }, + { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 32, 0x8a9136aa }, + { "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", 32, 0x62a8ab43 }, + { "\x1f\x1e\x1d\x1c\x1b\x1a\x19\x18\x17\x16\x15\x14\x13\x12\x11\x10\x0f\x0e\x0d\x0c\x0b\x0a\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00", 32, 0x113fdb5c }, + { "\x01\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x14\x00\x00\x00\x18\x28\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00", 48, 0xd9963a56 }, + { "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", 32, 0x46dd794e }, + { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28", 40, 0x0e2c157f }, + { "\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50", 40, 0xe980ebf6 }, + { "\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78", 40, 0xde74bded }, + { "\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0", 40, 0xd579c862 }, + { "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8", 40, 0xba979ad0 }, + { "\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0", 40, 0x2b29d913 }, + { "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0", 240, 0x24c5d375 }, + { 0, 0, 0 } }; static void test_crc32c(void) { unsigned i; - for(i=0;TEST_CRC32C[i].data;++i) { + for (i = 0; TEST_CRC32C[i].data; ++i) { uint32_t digest; digest = crc32c(0, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len); if (digest != TEST_CRC32C[i].digest) { @@ -275,7 +275,7 @@ static void test_tommy(void) tommy_arrayblk_init(&arrayblk); tommy_arrayblkof_init(&arrayblkof, sizeof(unsigned)); - for(i=0;inode, filter); - } break; + } break; case 'd' : { struct snapraid_filter* filter = filter_alloc_disk(1, optarg); if (!filter) { @@ -445,7 +445,7 @@ int main(int argc, char* argv[]) /* LCOV_EXCL_STOP */ } tommy_list_insert_tail(&filterlist_disk, &filter->node, filter); - } break; + } break; case 'm' : filter_missing = 1; break; @@ -623,7 +623,7 @@ int main(int argc, char* argv[]) case OPT_TEST_RUN : run = optarg; break; - default: + default : /* LCOV_EXCL_START */ fprintf(stderr, "Unknown option '%c'\n", (char)c); exit(EXIT_FAILURE); @@ -682,7 +682,7 @@ int main(int argc, char* argv[]) switch (operation) { case OPERATION_CHECK : break; - default: + default : if (opt.auditonly) { /* LCOV_EXCL_START */ fprintf(stderr, "You cannot use -a, --audit-only with the '%s' command\n", command); @@ -694,7 +694,7 @@ int main(int argc, char* argv[]) switch (operation) { case OPERATION_SYNC : break; - default: + default : if (opt.prehash) { /* LCOV_EXCL_START */ fprintf(stderr, "You cannot use -h, --pre-hash with the '%s' command\n", command); @@ -736,7 +736,7 @@ int main(int argc, char* argv[]) case OPERATION_FIX : case OPERATION_DRY : break; - default: + default : if (!tommy_list_empty(&filterlist_file)) { /* LCOV_EXCL_START */ fprintf(stderr, "You cannot use -f, --filter with the '%s' command\n", command); @@ -761,7 +761,7 @@ int main(int argc, char* argv[]) case OPERATION_CHECK : case OPERATION_FIX : break; - default: + default : if (filter_error != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "You cannot use -e, --filter-error with the '%s' command\n", command); @@ -774,7 +774,7 @@ int main(int argc, char* argv[]) case OPERATION_CHECK : case OPERATION_FIX : break; - default: + default : if (import != 0) { /* LCOV_EXCL_START */ fprintf(stderr, "You cannot import with the '%s' command\n", command); @@ -803,14 +803,14 @@ int main(int argc, char* argv[]) t = time(0); tm = localtime(&t); fprintf(stdlog, "version:%s\n", PACKAGE_VERSION); - fprintf(stdlog, "unixtime:%"PRIi64"\n", (int64_t)t); + fprintf(stdlog, "unixtime:%" PRIi64 "\n", (int64_t)t); if (tm) { char datetime[64]; strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tm); fprintf(stdlog, "time:%s\n", datetime); } fprintf(stdlog, "command:%s\n", command); - for(i=0;iblock_size = 256 * 1024; /* default 256 KiB */ state->raid_mode = RAID_MODE_CAUCHY; state->file_mode = MODE_SEQUENTIAL; - for(l=0;lparity_path[l][0] = 0; state->parity_device[l] = 0; state->tick_parity[l] = 0; @@ -139,7 +139,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } } - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { if (state->parity_path[l][0] == 0) { /* LCOV_EXCL_START */ fprintf(stderr, "No '%s' specification in '%s'\n", lev_config_name(l), path); @@ -156,10 +156,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } /* checks for equal paths */ - for(i=state->contentlist;i!=0;i=i->next) { + for (i = state->contentlist; i != 0; i = i->next) { struct snapraid_content* content = i->data; - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++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); @@ -171,7 +171,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t /* check if all the data and parity disks are different */ if (!state->opt.skip_device) { - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { tommy_node* j; struct snapraid_disk* disk = i->data; @@ -188,13 +188,13 @@ static void state_config_check(struct snapraid_state* state, const char* path, t #endif if (!state->opt.force_device) { - for(j=i->next;j!=0;j=j->next) { + 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); + fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", disk->device); fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); fprintf(stderr, "to change one of the disk serial.\n"); #endif @@ -208,12 +208,12 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } } - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++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); + fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", disk->device); fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); fprintf(stderr, "to change one of the disk serial.\n"); #endif @@ -226,7 +226,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t /* 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); + fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", disk->device); fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); fprintf(stderr, "to change one of the disk serial.\n"); #endif @@ -236,7 +236,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } #ifdef _WIN32 - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { if (state->parity_device[l] == 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Disk '%s' has a zero serial number.\n", state->parity_path[l]); @@ -259,29 +259,29 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } #endif - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { unsigned j; - for(j=l+1;jlevel;++j) { + for (j = l + 1; j < state->level; ++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]); + fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", state->parity_device[l]); fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); fprintf(stderr, "to change one of the disk serial.\n"); -#endif +#endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } } } - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++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); + fprintf(stderr, "Both have the serial number '%" PRIx64 "'.\n", state->pool_device); fprintf(stderr, "Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); fprintf(stderr, "to change one of the disk serial.\n"); #endif @@ -296,12 +296,12 @@ static void state_config_check(struct snapraid_state* state, const char* path, t unsigned content_count; content_count = 0; - for(i=state->contentlist;i!=0;i=i->next) { + for (i = state->contentlist; i != 0; i = i->next) { tommy_node* j; struct snapraid_content* content = i->data; /* check if there are others in the same disk */ - for(j=i->next;j!=0;j=j->next) { + for (j = i->next; j != 0; j = j->next) { struct snapraid_content* other = j->data; if (content->device == other->device) { break; @@ -315,9 +315,9 @@ static void state_config_check(struct snapraid_state* state, const char* path, t ++content_count; } - if (content_count < state->level+1) { + 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); + fprintf(stderr, "You must have at least %d 'content' files in different disks.\n", state->level + 1); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -338,10 +338,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } /* ensure that specified filter disks are valid ones */ - for(i=tommy_list_head(filterlist_disk);i!=0;i=i->next) { + for (i = tommy_list_head(filterlist_disk); i != 0; i = i->next) { tommy_node* j; struct snapraid_filter* filter = i->data; - for(j=state->disklist;j!=0;j=j->next) { + for (j = state->disklist; j != 0; j = j->next) { struct snapraid_disk* disk = j->data; if (fnmatch(filter->pattern, disk->name, FNM_CASEINSENSITIVE_FOR_WIN) == 0) break; @@ -354,7 +354,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } } - + } void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt, tommy_list* filterlist_disk) @@ -417,7 +417,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co sgetspace(f); if (strcmp(tag, "blocksize") == 0 - /* block_size is the old format of the option */ + /* block_size is the old format of the option */ || strcmp(tag, "block_size") == 0) { ret = sgetu32(f, &state->block_size); @@ -433,7 +433,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - if (state->block_size > 16*1024) { + if (state->block_size > 16 * 1024) { /* LCOV_EXCL_START */ fprintf(stderr, "Too big 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); @@ -476,7 +476,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co level = 2; state->raid_mode = RAID_MODE_VANDERMONDE; break; - default: + default : /* LCOV_EXCL_START */ fprintf(stderr, "Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); @@ -622,7 +622,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } /* check if the content file is already specified */ - for(i=state->contentlist;i!=0;i=i->next) { + for (i = state->contentlist; i != 0; i = i->next) { content = i->data; if (pathcmp(content->content, buffer) == 0) break; @@ -705,7 +705,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } /* check if the disk name already exists */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { disk = i->data; if (strcmp(disk->name, buffer) == 0) break; @@ -879,13 +879,13 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* intentionally not set the prevhashseed, if used valgrind will warn about it */ fprintf(stdlog, "blocksize:%u\n", state->block_size); - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; fprintf(stdlog, "disk:%s:%s\n", disk->name, disk->dir); } fprintf(stdlog, "mode:%s\n", lev_raid_name(state->raid_mode, state->level)); - for(l=0;llevel;++l) + for (l = 0; l < state->level; ++l) fprintf(stdlog, "%s:%s\n", lev_config_name(l), state->parity_path[l]); if (state->pool[0] != 0) fprintf(stdlog, "pool:%s\n", state->pool); @@ -906,12 +906,12 @@ static void state_map(struct snapraid_state* state) /* this happens when a disk is removed from the configuration file */ /* From SnapRAID 4.0 mappings are automatically removed if a disk is not used */ /* when saving the content file, but we keep this code to import older content files. */ - for(i=state->maplist;i!=0;) { + for (i = state->maplist; i != 0; ) { struct snapraid_map* map = i->data; struct snapraid_disk* disk; tommy_node* j; - for(j=state->disklist;j!=0;j=j->next) { + for (j = state->disklist; j != 0; j = j->next) { disk = j->data; if (strcmp(disk->name, map->name) == 0) { /* disk found */ @@ -921,8 +921,8 @@ static void state_map(struct snapraid_state* state) /* go to the next mapping before removing */ i = i->next; - - if (j==0) { + + if (j == 0) { /* disk not found, remove the mapping */ tommy_list_remove_existing(&state->maplist, &map->node); map_free(map); @@ -932,32 +932,32 @@ static void state_map(struct snapraid_state* state) /* maps each unmapped disk present in the configuration file in the first available hole */ /* this happens when you add disks for the first time in the configuration file */ hole = 0; /* first position to try */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; struct snapraid_map* map; tommy_node* j; /* check if the disk is already mapped */ - for(j=state->maplist;j!=0;j=j->next) { + for (j = state->maplist; j != 0; j = j->next) { map = j->data; if (strcmp(disk->name, map->name) == 0) { /* mapping found */ break; } } - if (j!=0) + if (j != 0) continue; /* mapping not found, search for an hole */ while (1) { - for(j=state->maplist;j!=0;j=j->next) { + for (j = state->maplist; j != 0; j = j->next) { map = j->data; if (map->position == hole) { /* position already used */ break; } } - if (j==0) { + if (j == 0) { /* hole found */ break; } @@ -978,14 +978,14 @@ static void state_map(struct snapraid_state* state) /* checks if mapping match the disk uuid */ uuid_mismatch = 0; - for(i=state->maplist;i!=0;i=i->next) { + for (i = state->maplist; i != 0; i = i->next) { struct snapraid_map* map = i->data; struct snapraid_disk* disk; tommy_node* j; char uuid[UUID_MAX]; int ret; - for(j=state->disklist;j!=0;j=j->next) { + for (j = state->disklist; j != 0; j = j->next) { disk = j->data; if (strcmp(disk->name, map->name) == 0) { /* disk found */ @@ -993,7 +993,7 @@ static void state_map(struct snapraid_state* state) } } - if (j==0) { + if (j == 0) { /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency for mapping '%s'\n", map->name); exit(EXIT_FAILURE); @@ -1044,7 +1044,7 @@ static void state_map(struct snapraid_state* state) /* count the number of data disks, including holes left after removing some */ diskcount = 0; - for(i=state->maplist;i!=0;i=i->next) { + for (i = state->maplist; i != 0; i = i->next) { struct snapraid_map* map = i->data; if (map->position + 1 > diskcount) @@ -1079,10 +1079,10 @@ static void state_content_check(struct snapraid_state* state, const char* path) tommy_node* i; /* checks that any map has different name and position */ - for(i=state->maplist;i!=0;i=i->next) { + for (i = state->maplist; i != 0; i = i->next) { struct snapraid_map* map = i->data; tommy_node* j; - for(j=i->next;j!=0;j=j->next) { + 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 */ @@ -1110,7 +1110,7 @@ static int position_is_required(struct snapraid_state* state, block_off_t pos) tommy_node* i; /* check for each disk */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; struct snapraid_block* block = disk_block_get(disk, pos); @@ -1139,7 +1139,7 @@ static int info_is_required(struct snapraid_state* state, block_off_t pos) tommy_node* i; /* check for each disk */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; struct snapraid_block* block = disk_block_get(disk, pos); @@ -1156,7 +1156,7 @@ static void position_clear_deleted(struct snapraid_state* state, block_off_t pos tommy_node* i; /* check for each disk if block is really used */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; struct snapraid_block* block = disk_block_get(disk, pos); @@ -1185,7 +1185,7 @@ static struct snapraid_disk* find_disk(struct snapraid_state* state, const char* { tommy_node* i; - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; if (strcmp(disk->name, name) == 0) return disk; @@ -2150,7 +2150,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* to be backward compatible with old context files without info */ /* create info records if missing */ - for(b=0;binfoarr, b); @@ -2204,7 +2204,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) /* clear the info for unused blocks */ /* and get some other info */ info_has_rehash = 0; /* if there is a rehash info */ - for(b=0;binfoarr, b); @@ -2280,7 +2280,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) } /* for each map */ - for(i=state->maplist;i!=0;i=i->next) { + for (i = state->maplist; i != 0; i = i->next) { struct snapraid_map* map = i->data; struct snapraid_disk* disk; @@ -2322,7 +2322,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) } /* for each disk */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { tommy_node* j; struct snapraid_disk* disk = i->data; @@ -2331,7 +2331,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) continue; /* for each file */ - for(j=disk->filelist;j!=0;j=j->next) { + for (j = disk->filelist; j != 0; j = j->next) { struct snapraid_file* file = j->data; uint64_t size; uint64_t mtime_sec; @@ -2366,7 +2366,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) } /* for each block in the file */ - for(b=0;bblockmax;++b) { + for (b = 0; b < file->blockmax; ++b) { struct snapraid_block* block = &file->blockvec[b]; unsigned block_state = block_state_get(block); @@ -2388,7 +2388,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) case BLOCK_STATE_REP : sputsl("rep ", f); break; - default: + default : /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency in state for block %u state %u\n", block->parity_pos, block_state); exit(EXIT_FAILURE); @@ -2415,7 +2415,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) } /* for each link */ - for(j=disk->linklist;j!=0;j=j->next) { + for (j = disk->linklist; j != 0; j = j->next) { struct snapraid_link* link = j->data; switch (link_flag_get(link, FILE_IS_LINK_MASK)) { @@ -2445,7 +2445,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) } /* for each dir */ - for(j=disk->dirlist;j!=0;j=j->next) { + for (j = disk->dirlist; j != 0; j = j->next) { struct snapraid_dir* dir = j->data; sputsl("dir ", f); @@ -2473,7 +2473,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - for(b=0;binfoarr, b); /* save only stuffs different than 0 */ @@ -2555,7 +2555,7 @@ static void decoding_error(const char* path, STREAM* f) if (seof(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Unexpected end of content file '%s' at offset %"PRIi64"\n", path, stell(f)); + 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 */ @@ -2563,12 +2563,12 @@ static void decoding_error(const char* path, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading the content file '%s' at offset %"PRIi64"\n", path, stell(f)); + 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)); + fprintf(stderr, "Decoding error in '%s' at offset %" PRIi64 "\n", path, stell(f)); buf[0] = 0; buf[1] = 0; @@ -2591,7 +2591,7 @@ 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)); + fprintf(stderr, "Error flushing the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2840,7 +2840,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST case 'p' : block_state_set(block, BLOCK_STATE_REP); break; - default: + default : /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid block type!\n"); @@ -3123,7 +3123,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* go to the next run */ v_pos += v_count; break; - default: + default : /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid hole type!\n"); @@ -3283,7 +3283,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST case 'k' : state->hash = HASH_SPOOKY2; break; - default: + default : /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid checksum!\n"); @@ -3310,7 +3310,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST case 'k' : state->prevhash = HASH_SPOOKY2; break; - default: + default : /* LCOV_EXCL_START */ decoding_error(path, f); fprintf(stderr, "Invalid checksum!\n"); @@ -3419,7 +3419,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST 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, "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 */ @@ -3448,7 +3448,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (serror(f)) { /* LCOV_EXCL_START */ - fprintf(stderr, "Error reading the content file '%s' at offset %"PRIi64"\n", path, stell(f)); + fprintf(stderr, "Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3464,7 +3464,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* 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)); + fprintf(stderr, "Internal inconsistency in parity size in '%s' at offset %" PRIi64 "\n", path, stell(f)); if (state->opt.skip_content_check) { fprintf(stderr, "Overriding from %u to %u.\n", blockmax, parity_size(state)); blockmax = parity_size(state); @@ -3514,7 +3514,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* and get some other info */ info_oldest = 0; /* oldest time in info */ info_has_rehash = 0; /* if there is a rehash info */ - for(b=0;binfoarr, b); @@ -3599,7 +3599,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* for each map */ mapping_idx = 0; - for(i=state->maplist;i!=0;i=i->next) { + for (i = state->maplist; i != 0; i = i->next) { struct snapraid_map* map = i->data; struct snapraid_disk* disk; @@ -3635,7 +3635,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) } /* for each disk */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { tommy_node* j; struct snapraid_disk* disk = i->data; @@ -3644,7 +3644,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) continue; /* for each file */ - for(j=disk->filelist;j!=0;j=j->next) { + for (j = disk->filelist; j != 0; j = j->next) { struct snapraid_file* file = j->data; struct snapraid_block* blockvec = file->blockvec; uint64_t size; @@ -3681,15 +3681,15 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) unsigned block_state = block_state_get(blockvec + begin); uint32_t v_pos = blockvec[begin].parity_pos; uint32_t v_count; - + block_off_t end; /* find the end of run of blocks */ end = begin + 1; while (end < file->blockmax && block_state == block_state_get(blockvec + end) - && blockvec[end-1].parity_pos + 1 == blockvec[end].parity_pos) - { + && blockvec[end - 1].parity_pos + 1 == blockvec[end].parity_pos + ) { ++end; } @@ -3703,7 +3703,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) case BLOCK_STATE_REP : sputc('p', f); break; - default: + default : /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency in state for block %u state %u\n", v_pos, block_state); exit(EXIT_FAILURE); @@ -3716,7 +3716,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputb32(v_count, f); /* write hashes */ - for(b=begin;blinklist;j!=0;j=j->next) { + for (j = disk->linklist; j != 0; j = j->next) { struct snapraid_link* link = j->data; switch (link_flag_get(link, FILE_IS_LINK_MASK)) { @@ -3773,7 +3773,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) } /* for each dir */ - for(j=disk->dirlist;j!=0;j=j->next) { + for (j = disk->dirlist; j != 0; j = j->next) { struct snapraid_dir* dir = j->data; sputc('r', f); @@ -3808,8 +3808,8 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* find the end of run of blocks */ end = begin + 1; while (end < blockmax - && is_deleted == is_block_deleted(disk, end)) - { + && is_deleted == is_block_deleted(disk, end) + ) { ++end; } @@ -3868,8 +3868,8 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* find the end of run of blocks */ end = begin + 1; while (end < blockmax - && info == info_get(&state->infoarr, end)) - { + && info == info_get(&state->infoarr, end) + ) { ++end; } @@ -4011,7 +4011,7 @@ void state_read(struct snapraid_state* state) if (other_st.st_size != st.st_size) { fprintf(stderr, "WARNING! Content files '%s' and '%s' have a different size!\n", path, other_path); fprintf(stderr, "Likely one of the two is broken!\n"); - + /* ensure to rewrite all the content files */ state->need_write = 1; } @@ -4174,14 +4174,14 @@ void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tom if (state->opt.verbose) { tommy_node* k; - for(k=tommy_list_head(filterlist_disk);k!=0;k=k->next) { + for (k = tommy_list_head(filterlist_disk); k != 0; k = k->next) { struct snapraid_filter* filter = k->data; printf("\t%s", filter->pattern); if (filter->is_disk) printf("//"); printf("\n"); } - for(k=tommy_list_head(filterlist_file);k!=0;k=k->next) { + for (k = tommy_list_head(filterlist_file); k != 0; k = k->next) { struct snapraid_filter* filter = k->data; printf("\t%s", filter->pattern); if (filter->is_dir) @@ -4195,7 +4195,7 @@ void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tom } /* for each disk */ - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { tommy_node* j; struct snapraid_disk* disk = i->data; @@ -4204,7 +4204,7 @@ void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tom printf("Scanning disk %s...\n", disk->name); /* for each file */ - for(j=tommy_list_head(&disk->filelist);j!=0;j=j->next) { + for (j = tommy_list_head(&disk->filelist); j != 0; j = j->next) { struct snapraid_file* file = j->data; if (filter_path(filterlist_disk, disk->name, file->sub) != 0 @@ -4217,7 +4217,7 @@ void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tom } /* for each link */ - for(j=tommy_list_head(&disk->linklist);j!=0;j=j->next) { + for (j = tommy_list_head(&disk->linklist); j != 0; j = j->next) { struct snapraid_link* link = j->data; if (filter_path(filterlist_disk, disk->name, link->sub) != 0 @@ -4229,7 +4229,7 @@ void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tom } /* for each dir */ - for(j=tommy_list_head(&disk->dirlist);j!=0;j=j->next) { + for (j = tommy_list_head(&disk->dirlist); j != 0; j = j->next) { struct snapraid_dir* dir = j->data; if (filter_dir(filterlist_disk, disk->name, dir->sub) != 0 @@ -4245,7 +4245,7 @@ void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tom int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, block_off_t blockmax, block_off_t countmax) { if (state->opt.gui) { - fprintf(stdlog,"run:begin:%u:%u:%u\n", blockstart, blockmax, countmax); + fprintf(stdlog, "run:begin:%u:%u:%u\n", blockstart, blockmax, countmax); fflush(stdlog); } else { time_t now; @@ -4283,7 +4283,7 @@ void state_progress_end(struct snapraid_state* state, block_off_t countpos, bloc time_t now; time_t elapsed; - unsigned countsize_MiB = (countsize + 1024*1024 - 1) / (1024*1024); + unsigned countsize_MiB = (countsize + 1024 * 1024 - 1) / (1024 * 1024); now = time(0); @@ -4309,7 +4309,7 @@ void state_progress_stop(struct snapraid_state* state) now = time(0); printf("\n"); - + state->progress_interruption = now; } @@ -4330,7 +4330,7 @@ void state_progress_restart(struct snapraid_state* state) int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off_t countpos, block_off_t countmax, data_off_t countsize) { if (state->opt.gui) { - fprintf(stdlog, "run:pos:%u:%u:%"PRIu64"\n", blockpos, countpos, countsize); + fprintf(stdlog, "run:pos:%u:%u:%" PRIu64 "\n", blockpos, countpos, countsize); fflush(stdlog); } else { time_t now; @@ -4351,7 +4351,7 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off tick_total = state->tick_cpu + state->tick_io; tick_cpu = state->tick_cpu; - printf("%u%%, %u MiB", countpos * 100 / countmax, (unsigned)(countsize / (1024*1024))); + printf("%u%%, %u MiB", countpos * 100 / countmax, (unsigned)(countsize / (1024 * 1024))); /* if we have at least 5 measures */ if (state->progress_tick >= 5) { @@ -4389,10 +4389,10 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off delta_tick_cpu = tick_cpu - state->progress_tick_cpu[oldest]; if (delta_time != 0) - printf(", %u MiB/s", (unsigned)(delta_size / (1024*1024) / delta_time)); + printf(", %u MiB/s", (unsigned)(delta_size / (1024 * 1024) / delta_time)); if (delta_tick_total != 0) - printf(", CPU %"PRIu64"%%", delta_tick_cpu * 100U / delta_tick_total); + printf(", CPU %" PRIu64 "%%", delta_tick_cpu * 100U / delta_tick_total); /* estimate the remaining time */ if (delta_pos != 0) { @@ -4452,13 +4452,13 @@ void state_usage_print(struct snapraid_state* state) tick_max = 0; tick_total = 0; - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; tick_total += disk->tick; if (disk->tick > tick_max) tick_max = disk->tick; } - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { tick_total += state->tick_parity[l]; if (state->tick_parity[l] > tick_max) tick_max = state->tick_parity[l]; @@ -4468,23 +4468,23 @@ void state_usage_print(struct snapraid_state* state) return; printf("Time for disk:"); - for(i=state->disklist;i!=0;i=i->next) { + for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; if (disk->tick == tick_max) printf(" %s:", disk->name); else printf(" "); - printf("%"PRIu64"%%", disk->tick * 100U / tick_total); + printf("%" PRIu64 "%%", disk->tick * 100U / tick_total); } printf("\n"); printf("Time for parity:"); - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { if (state->tick_parity[l] == tick_max) printf(" %s:", lev_config_name(l)); else printf(" "); - printf("%"PRIu64"%%", state->tick_parity[l] * 100U / tick_total); + printf("%" PRIu64 "%%", state->tick_parity[l] * 100U / tick_total); } printf("\n"); } @@ -4516,7 +4516,7 @@ void generate_configuration(const char* path) printf("# Use this blocksize\n"); printf("blocksize %u\n", state.block_size / 1024); printf("\n"); - for(i=0;inext) { + for (j = state.maplist; j; j = j->next) { struct snapraid_map* map = j->data; struct snapraid_disk* disk; printf("# Set the correct dir for disk '%s'\n", map->name); diff --git a/cmdline/status.c b/cmdline/status.c index f5dc1bb2..9a36f391 100644 --- a/cmdline/status.c +++ b/cmdline/status.c @@ -67,7 +67,7 @@ int state_status(struct snapraid_state* state) file_size = 0; file_fragmented = 0; extra_fragment = 0; - for(node_disk=state->disklist;node_disk!=0;node_disk=node_disk->next) { + for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) { struct snapraid_disk* disk = node_disk->data; tommy_node* node; unsigned disk_file_count = 0; @@ -90,7 +90,7 @@ int state_status(struct snapraid_state* state) fragmented = 0; prev_pos = file->blockvec[0].parity_pos; - for(i=1;iblockmax;++i) { + for (i = 1; i < file->blockmax; ++i) { block_off_t parity_pos = file->blockvec[i].parity_pos; if (prev_pos + 1 != parity_pos) { fragmented = 1; @@ -116,7 +116,7 @@ int state_status(struct snapraid_state* state) fprintf(stdlog, "summary:disk_file_count:%s:%u\n", disk->name, disk_file_count); fprintf(stdlog, "summary:disk_fragmented_file_count:%s:%u\n", disk->name, disk_file_fragmented); fprintf(stdlog, "summary:disk_excess_fragment_count:%s:%u\n", disk->name, disk_extra_fragment); - fprintf(stdlog, "summary:disk_file_size:%s:%"PRIu64"\n", disk->name, disk_file_size); + fprintf(stdlog, "summary:disk_file_size:%s:%" PRIu64 "\n", disk->name, disk_file_size); } printf("\n"); @@ -124,16 +124,16 @@ int state_status(struct snapraid_state* state) printf("Files: %u\n", file_count); printf("Fragmented files: %u\n", file_fragmented); printf("Excess fragments: %u\n", extra_fragment); - printf("Files size: %"PRIu64" GiB\n", file_size / (1024*1024*1024) ); - printf("Parity size: %"PRIu64" GiB\n", blockmax * (uint64_t)state->block_size / (1024*1024*1024) ); + printf("Files size: %" PRIu64 " GiB\n", file_size / (1024 * 1024 * 1024) ); + printf("Parity size: %" PRIu64 " GiB\n", blockmax * (uint64_t)state->block_size / (1024 * 1024 * 1024) ); printf("\n"); fprintf(stdlog, "summary:file_count:%u\n", file_count); fprintf(stdlog, "summary:fragmented_file_count:%u\n", file_fragmented); fprintf(stdlog, "summary:excess_fragment_count:%u\n", extra_fragment); - fprintf(stdlog, "summary:file_size:%"PRIu64"\n", file_size); - fprintf(stdlog, "summary:parity_size:%"PRIu64"\n", blockmax * (uint64_t)state->block_size); + fprintf(stdlog, "summary:file_size:%" PRIu64 "\n", file_size); + fprintf(stdlog, "summary:parity_size:%" PRIu64 "\n", blockmax * (uint64_t)state->block_size); fprintf(stdlog, "summary:hash:%s\n", hash_config_name(state->hash)); fprintf(stdlog, "summary:prev_hash:%s\n", hash_config_name(state->prevhash)); fprintf(stdlog, "summary:best_hash:%s\n", hash_config_name(state->besthash)); @@ -146,7 +146,7 @@ int state_status(struct snapraid_state* state) rehash = 0; unsynced_blocks = 0; fprintf(stdlog, "block_count:%u\n", blockmax); - for(i=0;idisklist;node_disk!=0;node_disk=node_disk->next) { + for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) { struct snapraid_disk* disk = node_disk->data; struct snapraid_block* block = disk_block_get(disk, i); @@ -183,9 +183,9 @@ int state_status(struct snapraid_state* state) if (state->opt.gui) { if (info != 0) - fprintf(stdlog, "block:%u:%"PRIu64":%s:%s:%s:%s\n", i, (uint64_t)info_get_time(info), one_valid ? "used": "", one_invalid ? "unsynced" : "", info_get_bad(info) ? "bad" : "", info_get_rehash(info) ? "rehash" : ""); + fprintf(stdlog, "block:%u:%" PRIu64 ":%s:%s:%s:%s\n", i, (uint64_t)info_get_time(info), one_valid ? "used" : "", one_invalid ? "unsynced" : "", info_get_bad(info) ? "bad" : "", info_get_rehash(info) ? "rehash" : ""); else - fprintf(stdlog, "block_noinfo:%u:%s:%s\n", i, one_valid ? "used": "", one_invalid ? "unsynced" : ""); + fprintf(stdlog, "block_noinfo:%u:%s:%s\n", i, one_valid ? "used" : "", one_invalid ? "unsynced" : ""); } } @@ -210,7 +210,7 @@ int state_status(struct snapraid_state* state) unsigned j = i + 1; while (j < count && info_get_time(infomap[i]) == info_get_time(infomap[j])) ++j; - fprintf(stdlog, "info_time:%"PRIu64":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); + fprintf(stdlog, "info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); i = j; } @@ -224,11 +224,11 @@ int state_status(struct snapraid_state* state) /* compute graph limits */ barpos = 0; barmax = 0; - for(i=0;i= pivot) { printf("*"); } else if (bar[x] > 0) { @@ -307,13 +307,13 @@ int state_status(struct snapraid_state* state) printf("They are at blocks:"); /* print all the errors */ - for(i=0;iinfoarr, i); /* skip unused blocks */ if (info == 0) continue; - + if (info_get_bad(info)) printf(" %u", i); } diff --git a/cmdline/sync.c b/cmdline/sync.c index e483a0a6..6c26a4af 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -53,14 +53,14 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* first count the number of blocks to process */ countmax = 0; - for(j=0;jname, file->sub); if (handle[j].st.st_size != file->size) { - fprintf(stderr, "Unexpected size change at file '%s' from %"PRIu64" to %"PRIu64".\n", handle[j].path, file->size, handle[j].st.st_size); + fprintf(stderr, "Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); } else if (handle[j].st.st_mtime != file->mtime_sec || STAT_NSEC(&handle[j].st) != file->mtime_nsec) { - fprintf(stderr, "Unexpected time change at file '%s' from %"PRIu64".%d to %"PRIu64".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); + fprintf(stderr, "Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); } else { - fprintf(stderr, "Unexpected inode change from %"PRIu64" to %"PRIu64" at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); + fprintf(stderr, "Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); } fprintf(stderr, "WARNING! You cannot modify files during a sync.\n"); fprintf(stderr, "Rerun the sync command when finished.\n"); @@ -290,7 +290,7 @@ end: fprintf(stdlog, "hash_summary:error_readwrite:%u\n", error); bail: - for(j=0;jblock_size, buffer); /* fill up the zero buffer */ - memset(buffer[buffermax-1], 0, state->block_size); - raid_zero(buffer[buffermax-1]); + memset(buffer[buffermax - 1], 0, state->block_size); + raid_zero(buffer[buffermax - 1]); failed = malloc_nofail(diskmax * sizeof(struct failed_struct)); failed_map = malloc_nofail(diskmax * sizeof(unsigned)); @@ -383,14 +383,14 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* first count the number of blocks to process */ countmax = 0; - for(i=blockstart;iname, file->sub, strerror(errno)); fprintf(stderr, "DANGER! Unexpected open error in a data disk, it isn't possible to sync.\n"); @@ -618,12 +618,12 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari struct snapraid_file* file = block_file_get(block); fprintf(stdlog, "error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, file->sub); if (handle[j].st.st_size != file->size) { - fprintf(stderr, "Unexpected size change at file '%s' from %"PRIu64" to %"PRIu64".\n", handle[j].path, file->size, handle[j].st.st_size); + fprintf(stderr, "Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); } else if (handle[j].st.st_mtime != file->mtime_sec || STAT_NSEC(&handle[j].st) != file->mtime_nsec) { - fprintf(stderr, "Unexpected time change at file '%s' from %"PRIu64".%d to %"PRIu64".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); + fprintf(stderr, "Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); } else { - fprintf(stderr, "Unexpected inode change from %"PRIu64" to %"PRIu64" at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); + fprintf(stderr, "Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); } fprintf(stderr, "WARNING! You cannot modify files during a sync.\n"); fprintf(stderr, "Rerun the sync command when finished.\n"); @@ -733,7 +733,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari parity_needs_to_be_updated = 1; } } - + /* copy the hash in the block, but doesn't mark the block as hashed */ /* this allow in case of skipped block to do not save the failed computation */ memcpy(block->hash, hash, HASH_SIZE); @@ -752,7 +752,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* setup the blocks to recover */ failed_mac = 0; - for(j=0;jlevel + failed[j].index]; unsigned block_state = block_state_get(failed[j].block); @@ -789,8 +789,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* read the parity */ /* we are sure that parity exists because */ /* we have at least one BLK block */ - for(l=0;llevel;++l) { - ret = parity_read(parity[l], i, buffer[diskmax+l], state->block_size, stdlog); + for (l = 0; l < state->level; ++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)); @@ -810,7 +810,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari raid_rec(failed_mac, failed_map, diskmax, state->level, state->block_size, buffer); /* check the result and prepare the data */ - for(j=0;jlevel + failed[j].index]; @@ -862,8 +862,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari state_usage_cpu(state); /* write the parity */ - for(l=0;llevel;++l) { - ret = parity_write(parity[l], i, buffer[diskmax+l], state->block_size); + for (l = 0; l < state->level; ++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)); @@ -881,7 +881,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } /* for each disk, mark the blocks as processed */ - for(j=0;jhash, rehandle[j].hash, HASH_SIZE); } @@ -993,7 +993,7 @@ end: fflush(stdlog); bail: - for(j=0;jlevel;++l) { + for (l = 0; l < state->level; ++l) { /* create the file and open for writing */ parity_ptr[l] = &parity[l]; ret = parity_create(parity_ptr[l], state->parity_path[l], &out_size, state->file_mode); @@ -1118,7 +1118,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t } } - for(l=0;llevel;++l) { + for (l = 0; l < state->level; ++l) { ret = parity_sync(parity_ptr[l]); if (ret == -1) { /* LCOV_EXCL_START */ diff --git a/cmdline/unix.c b/cmdline/unix.c index f02f4bf9..77fee7e3 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -209,7 +209,7 @@ int fsinfo(const char* path, int* has_persistent_inode) { #if HAVE_STATFS && HAVE_STRUCT_STATFS_F_TYPE struct statfs st; - + if (statfs(path, &st) != 0) return -1; @@ -220,7 +220,7 @@ int fsinfo(const char* path, int* has_persistent_inode) case 0x4d44 : /* VFAT, "msdos" in the stat command */ *has_persistent_inode = 0; break; - default: + default : /* by default assume yes */ *has_persistent_inode = 1; break; diff --git a/cmdline/util.c b/cmdline/util.c index 482d849b..e0757e49 100644 --- a/cmdline/util.c +++ b/cmdline/util.c @@ -102,7 +102,7 @@ STREAM* sopen_multi_write(unsigned count) s->handle_size = count; s->handle = malloc_nofail(count * sizeof(struct stream_handle)); - for(i=0;ihandle[i].f = -1; s->buffer = malloc_nofail(STREAM_SIZE); @@ -163,7 +163,7 @@ int sclose(STREAM* s) } } - for(i=0;ihandle_size;++i) { + for (i = 0; i < s->handle_size; ++i) { if (close(s->handle[i].f) != 0) { /* LCOV_EXCL_START */ fail = 1; @@ -252,7 +252,7 @@ int sflush(STREAM* s) s->crc = crc32c(s->crc, s->buffer, size); s->crc_uncached = s->crc; - for(i=0;ihandle_size;++i) { + for (i = 0; i < s->handle_size; ++i) { ret = write(s->handle[i].f, s->buffer, size); if (ret != size) { @@ -424,7 +424,7 @@ int sgetlasttok(STREAM* f, char* str, int size) /* LCOV_EXCL_STOP */ } - while (ret > 0 && (str[ret-1] == ' ' || str[ret-1] == '\t')) + while (ret > 0 && (str[ret - 1] == ' ' || str[ret - 1] == '\t')) --ret; str[ret] = 0; @@ -437,13 +437,13 @@ int sgetu32(STREAM* f, uint32_t* value) int c; c = sgetc(f); - if (c>='0' && c<='9') { + if (c >= '0' && c <= '9') { uint32_t v; v = c - '0'; c = sgetc(f); - while (c>='0' && c<='9') { + while (c >= '0' && c <= '9') { v *= 10; v += c - '0'; c = sgetc(f); @@ -466,13 +466,13 @@ int sgetu64(STREAM* f, uint64_t* value) int c; c = sgetc(f); - if (c>='0' && c<='9') { + if (c >= '0' && c <= '9') { uint64_t v; v = c - '0'; c = sgetc(f); - while (c>='0' && c<='9') { + while (c >= '0' && c <= '9') { v *= 10; v += c - '0'; c = sgetc(f); @@ -872,7 +872,7 @@ int ssync(STREAM* s) { unsigned i; - for(i=0;ihandle_size;++i) { + for (i = 0; i < s->handle_size; ++i) { if (fsync(s->handle[i].f) != 0) { /* LCOV_EXCL_START */ s->state = STREAM_STATE_ERROR; @@ -1314,7 +1314,7 @@ void pathprint(char* dst, size_t size, const char* format, ...) { size_t len; va_list ap; - + va_start(ap, format); len = vsnprintf(dst, size, format, ap); va_end(ap); @@ -1340,7 +1340,7 @@ void pathslash(char* dst, size_t size) } dst[len] = '/'; - dst[len+1] = 0; + dst[len + 1] = 0; } } @@ -1589,12 +1589,12 @@ void** malloc_nofail_vector_align(int nd, int n, size_t size, void** freeptr) return ptr; } -void mrand_vector(int n , size_t size, void** vv) +void mrand_vector(int n, size_t size, void** vv) { raid_mrand_vector(n, size, vv); } -void mtest_vector(int n , size_t size, void** vv) +void mtest_vector(int n, size_t size, void** vv) { if (raid_mtest_vector(n, size, vv) != 0) { /* LCOV_EXCL_START */ @@ -1642,15 +1642,15 @@ static inline uint64_t util_rotl64(uint64_t x, int8_t r) static inline uint32_t util_swap32(uint32_t v) { return (util_rotl32(v, 8) & 0x00ff00ff) - | (util_rotl32(v, 24) & 0xff00ff00); + | (util_rotl32(v, 24) & 0xff00ff00); } static inline uint64_t util_swap64(uint64_t v) { return (util_rotl64(v, 8) & 0x000000ff000000ffULL) - | (util_rotl64(v, 24) & 0x0000ff000000ff00ULL) - | (util_rotl64(v, 40) & 0x00ff000000ff0000ULL) - | (util_rotl64(v, 56) & 0xff000000ff000000ULL); + | (util_rotl64(v, 24) & 0x0000ff000000ff00ULL) + | (util_rotl64(v, 40) & 0x00ff000000ff0000ULL) + | (util_rotl64(v, 56) & 0xff000000ff000000ULL); } #endif @@ -1669,7 +1669,7 @@ void memhash(unsigned kind, const unsigned char* seed, void* digest, const void* case HASH_SPOOKY2 : SpookyHash128(src, size, seed, digest); break; - default: + default : /* LCOV_EXCL_START */ fprintf(stderr, "Internal inconsistency in hash function %u\n", kind); exit(EXIT_FAILURE); @@ -1684,7 +1684,7 @@ const char* hash_config_name(unsigned kind) case HASH_UNDEFINED : return "undefined"; case HASH_MURMUR3 : return "murmur3"; case HASH_SPOOKY2 : return "spooky2"; - default: + default : /* LCOV_EXCL_START */ return "unknown"; /* LCOV_EXCL_STOP */ @@ -1699,7 +1699,7 @@ void randomize(void* void_ptr, unsigned size) unsigned char* ptr = void_ptr; unsigned i; - for(i=0;i