30static uint16_t
read_le16(
const uint8_t *p) {
return (uint16_t)((uint16_t)p[0] | ((uint16_t)p[1] << 8)); }
33{
return (uint32_t)p[0] | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24); }
39 p[0] = (uint8_t)(v & 0xFF);
40 p[1] = (uint8_t)((v >> 8) & 0xFF);
45 p[0] = (uint8_t)(v & 0xFF);
46 p[1] = (uint8_t)((v >> 8) & 0xFF);
47 p[2] = (uint8_t)((v >> 16) & 0xFF);
48 p[3] = (uint8_t)((v >> 24) & 0xFF);
73#define JUNK_MAP_HEADER_SIZE 8
77 if(out_data == NULL || out_len == NULL)
return -1;
81 uint8_t *buf = (uint8_t *)malloc(size);
83 if(buf == NULL)
return -4;
89 for(uint32_t i = 0; i < count; i++)
95 write_le16(p + 16, entries[i].partition_index);
107 if(data == NULL || entries == NULL || count == NULL || seed_size == NULL)
return -1;
112 uint32_t entry_cnt =
read_le32(data + 2);
127 uint32_t entry_size = 18 + (uint32_t)ss * 4;
130 if(data_len < required)
return -2;
134 if(e == NULL)
return -4;
136 for(uint32_t i = 0; i < entry_cnt; i++)
143 memcpy(e[i].seed, p + 18, ss *
sizeof(uint32_t));
155 uint8_t *output, uint32_t length)
157 if(entries == NULL || entry_count == 0 || output == NULL)
return -1;
161 int hi = (int)entry_count - 1;
165 int mid = lo + (hi - lo) / 2;
166 uint64_t entry_end = entries[mid].
offset + entries[mid].
length;
168 if(disc_offset >= entry_end)
170 else if(disc_offset < entries[mid].offset)
178 uint64_t block_start = entries[mid].
offset & ~(uint64_t)0x7FFF;
179 uint64_t stream_pos = disc_offset - block_start;
183 memcpy(seed_copy, entries[mid].seed,
sizeof(seed_copy));
189 uint8_t discard[4096];
190 size_t rem = (size_t)stream_pos;
194 size_t step = rem >
sizeof(discard) ?
sizeof(discard) : rem;
213 if(ctx == NULL)
return;
219 HASH_FIND_INT(ctx->
mediaTags, &tag, item);
225 uint16_t seed_size = 0;
void ngc_lfg_get_bytes(struct ngc_lfg_ctx *ctx, uint8_t *out, size_t count)
Generate count bytes of junk data into out.
void ngc_lfg_set_seed(struct ngc_lfg_ctx *ctx, const uint32_t seed[17])
Initialize the LFG from a 17-word big-endian seed.
#define NGC_LFG_SEED_SIZE
Number of uint32 words needed to seed the LFG.
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.
static uint64_t read_le64(const uint8_t *p)
static uint32_t read_le32(const uint8_t *p)
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.
static void write_le32(uint8_t *p, uint32_t v)
static void write_le16(uint8_t *p, uint16_t v)
static void write_le64(uint8_t *p, uint64_t v)
#define JUNK_MAP_HEADER_SIZE
void ngcw_junk_lazy_init(aaruformat_context *ctx)
Lazy initialization: load junk map from media tags.
static uint16_t read_le16(const uint8_t *p)
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.
#define NGCW_JUNK_MAP_VERSION
Current junk map serialization version.
In-memory junk map entry.
uint64_t length
Length of junk region in bytes.
uint16_t partition_index
Partition index (0xFFFF for GC / inter-partition).
uint64_t offset
Disc byte offset where junk starts.
Master context representing an open or in‑creation Aaru image.
uint16_t ngcw_junk_seed_size
LFG seed size in uint32 words (expected: 17).
void * ngcw_junk_entries
Parsed NgcwJunkEntry array, NULL if not loaded.
mediaTagEntry * mediaTags
Hash table of extra media tags (uthash root).
uint32_t ngcw_junk_entry_count
Number of junk entries.
Hash table entry for an arbitrary media tag (e.g., proprietary drive/medium descriptor).
uint8_t * data
Tag data blob (opaque to library core); length bytes long.
uint32_t length
Length in bytes of data.
LFG context holding the 521-word circular buffer and byte position.