]> mj.ucw.cz Git - libucw.git/commitdiff
obuck_slurp_pool() is now able to skip unwanted buckets. Some day we can
authorMartin Mares <mj@ucw.cz>
Sun, 26 Sep 2004 16:09:18 +0000 (16:09 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 26 Sep 2004 16:09:18 +0000 (16:09 +0000)
improve it by sizing the buffer adaptively, but not now.

lib/bucket.c
lib/bucket.h
lib/buckettool.c

index 29331084caebd580b8fb36e424a4b24a44f9ff7f..296c7fa87db25792d51e1069997e40974a4ed51b 100644 (file)
@@ -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))
index 1af677cad8907556efe32502b40efa88ccf461eb..c6be0b2b12bae5735f637737be6a8942d6be0c47 100644 (file)
@@ -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.) */
 
index 5b503580ec9fbbb2e54e6a4344ee26e3bc053322..6458c539a1268ad342cdbcabc76b6967f3738ca2 100644 (file)
@@ -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)