+static bool inside_transaction(const struct tdb_context *tdb)
+{
+ if (tdb->flags & TDB_VERSION1)
+ return tdb->tdb1.transaction != NULL;
+ else
+ return tdb->tdb2.transaction != NULL;
+}
+
+static bool readonly_changable(struct tdb_context *tdb, const char *caller)
+{
+ if (inside_transaction(tdb)) {
+ tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL,
+ TDB_LOG_USE_ERROR,
+ "%s: can't change"
+ " TDB_RDONLY inside transaction",
+ caller);
+ return false;
+ }
+
+ if (tdb->file->allrecord_lock.count != 0
+ || tdb->file->num_lockrecs != 0) {
+ tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL,
+ TDB_LOG_USE_ERROR,
+ "%s: can't change"
+ " TDB_RDONLY holding locks",
+ caller);
+ return false;
+ }
+ return true;
+}
+