- new_size = MAX(top_size, map_size);
- size = TDB1_ALIGN(new_size, tdb->tdb1.page_size) - tdb->file->map_size;
+ new_size = MAX(top_size, new_size);
+ return TDB1_ALIGN(new_size, page_size) - map_size;
+}
+
+/* expand the database at least size bytes by expanding the underlying
+ file and doing the mmap again if necessary */
+int tdb1_expand(struct tdb_context *tdb, tdb1_off_t size)
+{
+ struct tdb1_record rec;
+ tdb1_off_t offset;
+
+ if (tdb1_lock(tdb, -1, F_WRLCK) == -1) {
+ tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
+ "lock failed in tdb1_expand");
+ return -1;
+ }
+
+ /* must know about any previous expansions by another process */
+ tdb->tdb1.io->tdb1_oob(tdb, tdb->file->map_size, 1, 1);
+
+ size = tdb1_expand_adjust(tdb->file->map_size, size,
+ tdb->tdb1.page_size);