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
20 //config:### config FEATURE_VOLUMEID_MSDOS
21 //config:### bool "msdos filesystem"
22 //config:### default y
23 //config:### depends on VOLUMEID
25 //kbuild:### lib-$(CONFIG_FEATURE_VOLUMEID_MSDOS) += msdos.o
27 #include "volume_id_internal.h"
29 struct msdos_partition_entry {
42 #define MSDOS_PARTTABLE_OFFSET 0x1be
43 #define MSDOS_SIG_OFF 0x1fe
45 #define DOS_EXTENDED_PARTITION 0x05
46 #define LINUX_EXTENDED_PARTITION 0x85
47 #define WIN98_EXTENDED_PARTITION 0x0f
48 #define LINUX_RAID_PARTITION 0xfd
49 #define is_extended(type) \
50 (type == DOS_EXTENDED_PARTITION || \
51 type == WIN98_EXTENDED_PARTITION || \
52 type == LINUX_EXTENDED_PARTITION)
53 #define is_raid(type) \
54 (type == LINUX_RAID_PARTITION)
56 int FAST_FUNC volume_id_probe_msdos_part_table(struct volume_id *id, uint64_t off)
62 uint64_t extended = 0;
67 struct msdos_partition_entry *part;
68 struct volume_id_partition *p;
70 dbg("probing at offset 0x%llx", (unsigned long long) off);
72 buf = volume_id_get_buffer(id, off, 0x200);
76 if (buf[MSDOS_SIG_OFF] != 0x55 || buf[MSDOS_SIG_OFF + 1] != 0xaa)
79 /* check flags on all entries for a valid partition table */
80 part = (struct msdos_partition_entry*) &buf[MSDOS_PARTTABLE_OFFSET];
81 for (i = 0; i < 4; i++) {
82 if (part[i].boot_ind != 0
83 && part[i].boot_ind != 0x80
88 if (part[i].nr_sects != 0)
94 if (id->partitions != NULL)
96 id->partitions = xzalloc(VOLUME_ID_PARTITIONS_MAX *
97 sizeof(struct volume_id_partition));
99 for (i = 0; i < 4; i++) {
100 poff = (uint64_t) le32_to_cpu(part[i].start_sect) * BSIZE;
101 plen = (uint64_t) le32_to_cpu(part[i].nr_sects) * BSIZE;
106 p = &id->partitions[i];
108 // p->pt_type_raw = part[i].sys_ind;
110 if (is_extended(part[i].sys_ind)) {
111 dbg("found extended partition at 0x%llx", (unsigned long long) poff);
112 // volume_id_set_usage_part(p, VOLUME_ID_PARTITIONTABLE);
113 // p->type = "msdos_extended_partition";
115 extended = off + poff;
117 dbg("found 0x%x data partition at 0x%llx, len 0x%llx",
118 part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen);
120 // if (is_raid(part[i].sys_ind))
121 // volume_id_set_usage_part(p, VOLUME_ID_RAID);
123 // volume_id_set_usage_part(p, VOLUME_ID_UNPROBED);
126 // p->pt_off = off + poff;
128 id->partition_count = i+1;
135 /* follow extended partition chain and add data partitions */
138 dbg("extended chain limit reached");
142 buf = volume_id_get_buffer(id, current, 0x200);
146 part = (struct msdos_partition_entry*) &buf[MSDOS_PARTTABLE_OFFSET];
148 if (buf[MSDOS_SIG_OFF] != 0x55 || buf[MSDOS_SIG_OFF + 1] != 0xaa)
153 for (i = 0; i < 4; i++) {
154 poff = (uint64_t) le32_to_cpu(part[i].start_sect) * BSIZE;
155 plen = (uint64_t) le32_to_cpu(part[i].nr_sects) * BSIZE;
160 if (is_extended(part[i].sys_ind)) {
161 dbg("found extended partition at 0x%llx", (unsigned long long) poff);
163 next = extended + poff;
165 dbg("found 0x%x data partition at 0x%llx, len 0x%llx",
166 part[i].sys_ind, (unsigned long long) poff, (unsigned long long) plen);
168 /* we always start at the 5th entry */
169 // while (id->partition_count < 4)
170 // volume_id_set_usage_part(&id->partitions[id->partition_count++], VOLUME_ID_UNUSED);
171 if (id->partition_count < 4)
172 id->partition_count = 4;
174 // p = &id->partitions[id->partition_count];
176 // if (is_raid(part[i].sys_ind))
177 // volume_id_set_usage_part(p, VOLUME_ID_RAID);
179 // volume_id_set_usage_part(p, VOLUME_ID_UNPROBED);
181 // p->pt_off = current + poff;
183 id->partition_count++;
185 // p->pt_type_raw = part[i].sys_ind;
187 if (id->partition_count >= VOLUME_ID_PARTITIONS_MAX) {
188 dbg("too many partitions");
197 // volume_id_set_usage(id, VOLUME_ID_PARTITIONTABLE);
198 // id->type = "msdos_partition_table";