Skip to content

Commit

Permalink
kernel - Change legacy MBR partition type from 0xA5 to 0x6C
Browse files Browse the repository at this point in the history
* Should have done this years ago but finally change the legacy MBR
  partition type DragonFlyBSD uses from 0xA5 (which was shared with
  FreeBSD), to something different 0x6C.

* Makes it less confusing for Grub.

* Does not change EFI boot, which uses 16-byte UUIDs (we already have
  our own) and does not use 8-bit partition ids.

* Boot code and kernel now recognize both 0xA5 and 0x6C.  Existing users
  do *NOT* need to reinstall their boot code.
  • Loading branch information
Matthew Dillon committed Sep 12, 2017
1 parent 2116b62 commit 794d80a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 32 deletions.
5 changes: 3 additions & 2 deletions sbin/fdisk/fdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ struct part_type
,{0x63, "ISC UNIX, other System V/386, GNU HURD or Mach"}
,{0x64, "Novell Netware 2.xx"}
,{0x65, "Novell Netware 3.xx"}
,{0x6C, "DragonFlyBSD"}
,{0x70, "DiskSecure Multi-Boot"}
,{0x75, "PCIX"}
,{0x77, "QNX4.x"}
Expand Down Expand Up @@ -363,7 +364,7 @@ main(int argc, char *argv[])
read_s0();
reset_boot();
partp = (struct dos_partition *) (&mboot.parts[0]);
partp->dp_typ = DOSPTYP_386BSD;
partp->dp_typ = DOSPTYP_DFLYBSD;
partp->dp_flag = ACTIVE;
partp->dp_start = dos_sectors;
if (disksecs - dos_sectors > 0xFFFFFFFFU) {
Expand Down Expand Up @@ -559,7 +560,7 @@ struct dos_partition *partp = (struct dos_partition *) (&mboot.parts[3]);

init_boot();

partp->dp_typ = DOSPTYP_386BSD;
partp->dp_typ = DOSPTYP_DFLYBSD;
partp->dp_flag = ACTIVE;
start = roundup(start, dos_sectors);
if (start == 0)
Expand Down
8 changes: 4 additions & 4 deletions sys/boot/pc32/boot0/boot0.S
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ tables:
/*
* These values indicate bootable types we know the names of.
*/
.byte 0x1, 0x6, 0x7, 0xb, 0xc, 0xe, 0x83
.byte 0x9f, 0xa5, 0xa6, 0xa9
.byte 0x1, 0x6, 0x7, 0xc, 0xe, 0x6c, 0x83, 0x9f
.byte 0xa5, 0xa6, 0xa9

/*
* These are offsets that match the known names above and
Expand All @@ -529,10 +529,10 @@ tables:
.byte os_dos-. # Windows
.byte os_dos-. # Windows
.byte os_dos-. # Windows
.byte os_dos-. # Windows
.byte os_dfbsd-. # DragonFly (new)
.byte os_linux-. # Linux
.byte os_bsd-. # BSD/OS
.byte os_dfbsd-. # DragonFly/FreeBSD
.byte os_dfbsd-. # DragonFly (old) / FreeBSD
.byte os_bsd-. # OpenBSD
.byte os_bsd-. # NetBSD

Expand Down
23 changes: 10 additions & 13 deletions sys/boot/pc32/boot2/boot1.S
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
.set PRT_OFF,0x1be // Partition offset
.set PRT_NUM,0x4 // Partitions
.set PRT_BSD,0xa5 // Partition type
.set PRT_DFLY,0x6c // Partition type

// Flag Bits
.set FL_PACKET,0x80 // Packet mode
Expand Down Expand Up @@ -178,9 +179,11 @@ main: cld // String ops inc
mov $0x1,%cx // Two passes
main.1: mov $BOOT2_LOAD_BUF+PRT_OFF,%si // Partition table
movb $0x1,%dh // Partition
main.2: cmpb $PRT_BSD,0x4(%si) // Our partition type?
main.2: cmpb $PRT_BSD,0x4(%si) // FreeBSD / old DFly
je main.2a
cmpb $PRT_DFLY,0x4(%si) // New DFly
jne main.3 // No
jcxz main.5 // If second pass
main.2a: jcxz main.5 // If second pass
testb $0x80,(%si) // Active?
jnz main.5 // Yes
main.3: add $0x10,%si // Next entry
Expand All @@ -193,7 +196,6 @@ main.3: add $0x10,%si // Next entry
// If we get here, we didn't find any FreeBSD slices at all, so print an
// error message and die.
//
mov $msg_part,%si // Message
jmp error // Error
//
// Floppies use partition 0 of drive 0.
Expand Down Expand Up @@ -299,14 +301,12 @@ nread_alt:
push %cs // Read from
callw xread.1 // disk
jnc return // If success, return
mov $msg_read,%si // Otherwise, set the error
// message and fall through to
// the error routine
//
// Print out the error message pointed to by %ds:(%si) followed
// by a prompt, wait for a keypress, and then reboot the machine.

// Print that an error occured (no room to determine which error
// occured) and the prompt. Then wait for a keypress, then reboot the
// machine.
//
error: callw putstr // Display message
error:
mov $prompt,%si // Display
callw putstr // prompt
xorb %ah,%ah // BIOS: Get
Expand Down Expand Up @@ -440,9 +440,6 @@ read.6: retw // To caller

// Messages

msg_read: .asciz "Read"
msg_part: .asciz "Boot"

prompt: .asciz " error\r\n"

flags: .byte FLAGS // Flags
Expand Down
5 changes: 3 additions & 2 deletions sys/boot/pc32/boot2/boot2.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,8 @@ dskprobe(void)
sl = dsk.slice;
if (sl < BASE_SLICE) {
for (i = 0; i < NDOSPART; i++)
if (dp[i].dp_typ == DOSPTYP_386BSD &&
if ((dp[i].dp_typ == DOSPTYP_386BSD ||
dp[i].dp_typ == DOSPTYP_DFLYBSD) &&
(dp[i].dp_flag & 0x80 || sl < BASE_SLICE)) {
sl = BASE_SLICE + i;
if (dp[i].dp_flag & 0x80 ||
Expand All @@ -552,7 +553,7 @@ dskprobe(void)
if (sl != WHOLE_DISK_SLICE) {
if (sl != COMPATIBILITY_SLICE)
dp += sl - BASE_SLICE;
if (dp->dp_typ != DOSPTYP_386BSD) {
if (dp->dp_typ != DOSPTYP_386BSD && dp->dp_typ != DOSPTYP_DFLYBSD) {
printf(INVALID_S, "slice");
return -1;
}
Expand Down
20 changes: 14 additions & 6 deletions sys/boot/pc32/libi386/biosdisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ bd_print(int verbose)
dptr = &od->od_slicetab[0];

/* Check for a "dedicated" disk */
if (((dptr[3].dp_typ == DOSPTYP_386BSD) ||
(dptr[3].dp_typ == DOSPTYP_NETBSD)) &&
if ((dptr[3].dp_typ == DOSPTYP_386BSD ||
dptr[3].dp_typ == DOSPTYP_NETBSD ||
dptr[3].dp_typ == DOSPTYP_DFLYBSD) &&
(dptr[3].dp_start == 0) &&
(dptr[3].dp_size == 50000)) {
sprintf(line, " disk%d", i);
Expand Down Expand Up @@ -306,6 +307,7 @@ bd_printslice(struct open_disk *od, struct dos_partition *dp, char *prefix,
char line[80];

switch (dp->dp_typ) {
case DOSPTYP_DFLYBSD:
case DOSPTYP_386BSD:
case DOSPTYP_NETBSD:
/* XXX: possibly add types 0 and 1, as in subr_disk, for gpt magic */
Expand Down Expand Up @@ -637,7 +639,8 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
/*
* Check for the historically bogus MBR found on true dedicated disks
*/
if ((dptr[3].dp_typ == DOSPTYP_386BSD) &&
if ((dptr[3].dp_typ == DOSPTYP_386BSD ||
dptr[3].dp_typ == DOSPTYP_DFLYBSD) &&
(dptr[3].dp_start == 0) &&
(dptr[3].dp_size == 50000)) {
sector = 0;
Expand All @@ -664,10 +667,14 @@ bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
DEBUG("slice entry %d at %d, %d sectors", dev->d_kind.biosdisk.slice - 1, sector, dptr->dp_size);

/*
* If we are looking at a BSD slice, and the partition is < 0, assume the 'a' partition
* If we are looking at a BSD slice, and the partition is < 0,
* assume the 'a' partition
*/
if ((dptr->dp_typ == DOSPTYP_386BSD) && (dev->d_kind.biosdisk.partition < 0))
if ((dptr->dp_typ == DOSPTYP_386BSD ||
dptr->dp_typ == DOSPTYP_DFLYBSD) &&
dev->d_kind.biosdisk.partition < 0) {
dev->d_kind.biosdisk.partition = 0;
}

unsliced:
/*
Expand Down Expand Up @@ -878,7 +885,8 @@ bd_bestslice(struct open_disk *od)
dp = &od->od_slicetab[0];
for (i = 0; i < od->od_nslices; i++, dp++) {
switch (dp->dp_typ) {
case DOSPTYP_386BSD: /* FreeBSD */
case DOSPTYP_DFLYBSD: /* DragonFlyBSD */
case DOSPTYP_386BSD: /* FreeBSD and old DFlyBSD */
pref = dp->dp_flag & 0x80 ? PREF_FBSD_ACT : PREF_FBSD;
break;

Expand Down
4 changes: 3 additions & 1 deletion sys/kern/subr_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ disk_probe_slice(struct disk *dp, cdev_t dev, int slice, int reprobe)
} else {
if (sp->ds_type == DOSPTYP_386BSD || /* XXX */
sp->ds_type == DOSPTYP_NETBSD ||
sp->ds_type == DOSPTYP_OPENBSD) {
sp->ds_type == DOSPTYP_OPENBSD ||
sp->ds_type == DOSPTYP_DFLYBSD) {
log(LOG_WARNING, "%s: cannot find label (%s)\n",
dev->si_name, msg);
}
Expand Down Expand Up @@ -453,6 +454,7 @@ disk_probe(struct disk *dp, int reprobe)
if (sp->ds_type == DOSPTYP_386BSD ||
sp->ds_type == DOSPTYP_NETBSD ||
sp->ds_type == DOSPTYP_OPENBSD ||
sp->ds_type == DOSPTYP_DFLYBSD ||
sp->ds_type == 0 ||
sp->ds_type == 1) {
if (dp->d_slice->dss_first_bsd_slice == 0)
Expand Down
7 changes: 4 additions & 3 deletions sys/kern/subr_diskmbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ static struct dos_partition historical_bogus_partition_table[NDOSPART] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0x80, 0, 1, 0, DOSPTYP_386BSD, 255, 255, 255, 0, 50000, },
{ 0x80, 0, 1, 0, DOSPTYP_DFLYBSD, 255, 255, 255, 0, 50000, },
};
static struct dos_partition historical_bogus_partition_table_fixed[NDOSPART] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0x80, 0, 1, 0, DOSPTYP_386BSD, 254, 255, 255, 0, 50000, },
{ 0x80, 0, 1, 0, DOSPTYP_DFLYBSD, 254, 255, 255, 0, 50000, },
};

static int check_part (char *sname, struct dos_partition *dp,
Expand Down Expand Up @@ -205,7 +205,8 @@ mbrinit(cdev_t dev, struct disk_info *info, struct diskslices **sspp)
/*
* TODO:
* Perhaps skip entries with 0 size.
* Perhaps only look at entries of type DOSPTYP_386BSD.
* Perhaps only look at entries of type DOSPTYP_386BSD or
* DOSPTYP_DFLYBSD
*/
max_ncyls = 0;
max_nsectors = 0;
Expand Down
4 changes: 3 additions & 1 deletion sys/kern/subr_diskslice.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,11 @@ dsreadandsetlabel(cdev_t dev, u_int flags,
lp = ops->op_clone_label(info, sp);
}
if (msg != NULL) {
if (sp->ds_type == DOSPTYP_386BSD /* XXX */)
if (sp->ds_type == DOSPTYP_386BSD ||
sp->ds_type == DOSPTYP_DFLYBSD) {
log(LOG_WARNING, "%s: cannot find label (%s)\n",
sname, msg);
}
if (lp.opaque)
kfree(lp.opaque, M_DEVBUF);
} else {
Expand Down
5 changes: 5 additions & 0 deletions sys/sys/diskmbr.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
#define DOSMAGICOFFSET 510
#define DOSMAGIC 0xAA55

/*
* NOTE: DragonFlyBSD had been using 0xA5 forever but after many years
* we're finally shifting to our own as A5 causes conflicts in grub.
*/
#define DOSPTYP_DFLYBSD 0x6c /* DragonFlyBSD partition type */
#define DOSPTYP_386BSD 0xa5 /* 386BSD partition type */
#define DOSPTYP_OPENBSD 0xa6 /* OpenBSD partition type */
#define DOSPTYP_NETBSD 0xa9 /* NetBSD partition type */
Expand Down

0 comments on commit 794d80a

Please sign in to comment.