]> mj.ucw.cz Git - libucw.git/commitdiff
Replaced the "orig_len" field in bucket headers which was never used
authorMartin Mares <mj@ucw.cz>
Sun, 19 Oct 2003 16:47:55 +0000 (16:47 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 19 Oct 2003 16:47:55 +0000 (16:47 +0000)
for anything useful by bucket type code.

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

index 7c7b6f61a7bf05b65bcf0e925d406144fe8d0ba8..af6b46bf1ffcd6a40ca9624ea481bfa97d548943 100644 (file)
@@ -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<LEN(j); i++)
         bputc(b, (i+j) % 256);
       obuck_create_end(b, &h);
-      printf("Writing %08x %d -> %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<COUNT; j++)
@@ -578,10 +578,10 @@ int main(int argc, char **argv)
        h.oid = ids[j];
        obuck_find_by_oid(&h);
        b = obuck_fetch();
-       printf("Reading %08x %d -> %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<h.orig_length; i++)
+       for(i=0; i<h.length; i++)
          if ((unsigned) bgetc(b) != (i+j) % 256)
            die("Contents mismatch");
        if (bgetc(b) != EOF)
@@ -591,7 +591,7 @@ int main(int argc, char **argv)
   if (obuck_find_first(&h, 0))
     do
       {
-       printf("<<< %08x\t%d\n", h.oid, h.orig_length);
+       printf("<<< %08x\t%d\n", h.oid, h.length);
        cnt--;
       }
     while (obuck_find_next(&h, 0));
index 811455238678b461188cd6a656bb1a5f84d0494b..ac14a6ddb01c99c070054b023140dd1798bb850d 100644 (file)
@@ -7,6 +7,9 @@
  *     of the GNU Lesser General Public License.
  */
 
+#ifndef _SHERLOCK_BUCKET_H
+#define _SHERLOCK_BUCKET_H
+
 /*
  * Format: The object pool is merely a sequence of object buckets.
  * Each bucket starts with struct obuck_header and it's padded
@@ -32,11 +35,18 @@ extern byte *obuck_name;    /* Internal, for use by buckettool only! */
 struct obuck_header {
   u32 magic;                   /* OBUCK_MAGIC should dwell here */
   oid_t oid;                   /* ID of this object or OBUCK_OID_DELETED */
-  u32 length;                  /* Length of compressed data in the bucket */
-  u32 orig_length;             /* Length of uncompressed data */
+  u32 length;                  /* Length of data in the bucket */
+  u32 type;                    /* Data type */
   /* Bucket data continue here */
 };
 
+enum bucket_type {
+  BUCKET_TYPE_COMPAT = 0x7fffffff,     /* and less -- buckets created by older versions of Sherlock */
+  BUCKET_TYPE_PLAIN = 0x80000000,      /* plain textual buckets */
+  BUCKET_TYPE_V30 = 0x80000001,                /* v3.0 uncompressed buckets */
+  BUCKET_TYPE_V30C = 0x80000002                /* v3.0 compressed buckets */
+};
+
 struct fastbuf;
 
 void obuck_init(int writeable);        /* Initialize the bucket module */
@@ -57,7 +67,7 @@ struct fastbuf *obuck_fetch(void);
 void obuck_fetch_end(struct fastbuf *b);
 
 /* Creating buckets */
-struct fastbuf *obuck_create(void);
+struct fastbuf *obuck_create(u32 type);
 void obuck_create_end(struct fastbuf *b, struct obuck_header *hdrp);
 
 /* Deleting buckets */
@@ -75,3 +85,5 @@ static inline sh_off_t obuck_get_pos(oid_t oid)
 
 /* Shaking down bucket file */
 void obuck_shakedown(int (*kibitz)(struct obuck_header *old, oid_t new, byte *buck));
+
+#endif
index bc8ce32d10ceca1cca491ecea404c6807c264ffe..c911e5ce694937f5e111e56354bd4314a0b5bf1e 100644 (file)
@@ -34,7 +34,7 @@ CF_USAGE
 -L\t\tlist all buckets including deleted ones\n\
 -d <obj>\tdelete bucket\n\
 -x <obj>\textract bucket\n\
--i\t\tinsert buckets separated by blank lines\n\
+-i[<type>]\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();