From d05089d86ef032b245c7f928e623b88c82998ab0 Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Fri, 12 Dec 2014 22:51:24 +0100 Subject: [PATCH] journal: consistently use OBJECT_ names instead of numbers Note that numbers 0 and -1 are both replaced with OBJECT_UNUSED, because they are treated the same everywhere (e.g. type_to_context() translates them both to 0). --- src/journal/journal-authenticate.c | 2 +- src/journal/journal-def.h | 2 +- src/journal/journal-file.c | 10 +++++----- src/journal/journal-verify.c | 8 ++++---- src/journal/sd-journal.c | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/journal/journal-authenticate.c b/src/journal/journal-authenticate.c index fd3b82134..0e31c8dc9 100644 --- a/src/journal/journal-authenticate.c +++ b/src/journal/journal-authenticate.c @@ -246,7 +246,7 @@ int journal_file_hmac_put_object(JournalFile *f, int type, Object *o, uint64_t p if (r < 0) return r; } else { - if (type > 0 && o->object.type != type) + if (type > OBJECT_UNUSED && o->object.type != type) return -EBADMSG; } diff --git a/src/journal/journal-def.h b/src/journal/journal-def.h index e55fa196f..005e5fa14 100644 --- a/src/journal/journal-def.h +++ b/src/journal/journal-def.h @@ -53,7 +53,7 @@ typedef struct FSSHeader FSSHeader; /* Object types */ enum { - OBJECT_UNUSED, + OBJECT_UNUSED, /* also serves as "any type" or "additional context" */ OBJECT_DATA, OBJECT_FIELD, OBJECT_ENTRY, diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 4632326d4..6ee0fff04 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -376,7 +376,7 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size) static unsigned type_to_context(int type) { /* One context for each type, plus one catch-all for the rest */ - return type > 0 && type < _OBJECT_TYPE_MAX ? type : 0; + return type > OBJECT_UNUSED && type < _OBJECT_TYPE_MAX ? type : 0; } static int journal_file_move_to(JournalFile *f, int context, bool keep_always, uint64_t offset, uint64_t size, void **ret) { @@ -446,7 +446,7 @@ int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Objec if (s < minimum_header_size(o)) return -EBADMSG; - if (type > 0 && o->object.type != type) + if (type > OBJECT_UNUSED && o->object.type != type) return -EBADMSG; if (s > sizeof(ObjectHeader)) { @@ -494,7 +494,7 @@ int journal_file_append_object(JournalFile *f, int type, uint64_t size, Object * void *t; assert(f); - assert(type > 0 && type < _OBJECT_TYPE_MAX); + assert(type > OBJECT_UNUSED && type < _OBJECT_TYPE_MAX); assert(size >= sizeof(ObjectHeader)); assert(offset); assert(ret); @@ -507,7 +507,7 @@ int journal_file_append_object(JournalFile *f, int type, uint64_t size, Object * if (p == 0) p = le64toh(f->header->header_size); else { - r = journal_file_move_to_object(f, -1, p, &tail); + r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &tail); if (r < 0) return r; @@ -2294,7 +2294,7 @@ void journal_file_dump(JournalFile *f) { p = le64toh(f->header->header_size); while (p != 0) { - r = journal_file_move_to_object(f, -1, p, &o); + r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &o); if (r < 0) goto fail; diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index 75792a5a6..b03335ef3 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -865,7 +865,7 @@ int journal_file_verify( if (show_progress) draw_progress(0x7FFF * p / le64toh(f->header->tail_object_offset), &last_usec); - r = journal_file_move_to_object(f, -1, p, &o); + r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &o); if (r < 0) { error(p, "invalid object"); goto fail; @@ -1085,11 +1085,11 @@ int journal_file_verify( q = last_tag; while (q <= p) { - r = journal_file_move_to_object(f, -1, q, &o); + r = journal_file_move_to_object(f, OBJECT_UNUSED, q, &o); if (r < 0) goto fail; - r = journal_file_hmac_put_object(f, -1, o, q); + r = journal_file_hmac_put_object(f, OBJECT_UNUSED, o, q); if (r < 0) goto fail; @@ -1097,7 +1097,7 @@ int journal_file_verify( } /* Position might have changed, let's reposition things */ - r = journal_file_move_to_object(f, -1, p, &o); + r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &o); if (r < 0) goto fail; diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 028060d34..be08a92b7 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -2588,10 +2588,10 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_ continue; } - /* We do not use the type context here, but 0 instead, - * so that we can look at this data object at the same + /* We do not use OBJECT_DATA context here, but OBJECT_UNUSED + * instead, so that we can look at this data object at the same * time as one on another file */ - r = journal_file_move_to_object(j->unique_file, 0, j->unique_offset, &o); + r = journal_file_move_to_object(j->unique_file, OBJECT_UNUSED, j->unique_offset, &o); if (r < 0) return r; -- 2.30.2