mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Reformat code.
This commit is contained in:
@@ -32,12 +32,12 @@
|
||||
#ifndef LIBAARUFORMAT_CONTEXT_H
|
||||
#define LIBAARUFORMAT_CONTEXT_H
|
||||
|
||||
#include "structs.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "structs.h"
|
||||
|
||||
typedef struct aaruformatContext
|
||||
{
|
||||
uint64_t magic;
|
||||
|
||||
@@ -107,36 +107,36 @@ AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_is_suffix_correct(void* context, const u
|
||||
AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector);
|
||||
|
||||
AARU_EXPORT bool AARU_CALL aaruf_ecc_cd_check(void* context,
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint32_t majorCount,
|
||||
uint32_t minorCount,
|
||||
uint32_t majorMult,
|
||||
uint32_t minorInc,
|
||||
const uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset);
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint32_t majorCount,
|
||||
uint32_t minorCount,
|
||||
uint32_t majorMult,
|
||||
uint32_t minorInc,
|
||||
const uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset);
|
||||
|
||||
AARU_EXPORT void AARU_CALL aaruf_ecc_cd_write(void* context,
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint32_t majorCount,
|
||||
uint32_t minorCount,
|
||||
uint32_t majorMult,
|
||||
uint32_t minorInc,
|
||||
uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset);
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint32_t majorCount,
|
||||
uint32_t minorCount,
|
||||
uint32_t majorMult,
|
||||
uint32_t minorInc,
|
||||
uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset);
|
||||
|
||||
AARU_EXPORT void AARU_CALL aaruf_ecc_cd_write_sector(void* context,
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset);
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset);
|
||||
|
||||
AARU_LOCAL void AARU_CALL aaruf_cd_lba_to_msf(int64_t pos, uint8_t* minute, uint8_t* second, uint8_t* frame);
|
||||
|
||||
|
||||
@@ -37,12 +37,12 @@
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
#include "enums.h"
|
||||
|
||||
#include <aaru.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "enums.h"
|
||||
|
||||
/**Header, at start of file */
|
||||
typedef struct AaruHeader
|
||||
{
|
||||
|
||||
@@ -30,12 +30,13 @@
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <aaruformat.h>
|
||||
#include <errno.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
int aaruf_close(void* context)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -30,11 +30,12 @@
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <aaruformat.h>
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
void* aaruf_crc64_init(uint64_t polynomial, uint64_t seed)
|
||||
{
|
||||
Crc64Context* ctx;
|
||||
@@ -53,8 +54,7 @@ void* aaruf_crc64_init(uint64_t polynomial, uint64_t seed)
|
||||
{
|
||||
uint64_t entry = (uint64_t)i;
|
||||
for(j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ polynomial;
|
||||
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
|
||||
@@ -92,8 +92,7 @@ uint64_t aaruf_crc64_data(const uint8_t* data, size_t len, uint64_t polynomial,
|
||||
{
|
||||
uint64_t entry = (uint64_t)i;
|
||||
for(j = 0; j < 8; j++)
|
||||
if((entry & 1) == 1)
|
||||
entry = (entry >> 1) ^ polynomial;
|
||||
if((entry & 1) == 1) entry = (entry >> 1) ^ polynomial;
|
||||
else
|
||||
entry = entry >> 1;
|
||||
|
||||
|
||||
@@ -30,11 +30,12 @@
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <aaruformat.h>
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
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;
|
||||
|
||||
63
src/ecc_cd.c
63
src/ecc_cd.c
@@ -31,12 +31,13 @@
|
||||
// ECC algorithm from ECM(c) 2002-2011 Neill Corlett
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <aaruformat.h>
|
||||
#include <malloc.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
void* aaruf_ecc_cd_init()
|
||||
{
|
||||
CdEccContext* context;
|
||||
@@ -153,16 +154,16 @@ bool aaruf_ecc_cd_is_suffix_correct_mode2(void* context, const uint8_t* sector)
|
||||
}
|
||||
|
||||
bool aaruf_ecc_cd_check(void* context,
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint32_t majorCount,
|
||||
uint32_t minorCount,
|
||||
uint32_t majorMult,
|
||||
uint32_t minorInc,
|
||||
const uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset)
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint32_t majorCount,
|
||||
uint32_t minorCount,
|
||||
uint32_t majorMult,
|
||||
uint32_t minorInc,
|
||||
const uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset)
|
||||
{
|
||||
CdEccContext* ctx;
|
||||
uint32_t size, major, idx, minor;
|
||||
@@ -198,16 +199,16 @@ bool aaruf_ecc_cd_check(void* context,
|
||||
}
|
||||
|
||||
void aaruf_ecc_cd_write(void* context,
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint32_t majorCount,
|
||||
uint32_t minorCount,
|
||||
uint32_t majorMult,
|
||||
uint32_t minorInc,
|
||||
uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset)
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint32_t majorCount,
|
||||
uint32_t minorCount,
|
||||
uint32_t majorMult,
|
||||
uint32_t minorInc,
|
||||
uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset)
|
||||
{
|
||||
CdEccContext* ctx;
|
||||
uint32_t size, major, idx, minor;
|
||||
@@ -243,12 +244,12 @@ void aaruf_ecc_cd_write(void* context,
|
||||
}
|
||||
|
||||
void aaruf_ecc_cd_write_sector(void* context,
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset)
|
||||
const uint8_t* address,
|
||||
const uint8_t* data,
|
||||
uint8_t* ecc,
|
||||
int32_t addressOffset,
|
||||
int32_t dataOffset,
|
||||
int32_t eccOffset)
|
||||
{
|
||||
aaruf_ecc_cd_write(context, address, data, 86, 24, 2, 86, ecc, addressOffset, dataOffset, eccOffset); // P
|
||||
aaruf_ecc_cd_write(context, address, data, 52, 43, 86, 88, ecc, addressOffset, dataOffset, eccOffset + 0xAC); // Q
|
||||
@@ -262,8 +263,8 @@ void aaruf_cd_lba_to_msf(int64_t pos, uint8_t* minute, uint8_t* second, uint8_t*
|
||||
}
|
||||
|
||||
void aaruf_ecc_cd_reconstruct_prefix(uint8_t* sector, // must point to a full 2352-byte sector
|
||||
uint8_t type,
|
||||
int64_t lba)
|
||||
uint8_t type,
|
||||
int64_t lba)
|
||||
{
|
||||
uint8_t minute, second, frame;
|
||||
|
||||
@@ -319,8 +320,8 @@ void aaruf_ecc_cd_reconstruct_prefix(uint8_t* sector, // must point to a full 23
|
||||
}
|
||||
|
||||
void aaruf_ecc_cd_reconstruct(void* context,
|
||||
uint8_t* sector, // must point to a full 2352-byte sector
|
||||
uint8_t type)
|
||||
uint8_t* sector, // must point to a full 2352-byte sector
|
||||
uint8_t type)
|
||||
{
|
||||
uint32_t computedEdc;
|
||||
uint8_t zeroaddress[4];
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <aaru.h>
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
// Converts between image data type and aaru media tag type
|
||||
|
||||
@@ -30,10 +30,11 @@
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <aaruformat.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
//! Identifies a file as aaruformat, using path
|
||||
/*!
|
||||
*
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <aaruformat.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <malloc.h>
|
||||
@@ -38,6 +37,8 @@
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
void* aaruf_open(const char* filepath)
|
||||
{
|
||||
aaruformatContext* ctx;
|
||||
@@ -318,8 +319,7 @@ void* aaruf_open(const char* filepath)
|
||||
break;
|
||||
case CdSectorSuffix:
|
||||
case CdSectorSuffixCorrected:
|
||||
if(idxEntries[i].dataType == CdSectorSuffixCorrected)
|
||||
ctx->sectorSuffixCorrected = data;
|
||||
if(idxEntries[i].dataType == CdSectorSuffixCorrected) ctx->sectorSuffixCorrected = data;
|
||||
else
|
||||
ctx->sectorSuffix = data;
|
||||
|
||||
@@ -461,8 +461,7 @@ void* aaruf_open(const char* filepath)
|
||||
break;
|
||||
}
|
||||
|
||||
if(idxEntries[i].dataType == CdSectorPrefixCorrected)
|
||||
ctx->sectorPrefixDdt = cdDdt;
|
||||
if(idxEntries[i].dataType == CdSectorPrefixCorrected) ctx->sectorPrefixDdt = cdDdt;
|
||||
else if(idxEntries[i].dataType == CdSectorSuffixCorrected)
|
||||
ctx->sectorSuffixDdt = cdDdt;
|
||||
else
|
||||
|
||||
16
src/read.c
16
src/read.c
@@ -30,10 +30,11 @@
|
||||
// Copyright © 2011-2020 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
#include <aaruformat.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <aaruformat.h>
|
||||
|
||||
int32_t aaruf_read_media_tag(void* context, uint8_t* data, int32_t tag, uint32_t* length)
|
||||
{
|
||||
aaruformatContext* ctx;
|
||||
@@ -165,7 +166,9 @@ int32_t aaruf_read_track_sector(void* context, uint8_t* data, uint64_t sectorAdd
|
||||
for(i = 0; i < ctx->numberOfDataTracks; i++)
|
||||
{
|
||||
if(ctx->dataTracks[i].sequence == track)
|
||||
{ return aaruf_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;
|
||||
@@ -233,8 +236,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
|
||||
case CdMode1:
|
||||
memcpy(bareData, data + 16, 2048);
|
||||
|
||||
if(ctx->sectorPrefix != NULL)
|
||||
memcpy(data, ctx->sectorPrefix + (sectorAddress * 16), 16);
|
||||
if(ctx->sectorPrefix != NULL) memcpy(data, ctx->sectorPrefix + (sectorAddress * 16), 16);
|
||||
else if(ctx->sectorPrefixDdt != NULL)
|
||||
{
|
||||
if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
|
||||
@@ -257,8 +259,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
|
||||
else
|
||||
return AARUF_ERROR_REACHED_UNREACHABLE_CODE;
|
||||
|
||||
if(ctx->sectorSuffix != NULL)
|
||||
memcpy(data + 2064, ctx->sectorSuffix + sectorAddress * 288, 288);
|
||||
if(ctx->sectorSuffix != NULL) memcpy(data + 2064, ctx->sectorSuffix + sectorAddress * 288, 288);
|
||||
else if(ctx->sectorSuffixDdt != NULL)
|
||||
{
|
||||
if((ctx->sectorSuffixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
|
||||
@@ -285,8 +286,7 @@ int32_t read_sector_long(void* context, uint8_t* data, uint64_t sectorAddress, u
|
||||
case CdMode2Formless:
|
||||
case CdMode2Form1:
|
||||
case CdMode2Form2:
|
||||
if(ctx->sectorPrefix != NULL)
|
||||
memcpy(data, ctx->sectorPrefix + sectorAddress * 16, 16);
|
||||
if(ctx->sectorPrefix != NULL) memcpy(data, ctx->sectorPrefix + sectorAddress * 16, 16);
|
||||
else if(ctx->sectorPrefixDdt != NULL)
|
||||
{
|
||||
if((ctx->sectorPrefixDdt[sectorAddress] & CD_XFIX_MASK) == Correct)
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// Created by claunia on 5/10/21.
|
||||
//
|
||||
|
||||
#include "../include/aaruformat.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "../include/aaruformat.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#define EXPECTED_CRC64 0xbf09992cc5ede38e
|
||||
#define EXPECTED_CRC64_15BYTES 0x797F3766FD93975B
|
||||
#define EXPECTED_CRC64_31BYTES 0xCD9201905A7937FD
|
||||
|
||||
Reference in New Issue
Block a user