From 4ba6ee874c628b7c7f45c2015d3ff025ed62b619 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 9 Apr 2026 15:15:48 +0200 Subject: [PATCH] Log the modification time of the content file in probe and other commmands --- HISTORY | 3 +-- cmdline/device.c | 4 ++-- cmdline/snapraid.c | 3 +++ cmdline/state.c | 53 ++++++++++++++++++++++++++++++++++++++++------ cmdline/state.h | 5 +++++ 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/HISTORY b/HISTORY index f2b20428..28f87912 100644 --- a/HISTORY +++ b/HISTORY @@ -10,8 +10,7 @@ SnapRAID HISTORY "make check" on build servers that may use such filesystems. No update is required if you have not encountered an error message about failure to advise files. - Note that this error is surfacing only now because the 14.x branch includes - more extensive tests. + * Log the modification time of the content file in probe and other commmands. 14.1 2026/03 ============ diff --git a/cmdline/device.c b/cmdline/device.c index 8f537d3d..63addd80 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -820,7 +820,7 @@ void state_attr(struct snapraid_state* state, tommy_list* low) } } -static void state_probe(struct snapraid_state* state, tommy_list* low) +static void state_probe_report(struct snapraid_state* state, tommy_list* low) { tommy_node* i; size_t device_pad; @@ -1126,7 +1126,7 @@ void state_device(struct snapraid_state* state, int operation, tommy_list* filte state_smart(state, state->level + tommy_list_count(&state->disklist), &low); if (operation == DEVICE_PROBE) - state_probe(state, &low); + state_probe_report(state, &low); if (operation == DEVICE_UP) state_attr(state, &low); diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 3b99f672..8a98a702 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1974,6 +1974,9 @@ int snapraid_main(int argc, char* argv[]) } else if (operation == OPERATION_SMART) { state_device(&state, DEVICE_SMART, 0); } else if (operation == OPERATION_PROBE) { + /* probe also the content file */ + state_probe(&state); + state_device(&state, DEVICE_PROBE, 0); } else if (operation == OPERATION_STATUS) { state_read(&state); diff --git a/cmdline/state.c b/cmdline/state.c index 953eec81..a9bafd44 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -4194,6 +4194,39 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) *out_crc = crc; } +void state_probe(struct snapraid_state* state) +{ + char path[PATH_MAX]; + struct stat st; + tommy_node* node; + + /* iterate over all the available content files and check the first one present */ + node = tommy_list_head(&state->contentlist); + while (node) { + struct snapraid_content* content = node->data; + + pathcpy(path, sizeof(path), content->content); + + if (stat(path, &st) == 0) { + /* if found stop the search */ + break; + } + + /* next content file */ + node = node->next; + } + + /* if not found, assume empty */ + if (!node) + return; + + if (!state->no_conf) { + /* intentionally don't output the content path because it's not really read */ + log_tag("content_info:probe_unixtime:%" PRId64 "\n", (int64_t)st.st_mtime); + log_flush(); + } +} + void state_read(struct snapraid_state* state) { STREAM* f; @@ -4210,16 +4243,11 @@ void state_read(struct snapraid_state* state) struct snapraid_content* content = node->data; pathcpy(path, sizeof(path), content->content); - if (!state->no_conf) { - char esc_buffer[ESC_MAX]; - log_tag("content:%s\n", esc_tag(path, esc_buffer)); - log_flush(); - } msg_progress("Loading state from %s...\n", path); f = sopen_read(path, STREAM_FLAGS_SEQUENTIAL | STREAM_FLAGS_CRC); if (f != 0) { - /* if opened stop the search */ + /* if found stop the search */ break; } else { /* if it's real error of an existing file, abort */ @@ -4261,6 +4289,13 @@ void state_read(struct snapraid_state* state) /* LCOV_EXCL_STOP */ } + if (!state->no_conf) { + char esc_buffer[ESC_MAX]; + log_tag("content:%s\n", esc_tag(path, esc_buffer)); + log_tag("content_info:read_unixtime:%" PRId64 "\n", (int64_t)st.st_mtime); + log_flush(); + } + /* go further to check other content files */ while (node) { char other_path[PATH_MAX]; @@ -4566,6 +4601,7 @@ static void state_rename_content(struct snapraid_state* state) void state_write(struct snapraid_state* state) { uint32_t crc; + time_t now; /* write all the content files */ state_write_content(state, &crc); @@ -4576,6 +4612,11 @@ void state_write(struct snapraid_state* state) /* rename the new files, over the old ones */ state_rename_content(state); + /* log the write time of the content file */ + now = time(0); + log_tag("content_info:write_unixtime:%" PRId64 "\n", (int64_t)now); + log_flush(); + state->need_write = 0; /* no write needed anymore */ state->checked_read = 0; /* what we wrote is not checked in read */ state->written = 1; diff --git a/cmdline/state.h b/cmdline/state.h index 677a5198..e0859647 100644 --- a/cmdline/state.h +++ b/cmdline/state.h @@ -217,6 +217,11 @@ void state_done(struct snapraid_state* state); */ void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt, tommy_list* filterlist_disk); +/** + * Probe the state. + */ +void state_probe(struct snapraid_state* state); + /** * Read the state. */