diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-08-20 16:11:42 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-08-20 16:11:42 +0200 |
commit | 8088cbd3cfcf539c984d8042cd2b92ebbfda6d82 (patch) | |
tree | 564b151870105cb540313774907181c1bf85c3b1 | |
parent | f7fab8a5ae7a3b378040203821383f5a8fc91126 (diff) |
journal: use a macro to check for file header flags
-rw-r--r-- | src/journal/journal-authenticate.c | 2 | ||||
-rw-r--r-- | src/journal/journal-file.c | 15 | ||||
-rw-r--r-- | src/journal/journal-file.h | 6 | ||||
-rw-r--r-- | src/journal/journal-verify.c | 8 |
4 files changed, 17 insertions, 14 deletions
diff --git a/src/journal/journal-authenticate.c b/src/journal/journal-authenticate.c index 9853edb58c..ddcf856aec 100644 --- a/src/journal/journal-authenticate.c +++ b/src/journal/journal-authenticate.c @@ -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); } diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index f419cf6b65..760efaebbb 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -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), diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h index 7358173e7a..5b1530e7a7 100644 --- a/src/journal/journal-file.h +++ b/src/journal/journal-file.h @@ -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); diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index 08f3e16aa9..6afeab9a80 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -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; |