diff --git a/include/aaruformat/context.h b/include/aaruformat/context.h index 7664359..c6e7d49 100644 --- a/include/aaruformat/context.h +++ b/include/aaruformat/context.h @@ -158,7 +158,7 @@ typedef struct aaruformatContext /* Optical auxiliary buffers (NULL if not present) */ uint8_t *sector_prefix; ///< Raw per-sector prefix (e.g., sync+header) uncorrected. uint8_t *sectorPrefixCorrected; ///< Corrected variant (post error correction) if stored. - uint8_t *sectorSuffix; ///< Raw per-sector suffix (EDC/ECC) uncorrected. + uint8_t *sector_suffix; ///< Raw per-sector suffix (EDC/ECC) uncorrected. uint8_t *sectorSuffixCorrected; ///< Corrected suffix if stored separately. uint8_t *sectorSubchannel; ///< Raw 96-byte subchannel (if captured). uint8_t *mode2_subheaders; ///< MODE2 Form1/Form2 8-byte subheaders (concatenated). @@ -232,11 +232,10 @@ typedef struct aaruformatContext uint8_t currentTrackType; ///< Current track type (when writing optical images with tracks, needed for block ///< compression type). bool writingLong; ///< True if writing long sectors - uint8_t *sectorSuffixBuffer; ///< Buffer for storing sector suffixes when writing optical images - size_t sector_prefix_length; ///< Length of sectorPrefixBuffer - size_t sectorSuffixBufferLength; ///< Length of sectorSuffixBuffer - size_t sector_prefix_offset; ///< Current position in sectorPrefixBuffer - size_t sectorSuffixBufferOffset; ///< Current position in sectorSuffixBuffer + size_t sector_prefix_length; ///< Length of sector_prefix + size_t sector_suffix_length; ///< Length of sector_suffix + size_t sector_prefix_offset; ///< Current position in sector_prefix + size_t sector_suffix_offset; ///< Current position in sector_suffix } aaruformatContext; /** \struct DumpHardwareEntriesWithData diff --git a/src/blocks/data.c b/src/blocks/data.c index 99a1063..1eea095 100644 --- a/src/blocks/data.c +++ b/src/blocks/data.c @@ -315,7 +315,7 @@ int32_t process_data_block(aaruformatContext *ctx, IndexEntry *entry) if(entry->dataType == CdSectorSuffixCorrected) ctx->sectorSuffixCorrected = data; else - ctx->sectorSuffix = data; + ctx->sector_suffix = data; ctx->readableSectorTags[CdSectorSubHeader] = true; ctx->readableSectorTags[CdSectorEcc] = true; diff --git a/src/close.c b/src/close.c index 8133bdd..19b199d 100644 --- a/src/close.c +++ b/src/close.c @@ -499,7 +499,7 @@ static void write_checksum_block(aaruformatContext *ctx) bool has_checksums = ctx->checksums.hasMd5 || ctx->checksums.hasSha1 || ctx->checksums.hasSha256 || ctx->checksums.hasSpamSum || ctx->checksums.hasBlake3; - if(!has_checksums) return ; + if(!has_checksums) return; ChecksumHeader checksum_header = {0}; checksum_header.identifier = ChecksumBlock; @@ -607,7 +607,7 @@ static void write_checksum_block(aaruformatContext *ctx) static void write_tracks_block(aaruformatContext *ctx) { // Write tracks block - if(ctx->tracksHeader.entries <= 0 || ctx->trackEntries == NULL) return ; + if(ctx->tracksHeader.entries <= 0 || ctx->trackEntries == NULL) return; fseek(ctx->imageStream, 0, SEEK_END); long tracks_position = ftell(ctx->imageStream); @@ -659,7 +659,7 @@ static void write_tracks_block(aaruformatContext *ctx) static void write_mode2_subheaders_block(aaruformatContext *ctx) { // Write MODE 2 subheader data block - if(ctx->mode2_subheaders == NULL) return ; + if(ctx->mode2_subheaders == NULL) return; fseek(ctx->imageStream, 0, SEEK_END); long mode2_subheaders_position = ftell(ctx->imageStream); @@ -916,8 +916,10 @@ static int32_t write_index_block(aaruformatContext *ctx) * @param context Opaque pointer returned by earlier open/create calls (must be an aaruformatContext). * @return 0 on success; -1 or negative libaaruformat error code on failure. * @retval 0 All pending data flushed (if writing) and resources released successfully. - * @retval -1 Invalid context pointer or initial header rewrite failure (errno = EINVAL or AARUF_ERROR_CANNOT_WRITE_HEADER). - * @retval AARUF_ERROR_CANNOT_WRITE_HEADER A later write helper (e.g., index, DDT) failed and returned this code directly. + * @retval -1 Invalid context pointer or initial header rewrite failure (errno = EINVAL or + * AARUF_ERROR_CANNOT_WRITE_HEADER). + * @retval AARUF_ERROR_CANNOT_WRITE_HEADER A later write helper (e.g., index, DDT) failed and returned this code + * directly. * @retval Propagated from a write helper if future helpers add more error codes. * @note On success the context memory itself is freed; the caller must not reuse the pointer. */ @@ -1027,8 +1029,8 @@ int aaruf_close(void *context) ctx->sector_prefix = NULL; free(ctx->sectorPrefixCorrected); ctx->sectorPrefixCorrected = NULL; - free(ctx->sectorSuffix); - ctx->sectorSuffix = NULL; + free(ctx->sector_suffix); + ctx->sector_suffix = NULL; free(ctx->sectorSuffixCorrected); ctx->sectorSuffixCorrected = NULL; free(ctx->sectorSubchannel); diff --git a/src/read.c b/src/read.c index 86a6930..c802680 100644 --- a/src/read.c +++ b/src/read.c @@ -827,7 +827,7 @@ int32_t aaruf_read_sector_long(void *context, const uint64_t sector_address, boo TRACE("Exiting aaruf_read_sector_long() = AARUF_ERROR_BUFFER_TOO_SMALL"); return AARUF_ERROR_BUFFER_TOO_SMALL; } - if((ctx->sectorSuffix == NULL || ctx->sector_prefix == NULL) && + if((ctx->sector_suffix == NULL || ctx->sector_prefix == NULL) && (ctx->sectorSuffixCorrected == NULL || ctx->sectorPrefixCorrected == NULL)) return aaruf_read_sector(context, sector_address, negative, data, length); @@ -907,8 +907,8 @@ int32_t aaruf_read_sector_long(void *context, const uint64_t sector_address, boo if(res != AARUF_STATUS_OK) return res; - if(ctx->sectorSuffix != NULL) - memcpy(data + 2064, ctx->sectorSuffix + corrected_sector_address * 288, 288); + if(ctx->sector_suffix != NULL) + memcpy(data + 2064, ctx->sector_suffix + corrected_sector_address * 288, 288); else if(ctx->sectorSuffixDdt != NULL) { if((ctx->sectorSuffixDdt[corrected_sector_address] & CD_XFIX_MASK) == Correct) diff --git a/src/write.c b/src/write.c index 41b2f18..e5e047e 100644 --- a/src/write.c +++ b/src/write.c @@ -589,14 +589,13 @@ int32_t aaruf_write_sector_long(void *context, uint64_t sector_address, bool neg } } - if(ctx->sectorSuffixBuffer == NULL) + if(ctx->sector_suffix == NULL) { - ctx->sectorSuffixBufferLength = - 288 * (ctx->userDataDdtHeader.negative + ctx->imageInfo.Sectors + - ctx->userDataDdtHeader.overflow); - ctx->sectorSuffixBuffer = malloc(ctx->sectorSuffixBufferLength); + ctx->sector_suffix_length = 288 * (ctx->userDataDdtHeader.negative + ctx->imageInfo.Sectors + + ctx->userDataDdtHeader.overflow); + ctx->sector_suffix = malloc(ctx->sector_suffix_length); - if(ctx->sectorSuffixBuffer == NULL) + if(ctx->sector_suffix == NULL) { FATAL("Could not allocate memory for CD sector suffix buffer"); @@ -672,19 +671,19 @@ int32_t aaruf_write_sector_long(void *context, uint64_t sector_address, bool neg else { // Copy CD suffix from data buffer to suffix buffer - memcpy(ctx->sectorSuffixBuffer + ctx->sectorSuffixBufferOffset, data + 2064, 288); + memcpy(ctx->sector_suffix + ctx->sector_suffix_offset, data + 2064, 288); ctx->sectorSuffixDdtMini[corrected_sector_address] = - (uint16_t)(ctx->sectorSuffixBufferOffset / 288); + (uint16_t)(ctx->sector_suffix_offset / 288); ctx->sectorSuffixDdtMini[corrected_sector_address] |= SectorStatusErrored << 12; - ctx->sectorSuffixBufferOffset += 288; + ctx->sector_suffix_offset += 288; // Grow suffix buffer if needed - if(ctx->sectorSuffixBufferOffset >= ctx->sectorSuffixBufferLength) + if(ctx->sector_suffix_offset >= ctx->sector_suffix_length) { - ctx->sectorSuffixBufferLength *= 2; - ctx->sectorSuffixBuffer = realloc(ctx->sectorSuffixBuffer, ctx->sectorSuffixBufferLength); + ctx->sector_suffix_length *= 2; + ctx->sector_suffix = realloc(ctx->sector_suffix, ctx->sector_suffix_length); - if(ctx->sectorSuffixBuffer == NULL) + if(ctx->sector_suffix == NULL) { FATAL("Could not allocate memory for CD sector suffix buffer"); @@ -746,14 +745,13 @@ int32_t aaruf_write_sector_long(void *context, uint64_t sector_address, bool neg } } - if(ctx->sectorSuffixBuffer == NULL) + if(ctx->sector_suffix == NULL) { - ctx->sectorSuffixBufferLength = - 288 * (ctx->userDataDdtHeader.negative + ctx->imageInfo.Sectors + - ctx->userDataDdtHeader.overflow); - ctx->sectorSuffixBuffer = malloc(ctx->sectorSuffixBufferLength); + ctx->sector_suffix_length = 288 * (ctx->userDataDdtHeader.negative + ctx->imageInfo.Sectors + + ctx->userDataDdtHeader.overflow); + ctx->sector_suffix = malloc(ctx->sector_suffix_length); - if(ctx->sectorSuffixBuffer == NULL) + if(ctx->sector_suffix == NULL) { FATAL("Could not allocate memory for CD sector suffix buffer"); @@ -853,20 +851,19 @@ int32_t aaruf_write_sector_long(void *context, uint64_t sector_address, bool neg else { // Copy CD suffix from data buffer to suffix buffer - memcpy(ctx->sectorSuffixBuffer + ctx->sectorSuffixBufferOffset, data + 2348, 4); + memcpy(ctx->sector_suffix + ctx->sector_suffix_offset, data + 2348, 4); ctx->sectorSuffixDdtMini[corrected_sector_address] = - (uint16_t)(ctx->sectorSuffixBufferOffset / 288); + (uint16_t)(ctx->sector_suffix_offset / 288); ctx->sectorSuffixDdtMini[corrected_sector_address] |= SectorStatusErrored << 12; - ctx->sectorSuffixBufferOffset += 288; + ctx->sector_suffix_offset += 288; // Grow suffix buffer if needed - if(ctx->sectorSuffixBufferOffset >= ctx->sectorSuffixBufferLength) + if(ctx->sector_suffix_offset >= ctx->sector_suffix_length) { - ctx->sectorSuffixBufferLength *= 2; - ctx->sectorSuffixBuffer = - realloc(ctx->sectorSuffixBuffer, ctx->sectorSuffixBufferLength); + ctx->sector_suffix_length *= 2; + ctx->sector_suffix = realloc(ctx->sector_suffix, ctx->sector_suffix_length); - if(ctx->sectorSuffixBuffer == NULL) + if(ctx->sector_suffix == NULL) { FATAL("Could not allocate memory for CD sector suffix buffer"); @@ -895,19 +892,19 @@ int32_t aaruf_write_sector_long(void *context, uint64_t sector_address, bool neg else { // Copy CD suffix from data buffer to suffix buffer - memcpy(ctx->sectorSuffixBuffer + ctx->sectorSuffixBufferOffset, data + 2072, 280); + memcpy(ctx->sector_suffix + ctx->sector_suffix_offset, data + 2072, 280); ctx->sectorSuffixDdtMini[corrected_sector_address] = - (uint16_t)(ctx->sectorSuffixBufferOffset / 288); + (uint16_t)(ctx->sector_suffix_offset / 288); ctx->sectorSuffixDdtMini[corrected_sector_address] |= SectorStatusErrored << 12; - ctx->sectorSuffixBufferOffset += 288; + ctx->sector_suffix_offset += 288; // Grow suffix buffer if needed - if(ctx->sectorSuffixBufferOffset >= ctx->sectorSuffixBufferLength) + if(ctx->sector_suffix_offset >= ctx->sector_suffix_length) { - ctx->sectorSuffixBufferLength *= 2; - ctx->sectorSuffixBuffer = realloc(ctx->sectorSuffixBuffer, ctx->sectorSuffixBufferLength); + ctx->sector_suffix_length *= 2; + ctx->sector_suffix = realloc(ctx->sector_suffix, ctx->sector_suffix_length); - if(ctx->sectorSuffixBuffer == NULL) + if(ctx->sector_suffix == NULL) { FATAL("Could not allocate memory for CD sector suffix buffer"); diff --git a/tool/info.c b/tool/info.c index a43723b..96081fc 100644 --- a/tool/info.c +++ b/tool/info.c @@ -69,7 +69,7 @@ int info(const char *path) if(ctx->sectorPrefixCorrected != NULL) printf("Sector prefix corrected array has been read.\n"); - if(ctx->sectorSuffix != NULL) printf("Sector suffix array has been read.\n"); + if(ctx->sector_suffix != NULL) printf("Sector suffix array has been read.\n"); if(ctx->sectorSuffixCorrected != NULL) printf("Sector suffix corrected array has been read.\n");