mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Update DDT entry documentation to indicate 64-bit values
This commit is contained in:
@@ -93,11 +93,11 @@ typedef struct DdtHeader
|
||||
* secondaryIndex = I % itemsPerPrimaryEntry
|
||||
* The primary table entry at primaryIndex yields a secondary DDT file offset (scaled by 2^blockAlignmentShift),
|
||||
* whose table entries are then indexed by secondaryIndex.
|
||||
* 3. Read raw DDT entry value E (16-bit if sizeType == SmallDdtSizeType, 32-bit if BigDdtSizeType).
|
||||
* 3. Read raw DDT entry value E (64-bit).
|
||||
* 4. If E == 0: sector_status = SectorStatusNotDumped; offset=block_offset=0.
|
||||
* Otherwise extract:
|
||||
* statusBits = E >> 12 (small) or E >> 28 (big)
|
||||
* baseBits = E & 0x0FFF (small) or E & 0x0FFFFFFF (big)
|
||||
* statusBits = E >> 60
|
||||
* baseBits = E & 0xFFFFFFFFFFFFFFF
|
||||
* sectorOffsetWithinBlock = baseBits & ((1 << dataShift) - 1)
|
||||
* blockIndex = baseBits >> dataShift
|
||||
* block_offset (bytes) = blockIndex << blockAlignmentShift
|
||||
|
||||
@@ -378,7 +378,6 @@ int32_t aaruf_get_tracks(const void *context, uint8_t *buffer, size_t *length)
|
||||
* @retval AARUF_ERROR_NOT_ENOUGH_MEMORY Memory allocation failed while copying tracks.
|
||||
*
|
||||
* @warning Not thread-safe. Do not invoke concurrently with readers/writers of the same context.
|
||||
* @warning Counts above 65535 will be truncated to 16-bit without error (potential data loss of extra entries).
|
||||
* @note After success, aaruf_get_tracks() can be used to read back the stored table.
|
||||
* @see aaruf_get_tracks()
|
||||
*
|
||||
|
||||
15
src/close.c
15
src/close.c
@@ -1183,16 +1183,14 @@ static void write_sector_suffix(aaruformat_context *ctx)
|
||||
* index into the stored 16‑byte prefix capture buffer plus a 4-bit status code. It is written only
|
||||
* if at least one prefix status or captured prefix was recorded (i.e., the in-memory DDT array exists).
|
||||
*
|
||||
* Encoding (current implementation uses the "mini" 16-bit form):
|
||||
* Bits 15..12 : SectorStatus enum value (see enums.h, values already positioned for v2 mini layout).
|
||||
* Bits 11..0 : 12-bit index (0..4095) of the 16-byte prefix chunk inside the CdSectorPrefix data block,
|
||||
* Encoding:
|
||||
* Bits 63..61 : SectorStatus enum value (see enums.h, values already positioned for v2 layout).
|
||||
* Bits 60..0 : Index of the 16-byte prefix chunk inside the CdSectorPrefix data block,
|
||||
* or 0 when no external prefix bytes were stored (status applies to a generated/implicit prefix).
|
||||
*
|
||||
* Notes:
|
||||
* - Unlike DDT v1, there are no CD_XFIX_MASK / CD_DFIX_MASK macros used here. The bit layout is compact
|
||||
* and directly encoded when writing (status values are pre-shifted where needed in write.c).
|
||||
* - Only the 16-bit mini variant is currently produced (sectorPrefixDdt2). A 32-bit form is reserved
|
||||
* for future expansion (sectorPrefixDdt) but is not emitted unless populated.
|
||||
* - The table length equals (negative + Sectors + overflow) * entrySize.
|
||||
* - dataShift is set to 4 (2^4 = 16) expressing the granularity of referenced prefix units.
|
||||
* - Compression is applied if enabled; crc64/cmpCrc64 protect the raw table bytes.
|
||||
@@ -1318,14 +1316,13 @@ static void write_sector_prefix_ddt(aaruformat_context *ctx)
|
||||
* the in-memory mini entry records the index of its 16 * 18 (288) byte chunk. If no suffix bytes
|
||||
* were explicitly stored for a sector the index field is zero and only the status applies.
|
||||
*
|
||||
* Encoding (mini 16-bit variant only, DDT v2 semantics):
|
||||
* Bits 15..12 : SectorStatus enumeration (already aligned for direct storage; no legacy masks used).
|
||||
* Bits 11..0 : 12-bit index (0..4095) referencing a suffix unit of size 288 bytes (2^dataShift granularity),
|
||||
* Encoding (DDT v2 semantics):
|
||||
* Bits 63..61 : SectorStatus enumeration (already aligned for direct storage; no legacy masks used).
|
||||
* Bits 60..0 : Index referencing a suffix unit of size 288 bytes (2^dataShift granularity),
|
||||
* or 0 when the sector uses an implicit / regenerated suffix (no external data captured).
|
||||
*
|
||||
* Characteristics & constraints:
|
||||
* - Only DDT v2 is supported here; no fallback or mixed-mode emission with v1 occurs.
|
||||
* - Only the compact "mini" (16-bit) table form is currently produced (sectorSuffixDdt2 filled during write).
|
||||
* - Table length = (negative + total Sectors + overflow) * sizeof(uint16_t).
|
||||
* - dataShift mirrors userDataDdtHeader.dataShift (expressing granularity for index referencing).
|
||||
* - Single-level table (levels = 1, tableLevel = 0, tableShift = 0).
|
||||
|
||||
@@ -135,8 +135,6 @@ static void cleanup_failed_create(aaruformat_context *ctx)
|
||||
* The function automatically selects optimal DDT parameters:
|
||||
* - Single-level DDT (tableShift=0): For images < 138,412,552 sectors
|
||||
* - Multi-level DDT (tableShift=22): For images ≥ 138,412,552 sectors
|
||||
* - Small entries (16-bit): Default, supports most image sizes efficiently
|
||||
* - Big entries (32-bit): Reserved for future use with very large images
|
||||
*
|
||||
* The DDT offset calculation ensures proper alignment:
|
||||
* - Primary DDT placed immediately after header (block-aligned)
|
||||
@@ -233,7 +231,6 @@ static void cleanup_failed_create(aaruformat_context *ctx)
|
||||
*
|
||||
* @note DDT Initialization (Block Media Only):
|
||||
* - Uses DDT version 2 format with configurable compression and alignment
|
||||
* - Supports both small (16-bit) and big (32-bit) DDT entry sizes
|
||||
* - Calculates optimal table sizes based on sector counts and shift parameters
|
||||
* - All DDT entries are initialized to zero (indicating unallocated sectors)
|
||||
* - Multi-level DDT is used for images with ≥ 138,412,552 total sectors
|
||||
|
||||
@@ -73,7 +73,6 @@
|
||||
* - The found_user_data_ddt flag is updated to reflect the success of user data DDT loading
|
||||
*
|
||||
* @note DDT v2 Features:
|
||||
* - Supports both small (16-bit) and big (32-bit) DDT entry sizes
|
||||
* - Handles multi-level DDT hierarchies with tableShift parameter
|
||||
* - Updates context with sector counts, DDT version, and primary DDT offset
|
||||
* - Stores DDT data in size-appropriate context fields (userDataDdtMini/Big, sectorPrefixDdt, etc.)
|
||||
@@ -530,8 +529,7 @@ int32_t decode_ddt_entry_v2(aaruformat_context *ctx, const uint64_t sector_addre
|
||||
*
|
||||
* Used when the DDT table does not use multi-level indirection (tableShift = 0). This function
|
||||
* performs direct lookup in the primary DDT table to extract sector offset, block offset, and
|
||||
* sector status information. It handles both small (16-bit) and big (32-bit) DDT entry formats
|
||||
* and performs bit manipulation to decode the packed DDT entry values.
|
||||
* sector status information. It performs bit manipulation to decode the packed DDT entry values.
|
||||
*
|
||||
* @param ctx Pointer to the aaruformat context containing the loaded DDT table.
|
||||
* @param sector_address Logical sector address to decode (adjusted for negative sectors).
|
||||
@@ -556,17 +554,12 @@ int32_t decode_ddt_entry_v2(aaruformat_context *ctx, const uint64_t sector_addre
|
||||
* - The DDT size type is unknown/unsupported (not SmallDdtSizeType or BigDdtSizeType)
|
||||
* - Internal consistency checks fail
|
||||
*
|
||||
* @note DDT Entry Decoding (Small DDT - 16-bit entries):
|
||||
* - Bits 15-12: Sector status (4 bits)
|
||||
* - Bits 11-0: Combined offset and block index (12 bits)
|
||||
* @note DDT Entry Decoding
|
||||
* - Bits 63-61: Sector status (4 bits)
|
||||
* - Bits 60-0: Combined offset and block index (60 bits)
|
||||
* - Offset mask: Derived from dataShift parameter
|
||||
* - Block offset: Calculated using blockAlignmentShift parameter
|
||||
*
|
||||
* @note DDT Entry Decoding (Big DDT - 32-bit entries):
|
||||
* - Bits 31-28: Sector status (4 bits)
|
||||
* - Bits 27-0: Combined offset and block index (28 bits)
|
||||
* - Offset mask and block offset calculated same as small DDT
|
||||
*
|
||||
* @note Negative Sector Handling:
|
||||
* - Sector address is automatically adjusted by adding ctx->userDataDdtHeader.negative
|
||||
* - This allows proper indexing into the DDT table for negative sector addresses
|
||||
@@ -708,7 +701,6 @@ int32_t decode_ddt_single_level_v2(aaruformat_context *ctx, uint64_t sector_addr
|
||||
* @note Secondary DDT Processing:
|
||||
* - Supports both LZMA compression and uncompressed formats
|
||||
* - Performs full CRC64 validation of secondary DDT data
|
||||
* - Handles both small (16-bit) and big (32-bit) entry formats
|
||||
* - Same bit manipulation as single-level DDT for final entry decoding
|
||||
*
|
||||
* @note Error Handling Strategy:
|
||||
|
||||
@@ -370,9 +370,9 @@ int32_t aaruf_write_sector(void *context, uint64_t sector_address, bool negative
|
||||
* 8. **User Data Delegation**: Calls aaruf_write_sector() with extracted user data and derived status
|
||||
*
|
||||
* **Memory Management Strategy:**
|
||||
* - **Mini-DDT Arrays**: Lazily allocated 16-bit arrays sized for total addressable space (negative + user + overflow)
|
||||
* * sectorPrefixDdt2: Tracks prefix status and buffer offsets (high 4 bits = status, low 12 bits = offset/16)
|
||||
* * sectorSuffixDdt2: Tracks suffix status and buffer offsets (high 4 bits = status, low 12 bits = offset/288)
|
||||
* - **DDT Arrays**: Lazily allocated 64-bit arrays sized for total addressable space (negative + user + overflow)
|
||||
* * sectorPrefixDdt2: Tracks prefix status and buffer offsets (high 4 bits = status, low 60 bits = offset/16)
|
||||
* * sectorSuffixDdt2: Tracks suffix status and buffer offsets (high 4 bits = status, low 60 bits = offset/288)
|
||||
* - **Prefix Buffer**: Dynamically growing buffer storing non-standard 16-byte CD prefixes
|
||||
* - **Suffix Buffer**: Dynamically growing buffer storing non-standard CD suffixes (288 bytes for Mode 1, 4 bytes for
|
||||
* Mode 2 Form 2, 280 bytes for Mode 2 Form 1)
|
||||
|
||||
Reference in New Issue
Block a user