X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fbuckettool.c;h=ae55b3ca4d4f92c784c25bae194ac3c0fae308fd;hb=2a5686e35c9d6be6cefe22d49cfff6d23ec2e842;hp=eaf376c76da98c22a95bcbee56541add479dfd2e;hpb=31d51567ca4e34c814c5c45b3058bbac6d778ab0;p=libucw.git diff --git a/lib/buckettool.c b/lib/buckettool.c index eaf376c7..ae55b3ca 100644 --- a/lib/buckettool.c +++ b/lib/buckettool.c @@ -2,6 +2,9 @@ * Sherlock Library -- Bucket Manipulation Tool * * (c) 2001 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. */ #include "lib/lib.h" @@ -35,6 +38,7 @@ CF_USAGE -c\t\tconcatenate and dump all buckets\n\ -f\t\taudit bucket file structure\n\ -F\t\taudit and fix bucket file structure\n\ +-q\t\tquick check of bucket file consistency\n\ -s\t\tshake down bucket file (without updating other structures!!!)\n\ -v\t\tbe verbose\n\ "); @@ -104,7 +108,7 @@ insert(void) struct obuck_header h; byte *e; - in = bfdopen(0, 4096); + in = bfdopen_shared(0, 4096); obuck_init(1); do { @@ -119,7 +123,7 @@ insert(void) } while (e); obuck_cleanup(); - /* bclose(in) not done, we don't want fd 0 closed */ + bclose(in); } static void @@ -186,9 +190,12 @@ fsck(int fix) printf("%08x missing trailer\n", oid); else if (chk != OBUCK_TRAILER) printf("%08x mismatched trailer\n", oid); - /* OK */ - pos = end; - continue; + else + { + /* OK */ + pos = end; + continue; + } } errors++; end = pos; @@ -227,6 +234,8 @@ fsck(int fix) sh_pwrite(fd, &chk, 4, end-4); printf("*** replaced the invalid chunk by a DELETED bucket of size %d\n", (uns)(end - pos)); } + else + printf("*** would mark %d bytes as DELETED\n", (uns)(end - pos)); pos = end; } finish: @@ -257,6 +266,13 @@ shake(void) obuck_cleanup(); } +static void +quickcheck(void) +{ + obuck_init(1); + obuck_cleanup(); +} + int main(int argc, char **argv) { @@ -265,7 +281,7 @@ main(int argc, char **argv) log_init(NULL); op = 0; - while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:icfFsv", CF_NO_LONG_OPTS, NULL)) != -1) + while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:icfFqsv", CF_NO_LONG_OPTS, NULL)) != -1) if (i == '?' || op) help(); else if (i == 'v') @@ -304,6 +320,9 @@ main(int argc, char **argv) case 'F': fsck(1); break; + case 'q': + quickcheck(); + break; case 's': shake(); break;