Log the modification time of the content file in probe and other commmands

This commit is contained in:
Andrea Mazzoleni 2026-04-09 15:15:48 +02:00
parent 323c943afb
commit 4ba6ee874c
5 changed files with 58 additions and 10 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -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.
*/