mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-12 02:10:54 +00:00
109 lines
2.8 KiB
C
109 lines
2.8 KiB
C
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Copyright (C) 2013 Andrea Mazzoleni
|
|
|
|
#include "os/portable.h"
|
|
|
|
#include "util.h"
|
|
#include "elem.h"
|
|
#include "state.h"
|
|
#include "parity.h"
|
|
#include "handle.h"
|
|
|
|
/****************************************************************************/
|
|
/* list */
|
|
|
|
void state_list(struct snapraid_state* state)
|
|
{
|
|
tommy_node* i;
|
|
unsigned file_count;
|
|
data_off_t file_size;
|
|
unsigned link_count;
|
|
file_count = 0;
|
|
file_size = 0;
|
|
link_count = 0;
|
|
|
|
msg_progress("Listing...\n");
|
|
|
|
/* for each disk */
|
|
for (i = state->disklist; i != 0; i = i->next) {
|
|
tommy_node* j;
|
|
struct snapraid_disk* disk = i->data;
|
|
|
|
/* sort by name */
|
|
tommy_list_sort(&disk->filelist, file_path_compare);
|
|
|
|
/* for each file */
|
|
for (j = disk->filelist; j != 0; j = j->next) {
|
|
struct snapraid_file* file = j->data;
|
|
#if HAVE_LOCALTIME_R
|
|
struct tm tm_res;
|
|
#endif
|
|
struct tm* tm;
|
|
time_t t;
|
|
|
|
++file_count;
|
|
file_size += file->size;
|
|
|
|
if (state->opt.gui_verbose)
|
|
log_tag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIu64 "\n", disk->name, esc_tag(file->sub), file->size, file->mtime_sec, file->mtime_nsec, file->inode);
|
|
|
|
t = file->mtime_sec;
|
|
#if HAVE_LOCALTIME_R
|
|
tm = localtime_r(&t, &tm_res);
|
|
#else
|
|
tm = localtime(&t);
|
|
#endif
|
|
|
|
printf("%12" PRIu64 " ", file->size);
|
|
if (tm) {
|
|
printf("%04u/%02u/%02u %02u:%02u", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
|
|
if (msg_level >= MSG_VERBOSE)
|
|
printf(":%02u.%09u", tm->tm_sec, file->mtime_nsec);
|
|
printf(" ");
|
|
}
|
|
printf("%s\n", fmt_term(disk, file->sub));
|
|
}
|
|
|
|
/* sort by name */
|
|
tommy_list_sort(&disk->linklist, link_alpha_compare);
|
|
|
|
/* for each link */
|
|
for (j = disk->linklist; j != 0; j = j->next) {
|
|
struct snapraid_link* slink = j->data;
|
|
const char* type;
|
|
|
|
switch (slink->flag & FILE_IS_LINK_MASK) {
|
|
case FILE_IS_HARDLINK : type = "hardlink"; break;
|
|
case FILE_IS_SYMLINK : type = "symlink"; break;
|
|
case FILE_IS_SYMDIR : type = "symdir"; break;
|
|
case FILE_IS_JUNCTION : type = "junction"; break;
|
|
/* LCOV_EXCL_START */
|
|
default : type = "unknown"; break;
|
|
/* LCOV_EXCL_STOP */
|
|
}
|
|
|
|
++link_count;
|
|
|
|
if (state->opt.gui_verbose)
|
|
log_tag("link_%s:%s:%s:%s\n", type, disk->name, esc_tag(slink->sub), esc_tag(slink->linkto));
|
|
|
|
printf("%12s ", type);
|
|
printf(" ");
|
|
if (msg_level >= MSG_VERBOSE)
|
|
printf(" ");
|
|
printf("%s -> %s\n", fmt_term(disk, slink->sub), fmt_term(disk, slink->linkto));
|
|
}
|
|
}
|
|
|
|
msg_status("\n");
|
|
msg_status("%8u files, for %" PRIu64 " GB\n", file_count, file_size / GIGA);
|
|
msg_status("%8u links\n", link_count);
|
|
|
|
log_tag("summary:file_count:%u\n", file_count);
|
|
log_tag("summary:file_size:%" PRIu64 "\n", file_size);
|
|
log_tag("summary:link_count:%u\n", link_count);
|
|
log_tag("summary:exit:ok\n");
|
|
log_flush();
|
|
}
|
|
|