tdb_len_t len2 = PAGESIZE - (off % PAGESIZE);
ecode = transaction_write(tdb, off, buf, len2);
if (ecode != TDB_SUCCESS) {
- return -1;
+ return ecode;
}
len -= len2;
off += len2;
/*
out of bounds check during a transaction
*/
-static enum TDB_ERROR transaction_oob(struct tdb_context *tdb, tdb_off_t len,
- bool probe)
+static enum TDB_ERROR transaction_oob(struct tdb_context *tdb,
+ tdb_off_t off, tdb_len_t len, bool probe)
{
- if (len <= tdb->file->map_size || probe) {
+ if ((off + len >= off && off + len <= tdb->file->map_size) || probe) {
return TDB_SUCCESS;
}
tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
"tdb_oob len %lld beyond transaction size %lld",
- (long long)len,
+ (long long)(off + len),
(long long)tdb->file->map_size);
return TDB_ERR_IO;
}
{
enum TDB_ERROR ecode;
+ if (tdb->flags & TDB_VERSION1) {
+ if (tdb1_transaction_start(tdb) == -1)
+ return tdb->last_error;
+ return TDB_SUCCESS;
+ }
+
tdb->stats.transactions++;
/* some sanity checks */
if (tdb->flags & TDB_INTERNAL) {
/* make sure we know about any file expansions already done by
anyone else */
- tdb->tdb2.io->oob(tdb, tdb->file->map_size + 1, true);
+ tdb->tdb2.io->oob(tdb, tdb->file->map_size, 1, true);
tdb->tdb2.transaction->old_map_size = tdb->file->map_size;
/* finally hook the io methods, replacing them with
*/
void tdb_transaction_cancel(struct tdb_context *tdb)
{
+ if (tdb->flags & TDB_VERSION1) {
+ tdb1_transaction_cancel(tdb);
+ return;
+ }
tdb->stats.transaction_cancel++;
_tdb_transaction_cancel(tdb);
}
*recovery_offset = tdb_read_off(tdb,
offsetof(struct tdb_header, recovery));
if (TDB_OFF_IS_ERR(*recovery_offset)) {
- return *recovery_offset;
+ return TDB_OFF_TO_ERR(*recovery_offset);
}
if (*recovery_offset == 0) {
tdb->stats.transaction_expand_file++;
ecode = methods->expand_file(tdb, addition);
if (ecode != TDB_SUCCESS) {
- return tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
- "tdb_recovery_allocate:"
- " failed to create recovery area");
+ tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
+ "tdb_recovery_allocate:"
+ " failed to create recovery area");
+ return TDB_ERR_TO_OFF(ecode);
}
/* we have to reset the old map size so that we don't try to
ecode = methods->twrite(tdb, offsetof(struct tdb_header, recovery),
&recovery_off, sizeof(tdb_off_t));
if (ecode != TDB_SUCCESS) {
- return tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
- "tdb_recovery_allocate:"
- " failed to write recovery head");
+ tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
+ "tdb_recovery_allocate:"
+ " failed to write recovery head");
+ return TDB_ERR_TO_OFF(ecode);
}
transaction_write_existing(tdb, offsetof(struct tdb_header, recovery),
&recovery_off,
recovery);
if (TDB_OFF_IS_ERR(recovery_off)) {
free(recovery);
- return recovery_off;
+ return TDB_OFF_TO_ERR(recovery_off);
}
}
*/
enum TDB_ERROR tdb_transaction_prepare_commit(struct tdb_context *tdb)
{
- return _tdb_transaction_prepare_commit(tdb);
+ if (tdb->flags & TDB_VERSION1) {
+ if (tdb1_transaction_prepare_commit(tdb) == -1)
+ return tdb->last_error;
+ return TDB_SUCCESS;
+ }
+ return tdb->last_error = _tdb_transaction_prepare_commit(tdb);
}
/*
int i;
enum TDB_ERROR ecode;
+ if (tdb->flags & TDB_VERSION1) {
+ if (tdb1_transaction_commit(tdb) == -1)
+ return tdb->last_error;
+ return TDB_SUCCESS;
+ }
+
if (tdb->tdb2.transaction == NULL) {
return tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL,
TDB_LOG_USE_ERROR,
/* find the recovery area */
recovery_head = tdb_read_off(tdb, offsetof(struct tdb_header,recovery));
if (TDB_OFF_IS_ERR(recovery_head)) {
- return tdb_logerr(tdb, recovery_head, TDB_LOG_ERROR,
+ ecode = TDB_OFF_TO_ERR(recovery_head);
+ return tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
"tdb_transaction_recover:"
" failed to read recovery head");
}
/* read the recovery record */
ecode = tdb_read_convert(tdb, recovery_head, &rec, sizeof(rec));
if (ecode != TDB_SUCCESS) {
- return ecode;
+ return TDB_ERR_TO_OFF(ecode);
}
return (rec.magic == TDB_RECOVERY_MAGIC);