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
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "libvolume_id.h"
32 #include "libvolume_id-private.h"
34 struct volume_descriptor {
35 struct descriptor_tag {
46 struct anchor_descriptor {
50 struct primary_descriptor {
61 struct volume_structure_descriptor {
67 #define UDF_VSD_OFFSET 0x8000
69 int volume_id_probe_udf(struct volume_id *id, uint64_t off, uint64_t size)
71 struct volume_descriptor *vd;
72 struct volume_structure_descriptor *vsd;
80 info("probing at offset 0x%llx\n", (unsigned long long) off);
82 vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET, 0x200);
86 if (memcmp(vsd->id, "NSR02", 5) == 0)
88 if (memcmp(vsd->id, "NSR03", 5) == 0)
90 if (memcmp(vsd->id, "BEA01", 5) == 0)
92 if (memcmp(vsd->id, "BOOT2", 5) == 0)
94 if (memcmp(vsd->id, "CD001", 5) == 0)
96 if (memcmp(vsd->id, "CDW02", 5) == 0)
98 if (memcmp(vsd->id, "TEA03", 5) == 0)
103 /* search the next VSD to get the logical block size of the volume */
104 for (bs = 0x800; bs < 0x8000; bs += 0x800) {
105 vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET + bs, 0x800);
108 dbg("test for blocksize: 0x%x\n", bs);
109 if (vsd->id[0] != '\0')
115 /* search the list of VSDs for a NSR descriptor */
116 for (b = 0; b < 64; b++) {
117 vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET + (b * bs), 0x800);
121 dbg("vsd: %c%c%c%c%c\n",
122 vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]);
124 if (vsd->id[0] == '\0')
126 if (memcmp(vsd->id, "NSR02", 5) == 0)
128 if (memcmp(vsd->id, "NSR03", 5) == 0)
134 /* read anchor volume descriptor */
135 vd = (struct volume_descriptor *) volume_id_get_buffer(id, off + (256 * bs), 0x200);
139 type = le16_to_cpu(vd->tag.id);
140 if (type != 2) /* TAG_ID_AVDP */
143 /* get desriptor list address and block count */
144 count = le32_to_cpu(vd->type.anchor.length) / bs;
145 loc = le32_to_cpu(vd->type.anchor.location);
146 dbg("0x%x descriptors starting at logical secor 0x%x\n", count, loc);
148 /* pick the primary descriptor from the list */
149 for (b = 0; b < count; b++) {
150 vd = (struct volume_descriptor *) volume_id_get_buffer(id, off + ((loc + b) * bs), 0x200);
154 type = le16_to_cpu(vd->tag.id);
155 dbg("descriptor type %i\n", type);
160 if (le32_to_cpu(vd->tag.location) != loc + b)
163 if (type == 1) /* TAG_ID_PVD */
169 volume_id_set_label_raw(id, &(vd->type.primary.ident.clen), 32);
171 clen = vd->type.primary.ident.clen;
172 dbg("label string charsize=%i bit\n", clen);
174 volume_id_set_label_string(id, vd->type.primary.ident.c, 31);
176 volume_id_set_label_unicode16(id, vd->type.primary.ident.c, BE,31);
179 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);