libaaruformat 1.0 Aaru Data Preservation Suite - Format Library

Loading...
Searching...
No Matches
helpers.c File Reference
`#include <aaru.h>`
`#include <aaruformat.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <time.h>`

Go to the source code of this file.

## Functions
int32_t | aaruf_get_media_tag_type_for_datatype (const int32_t type)
| Converts an image data type to an Aaru media tag type.
int32_t | aaruf_get_datatype_for_media_tag_type (const int32_t tag_type)
| Converts an Aaru media tag type to an image data type.
int32_t | aaruf_get_xml_mediatype (const int32_t type)
int | compare_extents (const void *a, const void *b)
| Comparison function for sorting DumpExtent arrays by start sector.
void | generate_random_bytes (uint8_t *buffer, size_t length)
| Generates cryptographically strong random bytes.

## Function Documentation

## ◆ aaruf_get_datatype_for_media_tag_type()

int32_t aaruf_get_datatype_for_media_tag_type | ( | const int32_t | tag_type | ) |

Converts an Aaru media tag type to an image data type.

Maps the given Aaru media tag type to the corresponding image data type. This is the inverse function of aaruf_get_media_tag_type_for_datatype.

Parameters

  tag_type | Aaru media tag type identifier.

Returns
  Corresponding image data type, or -1 if not found.

Definition at line 197 of file helpers.c.

References AACS_CPRM_MKB, AACS_DataKeys, AACS_LBAExtents, AACS_MediaIdentifier, AACS_MKB, AACS_SerialNumber, AACS_VolumeIdentifier, AacsDataKeys, AacsLbaExtents, AacsMediaIdentifier, AacsMediaKeyBlock, AacsSerialNumber, AacsVolumeIdentifier, AARU_CALL, AARU_LOCAL, ATA_IDENTIFY, AtaIdentify, ATAPI_IDENTIFY, AtapiIdentify, BD_BCA, BD_CartridgeStatus, BD_DDS, BD_DI, BD_SpareArea, BlurayBca, BlurayCartridgeStatus, BlurayDds, BlurayDi, BluraySpareArea, CD_ATIP, CD_FirstTrackPregap, CD_FullTOC, CD_LeadIn, CD_LeadOut, CD_MCN, CD_PMA, CD_SessionInfo, CD_TEXT, CD_TOC, CompactDiscAtip, CompactDiscFirstTrackPregap, CompactDiscLeadIn, CompactDiscLeadInCdText, CompactDiscLeadOut, CompactDiscMediaCatalogueNumber, CompactDiscPartialToc, CompactDiscPma, CompactDiscSessionInfo, CompactDiscToc, CprmMediaKeyBlock, DiscControlBlock, DVD_ADIP, DVD_BCA, DVD_CMI, DVD_DiscKey, DVD_DiscKey_Decrypted, DVD_DMI, DVD_MediaIdentifier, DVD_MKB, DVD_PFI, DvdAdip, DvdBca, DvdDiscControlBlock, DvdDiscKey, DvdDiscKeyDecrypted, DVDDL_JumpIntervalSize, DVDDL_LayerCapacity, DVDDL_ManualLayerJumpLBA, DVDDL_MiddleZoneAddress, DvdDlJumpIntervalSize, DvdDlLayerCapacity, DvdDlManualLayerJumpLba, DvdDlMiddleZoneAddress, DvdDmi, DvdLeadInCmi, DvdMediaIdentifier, DvdMediaKeyBlock, DvdPfi, DVDR_MediaIdentifier, DVDR_PFI, DVDR_PreRecordedInfo, DVDR_RMD, DVDRAM_DDS, DVDRAM_MediumStatus, DVDRAM_SpareArea, DvdRamDds, DvdRamMediumStatus, DvdRamSpareArea, DvdRMediaIdentifier, DvdRPfi, DvdRPrerecordedInfo, DvdRRmd, Floppy_LeadOut, FloppyLeadOut, HDDVD_CPI, HDDVD_MediumStatus, HdDvdCpi, HdDvdMediumStatus, Hybrid_RecognizedLayers, HybridRecognizedLayers, MMC_CID, MMC_CSD, MMC_DiscInformation, MMC_ExtendedCSD, MMC_OCR, MMC_POWResourcesInformation, MMC_TrackResourcesInformation, MMC_WriteProtection, MultiMediaCardCid, MultiMediaCardCsd, MultiMediaCardExtendedCsd, MultiMediaCardOcr, PCMCIA_CIS, PcmciaCis, SCSI_INQUIRY, SCSI_MODEPAGE_2A, SCSI_MODESENSE_10, SCSI_MODESENSE_6, ScsiInquiry, ScsiMmcDiscInformation, ScsiMmcPowResourcesInformation, ScsiMmcTrackResourcesInformation, ScsiMmcWriteProtection, ScsiModePage2A, ScsiModeSense10, ScsiModeSense6, SD_CID, SD_CSD, SD_OCR, SD_SCR, SecureDigitalCid, SecureDigitalCsd, SecureDigitalOcr, SecureDigitalScr, USB_Descriptors, UsbDescriptors, Xbox_DMI, Xbox_PFI, Xbox_SecuritySector, XboxDmi, XboxPfi, and XboxSecuritySector.

Referenced by write_media_tags().

## ◆ aaruf_get_media_tag_type_for_datatype()

int32_t aaruf_get_media_tag_type_for_datatype | ( | const int32_t | type | ) |

Converts an image data type to an Aaru media tag type.

Maps the given image data type to the corresponding Aaru media tag type.

Parameters

  type | Image data type identifier.

Returns
  Corresponding Aaru media tag type, or -1 if not found.

Definition at line 39 of file helpers.c.

References AACS_CPRM_MKB, AACS_DataKeys, AACS_LBAExtents, AACS_MediaIdentifier, AACS_MKB, AACS_SerialNumber, AACS_VolumeIdentifier, AacsDataKeys, AacsLbaExtents, AacsMediaIdentifier, AacsMediaKeyBlock, AacsSerialNumber, AacsVolumeIdentifier, AARU_CALL, AARU_LOCAL, ATA_IDENTIFY, AtaIdentify, ATAPI_IDENTIFY, AtapiIdentify, BD_BCA, BD_CartridgeStatus, BD_DDS, BD_DI, BD_SpareArea, BlurayBca, BlurayCartridgeStatus, BlurayDds, BlurayDi, BluraySpareArea, CD_ATIP, CD_FirstTrackPregap, CD_FullTOC, CD_LeadIn, CD_LeadOut, CD_MCN, CD_PMA, CD_SessionInfo, CD_TEXT, CD_TOC, CompactDiscAtip, CompactDiscFirstTrackPregap, CompactDiscLeadIn, CompactDiscLeadInCdText, CompactDiscLeadOut, CompactDiscMediaCatalogueNumber, CompactDiscPartialToc, CompactDiscPma, CompactDiscSessionInfo, CompactDiscToc, CprmMediaKeyBlock, DiscControlBlock, DVD_ADIP, DVD_BCA, DVD_CMI, DVD_DiscKey, DVD_DiscKey_Decrypted, DVD_DMI, DVD_MediaIdentifier, DVD_MKB, DVD_PFI, DvdAdip, DvdBca, DvdDiscControlBlock, DvdDiscKey, DvdDiscKeyDecrypted, DVDDL_JumpIntervalSize, DVDDL_LayerCapacity, DVDDL_ManualLayerJumpLBA, DVDDL_MiddleZoneAddress, DvdDlJumpIntervalSize, DvdDlLayerCapacity, DvdDlManualLayerJumpLba, DvdDlMiddleZoneAddress, DvdDmi, DvdLeadInCmi, DvdMediaIdentifier, DvdMediaKeyBlock, DvdPfi, DVDR_MediaIdentifier, DVDR_PFI, DVDR_PreRecordedInfo, DVDR_RMD, DVDRAM_DDS, DVDRAM_MediumStatus, DVDRAM_SpareArea, DvdRamDds, DvdRamMediumStatus, DvdRamSpareArea, DvdRMediaIdentifier, DvdRPfi, DvdRPrerecordedInfo, DvdRRmd, Floppy_LeadOut, FloppyLeadOut, HDDVD_CPI, HDDVD_MediumStatus, HdDvdCpi, HdDvdMediumStatus, Hybrid_RecognizedLayers, HybridRecognizedLayers, MMC_CID, MMC_CSD, MMC_DiscInformation, MMC_ExtendedCSD, MMC_OCR, MMC_POWResourcesInformation, MMC_TrackResourcesInformation, MMC_WriteProtection, MultiMediaCardCid, MultiMediaCardCsd, MultiMediaCardExtendedCsd, MultiMediaCardOcr, PCMCIA_CIS, PcmciaCis, SCSI_INQUIRY, SCSI_MODEPAGE_2A, SCSI_MODESENSE_10, SCSI_MODESENSE_6, ScsiInquiry, ScsiMmcDiscInformation, ScsiMmcPowResourcesInformation, ScsiMmcTrackResourcesInformation, ScsiMmcWriteProtection, ScsiModePage2A, ScsiModeSense10, ScsiModeSense6, SD_CID, SD_CSD, SD_OCR, SD_SCR, SecureDigitalCid, SecureDigitalCsd, SecureDigitalOcr, SecureDigitalScr, USB_Descriptors, UsbDescriptors, Xbox_DMI, Xbox_PFI, Xbox_SecuritySector, XboxDmi, XboxPfi, and XboxSecuritySector.

Referenced by process_data_block().

## ◆ aaruf_get_xml_mediatype()

int32_t aaruf_get_xml_mediatype | ( | const int32_t | type | ) |

Definition at line 347 of file helpers.c.

References AARU_CALL, AARU_LOCAL, BDR, BDRE, BDREXL, BDROM, BDRXL, BlockMedia, CBHD, CD, CD32, CDDA, CDEG, CDG, CDI, CDIREADY, CDMIDI, CDMO, CDMRW, CDPLUS, CDR, CDROM, CDROMXA, CDRW, CDTV, CDV, DDCD, DDCDR, DDCDRW, DTSCD, DVDDownload, DVDPR, DVDPRDL, DVDPRW, DVDPRWDL, DVDR, DVDRAM, DVDRDL, DVDROM, DVDRW, DVDRWDL, EVD, FDDVD, FMTOWNS, FVD, GDR, GDROM, GOD, HDDVDR, HDDVDRAM, HDDVDRDL, HDDVDROM, HDDVDRW, HDDVDRWDL, HDVMD, HVD, JaguarCD, LD, LDROM, LDROM2, LVROM, MEGACD, MegaLD, MilCD, NeoGeoCD, Nuon, OpticalDisc, PCD, PCFX, Pippin, Playdia, PS1CD, PS2CD, PS2DVD, PS3BD, PS3DVD, PS4BD, SACD, SATURNCD, SuperCDROM2, SVCD, SVOD, ThreeDO, UMD, VCD, VCDHD, VideoNow, VideoNowColor, VideoNowXp, WOD, WUOD, XGD, XGD2, XGD3, and XGD4.

Referenced by aaruf_create(), and aaruf_open().

## ◆ compare_extents()

int compare_extents | ( | const void * | a,
|  | const void * | b )

Comparison function for sorting DumpExtent arrays by start sector.

This function is used by qsort() to order dump extents in ascending order based on their start sector values. Extents with lower start sectors will appear first in the sorted array. This ordering is important for efficient extent lookup and validation during image operations.

Parameters

  a | Pointer to the first DumpExtent to compare.
  b | Pointer to the second DumpExtent to compare.

Returns
  Negative value if a->start < b->start, zero if equal, positive if a->start > b->start.

Definition at line 459 of file helpers.c.

References DumpExtent::start.

Referenced by aaruf_set_dumphw(), and process_dumphw_block().

## ◆ generate_random_bytes()

void generate_random_bytes | ( | uint8_t * | buffer,
|  | size_t | length )

Generates cryptographically strong random bytes.

This function fills the provided buffer with random bytes using platform-appropriate cryptographic random number generators. On Unix-like systems (including macOS and Linux), it reads from /dev/urandom. On Windows, it uses CryptGenRandom. If the platform-specific methods fail, it falls back to a time-seeded pseudo-random generator.

Parameters

  buffer | Pointer to the buffer to fill with random bytes.
  length | Number of random bytes to generate.

Definition at line 480 of file helpers.c.

Referenced by aaruf_create().