static int bump_entry_array(
JournalFile *f,
- Object *o,
- uint64_t offset,
- uint64_t first,
+ Object *o, /* the current entry array object. */
+ uint64_t offset, /* the offset of the entry array object. */
+ uint64_t first, /* The offset of the first entry array object in the chain. */
direction_t direction,
uint64_t *ret) {
- uint64_t p, q = 0;
int r;
assert(f);
- assert(offset);
assert(ret);
if (direction == DIRECTION_DOWN) {
assert(o);
+ assert(o->object.type == OBJECT_ENTRY_ARRAY);
+
*ret = le64toh(o->entry_array.next_entry_array_offset);
- return 0;
- }
+ } else {
- /* Entry array chains are a singly linked list, so to find the previous array in the chain, we have
- * to start iterating from the top. */
+ /* Entry array chains are a singly linked list, so to find the previous array in the chain, we have
+ * to start iterating from the top. */
- p = first;
+ assert(offset > 0);
- while (p > 0 && p != offset) {
- r = journal_file_move_to_object(f, OBJECT_ENTRY_ARRAY, p, &o);
- if (r < 0)
- return r;
+ uint64_t p = first, q = 0;
+ while (p > 0 && p != offset) {
+ r = journal_file_move_to_object(f, OBJECT_ENTRY_ARRAY, p, &o);
+ if (r < 0)
+ return r;
- q = p;
- p = le64toh(o->entry_array.next_entry_array_offset);
- }
+ q = p;
+ p = le64toh(o->entry_array.next_entry_array_offset);
+ }
- /* If we can't find the previous entry array in the entry array chain, we're likely dealing with a
- * corrupted journal file. */
- if (p == 0)
- return -EBADMSG;
+ /* If we can't find the previous entry array in the entry array chain, we're likely dealing with a
+ * corrupted journal file. */
+ if (p == 0)
+ return -EBADMSG;
- *ret = q;
+ *ret = q;
+ }
- return 0;
+ return *ret > 0;
}
static int generic_array_get(
* array and start iterating entries from there. */
r = bump_entry_array(f, NULL, a, first, DIRECTION_UP, &a);
- if (r < 0)
+ if (r <= 0)
return r;
i = UINT64_MAX;
} while (bump_array_index(&i, direction, k) > 0);
r = bump_entry_array(f, o, a, first, direction, &a);
- if (r < 0)
+ if (r <= 0)
return r;
t += k;