2
* Copyright (C) 1999 by Andries Brouwer
3
* Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
4
* Copyright (C) 2001 by Andreas Dilger
5
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6
* Copyright (C) 2008 Karel Zak <kzak@redhat.com>
8
* This file may be redistributed under the terms of the
9
* GNU Lesser General Public License.
19
#include "superblocks.h"
21
struct volume_descriptor {
22
struct descriptor_tag {
31
} __attribute__((packed)) tag;
34
struct anchor_descriptor {
37
} __attribute__((packed)) anchor;
39
struct primary_descriptor {
45
} __attribute__((packed)) ident;
46
} __attribute__((packed)) primary;
48
} __attribute__((packed)) type;
50
} __attribute__((packed));
52
struct volume_structure_descriptor {
56
} __attribute__((packed));
58
#define UDF_VSD_OFFSET 0x8000
60
static int probe_udf(blkid_probe pr, const struct blkid_idmag *mag)
62
struct volume_descriptor *vd;
63
struct volume_structure_descriptor *vsd;
70
/* search Volume Sequence Descriptor (VSD) to get the logical
71
* block size of the volume */
72
for (bs = 0x800; bs < 0x8000; bs += 0x800) {
73
vsd = (struct volume_structure_descriptor *)
74
blkid_probe_get_buffer(pr,
79
if (vsd->id[0] != '\0')
85
/* search the list of VSDs for a NSR descriptor */
86
for (b = 0; b < 64; b++) {
87
vsd = (struct volume_structure_descriptor *)
88
blkid_probe_get_buffer(pr,
89
UDF_VSD_OFFSET + (b * bs),
93
if (vsd->id[0] == '\0')
95
if (memcmp(vsd->id, "NSR02", 5) == 0)
97
if (memcmp(vsd->id, "NSR03", 5) == 0)
103
/* read Anchor Volume Descriptor (AVDP) */
104
vd = (struct volume_descriptor *)
105
blkid_probe_get_buffer(pr, 256 * bs, sizeof(*vd));
109
type = le16_to_cpu(vd->tag.id);
110
if (type != 2) /* TAG_ID_AVDP */
113
/* get desriptor list address and block count */
114
count = le32_to_cpu(vd->type.anchor.length) / bs;
115
loc = le32_to_cpu(vd->type.anchor.location);
117
/* pick the primary descriptor from the list */
118
for (b = 0; b < count; b++) {
119
vd = (struct volume_descriptor *)
120
blkid_probe_get_buffer(pr, (loc + b) * bs, sizeof(*vd));
124
type = le16_to_cpu(vd->tag.id);
127
if (le32_to_cpu(vd->tag.location) != loc + b)
129
if (type == 1) { /* TAG_ID_PVD */
130
uint8_t clen = vd->type.primary.ident.clen;
133
blkid_probe_set_label(pr,
134
vd->type.primary.ident.c, 31);
136
blkid_probe_set_utf8label(pr,
137
vd->type.primary.ident.c,
138
31, BLKID_ENC_UTF16BE);
146
const struct blkid_idinfo udf_idinfo =
149
.usage = BLKID_USAGE_FILESYSTEM,
150
.probefunc = probe_udf,
151
.flags = BLKID_IDINFO_TOLERANT,
154
{ .magic = "BEA01", .len = 5, .kboff = 32, .sboff = 1 },
155
{ .magic = "BOOT2", .len = 5, .kboff = 32, .sboff = 1 },
156
{ .magic = "CD001", .len = 5, .kboff = 32, .sboff = 1 },
157
{ .magic = "CDW02", .len = 5, .kboff = 32, .sboff = 1 },
158
{ .magic = "NSR02", .len = 5, .kboff = 32, .sboff = 1 },
159
{ .magic = "NSR03", .len = 5, .kboff = 32, .sboff = 1 },
160
{ .magic = "TEA01", .len = 5, .kboff = 32, .sboff = 1 },