WARNING: File format change: flags are now compressed integer
authorJonathan Dieter <jdieter@gmail.com>
Wed, 18 Jul 2018 16:25:03 +0000 (17:25 +0100)
committerJonathan Dieter <jdieter@gmail.com>
Wed, 18 Jul 2018 16:25:03 +0000 (17:25 +0100)
Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
src/lib/header.c
test/empty.c
zchunk_format.txt

index 815dd505cbf19a46c91dfcee717fd3eba9b8e294..78bafcff025e23dbd2cf52ba5747552f98e3ea33 100644 (file)
                                 return False; \
                             }
 
-static int check_flags(zckCtx *zck, char *header, size_t *length, size_t max_length) {
-    if(max_length < 4) {
-        zck_log(ZCK_LOG_ERROR, "Read past end of header\n");
-        return False;
-    }
-    zck->has_streams = header[3] & 0x01;
+static int check_flags(zckCtx *zck, size_t flags) {
+    zck->has_streams = flags & 1;
     if(zck->has_streams) {
         zck_log(ZCK_LOG_ERROR, "This version of zchunk doesn't support streams\n");
         return False;
     }
-    if((header[3] & 0xfe) != 0 || header[2] != 0 || header[1] != 0 ||
-       header[0] != 0) {
+    flags = flags & (SIZE_MAX - 1);
+    if(flags != 0) {
         zck_log(ZCK_LOG_ERROR, "Unknown flags(s) set\n");
         return False;
     }
-    *length += 4;
     return True;
 }
 
 static int read_header_from_file(zckCtx *zck) {
-    if(zck->header_length > MAX_HEADER_IN_MEM) {
-
-    }
-
     /* Allocate header and store any extra bytes at beginning of header */
     zck->header = realloc(zck->header, zck->lead_size + zck->header_length);
     if(zck->header == NULL) {
@@ -146,7 +137,10 @@ static int read_preface(zckCtx *zck) {
     length += zck->hash_type.digest_size;
 
     /* Read flags */
-    if(!check_flags(zck, header+length, &length, max_length-length))
+    size_t flags = 0;
+    if(!compint_to_size(&flags, header+length, &length, max_length))
+        return False;
+    if(!check_flags(zck, flags))
         return False;
 
     /* Setup for reading compression type */
@@ -248,12 +242,10 @@ static int preface_create(zckCtx *zck) {
     length += zck->hash_type.digest_size;
 
     /* Write out flags */
-    memset(header + length, 0, 3);
-    length += 3;
-    /* Final byte for flags */
+    size_t flags = 0;
     if(zck->has_streams)
-        header[length] &= 1;
-    length += 1;
+        flags &= 1;
+    compint_from_size(header+length, flags, &length);
 
     /* Write out compression type and index size */
     if(!compint_from_int(header+length, zck->comp.type, &length)) {
index a6b9452801175ad9c77aa90bb320c46cc06d3ad2..79936bd268cf2d447191ad3e83e8ab4c691987f1 100644 (file)
@@ -36,7 +36,7 @@
 #include "zck_private.h"
 #include "util.h"
 
-static char *checksum="3fbbbd3977f9e7a0660798d4823c500d0684cb8e576f65b2460af39eee65a73e";
+static char *checksum="8efaeb8e7b3d51a943353f7e6ca4a22266f18c3ef10478b20d50040f4226015d";
 
 int main (int argc, char *argv[]) {
     /* Create empty zchunk file */
index 73deee657ad59741a2863555f6aab9dabede99d4..6cd860ed1a306ccc2859bf10dbc8ffafc5653e84 100644 (file)
@@ -38,9 +38,9 @@ Header checksum
 
 
 The preface:
-+===============+-+-+-+-+========================+
-| Data checksum | Flags | Compression type (ci ) |
-+===============+-+-+-+-+========================+
++===============+============+========================+
+| Data checksum | Flags (ci) | Compression type (ci ) |
++===============+============+========================+
 
 Data checksum
  This is the checksum of everything after the header, including the compressed
@@ -48,8 +48,9 @@ Data checksum
  overall checksum type, *not* the chunk checksum type.
 
 Flags
- 32 bits for flags.  All unused flags MUST be set to 0.  If a decoder sees a
- flag set that it doesn't recognize, it MUST exit with an error.
+ This is a compressed integer containing a bitmask of the flags.  All unused
+ flags MUST be set to 0.  If a decoder sees a flag set that it doesn't
+ recognize, it MUST exit with an error.
 
  Current flags are:
   bit 0: File has data streams