Skip to content

Commit

Permalink
partitions: dos: Treat all extended partition types equally
Browse files Browse the repository at this point in the history
Creating logical DOS partitions with fdisk (Fedora 27, fdisk from
util-linux 2.30.2) results in extended partition of type 0x05 being
created on the device. Partitioned like this, device is succesfully
recognized by Linux, but, due to algorithm in dos_partition(), not
Barebox.

Looking closer at the actual contents of MBR shows that while marked
as "Extended partition with CHS addressing" that partition still have
all of the LBA adressed fields filled correctly.

Given the above and the fact that similar code in Linux
kernel (block/partitions/msdos.c) does not make a distinction between
types 0x0f and 0x05, port Linux's is_extended_partition() and convert
the code to treat types 0x05, 0x0f and 0x85 the same way.

Signed-off-by: Andrey Smirnov <[email protected]>
Signed-off-by: Sascha Hauer <[email protected]>
  • Loading branch information
ndreys authored and saschahauer committed Jan 22, 2018
1 parent bc0851d commit c9c58ef
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions common/partitions/dos.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@

#include "parser.h"


enum {
/* These three have identical behaviour; use the second one if DOS FDISK gets
confused about extended/logical partitions starting past cylinder 1023. */
DOS_EXTENDED_PARTITION = 5,
LINUX_EXTENDED_PARTITION = 0x85,
WIN98_EXTENDED_PARTITION = 0x0f,
};

static inline int is_extended_partition(struct partition *p)
{
return (p->dos_partition_type == DOS_EXTENDED_PARTITION ||
p->dos_partition_type == WIN98_EXTENDED_PARTITION ||
p->dos_partition_type == LINUX_EXTENDED_PARTITION);
}

/**
* Guess the size of the disk, based on the partition table entries
* @param dev device to create partitions for
Expand Down Expand Up @@ -212,13 +228,8 @@ static void dos_partition(void *buf, struct block_device *blk,
sprintf(pd->parts[n].partuuid, "%08x-%02d",
signature, i + 1);
pd->used_entries++;
/*
* Partitions of type 0x05 and 0x0f (and some more)
* contain extended partitions. Only check for type 0x0f
* here as this is the easiest to parse and common
* enough.
*/
if (pentry.dos_partition_type == 0x0f) {

if (is_extended_partition(&pentry)) {
if (!extended_partition)
extended_partition = &pd->parts[n];
else
Expand Down

0 comments on commit c9c58ef

Please sign in to comment.