written to, it gets created in this list */
uint8_t **blocks;
size_t num_blocks;
- size_t last_block_size; /* number of valid bytes in the last block */
/* non-zero when an internal transaction error has
occurred. All write operations will then fail until the
return 0;
}
- /* it is in the block list. Now check for the last block */
- if (blk == ntdb->transaction->num_blocks-1) {
- if (len > ntdb->transaction->last_block_size) {
- ecode = NTDB_ERR_IO;
- goto fail;
- }
- }
-
/* now copy it out of this block */
memcpy(buf, ntdb->transaction->blocks[blk] + (off % NTDB_PGSIZE), len);
return NTDB_SUCCESS;
(1+(blk - ntdb->transaction->num_blocks))*sizeof(uint8_t *));
ntdb->transaction->blocks = new_blocks;
ntdb->transaction->num_blocks = blk+1;
- ntdb->transaction->last_block_size = 0;
}
/* allocate and fill a block? */
SAFE_FREE(ntdb->transaction->blocks[blk]);
goto fail;
}
- if (blk == ntdb->transaction->num_blocks-1) {
- ntdb->transaction->last_block_size = len2;
- }
}
}
} else {
memcpy(ntdb->transaction->blocks[blk] + off, buf, len);
}
- if (blk == ntdb->transaction->num_blocks-1) {
- if (len + off > ntdb->transaction->last_block_size) {
- ntdb->transaction->last_block_size = len + off;
- }
- }
-
return NTDB_SUCCESS;
fail:
return;
}
- if (blk == ntdb->transaction->num_blocks-1 &&
- off + len > ntdb->transaction->last_block_size) {
- if (off >= ntdb->transaction->last_block_size) {
- return;
- }
- len = ntdb->transaction->last_block_size - off;
- }
-
/* overwrite part of an existing block */
memcpy(ntdb->transaction->blocks[blk] + off, buf, len);
}
if (ntdb->transaction->blocks[i] == NULL) {
continue;
}
- recovery_size += 2*sizeof(ntdb_off_t);
- if (i == ntdb->transaction->num_blocks-1) {
- recovery_size += ntdb->transaction->last_block_size;
- } else {
- recovery_size += NTDB_PGSIZE;
- }
+ recovery_size += 2*sizeof(ntdb_off_t) + NTDB_PGSIZE;
}
return recovery_size;
offset = i * NTDB_PGSIZE;
length = NTDB_PGSIZE;
- if (i == ntdb->transaction->num_blocks-1) {
- length = ntdb->transaction->last_block_size;
- }
-
if (offset >= ntdb->transaction->old_map_size) {
continue;
}
" boundary");
goto fail;
}
- if (offset + length > ntdb->transaction->old_map_size) {
- /* Short read at EOF. */
- length = ntdb->transaction->old_map_size - offset;
- }
buffer = ntdb_access_read(ntdb, offset, length, false);
if (NTDB_PTR_IS_ERR(buffer)) {
ecode = NTDB_PTR_ERR(buffer);
offset = i * NTDB_PGSIZE;
length = NTDB_PGSIZE;
- if (i == ntdb->transaction->num_blocks-1) {
- length = ntdb->transaction->last_block_size;
- }
ecode = methods->twrite(ntdb, offset,
ntdb->transaction->blocks[i], length);