Do not consider rewinded the first time block 0 is written.

This commit is contained in:
2025-10-20 01:13:14 +01:00
parent d6ea7db911
commit 94e44ef304
2 changed files with 35 additions and 24 deletions

View File

@@ -292,6 +292,7 @@ typedef struct aaruformat_context
bool is_writing; ///< True if context opened/created for writing.
bool rewinded; ///< True if stream has been rewound after open (write path).
bool writing_long; ///< True if writing long sectors
bool block_zero_written; ///< True if block zero has been written (writing path).
/* Options */
uint32_t lzma_dict_size; ///< LZMA dictionary size (writing path).

View File

@@ -149,6 +149,10 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sector_
if(!ctx->rewinded)
{
if(sector_address <= ctx->last_written_block)
{
if(sector_address == 0 && !ctx->block_zero_written)
ctx->block_zero_written = true;
else
{
TRACE("Rewinded");
ctx->rewinded = true;
@@ -164,6 +168,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sector_
// Disable BLAKE3 calculation
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
}
}
else
ctx->last_written_block = sector_address;
}
@@ -641,6 +646,10 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector_long(void *context, uint64_t se
if(!ctx->rewinded)
{
if(sector_address <= ctx->last_written_block)
{
if(sector_address == 0 && !ctx->block_zero_written)
ctx->block_zero_written = true;
else
{
TRACE("Rewinded");
ctx->rewinded = true;
@@ -656,6 +665,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector_long(void *context, uint64_t se
// Disable BLAKE3 calculation
if(ctx->calculating_blake3) ctx->calculating_blake3 = false;
}
}
else
ctx->last_written_block = sector_address;
}