journal: even more simple static object tests

This commit is contained in:
Lennart Poettering 2012-08-18 01:45:39 +02:00
parent 97147f8c1f
commit fb9a24b6b1
4 changed files with 29 additions and 0 deletions

View file

@ -188,6 +188,8 @@ _packed_ struct Header {
/* Added in 189 */
le64_t n_tags;
le64_t n_entry_arrays;
/* Size: 224 */
};
#define FSS_HEADER_SIGNATURE ((char[]) { 'K', 'S', 'H', 'H', 'R', 'H', 'L', 'P' })

View file

@ -798,6 +798,14 @@ uint64_t journal_file_entry_array_n_items(Object *o) {
return (le64toh(o->object.size) - offsetof(Object, entry_array.items)) / sizeof(uint64_t);
}
uint64_t journal_file_hash_table_n_items(Object *o) {
assert(o);
assert(o->object.type == OBJECT_DATA_HASH_TABLE ||
o->object.type == OBJECT_FIELD_HASH_TABLE);
return (le64toh(o->object.size) - offsetof(Object, hash_table.items)) / sizeof(HashItem);
}
static int link_entry_into_array(JournalFile *f,
le64_t *first,
le64_t *idx,

View file

@ -126,6 +126,7 @@ int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Objec
uint64_t journal_file_entry_n_items(Object *o);
uint64_t journal_file_entry_array_n_items(Object *o);
uint64_t journal_file_hash_table_n_items(Object *o);
int journal_file_append_object(JournalFile *f, int type, uint64_t size, Object **ret, uint64_t *offset);
int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqno, Object **ret, uint64_t *offset);

View file

@ -134,6 +134,19 @@ static int journal_file_object_verify(JournalFile *f, Object *o) {
if ((le64toh(o->object.size) - offsetof(HashTableObject, items)) / sizeof(HashItem) <= 0)
return -EBADMSG;
for (i = 0; i < journal_file_hash_table_n_items(o); i++) {
if (o->hash_table.items[i].head_hash_offset != 0 &&
!VALID64(le64toh(o->hash_table.items[i].head_hash_offset)))
return -EBADMSG;
if (o->hash_table.items[i].tail_hash_offset != 0 &&
!VALID64(le64toh(o->hash_table.items[i].tail_hash_offset)))
return -EBADMSG;
if ((o->hash_table.items[i].head_hash_offset != 0) !=
(o->hash_table.items[i].tail_hash_offset != 0))
return -EBADMSG;
}
break;
case OBJECT_ENTRY_ARRAY:
@ -146,6 +159,11 @@ static int journal_file_object_verify(JournalFile *f, Object *o) {
if (!VALID64(o->entry_array.next_entry_array_offset))
return -EBADMSG;
for (i = 0; i < journal_file_entry_array_n_items(o); i++)
if (o->entry_array.items[i] != 0 &&
!VALID64(o->entry_array.items[i]))
return -EBADMSG;
break;
case OBJECT_TAG: