Adds preliminary list command.

This commit is contained in:
Andrea Mazzoleni 2013-10-04 21:35:08 +02:00
parent 70244133f4
commit 1b46d03d70
6 changed files with 127 additions and 13 deletions

View file

@ -16,6 +16,7 @@ snapraid_SOURCES = \
scrub.c \
status.c \
dup.c \
list.c \
pool.c \
parity.c \
handle.c \
@ -123,6 +124,7 @@ check-local:
echo --- As empty, sync and check forcing murmur3
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) diff
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) dup
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) list
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-murmur3 sync
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status
if HAVE_SYMLINK
@ -134,10 +136,11 @@ endif
$(TESTENV) ./mktest$(EXEEXT) generate 1 5 $(CHECKCOUNT) $(CHECKSIZE)
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) diff > test.log
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) diff -G > test.log
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) dup
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) dup -G
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) --test-force-order-physical sync
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status
echo --- Some commands with a not empty array
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) dup -l test.log
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(CONF) list -l test.log
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status -l test.log
if HAVE_SYMLINK
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(RAID5) pool
endif
@ -162,10 +165,12 @@ endif
ln test/disk3/file_hardlink1 test/disk3/file_hardlink2
ln test/disk3/file_hardlink1 test/disk3/file_hardlink3
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(RAID5) diff > test.log
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(RAID5) dup
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-fallocate -c $(RAID5) --test-force-order-inode sync
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) status
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-sequential -c $(RAID5) check
echo --- Some commands with a not empty array
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(RAID5) dup
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -v -c $(RAID5) list
if HAVE_SYMLINK
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(RAID5) pool
endif

3
TODO
View file

@ -5,9 +5,6 @@ This is the list of TODO items for SnapRAID.
- Next
* Remove/Reduce the opt.gui uses. We can now always output to stdlog becase
it never go to screen.
* Detect files moved from one disk to another. We won't be able to reuse
parity, but we can reuse the hash to check that the file was moved
correctly.

100
list.c Normal file
View file

@ -0,0 +1,100 @@
/*
* Copyright (C) 2011 Andrea Mazzoleni
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "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;
/* 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_alpha_compare);
/* for each file */
for(j=disk->filelist;j!=0;j=j->next) {
struct snapraid_file* file = j->data;
struct tm tm_res;
struct tm* tm;
time_t t;
++file_count;
file_size += file->size;
fprintf(stdlog, "file:%s:%s:%"PRIu64":%"PRIi64":%u:%"PRIi64"\n", disk->name, file->sub, file->size, file->mtime_sec, file->mtime_nsec, file->inode);
t = file->mtime_sec;
tm = localtime_r(&t, &tm_res);
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);
}
printf("%s%s\n", disk->dir, file->sub);
}
/* for each link */
for(j=disk->linklist;j!=0;j=j->next) {
struct snapraid_link* link = j->data;
const char* type;
switch (link->flag &FILE_IS_LINK_MASK) {
case FILE_IS_HARDLINK : type = "link"; break;
case FILE_IS_SYMLINK : type = "symlink"; break;
case FILE_IS_SYMDIR : type = "symdir"; break;
case FILE_IS_JUNCTION : type = "junction"; break;
default: type = "unknown"; break;
}
++link_count;
fprintf(stdlog, "link_%s:%s:%s:%s\n", type, disk->name, link->sub, link->linkto);
printf("%12s %s%s -> %s%s\n", type, disk->dir, link->sub, disk->dir, link->linkto);
}
}
printf("\n");
printf("%u files, for %"PRIu64" MiB.\n", file_count, file_size / (1024*1024));
printf("%u links.\n", link_count);
fprintf(stdlog, "summary:file_count:%u\n", file_count);
fprintf(stdlog, "summary:file_size:%"PRIu64"\n", file_size);
fprintf(stdlog, "summary:link_count:%u\n", link_count);
fprintf(stdlog, "summary:exit:ok\n");
fflush(stdlog);
}

2
pool.c
View file

@ -209,7 +209,7 @@ void state_pool(struct snapraid_state* state)
else
printf("No link created\n");
fprintf(stdlog, "summary:link::%u\n", count);
fprintf(stdlog, "summary:link_count::%u\n", count);
fprintf(stdlog, "summary:exit:ok\n");
fflush(stdlog);
}

View file

@ -207,11 +207,12 @@ void signal_handler(int signal)
#define OPERATION_FIX 3
#define OPERATION_DRY 4
#define OPERATION_DUP 5
#define OPERATION_POOL 6
#define OPERATION_REHASH 7
#define OPERATION_SCRUB 8
#define OPERATION_STATUS 9
#define OPERATION_REWRITE 10
#define OPERATION_LIST 6
#define OPERATION_POOL 7
#define OPERATION_REHASH 8
#define OPERATION_SCRUB 9
#define OPERATION_STATUS 10
#define OPERATION_REWRITE 11
int main(int argc, char* argv[])
{
@ -457,6 +458,8 @@ int main(int argc, char* argv[])
operation = OPERATION_DRY;
} else if (strcmp(argv[optind], "dup") == 0) {
operation = OPERATION_DUP;
} else if (strcmp(argv[optind], "list") == 0) {
operation = OPERATION_LIST;
} else if (strcmp(argv[optind], "pool") == 0) {
operation = OPERATION_POOL;
} else if (strcmp(argv[optind], "rehash") == 0) {
@ -686,6 +689,10 @@ int main(int argc, char* argv[])
state_read(&state);
state_dup(&state);
} else if (operation == OPERATION_LIST) {
state_read(&state);
state_list(&state);
} else if (operation == OPERATION_POOL) {
state_read(&state);

View file

@ -180,6 +180,11 @@ int state_status(struct snapraid_state* state);
*/
void state_dup(struct snapraid_state* state);
/**
* List content.
*/
void state_list(struct snapraid_state* state);
/**
* Creates pool tree.
*/