Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Jun 2002 22:32:06 -0700 (PDT)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 12315 for review
Message-ID:  <200206030532.g535W6667707@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=12315

Change 12315 by marcel@marcel_vaio on 2002/06/02 22:31:39

	Enhance the migrate command some more:
	o  Add option -s to migrate a FreeBSD slice to a FreeBSD disklabel
	   partition (as was done until now).
	o  Turn the MBR into a Protective MBR unless -k (keep) is given.
	o  Create GPT-based partitions by migrating FreeBSD disklabels
	   into GPT partitions. This is the default now.

Affected files ...

... //depot/projects/ia64/sbin/gpt/gpt.c#8 edit
... //depot/projects/ia64/sbin/gpt/gpt.h#5 edit
... //depot/projects/ia64/sbin/gpt/map.c#4 edit
... //depot/projects/ia64/sbin/gpt/migrate.c#2 edit
... //depot/projects/ia64/sbin/gpt/mkdisk.sh#2 edit

Differences ...

==== //depot/projects/ia64/sbin/gpt/gpt.c#8 (text+ko) ====

@@ -140,7 +140,7 @@
 	return buf;
 }
 
-static void*
+void*
 gpt_read(int fd, off_t lba, size_t count)
 {
 	off_t ofs;
@@ -344,10 +344,12 @@
 	"%s: MBR partition: type=%d, start=%llu, size=%llu", device_name,
 					    mbr->mbr_part[i].part_typ,
 					    (long long)start, (long long)size);
-				m = map_add(start, size, MAP_TYPE_MBR_PART,
-				    NULL);
-				if (m == NULL)
-					goto close;
+				if (mbr->mbr_part[i].part_typ != 0xee) {
+					m = map_add(start, size,
+					    MAP_TYPE_MBR_PART, NULL);
+					if (m == NULL)
+						goto close;
+				}
 			}
 		}
 	} else {

==== //depot/projects/ia64/sbin/gpt/gpt.h#5 (text+ko) ====

@@ -58,6 +58,7 @@
 uint32_t crc32(const void *, size_t);
 void	gpt_close(int);
 int	gpt_open(const char *);
+void*	gpt_read(int, off_t, size_t);
 int	gpt_write(int, map_t *);
 void	unicode16(short *, const wchar_t *, size_t);
 

==== //depot/projects/ia64/sbin/gpt/map.c#4 (text+ko) ====


==== //depot/projects/ia64/sbin/gpt/migrate.c#2 (text+ko) ====

@@ -27,6 +27,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/disklabel.h>
 #include <sys/uuid.h>
 #include <sys/gpt.h>
 
@@ -40,17 +41,69 @@
 #include "map.h"
 #include "gpt.h"
 
-int keep;
+int keep, slice;
 
 static void
 usage_migrate(void)
 {
 
 	fprintf(stderr,
-	    "usage: %s [-k] device\n", getprogname());
+	    "usage: %s [-ks] device\n", getprogname());
 	exit(1);
 }
 
+static struct gpt_ent*
+migrate_disklabel(int fd, off_t start, struct gpt_ent *ent)
+{
+	char *buf;
+	struct disklabel *dl;
+	int i;
+
+	buf = gpt_read(fd, start + LABELSECTOR, 1);
+	dl = (void*)(buf + LABELOFFSET);
+
+	if (dl->d_magic != DISKMAGIC || dl->d_magic2 != DISKMAGIC) {
+		warnx("%s: warning: FreeBSD slice without disklabel",
+		    device_name);
+		return (ent);
+	}
+
+	for (i = 0; i < dl->d_npartitions; i++) {
+		switch (dl->d_partitions[i].p_fstype) {
+		case FS_SWAP: {
+			uuid_t swap = GPT_ENT_TYPE_FREEBSD_SWAP;
+			ent->ent_type = swap;
+			unicode16(ent->ent_name,
+			    L"FreeBSD swap partition", 36);
+			break;
+		}
+		case FS_BSDFFS: {
+			uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS;
+			ent->ent_type = ufs;
+			unicode16(ent->ent_name,
+			    L"FreeBSD UFS partition", 36);
+			break;
+		}
+		case FS_VINUM: {
+			uuid_t vinum = GPT_ENT_TYPE_FREEBSD_VINUM;
+			ent->ent_type = vinum;
+			unicode16(ent->ent_name,
+			    L"FreeBSD vinum partition", 36);
+			break;
+		}
+		default:
+			continue;
+		}
+
+		ent->ent_lba_start = dl->d_partitions[i].p_offset;
+		ent->ent_lba_end = ent->ent_lba_start +
+		    dl->d_partitions[i].p_size - 1LL;
+		ent++;
+	}
+
+	return (ent);
+}
+
 static void
 migrate(int fd)
 {
@@ -75,12 +128,6 @@
 
 	mbr = map->map_data;
 
-	if (verbose) {
-		printf("\tBefore image:\n");
-		map_dump();
-		putchar('\n');
-	}
-
 	if (map_find(MAP_TYPE_PRI_GPT_HDR) != NULL ||
 	    map_find(MAP_TYPE_SEC_GPT_HDR) != NULL) {
 		warnx("%s: error: device already contains a GPT", device_name);
@@ -159,30 +206,37 @@
 
 	/* Mirror partitions. */
 	for (i = 0; i < 4; i++) {
+		start = mbr->mbr_part[i].part_start_hi;
+		start = (start << 16) + mbr->mbr_part[i].part_start_lo;
+		size = mbr->mbr_part[i].part_size_hi;
+		size = (size << 16) + mbr->mbr_part[i].part_size_lo;
+
 		switch (mbr->mbr_part[i].part_typ) {
 		case 165: {	/* FreeBSD */
-			uuid_t freebsd = GPT_ENT_TYPE_FREEBSD;
-			ent->ent_type = freebsd;
-			unicode16(ent->ent_name,
-			    L"FreeBSD disklabel partition", 36);
+			if (slice) {
+				uuid_t freebsd = GPT_ENT_TYPE_FREEBSD;
+				ent->ent_type = freebsd;
+				ent->ent_lba_start = start;
+				ent->ent_lba_end = start + size - 1LL;
+				unicode16(ent->ent_name,
+				    L"FreeBSD disklabel partition", 36);
+				ent++;
+			} else
+				ent = migrate_disklabel(fd, start, ent);
 			break;
 		}
 		case 239: {	/* EFI */
 			uuid_t efi_slice = GPT_ENT_TYPE_EFI;
 			ent->ent_type = efi_slice;
+			ent->ent_lba_start = start;
+			ent->ent_lba_end = start + size - 1LL;
 			unicode16(ent->ent_name, L"EFI system partition", 36);
+			ent++;
 			break;
 		}
 		default:
 			continue;
 		}
-		start = mbr->mbr_part[i].part_start_hi;
-		start = (start << 16) + mbr->mbr_part[i].part_start_lo;
-		size = mbr->mbr_part[i].part_size_hi;
-		size = (size << 16) + mbr->mbr_part[i].part_size_lo;
-		ent->ent_lba_start = start;
-		ent->ent_lba_end = start + size - 1LL;
-		ent++;
 	}
 	ent = tbl->map_data;
 
@@ -206,10 +260,29 @@
 	gpt_write(fd, lbt);
 	gpt_write(fd, tpg);
 
-	if (verbose) {
-		printf("\tAfter image:\n");
-		map_dump();
-		putchar('\n');
+	if (!keep) {
+		map = map_find(MAP_TYPE_MBR);
+		mbr = map->map_data;
+		/*
+		 * Turn the MBR into a Protective MBR.
+		 */
+		bzero(mbr->mbr_part, sizeof(mbr->mbr_part));
+		mbr->mbr_part[0].part_shd = 0xff;
+		mbr->mbr_part[0].part_ssect = 0xff;
+		mbr->mbr_part[0].part_scyl = 0xff;
+		mbr->mbr_part[0].part_typ = 0xee;
+		mbr->mbr_part[0].part_ehd = 0xff;
+		mbr->mbr_part[0].part_esect = 0xff;
+		mbr->mbr_part[0].part_ecyl = 0xff;
+		mbr->mbr_part[0].part_start_lo = 1;
+		if (mediasz > 0xffffffff) {
+			mbr->mbr_part[0].part_size_lo = 0xffff;
+			mbr->mbr_part[0].part_size_hi = 0xffff;
+		} else {
+			mbr->mbr_part[0].part_size_lo = mediasz & 0xffff;
+			mbr->mbr_part[0].part_size_hi = mediasz >> 16;
+		}
+		gpt_write(fd, map);
 	}
 }
 
@@ -219,11 +292,14 @@
 	int ch, fd;
 
 	/* Get the migrate options */
-	while ((ch = getopt(argc, argv, "k")) != -1) {
+	while ((ch = getopt(argc, argv, "ks")) != -1) {
 		switch(ch) {
 		case 'k':
 			keep = 1;
 			break;
+		case 's':
+			slice = 1;
+			break;
 		default:
 			usage_migrate();
 		}

==== //depot/projects/ia64/sbin/gpt/mkdisk.sh#2 (text+ko) ====

@@ -1,9 +1,10 @@
 #!/bin/sh
 
-dd if=/dev/zero of=disk count=4096
+dd if=/dev/zero of=disk count=125307
 sudo mdconfig -a -t vnode -f disk -u 4
 sudo fdisk -f - md4 <<EOF
-g c64 h4 s16
-p 1 165 16 4016
+g c567 h13 s17
+p 1 165 221 124865
 EOF
+sudo disklabel -w -r md4 pan60
 sudo mdconfig -d -u 4

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206030532.g535W6667707>