X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Fcheck.c;h=a8b5b3d558c04e2943912d77b7b558e3cd609499;hp=88b86429cb97aed7a2486f53a7699626d7fc3041;hb=6d3832ee613adeb9ae7ed6454996ffa39c32650f;hpb=007a7e4e8df8f43c61126599bcc582750cbf17fe diff --git a/ccan/tdb2/check.c b/ccan/tdb2/check.c index 88b86429..a8b5b3d5 100644 --- a/ccan/tdb2/check.c +++ b/ccan/tdb2/check.c @@ -436,7 +436,7 @@ fail: static enum TDB_ERROR check_hash(struct tdb_context *tdb, tdb_off_t used[], size_t num_used, size_t num_ftables, - int (*check)(TDB_DATA, TDB_DATA, void *), + enum TDB_ERROR (*check)(TDB_DATA, TDB_DATA, void *), void *data) { /* Free tables also show up as used. */ @@ -478,7 +478,7 @@ static enum TDB_ERROR check_free(struct tdb_context *tdb, } - ecode = tdb->methods->oob(tdb, off + ecode = tdb->tdb2.io->oob(tdb, off + frec_len(frec) + sizeof(struct tdb_used_record), false); @@ -533,11 +533,13 @@ static enum TDB_ERROR check_free_table(struct tdb_context *tdb, h = bucket_off(ftable_off, i); for (off = tdb_read_off(tdb, h); off; off = f.next) { - if (!first) - first = off; if (TDB_OFF_IS_ERR(off)) { return off; } + if (!first) { + off &= TDB_OFF_MASK; + first = off; + } ecode = tdb_read_convert(tdb, off, &f, sizeof(f)); if (ecode != TDB_SUCCESS) { return ecode; @@ -585,7 +587,7 @@ tdb_off_t dead_space(struct tdb_context *tdb, tdb_off_t off) for (len = 0; off + len < tdb->file->map_size; len++) { char c; - ecode = tdb->methods->tread(tdb, off, &c, 1); + ecode = tdb->tdb2.io->tread(tdb, off, &c, 1); if (ecode != TDB_SUCCESS) { return ecode; } @@ -780,6 +782,12 @@ enum TDB_ERROR tdb_check_(struct tdb_context *tdb, uint64_t features; enum TDB_ERROR ecode; + if (tdb->flags & TDB_VERSION1) { + if (tdb1_check(tdb, check, data) == -1) + return tdb->last_error; + return TDB_SUCCESS; + } + ecode = tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false); if (ecode != TDB_SUCCESS) { return tdb->last_error = ecode;