From ffc8d4602aeedba058ec991b430b1e4520d65273 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Thu, 6 Feb 2020 17:16:59 +0100
Subject: [PATCH] WIP Change partition id to 108 globally.

---
 nrelease/Makefile                             | 2 +-
 sbin/fdisk/fdisk.8                            | 4 ++--
 sbin/fdisk/fdisk.c                            | 4 ++--
 sbin/gpt/boot.c                               | 4 +---
 sbin/gpt/migrate.c                            | 4 +++-
 sys/sys/diskmbr.h                             | 4 ++--
 usr.sbin/installer/dfuibe_installer/fn_disk.c | 4 ++--
 usr.sbin/installer/libinstaller/survey.c      | 6 +++---
 usr.sbin/installer/libinstaller/sysids.h      | 2 +-
 9 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/nrelease/Makefile b/nrelease/Makefile
index 5f8b67c53b..6909453d8f 100644
--- a/nrelease/Makefile
+++ b/nrelease/Makefile
@@ -357,7 +357,7 @@ mkimg:
 	awk '(NR==1){printf("g c%s h%s s%s\n", $$2, $$4, $$6);}' \
 	    ${ISODIR}/fdisk.dat >${ISODIR}/fdisk.conf
 	echo "p 1 239 63 257985" >>${ISODIR}/fdisk.conf
-	awk '($$1=="1:"){printf("p 2 165 258048 %lu\n", $$3 - 258528);}' \
+	awk '($$1=="1:"){printf("p 2 108 258048 %lu\n", $$3 - 258528);}' \
 	    ${ISODIR}/fdisk.dat >>${ISODIR}/fdisk.conf
 	echo "a 2" >>${ISODIR}/fdisk.conf
 	fdisk -iv -f ${ISODIR}/fdisk.conf `cat ${ISODIR}/vn.which`
diff --git a/sbin/fdisk/fdisk.8 b/sbin/fdisk/fdisk.8
index cafab518b1..d188b73769 100644
--- a/sbin/fdisk/fdisk.8
+++ b/sbin/fdisk/fdisk.8
@@ -1,6 +1,6 @@
 .\" $FreeBSD: src/sbin/i386/fdisk/fdisk.8,v 1.17.2.11 2002/04/25 16:25:12 trhodes Exp $
 .\"
-.Dd March 27, 2019
+.Dd February 6, 2020
 .Dt FDISK 8
 .Os
 .Sh NAME
@@ -197,7 +197,7 @@ An example follows:
 	Warning: BIOS sector numbering starts with sector 1
 	Information from DOS bootblock is:
 	The data for partition 1 is:
-	sysid 165,(DragonFly/FreeBSD/NetBSD/386BSD)
+	sysid 108,(DragonFly BSD)
 	    start 495, size 380160 (185 Meg), flag 0
 		beg: cyl 1/ sector 1/ head 0;
 		end: cyl 768/ sector 33/ head 14
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index f313102dde..053d6553e1 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -175,7 +175,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"}
+	,{0x6C, "DragonFly BSD"}
 	,{0x70, "DiskSecure Multi-Boot"}
 	,{0x75, "PCIX"}
 	,{0x77, "QNX4.x"}
@@ -598,7 +598,7 @@ struct dos_partition *partp = ((struct dos_partition *) &mboot.parts) + i - 1;
 	}
 
 	do {
-		Decimal("sysid (165=DragonFly)", partp->dp_typ, tmp);
+		Decimal("sysid (108=DragonFly)", partp->dp_typ, tmp);
 		Decimal("start", partp->dp_start, tmp);
 		Decimal("size", partp->dp_size, tmp);
 		if (!sanitize_partition(partp)) {
diff --git a/sbin/gpt/boot.c b/sbin/gpt/boot.c
index f5dae3644b..a6ea6204d2 100644
--- a/sbin/gpt/boot.c
+++ b/sbin/gpt/boot.c
@@ -30,8 +30,6 @@
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
- * 
- * $DragonFly: src/sbin/gpt/boot.c,v 1.2 2008/08/21 23:10:04 thomas Exp $
  */
 
 #include <sys/types.h>
@@ -174,7 +172,7 @@ bootset(int fd)
 	mbr->mbr_part[1].part_size_lo = htole16(size);
 	mbr->mbr_part[1].part_size_hi = htole16(size >> 16);
 
-	mbr->mbr_part[1].part_typ = 165;
+	mbr->mbr_part[1].part_typ = 108;
 	mbr->mbr_part[1].part_flag = 0x80;
 
 	gpt_write(fd, map);
diff --git a/sbin/gpt/migrate.c b/sbin/gpt/migrate.c
index 3c5a6c92b5..f4986e81e7 100644
--- a/sbin/gpt/migrate.c
+++ b/sbin/gpt/migrate.c
@@ -24,7 +24,6 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sbin/gpt/migrate.c,v 1.16 2005/09/01 02:42:52 marcel Exp $
- * $DragonFly: src/sbin/gpt/migrate.c,v 1.3 2007/06/18 05:13:39 dillon Exp $
  */
 
 #include <sys/types.h>
@@ -250,6 +249,9 @@ migrate(int fd)
 		switch (mbr->mbr_part[i].part_typ) {
 		case 0:
 			continue;
+		case 108:
+			/* TODO: Port to DragonFly and test */
+			continue;
 		case 165: {	/* FreeBSD */
 			if (slice) {
 				uuid_t freebsd = GPT_ENT_TYPE_FREEBSD;
diff --git a/sys/sys/diskmbr.h b/sys/sys/diskmbr.h
index 32c962e937..df7b80b7b9 100644
--- a/sys/sys/diskmbr.h
+++ b/sys/sys/diskmbr.h
@@ -43,10 +43,10 @@
 #define	DOSMAGIC	0xAA55
 
 /*
- * NOTE: DragonFlyBSD had been using 0xA5 forever but after many years
+ * NOTE: DragonFly BSD 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_DFLYBSD	0x6c	/* DragonFly BSD partition type */
 #define	DOSPTYP_386BSD	0xa5	/* 386BSD partition type */
 #define	DOSPTYP_OPENBSD	0xa6	/* OpenBSD partition type */
 #define	DOSPTYP_NETBSD	0xa9	/* NetBSD partition type */
diff --git a/usr.sbin/installer/dfuibe_installer/fn_disk.c b/usr.sbin/installer/dfuibe_installer/fn_disk.c
index b50b4cd0b4..3cff546c5b 100644
--- a/usr.sbin/installer/dfuibe_installer/fn_disk.c
+++ b/usr.sbin/installer/dfuibe_installer/fn_disk.c
@@ -710,7 +710,7 @@ format_slice(struct i_fn_args *a)
 		return 0;
 
 	/*
-	 * Set the slice's sysid to 165.
+	 * Set the slice's sysid to 108.
 	 */
 	disk_get_geometry(storage_get_selected_disk(a->s), &cyl, &hd, &sec);
 	command_add(cmds, "%s%s 'g c%d h%d s%d' >%snew.fdisk",
@@ -720,7 +720,7 @@ format_slice(struct i_fn_args *a)
 	command_add(cmds, "%s%s 'p %d %d %lu %lu' >>%snew.fdisk",
 	    a->os_root, cmd_name(a, "ECHO"),
 	    slice_get_number(storage_get_selected_slice(a->s)),
-	    165,
+	    108,
 	    slice_get_start(storage_get_selected_slice(a->s)),
 	    slice_get_size(storage_get_selected_slice(a->s)),
 	    a->tmp);
diff --git a/usr.sbin/installer/libinstaller/survey.c b/usr.sbin/installer/libinstaller/survey.c
index b8fc42da97..a672499d60 100644
--- a/usr.sbin/installer/libinstaller/survey.c
+++ b/usr.sbin/installer/libinstaller/survey.c
@@ -115,7 +115,7 @@ parse_slice_info(char *line, int *slice,
 
 	/*
 	 * Part        Start        Size Type Flags
-	 *    1:          63     2128833 0xa5 0x80
+	 *    1:          63     2128833 0x6c 0x80
 	 */
 	if ((word = strtok(line, " \t")) == NULL)	/* 1: */
 		return(0);
@@ -126,7 +126,7 @@ parse_slice_info(char *line, int *slice,
 	if ((word = strtok(NULL, " \t")) == NULL)	/* 2128833 */
 		return(0);
 	*size = strtoul(word, NULL, 10);
-	if ((word = strtok(NULL, " \t")) == NULL)	/* 0xa5 */
+	if ((word = strtok(NULL, " \t")) == NULL)	/* 0x6c */
 		return(0);
 	if (!hex_to_int(word, type))
 		return(0);
@@ -321,7 +321,7 @@ survey_storage(struct i_fn_args *a)
 			/*
 			 * /dev/ad3: 2112 cyl 16 hd 63 sec
 			 * Part        Start        Size Type Flags
-			 *    1:          63     2128833 0xa5 0x80
+			 *    1:          63     2128833 0x6c 0x80
 			 */
 			while (d != NULL && strcmp(line, "@END") != 0 && fgets_chomp(line, 255, f)) {
 				if (strncmp(line, "/dev/", 5) == 0) {
diff --git a/usr.sbin/installer/libinstaller/sysids.h b/usr.sbin/installer/libinstaller/sysids.h
index 28d3c2c41a..62f5bb9f23 100644
--- a/usr.sbin/installer/libinstaller/sysids.h
+++ b/usr.sbin/installer/libinstaller/sysids.h
@@ -24,7 +24,6 @@
  * the rights to redistribute these changes.
  *
  * $FreeBSD: /repoman/r/ncvs/src/sbin/i386/fdisk/fdisk.c,v 1.36.2.14 2004/01/30 14:40:47 harti Exp $
- * $_DragonFly: src/sbin/i386/fdisk/fdisk.c,v 1.9 2004/07/08 17:50:46 cpressey Exp $
  */
 
 /*
@@ -91,6 +90,7 @@ static 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, "DragonFly BSD"}
 	,{0x70, "DiskSecure Multi-Boot"}
 	,{0x75, "PCIX"}
 	,{0x77, "QNX4.x"}
-- 
2.24.1

