From 9d7dcdd4798d75e50281284c4896946afa5fe97a Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 20 May 2026 00:17:18 +0200 Subject: [PATCH 1/8] If skip_access is enabled, don't call fsinfo on the device --- cmdline/state.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmdline/state.c b/cmdline/state.c index a9bafd44..5dac9a9a 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -310,9 +310,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } } - /* skip data disks that are not accessible */ - if (disk->skip_access) - continue; + if (!state->opt.skip_parity_access) { for (l = 0; l < state->level; ++l) { @@ -1802,6 +1800,9 @@ void state_refresh(struct snapraid_state* state) /* LCOV_EXCL_STOP */ } + if (disk->skip_access) + continue; + ret = fsinfo(disk->dir, 0, 0, &total_space, &free_space, disk->fstype, sizeof(disk->fstype), disk->fslabel, sizeof(disk->fslabel)); if (ret != 0) { /* LCOV_EXCL_START */ @@ -1828,6 +1829,9 @@ void state_refresh(struct snapraid_state* state) state->parity[l].total_blocks = 0; state->parity[l].free_blocks = 0; + if (state->parity[l].skip_access) + continue; + for (s = 0; s < state->parity[l].split_mac; ++s) { struct snapraid_split* split = &state->parity[l].split_map[s]; uint64_t total_space; From b428cd80cce0a857e2ff716ef0a01b3881a0804d Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 20 May 2026 00:17:46 +0200 Subject: [PATCH 2/8] Verify the number of splits --- cmdline/state.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmdline/state.c b/cmdline/state.c index 5dac9a9a..aeee94eb 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -3088,6 +3088,14 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } + if (v_split_mac > SPLIT_MAX) { + /* LCOV_EXCL_START */ + decoding_error(path, f); + log_fatal(ECONTENT, "Too many splits '%u' in the content file!\n", v_split_mac); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + if (v_level >= LEV_MAX) { /* LCOV_EXCL_START */ decoding_error(path, f); From 4d09bffb944c78a60d6a1b176503a42870646b33 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 20 May 2026 00:20:52 +0200 Subject: [PATCH 3/8] Support the root filesystem as data and parity disk --- cmdline/state.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmdline/state.c b/cmdline/state.c index aeee94eb..4352857f 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -722,10 +722,9 @@ void state_config(struct snapraid_state* state, const char* path, const char* co pathimport(device, sizeof(device), split_map[s]); slash = strrchr(device, '/'); if (slash) - *slash = 0; + slash[1] = 0; else pathcpy(device, sizeof(device), "."); - if (stat(device, &st) == 0) { dev = st.st_dev; @@ -875,7 +874,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co pathimport(device, sizeof(device), buffer); slash = strrchr(device, '/'); if (slash) - *(slash + 1) = 0; + slash[1] = 0; else pathcpy(device, sizeof(device), "."); if (stat(device, &st) == 0) { From 10c327a558c7a869e4f7690f4f92aee4e5525cce Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 20 May 2026 00:23:43 +0200 Subject: [PATCH 4/8] Fixed syncing of the directory of the content file --- cmdline/state.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmdline/state.c b/cmdline/state.c index 4352857f..1f65e702 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -4548,9 +4548,9 @@ static void state_rename_content(struct snapraid_state* state) pathcpy(dir, sizeof(dir), content->content); - slash = strrchr(tmp, '/'); + slash = strrchr(dir, '/'); if (slash) - *slash = 0; + slash[1] = 0; else pathcpy(dir, sizeof(dir), "."); From 00e50bd965012bdd2e337152411b00142ca0b9e3 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 20 May 2026 00:24:02 +0200 Subject: [PATCH 5/8] Fix wrong sizeof --- cmdline/state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdline/state.c b/cmdline/state.c index 1f65e702..25ce7089 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -5255,7 +5255,7 @@ int state_progress(struct snapraid_state* state, struct snapraid_io* io, block_o str_cpu[0] = 0; } if (out_temperature) { - snprintf(str_temp, sizeof(str_eta), "%u", out_temperature); + snprintf(str_temp, sizeof(str_temp), "%u", out_temperature); } else { str_temp[0] = 0; } From 6bfbc6e3b21c6b6957f9d61d24ece90813df64ae Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 20 May 2026 19:10:34 +0200 Subject: [PATCH 6/8] Fix potential division by zero with minuscule devices --- cmdline/unix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmdline/unix.c b/cmdline/unix.c index 1404b4c3..5874307c 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -2101,7 +2101,8 @@ static int devup(dev_t device, const char* name) } /* select a random offset */ - offset = (random_u64() % (size / 4096)) * 4096; + uint64_t blocks = size / 4096; + offset = blocks > 0 ? (random_u64() % blocks) * 4096 : 0; #if HAVE_POSIX_FADVISE /* clear cache */ From b50332db54d1e47da2c2490a3329cd57352a44f3 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 20 May 2026 19:36:15 +0200 Subject: [PATCH 7/8] Fix a double close in Windows --- cmdline/mingw.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmdline/mingw.c b/cmdline/mingw.c index aa4c6460..dae328d6 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -2989,14 +2989,12 @@ static int devup(uint64_t device, const char* name, const char* wfile) if (!CloseHandle(h)) { DWORD error = GetLastError(); - CloseHandle(h); VirtualFree(buffer, 0, MEM_RELEASE); windows_errno(error); log_tag("device:%s:%s:error:%lu\n", file, name, error); return -1; } - CloseHandle(h); VirtualFree(buffer, 0, MEM_RELEASE); log_tag("attr:%s:%s:power:up\n", file, name); From 836480951e9fe25bbcff8ff4c0758e6ded3d697d Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 20 May 2026 19:57:11 +0200 Subject: [PATCH 8/8] Fix leak on termination on Windows --- cmdline/mingw.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cmdline/mingw.c b/cmdline/mingw.c index dae328d6..0ed3fdb4 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -3344,17 +3344,21 @@ int windows_key_create(windows_key_t* key, void (*destructor)(void*)) return 0; } -int windows_key_delete(windows_key_t key) +int windows_key_delete(windows_key_t void_key) { - struct windows_key_context* context = key; + struct windows_key_context* key = void_key; - /* remove from the list of destructors */ - if (context->func) - tommy_list_remove_existing(&windows_key_list, &context->node); + /* use the destructor for the local variable and remove from the list of destructors */ + if (key->func) { + void* value = windows_getspecific(key); + if (value) + key->func(value); + tommy_list_remove_existing(&windows_key_list, &key->node); + } - TlsFree(context->key); + TlsFree(key->key); - free(context); + free(key); return 0; }