2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "volume_id_internal.h"
23 struct volume_descriptor
{
24 struct descriptor_tag
{
33 } __attribute__((__packed__
)) tag
;
35 struct anchor_descriptor
{
38 } __attribute__((__packed__
)) anchor
;
39 struct primary_descriptor
{
45 } __attribute__((__packed__
)) ident
;
46 } __attribute__((__packed__
)) primary
;
47 } __attribute__((__packed__
)) type
;
48 } __attribute__((__packed__
));
50 struct volume_structure_descriptor
{
54 } __attribute__((__packed__
));
56 #define UDF_VSD_OFFSET 0x8000
58 int volume_id_probe_udf(struct volume_id
*id
/*,uint64_t off*/)
60 #define off ((uint64_t)0)
61 struct volume_descriptor
*vd
;
62 struct volume_structure_descriptor
*vsd
;
70 dbg("probing at offset 0x%llx", (unsigned long long) off
);
72 vsd
= volume_id_get_buffer(id
, off
+ UDF_VSD_OFFSET
, 0x200);
76 if (memcmp(vsd
->id
, "NSR02", 5) == 0)
78 if (memcmp(vsd
->id
, "NSR03", 5) == 0)
80 if (memcmp(vsd
->id
, "BEA01", 5) == 0)
82 if (memcmp(vsd
->id
, "BOOT2", 5) == 0)
84 if (memcmp(vsd
->id
, "CD001", 5) == 0)
86 if (memcmp(vsd
->id
, "CDW02", 5) == 0)
88 if (memcmp(vsd
->id
, "TEA03", 5) == 0)
93 /* search the next VSD to get the logical block size of the volume */
94 for (bs
= 0x800; bs
< 0x8000; bs
+= 0x800) {
95 vsd
= volume_id_get_buffer(id
, off
+ UDF_VSD_OFFSET
+ bs
, 0x800);
98 dbg("test for blocksize: 0x%x", bs
);
99 if (vsd
->id
[0] != '\0')
105 /* search the list of VSDs for a NSR descriptor */
106 for (b
= 0; b
< 64; b
++) {
107 vsd
= volume_id_get_buffer(id
, off
+ UDF_VSD_OFFSET
+ (b
* bs
), 0x800);
111 dbg("vsd: %c%c%c%c%c",
112 vsd
->id
[0], vsd
->id
[1], vsd
->id
[2], vsd
->id
[3], vsd
->id
[4]);
114 if (vsd
->id
[0] == '\0')
116 if (memcmp(vsd
->id
, "NSR02", 5) == 0)
118 if (memcmp(vsd
->id
, "NSR03", 5) == 0)
124 /* read anchor volume descriptor */
125 vd
= volume_id_get_buffer(id
, off
+ (256 * bs
), 0x200);
129 type
= le16_to_cpu(vd
->tag
.id
);
130 if (type
!= 2) /* TAG_ID_AVDP */
133 /* get desriptor list address and block count */
134 count
= le32_to_cpu(vd
->type
.anchor
.length
) / bs
;
135 loc
= le32_to_cpu(vd
->type
.anchor
.location
);
136 dbg("0x%x descriptors starting at logical secor 0x%x", count
, loc
);
138 /* pick the primary descriptor from the list */
139 for (b
= 0; b
< count
; b
++) {
140 vd
= volume_id_get_buffer(id
, off
+ ((loc
+ b
) * bs
), 0x200);
144 type
= le16_to_cpu(vd
->tag
.id
);
145 dbg("descriptor type %i", type
);
150 if (le32_to_cpu(vd
->tag
.location
) != loc
+ b
)
153 if (type
== 1) /* TAG_ID_PVD */
159 // volume_id_set_label_raw(id, &(vd->type.primary.ident.clen), 32);
161 clen
= vd
->type
.primary
.ident
.clen
;
162 dbg("label string charsize=%i bit", clen
);
164 volume_id_set_label_string(id
, vd
->type
.primary
.ident
.c
, 31);
166 volume_id_set_label_unicode16(id
, vd
->type
.primary
.ident
.c
, BE
, 31);
169 // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);