Close current data block before writing cached secondary level table

This commit is contained in:
2025-09-28 16:13:56 +01:00
parent ce20e37007
commit a4b76fe509
2 changed files with 8 additions and 1 deletions

View File

@@ -903,10 +903,16 @@ void set_ddt_multi_level_v2(aaruformatContext *ctx, uint64_t sectorAddress, bool
// Step 3: Write the currently in-memory cached secondary level table to the end of the file // Step 3: Write the currently in-memory cached secondary level table to the end of the file
if(ctx->cachedDdtOffset != 0) if(ctx->cachedDdtOffset != 0)
{ {
// Close the current data block first
if(ctx->writingBuffer != NULL) aaruf_close_current_block(ctx);
// Get current position and seek to end of file // Get current position and seek to end of file
currentPos = ftell(ctx->imageStream); currentPos = ftell(ctx->imageStream);
fseek(ctx->imageStream, 0, SEEK_END); fseek(ctx->imageStream, 0, SEEK_END);
endOfFile = ftell(ctx->imageStream); endOfFile = ftell(ctx->imageStream);
endOfFile = endOfFile / (1 << ctx->userDataDdtHeader.blockAlignmentShift) *
(1 << ctx->userDataDdtHeader.blockAlignmentShift);
fseek(ctx->imageStream, endOfFile, SEEK_SET);
// Prepare DDT header for the cached table // Prepare DDT header for the cached table
memset(&ddtHeader, 0, sizeof(DdtHeader2)); memset(&ddtHeader, 0, sizeof(DdtHeader2));

View File

@@ -85,6 +85,8 @@ int32_t aaruf_write_sector(void *context, uint64_t sectorAddress, uint8_t *data,
} }
} }
set_ddt_entry_v2(ctx, sectorAddress, ctx->currentBlockOffset, ctx->nextBlockPosition, sectorStatus);
// No block set // No block set
if(ctx->writingBufferPosition == 0) if(ctx->writingBufferPosition == 0)
{ {
@@ -120,7 +122,6 @@ int32_t aaruf_write_sector(void *context, uint64_t sectorAddress, uint8_t *data,
pos / (1 << ctx->userDataDdtHeader.blockAlignmentShift) * (1 << ctx->userDataDdtHeader.blockAlignmentShift); pos / (1 << ctx->userDataDdtHeader.blockAlignmentShift) * (1 << ctx->userDataDdtHeader.blockAlignmentShift);
} }
set_ddt_entry_v2(ctx, sectorAddress, ctx->currentBlockOffset, ctx->nextBlockPosition, sectorStatus);
TRACE("Copying data to writing buffer at position %zu", ctx->writingBufferPosition); TRACE("Copying data to writing buffer at position %zu", ctx->writingBufferPosition);
memcpy(ctx->writingBuffer, data, length); memcpy(ctx->writingBuffer, data, length);
TRACE("Advancing writing buffer position to %zu", ctx->writingBufferPosition + length); TRACE("Advancing writing buffer position to %zu", ctx->writingBufferPosition + length);