chiark / gitweb /
journal: use a macro to check for file header flags
authorLennart Poettering <lennart@poettering.net>
Mon, 20 Aug 2012 14:11:42 +0000 (16:11 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 20 Aug 2012 14:11:42 +0000 (16:11 +0200)
src/journal/journal-authenticate.c
src/journal/journal-file.c
src/journal/journal-file.h
src/journal/journal-verify.c

index 9853edb..ddcf856 100644 (file)
@@ -464,5 +464,5 @@ int journal_file_append_first_tag(JournalFile *f) {
 bool journal_file_fss_enabled(JournalFile *f) {
         assert(f);
 
-        return !!(le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_SEALED);
+        return JOURNAL_HEADER_SEALED(f->header);
 }
index f419cf6..760efae 100644 (file)
@@ -210,8 +210,7 @@ static int journal_file_verify_header(JournalFile *f) {
         if (le64toh(f->header->header_size) < HEADER_SIZE_MIN)
                 return -EBADMSG;
 
-        if ((le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_SEALED) &&
-                !JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays))
+        if (JOURNAL_HEADER_SEALED(f->header) && !JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays))
                 return -EBADMSG;
 
         if ((le64toh(f->header->header_size) + le64toh(f->header->arena_size)) > (uint64_t) f->last_stat.st_size)
@@ -251,10 +250,10 @@ static int journal_file_verify_header(JournalFile *f) {
                 }
         }
 
-        f->compress = !!(le32toh(f->header->incompatible_flags) & HEADER_INCOMPATIBLE_COMPRESSED);
+        f->compress = JOURNAL_HEADER_COMPRESSED(f->header);
 
         if (f->writable)
-                f->seal = !!(le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_SEALED);
+                f->seal = JOURNAL_HEADER_SEALED(f->header);
 
         return 0;
 }
@@ -1927,10 +1926,10 @@ void journal_file_print_header(JournalFile *f) {
                f->header->state == STATE_OFFLINE ? "OFFLINE" :
                f->header->state == STATE_ONLINE ? "ONLINE" :
                f->header->state == STATE_ARCHIVED ? "ARCHIVED" : "UNKNOWN",
-               (f->header->compatible_flags & HEADER_COMPATIBLE_SEALED) ? " SEALED" : "",
-               (f->header->compatible_flags & ~HEADER_COMPATIBLE_SEALED) ? " ???" : "",
-               (f->header->incompatible_flags & HEADER_INCOMPATIBLE_COMPRESSED) ? " COMPRESSED" : "",
-               (f->header->incompatible_flags & ~HEADER_INCOMPATIBLE_COMPRESSED) ? " ???" : "",
+               JOURNAL_HEADER_SEALED(f->header) ? " SEALED" : "",
+               (le32toh(f->header->compatible_flags) & ~HEADER_COMPATIBLE_SEALED) ? " ???" : "",
+               JOURNAL_HEADER_COMPRESSED(f->header) ? " COMPRESSED" : "",
+               (le32toh(f->header->incompatible_flags) & ~HEADER_INCOMPATIBLE_COMPRESSED) ? " ???" : "",
                (unsigned long long) le64toh(f->header->header_size),
                (unsigned long long) le64toh(f->header->arena_size),
                (unsigned long long) le64toh(f->header->data_hash_table_size) / sizeof(HashItem),
index 7358173..5b1530e 100644 (file)
@@ -137,6 +137,12 @@ static inline bool VALID_EPOCH(uint64_t u) {
 #define JOURNAL_HEADER_CONTAINS(h, field) \
         (le64toh((h)->header_size) >= offsetof(Header, field) + sizeof((h)->field))
 
+#define JOURNAL_HEADER_SEALED(h) \
+        (!!(le32toh((h)->compatible_flags) & HEADER_COMPATIBLE_SEALED))
+
+#define JOURNAL_HEADER_COMPRESSED(h) \
+        (!!(le32toh((h)->incompatible_flags) & HEADER_INCOMPATIBLE_COMPRESSED))
+
 int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Object **ret);
 
 uint64_t journal_file_entry_n_items(Object *o);
index 08f3e16..6afeab9 100644 (file)
@@ -36,7 +36,6 @@
 /* FIXME:
  *
  * - evolve key even if nothing happened in regular intervals
- * - add macro for accessing flags
  *
  * - Allow building without libgcrypt
  * - check with sparse
@@ -806,8 +805,7 @@ int journal_file_verify(
                         goto fail;
                 }
 
-                if (o->object.flags & OBJECT_COMPRESSED &&
-                    !(le32toh(f->header->incompatible_flags) & HEADER_INCOMPATIBLE_COMPRESSED)) {
+                if ((o->object.flags & OBJECT_COMPRESSED) && !JOURNAL_HEADER_COMPRESSED(f->header)) {
                         log_error("Compressed object in file without compression at %llu", (unsigned long long) p);
                         r = -EBADMSG;
                         goto fail;
@@ -828,7 +826,7 @@ int journal_file_verify(
                         break;
 
                 case OBJECT_ENTRY:
-                        if ((le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_SEALED) && n_tags <= 0) {
+                        if (JOURNAL_HEADER_SEALED(f->header) && n_tags <= 0) {
                                 log_error("First entry before first tag at %llu", (unsigned long long) p);
                                 r = -EBADMSG;
                                 goto fail;
@@ -941,7 +939,7 @@ int journal_file_verify(
                 case OBJECT_TAG: {
                         uint64_t q, rt;
 
-                        if (!(le32toh(f->header->compatible_flags) & HEADER_COMPATIBLE_SEALED)) {
+                        if (!JOURNAL_HEADER_SEALED(f->header)) {
                                 log_error("Tag object in file without sealing at %llu", (unsigned long long) p);
                                 r = -EBADMSG;
                                 goto fail;