mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 11:14:39 +00:00
Add const qualifiers to function parameters and local variables for improved type safety
This commit is contained in:
@@ -127,14 +127,15 @@ bool aaruf_ecc_cd_is_suffix_correct(void *context, const uint8_t *sector)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool correct_ecc_p = aaruf_ecc_cd_check(context, sector, sector, 86, 24, 2, 86, sector, 0xC, 0x10, 0x81C);
|
||||
const bool correct_ecc_p = aaruf_ecc_cd_check(context, sector, sector, 86, 24, 2, 86, sector, 0xC, 0x10, 0x81C);
|
||||
if(!correct_ecc_p)
|
||||
{
|
||||
TRACE("Exiting aaruf_ecc_cd_is_suffix_correct() = false");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool correct_ecc_q = aaruf_ecc_cd_check(context, sector, sector, 52, 43, 86, 88, sector, 0xC, 0x10, 0x81C + 0xAC);
|
||||
const bool correct_ecc_q =
|
||||
aaruf_ecc_cd_check(context, sector, sector, 52, 43, 86, 88, sector, 0xC, 0x10, 0x81C + 0xAC);
|
||||
if(!correct_ecc_q)
|
||||
{
|
||||
TRACE("Exiting aaruf_ecc_cd_is_suffix_correct() = false");
|
||||
@@ -186,13 +187,14 @@ bool aaruf_ecc_cd_is_suffix_correct_mode2(void *context, const uint8_t *sector)
|
||||
|
||||
memset(&zeroaddress, 4, sizeof(uint8_t));
|
||||
|
||||
bool correct_ecc_p = aaruf_ecc_cd_check(context, zeroaddress, sector, 86, 24, 2, 86, sector, 0, 0x10, 0x81C);
|
||||
const bool correct_ecc_p = aaruf_ecc_cd_check(context, zeroaddress, sector, 86, 24, 2, 86, sector, 0, 0x10, 0x81C);
|
||||
if(!correct_ecc_p)
|
||||
{
|
||||
TRACE("Exiting aaruf_ecc_cd_is_suffix_correct_mode2() = false");
|
||||
return false;
|
||||
}
|
||||
bool correct_ecc_q =
|
||||
|
||||
const bool correct_ecc_q =
|
||||
aaruf_ecc_cd_check(context, zeroaddress, sector, 52, 43, 86, 88, sector, 0, 0x10, 0x81C + 0xAC);
|
||||
if(!correct_ecc_q)
|
||||
{
|
||||
@@ -223,9 +225,10 @@ bool aaruf_ecc_cd_is_suffix_correct_mode2(void *context, const uint8_t *sector)
|
||||
* @param ecc_offset Offset for the ECC field.
|
||||
* @return true if ECC is correct, false otherwise.
|
||||
*/
|
||||
bool aaruf_ecc_cd_check(void *context, const uint8_t *address, const uint8_t *data, uint32_t major_count,
|
||||
uint32_t minor_count, uint32_t major_mult, uint32_t minor_inc, const uint8_t *ecc,
|
||||
int32_t address_offset, int32_t data_offset, int32_t ecc_offset)
|
||||
bool aaruf_ecc_cd_check(void *context, const uint8_t *address, const uint8_t *data, const uint32_t major_count,
|
||||
const uint32_t minor_count, const uint32_t major_mult, const uint32_t minor_inc,
|
||||
const uint8_t *ecc, const int32_t address_offset, const int32_t data_offset,
|
||||
const int32_t ecc_offset)
|
||||
{
|
||||
TRACE("Entering aaruf_ecc_cd_check(%p, %p, %p, %u, %u, %u, %u, %p, %d, %d, %d)", context, address, data,
|
||||
major_count, minor_count, major_mult, minor_inc, ecc, address_offset, data_offset, ecc_offset);
|
||||
@@ -291,9 +294,9 @@ bool aaruf_ecc_cd_check(void *context, const uint8_t *address, const uint8_t *da
|
||||
* @param data_offset Offset for the data field.
|
||||
* @param ecc_offset Offset for the ECC field.
|
||||
*/
|
||||
void aaruf_ecc_cd_write(void *context, const uint8_t *address, const uint8_t *data, uint32_t major_count,
|
||||
uint32_t minor_count, uint32_t major_mult, uint32_t minor_inc, uint8_t *ecc,
|
||||
int32_t address_offset, int32_t data_offset, int32_t ecc_offset)
|
||||
void aaruf_ecc_cd_write(void *context, const uint8_t *address, const uint8_t *data, const uint32_t major_count,
|
||||
const uint32_t minor_count, const uint32_t major_mult, const uint32_t minor_inc, uint8_t *ecc,
|
||||
const int32_t address_offset, const int32_t data_offset, const int32_t ecc_offset)
|
||||
{
|
||||
TRACE("Entering aaruf_ecc_cd_write(%p, %p, %p, %u, %u, %u, %u, %p, %d, %d, %d)", context, address, data,
|
||||
major_count, minor_count, major_mult, minor_inc, ecc, address_offset, data_offset, ecc_offset);
|
||||
@@ -353,7 +356,7 @@ void aaruf_ecc_cd_write(void *context, const uint8_t *address, const uint8_t *da
|
||||
* @param ecc_offset Offset for the ECC field.
|
||||
*/
|
||||
void aaruf_ecc_cd_write_sector(void *context, const uint8_t *address, const uint8_t *data, uint8_t *ecc,
|
||||
int32_t address_offset, int32_t data_offset, int32_t ecc_offset)
|
||||
const int32_t address_offset, const int32_t data_offset, const int32_t ecc_offset)
|
||||
{
|
||||
TRACE("Entering aaruf_ecc_cd_write_sector(%p, %p, %p, %p, %d, %d, %d)", context, address, data, ecc, address_offset,
|
||||
data_offset, ecc_offset);
|
||||
@@ -373,7 +376,7 @@ void aaruf_ecc_cd_write_sector(void *context, const uint8_t *address, const uint
|
||||
* @param second Pointer to store the second value.
|
||||
* @param frame Pointer to store the frame value.
|
||||
*/
|
||||
void aaruf_cd_lba_to_msf(int64_t pos, uint8_t *minute, uint8_t *second, uint8_t *frame)
|
||||
void aaruf_cd_lba_to_msf(const int64_t pos, uint8_t *minute, uint8_t *second, uint8_t *frame)
|
||||
{
|
||||
TRACE("Entering aaruf_cd_lba_to_msf(%lld, %p, %p, %p)", pos, minute, second, frame);
|
||||
|
||||
@@ -391,7 +394,7 @@ void aaruf_cd_lba_to_msf(int64_t pos, uint8_t *minute, uint8_t *second, uint8_t
|
||||
* @param type Track type (mode).
|
||||
* @param lba Logical Block Address.
|
||||
*/
|
||||
void aaruf_ecc_cd_reconstruct_prefix(uint8_t *sector, uint8_t type, int64_t lba)
|
||||
void aaruf_ecc_cd_reconstruct_prefix(uint8_t *sector, const uint8_t type, const int64_t lba)
|
||||
{
|
||||
TRACE("Entering aaruf_ecc_cd_reconstruct_prefix(%p, %u, %lld)", sector, type, lba);
|
||||
|
||||
@@ -458,7 +461,7 @@ void aaruf_ecc_cd_reconstruct_prefix(uint8_t *sector, uint8_t type, int64_t lba)
|
||||
* @param sector Pointer to the sector data (must be 2352 bytes).
|
||||
* @param type Track type (mode).
|
||||
*/
|
||||
void aaruf_ecc_cd_reconstruct(void *context, uint8_t *sector, uint8_t type)
|
||||
void aaruf_ecc_cd_reconstruct(void *context, uint8_t *sector, const uint8_t type)
|
||||
{
|
||||
TRACE("Entering aaruf_ecc_cd_reconstruct(%p, %p, %u)", context, sector, type);
|
||||
|
||||
|
||||
@@ -56,11 +56,11 @@ AARU_EXPORT spamsum_ctx *AARU_CALL aaruf_spamsum_init(void)
|
||||
* @param len Length of the data in bytes.
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
AARU_EXPORT int AARU_CALL aaruf_spamsum_update(spamsum_ctx *ctx, const uint8_t *data, uint32_t len)
|
||||
AARU_EXPORT int AARU_CALL aaruf_spamsum_update(spamsum_ctx *ctx, const uint8_t *data, const uint32_t len)
|
||||
{
|
||||
if(!ctx || !data) return -1;
|
||||
|
||||
for (int i = 0; i < len; i++) fuzzy_engine_step(ctx, data[i]);
|
||||
for(int i = 0; i < len; i++) fuzzy_engine_step(ctx, data[i]);
|
||||
|
||||
ctx->total_size += len;
|
||||
|
||||
@@ -88,7 +88,7 @@ AARU_LOCAL inline void fuzzy_engine_step(spamsum_ctx *ctx, uint8_t c)
|
||||
* When the rolling hash hits a reset value then we emit a normal hash
|
||||
* as a element of the signature and reset the normal hash. */
|
||||
roll_hash(ctx, c);
|
||||
uint64_t h = ROLL_SUM(ctx);
|
||||
const uint64_t h = ROLL_SUM(ctx);
|
||||
|
||||
for(i = ctx->bh_start; i < ctx->bh_end; ++i)
|
||||
{
|
||||
@@ -178,8 +178,8 @@ AARU_LOCAL inline void fuzzy_try_fork_blockhash(spamsum_ctx *ctx)
|
||||
|
||||
// assert(ctx->bh_end != 0);
|
||||
|
||||
uint32_t obh = ctx->bh_end - 1;
|
||||
uint32_t nbh = ctx->bh_end;
|
||||
const uint32_t obh = ctx->bh_end - 1;
|
||||
const uint32_t nbh = ctx->bh_end;
|
||||
ctx->bh[nbh].h = ctx->bh[obh].h;
|
||||
ctx->bh[nbh].half_h = ctx->bh[obh].half_h;
|
||||
ctx->bh[nbh].digest[0] = 0;
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
* @param length Length of the data buffer.
|
||||
* @return AARUF_STATUS_OK on success, or an error code on failure.
|
||||
*/
|
||||
int32_t aaruf_cst_transform(const uint8_t *interleaved, uint8_t *sequential, size_t length)
|
||||
int32_t aaruf_cst_transform(const uint8_t *interleaved, uint8_t *sequential, const size_t length)
|
||||
{
|
||||
uint8_t *p = NULL;
|
||||
uint8_t *q = NULL;
|
||||
@@ -190,7 +190,7 @@ int32_t aaruf_cst_transform(const uint8_t *interleaved, uint8_t *sequential, siz
|
||||
* @param length Length of the data in bytes.
|
||||
* @return AARUF_STATUS_OK on success, or an error code on failure.
|
||||
*/
|
||||
int32_t aaruf_cst_untransform(const uint8_t *sequential, uint8_t *interleaved, size_t length)
|
||||
int32_t aaruf_cst_untransform(const uint8_t *sequential, uint8_t *interleaved, const size_t length)
|
||||
{
|
||||
uint8_t *p, *q, *r, *s, *t, *u, *v, *w;
|
||||
size_t q_start;
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
* @return 0 on success, or an error code on failure.
|
||||
*/
|
||||
AARU_EXPORT int32_t AARU_CALL aaruf_lzma_decode_buffer(uint8_t *dst_buffer, size_t *dst_size, const uint8_t *src_buffer,
|
||||
size_t *src_len, const uint8_t *props, size_t props_size)
|
||||
size_t *src_len, const uint8_t *props, const size_t props_size)
|
||||
{
|
||||
return LzmaUncompress(dst_buffer, dst_size, src_buffer, src_len, props, props_size);
|
||||
}
|
||||
@@ -63,9 +63,10 @@ AARU_EXPORT int32_t AARU_CALL aaruf_lzma_decode_buffer(uint8_t *dst_buffer, size
|
||||
* @return 0 on success, or an error code on failure.
|
||||
*/
|
||||
AARU_EXPORT int32_t AARU_CALL aaruf_lzma_encode_buffer(uint8_t *dst_buffer, size_t *dst_size, const uint8_t *src_buffer,
|
||||
size_t src_len, uint8_t *out_props, size_t *out_props_size,
|
||||
int32_t level, uint32_t dict_size, int32_t lc, int32_t lp,
|
||||
int32_t pb, int32_t fb, int32_t num_threads)
|
||||
const size_t src_len, uint8_t *out_props, size_t *out_props_size,
|
||||
const int32_t level, const uint32_t dict_size, const int32_t lc,
|
||||
const int32_t lp, const int32_t pb, const int32_t fb,
|
||||
const int32_t num_threads)
|
||||
{
|
||||
return LzmaCompress(dst_buffer, dst_size, src_buffer, src_len, out_props, out_props_size, level, dict_size, lc, lp,
|
||||
pb, fb, num_threads);
|
||||
|
||||
@@ -157,7 +157,7 @@ AARU_EXPORT void AARU_CALL aaruf_crc64_free(crc64_ctx *ctx)
|
||||
if(ctx) free(ctx);
|
||||
}
|
||||
|
||||
AARU_EXPORT uint64_t AARU_CALL aaruf_crc64_data(const uint8_t *data, uint32_t len)
|
||||
AARU_EXPORT uint64_t AARU_CALL aaruf_crc64_data(const uint8_t *data, const uint32_t len)
|
||||
{
|
||||
crc64_ctx *ctx = aaruf_crc64_init();
|
||||
uint64_t crc = 0;
|
||||
|
||||
@@ -91,7 +91,7 @@ CLMUL static __m128i fold(__m128i in, __m128i fold_constants)
|
||||
* @param length Length of the data buffer in bytes.
|
||||
* @return Computed CRC64 value.
|
||||
*/
|
||||
AARU_EXPORT CLMUL uint64_t AARU_CALL aaruf_crc64_clmul(uint64_t crc, const uint8_t *data, long length)
|
||||
AARU_EXPORT CLMUL uint64_t AARU_CALL aaruf_crc64_clmul(const uint64_t crc, const uint8_t *data, long length)
|
||||
{
|
||||
TRACE("Entering aaruf_crc64_clmul(%" PRIu64 ", %p, %ld)", crc, data, length);
|
||||
|
||||
|
||||
28
src/create.c
28
src/create.c
@@ -98,10 +98,10 @@
|
||||
* @warning Application name length validation is strict - exceeding the limit will
|
||||
* cause creation failure with AARUF_ERROR_INVALID_APP_NAME_LENGTH.
|
||||
*/
|
||||
void *aaruf_create(const char *filepath, uint32_t media_type, uint32_t sector_size, uint64_t user_sectors,
|
||||
uint64_t negative_sectors, uint64_t overflow_sectors, const char *options,
|
||||
const uint8_t *application_name, uint8_t application_name_length, uint8_t application_major_version,
|
||||
uint8_t application_minor_version)
|
||||
void *aaruf_create(const char *filepath, const uint32_t media_type, const uint32_t sector_size,
|
||||
const uint64_t user_sectors, const uint64_t negative_sectors, const uint64_t overflow_sectors,
|
||||
const char *options, const uint8_t *application_name, const uint8_t application_name_length,
|
||||
const uint8_t application_major_version, const uint8_t application_minor_version)
|
||||
{
|
||||
TRACE("Entering aaruf_create(%s, %u, %u, %llu, %llu, %llu, %s, %s, %u, %u, %u)", filepath, media_type, sector_size,
|
||||
user_sectors, negative_sectors, overflow_sectors, options,
|
||||
@@ -110,7 +110,7 @@ void *aaruf_create(const char *filepath, uint32_t media_type, uint32_t sector_si
|
||||
|
||||
// Parse the options
|
||||
TRACE("Parsing options");
|
||||
aaru_options parsed_options = parse_options(options);
|
||||
const aaru_options parsed_options = parse_options(options);
|
||||
|
||||
// Allocate context
|
||||
TRACE("Allocating memory for context");
|
||||
@@ -246,20 +246,20 @@ void *aaruf_create(const char *filepath, uint32_t media_type, uint32_t sector_si
|
||||
(uint32_t *)calloc(ctx->userDataDdtHeader.entries, sizeof(uint32_t)); // All entries to zero
|
||||
|
||||
// Set the primary DDT offset (just after the header, block aligned)
|
||||
ctx->primaryDdtOffset = sizeof(AaruHeaderV2); // Start just after the header
|
||||
uint64_t alignmentMask = (1ULL << ctx->userDataDdtHeader.blockAlignmentShift) - 1;
|
||||
ctx->primaryDdtOffset = (ctx->primaryDdtOffset + alignmentMask) & ~alignmentMask;
|
||||
ctx->primaryDdtOffset = sizeof(AaruHeaderV2); // Start just after the header
|
||||
const uint64_t alignmentMask = (1ULL << ctx->userDataDdtHeader.blockAlignmentShift) - 1;
|
||||
ctx->primaryDdtOffset = (ctx->primaryDdtOffset + alignmentMask) & ~alignmentMask;
|
||||
|
||||
TRACE("Primary DDT will be placed at offset %" PRIu64, ctx->primaryDdtOffset);
|
||||
|
||||
// Calculate size of primary DDT table
|
||||
uint64_t primaryTableSize = ctx->userDataDdtHeader.sizeType == SmallDdtSizeType
|
||||
? ctx->userDataDdtHeader.entries * sizeof(uint16_t)
|
||||
: ctx->userDataDdtHeader.entries * sizeof(uint32_t);
|
||||
const uint64_t primaryTableSize = ctx->userDataDdtHeader.sizeType == SmallDdtSizeType
|
||||
? ctx->userDataDdtHeader.entries * sizeof(uint16_t)
|
||||
: ctx->userDataDdtHeader.entries * sizeof(uint32_t);
|
||||
|
||||
// Calculate where data blocks can start (after primary DDT + header)
|
||||
uint64_t dataStartPosition = ctx->primaryDdtOffset + sizeof(DdtHeader2) + primaryTableSize;
|
||||
ctx->nextBlockPosition = (dataStartPosition + alignmentMask) & ~alignmentMask;
|
||||
const uint64_t dataStartPosition = ctx->primaryDdtOffset + sizeof(DdtHeader2) + primaryTableSize;
|
||||
ctx->nextBlockPosition = (dataStartPosition + alignmentMask) & ~alignmentMask;
|
||||
|
||||
TRACE("Data blocks will start at position %" PRIu64, ctx->nextBlockPosition);
|
||||
|
||||
@@ -278,7 +278,7 @@ void *aaruf_create(const char *filepath, uint32_t media_type, uint32_t sector_si
|
||||
|
||||
// Initialize index entries array
|
||||
TRACE("Initializing index entries array");
|
||||
UT_icd index_entry_icd = {sizeof(IndexEntry), NULL, NULL, NULL};
|
||||
const UT_icd index_entry_icd = {sizeof(IndexEntry), NULL, NULL, NULL};
|
||||
utarray_new(ctx->indexEntries, &index_entry_icd);
|
||||
|
||||
if(ctx->indexEntries == NULL)
|
||||
|
||||
@@ -383,8 +383,8 @@ int32_t process_ddt_v1(aaruformatContext *ctx, IndexEntry *entry, bool *found_us
|
||||
* @warning No bounds checking is performed on sector_address. Accessing beyond the DDT table
|
||||
* boundaries will result in undefined behavior.
|
||||
*/
|
||||
int32_t decode_ddt_entry_v1(aaruformatContext *ctx, uint64_t sector_address, uint64_t *offset, uint64_t *block_offset,
|
||||
uint8_t *sector_status)
|
||||
int32_t decode_ddt_entry_v1(aaruformatContext *ctx, const uint64_t sector_address, uint64_t *offset,
|
||||
uint64_t *block_offset, uint8_t *sector_status)
|
||||
{
|
||||
TRACE("Entering decode_ddt_entry_v1(%p, %" PRIu64 ", %p, %p, %p)", ctx, sector_address, offset, block_offset,
|
||||
sector_status);
|
||||
|
||||
@@ -517,8 +517,8 @@ int32_t process_ddt_v2(aaruformatContext *ctx, IndexEntry *entry, bool *found_us
|
||||
* @warning All output parameters must be valid pointers. No bounds checking is performed
|
||||
* on the sector_address parameter at this level.
|
||||
*/
|
||||
int32_t decode_ddt_entry_v2(aaruformatContext *ctx, uint64_t sector_address, uint64_t *offset, uint64_t *block_offset,
|
||||
uint8_t *sector_status)
|
||||
int32_t decode_ddt_entry_v2(aaruformatContext *ctx, const uint64_t sector_address, uint64_t *offset,
|
||||
uint64_t *block_offset, uint8_t *sector_status)
|
||||
{
|
||||
TRACE("Entering decode_ddt_entry_v2(%p, %" PRIu64 ", %llu, %llu, %d)", ctx, sector_address, *offset, *block_offset,
|
||||
*sector_status);
|
||||
@@ -1031,8 +1031,8 @@ int32_t decode_ddt_multi_level_v2(aaruformatContext *ctx, uint64_t sector_addres
|
||||
* @return Returns one of the following status codes:
|
||||
* @retval true if the entry was set successfully, false otherwise.
|
||||
*/
|
||||
bool set_ddt_entry_v2(aaruformatContext *ctx, uint64_t sector_address, uint64_t offset, uint64_t block_offset,
|
||||
uint8_t sector_status, uint64_t *ddt_entry)
|
||||
bool set_ddt_entry_v2(aaruformatContext *ctx, const uint64_t sector_address, const uint64_t offset,
|
||||
const uint64_t block_offset, const uint8_t sector_status, uint64_t *ddt_entry)
|
||||
{
|
||||
TRACE("Entering set_ddt_entry_v2(%p, %" PRIu64 ", %llu, %llu, %d)", ctx, sector_address, offset, block_offset,
|
||||
sector_status);
|
||||
@@ -1066,8 +1066,9 @@ bool set_ddt_entry_v2(aaruformatContext *ctx, uint64_t sector_address, uint64_t
|
||||
* @return Returns one of the following status codes:
|
||||
* @retval true if the entry was set successfully, false otherwise.
|
||||
*/
|
||||
bool set_ddt_single_level_v2(aaruformatContext *ctx, uint64_t sector_address, bool negative, uint64_t offset,
|
||||
uint64_t block_offset, uint8_t sector_status, uint64_t *ddt_entry)
|
||||
bool set_ddt_single_level_v2(aaruformatContext *ctx, uint64_t sector_address, const bool negative,
|
||||
const uint64_t offset, const uint64_t block_offset, const uint8_t sector_status,
|
||||
uint64_t *ddt_entry)
|
||||
{
|
||||
TRACE("Entering set_ddt_single_level_v2(%p, %" PRIu64 ", %llu, %llu, %d)", ctx, sector_address, offset,
|
||||
block_offset, sector_status);
|
||||
@@ -1096,7 +1097,7 @@ bool set_ddt_single_level_v2(aaruformatContext *ctx, uint64_t sector_address, bo
|
||||
|
||||
if(*ddt_entry == 0)
|
||||
{
|
||||
uint64_t block_index = block_offset >> ctx->userDataDdtHeader.blockAlignmentShift;
|
||||
const uint64_t block_index = block_offset >> ctx->userDataDdtHeader.blockAlignmentShift;
|
||||
*ddt_entry =
|
||||
offset & ((1ULL << ctx->userDataDdtHeader.dataShift) - 1) | block_index << ctx->userDataDdtHeader.dataShift;
|
||||
}
|
||||
@@ -1688,8 +1689,8 @@ bool set_ddt_multi_level_v2(aaruformatContext *ctx, uint64_t sector_address, boo
|
||||
if(*ddt_entry == 0)
|
||||
{
|
||||
block_index = block_offset >> ctx->userDataDdtHeader.blockAlignmentShift;
|
||||
*ddt_entry = offset & (1ULL << ctx->userDataDdtHeader.dataShift) - 1 | block_index
|
||||
<< ctx->userDataDdtHeader.dataShift;
|
||||
*ddt_entry = offset & (1ULL << ctx->userDataDdtHeader.dataShift) - 1 | block_index
|
||||
<< ctx->userDataDdtHeader.dataShift;
|
||||
|
||||
if(ctx->userDataDdtHeader.sizeType == SmallDdtSizeType)
|
||||
{
|
||||
|
||||
@@ -89,7 +89,7 @@ int aaruf_identify(const char *filename)
|
||||
|
||||
if(stream == NULL) return errno;
|
||||
|
||||
int ret = aaruf_identify_stream(stream);
|
||||
const int ret = aaruf_identify_stream(stream);
|
||||
|
||||
fclose(stream);
|
||||
|
||||
@@ -164,7 +164,7 @@ int aaruf_identify_stream(FILE *image_stream)
|
||||
|
||||
AaruHeader header;
|
||||
|
||||
size_t ret = fread(&header, sizeof(AaruHeader), 1, image_stream);
|
||||
const size_t ret = fread(&header, sizeof(AaruHeader), 1, image_stream);
|
||||
|
||||
if(ret != 1) return 0;
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ UT_array *process_index_v1(aaruformatContext *ctx)
|
||||
if(ctx == NULL || ctx->imageStream == NULL) return NULL;
|
||||
|
||||
// Initialize the index entries array
|
||||
UT_icd index_entry_icd = {sizeof(IndexEntry), NULL, NULL, NULL};
|
||||
const UT_icd index_entry_icd = {sizeof(IndexEntry), NULL, NULL, NULL};
|
||||
|
||||
utarray_new(index_entries, &index_entry_icd);
|
||||
|
||||
|
||||
@@ -84,10 +84,10 @@ UT_array *process_index_v2(aaruformatContext *ctx)
|
||||
UT_array *index_entries = NULL;
|
||||
IndexEntry entry;
|
||||
|
||||
if(ctx == NULL || ctx->imageStream == NULL) {return NULL;}
|
||||
if(ctx == NULL || ctx->imageStream == NULL) { return NULL; }
|
||||
|
||||
// Initialize the index entries array
|
||||
UT_icd index_entry_icd = {sizeof(IndexEntry), NULL, NULL, NULL};
|
||||
const UT_icd index_entry_icd = {sizeof(IndexEntry), NULL, NULL, NULL};
|
||||
|
||||
utarray_new(index_entries, &index_entry_icd);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ UT_array *process_index_v3(aaruformatContext *ctx)
|
||||
if(ctx == NULL || ctx->imageStream == NULL) return NULL;
|
||||
|
||||
// Initialize the index entries array
|
||||
UT_icd index_entry_icd = {sizeof(IndexEntry), NULL, NULL, NULL};
|
||||
const UT_icd index_entry_icd = {sizeof(IndexEntry), NULL, NULL, NULL};
|
||||
|
||||
utarray_new(index_entries, &index_entry_icd);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ void add_to_cache(struct CacheHeader *cache, const char *key, void *value)
|
||||
}
|
||||
}
|
||||
|
||||
FORCE_INLINE char *uint64_to_string(uint64_t number)
|
||||
FORCE_INLINE char *uint64_to_string(const uint64_t number)
|
||||
{
|
||||
char *char_key = malloc(17); // 16 hex digits + null terminator
|
||||
if(!char_key) return NULL;
|
||||
@@ -85,7 +85,7 @@ FORCE_INLINE char *uint64_to_string(uint64_t number)
|
||||
* @param key 64-bit integer key to search for.
|
||||
* @return Pointer to the value if found, or NULL if not found.
|
||||
*/
|
||||
void *find_in_cache_uint64(struct CacheHeader *cache, uint64_t key)
|
||||
void *find_in_cache_uint64(struct CacheHeader *cache, const uint64_t key)
|
||||
{
|
||||
return find_in_cache(cache, uint64_to_string(key));
|
||||
}
|
||||
@@ -99,7 +99,7 @@ void *find_in_cache_uint64(struct CacheHeader *cache, uint64_t key)
|
||||
* @param key 64-bit integer key to add.
|
||||
* @param value Pointer to the value to store.
|
||||
*/
|
||||
void add_to_cache_uint64(struct CacheHeader *cache, uint64_t key, void *value)
|
||||
void add_to_cache_uint64(struct CacheHeader *cache, const uint64_t key, void *value)
|
||||
{
|
||||
return add_to_cache(cache, uint64_to_string(key), value);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ aaru_options parse_options(const char *options)
|
||||
const char *key = token;
|
||||
const char *value = equal + 1;
|
||||
|
||||
bool bval = strncmp(value, "true", 4) == 0;
|
||||
const bool bval = strncmp(value, "true", 4) == 0;
|
||||
|
||||
if(strncmp(key, "compress", 8) == 0)
|
||||
parsed.compress = bval;
|
||||
|
||||
27
src/read.c
27
src/read.c
@@ -82,7 +82,7 @@
|
||||
* @warning Media tag data is stored as-is from the original medium. No format
|
||||
* conversion or validation is performed on the tag content.
|
||||
*/
|
||||
int32_t aaruf_read_media_tag(void *context, uint8_t *data, int32_t tag, uint32_t *length)
|
||||
int32_t aaruf_read_media_tag(void *context, uint8_t *data, const int32_t tag, uint32_t *length)
|
||||
{
|
||||
TRACE("Entering aaruf_read_media_tag(%p, %p, %d, %u)", context, data, tag, *length);
|
||||
|
||||
@@ -238,7 +238,7 @@ int32_t aaruf_read_media_tag(void *context, uint8_t *data, int32_t tag, uint32_t
|
||||
* @warning Sector addresses are zero-based. The maximum valid address is
|
||||
* ctx->imageInfo.Sectors - 1.
|
||||
*/
|
||||
int32_t aaruf_read_sector(void *context, uint64_t sector_address, uint8_t *data, uint32_t *length)
|
||||
int32_t aaruf_read_sector(void *context, const uint64_t sector_address, uint8_t *data, uint32_t *length)
|
||||
{
|
||||
TRACE("Entering aaruf_read_sector(%p, %" PRIu64 ", %p, %u)", context, sector_address, data, *length);
|
||||
|
||||
@@ -601,7 +601,8 @@ int32_t aaruf_read_sector(void *context, uint64_t sector_address, uint8_t *data,
|
||||
* @warning Track sequence numbers may not be contiguous. Always verify track
|
||||
* existence before assuming a track number is valid.
|
||||
*/
|
||||
int32_t aaruf_read_track_sector(void *context, uint8_t *data, uint64_t sector_address, uint32_t *length, uint8_t track)
|
||||
int32_t aaruf_read_track_sector(void *context, uint8_t *data, const uint64_t sector_address, uint32_t *length,
|
||||
const uint8_t track)
|
||||
{
|
||||
TRACE("Entering aaruf_read_track_sector(%p, %p, %" PRIu64 ", %u, %d)", context, data, sector_address, *length,
|
||||
track);
|
||||
@@ -744,18 +745,18 @@ int32_t aaruf_read_track_sector(void *context, uint8_t *data, uint64_t sector_ad
|
||||
* @warning Not all AaruFormat images contain the metadata necessary for long sector
|
||||
* reading. Some images may only support basic sector reading via aaruf_read_sector().
|
||||
*/
|
||||
int32_t aaruf_read_sector_long(void *context, uint64_t sector_address, uint8_t *data, uint32_t *length)
|
||||
int32_t aaruf_read_sector_long(void *context, const uint64_t sector_address, uint8_t *data, uint32_t *length)
|
||||
{
|
||||
TRACE("Entering aaruf_read_sector_long(%p, %" PRIu64 ", %p, %u)", context, sector_address, data, *length);
|
||||
|
||||
aaruformatContext *ctx = NULL;
|
||||
uint32_t bare_length = 0;
|
||||
uint32_t tag_length = 0;
|
||||
uint8_t *bare_data = NULL;
|
||||
int32_t res = 0;
|
||||
TrackEntry trk;
|
||||
int i = 0;
|
||||
bool trk_found = false;
|
||||
const aaruformatContext *ctx = NULL;
|
||||
uint32_t bare_length = 0;
|
||||
uint32_t tag_length = 0;
|
||||
uint8_t *bare_data = NULL;
|
||||
int32_t res = 0;
|
||||
TrackEntry trk;
|
||||
int i = 0;
|
||||
bool trk_found = false;
|
||||
|
||||
if(context == NULL)
|
||||
{
|
||||
@@ -821,7 +822,7 @@ int32_t aaruf_read_sector_long(void *context, uint64_t sector_address, uint8_t *
|
||||
if(sector_address >= ctx->dataTracks[i].start && sector_address <= ctx->dataTracks[i].end)
|
||||
{
|
||||
trk_found = true;
|
||||
trk = ctx->dataTracks[i];
|
||||
trk = ctx->dataTracks[i];
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ extern "C"
|
||||
#define CRC32_ISO_POLY 0xEDB88320
|
||||
#define CRC32_ISO_SEED 0xFFFFFFFF
|
||||
|
||||
uint32_t crc32_data(const uint8_t *data, uint32_t len)
|
||||
uint32_t crc32_data(const uint8_t *data, const uint32_t len)
|
||||
{
|
||||
uint32_t localHashInt = CRC32_ISO_SEED;
|
||||
uint32_t localTable[256];
|
||||
|
||||
@@ -31,8 +31,9 @@ int printhex(unsigned char *array, unsigned int length, int width, bool color)
|
||||
int read_long(unsigned long long sector_no, const char *path);
|
||||
int verify(const char *path);
|
||||
int verify_sectors(const char *path);
|
||||
bool check_cd_sector_channel(CdEccContext *context, uint8_t *sector, bool *unknown, bool *has_edc, bool *edc_correct,
|
||||
bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q, bool *ecc_q_correct);
|
||||
bool check_cd_sector_channel(CdEccContext *context, const uint8_t *sector, bool *unknown, bool *has_edc,
|
||||
bool *edc_correct, bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q,
|
||||
bool *ecc_q_correct);
|
||||
int compare(const char *path1, const char *path2);
|
||||
int cli_compare(const char *path1, const char *path2);
|
||||
int convert(const char *input_path, const char *output_path);
|
||||
|
||||
@@ -110,9 +110,9 @@ int cli_compare(const char *path1, const char *path2)
|
||||
read_result2 = aaruf_read_sector(ctx2, sector, buffer2, &buffer2_length);
|
||||
|
||||
// Handle read errors or missing sectors
|
||||
bool sector1_available = (read_result1 == AARUF_STATUS_OK);
|
||||
bool sector2_available = (read_result2 == AARUF_STATUS_OK);
|
||||
bool sectors_different = false;
|
||||
const bool sector1_available = (read_result1 == AARUF_STATUS_OK);
|
||||
const bool sector2_available = (read_result2 == AARUF_STATUS_OK);
|
||||
bool sectors_different = false;
|
||||
|
||||
if(!sector1_available && !sector2_available)
|
||||
{
|
||||
@@ -149,7 +149,7 @@ int cli_compare(const char *path1, const char *path2)
|
||||
// Update progress every 1000 sectors or at the end
|
||||
if(sectors_processed % 1000 == 0 || sector == total_sectors - 1)
|
||||
{
|
||||
int progress = (int)((sectors_processed * 100) / total_sectors);
|
||||
const int progress = (int)((sectors_processed * 100) / total_sectors);
|
||||
printf("Progress: %d%% (%llu/%llu sectors)\r", progress, (unsigned long long)sectors_processed,
|
||||
(unsigned long long)total_sectors);
|
||||
fflush(stdout);
|
||||
|
||||
@@ -39,7 +39,7 @@ int cmd_identify(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = identify(filename->sval[0]);
|
||||
const int result = identify(filename->sval[0]);
|
||||
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
|
||||
return result;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ int cmd_info(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = info(filename->sval[0]);
|
||||
const int result = info(filename->sval[0]);
|
||||
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
|
||||
return result;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ int cmd_compare(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = compare(filename1->sval[0], filename2->sval[0]);
|
||||
const int result = compare(filename1->sval[0], filename2->sval[0]);
|
||||
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
|
||||
return result;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ int cmd_cli_compare(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = cli_compare(filename1->sval[0], filename2->sval[0]);
|
||||
const int result = cli_compare(filename1->sval[0], filename2->sval[0]);
|
||||
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
|
||||
return result;
|
||||
}
|
||||
@@ -118,7 +118,8 @@ int cmd_read_common(int argc, char *argv[], bool long_mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = long_mode ? read_long(sector->ival[0], filename->sval[0]) : read(sector->ival[0], filename->sval[0]);
|
||||
const int result =
|
||||
long_mode ? read_long(sector->ival[0], filename->sval[0]) : read(sector->ival[0], filename->sval[0]);
|
||||
|
||||
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
|
||||
return result;
|
||||
@@ -142,7 +143,7 @@ int cmd_verify_common(int argc, char *argv[], bool sectors_mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = sectors_mode ? verify_sectors(filename->sval[0]) : verify(filename->sval[0]);
|
||||
const int result = sectors_mode ? verify_sectors(filename->sval[0]) : verify(filename->sval[0]);
|
||||
|
||||
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
|
||||
return result;
|
||||
@@ -167,7 +168,7 @@ int cmd_convert(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
int result = convert(input_filename->sval[0], output_filename->sval[0]);
|
||||
const int result = convert(input_filename->sval[0], output_filename->sval[0]);
|
||||
arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
|
||||
void draw_progress_bar(int row, int percent)
|
||||
{
|
||||
int width = tb_width() / 2;
|
||||
int bar_width = width - 4; // leave space for borders
|
||||
int filled = (bar_width * percent) / 100;
|
||||
const int width = tb_width() / 2;
|
||||
const int bar_width = width - 4; // leave space for borders
|
||||
const int filled = (bar_width * percent) / 100;
|
||||
|
||||
// Draw progress bar outline
|
||||
tb_printf(2, row, TB_YELLOW | TB_BOLD, TB_BLUE, "[");
|
||||
|
||||
@@ -22,11 +22,12 @@
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
bool check_cd_sector_channel(CdEccContext *context, uint8_t *sector, bool *unknown, bool *has_edc, bool *edc_correct,
|
||||
bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q, bool *ecc_q_correct)
|
||||
bool check_cd_sector_channel(CdEccContext *context, const uint8_t *sector, bool *unknown, bool *has_edc,
|
||||
bool *edc_correct, bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q,
|
||||
bool *ecc_q_correct)
|
||||
{
|
||||
uint32_t storedEdc = 0, edc = 0, calculatedEdc = 0;
|
||||
int size = 0, pos = 0;
|
||||
int size = 0, pos = 0;
|
||||
uint8_t zeroaddress[4];
|
||||
|
||||
*has_edc = false;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "aaruformattool.h"
|
||||
|
||||
int read(unsigned long long sector_no, const char *path)
|
||||
int read(const unsigned long long sector_no, const char *path)
|
||||
{
|
||||
aaruformatContext *ctx = NULL;
|
||||
int32_t res = 0;
|
||||
@@ -76,7 +76,7 @@ int read(unsigned long long sector_no, const char *path)
|
||||
return AARUF_STATUS_OK;
|
||||
}
|
||||
|
||||
int read_long(unsigned long long sector_no, const char *path)
|
||||
int read_long(const unsigned long long sector_no, const char *path)
|
||||
{
|
||||
aaruformatContext *ctx = NULL;
|
||||
int32_t res = 0;
|
||||
|
||||
Reference in New Issue
Block a user