1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "volume_id_internal.h"
22
23#define ISO_SUPERBLOCK_OFFSET 0x8000
24#define ISO_SECTOR_SIZE 0x800
25#define ISO_VD_OFFSET (ISO_SUPERBLOCK_OFFSET + ISO_SECTOR_SIZE)
26#define ISO_VD_PRIMARY 0x1
27#define ISO_VD_SUPPLEMENTARY 0x2
28#define ISO_VD_END 0xff
29#define ISO_VD_MAX 16
30
31struct iso_volume_descriptor {
32 uint8_t vd_type;
33 uint8_t vd_id[5];
34 uint8_t vd_version;
35 uint8_t flags;
36 uint8_t system_id[32];
37 uint8_t volume_id[32];
38 uint8_t unused[8];
39 uint8_t space_size[8];
40 uint8_t escape_sequences[8];
41} __attribute__((__packed__));
42
43struct high_sierra_volume_descriptor {
44 uint8_t foo[8];
45 uint8_t type;
46 uint8_t id[4];
47 uint8_t version;
48} __attribute__((__packed__));
49
50int volume_id_probe_iso9660(struct volume_id *id, uint64_t off)
51{
52 uint8_t *buf;
53 struct iso_volume_descriptor *is;
54 struct high_sierra_volume_descriptor *hs;
55
56 dbg("probing at offset 0x%llx", (unsigned long long) off);
57
58 buf = volume_id_get_buffer(id, off + ISO_SUPERBLOCK_OFFSET, 0x200);
59 if (buf == NULL)
60 return -1;
61
62 is = (struct iso_volume_descriptor *) buf;
63
64 if (memcmp(is->vd_id, "CD001", 5) == 0) {
65 int vd_offset;
66 int i;
67
68 dbg("read label from PVD");
69
70 volume_id_set_label_string(id, is->volume_id, 32);
71
72 dbg("looking for SVDs");
73 vd_offset = ISO_VD_OFFSET;
74 for (i = 0; i < ISO_VD_MAX; i++) {
75 uint8_t svd_label[64];
76
77 is = volume_id_get_buffer(id, off + vd_offset, 0x200);
78 if (is == NULL || is->vd_type == ISO_VD_END)
79 break;
80 if (is->vd_type != ISO_VD_SUPPLEMENTARY)
81 continue;
82
83 dbg("found SVD at offset 0x%llx", (unsigned long long) (off + vd_offset));
84 if (memcmp(is->escape_sequences, "%/@", 3) == 0
85 || memcmp(is->escape_sequences, "%/C", 3) == 0
86 || memcmp(is->escape_sequences, "%/E", 3) == 0
87 ) {
88 dbg("Joliet extension found");
89 volume_id_set_unicode16((char *)svd_label, sizeof(svd_label), is->volume_id, BE, 32);
90 if (memcmp(id->label, svd_label, 16) == 0) {
91 dbg("SVD label is identical, use the possibly longer PVD one");
92 break;
93 }
94
95
96 volume_id_set_label_string(id, svd_label, 32);
97
98 goto found;
99 }
100 vd_offset += ISO_SECTOR_SIZE;
101 }
102 goto found;
103 }
104
105 hs = (struct high_sierra_volume_descriptor *) buf;
106
107 if (memcmp(hs->id, "CDROM", 5) == 0) {
108
109 goto found;
110 }
111
112 return -1;
113
114 found:
115
116
117
118 return 0;
119}
120