X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Fcheck.c;h=3003b626161122f59d6721c3133193b1d2ea203e;hb=20f3b260313fb4d5566aeb0d0c5439574e914e2d;hp=6d846f414264404255eac5f67d0c93ea824b219b;hpb=bbeb528e74c0e234e1f724ac8d54be404cfc6f9a;p=ccan diff --git a/ccan/tdb2/check.c b/ccan/tdb2/check.c index 6d846f41..3003b626 100644 --- a/ccan/tdb2/check.c +++ b/ccan/tdb2/check.c @@ -148,7 +148,7 @@ static enum TDB_ERROR check_hash_chain(struct tdb_context *tdb, off = tdb_read_off(tdb, off + offsetof(struct tdb_chain, next)); if (TDB_OFF_IS_ERR(off)) { - return off; + return TDB_OFF_TO_ERR(off); } if (off == 0) return TDB_SUCCESS; @@ -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. */ @@ -534,7 +534,7 @@ 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 (TDB_OFF_IS_ERR(off)) { - return off; + return TDB_OFF_TO_ERR(off); } if (!first) { off &= TDB_OFF_MASK; @@ -589,7 +589,7 @@ tdb_off_t dead_space(struct tdb_context *tdb, tdb_off_t off) char c; ecode = tdb->tdb2.io->tread(tdb, off, &c, 1); if (ecode != TDB_SUCCESS) { - return ecode; + return TDB_ERR_TO_OFF(ecode); } if (c != 0 && c != 0x43) break; @@ -634,7 +634,7 @@ static enum TDB_ERROR check_linear(struct tdb_context *tdb, } else { len = dead_space(tdb, off); if (TDB_OFF_IS_ERR(len)) { - return len; + return TDB_OFF_TO_ERR(len); } if (len < sizeof(rec.r)) { return tdb_logerr(tdb, TDB_ERR_CORRUPT, @@ -782,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; @@ -805,7 +811,7 @@ enum TDB_ERROR tdb_check_(struct tdb_context *tdb, for (ft = first_ftable(tdb); ft; ft = next_ftable(tdb, ft)) { if (TDB_OFF_IS_ERR(ft)) { - ecode = ft; + ecode = TDB_OFF_TO_ERR(ft); goto out; } ecode = check_free_table(tdb, ft, num_ftables, fr, num_free,