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
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
currentPos = ftell(ctx->imageStream);
fseek(ctx->imageStream, 0, SEEK_END);
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
memset(&ddtHeader, 0, sizeof(DdtHeader2));