From eefcb6d5ecc617a2cb2e35a220848e187585ff14 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 19 Oct 2003 16:47:55 +0000 Subject: [PATCH] Replaced the "orig_len" field in bucket headers which was never used for anything useful by bucket type code. --- lib/bucket.c | 18 +++++++++--------- lib/bucket.h | 18 +++++++++++++++--- lib/buckettool.c | 24 +++++++++++++++--------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/lib/bucket.c b/lib/bucket.c index 7c7b6f61..af6b46bf 100644 --- a/lib/bucket.c +++ b/lib/bucket.c @@ -280,7 +280,7 @@ obuck_predict_last_oid(void) } struct fastbuf * -obuck_create(void) +obuck_create(u32 type) { obuck_lock_write(); bflush(obuck_fb); @@ -289,7 +289,8 @@ obuck_create(void) obuck_broken("Misaligned file"); obuck_hdr.magic = OBUCK_INCOMPLETE_MAGIC; obuck_hdr.oid = bucket_start >> OBUCK_SHIFT; - obuck_hdr.length = obuck_hdr.orig_length = 0; + obuck_hdr.length = 0; + obuck_hdr.type = type; bucket_current = bucket_start; bwrite(obuck_fb, &obuck_hdr, sizeof(obuck_hdr)); obuck_fb->pos = -sizeof(obuck_hdr); @@ -301,7 +302,7 @@ obuck_create_end(struct fastbuf *b UNUSED, struct obuck_header *hdrp) { int pad; obuck_hdr.magic = OBUCK_MAGIC; - obuck_hdr.length = obuck_hdr.orig_length = btell(obuck_fb); + obuck_hdr.length = btell(obuck_fb); pad = (OBUCK_ALIGN - sizeof(obuck_hdr) - obuck_hdr.length - 4) & (OBUCK_ALIGN - 1); while (pad--) bputc(obuck_fb, 0); @@ -521,7 +522,6 @@ obuck_shakedown(int (*kibitz)(struct obuck_header *old, oid_t new, byte *buck)) obuck_hdr.length = bucket_start - wstart - sizeof(obuck_hdr) - 4; else obuck_hdr.length = 0x40000000 - sizeof(obuck_hdr) - 4; - obuck_hdr.orig_length = obuck_hdr.length; sh_pwrite(obuck_fd, &obuck_hdr, sizeof(obuck_hdr), wstart); wstart += sizeof(obuck_hdr) + obuck_hdr.length + 4; sh_pwrite(obuck_fd, &check, 4, wstart-4); @@ -561,7 +561,7 @@ int main(int argc, char **argv) for(i=0; i %d\n", h.oid, h.orig_length, h.length); + printf("Writing %08x %d\n", h.oid, h.length); ids[j] = h.oid; } for(j=0; j %d\n", h.oid, h.orig_length, h.length); - if (h.orig_length != LEN(j)) + printf("Reading %08x %d\n", h.oid, h.length); + if (h.length != LEN(j)) die("Invalid length"); - for(i=0; i\tdelete bucket\n\ -x \textract bucket\n\ --i\t\tinsert buckets separated by blank lines\n\ +-i[]\tinsert buckets separated by blank lines\n\ -c\t\tconcatenate and dump all buckets\n\ -f\t\taudit bucket file structure\n\ -F\t\taudit and fix bucket file structure\n\ @@ -67,7 +67,7 @@ list(int full) if (h.oid == OBUCK_OID_DELETED) printf("DELETED %6d\n", h.length); else - printf("%08x %6d %6d\n", h.oid, h.length, h.orig_length); + printf("%08x %6d %08x\n", h.oid, h.length, h.type); } while (obuck_find_next(&h, full)); obuck_cleanup(); @@ -101,25 +101,31 @@ extract(char *id) } static void -insert(void) +insert(byte *arg) { struct fastbuf *b, *in; byte buf[4096]; struct obuck_header h; byte *e; + u32 type; + + if (!arg) + type = BUCKET_TYPE_PLAIN; + else if (sscanf(arg, "%x", &type) != 1) + die("Type `%s' is not a hexadecimal number"); in = bfdopen_shared(0, 4096); obuck_init(1); do { - b = obuck_create(); + b = obuck_create(type); while ((e = bgets(in, buf, sizeof(buf))) && buf[0]) { *e++ = '\n'; bwrite(b, buf, e-buf); } obuck_create_end(b, &h); - printf("%08x %d %d\n", h.oid, h.length, h.orig_length); + printf("%08x %d %08x\n", h.oid, h.length, h.type); } while (e); obuck_cleanup(); @@ -137,7 +143,7 @@ cat(void) obuck_init(0); while (b = obuck_slurp_pool(&h)) { - printf("### %08x %6d %6d\n", h.oid, h.length, h.orig_length); + printf("### %08x %6d %08x\n", h.oid, h.length, h.type); lf = 1; while ((l = bread(b, buf, sizeof(buf)))) { @@ -224,7 +230,7 @@ fsck(int fix) { h.magic = OBUCK_MAGIC; h.oid = OBUCK_OID_DELETED; - h.length = h.orig_length = end - pos - sizeof(h) - 4; + h.length = end - pos - sizeof(h) - 4; sh_pwrite(fd, &h, sizeof(h), pos); chk = OBUCK_TRAILER; sh_pwrite(fd, &chk, 4, end-4); @@ -277,7 +283,7 @@ main(int argc, char **argv) log_init(NULL); op = 0; - while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:icfFqsv", CF_NO_LONG_OPTS, NULL)) != -1) + while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:i::cfFqsv", CF_NO_LONG_OPTS, NULL)) != -1) if (i == '?' || op) help(); else if (i == 'v') @@ -305,7 +311,7 @@ main(int argc, char **argv) extract(arg); break; case 'i': - insert(); + insert(arg); break; case 'c': cat(); -- 2.39.2