From 5aa1563675fd1cdd10936481d82df7a91e053521 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 4 Jun 2026 00:34:51 +0200 Subject: [PATCH] Further conversions from 32 to 64 bits --- cmdline/bw.c | 4 ++- cmdline/check.c | 48 +++++++++++++------------- cmdline/device.c | 6 ++-- cmdline/dry.c | 2 +- cmdline/elem.c | 4 +-- cmdline/elem.h | 4 +-- cmdline/handle.c | 8 ++--- cmdline/handle.h | 2 +- cmdline/import.c | 10 +++--- cmdline/import.h | 2 +- cmdline/io.h | 2 +- cmdline/mktest.c | 30 ++++++++--------- cmdline/pool.c | 2 +- cmdline/portable.h | 2 +- cmdline/scan.c | 2 +- cmdline/scrub.c | 4 +-- cmdline/search.c | 2 +- cmdline/snapraid.c | 12 +++---- cmdline/state.c | 32 +++++++++--------- cmdline/state.h | 12 +++---- cmdline/status.c | 12 ++++--- cmdline/stream.c | 24 ++++++------- cmdline/stream.h | 14 ++++---- cmdline/support.c | 84 ++++++++++++++++++++++++++++++++++++++++++++-- cmdline/support.h | 10 ++++++ cmdline/sync.c | 8 ++--- cmdline/unix.c | 44 ++++++++++++------------ cmdline/util.c | 6 ++-- cmdline/util.h | 14 ++++---- configure.ac | 1 + 30 files changed, 251 insertions(+), 156 deletions(-) diff --git a/cmdline/bw.c b/cmdline/bw.c index cba2595d..92852c7c 100644 --- a/cmdline/bw.c +++ b/cmdline/bw.c @@ -27,7 +27,9 @@ void bw_limit(struct snapraid_bw* bw, uint64_t bytes) if (eta > elapsed) { eta -= elapsed; - usleep(eta * 1000); + if (eta > 1000) + eta = 1000; + usleep((unsigned)eta * 1000); } } diff --git a/cmdline/check.c b/cmdline/check.c index 3998e3f4..2adeae65 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -61,7 +61,7 @@ struct failed_struct { * Check if a block hash matches the specified buffer. * Return ==0 if equal */ -static int blockcmp(struct snapraid_state* state, int rehash, struct snapraid_block* block, unsigned pos_size, unsigned char* buffer, unsigned char* buffer_zero) +static int blockcmp(struct snapraid_state* state, int rehash, struct snapraid_block* block, size_t pos_size, unsigned char* buffer, unsigned char* buffer_zero) { unsigned char hash[HASH_MAX]; @@ -105,7 +105,7 @@ static int is_hash_matching(struct snapraid_state* state, int rehash, unsigned d && block_has_updated_hash(failed[failed_map[j]].block) ) { /* if a hash doesn't match, fail the check */ - unsigned pos_size = file_block_size(failed[failed_map[j]].file, failed[failed_map[j]].file_pos, state->block_size); + size_t pos_size = file_block_size(failed[failed_map[j]].file, failed[failed_map[j]].file_pos, state->block_size); if (blockcmp(state, rehash, failed[failed_map[j]].block, pos_size, buffer[failed[failed_map[j]].index], buffer_zero) != 0) { log_tag("repair_hash_error:%u: Hash mismatch\n", failed_map[j]); return 0; @@ -157,7 +157,7 @@ static int is_parity_matching(struct snapraid_state* state, unsigned diskmax, un * Return <0 if failure for missing strategy, >0 if data is wrong and we cannot rebuild correctly, 0 on success. * If success, the parity is computed in the buffer variable. */ -static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, unsigned diskmax, struct failed_struct* failed, unsigned* failed_map, unsigned failed_count, void** buffer, void** buffer_recov, void* buffer_zero) +static int repair_step(struct snapraid_state* state, int rehash, block_off_t pos, unsigned diskmax, struct failed_struct* failed, unsigned* failed_map, unsigned failed_count, void** buffer, void** buffer_recov, void* buffer_zero) { unsigned i, n; int error; @@ -179,7 +179,7 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u /* if failures exceed parity level, recovery is impossible */ if (failed_count > n) { - log_tag("recover_strategy_error:%u: Impossible to recover from %u failures with %u parity\n", + log_tag("recover_strategy_error:%" PRIu64 ": Impossible to recover from %u failures with %u parity\n", pos, failed_count, n); return -1; } @@ -233,7 +233,7 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u return 0; /* log */ - log_tag("recover_parity_error:%u:", pos); + log_tag("recover_parity_error:%" PRIu64 ":", pos); for (i = 0; i < r; ++i) { if (i != 0) log_tag(","); @@ -275,7 +275,7 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u return 0; /* log */ - log_tag("recover_hash_error:%u:", pos); + log_tag("recover_hash_error:%" PRIu64 ":", pos); for (i = 0; i < r; ++i) { if (i != 0) log_tag("/"); @@ -290,12 +290,12 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u if (error) return error; - log_tag("recover_strategy_error:%u: No strategy to recover from %u failures with %u parity %s hash\n", + log_tag("recover_strategy_error:%" PRIu64 ": No strategy to recover from %u failures with %u parity %s hash\n", pos, failed_count, n, has_hash ? "with" : "without"); return -1; } -static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsigned diskmax, struct failed_struct* failed, unsigned* failed_map, unsigned failed_count, void** buffer, void** buffer_recov, void* buffer_zero) +static int repair(struct snapraid_state* state, int rehash, block_off_t pos, unsigned diskmax, struct failed_struct* failed, unsigned* failed_map, unsigned failed_count, void** buffer, void** buffer_recov, void* buffer_zero) { int ret; int error; @@ -404,7 +404,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* if nothing to fix */ if (!something_to_recover) { - log_tag("recover_sync:%u:%u: Skipped for already recovered\n", pos, n); + log_tag("recover_sync:%" PRIu64 ":%u: Skipped for already recovered\n", pos, n); /* recompute only the parity */ raid_gen(diskmax, state->level, state->block_size, buffer); @@ -467,7 +467,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign * block after the sync has this hash, or that * we restored the block before the 'sync'. */ - unsigned pos_size = file_block_size(failed[j].file, failed[j].file_pos, state->block_size); + size_t pos_size = file_block_size(failed[j].file, failed[j].file_pos, state->block_size); if (blockcmp(state, rehash, failed[j].block, pos_size, buffer[failed[j].index], buffer_zero) == 0) { /* it may contain garbage */ failed[j].is_outofdate = 1; @@ -484,9 +484,9 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign error += ret; if (ret < 0) - log_tag("recover_sync:%u:%u: Failed with no attempts\n", pos, n); + log_tag("recover_sync:%" PRIu64 ":%u: Failed with no attempts\n", pos, n); else - log_tag("recover_sync:%u:%u: Failed with %d attempts\n", pos, n, ret); + log_tag("recover_sync:%" PRIu64 ":%u: Failed with %d attempts\n", pos, n, ret); /* * Now assume that the parity IS NOT updated at the current state, @@ -615,11 +615,11 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign error += ret; if (ret < 0) - log_tag("recover_unsync:%u:%u: Failed with no attempts\n", pos, n); + log_tag("recover_unsync:%" PRIu64 ":%u: Failed with no attempts\n", pos, n); else - log_tag("recover_unsync:%u:%u: Failed with %d attempts\n", pos, n, ret); + log_tag("recover_unsync:%" PRIu64 ":%u: Failed with %d attempts\n", pos, n, ret); } else { - log_tag("recover_unsync:%u:%u: Skipped for%s%s\n", pos, n, + log_tag("recover_unsync:%" PRIu64 ":%u: Skipped for%s%s\n", pos, n, !something_to_recover ? " nothing to recover" : "", !something_unsynced ? " nothing unsynced" : "" ); @@ -643,7 +643,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign * In such case, the check/fix command won't report any information of the * files partially checked. */ -static int file_post(struct snapraid_state* state, int fix, unsigned i, struct snapraid_handle* handle, unsigned diskmax) +static int file_post(struct snapraid_state* state, int fix, block_off_t i, struct snapraid_handle* handle, unsigned diskmax) { unsigned j; int ret; @@ -709,7 +709,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = handle_close(&handle[j]); if (ret != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); + log_tag("%s:%" PRIu64 ":%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ @@ -720,7 +720,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error renaming '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); - log_tag("%s:%u:%s:%s: Rename error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); + log_tag("%s:%" PRIu64 ":%s:%s: Rename error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ @@ -749,7 +749,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = handle_close(&handle[j]); if (ret != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(report->sub), strerror(errno)); + log_tag("%s:%" PRIu64 ":%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(report->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ @@ -762,7 +762,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = handle_open(&handle[j], file, state->file_mode, 0); if (ret != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); + log_tag("%s:%" PRIu64 ":%s:%s: Open error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ @@ -797,7 +797,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = handle_utime(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Time error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); + log_tag("%s:%" PRIu64 ":%s:%s: Time error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); /* mark the file as damaged */ @@ -842,7 +842,7 @@ close_and_continue: ret = handle_close(&handle[j]); if (ret != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); + log_tag("%s:%" PRIu64 ":%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ @@ -937,7 +937,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna void* buffer_alloc; void** buffer; unsigned buffermax; - int ret; + ssize_t ret; data_off_t countsize; block_off_t countpos; block_off_t countmax; @@ -1048,7 +1048,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* for each disk, process the block */ for (j = 0; j < diskmax; ++j) { - int read_size; + ssize_t read_size; unsigned char hash[HASH_MAX]; struct snapraid_disk* disk; struct snapraid_block* block; diff --git a/cmdline/device.c b/cmdline/device.c index dc888bfa..47c2bfac 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -472,9 +472,9 @@ static double poisson_prob_at_least_one_failure(double rate) * Probability of having data loss in a RAID system with the specified ::redundancy * supposing the specified ::array_failure_rate, and ::replace_rate. */ -static double raid_prob_of_one_or_more_failures(double array_failure_rate, double replace_rate, unsigned n, unsigned redundancy) +static double raid_prob_of_one_or_more_failures(double array_failure_rate, double replace_rate, size_t n, size_t redundancy) { - unsigned i; + size_t i; double MTBF; double MTTR; double MTTDL; @@ -603,7 +603,7 @@ static void state_smart_log(devinfo_t* devinfo, double afr) log_tag("attr:%s:%s:temperature:%d\n", devinfo->file, devinfo->name, temp); } -static void state_smart(struct snapraid_state* state, unsigned n, tommy_list* low) +static void state_smart(struct snapraid_state* state, size_t n, tommy_list* low) { tommy_node* i; unsigned j; diff --git a/cmdline/dry.c b/cmdline/dry.c index 25e3b8fa..c83633ef 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -209,7 +209,7 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit /* for each disk, process the block */ for (j = 0; j < diskmax; ++j) { struct snapraid_task* task; - int read_size; + ssize_t read_size; struct snapraid_block* block; struct snapraid_disk* disk; unsigned diskcur; diff --git a/cmdline/elem.c b/cmdline/elem.c index 6d7e421c..9f0de3b3 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -511,11 +511,11 @@ const char* file_name(const struct snapraid_file* file) return r; } -unsigned file_block_size(struct snapraid_file* file, block_off_t file_pos, unsigned block_size) +size_t file_block_size(struct snapraid_file* file, block_off_t file_pos, size_t block_size) { /* if it's the last block */ if (file_pos + 1 == file->blockmax) { - unsigned block_remainder; + size_t block_remainder; if (file->size == 0) return 0; block_remainder = file->size % block_size; diff --git a/cmdline/elem.h b/cmdline/elem.h index 63ba3739..a82c7f31 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -875,7 +875,7 @@ int file_block_is_last(struct snapraid_file* file, block_off_t file_pos); * Get the size in bytes of the block. * If it's the last block of a file it could be less than block_size. */ -unsigned file_block_size(struct snapraid_file* file, block_off_t file_pos, unsigned block_size); +size_t file_block_size(struct snapraid_file* file, block_off_t file_pos, size_t block_size); /** * Compare a file with an inode. @@ -931,7 +931,7 @@ static inline tommy_uint32_t file_path_hash(const char* sub) */ static inline tommy_uint32_t file_stamp_hash(data_off_t size, int64_t mtime_sec, int mtime_nsec) { - return tommy_inthash_u32((tommy_uint32_t)size ^ tommy_inthash_u32(mtime_sec ^ tommy_inthash_u32(mtime_nsec))); + return tommy_inthash_u32((tommy_uint32_t)size ^ tommy_inthash_u32((tommy_uint32_t)mtime_sec ^ tommy_inthash_u32(mtime_nsec))); } /** diff --git a/cmdline/handle.c b/cmdline/handle.c index c4eb5e52..500950e4 100644 --- a/cmdline/handle.c +++ b/cmdline/handle.c @@ -224,11 +224,11 @@ int handle_close(struct snapraid_handle* handle) return 0; } -int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, log_ptr* out_missing) +ssize_t handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, log_ptr* out_missing) { ssize_t read_ret; data_off_t offset; - unsigned read_size; + size_t read_size; unsigned count; int ret; @@ -300,8 +300,8 @@ int handle_write(struct snapraid_handle* handle, block_off_t file_pos, unsigned { ssize_t write_ret; data_off_t offset; - unsigned write_size; - unsigned count; + ssize_t write_size; + ssize_t count; int ret; offset = file_pos * (data_off_t)block_size; diff --git a/cmdline/handle.h b/cmdline/handle.h index 009003b5..5f0b3aec 100644 --- a/cmdline/handle.h +++ b/cmdline/handle.h @@ -53,7 +53,7 @@ int handle_close(struct snapraid_handle* handle); * Read a block from a file. * If the read block is shorter, it's padded with 0. */ -int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, log_ptr* out_missing); +ssize_t handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned char* block_buffer, unsigned block_size, log_ptr* out_missing); /** * Write a block to a file. diff --git a/cmdline/import.c b/cmdline/import.c index 5d7f4e65..6f8a9b8c 100644 --- a/cmdline/import.c +++ b/cmdline/import.c @@ -44,7 +44,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t block_off_t i; data_off_t offset; void* buffer; - int ret; + ssize_t ret; int f; int flags; unsigned block_size = state->block_size; @@ -82,7 +82,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t offset = 0; for (i = 0; i < file->blockmax; ++i) { struct snapraid_import_block* block = &file->blockimp[i]; - unsigned read_size = block_size; + size_t read_size = block_size; if (read_size > size) read_size = size; @@ -150,7 +150,7 @@ static void import_dealloc(struct snapraid_state* state, const char* dir, struct offset = 0; for (i = 0; i < file->blockmax; ++i) { struct snapraid_import_block* block = &file->blockimp[i]; - unsigned read_size = block_size; + ssize_t read_size = block_size; if (read_size > size) read_size = size; @@ -183,11 +183,11 @@ void import_file_free(struct snapraid_import_file* file) int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid_block* missing_block, unsigned char* buffer) { struct snapraid_import_block* block; - int ret; + ssize_t ret; int f; const unsigned char* hash = missing_block->hash; unsigned block_size = state->block_size; - unsigned read_size; + size_t read_size; unsigned char buffer_hash[HASH_MAX]; const char* path; diff --git a/cmdline/import.h b/cmdline/import.h index 39da9795..fcc7f34a 100644 --- a/cmdline/import.h +++ b/cmdline/import.h @@ -16,7 +16,7 @@ */ struct snapraid_import_block { struct snapraid_import_file* file; /**< Back pointer to the file owning this block. */ - unsigned size; /**< Size of the block. */ + size_t size; /**< Size of the block. */ data_off_t offset; /**< Position of the block in the file. */ unsigned char hash[HASH_MAX]; /**< Hash of the block. */ unsigned char prevhash[HASH_MAX]; /**< Previous hash of the block. Valid only if we are in rehash state. */ diff --git a/cmdline/io.h b/cmdline/io.h index 771654f1..80623f65 100644 --- a/cmdline/io.h +++ b/cmdline/io.h @@ -62,7 +62,7 @@ struct snapraid_task { struct snapraid_block* block; struct snapraid_file* file; block_off_t file_pos; - int read_size; /**< Size of the data read. */ + ssize_t read_size; /**< Size of the data read. */ int is_timestamp_different; /**< Report if file has a changed timestamp. */ }; diff --git a/cmdline/mktest.c b/cmdline/mktest.c index 06ae7d48..8a898a32 100644 --- a/cmdline/mktest.c +++ b/cmdline/mktest.c @@ -13,14 +13,14 @@ */ unsigned long long seed = 0; -unsigned rnd(unsigned max) +size_t rnd(size_t max) { seed = seed * 6364136223846793005LL + 1442695040888963407LL; return (seed >> 32) % max; } -unsigned rndnz(unsigned max) +size_t rndnz(size_t max) { if (max <= 1) return 1; @@ -28,17 +28,17 @@ unsigned rndnz(unsigned max) return rnd(max - 1) + 1; } -void rndnz_range(unsigned char* data, int size) +void rndnz_range(unsigned char* data, ssize_t size) { - int i; + ssize_t i; for (i = 0; i < size; ++i) data[i] = rndnz(256); } -void rndnz_damage(unsigned char* data, int size) +void rndnz_damage(unsigned char* data, ssize_t size) { - int i; + ssize_t i; /* corrupt ensuring always different data */ for (i = 0; i < size; ++i) { @@ -57,7 +57,7 @@ char CHARSET[] = "qwertyuiopasdfghjklzxcvbnm1234567890 .-+"; void rnd_name(char* file) { - int l = 1 + rnd(20); + ssize_t l = 1 + rnd(20); while (l) { *file++ = CHARSET[rnd(CHARSET_LEN)]; @@ -126,7 +126,7 @@ int fallback(int f, struct stat* st) * Create a file with random content. * - If the file exists it's rewritten, but avoiding to truncating it to 0. */ -void cmd_generate_file(const char* path, int size) +void cmd_generate_file(const char* path, ssize_t size) { unsigned char* data; int f; @@ -208,7 +208,7 @@ void cmd_generate_symlink(const char* path, const char* linkto) /** * Create a file or a symlink with a random name. */ -void cmd_generate(const char* tag, int disk, int size) +void cmd_generate(const char* tag, int disk, ssize_t size) { char path[PATH_MAX]; char* file; @@ -276,7 +276,7 @@ void cmd_generate(const char* tag, int disk, int size) * - The written data may be equal or not at the already existing one. * - If it's a symlink nothing is done. */ -void cmd_write(const char* path, int size) +void cmd_write(const char* path, ssize_t size) { struct stat st; @@ -347,7 +347,7 @@ void cmd_write(const char* path, int size) * - The file timestamp is NOT modified. * - If it's a symlink nothing is done. */ -void cmd_damage(const char* path, int size) +void cmd_damage(const char* path, ssize_t size) { struct stat st; @@ -446,7 +446,7 @@ void cmd_damage(const char* path, int size) * - The file must exist. * - If it's a symlink nothing is done. */ -void cmd_append(const char* path, int size) +void cmd_append(const char* path, ssize_t size) { struct stat st; @@ -497,7 +497,7 @@ void cmd_append(const char* path, int size) * - The file is NEVER truncated to 0. * - If it's a symlink nothing is done. */ -void cmd_truncate(const char* path, int size) +void cmd_truncate(const char* path, ssize_t size) { struct stat st; @@ -565,7 +565,7 @@ void cmd_delete(const char* path) * Change a file. Or deleted/truncated/append/created. * - The file must exist. */ -void cmd_change(const char* path, int size) +void cmd_change(const char* path, ssize_t size) { struct stat st; @@ -605,7 +605,7 @@ void cmd_change(const char* path, int size) cmd_generate_symlink(path, linkto); } } else if (S_ISREG(st.st_mode)) { - int r; + size_t r; r = rnd(4); diff --git a/cmdline/pool.c b/cmdline/pool.c index e36ed9c6..e47d0be1 100644 --- a/cmdline/pool.c +++ b/cmdline/pool.c @@ -236,7 +236,7 @@ static void read_dir(tommy_hashdyn* poolset, const char* base_dir, const char* s if (S_ISLNK(st.st_mode)) { struct snapraid_pool* pool; char linkto[PATH_MAX]; - int ret; + ssize_t ret; ret = readlink(path_next, linkto, sizeof(linkto)); if (ret < 0 || ret >= PATH_MAX) { diff --git a/cmdline/portable.h b/cmdline/portable.h index 7f6783aa..f4f17266 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -253,7 +253,7 @@ #define close_range close_range_impl static inline int close_range_impl(unsigned int first, unsigned int last, unsigned int flags) { - return syscall(__NR_close_range, first, last, flags); + return (int)syscall(__NR_close_range, first, last, flags); } #define HAVE_CLOSE_RANGE 1 #endif diff --git a/cmdline/scan.c b/cmdline/scan.c index 423c58be..8c48f813 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -1568,7 +1568,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa } else if (type == 1) { /* LNK */ if (filter_path(&state->filterlist, &reason, disk->name, sub_next) == 0 && filter_path(&scan->local_filter_list, &reason, disk->name, sub_next) == 0) { - int ret; + ssize_t ret; ret = readlink(path_next, tmp, PATH_MAX); if (ret >= PATH_MAX) { diff --git a/cmdline/scrub.c b/cmdline/scrub.c index 9e248b2d..91860385 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -363,7 +363,7 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* for each disk, process the block */ for (j = 0; j < diskmax; ++j) { struct snapraid_task* task; - int read_size; + ssize_t read_size; unsigned char hash[HASH_MAX]; struct snapraid_block* block; int file_is_unsynced; @@ -756,7 +756,7 @@ bail: /** * Return a * b / c approximated to the upper value. */ -static uint32_t md(uint32_t a, uint32_t b, uint32_t c) +static uint64_t md(uint64_t a, uint32_t b, uint32_t c) { uint64_t v = a; diff --git a/cmdline/search.c b/cmdline/search.c index 49a4c80e..3187094a 100644 --- a/cmdline/search.c +++ b/cmdline/search.c @@ -37,7 +37,7 @@ struct search_file_compare_arg { const struct snapraid_file* file; unsigned char* buffer; data_off_t offset; - unsigned read_size; + size_t read_size; int prevhash; }; diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 29bce506..355901ab 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1055,7 +1055,7 @@ int snapraid_main(int argc, char* argv[]) } break; case 'o' : - olderthan = strtoul(optarg, &e, 10); + olderthan = strtou(optarg, &e, 10); if (e == optarg || *e || olderthan > 1000) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid number of days '%s'\n", optarg); @@ -1097,7 +1097,7 @@ int snapraid_main(int argc, char* argv[]) } break; case 'L' : - opt.io_error_limit = strtoul(optarg, &e, 0); + opt.io_error_limit = strtou(optarg, &e, 0); if (e == optarg || *e) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid error limit number '%s'\n", optarg); @@ -1202,7 +1202,7 @@ int snapraid_main(int argc, char* argv[]) opt.gui_touch_before = 1; break; case OPT_GUI_THRESHOLD_REMOVES : - opt.gui_threshold_removes = strtoul(optarg, &e, 0); + opt.gui_threshold_removes = strtou(optarg, &e, 0); if (e == optarg || *e) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid threshold '%s'\n", optarg); @@ -1211,7 +1211,7 @@ int snapraid_main(int argc, char* argv[]) } break; case OPT_GUI_THRESHOLD_UPDATES : - opt.gui_threshold_updates = strtoul(optarg, &e, 0); + opt.gui_threshold_updates = strtou(optarg, &e, 0); if (e == optarg || *e) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid threshold '%s'\n", optarg); @@ -1808,13 +1808,13 @@ int snapraid_main(int argc, char* argv[]) if (opt.gui_threshold_removes != 0 && state.removed_files >= opt.gui_threshold_removes) { if (state.need_write) state_write(&state); - log_fatal(EUSER, "Too many files were removed (%u, limit is %u). Sync aborted.\n", state.removed_files, opt.gui_threshold_removes); + log_fatal(EUSER, "Too many files were removed (%" PRIu64 ", limit is %u). Sync aborted.\n", state.removed_files, opt.gui_threshold_removes); exit(EXIT_SYNC_NEEDED); } if (opt.gui_threshold_updates != 0 && state.updated_files >= opt.gui_threshold_updates) { if (state.need_write) state_write(&state); - log_fatal(EUSER, "Too many files were updated (%u, limit is %u). Sync aborted.\n", state.updated_files, opt.gui_threshold_updates); + log_fatal(EUSER, "Too many files were updated (%" PRIu64 ", limit is %u). Sync aborted.\n", state.updated_files, opt.gui_threshold_updates); exit(EXIT_SYNC_NEEDED); } diff --git a/cmdline/state.c b/cmdline/state.c index 9a592d4e..4550b38e 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -590,7 +590,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co while (1) { char tag[PATH_MAX]; char buffer[PATH_MAX]; - int ret; + ssize_t ret; int c; unsigned level; @@ -1264,7 +1264,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* LCOV_EXCL_STOP */ } - smart[si] = strtoul(buffer, &e, 0); + smart[si] = strtou(buffer, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ @@ -1585,7 +1585,7 @@ static void state_map(struct snapraid_state* state) unsigned hole; tommy_node* i; unsigned uuid_mismatch; - unsigned diskcount; + size_t diskcount; unsigned l, s; /* @@ -1780,15 +1780,15 @@ static void state_map(struct snapraid_state* state) if (!state->opt.no_warnings) { /* LCOV_EXCL_START */ if (diskcount >= 36 && state->level < 6) { - log_error(EUSER, "WARNING! For %u disks, it's recommended to use six parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %zu disks, it's recommended to use six parity levels.\n", diskcount); } else if (diskcount >= 29 && state->level < 5) { - log_error(EUSER, "WARNING! For %u disks, it's recommended to use five parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %zu disks, it's recommended to use five parity levels.\n", diskcount); } else if (diskcount >= 22 && state->level < 4) { - log_error(EUSER, "WARNING! For %u disks, it's recommended to use four parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %zu disks, it's recommended to use four parity levels.\n", diskcount); } else if (diskcount >= 15 && state->level < 3) { - log_error(EUSER, "WARNING! For %u disks, it's recommended to use three parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %zu disks, it's recommended to use three parity levels.\n", diskcount); } else if (diskcount >= 5 && state->level < 2) { - log_error(EUSER, "WARNING! For %u disks, it's recommended to use two parity levels.\n", diskcount); + log_error(EUSER, "WARNING! For %zu disks, it's recommended to use two parity levels.\n", diskcount); } /* LCOV_EXCL_STOP */ } @@ -2941,9 +2941,9 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } } else if (c == 'y') { - uint32_t hash_size; + uint64_t hash_size; - ret = sgetb32(f, &hash_size); + ret = sgetb64(f, &hash_size); if (ret < 0) { /* LCOV_EXCL_START */ decoding_error(path, f); @@ -2968,7 +2968,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_START */ decoding_error(path, f); log_fatal(EUSER, "Mismatching 'hashsize' specification in the content file!\n"); - log_fatal(EUSER, "Please restore the 'hashsize' value in the configuration file to '%u'\n", hash_size); + log_fatal(EUSER, "Please restore the 'hashsize' value in the configuration file to '%" PRIu64 "'\n", hash_size); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3484,7 +3484,7 @@ static void* state_write_thread(void* arg) /* hash size */ sputc('y', f); - sputb32(BLOCK_HASH_SIZE, f); + sputb64(BLOCK_HASH_SIZE, f); if (serror(f)) { /* LCOV_EXCL_START */ @@ -5002,13 +5002,13 @@ void state_progress_end(struct snapraid_state* state, block_off_t countpos, bloc time_t now; time_t elapsed; - unsigned countsize_MB = (countsize + MEGA - 1) / MEGA; + data_off_t countsize_MB = (countsize + MEGA - 1) / MEGA; now = time(0); elapsed = now - state->progress_whole_start - state->progress_wasted; - msg_bar("%u%% completed, %u MB accessed", muldiv(countpos, 100, countmax), countsize_MB); + msg_bar("%u%% completed, %" PRIu64 " MB accessed", muldiv(countpos, 100, countmax), countsize_MB); msg_bar(" in %u:%02u", (unsigned)(elapsed / 3600), (unsigned)((elapsed % 3600) / 60)); @@ -5099,7 +5099,7 @@ static void state_progress_graph(struct snapraid_state* state, struct snapraid_i { uint64_t v; uint64_t tick_total; - unsigned bar; + size_t bar; tommy_node* i; unsigned l; size_t pad; @@ -5754,7 +5754,7 @@ void state_load_ignore_file(tommy_list* filter_list, const char* path, const cha line = 1; while (1) { char buffer[PATH_MAX]; - int ret; + ssize_t ret; int c; /* skip initial spaces */ diff --git a/cmdline/state.h b/cmdline/state.h index 4030d7bb..a654d68a 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -135,12 +135,12 @@ struct snapraid_state { unsigned besthash; /**< Best hash suggested. */ const char* command; /**< Command running. */ int smartignore[SMART_IGNORE_MAX]; /**< Smart attributes to ignore for all devices. */ - uint32_t rehash_blocks; /**< Blocks marked rehash */ - uint32_t bad_blocks; /**< Blocks marked bad */ - uint32_t unsynced_blocks; /**< If the parity is invalid, and a sync is needed. */ - uint32_t unscrubbed_blocks; /**< Blocks never scrubbed */ - uint32_t removed_files; /**< Files removed. Updated in scan */ - uint32_t updated_files; /**< Files updated. Updated in scan */ + uint64_t rehash_blocks; /**< Blocks marked rehash */ + uint64_t bad_blocks; /**< Blocks marked bad */ + uint64_t unsynced_blocks; /**< If the parity is invalid, and a sync is needed. */ + uint64_t unscrubbed_blocks; /**< Blocks never scrubbed */ + uint64_t removed_files; /**< Files removed. Updated in scan */ + uint64_t updated_files; /**< Files updated. Updated in scan */ tommy_list contentlist; /**< List of content files. */ tommy_list disklist; /**< List of all the data disks. */ diff --git a/cmdline/status.c b/cmdline/status.c index aa23cbb8..7754d808 100644 --- a/cmdline/status.c +++ b/cmdline/status.c @@ -19,7 +19,9 @@ unsigned day_ago(time_t ref, time_t now) if (now < ref) return 0; - return (now - ref) / (24 * 3600); + now -= ref; + + return (unsigned)(now / (24 * 3600)); } #define GRAPH_COLUMN 70 @@ -324,9 +326,9 @@ int state_status(struct snapraid_state* state) /* output scrub history as structured data */ log_tag("scrub_graph_range:%u:%u\n", GRAPH_COLUMN, barmax); - for (i = 0; i < GRAPH_COLUMN; ++i) { - unsigned days_ago = dayoldest - (dayoldest - daynewest) * i / (GRAPH_COLUMN - 1); - log_tag("scrub_graph_bar:%" PRIu64 ":%u:%u:%u\n", i, days_ago, bar_scrubbed[i], bar_new[i]); + for (l = 0; l < GRAPH_COLUMN; ++l) { + unsigned days_ago = dayoldest - (dayoldest - daynewest) * l / (GRAPH_COLUMN - 1); + log_tag("scrub_graph_bar:%u:%u:%u:%u\n", l, days_ago, bar_scrubbed[l], bar_new[l]); } printf("\n\n"); @@ -419,7 +421,7 @@ int state_status(struct snapraid_state* state) } if (state->bad_blocks) { - printf("DANGER! In the array there are %u errors!\n\n", state->bad_blocks); + printf("DANGER! In the array there are %" PRIu64 " errors!\n\n", state->bad_blocks); block_off_t bad_range; block_off_t bad_count; diff --git a/cmdline/stream.c b/cmdline/stream.c index 7e19a393..94c5c066 100644 --- a/cmdline/stream.c +++ b/cmdline/stream.c @@ -379,7 +379,7 @@ int sgetc_uncached(STREAM* s) return *s->pos++; } -int sgettok(STREAM* f, char* str, int size) +ssize_t sgettok(STREAM* f, char* str, int size) { char* i = str; char* send = str + size; @@ -416,7 +416,7 @@ int sgettok(STREAM* f, char* str, int size) return i - str; } -int sread(STREAM* f, void* void_data, unsigned size) +int sread(STREAM* f, void* void_data, size_t size) { unsigned char* data = void_data; @@ -447,7 +447,7 @@ int sread(STREAM* f, void* void_data, unsigned size) return 0; } -int sgetline(STREAM* f, char* str, int size) +ssize_t sgetline(STREAM* f, char* str, int size) { char* i = str; char* send = str + size; @@ -515,9 +515,9 @@ int sgetline(STREAM* f, char* str, int size) return i - str; } -int sgetlasttok(STREAM* f, char* str, int size) +ssize_t sgetlasttok(STREAM* f, char* str, int size) { - int ret; + ssize_t ret; ret = sgetline(f, str, size); if (ret < 0) { @@ -669,17 +669,17 @@ int sgetble32(STREAM* f, uint32_t* value) return 0; } -int sgetbs(STREAM* f, char* str, int size) +int sgetbs(STREAM* f, char* str, size_t size) { - uint32_t len; + uint64_t len; - if (sgetb32(f, &len) < 0) { + if (sgetb64(f, &len) < 0) { /* LCOV_EXCL_START */ return -1; /* LCOV_EXCL_STOP */ } - if (len + 1 > (uint32_t)size) { + if (len + 1 > size) { /* LCOV_EXCL_START */ return -1; /* LCOV_EXCL_STOP */ @@ -687,10 +687,10 @@ int sgetbs(STREAM* f, char* str, int size) str[len] = 0; - return sread(f, str, (int)len); + return sread(f, str, len); } -int swrite(const void* void_data, unsigned size, STREAM* f) +int swrite(const void* void_data, size_t size, STREAM* f) { const unsigned char* data = void_data; @@ -787,7 +787,7 @@ int sputbs(const char* str, STREAM* f) { size_t len = strlen(str); - if (sputb32(len, f) != 0) { + if (sputb64(len, f) != 0) { /* LCOV_EXCL_START */ return -1; /* LCOV_EXCL_STOP */ diff --git a/cmdline/stream.h b/cmdline/stream.h index ece27409..379e6881 100644 --- a/cmdline/stream.h +++ b/cmdline/stream.h @@ -152,7 +152,7 @@ uint32_t scrc_stream(STREAM* s); /** * Check if the buffer has enough data loaded. */ -static inline int sptrlookup(STREAM* s, int size) +static inline int sptrlookup(STREAM* s, ssize_t size) { return s->pos + size <= s->end; } @@ -243,7 +243,7 @@ static inline void sungetc(int c, STREAM* s) * Read a fixed amount of chars. * Return 0 on success, or -1 on error. */ -int sread(STREAM* f, void* void_data, unsigned size); +int sread(STREAM* f, void* void_data, size_t size); /** * Get a char from a stream, ignoring one '\r'. @@ -283,19 +283,19 @@ static inline int sgetspace(STREAM* f) * Stop at the first ' ', '\t', '\n' or EOF. * Return <0 if the buffer is too small, or the number of chars read. */ -int sgettok(STREAM* f, char* str, int size); +ssize_t sgettok(STREAM* f, char* str, int size); /** * Read until the end of line. * Stop at the first '\n' or EOF. Note that '\n' is left in the stream. * Return <0 if the buffer is too small, or the number of chars read. */ -int sgetline(STREAM* f, char* str, int size); +ssize_t sgetline(STREAM* f, char* str, int size); /** * Like sgetline() but remove ' ' and '\t' at the end. */ -int sgetlasttok(STREAM* f, char* str, int size); +ssize_t sgetlasttok(STREAM* f, char* str, int size); /** * Read a 32 bit number. @@ -329,7 +329,7 @@ int sgetble32(STREAM* f, uint32_t* value); * Read a binary string. * Return -1 on error or if the buffer is too small, or the number of chars read. */ -int sgetbs(STREAM* f, char* str, int size); +int sgetbs(STREAM* f, char* str, size_t size); /****************************************************************************/ /* put */ @@ -377,7 +377,7 @@ static inline int sputeol(STREAM* s) * Write a sized string. * Return 0 on success or -1 on error. */ -int swrite(const void* data, unsigned size, STREAM* f); +int swrite(const void* data, size_t size, STREAM* f); /****************************************************************************/ /* binary put */ diff --git a/cmdline/support.c b/cmdline/support.c index 734fc243..362c19a8 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -312,7 +312,7 @@ int msg_line_curr = 0; /**< Current line width on stdout */ static void vmsg(FILE* out, const char* format, va_list ap) { char* dup = strdup_nofail(format); - int len = strlen(dup); + ssize_t len = strlen(dup); int written = 0; char control = 0; @@ -1119,6 +1119,86 @@ char* worddigitstr(const char* haystack, const char* needle) return NULL; } +int strtoi(const char* nptr, char** endptr, int base) +{ + long val; + int save_errno = errno; + + errno = 0; + val = strtol(nptr, endptr, base); + + if (errno == ERANGE) { + return val > 0 ? INT_MAX : INT_MIN; + } + + if (val > INT_MAX) { + errno = ERANGE; + return INT_MAX; + } + + if (val < INT_MIN) { + errno = ERANGE; + return INT_MIN; + } + + if (errno == 0) { + errno = save_errno; + } + + return (int)val; +} + +unsigned strtou(const char* nptr, char** endptr, int base) +{ + const char* p = nptr; + char* end; + unsigned long val; + int neg = 0; + int save_errno = errno; + + while (isspace((unsigned char)*p)) { + ++p; + } + + if (*p == '-') { + neg = 1; + ++p; + } else if (*p == '+') { + ++p; + } + + errno = 0; + val = strtoul(p, &end, base); + + if (end == p) { + /* no conversion was performed */ + if (endptr) { + *endptr = (char*)nptr; + } + errno = save_errno; + return 0; + } + + if (endptr) { + *endptr = end; + } + + if (errno == ERANGE || val > UINT_MAX) { + errno = ERANGE; + return UINT_MAX; + } + + if (errno == 0) { + errno = save_errno; + } + + if (neg) { + return (unsigned)-val; + } + + return (unsigned)val; +} + /****************************************************************************/ /* path */ @@ -2592,7 +2672,7 @@ int smart_temp(devinfo_t* devinfo) if (t > 100) return -1; - return t; + return (int)t; } /****************************************************************************/ diff --git a/cmdline/support.h b/cmdline/support.h index 7d002fab..143574f9 100644 --- a/cmdline/support.h +++ b/cmdline/support.h @@ -358,6 +358,16 @@ char* strlwr(char* s); */ char* worddigitstr(const char* haystack, const char* needle); +/** + * Convert a string to an integer, with the same semantics as strtol. + */ +int strtoi(const char* nptr, char** endptr, int base); + +/** + * Convert a string to an unsigned integer, with the same semantics as strtoul. + */ +unsigned strtou(const char* nptr, char** endptr, int base); + /****************************************************************************/ /* path */ diff --git a/cmdline/sync.c b/cmdline/sync.c index 888f84b1..b202b2c4 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -99,7 +99,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta snapraid_info info; int rehash; struct snapraid_block* block; - int read_size; + ssize_t read_size; unsigned char hash[HASH_MAX]; unsigned block_state; struct snapraid_file* file; @@ -397,7 +397,7 @@ struct snapraid_plan { */ struct failed_struct { unsigned index; /**< Index of the failed block. */ - unsigned size; /**< Size of the block. */ + size_t size; /**< Size of the block. */ struct snapraid_block* block; /**< The failed block, or BLOCK_DELETED for a deleted block */ }; @@ -811,7 +811,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* for each disk, process the block */ for (j = 0; j < diskmax; ++j) { struct snapraid_task* task; - int read_size; + ssize_t read_size; unsigned char hash[HASH_MAX]; struct snapraid_block* block; unsigned block_state; @@ -1164,7 +1164,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari unsigned block_state = block_state_get(failed[j].block); if (block_state == BLOCK_STATE_BLK) { - unsigned size = failed[j].size; + size_t size = failed[j].size; /* compute the hash of the recovered block */ if (rehash) { diff --git a/cmdline/unix.c b/cmdline/unix.c index 6a0cf7c0..5708da4b 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -883,11 +883,11 @@ static const char* find_smartctl(void) * Return -1 on error, otherwise the size of data read */ #if HAVE_LINUX_DEVICE -static int sysread(const char* path, char* buf, size_t buf_size) +static ssize_t sysread(const char* path, char* buf, size_t buf_size) { int f; int ret; - int len; + ssize_t len; f = open(path, O_RDONLY); if (f == -1) { @@ -924,7 +924,7 @@ static int sysread(const char* path, char* buf, size_t buf_size) static int sysattr_vpd_pg80(const char* path, char* dst, size_t dst_size) { unsigned char buf[512]; - int ret = sysread(path, (char*)buf, sizeof(buf)); + ssize_t ret = sysread(path, (char*)buf, sizeof(buf)); /* need at least the header */ if (ret < 4) { @@ -1025,7 +1025,7 @@ static int sysattr_vpd_pg83(const char* path, char* dst, size_t dst_size) { unsigned char buf[4096]; - int ret = sysread(path, (char*)buf, sizeof(buf)); + ssize_t ret = sysread(path, (char*)buf, sizeof(buf)); if (ret < 4) { /* LCOV_EXCL_START */ return -1; @@ -1144,7 +1144,7 @@ next: #if HAVE_LINUX_DEVICE static int sysattr(const char* path, char* buf, size_t buf_size) { - int len; + ssize_t len; len = sysread(path, buf, buf_size); if (len < 0) { @@ -1555,7 +1555,7 @@ static int devdereference(uint64_t device, const char* dir, tommy_list* devlist) #if HAVE_LINUX_DEVICE static int tagread(const char* path, const char* tag, char* value, size_t value_size) { - int ret; + ssize_t ret; char buf[512]; size_t tag_len; char* i; @@ -1704,7 +1704,7 @@ static blkid_cache cache = 0; #if HAVE_LINUX_DEVICE static int devuuid_dev(uint64_t device, char* uuid, size_t uuid_size) { - int ret; + ssize_t ret; DIR* d; struct dirent* dd; struct stat st; @@ -2639,12 +2639,12 @@ int fssnapshot_mount(const char* path, struct fssnapshot_struct* fss) if (sfs.f_type == BTRFS_SUPER_MAGIC) { /* btrfs reserved inode 256 for subvolume roots */ - return fssnapshot_inode(path, sfs.f_type, 256, fss); + return fssnapshot_inode(path, BTRFS_SUPER_MAGIC, 256, fss); } else if (sfs.f_type == BCACHEFS_SUPER_MAGIC) { /* Bcachefs reserves inode 4096 for each subvolume's root directory */ - return fssnapshot_inode(path, sfs.f_type, 4096, fss); + return fssnapshot_inode(path, BCACHEFS_SUPER_MAGIC, 4096, fss); } else if (sfs.f_type == ZFS_SUPER_MAGIC) { - return fssnapshot_zfs(path, sfs.f_type, fss); + return fssnapshot_zfs(path, ZFS_SUPER_MAGIC, fss); } else { return -1; } @@ -3228,7 +3228,7 @@ static dev_t devread(const char* path) { int f; int ret; - int len; + ssize_t len; char buf[64]; char* e; unsigned ma; @@ -3268,7 +3268,7 @@ static dev_t devread(const char* path) buf[len] = 0; - ma = strtoul(buf, &e, 10); + ma = strtou(buf, &e, 10); if (*e != ':') { /* LCOV_EXCL_START */ log_fatal(EEXTERNAL, "Invalid format in '%s' for '%s'.\n", path, buf); @@ -3276,7 +3276,7 @@ static dev_t devread(const char* path) /* LCOV_EXCL_STOP */ } - mi = strtoul(e + 1, &e, 10); + mi = strtou(e + 1, &e, 10); if (*e != 0 && !isspace((unsigned char)*e)) { /* LCOV_EXCL_START */ log_fatal(EEXTERNAL, "Invalid format in '%s' for '%s'.\n", path, buf); @@ -3387,7 +3387,7 @@ static int devstat(dev_t device, uint64_t* count) char path[PATH_MAX]; char buf[512]; int token; - int ret; + ssize_t ret; char* i; *count = 0; @@ -3546,7 +3546,7 @@ static void devattr(dev_t device, uint64_t* info, char* serial, char* family, ch { char path[PATH_MAX]; char buf[512]; - int ret; + ssize_t ret; (void)family; /* not available, smartctl uses an internal database to get it */ @@ -3822,7 +3822,7 @@ static int devdownifup(dev_t device, const char* name, const char* smartctl, int static int devup(dev_t device, const char* name) { char file[PATH_MAX]; - int ret; + ssize_t ret; int f; void* buf; uint64_t size; @@ -4257,7 +4257,7 @@ void os_abort(void) #if HAVE_BACKTRACE && HAVE_BACKTRACE_SYMBOLS void* stack[32]; char** messages; - size_t size; + unsigned size; unsigned i; #endif @@ -4392,7 +4392,7 @@ int ambient_temperature(void) char label[128]; char* dash; char* e; - long temp; + int temp; if (strncmp(hwmon_entry->d_name, "temp", 4) != 0) continue; @@ -4419,7 +4419,7 @@ int ambient_temperature(void) /* LCOV_EXCL_STOP */ } - temp = strtol(value, &e, 10) / 1000; + temp = strtoi(value, &e, 10) / 1000; if (*e != 0 && !isspace((unsigned char)*e)) { /* LCOV_EXCL_START */ continue; @@ -4447,7 +4447,7 @@ int ambient_temperature(void) /* LCOV_EXCL_STOP */ } - log_tag("thermal:ambient:device:%s:%s:%s:%s:%ld\n", entry->d_name, name, hwmon_name, label, temp); + log_tag("thermal:ambient:device:%s:%s:%s:%s:%d\n", entry->d_name, name, hwmon_name, label, temp); /* check if temperature is in reasonable range */ if (temp < 15 || temp > 40) @@ -4459,7 +4459,7 @@ int ambient_temperature(void) /* check if label matches possible ambient labels */ for (int i = 0; AMBIENT_LABEL[i]; ++i) { if (worddigitstr(label, AMBIENT_LABEL[i]) != 0) { - log_tag("thermal:ambient:candidate:%ld\n", temp); + log_tag("thermal:ambient:candidate:%d\n", temp); if (lowest_temp == 0 || lowest_temp > temp) lowest_temp = temp; break; @@ -4468,7 +4468,7 @@ int ambient_temperature(void) /* accept also generic "temp1" */ if (strcmp(label, "temp1") == 0) { - log_tag("thermal:ambient:candidate:%ld\n", temp); + log_tag("thermal:ambient:candidate:%d\n", temp); if (lowest_temp == 0 || lowest_temp > temp) lowest_temp = temp; } diff --git a/cmdline/util.c b/cmdline/util.c index f7ad048f..bd17a933 100644 --- a/cmdline/util.c +++ b/cmdline/util.c @@ -402,7 +402,7 @@ uint32_t CRC32C_3[256] = { int crc_x86; #endif -uint32_t crc32c_gen(uint32_t crc, const unsigned char* ptr, unsigned size) +uint32_t crc32c_gen(uint32_t crc, const unsigned char* ptr, size_t size) { crc ^= CRC_IV; @@ -414,7 +414,7 @@ uint32_t crc32c_gen(uint32_t crc, const unsigned char* ptr, unsigned size) } #if CONFIG_X86 -uint32_t crc32c_x86(uint32_t crc, const unsigned char* ptr, unsigned size) +uint32_t crc32c_x86(uint32_t crc, const unsigned char* ptr, size_t size) { crc ^= CRC_IV; @@ -426,7 +426,7 @@ uint32_t crc32c_x86(uint32_t crc, const unsigned char* ptr, unsigned size) } #endif -uint32_t (*crc32c)(uint32_t crc, const unsigned char* ptr, unsigned size); +uint32_t (*crc32c)(uint32_t crc, const unsigned char* ptr, size_t size); void crc32c_init(void) { diff --git a/cmdline/util.h b/cmdline/util.h index 2bc1339d..cc974d8d 100644 --- a/cmdline/util.h +++ b/cmdline/util.h @@ -83,7 +83,7 @@ static inline uint32_t crc32c_plain_char(uint32_t crc, unsigned char c) /** * Compute the CRC-32 (Castagnoli) without the IV. */ -static inline uint32_t crc32c_gen_plain(uint32_t crc, const unsigned char* ptr, unsigned size) +static inline uint32_t crc32c_gen_plain(uint32_t crc, const unsigned char* ptr, size_t size) { while (size >= 4) { crc ^= ptr[0] | (uint32_t)ptr[1] << 8 | (uint32_t)ptr[2] << 16 | (uint32_t)ptr[3] << 24; @@ -105,7 +105,7 @@ static inline uint32_t crc32c_gen_plain(uint32_t crc, const unsigned char* ptr, * Compute the CRC-32 (Castagnoli) without the IV. */ #if CONFIG_X86 -static inline uint32_t crc32c_x86_plain(uint32_t crc, const unsigned char* ptr, unsigned size) +static inline uint32_t crc32c_x86_plain(uint32_t crc, const unsigned char* ptr, size_t size) { #ifdef CONFIG_X86_64 uint64_t crc64 = crc; @@ -114,7 +114,7 @@ static inline uint32_t crc32c_x86_plain(uint32_t crc, const unsigned char* ptr, ptr += 8; size -= 8; } - crc = crc64; + crc = (uint32_t)crc64; #else while (size >= 4) { asm ("crc32l %1, %0\n" : "+r" (crc) : "m" (*(const uint32_t*)ptr)); @@ -135,7 +135,7 @@ static inline uint32_t crc32c_x86_plain(uint32_t crc, const unsigned char* ptr, /** * Compute CRC-32 (Castagnoli) without the IV. */ -static inline uint32_t crc32c_plain(uint32_t crc, const unsigned char* ptr, unsigned size) +static inline uint32_t crc32c_plain(uint32_t crc, const unsigned char* ptr, size_t size) { #if CONFIG_X86 if (tommy_likely(crc_x86)) { @@ -148,13 +148,13 @@ static inline uint32_t crc32c_plain(uint32_t crc, const unsigned char* ptr, unsi /** * Compute the CRC-32 (Castagnoli) */ -extern uint32_t (*crc32c)(uint32_t crc, const unsigned char* ptr, unsigned size); +extern uint32_t (*crc32c)(uint32_t crc, const unsigned char* ptr, size_t size); /** * Internal entry points for testing. */ -uint32_t crc32c_gen(uint32_t crc, const unsigned char* ptr, unsigned size); -uint32_t crc32c_x86(uint32_t crc, const unsigned char* ptr, unsigned size); +uint32_t crc32c_gen(uint32_t crc, const unsigned char* ptr, size_t size); +uint32_t crc32c_x86(uint32_t crc, const unsigned char* ptr, size_t size); /** * Initialize the CRC-32 (Castagnoli) support. diff --git a/configure.ac b/configure.ac index ebbe6e64..74185dd1 100644 --- a/configure.ac +++ b/configure.ac @@ -207,6 +207,7 @@ AC_CHECK_CC_OPT([-Wall], CFLAGS="$CFLAGS -Wall", []) AC_CHECK_CC_OPT([-Wextra], CFLAGS="$CFLAGS -Wextra", []) AC_CHECK_CC_OPT([-Wuninitialized], CFLAGS="$CFLAGS -Wuninitialized", []) AC_CHECK_CC_OPT([-Wshadow], CFLAGS="$CFLAGS -Wshadow", []) +AC_CHECK_CC_OPT([-Wshorten-64-to-32], CFLAGS="$CFLAGS -Wshorten-64-to-32", []) dnl Disable warning about zero-length-bounds raised by gcc 10 on linux kernel header on the fm_extents field AC_CHECK_CC_OPT([-Wno-zero-length-bounds], CFLAGS="$CFLAGS -Wno-zero-length-bounds", [])