X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fbuckettool.c;h=6458c539a1268ad342cdbcabc76b6967f3738ca2;hb=5d26aed3953fe00d6d394f9767b4a029406eeeea;hp=4b7847a566a49ec7341807c724eb062686492fd2;hpb=beac4661ae8230dd1747cb4ebbfddc016183b140;p=libucw.git diff --git a/lib/buckettool.c b/lib/buckettool.c index 4b7847a5..6458c539 100644 --- a/lib/buckettool.c +++ b/lib/buckettool.c @@ -1,7 +1,7 @@ /* * Sherlock Library -- Bucket Manipulation Tool * - * (c) 2001 Martin Mares + * (c) 2001--2004 Martin Mares * (c) 2004 Robert Spalek * * This software may be freely distributed and used according to the terms @@ -13,12 +13,11 @@ #include "lib/fastbuf.h" #include "lib/lfs.h" #include "lib/conf.h" -#include "lib/pools.h" +#include "lib/mempool.h" #include "lib/object.h" -#include "lib/buck2obj.h" -#include "lib/obj2buck.h" #include "lib/lizard.h" -#include "charset/unistream.h" +#include "lib/bbuf.h" +#include "lib/ff-utf8.h" #include #include @@ -48,9 +47,9 @@ CF_USAGE -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\ +-r\t\tdo not parse V33 buckets, but print the raw content\n\ -s\t\tshake down bucket file (without updating other structures!!!)\n\ -v\t\tbe verbose\n\ --r\t\tdo not parse V33 buckets, but print the raw content\n\ "); exit(1); } @@ -93,49 +92,45 @@ delete(char *id) } static inline void -dump_oattr(struct fastbuf *out, struct oattr *oa) +dump_oattrs(struct fastbuf *out, struct oattr *oa) { - for (struct oattr *a = oa; a; a = a->same) - bprintf(out, "%c%s\n", a->attr, a->val); + for (; oa; oa = oa->next) + for (struct oattr *a=oa; a; a = a->same) + bprintf(out, "%c%s\n", a->attr, a->val); } static void dump_parsed_bucket(struct fastbuf *out, struct obuck_header *h, struct fastbuf *b) { - struct odes *o = obj_read_bucket(buck_buf, pool, h->type, h->length, b, NULL); - if (!o) - bprintf(out, "Cannot parse bucket %x of type %x and length %d: %m\n", h->oid, h->type, h->length); + struct odes *o_hdr, *o_body; + mp_flush(pool); + o_hdr = obj_new(pool); + o_body = obj_new(pool); + if (buck2obj_parse(buck_buf, h->type, h->length, b, o_hdr, NULL, o_body) < 0) + bprintf(out, ".Cannot parse bucket %x of type %x and length %d: %m\n", h->oid, h->type, h->length); else - { -#define IS_HEADER(x) (x=='O' || x=='U') - for (struct oattr *oa = o->attrs; oa; oa = oa->next) - if (IS_HEADER(oa->attr)) - dump_oattr(out, oa); - bputc(out, '\n'); - for (struct oattr *oa = o->attrs; oa; oa = oa->next) - if (!IS_HEADER(oa->attr)) - dump_oattr(out, oa); - } + { + dump_oattrs(out, o_hdr->attrs); + bputc(out, '\n'); + dump_oattrs(out, o_body->attrs); + } } static void extract(char *id) { struct fastbuf *b, *out; - byte buf[1024]; - int l; struct obuck_header h; h.oid = parse_id(id); obuck_init(0); obuck_find_by_oid(&h); out = bfdopen_shared(1, 65536); + if (verbose) + bprintf(out, "### %08x %6d %08x\n", h.oid, h.length, h.type); b = obuck_fetch(); if (h.type < BUCKET_TYPE_V33 || !buck_buf) - { - while ((l = bread(b, buf, sizeof(buf)))) - bwrite(out, buf, l); - } + bbcopy_slow(b, out, ~0U); else dump_parsed_bucket(out, &h, b); bclose(b); @@ -143,10 +138,6 @@ extract(char *id) obuck_cleanup(); } -#define GBUF_TYPE byte -#define GBUF_PREFIX(x) bb_##x -#include "lib/gbuf.h" - static void insert(byte *arg) { @@ -163,6 +154,9 @@ insert(byte *arg) type = BUCKET_TYPE_PLAIN; else if (sscanf(arg, "%x", &type) != 1) die("Type `%s' is not a hexadecimal number"); + if (type < 10) + type += BUCKET_TYPE_PLAIN; + put_attr_set_type(type); in = bfdopen_shared(0, 4096); obuck_init(1); @@ -181,26 +175,22 @@ insert(byte *arg) } if (!b) b = obuck_create(type); - if (type < BUCKET_TYPE_V33) - { - *e++ = '\n'; - bwrite(b, buf, e-buf); - } - else if (in_body == 1) + if (in_body == 1) { bputc(b, 0); in_body = 2; } - else if (type == BUCKET_TYPE_V33 || !in_body) + else if (type <= BUCKET_TYPE_V33 || !in_body) { - bwrite_v33(b, buf[0], buf+1, e-buf-1); + bput_attr(b, buf[0], buf+1, e-buf-1); } else { + ASSERT(BUCKET_TYPE_V33_LIZARD); uns want_len = lizard_filled + (e-buf) + 6 + LIZARD_NEEDS_CHARS; // +6 is the maximum UTF-8 length bb_grow(&lizard_buf, want_len); byte *ptr = lizard_buf.ptr + lizard_filled; - WRITE_V33(ptr, buf[0], buf+1, e-buf-1); + ptr = put_attr(ptr, buf[0], buf+1, e-buf-1); lizard_filled = ptr - lizard_buf.ptr; } } @@ -209,6 +199,11 @@ insert(byte *arg) bputl(b, lizard_filled #if 0 //TEST error resilience: write wrong length +1 +#endif + ); + bputl(b, adler32(lizard_buf.ptr, lizard_filled) +#if 0 //TEST error resilience: write wrong checksum + +1 #endif ); uns want_len = lizard_filled * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD; @@ -241,7 +236,7 @@ cat(void) obuck_init(0); out = bfdopen_shared(1, 65536); - while (b = obuck_slurp_pool(&h)) + while (b = obuck_slurp_pool(&h, OBUCK_OID_ANY)) { bprintf(out, "### %08x %6d %08x\n", h.oid, h.length, h.type); if (h.type < BUCKET_TYPE_V33 || !buck_buf) @@ -257,6 +252,7 @@ cat(void) } else dump_parsed_bucket(out, &h, b); + bputc(out, '\n'); } bclose(out); obuck_cleanup(); @@ -390,7 +386,7 @@ main(int argc, char **argv) log_init(NULL); op = 0; - while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:i::cfFqsvr", CF_NO_LONG_OPTS, NULL)) != -1) + while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:i::cfFqrsv", CF_NO_LONG_OPTS, NULL)) != -1) if (i == '?' || op) help(); else if (i == 'v')