From 786b7263000dedcb97e7369402e2e9dc967e36c4 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 13 Sep 2010 20:05:59 +0930 Subject: tdb: put example hashes into header, so we notice incorrect hash_fn. This is Stefan Metzmacher 's patch with minor changes: 1) Use the TDB_MAGIC constant so both hashes aren't of strings. 2) Check the hash in tdb_check (paranoia, really). 3) Additional check in the (unlikely!) case where both examples hash to 0. 4) Cosmetic changes to var names and complaint message. Signed-off-by: Rusty Russell --- lib/tdb/common/tdb_private.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/tdb/common/tdb_private.h') diff --git a/lib/tdb/common/tdb_private.h b/lib/tdb/common/tdb_private.h index 9d0f3bcd70..eccd6880ef 100644 --- a/lib/tdb/common/tdb_private.h +++ b/lib/tdb/common/tdb_private.h @@ -147,7 +147,9 @@ struct tdb_header { tdb_off_t rwlocks; /* obsolete - kept to detect old formats */ tdb_off_t recovery_start; /* offset of transaction recovery region */ tdb_off_t sequence_number; /* used when TDB_SEQNUM is set */ - tdb_off_t reserved[29]; + uint32_t magic1_hash; /* hash of TDB_MAGIC_FOOD. */ + uint32_t magic2_hash; /* hash of TDB_MAGIC. */ + tdb_off_t reserved[27]; }; struct tdb_lock_type { @@ -268,3 +270,5 @@ int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct tdb_record *rec); bool tdb_write_all(int fd, const void *buf, size_t count); int tdb_transaction_recover(struct tdb_context *tdb); +void tdb_header_hash(struct tdb_context *tdb, + uint32_t *magic1_hash, uint32_t *magic2_hash); -- cgit