diff --git a/HISTORY b/HISTORY index 0a6a2c74..a2706433 100644 --- a/HISTORY +++ b/HISTORY @@ -9,6 +9,8 @@ SnapRAID HISTORY without checking/fixing the others. * Added a new -i, --import option to automatically import deleted files when fixing. + * Added a new -l, --log option to save to disk the detailed log. + Note that if not specified the log is not printed anymore by default. * Added support also for hardlinks and empty directories. * Added support to save symlinks to files in Windows. Note that only the symlink is saved and not the linked file. diff --git a/Makefile.am b/Makefile.am index aa9b0d03..2249ab7f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -190,9 +190,9 @@ endif mkdir test/disk1 rm -r test/disk2 mkdir test/disk2 - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf fix 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf fix -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf check $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Sync after all the fixes with an empty drive to test --find-by-name @@ -204,11 +204,11 @@ endif rm test/disk3/6* $(TESTENV) ./mktest$(EXEEXT) generate 4 3 $(CHECKCOUNT) $(CHECKSIZE) $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf -t 100 sync - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf -t 700 sync - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf -t 1000 sync - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf sync $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Delete files from three disks and fix with import in RAID6 @@ -217,8 +217,8 @@ endif rm -r test/disk2/_a rm -r test/disk2/_b mv test/disk3/_a test/_a - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid6.conf fix 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -i test/_a -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid6.conf fix -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -i test/_a -c $(srcdir)/test-raid6.conf fix -l test.log rm -r test/_a $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf sync echo --- Abort sync late with additions, delete them and recover with RAID6 @@ -228,7 +228,7 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-kill-after-sync -c $(srcdir)/test-raid6.conf sync rm -r test/disk1/_c rm -r test/disk1/_d - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log rm -r test/disk1/_c rm -r test/disk1/_d $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf sync @@ -239,7 +239,7 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -t 1 --test-kill-after-sync -c $(srcdir)/test-raid6.conf sync rm -r test/disk1/_c rm -r test/disk1/_d - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid6.conf fix -l test.log rm -r test/disk1/_c rm -r test/disk1/_d $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf sync @@ -257,7 +257,7 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf --test-kill-after-sync sync rm -r test/disk2 mkdir test/disk2 - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix -l test.log rm -r test/disk1/_c $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf sync echo --- Abort sync late with more deletions than additions and then delete some unchanged stuff and fix with RAID5 @@ -267,7 +267,7 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf --test-kill-after-sync sync rm -r test/disk2 mkdir test/disk2 - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix -l test.log -rm -r test/disk1/_a -rm -r test/disk1/_b rm -r test/disk1/_c @@ -281,8 +281,8 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf -t 1 --test-kill-after-sync sync rm -r test/disk2 mkdir test/disk2 - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf fix 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf fix -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log -rm -r test/disk1/_a -rm -r test/disk1/_b rm -r test/disk1/_c @@ -291,67 +291,67 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf sync echo --- Delete some files, fix with -m and check with raid5 rm test/disk1/8* - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf -m fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf -m fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Delete some dirs in a disk, fix with -m and check with raid5 rm -r test/disk2/_a rm -r test/disk2/_b - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf -m fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf -m fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Delete some dirs in two disks, fix and check with raid6 using the -d option for each disk rm -r test/disk2/_a rm -r test/disk2/_b rm -r test/disk3/_a rm -r test/disk3/_b - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf fix 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf -d disk2 fix 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf -d disk3 fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf fix -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf -d disk2 fix -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf -d disk3 fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Delete the parity, fix and check with raid5 rm test/parity - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Delete the parity and the q-parity, fix and check with raid6 rm test/parity rm test/q-parity - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Delete the parity and a disk, fix and check with raid6 rm test/parity rm -r test/disk2/_a rm -r test/disk2/_b - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Delete the q-parity and a disk, fix and check with raid6 rm test/q-parity rm -r test/disk3/_a rm -r test/disk3/_b - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Corrupt the parity, fix and check with raid5 $(TESTENV) ./mktest$(EXEEXT) damage 1 100 10000 test/parity - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf -a check - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Corrupt the parity and the q-parity, fix and check with raid6 $(TESTENV) ./mktest$(EXEEXT) damage 2 100 10000 test/parity $(TESTENV) ./mktest$(EXEEXT) damage 2 100 10000 test/q-parity - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf -a check - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Corrupt some files, fix and check with raid5 $(TESTENV) ./mktest$(EXEEXT) damage 3 1 500 test/disk2/b* $(TESTENV) ./mktest$(EXEEXT) append 3 500 test/disk2/c* $(TESTENV) ./mktest$(EXEEXT) truncate 3 500 test/disk2/d* - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf -a check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf -a check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Corrupt some files, fix and check with raid6 $(TESTENV) ./mktest$(EXEEXT) damage 4 1 500 test/disk2/_a/_a/* @@ -362,11 +362,11 @@ endif $(TESTENV) ./mktest$(EXEEXT) append 4 500 test/disk3/_b/_a/* $(TESTENV) ./mktest$(EXEEXT) truncate 4 500 test/disk2/_b/_b/* $(TESTENV) ./mktest$(EXEEXT) truncate 4 500 test/disk3/_b/_b/* - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf -a check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf -a check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf -a check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf -a check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Another time with different values $(TESTENV) ./mktest$(EXEEXT) damage 5 2 50 test/disk2/_a/_a/* @@ -379,9 +379,9 @@ endif $(TESTENV) ./mktest$(EXEEXT) append 5 1500 test/disk3/_b/_a/* $(TESTENV) ./mktest$(EXEEXT) truncate 5 1500 test/disk2/_b/_b/* $(TESTENV) ./mktest$(EXEEXT) truncate 5 1500 test/disk3/_b/_b/* - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Corrupt the parity and some files, fix and check with raid6 $(TESTENV) ./mktest$(EXEEXT) damage 6 100 10000 test/parity @@ -389,9 +389,9 @@ endif $(TESTENV) ./mktest$(EXEEXT) damage 6 1 500 test/disk1/_a/_b/* $(TESTENV) ./mktest$(EXEEXT) append 6 500 test/disk1/_b/_a/* $(TESTENV) ./mktest$(EXEEXT) truncate 6 500 test/disk1/_b/_b/* - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-unrecoverable -c $(srcdir)/test-raid5.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Corrupt the q-parity and some files, fix and check with raid6 $(TESTENV) ./mktest$(EXEEXT) damage 7 100 10000 test/q-parity @@ -399,9 +399,9 @@ endif $(TESTENV) ./mktest$(EXEEXT) damage 7 1 500 test/disk1/_a/_b/* $(TESTENV) ./mktest$(EXEEXT) append 7 500 test/disk1/_b/_a/* $(TESTENV) ./mktest$(EXEEXT) truncate 7 500 test/disk1/_b/_b/* - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check 2>> test.log - $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix 2>> test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid5.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self --test-expect-recoverable -c $(srcdir)/test-raid6.conf check -l test.log + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf fix -l test.log $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check echo --- Sync after all the fixes $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf sync diff --git a/check.c b/check.c index e10fd327..2176b560 100644 --- a/check.c +++ b/check.c @@ -138,7 +138,7 @@ static int repair_step(struct snapraid_state* state, unsigned pos, unsigned disk return 0; } - fprintf(stderr, "error:%u:parity: Data error\n", pos); + fprintf(stdlog, "error:%u:parity: Data error\n", pos); ++error; } @@ -168,7 +168,7 @@ static int repair_step(struct snapraid_state* state, unsigned pos, unsigned disk return 0; } - fprintf(stderr, "error:%u:qarity: Data error\n", pos); + fprintf(stdlog, "error:%u:qarity: Data error\n", pos); ++error; } @@ -187,7 +187,7 @@ static int repair_step(struct snapraid_state* state, unsigned pos, unsigned disk return 0; } - fprintf(stderr, "error:%u:parity/qarity: Data error\n", pos); + fprintf(stdlog, "error:%u:parity/qarity: Data error\n", pos); ++error; } @@ -218,7 +218,7 @@ static int repair_step(struct snapraid_state* state, unsigned pos, unsigned disk return 0; } - fprintf(stderr, "error:%u:parity/qarity: Data error\n", pos); + fprintf(stdlog, "error:%u:parity/qarity: Data error\n", pos); ++error; } @@ -619,17 +619,17 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* check if the file was larger and now truncated */ if (ret == 1) { - fprintf(stderr, "File '%s' is larger than expected.\n", handle[j].path); - fprintf(stderr, "error:%u:%s:%s: Size error\n", i, handle[j].disk->name, block_file_get(block)->sub); + fprintf(stdlog, "File '%s' is larger than expected.\n", handle[j].path); + fprintf(stdlog, "error:%u:%s:%s: Size error\n", i, handle[j].disk->name, block_file_get(block)->sub); ++error; /* this is already a recovered error */ - fprintf(stderr, "fixed:%u:%s:%s: Fixed size\n", i, handle[j].disk->name, block_file_get(block)->sub); + fprintf(stdlog, "fixed:%u:%s:%s: Fixed size\n", i, handle[j].disk->name, block_file_get(block)->sub); ++recovered_error; } } else { /* if checking or hashing, open the file only for reading */ - ret = handle_open(&handle[j], block_file_get(block)); + ret = handle_open(&handle[j], block_file_get(block), stdlog); if (ret == -1) { /* save the failed block for the check/fix */ failed[failed_count].is_bad = 1; @@ -639,7 +639,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, failed[failed_count].handle = &handle[j]; ++failed_count; - fprintf(stderr, "error:%u:%s:%s: Open error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); + fprintf(stdlog, "error:%u:%s:%s: Open error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); ++error; continue; } @@ -648,8 +648,8 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (!file_flag_has(block_file_get(block), FILE_IS_LARGER) && handle[j].st.st_size > block_file_get(block)->size ) { - fprintf(stderr, "File '%s' is larger than expected.\n", handle[j].path); - fprintf(stderr, "error:%u:%s:%s: Size error\n", i, handle[j].disk->name, block_file_get(block)->sub); + fprintf(stdlog, "File '%s' is larger than expected.\n", handle[j].path); + fprintf(stdlog, "error:%u:%s:%s: Size error\n", i, handle[j].disk->name, block_file_get(block)->sub); ++error; /* if fragmented, it may be reopened, so store the notification */ @@ -659,7 +659,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, } /* read from the file */ - read_size = handle_read(&handle[j], block, buffer[j], state->block_size); + read_size = handle_read(&handle[j], block, buffer[j], state->block_size, stdlog); if (read_size == -1) { /* save the failed block for the check/fix */ failed[failed_count].is_bad = 1; @@ -669,7 +669,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, failed[failed_count].handle = &handle[j]; ++failed_count; - fprintf(stderr, "error:%u:%s:%s: Read error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); + fprintf(stdlog, "error:%u:%s:%s: Read error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); ++error; continue; } @@ -704,7 +704,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, failed[failed_count].handle = &handle[j]; ++failed_count; - fprintf(stderr, "error:%u:%s:%s: Data error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); + fprintf(stdlog, "error:%u:%s:%s: Data error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); ++error; continue; } @@ -729,11 +729,11 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* read the parity */ if (parity) { - ret = parity_read(parity, i, buffer_parity, state->block_size); + ret = parity_read(parity, i, buffer_parity, state->block_size, stdlog); if (ret == -1) { buffer_parity = 0; /* no parity to use */ - fprintf(stderr, "error:%u:parity: Read error\n", i); + fprintf(stdlog, "error:%u:parity: Read error\n", i); ++error; } } else { @@ -743,11 +743,11 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* read the qarity */ if (state->level >= 2) { if (qarity) { - ret = parity_read(qarity, i, buffer_qarity, state->block_size); + ret = parity_read(qarity, i, buffer_qarity, state->block_size, stdlog); if (ret == -1) { buffer_qarity = 0; /* no qarity to use */ - fprintf(stderr, "error:%u:qarity: Read error\n", i); + fprintf(stdlog, "error:%u:qarity: Read error\n", i); ++error; } } else { @@ -766,7 +766,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* print a list of all the errors in files */ for(j=0;jdisk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); + fprintf(stdlog, "unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); } if (fix) { @@ -786,7 +786,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, for(j=0;jdisk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); + fprintf(stdlog, "unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); } } if (partial_recover_error != 0) { @@ -802,7 +802,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (buffer_parity != 0 && memcmp(buffer_parity, buffer[diskmax], state->block_size) != 0) { buffer_parity = 0; - fprintf(stderr, "error:%u:parity: Data error\n", i); + fprintf(stdlog, "error:%u:parity: Data error\n", i); ++error; } @@ -811,7 +811,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (buffer_qarity != 0 && memcmp(buffer_qarity, buffer[diskmax + 1], state->block_size) != 0) { buffer_qarity = 0; - fprintf(stderr, "error:%u:qarity: Data error\n", i); + fprintf(stdlog, "error:%u:qarity: Data error\n", i); ++error; } } @@ -855,7 +855,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* mark the file as fixed */ file_flag_set(block_file_get(failed[j].block), FILE_IS_FIXED); - fprintf(stderr, "fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); + fprintf(stdlog, "fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].handle->disk->name, block_file_get(failed[j].block)->sub, block_file_pos(failed[j].block)); ++recovered_error; } @@ -874,7 +874,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, goto bail; } - fprintf(stderr, "fixed:%u:parity: Fixed data error\n", i); + fprintf(stdlog, "fixed:%u:parity: Fixed data error\n", i); ++recovered_error; } @@ -890,7 +890,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, goto bail; } - fprintf(stderr, "fixed:%u:qarity: Fixed data error\n", i); + fprintf(stdlog, "fixed:%u:qarity: Fixed data error\n", i); ++recovered_error; } } @@ -953,13 +953,16 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, ret = rename(path_from, path_to); if (ret != 0) { - fprintf(stderr, "Error renaming '%s' to '%s'. %s.\n", path_from, path_to, strerror(errno)); + fprintf(stderr, "Error renaming '%s' to '%s'. %s.\n", path_from, path_to, strerror(errno)); fprintf(stderr, "WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); printf("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; } + printf("Unrecoverable '%s'\n", path_from); + fprintf(stdlog, "status:bad:%s:%s\n", handle[j].disk->name, block_file_get(block)->sub); + /* and do not set the time if damaged */ continue; } @@ -969,7 +972,10 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* nothing to do */ continue; } - + + printf("Recovered '%s%s'\n", handle[j].disk->dir, handle[j].file->sub); + fprintf(stdlog, "status:ok:%s:%s\n", handle[j].disk->name, handle[j].file->sub); + inode = handle[j].st.st_ino; /* search for the corresponding inode */ @@ -1000,7 +1006,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, goto bail; } } else { - fprintf(stderr, "collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", handle[j].disk->name, block_file_get(block)->sub, collide_file->sub); + fprintf(stdlog, "collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", handle[j].disk->name, block_file_get(block)->sub, collide_file->sub); } } } @@ -1050,18 +1056,18 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (ret == -1) { failed = 1; - fprintf(stderr, "Error stating empty file '%s'. %s.\n", path, strerror(errno)); - fprintf(stderr, "error:%s:%s: Empty file stat error\n", disk->name, file->sub); + fprintf(stdlog, "Error stating empty file '%s'. %s.\n", path, strerror(errno)); + fprintf(stdlog, "error:%s:%s: Empty file stat error\n", disk->name, file->sub); ++error; } else if (!S_ISREG(st.st_mode)) { failed = 1; - fprintf(stderr, "error:%s:%s: Empty file error for not regular file\n", disk->name, file->sub); + fprintf(stdlog, "error:%s:%s: Empty file error for not regular file\n", disk->name, file->sub); ++error; } else if (st.st_size != 0) { failed = 1; - fprintf(stderr, "error:%s:%s: Empty file error for size '%"PRIu64"'\n", disk->name, file->sub, st.st_size); + fprintf(stdlog, "error:%s:%s: Empty file error for size '%"PRIu64"'\n", disk->name, file->sub, st.st_size); ++error; } @@ -1096,8 +1102,11 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, /* close it */ close(f); - fprintf(stderr, "fixed:%s:%s: Fixed empty file\n", disk->name, file->sub); + fprintf(stdlog, "fixed:%s:%s: Fixed empty file\n", disk->name, file->sub); ++recovered_error; + + printf("Recovered '%s%s'\n", disk->dir, file->sub); + fprintf(stdlog, "status:ok:%s:%s\n", disk->name, file->sub); } } @@ -1129,13 +1138,13 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (ret == -1) { failed = 1; - fprintf(stderr, "Error stating hardlink '%s'. %s.\n", path, strerror(errno)); - fprintf(stderr, "hardlinkerror:%s:%s:%s: Hardlink stat error\n", disk->name, link->sub, link->linkto); + fprintf(stdlog, "Error stating hardlink '%s'. %s.\n", path, strerror(errno)); + fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink stat error\n", disk->name, link->sub, link->linkto); ++error; } else if (!S_ISREG(st.st_mode)) { failed = 1; - fprintf(stderr, "hardlinkerror:%s:%s:%s: Hardlink error for not regular file\n", disk->name, link->sub, link->linkto); + fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink error for not regular file\n", disk->name, link->sub, link->linkto); ++error; } @@ -1145,25 +1154,25 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (ret == -1) { failed = 1; - fprintf(stderr, "Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno)); - fprintf(stderr, "hardlinkerror:%s:%s:%s: Hardlink to stat error\n", disk->name, link->sub, link->linkto); if (errno == ENOENT) { - /* if the targer doesn't exist, it's unrecoverable */ + /* if the target doesn't exist, it's unrecoverable */ unrecoverable = 1; ++unrecoverable_error; } + fprintf(stdlog, "Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno)); + fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink to stat error\n", disk->name, link->sub, link->linkto); ++error; } else if (!S_ISREG(stto.st_mode)) { failed = 1; - fprintf(stderr, "hardlinkerror:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, link->sub, link->linkto); + fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, link->sub, link->linkto); ++error; } else if (!failed && st.st_ino != stto.st_ino) { failed = 1; - fprintf(stderr, "Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto); - fprintf(stderr, "hardlinkerror:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, link->sub, link->linkto); + fprintf(stdlog, "Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto); + fprintf(stdlog, "hardlinkerror:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, link->sub, link->linkto); ++error; } } else { @@ -1173,14 +1182,14 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (ret < 0) { failed = 1; - fprintf(stderr, "Error reading symlink '%s'. %s.\n", path, strerror(errno)); - fprintf(stderr, "symlinkerror:%s:%s: Symlink read error\n", disk->name, link->sub); + fprintf(stdlog, "Error reading symlink '%s'. %s.\n", path, strerror(errno)); + fprintf(stdlog, "symlinkerror:%s:%s: Symlink read error\n", disk->name, link->sub); ++error; } else if (ret >= PATH_MAX) { failed = 1; - fprintf(stderr, "Error reading symlink '%s'. Symlink too long.\n", path); - fprintf(stderr, "symlinkerror:%s:%s: Symlink read error\n", disk->name, link->sub); + fprintf(stdlog, "Error reading symlink '%s'. Symlink too long.\n", path); + fprintf(stdlog, "symlinkerror:%s:%s: Symlink read error\n", disk->name, link->sub); ++error; } else { linkto[ret] = 0; @@ -1188,7 +1197,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (strcmp(linkto, link->linkto) != 0) { failed = 1; - fprintf(stderr, "symlinkerror:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, link->sub, linkto, link->linkto); + fprintf(stdlog, "symlinkerror:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, link->sub, linkto, link->linkto); ++error; } } @@ -1218,7 +1227,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (link_flag_has(link, FILE_IS_HARDLINK)) { ret = hardlink(pathto, path); if (ret != 0) { - fprintf(stderr, "Error writing hardlink '%s'. %s.\n", path, strerror(errno)); + fprintf(stderr, "Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno)); if (errno == EACCES) { fprintf(stderr, "WARNING! Please give write permission to the hardlink.\n"); } else { @@ -1230,12 +1239,12 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, goto bail; } - fprintf(stderr, "hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, link->sub); + fprintf(stdlog, "hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, link->sub); ++recovered_error; } else { ret = symlink(link->linkto, path); if (ret != 0) { - fprintf(stderr, "Error writing symlink '%s'. %s.\n", path, strerror(errno)); + fprintf(stderr, "Error writing symlink '%s' to '%s'. %s.\n", path, link->linkto, strerror(errno)); if (errno == EACCES) { fprintf(stderr, "WARNING! Please give write permission to the symlink.\n"); } else { @@ -1247,9 +1256,12 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, goto bail; } - fprintf(stderr, "symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, link->sub); + fprintf(stdlog, "symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, link->sub); ++recovered_error; } + + printf("Recovered '%s%s'\n", disk->dir, link->sub); + fprintf(stdlog, "status:ok:%s:%s\n", disk->name, link->sub); } } @@ -1276,13 +1288,13 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, if (ret == -1) { failed = 1; - fprintf(stderr, "Error stating dir '%s'. %s.\n", path, strerror(errno)); - fprintf(stderr, "dir_error:%s:%s: Dir stat error\n", disk->name, dir->sub); + fprintf(stdlog, "Error stating dir '%s'. %s.\n", path, strerror(errno)); + fprintf(stdlog, "dir_error:%s:%s: Dir stat error\n", disk->name, dir->sub); ++error; } else if (!S_ISDIR(st.st_mode)) { failed = 1; - fprintf(stderr, "dir_error:%s:%s: Dir error for not directory\n", disk->name, dir->sub); + fprintf(stdlog, "dir_error:%s:%s: Dir error for not directory\n", disk->name, dir->sub); ++error; } @@ -1311,8 +1323,11 @@ static int state_check_process(struct snapraid_state* state, int check, int fix, goto bail; } - fprintf(stderr, "dir_fixed:%s:%s: Fixed dir error\n", disk->name, dir->sub); + fprintf(stdlog, "dir_fixed:%s:%s: Fixed dir error\n", disk->name, dir->sub); ++recovered_error; + + printf("Recovered '%s%s'\n", disk->dir, dir->sub); + fprintf(stdlog, "status:ok:%s:%s\n", disk->name, dir->sub); } } } diff --git a/dry.c b/dry.c index 9b9c1faf..c64306d6 100644 --- a/dry.c +++ b/dry.c @@ -74,16 +74,16 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit } /* open the file for reading */ - ret = handle_open(&handle[j], block_file_get(block)); + ret = handle_open(&handle[j], block_file_get(block), stdlog); if (ret == -1) { - fprintf(stderr, "error:%u:%s:%s: Open error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); + fprintf(stdlog, "error:%u:%s:%s: Open error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); ++error; continue; } - read_size = handle_read(&handle[j], block, buffer, state->block_size); + read_size = handle_read(&handle[j], block, buffer, state->block_size, stdlog); if (read_size == -1) { - fprintf(stderr, "error:%u:%s:%s: Read error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); + fprintf(stdlog, "error:%u:%s:%s: Read error at position %u\n", i, handle[j].disk->name, block_file_get(block)->sub, block_file_pos(block)); ++error; continue; } @@ -93,9 +93,9 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit /* read the parity */ if (parity) { - ret = parity_read(parity, i, buffer, state->block_size); + ret = parity_read(parity, i, buffer, state->block_size, stdlog); if (ret == -1) { - fprintf(stderr, "error:%u:parity: Read error\n", i); + fprintf(stdlog, "error:%u:parity: Read error\n", i); ++error; } } @@ -103,9 +103,9 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit /* read the qarity */ if (state->level >= 2) { if (qarity) { - ret = parity_read(qarity, i, buffer, state->block_size); + ret = parity_read(qarity, i, buffer, state->block_size, stdlog); if (ret == -1) { - fprintf(stderr, "error:%u:qarity: Read error\n", i); + fprintf(stdlog, "error:%u:qarity: Read error\n", i); ++error; } } diff --git a/dup.c b/dup.c index 7a090c5b..0271b594 100644 --- a/dup.c +++ b/dup.c @@ -118,7 +118,7 @@ void state_dup(struct snapraid_state* state) ++count; size += dup->file->size; if (state->gui) { - fprintf(stderr, "dup:%s:%s:%s:%s:%"PRIu64": dup\n", disk->name, file->sub, dup->disk->name, dup->file->sub, dup->file->size); + fprintf(stdlog, "dup:%s:%s:%s:%s:%"PRIu64": dup\n", disk->name, file->sub, dup->disk->name, dup->file->sub, dup->file->size); } else { printf("Duplicate '%s%s'\n", disk->dir, file->sub); printf("of '%s%s'\n", dup->disk->dir, dup->file->sub); diff --git a/handle.c b/handle.c index bbe196a7..522a712b 100644 --- a/handle.c +++ b/handle.c @@ -109,7 +109,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file) return 0; } -int handle_open(struct snapraid_handle* handle, struct snapraid_file* file) +int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, FILE* stdout) { int ret; @@ -131,7 +131,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file) handle->f = -1; handle->valid_size = 0; - fprintf(stderr, "Error opening file '%s'. %s.\n", handle->path, strerror(errno)); + fprintf(stdout, "Error opening file '%s'. %s.\n", handle->path, strerror(errno)); return -1; } @@ -141,7 +141,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file) /* get the stat info */ ret = fstat(handle->f, &handle->st); if (ret != 0) { - fprintf(stderr, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); + fprintf(stdout, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; } @@ -152,7 +152,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file) /* advise sequential access */ ret = posix_fadvise(handle->f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { - fprintf(stderr, "Error advising file '%s'. %s.\n", handle->path, strerror(ret)); + fprintf(stdout, "Error advising file '%s'. %s.\n", handle->path, strerror(ret)); return -1; } #endif @@ -186,7 +186,7 @@ int handle_close(struct snapraid_handle* handle) return 0; } -int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size) +int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, FILE* stdout) { ssize_t read_ret; data_off_t offset; @@ -197,7 +197,7 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un /* check if we are going to read only not initialized data */ if (offset >= handle->valid_size) { - fprintf(stderr, "Reading missing data from file '%s' at offset %"PRIu64".\n", handle->path, offset); + fprintf(stdout, "Reading missing data from file '%s' at offset %"PRIu64".\n", handle->path, offset); return -1; } @@ -205,7 +205,7 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un #if !HAVE_PREAD if (lseek(handle->f, offset, SEEK_SET) != offset) { - fprintf(stderr, "Error seeking file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno)); + fprintf(stdout, "Error seeking file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno)); return -1; } #endif @@ -220,11 +220,11 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un #endif if (read_ret < 0) { - fprintf(stderr, "Error reading file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno)); + fprintf(stdout, "Error reading file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno)); return -1; } if (read_ret == 0) { - fprintf(stderr, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno)); + fprintf(stdout, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", handle->path, offset, strerror(errno)); return -1; } diff --git a/handle.h b/handle.h index 3856d5a8..1bdfe7d0 100644 --- a/handle.h +++ b/handle.h @@ -47,7 +47,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file); * Opens a file. * The file is opened for reading. */ -int handle_open(struct snapraid_handle* handle, struct snapraid_file* file); +int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, FILE* stdout); /** * Closes a file. @@ -58,7 +58,7 @@ int handle_close(struct snapraid_handle* handle); * Read a block from a file. * If the read block is shorter, it's padded with 0. */ -int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size); +int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size, FILE* stdout); /** * Writes a block to a file. diff --git a/parity.c b/parity.c index ecd81a70..4bb75e18 100644 --- a/parity.c +++ b/parity.c @@ -76,8 +76,8 @@ void parity_overflow(struct snapraid_state* state, data_off_t size) if (file->blockmax > 0) { if (file->blockvec[0].parity_pos > blockalloc) { if (state->gui) { - fprintf(stderr, "outofparity:%s:%s\n", disk->name, file->sub); - fflush(stderr); + fprintf(stdlog, "outofparity:%s:%s\n", disk->name, file->sub); + fflush(stdlog); } if (first) { first = 0; @@ -363,7 +363,7 @@ int parity_write(struct snapraid_parity* parity, block_off_t pos, unsigned char* return 0; } -int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size) +int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size, FILE* stdout) { ssize_t read_ret; data_off_t offset; @@ -373,13 +373,13 @@ int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* /* check if we are going to read only not initialized data */ if (offset >= parity->valid_size) { - fprintf(stderr, "Reading missing data from file '%s' at offset %"PRIu64".\n", parity->path, offset); + fprintf(stdout, "Reading missing data from file '%s' at offset %"PRIu64".\n", parity->path, offset); return -1; } #if !HAVE_PREAD if (lseek(parity->f, offset, SEEK_SET) != offset) { - fprintf(stderr, "Error seeking file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno)); + fprintf(stdout, "Error seeking file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno)); return -1; } #endif @@ -393,11 +393,11 @@ int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* read_ret = read(parity->f, block_buffer + count, block_size - count); #endif if (read_ret < 0) { - fprintf(stderr, "Error reading file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno)); + fprintf(stdout, "Error reading file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno)); return -1; } if (read_ret == 0) { - fprintf(stderr, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno)); + fprintf(stdout, "Unexpected end of file '%s' at offset %"PRIu64". %s.\n", parity->path, offset, strerror(errno)); return -1; } diff --git a/parity.h b/parity.h index 789881c3..7ca29857 100644 --- a/parity.h +++ b/parity.h @@ -68,7 +68,7 @@ int parity_close(struct snapraid_parity* parity); /** * Read a block from the parity file. */ -int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size); +int parity_read(struct snapraid_parity* parity, block_off_t pos, unsigned char* block_buffer, unsigned block_size, FILE* stdout); /** * Writes a block in the parity file. diff --git a/pool.c b/pool.c index 36aea366..a469214b 100644 --- a/pool.c +++ b/pool.c @@ -146,7 +146,7 @@ static void make_link(const char* pool_dir, struct snapraid_disk* disk, const ch ret = symlink(linkto, path); if (ret != 0) { if (errno == EEXIST) { - fprintf(stderr, "warning: '%s' already exists\n", path); + fprintf(stderr, "warning: Duplicate pooling for '%s'\n", path); #ifdef _WIN32 } else if (errno == EPERM) { fprintf(stderr, "You must run as Adminstrator to be able to create symlinks.\n"); diff --git a/portable.h b/portable.h index 01f2216a..8c55bfcc 100644 --- a/portable.h +++ b/portable.h @@ -138,5 +138,10 @@ void os_init(void); */ void os_done(void); +/** + * Global log file. + */ +FILE* stdlog; + #endif diff --git a/scan.c b/scan.c index ac8ec61f..59af51fb 100644 --- a/scan.c +++ b/scan.c @@ -93,8 +93,8 @@ static void scan_link(struct snapraid_scan* scan, struct snapraid_state* state, ++scan->count_equal; if (state->gui) { - fprintf(stderr, "scan:equal:%s:%s\n", disk->name, link->sub); - fflush(stderr); + fprintf(stdlog, "scan:equal:%s:%s\n", disk->name, link->sub); + fflush(stdlog); } /* nothing more to do */ @@ -102,8 +102,8 @@ static void scan_link(struct snapraid_scan* scan, struct snapraid_state* state, } else { /* it's an update */ if (state->gui) { - fprintf(stderr, "scan:update:%s:%s\n", disk->name, link->sub); - fflush(stderr); + fprintf(stdlog, "scan:update:%s:%s\n", disk->name, link->sub); + fflush(stdlog); } if (output) { printf("Update '%s%s'\n", disk->dir, link->sub); @@ -123,8 +123,8 @@ static void scan_link(struct snapraid_scan* scan, struct snapraid_state* state, ++scan->count_insert; if (state->gui) { - fprintf(stderr, "scan:add:%s:%s\n", disk->name, sub); - fflush(stderr); + fprintf(stdlog, "scan:add:%s:%s\n", disk->name, sub); + fflush(stdlog); } if (output) { printf("Add '%s%s'\n", disk->dir, sub); @@ -322,8 +322,8 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, } if (state->gui) { - fprintf(stderr, "scan:move:%s:%s:%s\n", disk->name, file->sub, sub); - fflush(stderr); + fprintf(stdlog, "scan:move:%s:%s:%s\n", disk->name, file->sub, sub); + fflush(stdlog); } if (output) { printf("Move '%s%s' '%s%s'\n", disk->dir, file->sub, disk->dir, sub); @@ -345,8 +345,8 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, ++scan->count_moved; if (state->gui) { - fprintf(stderr, "scan:move:%s:%s:%s\n", disk->name, file->sub, sub); - fflush(stderr); + fprintf(stdlog, "scan:move:%s:%s:%s\n", disk->name, file->sub, sub); + fflush(stdlog); } if (output) { printf("Move '%s%s' '%s%s'\n", disk->dir, file->sub, disk->dir, sub); @@ -368,8 +368,8 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, ++scan->count_equal; if (state->gui) { - fprintf(stderr, "scan:equal:%s:%s\n", disk->name, file->sub); - fflush(stderr); + fprintf(stdlog, "scan:equal:%s:%s\n", disk->name, file->sub); + fflush(stdlog); } } @@ -395,8 +395,8 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, if (strcmp(file->sub, sub) == 0) { /* if the name is the same, it's an update */ if (state->gui) { - fprintf(stderr, "scan:update:%s:%s\n", disk->name, file->sub); - fflush(stderr); + fprintf(stdlog, "scan:update:%s:%s\n", disk->name, file->sub); + fflush(stdlog); } if (output) { printf("Update '%s%s'\n", disk->dir, file->sub); @@ -406,9 +406,9 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, } else { /* if the name is different, it's an inode reuse */ if (state->gui) { - fprintf(stderr, "scan:remove:%s:%s\n", disk->name, file->sub); - fprintf(stderr, "scan:add:%s:%s\n", disk->name, sub); - fflush(stderr); + fprintf(stdlog, "scan:remove:%s:%s\n", disk->name, file->sub); + fprintf(stdlog, "scan:add:%s:%s\n", disk->name, sub); + fflush(stdlog); } if (output) { printf("Remove '%s%s'\n", disk->dir, file->sub); @@ -429,8 +429,8 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state, ++scan->count_insert; if (state->gui) { - fprintf(stderr, "scan:add:%s:%s\n", disk->name, sub); - fflush(stderr); + fprintf(stdlog, "scan:add:%s:%s\n", disk->name, sub); + fflush(stdlog); } if (output) { printf("Add '%s%s'\n", disk->dir, sub); @@ -505,8 +505,8 @@ static void scan_emptydir(struct snapraid_scan* scan, struct snapraid_state* sta ++scan->count_equal; if (state->gui) { - fprintf(stderr, "scan:equal:%s:%s\n", disk->name, dir->sub); - fflush(stderr); + fprintf(stdlog, "scan:equal:%s:%s\n", disk->name, dir->sub); + fflush(stdlog); } /* nothing more to do */ @@ -516,8 +516,8 @@ static void scan_emptydir(struct snapraid_scan* scan, struct snapraid_state* sta ++scan->count_insert; if (state->gui) { - fprintf(stderr, "scan:add:%s:%s\n", disk->name, sub); - fflush(stderr); + fprintf(stdlog, "scan:add:%s:%s\n", disk->name, sub); + fflush(stdlog); } if (output) { printf("Add '%s%s'\n", disk->dir, sub); @@ -736,8 +736,8 @@ void state_scan(struct snapraid_state* state, int output) ++scan->count_remove; if (state->gui) { - fprintf(stderr, "scan:remove:%s:%s\n", disk->name, file->sub); - fflush(stderr); + fprintf(stdlog, "scan:remove:%s:%s\n", disk->name, file->sub); + fflush(stdlog); } if (output) { printf("Remove '%s%s'\n", disk->dir, file->sub); @@ -760,8 +760,8 @@ void state_scan(struct snapraid_state* state, int output) ++scan->count_remove; if (state->gui) { - fprintf(stderr, "scan:remove:%s:%s\n", disk->name, link->sub); - fflush(stderr); + fprintf(stdlog, "scan:remove:%s:%s\n", disk->name, link->sub); + fflush(stdlog); } if (output) { printf("Remove '%s%s'\n", disk->dir, link->sub); @@ -784,8 +784,8 @@ void state_scan(struct snapraid_state* state, int output) ++scan->count_remove; if (state->gui) { - fprintf(stderr, "scan:remove:%s:%s\n", disk->name, dir->sub); - fflush(stderr); + fprintf(stdlog, "scan:remove:%s:%s\n", disk->name, dir->sub); + fflush(stdlog); } if (output) { printf("Remove '%s%s'\n", disk->dir, dir->sub); diff --git a/selftest.c b/selftest.c index 25dea4fd..daecb8b6 100644 --- a/selftest.c +++ b/selftest.c @@ -204,8 +204,8 @@ void selftest(int gui) unsigned i; if (gui) { - fprintf(stderr, "selftest:\n"); - fflush(stderr); + fprintf(stdlog, "selftest:\n"); + fflush(stdlog); } printf("Self test...\n"); diff --git a/snapraid.1 b/snapraid.1 index 06e0f518..86b1f98f 100644 --- a/snapraid.1 +++ b/snapraid.1 @@ -26,7 +26,7 @@ snapraid [\(hyc, \(hy\(hyconf CONFIG] .PD 0 .PP .PD - [\(hyv, \(hy\(hyverbose] + [\(hyv, \(hy\(hyverbose] [\(hyl, \(hy\(hylog FILE] .PD 0 .PP .PD @@ -515,6 +515,15 @@ or fix some specific block, in case of a damaged disk. Process only the specified number of blocks. It\(cqs present mainly for advanced manual recovering. .TP +.B \(hyl, \(hy\(hylog FILE +Outputs a detailed log to the specified file. +It contains the exact specification of which block of +any file is not recoverable and why. +You can use the special files \(a"1\(a" and \(a"2\(a" to output +to stdout and stderr. +If this option is not specified, no detailed log is +generated. +.TP .B \(hyv, \(hy\(hyverbose Prints more information in the processing. .TP diff --git a/snapraid.c b/snapraid.c index 4dfd2933..5e255493 100644 --- a/snapraid.c +++ b/snapraid.c @@ -61,6 +61,7 @@ void usage(void) printf(" " SWITCH_GETOPT_LONG("-d, --filter-dist NAME", "-f") " Process only files in the disk\n"); printf(" " SWITCH_GETOPT_LONG("-m, --filter-missing ", "-m") " Process only missing/delete files\n"); printf(" " SWITCH_GETOPT_LONG("-i, --import DIR ", "-i") " Import deleted files\n"); + printf(" " SWITCH_GETOPT_LONG("-l, --log FILE ", "-l") " Log file. Default none\n"); printf(" " SWITCH_GETOPT_LONG("-a, --audit-only ", "-A") " Check only file data and not parity\n"); printf(" " SWITCH_GETOPT_LONG("-N, --find-by-name ", "-N") " Find the files by name instead than by inode\n"); printf(" " SWITCH_GETOPT_LONG("-Z, --force-zero ", "-Z") " Force synching of files that get zero size\n"); @@ -91,6 +92,7 @@ struct option long_options[] = { { "start", 1, 0, 's' }, { "count", 1, 0, 't' }, { "import", 1, 0, 'i' }, + { "log", 1, 0, 'l' }, { "force-zero", 0, 0, 'Z' }, { "force-empty", 0, 0, 'E' }, { "force-second", 0, 0, 'S' }, @@ -128,7 +130,7 @@ struct option long_options[] = { }; #endif -#define OPTIONS "c:f:d:ms:t:i:ZESNaTvhVG" +#define OPTIONS "c:f:d:ms:t:i:l:ZESNaTvhVG" volatile int global_interrupt = 0; @@ -176,7 +178,8 @@ int main(int argc, char* argv[]) int filter_missing; char* e; const char* command; - char* import; + const char* import; + const char* log; os_init(); @@ -201,6 +204,7 @@ int main(int argc, char* argv[]) tommy_list_init(&filterlist_disk); filter_missing = 0; import = 0; + log = 0; opterr = 0; while ((c = @@ -252,7 +256,14 @@ int main(int argc, char* argv[]) fprintf(stderr, "Import directory '%s' already specified as '%s'\n", optarg, import); exit(EXIT_FAILURE); } - import = strdup_nofail(optarg); + import = optarg; + break; + case 'l' : + if (log) { + fprintf(stderr, "Log file '%s' already specified as '%s'\n", optarg, log); + exit(EXIT_FAILURE); + } + log = optarg; break; case 'Z' : force_zero = 1; @@ -373,6 +384,26 @@ int main(int argc, char* argv[]) raid_init(); + /* open the log file */ + if (log == 0) { +#ifdef _WIN32 + log = "nul"; +#else + log = "/dev/null"; +#endif + } + if (strcmp(log, "1") == 0) { + stdlog = stdout; + } else if (strcmp(log, "2") == 0) { + stdlog = stderr; + } else { + stdlog = fopen(log, "wt"); + if (!stdlog) { + fprintf(stderr, "Error opening the log file '%s'. %s.\n", log, strerror(errno)); + exit(EXIT_FAILURE); + } + } + if (!test_skip_self) selftest(gui); @@ -470,7 +501,14 @@ int main(int argc, char* argv[]) state_done(&state); tommy_list_foreach(&filterlist_file, (tommy_foreach_func*)filter_free); tommy_list_foreach(&filterlist_disk, (tommy_foreach_func*)filter_free); - free(import); + + /* close log file */ + if (stdlog != stdout && stdlog != stderr) { + if (fclose(stdlog) != 0) { + fprintf(stderr, "Error closing the log file '%s'. %s.\n", log, strerror(errno)); + exit(EXIT_FAILURE); + } + } os_done(); diff --git a/snapraid.d b/snapraid.d index bd8386c6..bb617847 100644 --- a/snapraid.d +++ b/snapraid.d @@ -8,7 +8,7 @@ Synopsis : [-N, --find-by-name] : [-Z, --force-zero] [-E, --force-empty] : [-s, --start BLKSTART] [-t, --count BLKCOUNT] - : [-v, --verbose] + : [-v, --verbose] [-l, --log FILE] : sync|pool|diff|dup|check|fix :snapraid [-V, --version] [-h, --help] @@ -372,6 +372,15 @@ Options Process only the specified number of blocks. It's present mainly for advanced manual recovering. + -l, --log FILE + Outputs a detailed log to the specified file. + It contains the exact specification of which block of + any file is not recoverable and why. + You can use the special files "1" and "2" to output + to stdout and stderr. + If this option is not specified, no detailed log is + generated. + -v, --verbose Prints more information in the processing. diff --git a/snapraid.txt b/snapraid.txt index 87c13d89..2d211dd2 100644 --- a/snapraid.txt +++ b/snapraid.txt @@ -12,7 +12,7 @@ snapraid [-c, --conf CONFIG] [-N, --find-by-name] [-Z, --force-zero] [-E, --force-empty] [-s, --start BLKSTART] [-t, --count BLKCOUNT] - [-v, --verbose] + [-v, --verbose] [-l, --log FILE] sync|pool|diff|dup|check|fix snapraid [-V, --version] [-h, --help] @@ -407,6 +407,15 @@ SnapRAID provides the following options: Process only the specified number of blocks. It's present mainly for advanced manual recovering. + -l, --log FILE + Outputs a detailed log to the specified file. + It contains the exact specification of which block of + any file is not recoverable and why. + You can use the special files "1" and "2" to output + to stdout and stderr. + If this option is not specified, no detailed log is + generated. + -v, --verbose Prints more information in the processing. diff --git a/state.c b/state.c index 2548d64e..51c34408 100644 --- a/state.c +++ b/state.c @@ -237,9 +237,9 @@ void state_config(struct snapraid_state* state, const char* path, int verbose, i state->skip_fallocate = skip_fallocate; if (state->gui) { - fprintf(stderr, "version:%s\n", PACKAGE_VERSION); - fprintf(stderr, "conf:%s\n", path); - fflush(stderr); + fprintf(stdlog, "version:%s\n", PACKAGE_VERSION); + fprintf(stdlog, "conf:%s\n", path); + fflush(stdlog); } f = sopen_read(path); @@ -586,21 +586,21 @@ void state_config(struct snapraid_state* state, const char* path, int verbose, i if (state->gui) { tommy_node* i; - fprintf(stderr, "blocksize:%u\n", state->block_size); + fprintf(stdlog, "blocksize:%u\n", state->block_size); for(i=state->disklist;i!=0;i=i->next) { struct snapraid_disk* disk = i->data; - fprintf(stderr, "disk:%s:%s\n", disk->name, disk->dir); + fprintf(stdlog, "disk:%s:%s\n", disk->name, disk->dir); } if (state->qarity[0] != 0) - fprintf(stderr, "mode:raid6\n"); + fprintf(stdlog, "mode:raid6\n"); else - fprintf(stderr, "mode:raid5\n"); - fprintf(stderr, "parity:%s\n", state->parity); + fprintf(stdlog, "mode:raid5\n"); + fprintf(stdlog, "parity:%s\n", state->parity); if (state->qarity[0] != 0) - fprintf(stderr, "qarity:%s\n", state->qarity); + fprintf(stdlog, "qarity:%s\n", state->qarity); if (state->pool[0] != 0) - fprintf(stderr, "pool:%s\n", state->pool); - fflush(stderr); + fprintf(stdlog, "pool:%s\n", state->pool); + fflush(stdlog); } } @@ -738,8 +738,8 @@ void state_read(struct snapraid_state* state) pathcpy(path, sizeof(path), content->content); if (state->gui) { - fprintf(stderr, "content:%s\n", path); - fflush(stderr); + fprintf(stdlog, "content:%s\n", path); + fflush(stdlog); } printf("Loading state from %s...\n", path); @@ -756,7 +756,7 @@ void state_read(struct snapraid_state* state) /* otherwise continue */ if (node->next) { - fprintf(stderr, "Not found, trying with another copy...\n"); + fprintf(stderr, "warning: Content file '%s' not found, trying with another copy...\n", path); } } @@ -768,7 +768,7 @@ void state_read(struct snapraid_state* state) /* create the initial mapping */ state_map(state); - fprintf(stderr, "No content file found. Assuming empty.\n"); + fprintf(stderr, "warning: No content file found. Assuming empty.\n"); return; } @@ -1894,8 +1894,8 @@ void state_filter(struct snapraid_state* state, tommy_list* filterlist_file, tom void state_progress_begin(struct snapraid_state* state, block_off_t blockstart, block_off_t blockmax, block_off_t countmax) { if (state->gui) { - fprintf(stderr,"run:begin:%u:%u:%u\n", blockstart, blockmax, countmax); - fflush(stderr); + fprintf(stdlog,"run:begin:%u:%u:%u\n", blockstart, blockmax, countmax); + fflush(stdlog); } else { time_t now; @@ -1910,8 +1910,8 @@ void state_progress_begin(struct snapraid_state* state, block_off_t blockstart, void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize) { if (state->gui) { - fprintf(stderr, "run:end\n"); - fflush(stderr); + fprintf(stdlog, "run:end\n"); + fflush(stdlog); } else { unsigned countsize_MiB = (countsize + 1024*1024 - 1) / (1024*1024); @@ -1948,8 +1948,8 @@ void state_progress_restart(struct snapraid_state* state) int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off_t countpos, block_off_t countmax, data_off_t countsize) { if (state->gui) { - fprintf(stderr, "run:pos:%u:%u:%"PRIu64"\n", blockpos, countpos, countsize); - fflush(stderr); + fprintf(stdlog, "run:pos:%u:%u:%"PRIu64"\n", blockpos, countpos, countsize); + fflush(stdlog); } else { time_t now; diff --git a/sync.c b/sync.c index f2f0ba3b..11228c72 100644 --- a/sync.c +++ b/sync.c @@ -185,7 +185,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } } - ret = handle_open(&handle[j], block_file_get(block)); + ret = handle_open(&handle[j], block_file_get(block), stderr); if (ret == -1) { if (errno == ENOENT) { fprintf(stderr, "Missing file '%s'.\n", handle[j].path); @@ -233,7 +233,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari continue; } - read_size = handle_read(&handle[j], block, buffer[j], state->block_size); + read_size = handle_read(&handle[j], block, buffer[j], state->block_size, stderr); if (read_size == -1) { fprintf(stderr, "DANGER! Unexpected read error in a data disk, it isn't possible to sync.\n"); printf("Stopping to allow recovery. Try with 'snapraid check'\n");