Namespace functions.

This commit is contained in:
2022-05-28 12:01:55 +01:00
parent d529a9631c
commit 660682bbd2
10 changed files with 107 additions and 107 deletions

View File

@@ -72,41 +72,41 @@
#define FORCE_INLINE static inline __attribute__((always_inline)) #define FORCE_INLINE static inline __attribute__((always_inline))
#endif #endif
AARU_EXPORT int AARU_CALL identify(const char* filename); AARU_EXPORT int AARU_CALL aaruf_identify(const char* filename);
AARU_EXPORT int AARU_CALL identifyStream(FILE* imageStream); AARU_EXPORT int AARU_CALL aaruf_identify_stream(FILE* imageStream);
AARU_EXPORT void* AARU_CALL open(const char* filepath); AARU_EXPORT void* AARU_CALL aaruf_open(const char* filepath);
AARU_EXPORT int AARU_CALL close(void* context); AARU_EXPORT int AARU_CALL aaruf_close(void* context);
AARU_EXPORT int32_t AARU_CALL read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t* length); AARU_EXPORT int32_t AARU_CALL aaruf_read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t* length);
AARU_EXPORT void* AARU_CALL crc64_init(uint64_t polynomial, uint64_t seed); AARU_EXPORT void* AARU_CALL aaruf_crc64_init(uint64_t polynomial, uint64_t seed);
AARU_EXPORT void* AARU_CALL crc64_init_ecma(void); AARU_EXPORT void* AARU_CALL aaruf_crc64_init_ecma(void);
AARU_EXPORT void AARU_CALL crc64_update(void* context, const uint8_t* data, size_t len); AARU_EXPORT void AARU_CALL aaruf_crc64_update(void* context, const uint8_t* data, size_t len);
AARU_EXPORT uint64_t AARU_CALL crc64_final(void* context); AARU_EXPORT uint64_t AARU_CALL aaruf_crc64_final(void* context);
AARU_EXPORT uint64_t AARU_CALL crc64_data(const uint8_t* data, size_t len, uint64_t polynomial, uint64_t seed); AARU_EXPORT uint64_t AARU_CALL aaruf_crc64_data(const uint8_t* data, size_t len, uint64_t polynomial, uint64_t seed);
AARU_EXPORT uint64_t AARU_CALL crc64_data_ecma(const uint8_t* data, size_t len); AARU_EXPORT uint64_t AARU_CALL aaruf_crc64_data_ecma(const uint8_t* data, size_t len);
AARU_EXPORT int32_t AARU_CALL read_sector(void* context, uint64_t sectorAddress, uint8_t* data, uint32_t* length); AARU_EXPORT int32_t AARU_CALL aaruf_read_sector(void* context, uint64_t sectorAddress, uint8_t* data, uint32_t* length);
AARU_EXPORT int32_t AARU_CALL cst_transform(const uint8_t* interleaved, uint8_t* sequential, size_t length); AARU_EXPORT int32_t AARU_CALL aaruf_cst_transform(const uint8_t* interleaved, uint8_t* sequential, size_t length);
AARU_EXPORT int32_t AARU_CALL cst_untransform(const uint8_t* sequential, uint8_t* interleaved, size_t length); AARU_EXPORT int32_t AARU_CALL aaruf_cst_untransform(const uint8_t* sequential, uint8_t* interleaved, size_t length);
AARU_LOCAL void* AARU_CALL ecc_cd_init(); AARU_EXPORT void* AARU_CALL aaruf_ecc_cd_init();
AARU_EXPORT bool AARU_CALL ecc_cd_is_suffix_correct(void* context, const uint8_t* sector); AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_is_suffix_correct(void* context, const uint8_t* sector);
AARU_EXPORT bool AARU_CALL ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector); AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector);
AARU_EXPORT bool AARU_CALL ecc_cd_check(void* context, AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_check(void* context,
const uint8_t* address, const uint8_t* address,
const uint8_t* data, const uint8_t* data,
uint32_t majorCount, uint32_t majorCount,
@@ -118,7 +118,7 @@ AARU_EXPORT bool AARU_CALL ecc_cd_check(void* context,
int32_t dataOffset, int32_t dataOffset,
int32_t eccOffset); int32_t eccOffset);
AARU_EXPORT void AARU_CALL ecc_cd_write(void* context, AARU_EXPORT void AARU_CALL aaruf_ecc_cd_write(void* context,
const uint8_t* address, const uint8_t* address,
const uint8_t* data, const uint8_t* data,
uint32_t majorCount, uint32_t majorCount,
@@ -130,7 +130,7 @@ AARU_EXPORT void AARU_CALL ecc_cd_write(void* context,
int32_t dataOffset, int32_t dataOffset,
int32_t eccOffset); int32_t eccOffset);
AARU_EXPORT void AARU_CALL ecc_cd_write_sector(void* context, AARU_EXPORT void AARU_CALL aaruf_ecc_cd_write_sector(void* context,
const uint8_t* address, const uint8_t* address,
const uint8_t* data, const uint8_t* data,
uint8_t* ecc, uint8_t* ecc,
@@ -138,19 +138,19 @@ AARU_EXPORT void AARU_CALL ecc_cd_write_sector(void* context,
int32_t dataOffset, int32_t dataOffset,
int32_t eccOffset); int32_t eccOffset);
AARU_LOCAL void AARU_CALL cd_lba_to_msf(int64_t pos, uint8_t* minute, uint8_t* second, uint8_t* frame); AARU_LOCAL void AARU_CALL aaruf_cd_lba_to_msf(int64_t pos, uint8_t* minute, uint8_t* second, uint8_t* frame);
AARU_EXPORT void AARU_CALL ecc_cd_reconstruct_prefix(uint8_t* sector, uint8_t type, int64_t lba); AARU_EXPORT void AARU_CALL aaruf_ecc_cd_reconstruct_prefix(uint8_t* sector, uint8_t type, int64_t lba);
AARU_EXPORT void AARU_CALL ecc_cd_reconstruct(void* context, uint8_t* sector, uint8_t type); AARU_EXPORT void AARU_CALL aaruf_ecc_cd_reconstruct(void* context, uint8_t* sector, uint8_t type);
AARU_EXPORT uint32_t AARU_CALL edc_cd_compute(void* context, uint32_t edc, const uint8_t* src, int size, int pos); AARU_EXPORT uint32_t AARU_CALL aaruf_edc_cd_compute(void* context, uint32_t edc, const uint8_t* src, int size, int pos);
AARU_EXPORT int32_t AARU_CALL AARU_EXPORT int32_t AARU_CALL
read_track_sector(void* context, uint8_t* data, uint64_t sectorAddress, uint32_t* length, uint8_t track); aaruf_read_track_sector(void* context, uint8_t* data, uint64_t sectorAddress, uint32_t* length, uint8_t track);
AARU_LOCAL int32_t AARU_CALL GetMediaTagTypeForDataType(int32_t type); AARU_LOCAL int32_t AARU_CALL aaruf_get_media_tag_type_for_datatype(int32_t type);
AARU_LOCAL int32_t AARU_CALL GetXmlMediaType(int32_t type); AARU_LOCAL int32_t AARU_CALL aaruf_get_xml_mediatype(int32_t type);
#endif // LIBAARUFORMAT_DECLS_H #endif // LIBAARUFORMAT_DECLS_H

View File

@@ -36,7 +36,7 @@
#include <stdio.h> #include <stdio.h>
#include <sys/mman.h> #include <sys/mman.h>
int close(void* context) int aaruf_close(void* context)
{ {
int i; int i;

View File

@@ -35,7 +35,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
void* crc64_init(uint64_t polynomial, uint64_t seed) void* aaruf_crc64_init(uint64_t polynomial, uint64_t seed)
{ {
Crc64Context* ctx; Crc64Context* ctx;
int i, j; int i, j;
@@ -64,9 +64,9 @@ void* crc64_init(uint64_t polynomial, uint64_t seed)
return ctx; return ctx;
} }
void* crc64_init_ecma(void) { return crc64_init(CRC64_ECMA_POLY, CRC64_ECMA_SEED); } void* aaruf_crc64_init_ecma(void) { return aaruf_crc64_init(CRC64_ECMA_POLY, CRC64_ECMA_SEED); }
void crc64_update(void* context, const uint8_t* data, size_t len) void aaruf_crc64_update(void* context, const uint8_t* data, size_t len)
{ {
Crc64Context* ctx = context; Crc64Context* ctx = context;
size_t i; size_t i;
@@ -74,14 +74,14 @@ void crc64_update(void* context, const uint8_t* data, size_t len)
for(i = 0; i < len; i++) ctx->hashInt = (ctx->hashInt >> 8) ^ ctx->table[data[i] ^ (ctx->hashInt & 0xFF)]; for(i = 0; i < len; i++) ctx->hashInt = (ctx->hashInt >> 8) ^ ctx->table[data[i] ^ (ctx->hashInt & 0xFF)];
} }
uint64_t crc64_final(void* context) uint64_t aaruf_crc64_final(void* context)
{ {
Crc64Context* ctx = context; Crc64Context* ctx = context;
return ctx->hashInt ^ ctx->finalSeed; return ctx->hashInt ^ ctx->finalSeed;
} }
uint64_t crc64_data(const uint8_t* data, size_t len, uint64_t polynomial, uint64_t seed) uint64_t aaruf_crc64_data(const uint8_t* data, size_t len, uint64_t polynomial, uint64_t seed)
{ {
uint64_t table[256]; uint64_t table[256];
uint64_t hashInt = seed; uint64_t hashInt = seed;
@@ -105,7 +105,7 @@ uint64_t crc64_data(const uint8_t* data, size_t len, uint64_t polynomial, uint64
return hashInt ^ seed; return hashInt ^ seed;
} }
uint64_t crc64_data_ecma(const uint8_t* data, size_t len) uint64_t aaruf_crc64_data_ecma(const uint8_t* data, size_t len)
{ {
return crc64_data(data, len, CRC64_ECMA_POLY, CRC64_ECMA_SEED); return aaruf_crc64_data(data, len, CRC64_ECMA_POLY, CRC64_ECMA_SEED);
} }

View File

@@ -35,7 +35,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
int32_t cst_transform(const uint8_t* interleaved, uint8_t* sequential, size_t length) int32_t aaruf_cst_transform(const uint8_t* interleaved, uint8_t* sequential, size_t length)
{ {
uint8_t *p, *q, *r, *s, *t, *u, *v, *w; uint8_t *p, *q, *r, *s, *t, *u, *v, *w;
size_t qStart; size_t qStart;
@@ -169,7 +169,7 @@ int32_t cst_transform(const uint8_t* interleaved, uint8_t* sequential, size_t le
return AARUF_STATUS_OK; return AARUF_STATUS_OK;
} }
int32_t cst_untransform(const uint8_t* sequential, uint8_t* interleaved, size_t length) int32_t aaruf_cst_untransform(const uint8_t* sequential, uint8_t* interleaved, size_t length)
{ {
uint8_t *p, *q, *r, *s, *t, *u, *v, *w; uint8_t *p, *q, *r, *s, *t, *u, *v, *w;
size_t qStart; size_t qStart;

View File

@@ -37,7 +37,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
void* ecc_cd_init() void* aaruf_ecc_cd_init()
{ {
CdEccContext* context; CdEccContext* context;
uint32_t edc, i, j; uint32_t edc, i, j;
@@ -87,7 +87,7 @@ void* ecc_cd_init()
return context; return context;
} }
bool ecc_cd_is_suffix_correct(void* context, const uint8_t* sector) bool aaruf_ecc_cd_is_suffix_correct(void* context, const uint8_t* sector)
{ {
CdEccContext* ctx; CdEccContext* ctx;
uint32_t storedEdc, edc, calculatedEdc; uint32_t storedEdc, edc, calculatedEdc;
@@ -105,10 +105,10 @@ bool ecc_cd_is_suffix_correct(void* context, const uint8_t* sector)
sector[0x819] != 0x00 || sector[0x81A] != 0x00 || sector[0x81B] != 0x00) sector[0x819] != 0x00 || sector[0x81A] != 0x00 || sector[0x81B] != 0x00)
return false; return false;
bool correctEccP = ecc_cd_check(context, sector, sector, 86, 24, 2, 86, sector, 0xC, 0x10, 0x81C); bool correctEccP = aaruf_ecc_cd_check(context, sector, sector, 86, 24, 2, 86, sector, 0xC, 0x10, 0x81C);
if(!correctEccP) return false; if(!correctEccP) return false;
bool correctEccQ = ecc_cd_check(context, sector, sector, 52, 43, 86, 88, sector, 0xC, 0x10, 0x81C + 0xAC); bool correctEccQ = aaruf_ecc_cd_check(context, sector, sector, 52, 43, 86, 88, sector, 0xC, 0x10, 0x81C + 0xAC);
if(!correctEccQ) return false; if(!correctEccQ) return false;
storedEdc = sector[0x810]; // TODO: Check casting storedEdc = sector[0x810]; // TODO: Check casting
@@ -121,7 +121,7 @@ bool ecc_cd_is_suffix_correct(void* context, const uint8_t* sector)
return calculatedEdc == storedEdc; return calculatedEdc == storedEdc;
} }
bool ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector) bool aaruf_ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector)
{ {
CdEccContext* ctx; CdEccContext* ctx;
uint32_t storedEdc, edc, calculatedEdc; uint32_t storedEdc, edc, calculatedEdc;
@@ -136,10 +136,10 @@ bool ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector)
memset(&zeroaddress, 4, sizeof(uint8_t)); memset(&zeroaddress, 4, sizeof(uint8_t));
bool correctEccP = ecc_cd_check(context, zeroaddress, sector, 86, 24, 2, 86, sector, 0, 0x10, 0x81C); bool correctEccP = aaruf_ecc_cd_check(context, zeroaddress, sector, 86, 24, 2, 86, sector, 0, 0x10, 0x81C);
if(!correctEccP) return false; if(!correctEccP) return false;
bool correctEccQ = ecc_cd_check(context, zeroaddress, sector, 52, 43, 86, 88, sector, 0, 0x10, 0x81C + 0xAC); bool correctEccQ = aaruf_ecc_cd_check(context, zeroaddress, sector, 52, 43, 86, 88, sector, 0, 0x10, 0x81C + 0xAC);
if(!correctEccQ) return false; if(!correctEccQ) return false;
storedEdc = sector[0x818]; // TODO: Check cast storedEdc = sector[0x818]; // TODO: Check cast
@@ -152,7 +152,7 @@ bool ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector)
return calculatedEdc == storedEdc; return calculatedEdc == storedEdc;
} }
bool ecc_cd_check(void* context, bool aaruf_ecc_cd_check(void* context,
const uint8_t* address, const uint8_t* address,
const uint8_t* data, const uint8_t* data,
uint32_t majorCount, uint32_t majorCount,
@@ -197,7 +197,7 @@ bool ecc_cd_check(void* context,
return true; return true;
} }
void ecc_cd_write(void* context, void aaruf_ecc_cd_write(void* context,
const uint8_t* address, const uint8_t* address,
const uint8_t* data, const uint8_t* data,
uint32_t majorCount, uint32_t majorCount,
@@ -242,7 +242,7 @@ void ecc_cd_write(void* context,
} }
} }
void ecc_cd_write_sector(void* context, void aaruf_ecc_cd_write_sector(void* context,
const uint8_t* address, const uint8_t* address,
const uint8_t* data, const uint8_t* data,
uint8_t* ecc, uint8_t* ecc,
@@ -250,18 +250,18 @@ void ecc_cd_write_sector(void* context,
int32_t dataOffset, int32_t dataOffset,
int32_t eccOffset) int32_t eccOffset)
{ {
ecc_cd_write(context, address, data, 86, 24, 2, 86, ecc, addressOffset, dataOffset, eccOffset); // P aaruf_ecc_cd_write(context, address, data, 86, 24, 2, 86, ecc, addressOffset, dataOffset, eccOffset); // P
ecc_cd_write(context, address, data, 52, 43, 86, 88, ecc, addressOffset, dataOffset, eccOffset + 0xAC); // Q aaruf_ecc_cd_write(context, address, data, 52, 43, 86, 88, ecc, addressOffset, dataOffset, eccOffset + 0xAC); // Q
} }
void cd_lba_to_msf(int64_t pos, uint8_t* minute, uint8_t* second, uint8_t* frame) void aaruf_cd_lba_to_msf(int64_t pos, uint8_t* minute, uint8_t* second, uint8_t* frame)
{ {
*minute = (uint8_t)((pos + 150) / 75 / 60); *minute = (uint8_t)((pos + 150) / 75 / 60);
*second = (uint8_t)((pos + 150) / 75 % 60); *second = (uint8_t)((pos + 150) / 75 % 60);
*frame = (uint8_t)((pos + 150) % 75); *frame = (uint8_t)((pos + 150) % 75);
} }
void ecc_cd_reconstruct_prefix(uint8_t* sector, // must point to a full 2352-byte sector void aaruf_ecc_cd_reconstruct_prefix(uint8_t* sector, // must point to a full 2352-byte sector
uint8_t type, uint8_t type,
int64_t lba) int64_t lba)
{ {
@@ -285,7 +285,7 @@ void ecc_cd_reconstruct_prefix(uint8_t* sector, // must point to a full 2352-byt
sector[0x00A] = 0xFF; sector[0x00A] = 0xFF;
sector[0x00B] = 0x00; sector[0x00B] = 0x00;
cd_lba_to_msf(lba, &minute, &second, &frame); aaruf_cd_lba_to_msf(lba, &minute, &second, &frame);
sector[0x00C] = (uint8_t)(((minute / 10) << 4) + minute % 10); sector[0x00C] = (uint8_t)(((minute / 10) << 4) + minute % 10);
sector[0x00D] = (uint8_t)(((second / 10) << 4) + second % 10); sector[0x00D] = (uint8_t)(((second / 10) << 4) + second % 10);
@@ -318,7 +318,7 @@ void ecc_cd_reconstruct_prefix(uint8_t* sector, // must point to a full 2352-byt
} }
} }
void ecc_cd_reconstruct(void* context, void aaruf_ecc_cd_reconstruct(void* context,
uint8_t* sector, // must point to a full 2352-byte sector uint8_t* sector, // must point to a full 2352-byte sector
uint8_t type) uint8_t type)
{ {
@@ -339,15 +339,15 @@ void ecc_cd_reconstruct(void* context,
// Compute EDC // Compute EDC
// //
case CdMode1: case CdMode1:
computedEdc = edc_cd_compute(context, 0, sector, 0x810, 0); computedEdc = aaruf_edc_cd_compute(context, 0, sector, 0x810, 0);
memcpy(sector + 0x810, &computedEdc, 4); memcpy(sector + 0x810, &computedEdc, 4);
break; break;
case CdMode2Form1: case CdMode2Form1:
computedEdc = edc_cd_compute(context, 0, sector, 0x808, 0x10); computedEdc = aaruf_edc_cd_compute(context, 0, sector, 0x808, 0x10);
memcpy(sector + 0x818, &computedEdc, 4); memcpy(sector + 0x818, &computedEdc, 4);
break; break;
case CdMode2Form2: case CdMode2Form2:
computedEdc = edc_cd_compute(context, 0, sector, 0x91C, 0x10); computedEdc = aaruf_edc_cd_compute(context, 0, sector, 0x91C, 0x10);
memcpy(sector + 0x92C, &computedEdc, 4); memcpy(sector + 0x92C, &computedEdc, 4);
break; break;
default: return; default: return;
@@ -372,9 +372,9 @@ void ecc_cd_reconstruct(void* context,
sector[0x819] = 0x00; sector[0x819] = 0x00;
sector[0x81A] = 0x00; sector[0x81A] = 0x00;
sector[0x81B] = 0x00; sector[0x81B] = 0x00;
ecc_cd_write_sector(context, sector, sector, sector, 0xC, 0x10, 0x81C); aaruf_ecc_cd_write_sector(context, sector, sector, sector, 0xC, 0x10, 0x81C);
break; break;
case CdMode2Form1: ecc_cd_write_sector(context, zeroaddress, sector, sector, 0, 0x10, 0x81C); break; case CdMode2Form1: aaruf_ecc_cd_write_sector(context, zeroaddress, sector, sector, 0, 0x10, 0x81C); break;
default: return; default: return;
} }
@@ -383,7 +383,7 @@ void ecc_cd_reconstruct(void* context,
// //
} }
uint32_t edc_cd_compute(void* context, uint32_t edc, const uint8_t* src, int size, int pos) uint32_t aaruf_edc_cd_compute(void* context, uint32_t edc, const uint8_t* src, int size, int pos)
{ {
CdEccContext* ctx; CdEccContext* ctx;

View File

@@ -34,7 +34,7 @@
#include <aaruformat.h> #include <aaruformat.h>
// Converts between image data type and aaru media tag type // Converts between image data type and aaru media tag type
int32_t GetMediaTagTypeForDataType(int32_t type) int32_t aaruf_get_media_tag_type_for_datatype(int32_t type)
{ {
switch(type) switch(type)
{ {
@@ -112,7 +112,7 @@ int32_t GetMediaTagTypeForDataType(int32_t type)
} }
// Get the CICM XML media type from AARU media type // Get the CICM XML media type from AARU media type
int32_t GetXmlMediaType(int32_t type) int32_t aaruf_get_xml_mediatype(int32_t type)
{ {
switch(type) switch(type)
{ {

View File

@@ -37,11 +37,11 @@
//! Identifies a file as aaruformat, using path //! Identifies a file as aaruformat, using path
/*! /*!
* *
* @param filename path to the file to identify * @param filename path to the file to aaruf_identify
* @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file. * @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file.
* If negative, error value * If negative, error value
*/ */
int identify(const char* filename) int aaruf_identify(const char* filename)
{ {
FILE* stream; FILE* stream;
@@ -49,7 +49,7 @@ int identify(const char* filename)
if(stream == NULL) return errno; if(stream == NULL) return errno;
int ret = identifyStream(stream); int ret = aaruf_identify_stream(stream);
fclose(stream); fclose(stream);
@@ -59,11 +59,11 @@ int identify(const char* filename)
//! Identifies a file as aaruformat, using an already existing stream //! Identifies a file as aaruformat, using an already existing stream
/*! /*!
* *
* @param imageStream stream of the file to identify * @param imageStream stream of the file to aaruf_identify
* @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file. * @return If positive, confidence value, with 100 being maximum confidentiality, and 0 not recognizing the file.
* If negative, error value * If negative, error value
*/ */
int identifyStream(FILE* imageStream) int aaruf_identify_stream(FILE* imageStream)
{ {
fseek(imageStream, 0, SEEK_SET); fseek(imageStream, 0, SEEK_SET);

View File

@@ -38,7 +38,7 @@
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
void* open(const char* filepath) void* aaruf_open(const char* filepath)
{ {
aaruformatContext* ctx; aaruformatContext* ctx;
int errorNo; int errorNo;
@@ -290,7 +290,7 @@ void* open(const char* filepath)
break; break;
} }
crc64 = crc64_data_ecma(data, blockHeader.length); crc64 = aaruf_crc64_data_ecma(data, blockHeader.length);
if(crc64 != blockHeader.crc64) if(crc64 != blockHeader.crc64)
{ {
fprintf(stderr, fprintf(stderr,
@@ -373,7 +373,7 @@ void* open(const char* filepath)
} }
memset(mediaTag, 0, sizeof(dataLinkedList)); memset(mediaTag, 0, sizeof(dataLinkedList));
mediaTag->type = GetMediaTagTypeForDataType(blockHeader.type); mediaTag->type = aaruf_get_media_tag_type_for_datatype(blockHeader.type);
mediaTag->data = data; mediaTag->data = data;
mediaTag->length = blockHeader.length; mediaTag->length = blockHeader.length;
@@ -759,8 +759,8 @@ void* open(const char* filepath)
fprintf(stderr, "libaaruformat: Could not read metadata block, continuing..."); fprintf(stderr, "libaaruformat: Could not read metadata block, continuing...");
} }
crc64 = crc64 = aaruf_crc64_data_ecma((const uint8_t*)ctx->trackEntries,
crc64_data_ecma((const uint8_t*)ctx->trackEntries, ctx->tracksHeader.entries * sizeof(TrackEntry)); ctx->tracksHeader.entries * sizeof(TrackEntry));
if(crc64 != ctx->tracksHeader.crc64) if(crc64 != ctx->tracksHeader.crc64)
{ {
fprintf(stderr, fprintf(stderr,
@@ -874,7 +874,7 @@ void* open(const char* filepath)
if(readBytes == ctx->dumpHardwareHeader.length) if(readBytes == ctx->dumpHardwareHeader.length)
{ {
crc64 = crc64_data_ecma(data, ctx->dumpHardwareHeader.length); crc64 = aaruf_crc64_data_ecma(data, ctx->dumpHardwareHeader.length);
if(crc64 != ctx->dumpHardwareHeader.crc64) if(crc64 != ctx->dumpHardwareHeader.crc64)
{ {
free(data); free(data);
@@ -1143,13 +1143,13 @@ void* open(const char* filepath)
if(!foundUserDataDdt) if(!foundUserDataDdt)
{ {
fprintf(stderr, "libaaruformat: Could not find user data deduplication table, aborting..."); fprintf(stderr, "libaaruformat: Could not find user data deduplication table, aborting...");
close(ctx); aaruf_close(ctx);
return NULL; return NULL;
} }
ctx->imageInfo.CreationTime = ctx->header.creationTime; ctx->imageInfo.CreationTime = ctx->header.creationTime;
ctx->imageInfo.LastModificationTime = ctx->header.lastWrittenTime; ctx->imageInfo.LastModificationTime = ctx->header.lastWrittenTime;
ctx->imageInfo.XmlMediaType = GetXmlMediaType(ctx->header.mediaType); ctx->imageInfo.XmlMediaType = aaruf_get_xml_mediatype(ctx->header.mediaType);
if(ctx->geometryBlock.identifier != GeometryBlock && ctx->imageInfo.XmlMediaType == BlockMedia) if(ctx->geometryBlock.identifier != GeometryBlock && ctx->imageInfo.XmlMediaType == BlockMedia)
{ {
@@ -1170,7 +1170,7 @@ void* open(const char* filepath)
// TODO: Cache tracks and sessions? // TODO: Cache tracks and sessions?
// Initialize ECC for Compact Disc // Initialize ECC for Compact Disc
ctx->eccCdContext = (CdEccContext*)ecc_cd_init(); ctx->eccCdContext = (CdEccContext*)aaruf_ecc_cd_init();
ctx->magic = AARU_MAGIC; ctx->magic = AARU_MAGIC;
ctx->libraryMajorVersion = LIBAARUFORMAT_MAJOR_VERSION; ctx->libraryMajorVersion = LIBAARUFORMAT_MAJOR_VERSION;

View File

@@ -34,7 +34,7 @@
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
int32_t 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, int32_t tag, uint32_t* length)
{ {
aaruformatContext* ctx; aaruformatContext* ctx;
dataLinkedList* item; dataLinkedList* item;
@@ -69,7 +69,7 @@ int32_t read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t* leng
return AARUF_ERROR_MEDIA_TAG_NOT_PRESENT; return AARUF_ERROR_MEDIA_TAG_NOT_PRESENT;
} }
int32_t read_sector(void* context, uint64_t sectorAddress, uint8_t* data, uint32_t* length) int32_t aaruf_read_sector(void* context, uint64_t sectorAddress, uint8_t* data, uint32_t* length)
{ {
aaruformatContext* ctx; aaruformatContext* ctx;
uint64_t ddtEntry; uint64_t ddtEntry;
@@ -148,7 +148,7 @@ int32_t read_sector(void* context, uint64_t sectorAddress, uint8_t* data, uint32
return AARUF_STATUS_OK; return AARUF_STATUS_OK;
} }
int32_t read_track_sector(void* context, uint8_t* data, uint64_t sectorAddress, uint32_t* length, uint8_t track) int32_t aaruf_read_track_sector(void* context, uint8_t* data, uint64_t sectorAddress, uint32_t* length, uint8_t track)
{ {
aaruformatContext* ctx; aaruformatContext* ctx;
int i; int i;
@@ -165,7 +165,7 @@ int32_t read_track_sector(void* context, uint8_t* data, uint64_t sectorAddress,
for(i = 0; i < ctx->numberOfDataTracks; i++) for(i = 0; i < ctx->numberOfDataTracks; i++)
{ {
if(ctx->dataTracks[i].sequence == track) if(ctx->dataTracks[i].sequence == track)
{ return read_sector(context, ctx->dataTracks[i].start + sectorAddress, data, length); } { return aaruf_read_sector(context, ctx->dataTracks[i].start + sectorAddress, data, length); }
} }
return AARUF_ERROR_TRACK_NOT_FOUND; return AARUF_ERROR_TRACK_NOT_FOUND;
@@ -199,16 +199,16 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
} }
if((ctx->sectorSuffix == NULL || ctx->sectorPrefix == NULL) && if((ctx->sectorSuffix == NULL || ctx->sectorPrefix == NULL) &&
(ctx->sectorSuffixCorrected == NULL || ctx->sectorPrefixCorrected == NULL)) (ctx->sectorSuffixCorrected == NULL || ctx->sectorPrefixCorrected == NULL))
return read_sector(context, sectorAddress, data, length); return aaruf_read_sector(context, sectorAddress, data, length);
bareLength = 0; bareLength = 0;
read_sector(context, sectorAddress, NULL, &bareLength); aaruf_read_sector(context, sectorAddress, NULL, &bareLength);
bareData = (uint8_t*)malloc(bareLength); bareData = (uint8_t*)malloc(bareLength);
if(bareData == NULL) return AARUF_ERROR_NOT_ENOUGH_MEMORY; if(bareData == NULL) return AARUF_ERROR_NOT_ENOUGH_MEMORY;
res = read_sector(context, sectorAddress, bareData, &bareLength); res = aaruf_read_sector(context, sectorAddress, bareData, &bareLength);
if(res < AARUF_STATUS_OK) return res; if(res < AARUF_STATUS_OK) return res;
@@ -239,7 +239,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
{ {
if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct) if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
{ {
ecc_cd_reconstruct_prefix(data, trk.type, sectorAddress); aaruf_ecc_cd_reconstruct_prefix(data, trk.type, sectorAddress);
res = AARUF_STATUS_OK; res = AARUF_STATUS_OK;
} }
else if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == NotDumped) else if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == NotDumped)
@@ -263,7 +263,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
{ {
if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Correct) if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
{ {
ecc_cd_reconstruct(ctx->eccCdContext, data, trk.type); aaruf_ecc_cd_reconstruct(ctx->eccCdContext, data, trk.type);
res = AARUF_STATUS_OK; res = AARUF_STATUS_OK;
} }
else if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == NotDumped) else if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == NotDumped)
@@ -291,7 +291,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
{ {
if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct) if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
{ {
ecc_cd_reconstruct_prefix(data, trk.type, sectorAddress); aaruf_ecc_cd_reconstruct_prefix(data, trk.type, sectorAddress);
res = AARUF_STATUS_OK; res = AARUF_STATUS_OK;
} }
else if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == NotDumped) else if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == NotDumped)
@@ -316,14 +316,14 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Mode2Form1Ok) if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Mode2Form1Ok)
{ {
memcpy(data + 24, bareData, 2048); memcpy(data + 24, bareData, 2048);
ecc_cd_reconstruct(ctx->eccCdContext, data, CdMode2Form1); aaruf_ecc_cd_reconstruct(ctx->eccCdContext, data, CdMode2Form1);
} }
else if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Mode2Form2Ok || else if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Mode2Form2Ok ||
(ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Mode2Form2NoCrc) (ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Mode2Form2NoCrc)
{ {
memcpy(data + 24, bareData, 2324); memcpy(data + 24, bareData, 2324);
if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Mode2Form2Ok) if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Mode2Form2Ok)
ecc_cd_reconstruct(ctx->eccCdContext, data, CdMode2Form2); aaruf_ecc_cd_reconstruct(ctx->eccCdContext, data, CdMode2Form2);
} }
else if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == NotDumped) else if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == NotDumped)
{ {
@@ -353,7 +353,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
case AppleSonyDS: case AppleSonyDS:
case AppleWidget: case AppleWidget:
case PriamDataTower: case PriamDataTower:
if(ctx->sectorSubchannel == NULL) return read_sector(context, sectorAddress, data, length); if(ctx->sectorSubchannel == NULL) return aaruf_read_sector(context, sectorAddress, data, length);
switch(ctx->imageInfo.MediaType) switch(ctx->imageInfo.MediaType)
{ {
@@ -378,7 +378,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
if(bareData == NULL) return AARUF_ERROR_NOT_ENOUGH_MEMORY; if(bareData == NULL) return AARUF_ERROR_NOT_ENOUGH_MEMORY;
res = read_sector(context, sectorAddress, bareData, &bareLength); res = aaruf_read_sector(context, sectorAddress, bareData, &bareLength);
if(bareLength != 512) return res; if(bareLength != 512) return res;

View File

@@ -61,78 +61,78 @@ class crc64Fixture : public ::testing::Test
TEST_F(crc64Fixture, crc64_auto) TEST_F(crc64Fixture, crc64_auto)
{ {
void* ctx = crc64_init_ecma(); void* ctx = aaruf_crc64_init_ecma();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
crc64_update(ctx, buffer, 1048576); aaruf_crc64_update(ctx, buffer, 1048576);
crc = crc64_final(ctx); crc = aaruf_crc64_final(ctx);
EXPECT_EQ(crc, EXPECTED_CRC64); EXPECT_EQ(crc, EXPECTED_CRC64);
} }
TEST_F(crc64Fixture, crc64_auto_misaligned) TEST_F(crc64Fixture, crc64_auto_misaligned)
{ {
void* ctx = crc64_init_ecma(); void* ctx = aaruf_crc64_init_ecma();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
crc64_update(ctx, buffer_misaligned + 1, 1048576); aaruf_crc64_update(ctx, buffer_misaligned + 1, 1048576);
crc = crc64_final(ctx); crc = aaruf_crc64_final(ctx);
EXPECT_EQ(crc, EXPECTED_CRC64); EXPECT_EQ(crc, EXPECTED_CRC64);
} }
TEST_F(crc64Fixture, crc64_auto_15bytes) TEST_F(crc64Fixture, crc64_auto_15bytes)
{ {
void* ctx = crc64_init_ecma(); void* ctx = aaruf_crc64_init_ecma();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
crc64_update(ctx, buffer, 15); aaruf_crc64_update(ctx, buffer, 15);
crc = crc64_final(ctx); crc = aaruf_crc64_final(ctx);
EXPECT_EQ(crc, EXPECTED_CRC64_15BYTES); EXPECT_EQ(crc, EXPECTED_CRC64_15BYTES);
} }
TEST_F(crc64Fixture, crc64_auto_31bytes) TEST_F(crc64Fixture, crc64_auto_31bytes)
{ {
void* ctx = crc64_init_ecma(); void* ctx = aaruf_crc64_init_ecma();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
crc64_update(ctx, buffer, 31); aaruf_crc64_update(ctx, buffer, 31);
crc = crc64_final(ctx); crc = aaruf_crc64_final(ctx);
EXPECT_EQ(crc, EXPECTED_CRC64_31BYTES); EXPECT_EQ(crc, EXPECTED_CRC64_31BYTES);
} }
TEST_F(crc64Fixture, crc64_auto_63bytes) TEST_F(crc64Fixture, crc64_auto_63bytes)
{ {
void* ctx = crc64_init_ecma(); void* ctx = aaruf_crc64_init_ecma();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
crc64_update(ctx, buffer, 63); aaruf_crc64_update(ctx, buffer, 63);
crc = crc64_final(ctx); crc = aaruf_crc64_final(ctx);
EXPECT_EQ(crc, EXPECTED_CRC64_63BYTES); EXPECT_EQ(crc, EXPECTED_CRC64_63BYTES);
} }
TEST_F(crc64Fixture, crc64_auto_2352bytes) TEST_F(crc64Fixture, crc64_auto_2352bytes)
{ {
void* ctx = crc64_init_ecma(); void* ctx = aaruf_crc64_init_ecma();
uint64_t crc; uint64_t crc;
EXPECT_NE(ctx, nullptr); EXPECT_NE(ctx, nullptr);
crc64_update(ctx, buffer, 2352); aaruf_crc64_update(ctx, buffer, 2352);
crc = crc64_final(ctx); crc = aaruf_crc64_final(ctx);
EXPECT_EQ(crc, EXPECTED_CRC64_2352BYTES); EXPECT_EQ(crc, EXPECTED_CRC64_2352BYTES);
} }