summaryrefslogtreecommitdiff
path: root/disk
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2019-11-01 09:23:21 -0400
committerTom Rini <[email protected]>2019-11-01 09:23:21 -0400
commit82679624f9aa6d1be733c46f3555d5166b6f5b72 (patch)
tree8a99cf79bc520b833e155094ef134c0526b1f005 /disk
parent412326d1bc2d346d7b4faad6fa547eaf065681a2 (diff)
parent5d80a1a93d42c8325d65516cc654ff6a9ceec58a (diff)
Merge branch '2019-10-30-master-imports'
- Migrate test.py to use python3 and current pytest. - NVMe bugfixes - Assorted other fixes - Android AVB updates.
Diffstat (limited to 'disk')
-rw-r--r--disk/part_dos.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 8ddc13b50c6..83ff40d310a 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -67,28 +67,39 @@ static int test_block_type(unsigned char *buffer)
{
int slot;
struct dos_partition *p;
+ int part_count = 0;
if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||
(buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) {
return (-1);
} /* no DOS Signature at all */
p = (struct dos_partition *)&buffer[DOS_PART_TBL_OFFSET];
- for (slot = 0; slot < 3; slot++) {
- if (p->boot_ind != 0 && p->boot_ind != 0x80) {
- if (!slot &&
- (strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],
- "FAT", 3) == 0 ||
- strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET],
- "FAT32", 5) == 0)) {
- return DOS_PBR; /* is PBR */
- } else {
- return -1;
- }
- }
+
+ /* Check that the boot indicators are valid and count the partitions. */
+ for (slot = 0; slot < 4; ++slot, ++p) {
+ if (p->boot_ind != 0 && p->boot_ind != 0x80)
+ break;
+ if (p->sys_ind)
+ ++part_count;
}
- return DOS_MBR; /* Is MBR */
-}
+ /*
+ * If the partition table is invalid or empty,
+ * check if this is a DOS PBR
+ */
+ if (slot != 4 || !part_count) {
+ if (!strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],
+ "FAT", 3) ||
+ !strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET],
+ "FAT32", 5))
+ return DOS_PBR; /* This is a DOS PBR and not an MBR */
+ }
+ if (slot == 4)
+ return DOS_MBR; /* This is an DOS MBR */
+
+ /* This is neither a DOS MBR nor a DOS PBR */
+ return -1;
+}
static int part_test_dos(struct blk_desc *dev_desc)
{