From 4054832c7e385388c6629561bf0ddb16b95698b5 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 22 Oct 2026 21:36:39 +0200 Subject: [PATCH] Add best-effort Linux disk instance mappings using boot_id and diskseq --- HISTORY | 3 +++ cmdline/unixapp.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/HISTORY b/HISTORY index e413d904..dd9a4005 100644 --- a/HISTORY +++ b/HISTORY @@ -3,6 +3,9 @@ SnapRAID HISTORY 15.1 2026/10 ============ + * Add synthetic device IDs on Linux, allowing SnapRAID Daemon to + preserve history for devices without unique hardware IDs while + they remain connected within the same boot. * Fix a failed internal inconsistency check when '--gui-touch-before' is used before the first sync when no content file exists yet. Also ensure that commands that can save the content file ('touch', diff --git a/cmdline/unixapp.c b/cmdline/unixapp.c index 78479c05..8609ba03 100644 --- a/cmdline/unixapp.c +++ b/cmdline/unixapp.c @@ -4447,6 +4447,7 @@ int devmap(void) { #if HAVE_LINUX_DEVICE char path[PATH_MAX]; + char boot_id[64]; DIR* d = opendir("/sys/block"); if (!d) { /* LCOV_EXCL_START */ @@ -4454,6 +4455,22 @@ int devmap(void) /* LCOV_EXCL_STOP */ } + /* optional boot identity: failure must not affect hardware mappings */ + if (sysattr("/proc/sys/kernel/random/boot_id", boot_id, sizeof(boot_id)) != 0 || strlen(boot_id) != 36) { + boot_id[0] = 0; + } else { + for (unsigned i = 0; i < 36; ++i) { + if (i == 8 || i == 13 || i == 18 || i == 23) { + if (boot_id[i] == '-') + continue; + } else if (hexval(boot_id[i]) >= 0) { + continue; + } + boot_id[0] = 0; + break; + } + } + struct dirent* dd; while (1) { char buf[256]; @@ -4517,6 +4534,20 @@ int devmap(void) if (sysattr(path, buf, sizeof(buf)) == 0 && buf[0] != 0) { log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf)); } + + /* + * This identifies the kernel device instance within one boot, not + * persistent hardware across reconnections. Missing attributes are optional. + */ + if (boot_id[0] != 0) { + pathprint(path, sizeof(path), "/sys/block/%s/diskseq", dd->d_name); + if (sysattr(path, buf, sizeof(buf)) == 0) { + char* end; + unsigned long long diskseq = strtonll(buf, &end, 10); + if (buf[0] >= '0' && buf[0] <= '9' && diskseq != 0 && end != buf && *end == 0) + log_tag("map:/dev/%s:linux-diskseq.%s.%llu\n", esc_tag(dd->d_name), esc_tag(boot_id), diskseq); + } + } } closedir(d);