if (hdr.hash_test != hash_test) {
tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
"check: hash test %llu should be %llu\n",
- hdr.hash_test, hash_test);
+ (long long)hdr.hash_test,
+ (long long)hash_test);
return false;
}
if (strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0) {
tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
"check: bad magic '%.*s'\n",
- sizeof(hdr.magic_food), hdr.magic_food);
+ (unsigned)sizeof(hdr.magic_food), hdr.magic_food);
return false;
}
if (!check_hash_tree(tdb, offsetof(struct tdb_header, hashtable),
TDB_TOPLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS,
- 0, 0, used, num_used, &num_found))
+ 0, 0, used, num_used, &num_found))
return false;
if (num_found != num_used) {
unsigned int *max_zone_bits)
{
struct free_zone_header zhdr;
- tdb_off_t off, hdrlen;
+ tdb_off_t off, hdrlen, end;
tdb_len_t len;
if (tdb_read_convert(tdb, zone_off, &zhdr, sizeof(zhdr)) == -1)
return TDB_OFF_ERR;
}
- /* Zone must be within file! */
- if (tdb->methods->oob(tdb, zone_off + (1ULL << zhdr.zone_bits), false))
- return TDB_OFF_ERR;
-
+ /* Zone header must be within file! */
hdrlen = sizeof(zhdr)
+ (BUCKETS_FOR_ZONE(zhdr.zone_bits) + 1) * sizeof(tdb_off_t);
- for (off = zone_off + hdrlen;
- off < zone_off + (1ULL << zhdr.zone_bits);
- off += len) {
+
+ if (tdb->methods->oob(tdb, zone_off + hdrlen, true))
+ return TDB_OFF_ERR;
+
+ end = zone_off + (1ULL << zhdr.zone_bits);
+ if (end > tdb->map_size)
+ end = tdb->map_size;
+
+ for (off = zone_off + hdrlen; off < end; off += len) {
union {
struct tdb_used_record u;
struct tdb_free_record f;
p = tdb_get(tdb, off, &pad, sizeof(pad));
if (!p)
return TDB_OFF_ERR;
- if (frec_magic(&p->f) == TDB_FREE_MAGIC) {
+ if (frec_magic(&p->f) == TDB_FREE_MAGIC
+ || frec_magic(&p->f) == TDB_COALESCING_MAGIC) {
if (frec_zone_bits(&p->f) != zhdr.zone_bits) {
tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
"tdb_check: Bad free zone bits %u"
(long long)off);
return TDB_OFF_ERR;
}
- /* This record is free! */
- if (!append(free, num_free, off))
- return TDB_OFF_ERR;
len = sizeof(p->u) + p->f.data_len;
if (off + len > zone_off + (1ULL << zhdr.zone_bits)) {
tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
(long long)len, (long long)off);
return TDB_OFF_ERR;
}
+ /* This record is free! */
+ if (frec_magic(&p->f) == TDB_FREE_MAGIC
+ && !append(free, num_free, off))
+ return TDB_OFF_ERR;
} else {
uint64_t klen, dlen, extra;
}
}
}
- return 1ULL << zhdr.zone_bits;
+ return off - zone_off;
}
/* FIXME: call check() function. */
tdb_len_t len;
size_t num_free = 0, num_used = 0, num_found = 0;
unsigned max_zone_bits = INITIAL_ZONE_BITS;
- uint8_t tailer;
if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false) != 0)
return -1;
/* First we do a linear scan, checking all records. */
for (off = sizeof(struct tdb_header);
- off < tdb->map_size - 1;
+ off < tdb->map_size;
off += len) {
len = check_zone(tdb, off, &used, &num_used, &free, &num_free,
&max_zone_bits);
goto fail;
}
- /* Check tailer. */
- if (tdb->methods->read(tdb, tdb->map_size - 1, &tailer, 1) == -1)
- goto fail;
- if (tailer != max_zone_bits) {
- tdb->ecode = TDB_ERR_CORRUPT;
- tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
- "tdb_check: Bad tailer value %u vs %u\n", tailer,
- max_zone_bits);
- goto fail;
- }
-
/* FIXME: Check key uniqueness? */
if (!check_hash(tdb, used, num_used))
goto fail;