libaaruformat 1.0 Aaru Data Preservation Suite - Format Library

Loading...
Searching...
No Matches
ecc_cd.c File Reference
`#include <stdbool.h>`
`#include <stdint.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "aaruformat.h"`
`#include "log.h"`

Go to the source code of this file.

## Functions
void * | aaruf_ecc_cd_init ()
| Initializes a Compact Disc ECC context.
bool | aaruf_ecc_cd_is_suffix_correct (void *context, const uint8_t *sector)
| Checks if the suffix (EDC/ECC) of a CD sector is correct (Mode 1).
bool | aaruf_ecc_cd_is_suffix_correct_mode2 (void *context, const uint8_t *sector)
| Checks if the suffix (EDC/ECC) of a CD sector is correct (Mode 2).
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)
| Checks the ECC of a CD sector.
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)
| Writes ECC for a CD sector.
void | aaruf_ecc_cd_write_sector (void *context, const uint8_t *address, const uint8_t *data, uint8_t *ecc, const int32_t address_offset, const int32_t data_offset, const int32_t ecc_offset)
| Writes ECC for a full CD sector (both P and Q ECC).
void | aaruf_cd_lba_to_msf (const int64_t pos, uint8_t *minute, uint8_t *second, uint8_t *frame)
| Converts a CD LBA (Logical Block Address) to MSF (Minute:Second:Frame) format.
void | aaruf_ecc_cd_reconstruct_prefix (uint8_t *sector, const uint8_t type, const int64_t lba)
| Reconstructs the prefix (sync, address, mode) of a CD sector.
void | aaruf_ecc_cd_reconstruct (void *context, uint8_t *sector, const uint8_t type)
| Reconstructs the EDC and ECC fields of a CD sector.
uint32_t | aaruf_edc_cd_compute (void *context, uint32_t edc, const uint8_t *src, int size, int pos)
| Computes the EDC (Error Detection Code) for a CD sector.

## Function Documentation

## ◆ aaruf_cd_lba_to_msf()

void aaruf_cd_lba_to_msf | ( | const int64_t | pos,
|  | uint8_t * | minute,
|  | uint8_t * | second,
|  | uint8_t * | frame )

Converts a CD LBA (Logical Block Address) to MSF (Minute:Second:Frame) format.

Parameters

  pos | LBA position.
  minute | Pointer to store the minute value.
  second | Pointer to store the second value.
  frame | Pointer to store the frame value.

Definition at line 374 of file ecc_cd.c.

References AARU_CALL, AARU_LOCAL, and TRACE.

Referenced by aaruf_ecc_cd_reconstruct_prefix().

## ◆ aaruf_ecc_cd_check()

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 )

Checks the ECC of a CD sector.

Parameters

  context | Pointer to the ECC context.
  address | Pointer to the address field.
  data | Pointer to the data field.
  major_count | Number of major iterations.
  minor_count | Number of minor iterations.
  major_mult | Major multiplier.
  minor_inc | Minor increment.
  ecc | Pointer to the ECC field.
  address_offset | Offset for the address field.
  data_offset | Offset for the data field.
  ecc_offset | Offset for the ECC field.

Returns
  true if ECC is correct, false otherwise.

Definition at line 227 of file ecc_cd.c.

References AARU_CALL, AARU_EXPORT, CdEccContext::ecc_b_table, CdEccContext::ecc_f_table, CdEccContext::inited_edc, and TRACE.

Referenced by aaruf_ecc_cd_is_suffix_correct(), and aaruf_ecc_cd_is_suffix_correct_mode2().

## ◆ aaruf_ecc_cd_init()

void * aaruf_ecc_cd_init | ( |  | ) |

Initializes a Compact Disc ECC context.

Allocates and initializes a context for Compact Disc ECC calculations.

Returns
  Pointer to the initialized CdEccContext structure, or NULL on failure.

Definition at line 35 of file ecc_cd.c.

References AARU_CALL, AARU_EXPORT, CdEccContext::ecc_b_table, CdEccContext::ecc_f_table, CdEccContext::edc_table, CdEccContext::inited_edc, and TRACE.

Referenced by aaruf_create(), and aaruf_open().

## ◆ aaruf_ecc_cd_is_suffix_correct()

bool aaruf_ecc_cd_is_suffix_correct | ( | void * | context,
|  | const uint8_t * | sector )

Checks if the suffix (EDC/ECC) of a CD sector is correct (Mode 1).

Parameters

  context | Pointer to the ECC context.
  sector | Pointer to the sector data.

Returns
  true if the suffix is correct, false otherwise.

Definition at line 101 of file ecc_cd.c.

References AARU_CALL, AARU_EXPORT, aaruf_ecc_cd_check(), aaruf_edc_cd_compute(), CdEccContext::inited_edc, and TRACE.

Referenced by aaruf_write_sector_long().

## ◆ aaruf_ecc_cd_is_suffix_correct_mode2()

bool aaruf_ecc_cd_is_suffix_correct_mode2 | ( | void * | context,
|  | const uint8_t * | sector )

Checks if the suffix (EDC/ECC) of a CD sector is correct (Mode 2).

Parameters

  context | Pointer to the ECC context.
  sector | Pointer to the sector data.

Returns
  true if the suffix is correct, false otherwise.

Definition at line 165 of file ecc_cd.c.

References AARU_CALL, AARU_EXPORT, aaruf_ecc_cd_check(), aaruf_edc_cd_compute(), CdEccContext::inited_edc, and TRACE.

Referenced by aaruf_write_sector_long().

## ◆ aaruf_ecc_cd_reconstruct()

void aaruf_ecc_cd_reconstruct | ( | void * | context,
|  | uint8_t * | sector,
|  | const uint8_t | type )

Reconstructs the EDC and ECC fields of a CD sector.

Parameters

  context | Pointer to the ECC context.
  sector | Pointer to the sector data (must be 2352 bytes).
  type | Track type (mode).

Definition at line 459 of file ecc_cd.c.

References AARU_CALL, AARU_EXPORT, aaruf_ecc_cd_write_sector(), aaruf_edc_cd_compute(), CdMode1, CdMode2Form1, CdMode2Form2, CdEccContext::inited_edc, and TRACE.

Referenced by aaruf_read_sector_long().

## ◆ aaruf_ecc_cd_reconstruct_prefix()

void aaruf_ecc_cd_reconstruct_prefix | ( | uint8_t * | sector,
|  | const uint8_t | type,
|  | const int64_t | lba )

Reconstructs the prefix (sync, address, mode) of a CD sector.

Parameters

  sector | Pointer to the sector data (must be 2352 bytes).
  type | Track type (mode).
  lba | Logical Block Address.

Definition at line 392 of file ecc_cd.c.

References AARU_CALL, AARU_EXPORT, aaruf_cd_lba_to_msf(), CdMode1, CdMode2Form1, CdMode2Form2, CdMode2Formless, and TRACE.

Referenced by aaruf_read_sector_long().

## ◆ aaruf_ecc_cd_write()

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 )

Writes ECC for a CD sector.

Parameters

  context | Pointer to the ECC context.
  address | Pointer to the address field.
  data | Pointer to the data field.
  major_count | Number of major iterations.
  minor_count | Number of minor iterations.
  major_mult | Major multiplier.
  minor_inc | Minor increment.
  ecc | Pointer to the ECC field to write.
  address_offset | Offset for the address field.
  data_offset | Offset for the data field.
  ecc_offset | Offset for the ECC field.

Definition at line 293 of file ecc_cd.c.

References AARU_CALL, AARU_EXPORT, CdEccContext::ecc_b_table, CdEccContext::ecc_f_table, CdEccContext::inited_edc, and TRACE.

Referenced by aaruf_ecc_cd_write_sector().

## ◆ aaruf_ecc_cd_write_sector()

void aaruf_ecc_cd_write_sector | ( | void * | context,
|  | const uint8_t * | address,
|  | const uint8_t * | data,
|  | uint8_t * | ecc,
|  | const int32_t | address_offset,
|  | const int32_t | data_offset,
|  | const int32_t | ecc_offset )

Writes ECC for a full CD sector (both P and Q ECC).

Parameters

  context | Pointer to the ECC context.
  address | Pointer to the address field.
  data | Pointer to the data field.
  ecc | Pointer to the ECC field to write.
  address_offset | Offset for the address field.
  data_offset | Offset for the data field.
  ecc_offset | Offset for the ECC field.

Definition at line 352 of file ecc_cd.c.

References AARU_CALL, AARU_EXPORT, aaruf_ecc_cd_write(), and TRACE.

Referenced by aaruf_ecc_cd_reconstruct().

## ◆ aaruf_edc_cd_compute()

uint32_t aaruf_edc_cd_compute | ( | void * | context,
|  | uint32_t | edc,
|  | const uint8_t * | src,
|  | int | size,
|  | int | pos )

Computes the EDC (Error Detection Code) for a CD sector.

Parameters

  context | Pointer to the ECC context.
  edc | Initial EDC value.
  src | Pointer to the data to compute EDC over.
  size | Number of bytes to process.
  pos | Starting position in the data.

Returns
  Computed EDC value.

Definition at line 547 of file ecc_cd.c.

References AARU_CALL, AARU_EXPORT, CdEccContext::edc_table, CdEccContext::inited_edc, and TRACE.

Referenced by aaruf_ecc_cd_is_suffix_correct(), aaruf_ecc_cd_is_suffix_correct_mode2(), aaruf_ecc_cd_reconstruct(), and aaruf_write_sector_long().