summaryrefslogtreecommitdiffstats
path: root/sbin/gpt/create.c
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2002-12-02 01:42:03 +0000
committermarcel <marcel@FreeBSD.org>2002-12-02 01:42:03 +0000
commit4abeaed33de9450b5e4900151806d6b8329b4958 (patch)
treef64f1e9698713b9f0a3d0bedc5af4f9a905e7278 /sbin/gpt/create.c
parentd5387889cf085aef87f5ad40da8b3971385e2a1e (diff)
downloadFreeBSD-src-4abeaed33de9450b5e4900151806d6b8329b4958.zip
FreeBSD-src-4abeaed33de9450b5e4900151806d6b8329b4958.tar.gz
o Newer EFI implementations require that a GPT is preceeded by
a PMBR. Make sure the create command creates a PMBR as well (if not already present). o When parsing the MBR, explicitly check for a PMBR and create a PMBR map node if one is found. o When parsing the MBR, recurse to handle extended partitions. This allows us to flatten nested MBRs when migrating to a GPT. o Have the migrate command bail out if it encounters a partition it doesn't know how to migrate. This avoids data loss. o Change the output of the show command so that the UUIDs of the GPT partitions fit on the same line. o Show when partitions are extended partitions and add the PMBR type. Approved by: re (blanket)
Diffstat (limited to 'sbin/gpt/create.c')
-rw-r--r--sbin/gpt/create.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/sbin/gpt/create.c b/sbin/gpt/create.c
index ec2b121..e9ac8ce 100644
--- a/sbin/gpt/create.c
+++ b/sbin/gpt/create.c
@@ -58,6 +58,7 @@ create(int fd)
map_t *gpt, *tpg;
map_t *tbl, *lbt;
map_t *map;
+ struct mbr *mbr;
struct gpt_hdr *hdr;
struct gpt_ent *ent;
unsigned int i;
@@ -67,6 +68,40 @@ create(int fd)
warnx("%s: error: device already contains a GPT", device_name);
return;
}
+ if (map_find(MAP_TYPE_MBR) != NULL) {
+ warnx("%s: error: device contains a MBR", device_name);
+ return;
+ }
+
+ /*
+ * Create PMBR.
+ */
+ if (map_find(MAP_TYPE_PMBR) == NULL) {
+ if (map_free(0LL, 1LL) == 0) {
+ warnx("%s: error: no room for the PMBR", device_name);
+ return;
+ }
+ mbr = gpt_read(fd, 0LL, 1);
+ bzero(mbr, sizeof(*mbr));
+ mbr->mbr_sig = MBR_SIG;
+ 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;
+ }
+ map = map_add(0LL, 1LL, MAP_TYPE_PMBR, mbr);
+ gpt_write(fd, map);
+ }
/* Get the amount of free space after the MBR */
blocks = map_free(1LL, 0LL);
OpenPOWER on IntegriCloud