libaaruformat 1.0 Aaru Data Preservation Suite - Format Library

Loading...
Searching...
No Matches
metadata.c
Go to the documentation of this file.
1/*
2 * This file is part of the Aaru Data Preservation Suite.
3 * Copyright (c) 2019-2025 Natalia Portillo.
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <inttypes.h>
20#include <stdint.h>
21#include <stdio.h>
22#include <stdlib.h>
23
24#include "aaruformat.h"
25#include "log.h"
26
35 void process_metadata_block(aaruformat_context *ctx, const IndexEntry *entry)
36{
37 TRACE("Entering process_metadata_block(%p, %p)", ctx, entry);
38 int pos = 0;
39 size_t read_bytes = 0;
40
41 // Check if the context and image stream are valid
42 if(ctx == NULL || ctx->imageStream == NULL)
43 {
44 FATAL("Invalid context or image stream.");
45 TRACE("Exiting process_metadata_block()");
46 return;
47 }
48
49 // Seek to block
50 TRACE("Seeking to metadata block at position %" PRIu64, entry->offset);
51 pos = fseek(ctx->imageStream, entry->offset, SEEK_SET);
52 if(pos < 0 || ftell(ctx->imageStream) != entry->offset)
53 {
54 FATAL("Could not seek to %" PRIu64 " as indicated by index entry...", entry->offset);
55
56 TRACE("Exiting process_metadata_block()");
57 return;
58 }
59
60 // Even if those two checks shall have been done before
61 TRACE("Reading metadata block header at position %" PRIu64, entry->offset);
62 read_bytes = fread(&ctx->metadata_block_header, 1, sizeof(MetadataBlockHeader), ctx->imageStream);
63
64 if(read_bytes != sizeof(MetadataBlockHeader))
65 {
66 memset(&ctx->metadata_block_header, 0, sizeof(MetadataBlockHeader));
67 FATAL("Could not read metadata block header, continuing...");
68
69 TRACE("Exiting process_metadata_block()");
70 return;
71 }
72
73 if(ctx->metadata_block_header.identifier != entry->blockType)
74 {
75 memset(&ctx->metadata_block_header, 0, sizeof(MetadataBlockHeader));
76 TRACE("Incorrect identifier for data block at position %" PRIu64 "", entry->offset);
77
78 TRACE("Exiting process_metadata_block()");
79 return;
80 }
81
82 ctx->image_info.ImageSize += ctx->metadata_block_header.blockSize;
83
84 ctx->metadata_block = (uint8_t *)malloc(ctx->metadata_block_header.blockSize);
85
86 if(ctx->metadata_block == NULL)
87 {
88 memset(&ctx->metadata_block_header, 0, sizeof(MetadataBlockHeader));
89 FATAL("Could not allocate memory for metadata block, continuing...");
90
91 TRACE("Exiting process_metadata_block()");
92 return;
93 }
94
95 TRACE("Reading metadata block of size %u at position %" PRIu64, ctx->metadata_block_header.blockSize,
96 entry->offset + sizeof(MetadataBlockHeader));
97 read_bytes = fread(ctx->metadata_block, 1, ctx->metadata_block_header.blockSize, ctx->imageStream);
98
99 if(read_bytes != ctx->metadata_block_header.blockSize)
100 {
101 memset(&ctx->metadata_block_header, 0, sizeof(MetadataBlockHeader));
102 free(ctx->metadata_block);
103 FATAL("Could not read metadata block, continuing...");
104 }
105
106 if(ctx->metadata_block_header.mediaSequence > 0 && ctx->metadata_block_header.lastMediaSequence > 0)
107 {
108 ctx->media_sequence = ctx->metadata_block_header.mediaSequence;
109 ctx->last_media_sequence = ctx->metadata_block_header.lastMediaSequence;
110 TRACE("Setting media sequence as %d of %d", ctx->media_sequence, ctx->last_media_sequence);
111 }
112
113 if(ctx->metadata_block_header.creatorLength > 0 &&
114 ctx->metadata_block_header.creatorOffset + ctx->metadata_block_header.creatorLength <=
115 ctx->metadata_block_header.blockSize)
116 {
117 ctx->creator = (uint8_t *)malloc(ctx->metadata_block_header.creatorLength);
118 if(ctx->creator != NULL)
119 memcpy(ctx->creator, ctx->metadata_block + ctx->metadata_block_header.creatorOffset,
120 ctx->metadata_block_header.creatorLength);
121 }
122
123 if(ctx->metadata_block_header.commentsLength > 0 &&
124 ctx->metadata_block_header.commentsOffset + ctx->metadata_block_header.commentsLength <=
125 ctx->metadata_block_header.blockSize)
126 {
127 ctx->comments = (uint8_t *)malloc(ctx->metadata_block_header.commentsLength);
128 if(ctx->comments != NULL)
129 memcpy(ctx->comments, ctx->metadata_block + ctx->metadata_block_header.commentsOffset,
130 ctx->metadata_block_header.commentsLength);
131 }
132
133 if(ctx->metadata_block_header.mediaTitleLength > 0 &&
134 ctx->metadata_block_header.mediaTitleOffset + ctx->metadata_block_header.mediaTitleLength <=
135 ctx->metadata_block_header.blockSize)
136 {
137 ctx->media_title = (uint8_t *)malloc(ctx->metadata_block_header.mediaTitleLength);
138 if(ctx->media_title != NULL)
139 memcpy(ctx->media_title, ctx->metadata_block + ctx->metadata_block_header.mediaTitleOffset,
140 ctx->metadata_block_header.mediaTitleLength);
141 }
142
143 if(ctx->metadata_block_header.mediaManufacturerLength > 0 &&
144 ctx->metadata_block_header.mediaManufacturerOffset + ctx->metadata_block_header.mediaManufacturerLength <=
145 ctx->metadata_block_header.blockSize)
146 {
147 ctx->media_manufacturer = (uint8_t *)malloc(ctx->metadata_block_header.mediaManufacturerLength);
148 if(ctx->media_manufacturer != NULL)
149 memcpy(ctx->media_manufacturer, ctx->metadata_block + ctx->metadata_block_header.mediaManufacturerOffset,
150 ctx->metadata_block_header.mediaManufacturerLength);
151 }
152
153 if(ctx->metadata_block_header.mediaModelLength > 0 &&
154 ctx->metadata_block_header.mediaModelOffset + ctx->metadata_block_header.mediaModelLength <=
155 ctx->metadata_block_header.blockSize)
156 {
157 ctx->media_model = (uint8_t *)malloc(ctx->metadata_block_header.mediaModelLength);
158 if(ctx->media_model != NULL)
159 memcpy(ctx->media_model, ctx->metadata_block + ctx->metadata_block_header.mediaModelOffset,
160 ctx->metadata_block_header.mediaModelLength);
161 }
162
163 if(ctx->metadata_block_header.mediaSerialNumberLength > 0 &&
164 ctx->metadata_block_header.mediaSerialNumberOffset + ctx->metadata_block_header.mediaSerialNumberLength <=
165 ctx->metadata_block_header.blockSize)
166 {
167 ctx->media_serial_number = (uint8_t *)malloc(ctx->metadata_block_header.mediaSerialNumberLength);
168 if(ctx->media_serial_number != NULL)
169 memcpy(ctx->media_serial_number, ctx->metadata_block + ctx->metadata_block_header.mediaSerialNumberOffset,
170 ctx->metadata_block_header.mediaSerialNumberLength);
171 }
172
173 if(ctx->metadata_block_header.mediaBarcodeLength > 0 &&
174 ctx->metadata_block_header.mediaBarcodeOffset + ctx->metadata_block_header.mediaBarcodeLength <=
175 ctx->metadata_block_header.blockSize)
176 {
177 ctx->media_barcode = (uint8_t *)malloc(ctx->metadata_block_header.mediaBarcodeLength);
178 if(ctx->media_barcode != NULL)
179 memcpy(ctx->media_barcode, ctx->metadata_block + ctx->metadata_block_header.mediaBarcodeOffset,
180 ctx->metadata_block_header.mediaBarcodeLength);
181 }
182
183 if(ctx->metadata_block_header.mediaPartNumberLength > 0 &&
184 ctx->metadata_block_header.mediaPartNumberOffset + ctx->metadata_block_header.mediaPartNumberLength <=
185 ctx->metadata_block_header.blockSize)
186 {
187 ctx->media_part_number = (uint8_t *)malloc(ctx->metadata_block_header.mediaPartNumberLength);
188 if(ctx->media_part_number != NULL)
189 memcpy(ctx->media_part_number, ctx->metadata_block + ctx->metadata_block_header.mediaPartNumberOffset,
190 ctx->metadata_block_header.mediaPartNumberLength);
191 }
192
193 if(ctx->metadata_block_header.driveManufacturerLength > 0 &&
194 ctx->metadata_block_header.driveManufacturerOffset + ctx->metadata_block_header.driveManufacturerLength <=
195 ctx->metadata_block_header.blockSize)
196 {
197 ctx->drive_manufacturer = (uint8_t *)malloc(ctx->metadata_block_header.driveManufacturerLength);
198 if(ctx->drive_manufacturer != NULL)
199 memcpy(ctx->drive_manufacturer, ctx->metadata_block + ctx->metadata_block_header.driveManufacturerOffset,
200 ctx->metadata_block_header.driveManufacturerLength);
201 }
202
203 if(ctx->metadata_block_header.driveModelLength > 0 &&
204 ctx->metadata_block_header.driveModelOffset + ctx->metadata_block_header.driveModelLength <=
205 ctx->metadata_block_header.blockSize)
206 {
207 ctx->drive_model = (uint8_t *)malloc(ctx->metadata_block_header.driveModelLength);
208 if(ctx->drive_model != NULL)
209 memcpy(ctx->drive_model, ctx->metadata_block + ctx->metadata_block_header.driveModelOffset,
210 ctx->metadata_block_header.driveModelLength);
211 }
212
213 if(ctx->metadata_block_header.driveSerialNumberLength > 0 &&
214 ctx->metadata_block_header.driveSerialNumberOffset + ctx->metadata_block_header.driveSerialNumberLength <=
215 ctx->metadata_block_header.blockSize)
216 {
217 ctx->drive_serial_number = (uint8_t *)malloc(ctx->metadata_block_header.driveSerialNumberLength);
218 if(ctx->drive_serial_number != NULL)
219 memcpy(ctx->drive_serial_number, ctx->metadata_block + ctx->metadata_block_header.driveSerialNumberOffset,
220 ctx->metadata_block_header.driveSerialNumberLength);
221 }
222
223 if(ctx->metadata_block_header.driveFirmwareRevisionLength > 0 &&
224 ctx->metadata_block_header.driveFirmwareRevisionOffset +
225 ctx->metadata_block_header.driveFirmwareRevisionLength <=
226 ctx->metadata_block_header.blockSize)
227 {
228 ctx->drive_firmware_revision = (uint8_t *)malloc(ctx->metadata_block_header.driveFirmwareRevisionLength);
229 if(ctx->drive_firmware_revision != NULL)
230 memcpy(ctx->drive_firmware_revision,
231 ctx->metadata_block + ctx->metadata_block_header.driveFirmwareRevisionOffset,
232 ctx->metadata_block_header.driveFirmwareRevisionLength);
233 }
234
235 TRACE("Exiting process_metadata_block()");
236}
237
246 void process_geometry_block(aaruformat_context *ctx, const IndexEntry *entry)
247{
248 TRACE("Entering process_geometry_block(%p, %p)", ctx, entry);
249 size_t read_bytes = 0;
250
251 // Check if the context and image stream are valid
252 if(ctx == NULL || ctx->imageStream == NULL)
253 {
254 FATAL("Invalid context or image stream.");
255
256 TRACE("Exiting process_geometry_block()");
257 return;
258 }
259
260 // Seek to block
261 if(fseek(ctx->imageStream, entry->offset, SEEK_SET) != 0)
262 {
263 FATAL("Could not seek to %" PRIu64 " as indicated by index entry...", entry->offset);
264
265 TRACE("Exiting process_geometry_block()");
266 return;
267 }
268
269 TRACE("Reading geometry block header at position %" PRIu64, entry->offset);
270 read_bytes = fread(&ctx->geometry_block, 1, sizeof(GeometryBlockHeader), ctx->imageStream);
271
272 if(read_bytes != sizeof(GeometryBlockHeader))
273 {
274 memset(&ctx->geometry_block, 0, sizeof(GeometryBlockHeader));
275 TRACE("Could not read geometry block header, continuing...");
276 return;
277 }
278
279 if(ctx->geometry_block.identifier != GeometryBlock)
280 {
281 memset(&ctx->geometry_block, 0, sizeof(GeometryBlockHeader));
282 TRACE("Incorrect identifier for geometry block at position %" PRIu64 "", entry->offset);
283 return;
284 }
285
286 ctx->image_info.ImageSize += sizeof(GeometryBlockHeader);
287
288 TRACE("Geometry set to %d cylinders %d heads %d sectors per track", ctx->geometry_block.cylinders,
289 ctx->geometry_block.heads, ctx->geometry_block.sectorsPerTrack);
290
291 ctx->cylinders = ctx->geometry_block.cylinders;
292 ctx->heads = ctx->geometry_block.heads;
293 ctx->sectors_per_track = ctx->geometry_block.sectorsPerTrack;
294
295 TRACE("Exiting process_geometry_block()");
296}
297
306 void process_cicm_block(aaruformat_context *ctx, const IndexEntry *entry)
307{
308 TRACE("Entering process_cicm_block(%p, %p)", ctx, entry);
309 int pos = 0;
310 size_t read_bytes = 0;
311
312 // Check if the context and image stream are valid
313 if(ctx == NULL || ctx->imageStream == NULL)
314 {
315 FATAL("Invalid context or image stream.");
316
317 TRACE("Exiting process_cicm_block()");
318 return;
319 }
320
321 // Seek to block
322 TRACE("Seeking to CICM XML metadata block at position %" PRIu64, entry->offset);
323 pos = fseek(ctx->imageStream, entry->offset, SEEK_SET);
324 if(pos < 0 || ftell(ctx->imageStream) != entry->offset)
325 {
326 FATAL("Could not seek to %" PRIu64 " as indicated by index entry...", entry->offset);
327
328 TRACE("Exiting process_cicm_block()");
329 return;
330 }
331
332 // Even if those two checks shall have been done before
333 TRACE("Reading CICM XML metadata block header at position %" PRIu64, entry->offset);
334 read_bytes = fread(&ctx->cicm_block_header, 1, sizeof(CicmMetadataBlock), ctx->imageStream);
335
336 if(read_bytes != sizeof(CicmMetadataBlock))
337 {
338 memset(&ctx->cicm_block_header, 0, sizeof(CicmMetadataBlock));
339 TRACE("Could not read CICM XML metadata header, continuing...");
340 return;
341 }
342
343 if(ctx->cicm_block_header.identifier != CicmBlock)
344 {
345 memset(&ctx->cicm_block_header, 0, sizeof(CicmMetadataBlock));
346 TRACE("Incorrect identifier for data block at position %" PRIu64 "", entry->offset);
347 }
348
349 ctx->image_info.ImageSize += ctx->cicm_block_header.length;
350
351 ctx->cicm_block = (uint8_t *)malloc(ctx->cicm_block_header.length);
352
353 if(ctx->cicm_block == NULL)
354 {
355 memset(&ctx->cicm_block_header, 0, sizeof(CicmMetadataBlock));
356 TRACE("Could not allocate memory for CICM XML metadata block, continuing...");
357
358 TRACE("Exiting process_cicm_block()");
359 return;
360 }
361
362 TRACE("Reading CICM XML metadata block of size %u at position %" PRIu64, ctx->cicm_block_header.length,
363 entry->offset + sizeof(CicmMetadataBlock));
364 read_bytes = fread(ctx->cicm_block, 1, ctx->cicm_block_header.length, ctx->imageStream);
365
366 if(read_bytes != ctx->cicm_block_header.length)
367 {
368 memset(&ctx->cicm_block_header, 0, sizeof(CicmMetadataBlock));
369 free(ctx->cicm_block);
370 TRACE("Could not read CICM XML metadata block, continuing...");
371 }
372
373 TRACE("Found CICM XML metadata block %" PRIu64 ".", entry->offset);
374
375 TRACE("Exiting process_cicm_block()");
376}
377
470 void process_aaru_metadata_json_block(aaruformat_context *ctx, const IndexEntry *entry)
471{
472 TRACE("Entering process_aaru_metadata_json_block(%p, %p)", ctx, entry);
473 int pos = 0;
474 size_t read_bytes = 0;
475
476 // Check if the context and image stream are valid
477 if(ctx == NULL || ctx->imageStream == NULL)
478 {
479 FATAL("Invalid context or image stream.");
480
481 TRACE("Exiting process_aaru_metadata_json_block()");
482 return;
483 }
484
485 // Seek to block
486 TRACE("Seeking to Aaru metadata JSON block at position %" PRIu64, entry->offset);
487 pos = fseek(ctx->imageStream, entry->offset, SEEK_SET);
488 if(pos < 0 || ftell(ctx->imageStream) != entry->offset)
489 {
490 FATAL("Could not seek to %" PRIu64 " as indicated by index entry...", entry->offset);
491
492 TRACE("Exiting process_aaru_metadata_json_block()");
493 return;
494 }
495
496 // Even if those two checks shall have been done before
497 TRACE("Reading Aaru metadata JSON block header at position %" PRIu64, entry->offset);
498 read_bytes = fread(&ctx->json_block_header, 1, sizeof(AaruMetadataJsonBlockHeader), ctx->imageStream);
499
500 if(read_bytes != sizeof(AaruMetadataJsonBlockHeader))
501 {
502 memset(&ctx->json_block_header, 0, sizeof(AaruMetadataJsonBlockHeader));
503 TRACE("Could not read Aaru metadata JSON header, continuing...");
504 return;
505 }
506
507 if(ctx->json_block_header.identifier != AaruMetadataJsonBlock)
508 {
509 memset(&ctx->json_block_header, 0, sizeof(AaruMetadataJsonBlockHeader));
510 TRACE("Incorrect identifier for data block at position %" PRIu64 "", entry->offset);
511 }
512
513 ctx->image_info.ImageSize += ctx->json_block_header.length;
514
515 ctx->json_block = (uint8_t *)malloc(ctx->json_block_header.length);
516
517 if(ctx->json_block == NULL)
518 {
519 memset(&ctx->json_block_header, 0, sizeof(AaruMetadataJsonBlockHeader));
520 TRACE("Could not allocate memory for Aaru metadata JSON block, continuing...");
521
522 TRACE("Exiting process_aaru_metadata_json_block()");
523 return;
524 }
525
526 TRACE("Reading Aaru metadata JSON block of size %u at position %" PRIu64, ctx->json_block_header.length,
527 entry->offset + sizeof(AaruMetadataJsonBlockHeader));
528 read_bytes = fread(ctx->json_block, 1, ctx->json_block_header.length, ctx->imageStream);
529
530 if(read_bytes != ctx->json_block_header.length)
531 {
532 memset(&ctx->json_block_header, 0, sizeof(AaruMetadataJsonBlockHeader));
533 free(ctx->json_block);
534 TRACE("Could not read Aaru metadata JSON block, continuing...");
535 }
536
537 TRACE("Found Aaru metadata JSON block %" PRIu64 ".", entry->offset);
538
539 TRACE("Exiting process_aaru_metadata_json_block()");
540}
541
618 AARU_EXPORT int32_t AARU_CALL aaruf_get_readable_sector_tags(const void *context, uint8_t *buffer, size_t *length)
619{
620 TRACE("Entering aaruf_get_readable_sector_tags(%p, %p, %zu)", context, buffer, (length ? *length : 0));
621
622 // Check context is correct AaruFormat context
623 if(context == NULL)
624 {
625 FATAL("Invalid context");
626
627 TRACE("Exiting aaruf_get_readable_sector_tags() = AARUF_ERROR_NOT_AARUFORMAT");
628 return AARUF_ERROR_NOT_AARUFORMAT;
629 }
630
631 const aaruformat_context *ctx = context;
632
633 // Not a libaaruformat context
634 if(ctx->magic != AARU_MAGIC)
635 {
636 FATAL("Invalid context");
637
638 TRACE("Exiting aaruf_get_readable_sector_tags() = AARUF_ERROR_NOT_AARUFORMAT");
639 return AARUF_ERROR_NOT_AARUFORMAT;
640 }
641
642 if(ctx->readableSectorTags == NULL)
643 {
644 FATAL("Image contains no readable sector tags");
645
646 TRACE("Exiting aaruf_get_readable_sector_tags() = AARUF_ERROR_METADATA_NOT_PRESENT");
647 return AARUF_ERROR_METADATA_NOT_PRESENT;
648 }
649
650 size_t required_length = sizeof(bool) * (MaxSectorTag + 1);
651
652 if(buffer == NULL || length == NULL || *length < required_length)
653 {
654 if(length) *length = required_length;
655 TRACE("Buffer too small for readable sector tags, required %zu bytes", required_length);
656
657 TRACE("Exiting aaruf_get_readable_sector_tags() = AARUF_ERROR_BUFFER_TOO_SMALL");
658 return AARUF_ERROR_BUFFER_TOO_SMALL;
659 }
660
661 memcpy(buffer, ctx->readableSectorTags, required_length);
662 *length = required_length;
663
664 TRACE("Exiting aaruf_get_readable_sector_tags(%p, %p, %zu) = AARUF_STATUS_OK", context, buffer, *length);
665 return AARUF_STATUS_OK;
666}
667
706 AARU_EXPORT int32_t AARU_CALL aaruf_get_readable_media_tags(const void *context, uint8_t *buffer, size_t *length)
707{
708 TRACE("Entering aaruf_get_readable_media_tags(%p, %p, %zu)", context, buffer, (length ? *length : 0));
709
710 // Check context is correct AaruFormat context
711 if(context == NULL)
712 {
713 FATAL("Invalid context");
714
715 TRACE("Exiting aaruf_get_readable_media_tags() = AARUF_ERROR_NOT_AARUFORMAT");
716 return AARUF_ERROR_NOT_AARUFORMAT;
717 }
718
719 const aaruformat_context *ctx = context;
720
721 // Not a libaaruformat context
722 if(ctx->magic != AARU_MAGIC)
723 {
724 FATAL("Invalid context");
725
726 TRACE("Exiting aaruf_get_readable_media_tags() = AARUF_ERROR_NOT_AARUFORMAT");
727 return AARUF_ERROR_NOT_AARUFORMAT;
728 }
729
730 // Required size: one byte for each MediaTagType (0 to MaxMediaTag)
731 size_t required_length = MaxMediaTag + 1;
732
733 if(buffer == NULL || length == NULL || *length < required_length)
734 {
735 if(length) *length = required_length;
736 TRACE("Buffer too small for readable media tags, required %zu bytes", required_length);
737
738 TRACE("Exiting aaruf_get_readable_media_tags() = AARUF_ERROR_BUFFER_TOO_SMALL");
739 return AARUF_ERROR_BUFFER_TOO_SMALL;
740 }
741
742 // Initialize all bytes to false (0)
743 memset(buffer, 0, required_length);
744
745 // Iterate through all media tag types and mark present ones as true
746 for(int32_t tag_type = 0; tag_type <= MaxMediaTag; tag_type++)
747 {
748 mediaTagEntry *item = NULL;
749 HASH_FIND_INT(ctx->mediaTags, &tag_type, item);
750
751 if(item != NULL)
752 {
753 buffer[tag_type] = 1;
754 TRACE("Media tag type %d is present", tag_type);
755 }
756 }
757
758 *length = required_length;
759
760 TRACE("Exiting aaruf_get_readable_media_tags(%p, %p, %zu) = AARUF_STATUS_OK", context, buffer, *length);
761 return AARUF_STATUS_OK;
762}
aaruformat.h
process_metadata_block
void process_metadata_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a metadata block from the image stream.
Definition metadata.c:35
process_cicm_block
void process_cicm_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a CICM XML metadata block from the image stream.
Definition metadata.c:306
process_geometry_block
void process_geometry_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes a logical geometry block from the image stream.
Definition metadata.c:246
process_aaru_metadata_json_block
void process_aaru_metadata_json_block(aaruformat_context *ctx, const IndexEntry *entry)
Processes an Aaru metadata JSON block from the image stream during image opening.
Definition metadata.c:470
aaruf_get_readable_media_tags
int32_t aaruf_get_readable_media_tags(const void *context, uint8_t *buffer, size_t *length)
Retrieves which media tags are present in the AaruFormat image.
Definition metadata.c:706
aaruf_get_readable_sector_tags
int32_t aaruf_get_readable_sector_tags(const void *context, uint8_t *buffer, size_t *length)
Retrieves which sector tags are readable in the AaruFormat image.
Definition metadata.c:618
AARU_MAGIC
#define AARU_MAGIC
Magic identifier for AaruFormat container (ASCII "AARUFRMT").
Definition consts.h:64
AARU_CALL
#define AARU_CALL
Definition decls.h:45
AARU_EXPORT
#define AARU_EXPORT
Definition decls.h:54
GeometryBlock
@ GeometryBlock
Block containing logical geometry.
Definition enums.h:148
AaruMetadataJsonBlock
@ AaruMetadataJsonBlock
Block containing JSON version of Aaru Metadata.
Definition enums.h:159
CicmBlock
@ CicmBlock
Block containing CICM XML metadata.
Definition enums.h:151
AARUF_STATUS_OK
#define AARUF_STATUS_OK
Sector present and read without uncorrectable errors.
Definition errors.h:75
AARUF_ERROR_METADATA_NOT_PRESENT
#define AARUF_ERROR_METADATA_NOT_PRESENT
Requested metadata not present in image.
Definition errors.h:69
AARUF_ERROR_NOT_AARUFORMAT
#define AARUF_ERROR_NOT_AARUFORMAT
Input file/stream failed magic or structural validation.
Definition errors.h:40
AARUF_ERROR_BUFFER_TOO_SMALL
#define AARUF_ERROR_BUFFER_TOO_SMALL
Caller-supplied buffer insufficient for data.
Definition errors.h:49
MaxMediaTag
@ MaxMediaTag
Definition aaru.h:1011
MaxSectorTag
@ MaxSectorTag
Definition aaru.h:918
log.h
FATAL
#define FATAL(fmt,...)
Definition log.h:40
TRACE
#define TRACE(fmt,...)
Definition log.h:25
AaruMetadataJsonBlockHeader
Header for an Aaru metadata JSON block (identifier == BlockType::AaruMetadataJsonBlock).
Definition metadata.h:120
AaruMetadataJsonBlockHeader::identifier
uint32_t identifier
Block identifier, must be BlockType::AaruMetadataJsonBlock.
Definition metadata.h:121
AaruMetadataJsonBlockHeader::length
uint32_t length
Length in bytes of the Aaru metadata JSON payload that follows.
Definition metadata.h:122
CicmMetadataBlock
Header for a CICM XML metadata block (identifier == BlockType::CicmBlock).
Definition metadata.h:108
CicmMetadataBlock::length
uint32_t length
Length in bytes of the CICM metadata payload that follows.
Definition metadata.h:110
CicmMetadataBlock::identifier
uint32_t identifier
Block identifier, must be BlockType::CicmBlock.
Definition metadata.h:109
GeometryBlockHeader
Legacy CHS style logical geometry metadata (BlockType::GeometryBlock).
Definition data.h:91
GeometryBlockHeader::identifier
uint32_t identifier
Block identifier, must be BlockType::GeometryBlock.
Definition data.h:92
GeometryBlockHeader::cylinders
uint32_t cylinders
Number of cylinders.
Definition data.h:93
GeometryBlockHeader::heads
uint32_t heads
Number of heads (tracks per cylinder).
Definition data.h:94
GeometryBlockHeader::sectorsPerTrack
uint32_t sectorsPerTrack
Number of sectors per track.
Definition data.h:95
ImageInfo::ImageSize
uint64_t ImageSize
Size of the image payload in bytes (excludes headers/metadata)
Definition aaru.h:873
IndexEntry
Single index entry describing a block's type, (optional) data classification, and file offset.
Definition index.h:109
IndexEntry::blockType
uint32_t blockType
Block identifier of the referenced block (value from BlockType).
Definition index.h:110
IndexEntry::offset
uint64_t offset
Absolute byte offset in the image where the referenced block header begins.
Definition index.h:112
MetadataBlockHeader
Header for a metadata block containing offsets and lengths to UTF-16LE descriptive strings.
Definition metadata.h:69
MetadataBlockHeader::commentsLength
uint32_t commentsLength
Length in bytes (including null) of comments string.
Definition metadata.h:78
MetadataBlockHeader::mediaSequence
int32_t mediaSequence
Sequence number within a multi-disc / multi-volume set (0-based or 1-based as producer defines).
Definition metadata.h:72
MetadataBlockHeader::identifier
uint32_t identifier
Block identifier, must be BlockType::MetadataBlock.
Definition metadata.h:70
MetadataBlockHeader::mediaTitleOffset
uint32_t mediaTitleOffset
Offset to UTF-16LE media title string.
Definition metadata.h:79
MetadataBlockHeader::driveModelLength
uint32_t driveModelLength
Length in bytes (including null) of drive model string.
Definition metadata.h:94
MetadataBlockHeader::driveManufacturerLength
uint32_t driveManufacturerLength
Length in bytes (including null) of drive manufacturer string.
Definition metadata.h:92
MetadataBlockHeader::blockSize
uint32_t blockSize
Total size in bytes of the entire metadata block (header + strings).
Definition metadata.h:71
MetadataBlockHeader::driveModelOffset
uint32_t driveModelOffset
Offset to UTF-16LE drive model string.
Definition metadata.h:93
MetadataBlockHeader::mediaModelOffset
uint32_t mediaModelOffset
Offset to UTF-16LE media model string.
Definition metadata.h:83
MetadataBlockHeader::creatorOffset
uint32_t creatorOffset
Offset to UTF-16LE creator string (or undefined if creatorLength==0).
Definition metadata.h:75
MetadataBlockHeader::mediaTitleLength
uint32_t mediaTitleLength
Length in bytes (including null) of media title string.
Definition metadata.h:80
MetadataBlockHeader::mediaManufacturerOffset
uint32_t mediaManufacturerOffset
Offset to UTF-16LE media manufacturer string.
Definition metadata.h:81
MetadataBlockHeader::driveSerialNumberLength
uint32_t driveSerialNumberLength
Length in bytes (including null) of drive serial number string.
Definition metadata.h:96
MetadataBlockHeader::driveSerialNumberOffset
uint32_t driveSerialNumberOffset
Offset to UTF-16LE drive serial number string.
Definition metadata.h:95
MetadataBlockHeader::mediaManufacturerLength
uint32_t mediaManufacturerLength
Length in bytes (including null) of media manufacturer string.
Definition metadata.h:82
MetadataBlockHeader::mediaModelLength
uint32_t mediaModelLength
Length in bytes (including null) of media model string.
Definition metadata.h:84
MetadataBlockHeader::driveFirmwareRevisionOffset
uint32_t driveFirmwareRevisionOffset
Offset to UTF-16LE drive firmware revision string.
Definition metadata.h:97
MetadataBlockHeader::lastMediaSequence
int32_t lastMediaSequence
Total number of media in the set; 0 or 1 if single item.
Definition metadata.h:74
MetadataBlockHeader::commentsOffset
uint32_t commentsOffset
Offset to UTF-16LE comments string.
Definition metadata.h:77
MetadataBlockHeader::driveManufacturerOffset
uint32_t driveManufacturerOffset
Offset to UTF-16LE drive manufacturer string.
Definition metadata.h:91
MetadataBlockHeader::mediaSerialNumberOffset
uint32_t mediaSerialNumberOffset
Offset to UTF-16LE media serial number string.
Definition metadata.h:85
MetadataBlockHeader::mediaSerialNumberLength
uint32_t mediaSerialNumberLength
Length in bytes (including null) of media serial number string.
Definition metadata.h:86
MetadataBlockHeader::mediaPartNumberOffset
uint32_t mediaPartNumberOffset
Offset to UTF-16LE media part number string.
Definition metadata.h:89
MetadataBlockHeader::mediaPartNumberLength
uint32_t mediaPartNumberLength
Length in bytes (including null) of media part number string.
Definition metadata.h:90
MetadataBlockHeader::mediaBarcodeLength
uint32_t mediaBarcodeLength
Length in bytes (including null) of media barcode string.
Definition metadata.h:88
MetadataBlockHeader::creatorLength
uint32_t creatorLength
Length in bytes (including null) of creator string (0 if absent).
Definition metadata.h:76
MetadataBlockHeader::driveFirmwareRevisionLength
uint32_t driveFirmwareRevisionLength
Length in bytes (including null) of drive firmware revision string.
Definition metadata.h:98
MetadataBlockHeader::mediaBarcodeOffset
uint32_t mediaBarcodeOffset
Offset to UTF-16LE media barcode string.
Definition metadata.h:87
aaruformat_context
Master context representing an open or in‑creation Aaru image.
Definition context.h:172
aaruformat_context::media_barcode
uint8_t * media_barcode
Barcode of the media represented by the image.
Definition context.h:222
aaruformat_context::creator
uint8_t * creator
Who (person) created the image?
Definition context.h:216
aaruformat_context::cicm_block
uint8_t * cicm_block
CICM XML payload.
Definition context.h:214
aaruformat_context::cylinders
uint32_t cylinders
Cylinders of the media represented by the image.
Definition context.h:234
aaruformat_context::drive_firmware_revision
uint8_t * drive_firmware_revision
Firmware revision of the drive used to read the media represented by the image.
Definition context.h:228
aaruformat_context::media_serial_number
uint8_t * media_serial_number
Serial number of the media represented by the image.
Definition context.h:221
aaruformat_context::metadata_block_header
MetadataBlockHeader metadata_block_header
Metadata block header.
Definition context.h:230
aaruformat_context::media_sequence
int32_t media_sequence
Number in sequence for the media represented by the image.
Definition context.h:238
aaruformat_context::media_model
uint8_t * media_model
Model of the media represented by the image.
Definition context.h:220
aaruformat_context::drive_serial_number
uint8_t * drive_serial_number
Serial number of the drive used to read the media represented by the image.
Definition context.h:226
aaruformat_context::drive_manufacturer
uint8_t * drive_manufacturer
Manufacturer of the drive used to read the media represented by the image.
Definition context.h:224
aaruformat_context::cicm_block_header
CicmMetadataBlock cicm_block_header
CICM metadata header (if present).
Definition context.h:231
aaruformat_context::drive_model
uint8_t * drive_model
Model of the drive used to read the media represented by the image.
Definition context.h:225
aaruformat_context::magic
uint64_t magic
File magic (AARU_MAGIC) post-open.
Definition context.h:174
aaruformat_context::mediaTags
mediaTagEntry * mediaTags
Hash table of extra media tags (uthash root).
Definition context.h:264
aaruformat_context::geometry_block
GeometryBlockHeader geometry_block
Logical geometry block (if present).
Definition context.h:229
aaruformat_context::json_block
uint8_t * json_block
JSON metadata block payload (UTF-8).
Definition context.h:215
aaruformat_context::media_part_number
uint8_t * media_part_number
Part number of the media represented by the image.
Definition context.h:223
aaruformat_context::json_block_header
AaruMetadataJsonBlockHeader json_block_header
JSON metadata block header (if present).
Definition context.h:233
aaruformat_context::sectors_per_track
uint32_t sectors_per_track
Sectors per track of the media represented by the image (for variable image, the smallest)
Definition context.h:236
aaruformat_context::comments
uint8_t * comments
Image comments.
Definition context.h:218
aaruformat_context::heads
uint32_t heads
Heads of the media represented by the image.
Definition context.h:235
aaruformat_context::imageStream
FILE * imageStream
Underlying FILE* stream (binary mode).
Definition context.h:176
aaruformat_context::image_info
ImageInfo image_info
Exposed high-level image info summary.
Definition context.h:260
aaruformat_context::readableSectorTags
bool * readableSectorTags
Per-sector boolean array (optical tags read successfully?).
Definition context.h:263
aaruformat_context::metadata_block
uint8_t * metadata_block
Raw metadata UTF-16LE concatenated strings.
Definition context.h:213
aaruformat_context::media_title
uint8_t * media_title
Title of the media represented by the image.
Definition context.h:217
aaruformat_context::last_media_sequence
int32_t last_media_sequence
Last media of the sequence the media represented by the image corresponds to.
Definition context.h:239
aaruformat_context::media_manufacturer
uint8_t * media_manufacturer
Manufacturer of the media represented by the image.
Definition context.h:219
mediaTagEntry
Hash table entry for an arbitrary media tag (e.g., proprietary drive/medium descriptor).
Definition context.h:119