improve it by sizing the buffer adaptively, but not now.
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;
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))
#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 {
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.) */
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)