1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-25 23:21:33 +03:00

journal: use a macro to check for file header flags

This commit is contained in:
Lennart Poettering 2012-08-20 16:11:42 +02:00
parent f7fab8a5ae
commit 8088cbd3cf
4 changed files with 17 additions and 14 deletions

View 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);
}

View 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),

View 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);

View 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;