From bdc5499205367eccef5700cba8af95ba941ac9b2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Sep 2011 07:16:13 +0930 Subject: tdb2: add TDB_RDONLY flag, allow setting/unsetting it. You can only unset it if the TDB was originally opened O_RDWR. Also, cleaned up error handling in tdb_allrecord_lock() so we only get one log message on a r/o database. Signed-off-by: Rusty Russell (Imported from CCAN commit b87e14495d5b07e1b247218a72329f10ecb3da7f) --- lib/tdb2/io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/tdb2/io.c') diff --git a/lib/tdb2/io.c b/lib/tdb2/io.c index d422d96326..24c70084e9 100644 --- a/lib/tdb2/io.c +++ b/lib/tdb2/io.c @@ -200,7 +200,7 @@ enum TDB_ERROR zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len) void *p = tdb->methods->direct(tdb, off, len, true); enum TDB_ERROR ecode = TDB_SUCCESS; - assert(!tdb->read_only); + assert(!(tdb->flags & TDB_RDONLY)); if (TDB_PTR_IS_ERR(p)) { return TDB_PTR_ERR(p); } @@ -248,7 +248,7 @@ static enum TDB_ERROR tdb_write(struct tdb_context *tdb, tdb_off_t off, { enum TDB_ERROR ecode; - if (tdb->read_only) { + if (tdb->flags & TDB_RDONLY) { return tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR, "Write to read-only database"); } @@ -337,7 +337,7 @@ enum TDB_ERROR tdb_read_convert(struct tdb_context *tdb, tdb_off_t off, enum TDB_ERROR tdb_write_off(struct tdb_context *tdb, tdb_off_t off, tdb_off_t val) { - if (tdb->read_only) { + if (tdb->flags & TDB_RDONLY) { return tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR, "Write to read-only database"); } @@ -416,7 +416,7 @@ static enum TDB_ERROR tdb_expand_file(struct tdb_context *tdb, char buf[8192]; enum TDB_ERROR ecode; - if (tdb->read_only) { + if (tdb->flags & TDB_RDONLY) { return tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR, "Expand on read-only database"); } @@ -488,7 +488,7 @@ void *tdb_access_write(struct tdb_context *tdb, { void *ret = NULL; - if (tdb->read_only) { + if (tdb->flags & TDB_RDONLY) { tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR, "Write to read-only database"); return TDB_ERR_PTR(TDB_ERR_RDONLY); -- cgit