]> mj.ucw.cz Git - libucw.git/blobdiff - lib/buckettool.c
`buckettool -c' (cat) now separates buckets by an empty line.
[libucw.git] / lib / buckettool.c
index aa61e515d39bad459620be935e9225a8b6984458..76b8fc37c21f5586074490981ecee352eefbf23a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     Sherlock Library -- Bucket Manipulation Tool
  *
 /*
  *     Sherlock Library -- Bucket Manipulation Tool
  *
- *     (c) 2001 Martin Mares <mj@ucw.cz>
+ *     (c) 2001--2004 Martin Mares <mj@ucw.cz>
  *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
 #include "lib/fastbuf.h"
 #include "lib/lfs.h"
 #include "lib/conf.h"
 #include "lib/fastbuf.h"
 #include "lib/lfs.h"
 #include "lib/conf.h"
-#include "lib/pools.h"
+#include "lib/mempool.h"
 #include "lib/object.h"
 #include "lib/object.h"
-#include "lib/buck2obj.h"
-#include "lib/obj2buck.h"
 #include "lib/lizard.h"
 #include "lib/lizard.h"
-#include "charset/unistream.h"
+#include "lib/bbuf.h"
+#include "lib/ff-utf8.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -48,9 +47,9 @@ CF_USAGE
 -f\t\taudit bucket file structure\n\
 -F\t\taudit and fix bucket file structure\n\
 -q\t\tquick check of bucket file consistency\n\
 -f\t\taudit bucket file structure\n\
 -F\t\taudit and fix bucket file structure\n\
 -q\t\tquick check of bucket file consistency\n\
+-r\t\tdo not parse V33 buckets, but print the raw content\n\
 -s\t\tshake down bucket file (without updating other structures!!!)\n\
 -v\t\tbe verbose\n\
 -s\t\tshake down bucket file (without updating other structures!!!)\n\
 -v\t\tbe verbose\n\
--r\t\tdo not parse V33 buckets, but print the raw content\n\
 ");
   exit(1);
 }
 ");
   exit(1);
 }
@@ -93,9 +92,9 @@ delete(char *id)
 }
 
 static inline void
 }
 
 static inline void
-dump_oattr(struct fastbuf *out, struct oattr *oa)
+dump_oattrs(struct fastbuf *out, struct oattr *a)
 {
 {
-  for (struct oattr *a = oa; a; a = a->same)
+  for (; a; a = a->same)
     bprintf(out, "%c%s\n", a->attr, a->val);
 }
 
     bprintf(out, "%c%s\n", a->attr, a->val);
 }
 
@@ -107,18 +106,13 @@ dump_parsed_bucket(struct fastbuf *out, struct obuck_header *h, struct fastbuf *
   o_hdr = obj_new(pool);
   o_body = obj_new(pool);
   if (buck2obj_parse(buck_buf, h->type, h->length, b, o_hdr, NULL, o_body) < 0)
   o_hdr = obj_new(pool);
   o_body = obj_new(pool);
   if (buck2obj_parse(buck_buf, h->type, h->length, b, o_hdr, NULL, o_body) < 0)
-  {
-    bprintf(out, "Cannot parse bucket %x of type %x and length %d: %m\n", h->oid, h->type, h->length);
-    return;
-  }
+    bprintf(out, ".Cannot parse bucket %x of type %x and length %d: %m\n", h->oid, h->type, h->length);
   else
   else
-  {
-    for (struct oattr *oa = o_hdr->attrs; oa; oa = oa->next)
-      dump_oattr(out, oa);
-    bputc(out, '\n');
-    for (struct oattr *oa = o_body->attrs; oa; oa = oa->next)
-      dump_oattr(out, oa);
-  }
+    {
+      dump_oattrs(out, o_hdr->attrs);
+      bputc(out, '\n');
+      dump_oattrs(out, o_body->attrs);
+    }
 }
 
 static void
 }
 
 static void
@@ -146,10 +140,6 @@ extract(char *id)
   obuck_cleanup();
 }
 
   obuck_cleanup();
 }
 
-#define        GBUF_TYPE       byte
-#define        GBUF_PREFIX(x)  bb_##x
-#include "lib/gbuf.h"
-
 static void
 insert(byte *arg)
 {
 static void
 insert(byte *arg)
 {
@@ -166,6 +156,8 @@ insert(byte *arg)
     type = BUCKET_TYPE_PLAIN;
   else if (sscanf(arg, "%x", &type) != 1)
     die("Type `%s' is not a hexadecimal number");
     type = BUCKET_TYPE_PLAIN;
   else if (sscanf(arg, "%x", &type) != 1)
     die("Type `%s' is not a hexadecimal number");
+  if (type < 10)
+    type += BUCKET_TYPE_PLAIN;
   attr_set_type(type);
 
   in = bfdopen_shared(0, 4096);
   attr_set_type(type);
 
   in = bfdopen_shared(0, 4096);
@@ -196,6 +188,7 @@ insert(byte *arg)
          }
          else
          {
          }
          else
          {
+           ASSERT(BUCKET_TYPE_V33_LIZARD);
            uns want_len = lizard_filled + (e-buf) + 6 + LIZARD_NEEDS_CHARS;    // +6 is the maximum UTF-8 length
            bb_grow(&lizard_buf, want_len);
            byte *ptr = lizard_buf.ptr + lizard_filled;
            uns want_len = lizard_filled + (e-buf) + 6 + LIZARD_NEEDS_CHARS;    // +6 is the maximum UTF-8 length
            bb_grow(&lizard_buf, want_len);
            byte *ptr = lizard_buf.ptr + lizard_filled;
@@ -208,6 +201,11 @@ insert(byte *arg)
        bputl(b, lizard_filled
 #if 0  //TEST error resilience: write wrong length
            +1
        bputl(b, lizard_filled
 #if 0  //TEST error resilience: write wrong length
            +1
+#endif
+           );
+       bputl(b, adler32(lizard_buf.ptr, lizard_filled)
+#if 0  //TEST error resilience: write wrong checksum
+           +1
 #endif
            );
        uns want_len = lizard_filled * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD;
 #endif
            );
        uns want_len = lizard_filled * LIZARD_MAX_MULTIPLY + LIZARD_MAX_ADD;
@@ -256,6 +254,7 @@ cat(void)
       }
       else
        dump_parsed_bucket(out, &h, b);
       }
       else
        dump_parsed_bucket(out, &h, b);
+      bputc(out, '\n');
     }
   bclose(out);
   obuck_cleanup();
     }
   bclose(out);
   obuck_cleanup();
@@ -389,7 +388,7 @@ main(int argc, char **argv)
 
   log_init(NULL);
   op = 0;
 
   log_init(NULL);
   op = 0;
-  while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:i::cfFqsvr", CF_NO_LONG_OPTS, NULL)) != -1)
+  while ((i = cf_getopt(argc, argv, CF_SHORT_OPTS "lLd:x:i::cfFqrsv", CF_NO_LONG_OPTS, NULL)) != -1)
     if (i == '?' || op)
       help();
     else if (i == 'v')
     if (i == '?' || op)
       help();
     else if (i == 'v')