2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
26 #include "libvolume_id.h"
29 #define ISO_SUPERBLOCK_OFFSET 0x8000
30 #define ISO_SECTOR_SIZE 0x800
31 #define ISO_VD_OFFSET (ISO_SUPERBLOCK_OFFSET + ISO_SECTOR_SIZE)
32 #define ISO_VD_PRIMARY 0x1
33 #define ISO_VD_SUPPLEMENTARY 0x2
34 #define ISO_VD_END 0xff
37 struct iso_volume_descriptor {
42 uint8_t system_id[32];
43 uint8_t volume_id[32];
45 uint8_t space_size[8];
46 uint8_t escape_sequences[8];
49 struct high_sierra_volume_descriptor {
56 int volume_id_probe_iso9660(struct volume_id *id, uint64_t off, uint64_t size)
59 struct iso_volume_descriptor *is;
60 struct high_sierra_volume_descriptor *hs;
62 info("probing at offset 0x%llx", (unsigned long long) off);
64 buf = volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200);
68 is = (struct iso_volume_descriptor *) buf;
70 if (memcmp(is->id, "CD001", 5) == 0) {
74 dbg("read label from PVD");
75 volume_id_set_label_raw(id, is->volume_id, 32);
76 volume_id_set_label_string(id, is->volume_id, 32);
78 dbg("looking for SVDs");
79 vd_offset = ISO_VD_OFFSET;
80 for (i = 0; i < ISO_VD_MAX; i++) {
81 uint8_t svd_label[64];
83 is = (struct iso_volume_descriptor *) volume_id_get_buffer(id, off + vd_offset, 0x200);
84 if (is == NULL || is->type == ISO_VD_END)
86 if (is->type != ISO_VD_SUPPLEMENTARY)
89 dbg("found SVD at offset 0x%llx", (unsigned long long) (off + vd_offset));
90 if (memcmp(is->escape_sequences, "%/@", 3) == 0||
91 memcmp(is->escape_sequences, "%/C", 3) == 0||
92 memcmp(is->escape_sequences, "%/E", 3) == 0) {
93 dbg("Joliet extension found");
94 volume_id_set_unicode16(svd_label, sizeof(svd_label), is->volume_id, BE, 32);
95 if (memcmp(id->label, svd_label, 16) == 0) {
96 dbg("SVD label is identical, use the possibly longer PVD one");
100 volume_id_set_label_raw(id, is->volume_id, 32);
101 volume_id_set_label_string(id, svd_label, 32);
102 strcpy(id->type_version, "Joliet Extension");
105 vd_offset += ISO_SECTOR_SIZE;
110 hs = (struct high_sierra_volume_descriptor *) buf;
112 if (memcmp(hs->id, "CDROM", 5) == 0) {
113 strcpy(id->type_version, "High Sierra");
120 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
121 id->type = "iso9660";