Add an -f option (for force) to the create command. The -f option

allows the user to force the creation of a GPT even when there's a
MBR on the device. The MBR is simply wiped and any partitions
described by it are lost. Without the -f option one cannot create
a GPT when there's a MBR.
This commit is contained in:
Marcel Moolenaar 2004-11-13 05:13:33 +00:00
parent 8b6fc67a49
commit 597c201050
2 changed files with 25 additions and 6 deletions

View File

@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include "map.h"
#include "gpt.h"
static int force;
static int primary_only;
static void
@ -46,7 +47,7 @@ usage_create(void)
{
fprintf(stderr,
"usage: %s [-p] device ...\n", getprogname());
"usage: %s [-fp] device ...\n", getprogname());
exit(1);
}
@ -70,9 +71,15 @@ 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;
map = map_find(MAP_TYPE_MBR);
if (map != NULL) {
if (!force) {
warnx("%s: error: device contains a MBR", device_name);
return;
}
/* Nuke the MBR in our internal map. */
map->map_type = MAP_TYPE_UNUSED;
}
/*
@ -206,8 +213,11 @@ cmd_create(int argc, char *argv[])
{
int ch, fd;
while ((ch = getopt(argc, argv, "p")) != -1) {
while ((ch = getopt(argc, argv, "fp")) != -1) {
switch(ch) {
case 'f':
force = 1;
break;
case 'p':
primary_only = 1;
break;

View File

@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd October 30, 2004
.Dd November 12, 2004
.Os
.Dt GPT 8
.Sh NAME
@ -138,12 +138,21 @@ as aliases for the most commonly used partition types.
.It Xo
.Nm
.Ic create
.Op Fl f
.Op Fl p
.Ar device ...
.Xc
The
.Ic create
command allows the user to create a new (empty) GPT.
By default one can not create a GPT when the device contains a MBR,
however this can be overridden with the
.Fl f
option.
If the
.Fl f
option is specified, an existing MBR is destroyed and any partitions
described by the MBR are lost.
.Pp
The
.Fl p