libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
ngcw_junk.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include "lfg.h"

Go to the source code of this file.

Data Structures

struct  NgcwJunkEntry
 In-memory junk map entry. More...

Macros

#define AARUFORMAT_CONTEXT_DECLARED
#define NGCW_JUNK_MAP_VERSION   1
 Current junk map serialization version.

Typedefs

typedef struct NgcwJunkEntry NgcwJunkEntry
 In-memory junk map entry.

Functions

int32_t ngcw_serialize_junk_map (const NgcwJunkEntry *entries, uint32_t count, uint8_t **out_data, uint32_t *out_len)
 Serialize a junk map for storage as a media tag.
int32_t ngcw_deserialize_junk_map (const uint8_t *data, uint32_t data_len, NgcwJunkEntry **entries, uint32_t *count, uint16_t *seed_size)
 Deserialize a junk map from a media tag buffer.
int ngcw_regenerate_junk_sector (const NgcwJunkEntry *entries, uint32_t entry_count, uint64_t disc_offset, uint8_t *output, uint32_t length)
 Regenerate a junk sector from the junk map.
void ngcw_junk_lazy_init (aaruformat_context *ctx)
 Lazy initialization: load junk map from media tags.

Macro Definition Documentation

◆ AARUFORMAT_CONTEXT_DECLARED

#define AARUFORMAT_CONTEXT_DECLARED

Definition at line 31 of file ngcw_junk.h.

◆ NGCW_JUNK_MAP_VERSION

#define NGCW_JUNK_MAP_VERSION   1

Current junk map serialization version.

Definition at line 40 of file ngcw_junk.h.

Referenced by ngcw_deserialize_junk_map(), and ngcw_serialize_junk_map().

Typedef Documentation

◆ NgcwJunkEntry

typedef struct NgcwJunkEntry NgcwJunkEntry

In-memory junk map entry.

Each entry describes a contiguous region of LFG-generated junk on disc.

Function Documentation

◆ ngcw_deserialize_junk_map()

int32_t ngcw_deserialize_junk_map ( const uint8_t * data,
uint32_t data_len,
NgcwJunkEntry ** entries,
uint32_t * count,
uint16_t * seed_size )

Deserialize a junk map from a media tag buffer.

Parameters
dataSerialized data buffer.
data_lenLength of the data buffer.
entriesOutput: malloc'd array of NgcwJunkEntry (caller must free).
countOutput: number of entries.
seed_sizeOutput: seed size in uint32 words.
Returns
0 on success, negative error code on failure.

< Current junk map serialization version.

< Number of uint32 words needed to seed the LFG.

Definition at line 104 of file ngcw_junk.c.

References JUNK_MAP_HEADER_SIZE, NgcwJunkEntry::length, NGC_LFG_SEED_SIZE, ngcw_deserialize_junk_map(), NGCW_JUNK_MAP_VERSION, NgcwJunkEntry::offset, NgcwJunkEntry::partition_index, read_le16(), read_le32(), and read_le64().

Referenced by ngcw_deserialize_junk_map(), and ngcw_junk_lazy_init().

◆ ngcw_junk_lazy_init()

void ngcw_junk_lazy_init ( aaruformat_context * ctx)

Lazy initialization: load junk map from media tags.

Populates ctx->ngcw_junk_entries from the kMediaTagNgcwJunkMap media tag.

Parameters
ctxAaruFormat context.

Definition at line 211 of file ngcw_junk.c.

References mediaTagEntry::data, JUNK_MAP_HEADER_SIZE, kMediaTagNgcwJunkMap, mediaTagEntry::length, aaruformat_context::mediaTags, ngcw_deserialize_junk_map(), aaruformat_context::ngcw_junk_entries, aaruformat_context::ngcw_junk_entry_count, ngcw_junk_lazy_init(), and aaruformat_context::ngcw_junk_seed_size.

Referenced by aaruf_read_sector(), and ngcw_junk_lazy_init().

◆ ngcw_regenerate_junk_sector()

int ngcw_regenerate_junk_sector ( const NgcwJunkEntry * entries,
uint32_t entry_count,
uint64_t disc_offset,
uint8_t * output,
uint32_t length )

Regenerate a junk sector from the junk map.

Looks up the given disc byte offset in the junk map, initializes the LFG with the matching entry's seed, advances to the correct stream position, and generates the requested number of bytes.

Parameters
entriesArray of junk entries (sorted by offset).
entry_countNumber of entries.
disc_offsetDisc byte offset of the sector to regenerate.
outputOutput buffer to fill.
lengthNumber of bytes to generate.
Returns
0 on success, -1 if the offset is not in the junk map.

< Number of uint32 words needed to seed the LFG.

Definition at line 154 of file ngcw_junk.c.

References NgcwJunkEntry::length, ngc_lfg_get_bytes(), NGC_LFG_SEED_SIZE, ngc_lfg_set_seed(), ngcw_regenerate_junk_sector(), and NgcwJunkEntry::offset.

Referenced by aaruf_read_sector(), and ngcw_regenerate_junk_sector().

◆ ngcw_serialize_junk_map()

int32_t ngcw_serialize_junk_map ( const NgcwJunkEntry * entries,
uint32_t count,
uint8_t ** out_data,
uint32_t * out_len )

Serialize a junk map for storage as a media tag.

Format (all little-endian): [2 bytes] version (uint16) [4 bytes] entry_count (uint32) [2 bytes] seed_size (uint16) — NGC_LFG_SEED_SIZE For each entry (86 bytes when seed_size=17): [8 bytes] offset (uint64) [8 bytes] length (uint64) [2 bytes] partition_index (uint16) [seed_size * 4 bytes] seed (raw bytes, big-endian uint32 words)

Parameters
entriesArray of junk entries.
countNumber of entries.
out_dataOutput: malloc'd buffer (caller must free).
out_lenOutput: length of the buffer.
Returns
0 on success, negative error code on failure.

< Number of uint32 words needed to seed the LFG.

< Current junk map serialization version.

< Number of uint32 words needed to seed the LFG.

< Number of uint32 words needed to seed the LFG.

Definition at line 75 of file ngcw_junk.c.

References JUNK_MAP_HEADER_SIZE, NGC_LFG_SEED_SIZE, NGCW_JUNK_MAP_VERSION, ngcw_serialize_junk_map(), write_le16(), write_le32(), and write_le64().

Referenced by ngcw_serialize_junk_map().