Add rewind tracking to aaruformatContext and initialize in create.c

This commit is contained in:
2025-10-03 00:17:16 +01:00
parent ba853e23b6
commit 9e128a0ab8
3 changed files with 16 additions and 0 deletions

View File

@@ -209,6 +209,9 @@ typedef struct aaruformatContext
UT_array *indexEntries; ///< Flattened index entries (UT_array of IndexEntry). UT_array *indexEntries; ///< Flattened index entries (UT_array of IndexEntry).
hash_map_t *sectorHashMap; ///< Deduplication hash map (fingerprint->entry mapping). hash_map_t *sectorHashMap; ///< Deduplication hash map (fingerprint->entry mapping).
bool deduplicate; ///< Storage deduplication active (duplicates coalesce). bool deduplicate; ///< Storage deduplication active (duplicates coalesce).
bool rewinded; ///< True if stream has been rewound after open (write path).
uint64_t last_written_block; ///< Last written block number (write path).
} aaruformatContext; } aaruformatContext;
/** \struct DumpHardwareEntriesWithData /** \struct DumpHardwareEntriesWithData

View File

@@ -307,6 +307,9 @@ void *aaruf_create(const char *filepath, const uint32_t media_type, const uint32
if(ctx->deduplicate) if(ctx->deduplicate)
ctx->sectorHashMap = create_map(ctx->userDataDdtHeader.blocks * 25 / 100); // 25% of total sectors ctx->sectorHashMap = create_map(ctx->userDataDdtHeader.blocks * 25 / 100); // 25% of total sectors
ctx->rewinded = false;
ctx->last_written_block = 0;
// Is writing // Is writing
ctx->isWriting = true; ctx->isWriting = true;

View File

@@ -146,6 +146,16 @@ int32_t aaruf_write_sector(void *context, uint64_t sector_address, bool negative
} }
// TODO: Check rewinded for disabling checksums // TODO: Check rewinded for disabling checksums
if(!ctx->rewinded)
{
if(sector_address <= ctx->last_written_block)
{
TRACE("Rewinded");
ctx->rewinded = true;
}
else
ctx->last_written_block = sector_address;
}
// TODO: If optical disc check track // TODO: If optical disc check track