diff --git a/include/aaruformat/context.h b/include/aaruformat/context.h index 1aea459..1856df3 100644 --- a/include/aaruformat/context.h +++ b/include/aaruformat/context.h @@ -209,6 +209,9 @@ typedef struct aaruformatContext UT_array *indexEntries; ///< Flattened index entries (UT_array of IndexEntry). hash_map_t *sectorHashMap; ///< Deduplication hash map (fingerprint->entry mapping). 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; /** \struct DumpHardwareEntriesWithData diff --git a/src/create.c b/src/create.c index f70a0c8..63d18eb 100644 --- a/src/create.c +++ b/src/create.c @@ -307,6 +307,9 @@ void *aaruf_create(const char *filepath, const uint32_t media_type, const uint32 if(ctx->deduplicate) ctx->sectorHashMap = create_map(ctx->userDataDdtHeader.blocks * 25 / 100); // 25% of total sectors + ctx->rewinded = false; + ctx->last_written_block = 0; + // Is writing ctx->isWriting = true; diff --git a/src/write.c b/src/write.c index dd7a6ce..b87b37e 100644 --- a/src/write.c +++ b/src/write.c @@ -146,6 +146,16 @@ int32_t aaruf_write_sector(void *context, uint64_t sector_address, bool negative } // 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