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 "volume_id.h"
31 struct volume_descriptor {
32 struct descriptor_tag {
41 } __attribute__((__packed__)) tag;
43 struct anchor_descriptor {
46 } __attribute__((__packed__)) anchor;
47 struct primary_descriptor {
53 } __attribute__((__packed__)) ident;
54 } __attribute__((__packed__)) primary;
55 } __attribute__((__packed__)) type;
56 } __attribute__((__packed__));
58 struct volume_structure_descriptor {
62 } __attribute__((__packed__));
64 #define UDF_VSD_OFFSET 0x8000
66 int volume_id_probe_udf(struct volume_id *id, uint64_t off)
68 struct volume_descriptor *vd;
69 struct volume_structure_descriptor *vsd;
77 dbg("probing at offset 0x%llx", (unsigned long long) off);
79 vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET, 0x200);
83 if (memcmp(vsd->id, "NSR02", 5) == 0)
85 if (memcmp(vsd->id, "NSR03", 5) == 0)
87 if (memcmp(vsd->id, "BEA01", 5) == 0)
89 if (memcmp(vsd->id, "BOOT2", 5) == 0)
91 if (memcmp(vsd->id, "CD001", 5) == 0)
93 if (memcmp(vsd->id, "CDW02", 5) == 0)
95 if (memcmp(vsd->id, "TEA03", 5) == 0)
100 /* search the next VSD to get the logical block size of the volume */
101 for (bs = 0x800; bs < 0x8000; bs += 0x800) {
102 vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET + bs, 0x800);
105 dbg("test for blocksize: 0x%x", bs);
106 if (vsd->id[0] != '\0')
112 /* search the list of VSDs for a NSR descriptor */
113 for (b = 0; b < 64; b++) {
114 vsd = (struct volume_structure_descriptor *) volume_id_get_buffer(id, off + UDF_VSD_OFFSET + (b * bs), 0x800);
118 dbg("vsd: %c%c%c%c%c",
119 vsd->id[0], vsd->id[1], vsd->id[2], vsd->id[3], vsd->id[4]);
121 if (vsd->id[0] == '\0')
123 if (memcmp(vsd->id, "NSR02", 5) == 0)
125 if (memcmp(vsd->id, "NSR03", 5) == 0)
131 /* read anchor volume descriptor */
132 vd = (struct volume_descriptor *) volume_id_get_buffer(id, off + (256 * bs), 0x200);
136 type = le16_to_cpu(vd->tag.id);
137 if (type != 2) /* TAG_ID_AVDP */
140 /* get desriptor list address and block count */
141 count = le32_to_cpu(vd->type.anchor.length) / bs;
142 loc = le32_to_cpu(vd->type.anchor.location);
143 dbg("0x%x descriptors starting at logical secor 0x%x", count, loc);
145 /* pick the primary descriptor from the list */
146 for (b = 0; b < count; b++) {
147 vd = (struct volume_descriptor *) volume_id_get_buffer(id, off + ((loc + b) * bs), 0x200);
151 type = le16_to_cpu(vd->tag.id);
152 dbg("descriptor type %i", type);
157 if (le32_to_cpu(vd->tag.location) != loc + b)
160 if (type == 1) /* TAG_ID_PVD */
166 volume_id_set_label_raw(id, &(vd->type.primary.ident.clen), 32);
168 clen = vd->type.primary.ident.clen;
169 dbg("label string charsize=%i bit", clen);
171 volume_id_set_label_string(id, vd->type.primary.ident.c, 31);
173 volume_id_set_label_unicode16(id, vd->type.primary.ident.c, BE,31);
176 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);