mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Close current data block before writing cached secondary level table
This commit is contained in:
@@ -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));
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user