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 struct volume_descriptor {
30 struct descriptor_tag {
41 struct anchor_descriptor {
45 struct primary_descriptor {
56 struct volume_structure_descriptor {
62 #define UDF_VSD_OFFSET 0x8000
64 int volume_id_probe_udf(struct volume_id *id, uint64_t off, uint64_t size)
66 struct volume_descriptor *vd;
67 struct volume_structure_descriptor *vsd;
75 info("probing at offset 0x%llx", (unsigned long long) off);
77 vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET, 0x200);
81 if (memcmp(vsd->id, "NSR02", 5) == 0)
83 if (memcmp(vsd->id, "NSR03", 5) == 0)
85 if (memcmp(vsd->id, "BEA01", 5) == 0)
87 if (memcmp(vsd->id, "BOOT2", 5) == 0)
89 if (memcmp(vsd->id, "CD001", 5) == 0)
91 if (memcmp(vsd->id, "CDW02", 5) == 0)
93 if (memcmp(vsd->id, "TEA03", 5) == 0)
98 /* search the next VSD to get the logical block size of the volume */
99 for (bs = 0x800; bs < 0x8000; bs += 0x800) {
100 vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET + bs, 0x800);
103 dbg("test for blocksize: 0x%x", bs);
104 if (vsd->id[0] != '\0')
110 /* search the list of VSDs for a NSR descriptor */
111 for (b = 0; b < 64; b++) {
112 vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET + (b * bs), 0x800);
116 dbg("vsd: %c%c%c%c%c",
117 vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]);
119 if (vsd->id[0] == '\0')
121 if (memcmp(vsd->id, "NSR02", 5) == 0)
123 if (memcmp(vsd->id, "NSR03", 5) == 0)
129 /* read anchor volume descriptor */
130 vd = (struct volume_descriptor *) volume_id_get_buffer(id, off + (256 * bs), 0x200);
134 type = le16_to_cpu(vd->tag.id);
135 if (type != 2) /* TAG_ID_AVDP */
138 /* get desriptor list address and block count */
139 count = le32_to_cpu(vd->type.anchor.length) / bs;
140 loc = le32_to_cpu(vd->type.anchor.location);
141 dbg("0x%x descriptors starting at logical secor 0x%x", count, loc);
143 /* pick the primary descriptor from the list */
144 for (b = 0; b < count; b++) {
145 vd = (struct volume_descriptor *) volume_id_get_buffer(id, off + ((loc + b) * bs), 0x200);
149 type = le16_to_cpu(vd->tag.id);
150 dbg("descriptor type %i", type);
155 if (le32_to_cpu(vd->tag.location) != loc + b)
158 if (type == 1) /* TAG_ID_PVD */
164 volume_id_set_label_raw(id, &(vd->type.primary.ident.clen), 32);
166 clen = vd->type.primary.ident.clen;
167 dbg("label string charsize=%i bit", clen);
169 volume_id_set_label_string(id, vd->type.primary.ident.c, 31);
171 volume_id_set_label_unicode16(id, vd->type.primary.ident.c, BE,31);
174 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);