journal-file: make seeking in corrupted files work

Previously, when we used a bisection table for seeking through a corrupted
file, and the end of the bisection table was corrupted we'd most likely fail
the entire seek operation. Improve the situation: if we encounter invalid
entries in a bisection table, linearly go backwards until we find a working
entry again.
This commit is contained in:
Lennart Poettering
2016-04-26 12:00:49 +02:00
parent caeab8f626
commit bee6a29198
+16 -6
View File
@@ -1984,9 +1984,14 @@ static int generic_array_bisect(
i = right - 1;
lp = p = le64toh(array->entry_array.items[i]);
if (p <= 0)
return -EBADMSG;
r = test_object(f, p, needle);
r = -EBADMSG;
else
r = test_object(f, p, needle);
if (r == -EBADMSG) {
log_debug_errno(r, "Encountered invalid entry while bisecting, cutting algorithm short. (1)");
n = i;
continue;
}
if (r < 0)
return r;
@@ -2062,9 +2067,14 @@ static int generic_array_bisect(
p = le64toh(array->entry_array.items[i]);
if (p <= 0)
return -EBADMSG;
r = test_object(f, p, needle);
r = -EBADMSG;
else
r = test_object(f, p, needle);
if (r == -EBADMSG) {
log_debug_errno(r, "Encountered invalid entry while bisecting, cutting algorithm short. (2)");
right = n = i;
continue;
}
if (r < 0)
return r;