From 73b56951b706f9516938d2b1560ef2a967d2e6df Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 26 Sep 2004 16:09:18 +0000 Subject: [PATCH] obuck_slurp_pool() is now able to skip unwanted buckets. Some day we can improve it by sizing the buffer adaptively, but not now. --- lib/bucket.c | 27 ++++++++++++++++++++------- lib/bucket.h | 4 +++- lib/buckettool.c | 2 +- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/bucket.c b/lib/bucket.c index 29331084..296c7fa8 100644 --- a/lib/bucket.c +++ b/lib/bucket.c @@ -434,8 +434,19 @@ obuck_slurp_refill(struct fastbuf *f) return 1; } +void +obuck_slurp_end(void) +{ + if (obuck_rpf) + { + bclose(obuck_rpf); + obuck_rpf = NULL; + obuck_unlock(); + } +} + struct fastbuf * -obuck_slurp_pool(struct obuck_header *hdrp) +obuck_slurp_pool(struct obuck_header *hdrp, oid_t next_oid) { static struct fastbuf limiter; uns l; @@ -455,16 +466,18 @@ obuck_slurp_pool(struct obuck_header *hdrp) if (bgetl(obuck_rpf) != OBUCK_TRAILER) obuck_broken("Missing trailer", slurp_start); } - slurp_start = btell(obuck_rpf); + if (next_oid == OBUCK_OID_ANY) + slurp_start = btell(obuck_rpf); + else + { + slurp_start = obuck_get_pos(next_oid); + bsetpos(obuck_rpf, slurp_start); + } if (slurp_start < slurp_end) l = bread(obuck_rpf, hdrp, sizeof(struct obuck_header)); else - l = 0; - if (!l) { - bclose(obuck_rpf); - obuck_rpf = NULL; - obuck_unlock(); + obuck_slurp_end(); return NULL; } if (l != sizeof(struct obuck_header)) diff --git a/lib/bucket.h b/lib/bucket.h index 1af677ca..c6be0b2b 100644 --- a/lib/bucket.h +++ b/lib/bucket.h @@ -32,6 +32,7 @@ extern byte *obuck_name; /* Internal, for use by buckettool only! */ #define OBUCK_INCOMPLETE_MAGIC 0xdeadfeel #define OBUCK_TRAILER 0xfeedcafe #define OBUCK_OID_DELETED (~(oid_t)0) +#define OBUCK_OID_ANY (~(oid_t)0) #define OBUCK_OID_FIRST_SPECIAL (~(oid_t)0xffff) struct obuck_header { @@ -76,7 +77,8 @@ void obuck_create_end(struct fastbuf *b, struct obuck_header *hdrp); void obuck_delete(oid_t oid); /* Fast reading of the whole pool */ -struct fastbuf *obuck_slurp_pool(struct obuck_header *hdrp); +struct fastbuf *obuck_slurp_pool(struct obuck_header *hdrp, oid_t next_oid); +void obuck_slurp_end(void); /* Convert bucket ID to file position (for size limitations etc.) */ diff --git a/lib/buckettool.c b/lib/buckettool.c index 5b503580..6458c539 100644 --- a/lib/buckettool.c +++ b/lib/buckettool.c @@ -236,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) -- 2.39.2