Module Name: src Committed By: jmcneill Date: Sun May 24 18:42:48 UTC 2020
Modified Files: src/sbin/fdisk: fdisk.8 fdisk.c Log Message: Add -g flag to preserve GPT headers when updating MBR. To generate a diff of this commit: cvs rdiff -u -r1.90 -r1.91 src/sbin/fdisk/fdisk.8 cvs rdiff -u -r1.157 -r1.158 src/sbin/fdisk/fdisk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/fdisk/fdisk.8 diff -u src/sbin/fdisk/fdisk.8:1.90 src/sbin/fdisk/fdisk.8:1.91 --- src/sbin/fdisk/fdisk.8:1.90 Sun Dec 15 11:49:28 2019 +++ src/sbin/fdisk/fdisk.8 Sun May 24 18:42:48 2020 @@ -1,6 +1,6 @@ -.\" $NetBSD: fdisk.8,v 1.90 2019/12/15 11:49:28 wiz Exp $ +.\" $NetBSD: fdisk.8,v 1.91 2020/05/24 18:42:48 jmcneill Exp $ .\" -.Dd December 14, 2019 +.Dd May 24, 2020 .Dt FDISK 8 .Os .Sh NAME @@ -8,7 +8,7 @@ .Nd MS-DOS partition maintenance program .Sh SYNOPSIS .Nm -.Op Fl aBFfIiSuv +.Op Fl aBFfgIiSuv .Oo .Fl 0 | 1 | 2 | 3 | E Ar number .Op Fl s Oo Ar id Oc Ns Oo / Ns Oo Ar start Oc Ns Oo / Ns Oo Ar size Oc Ns Oo / Ns Oo Ar bootmenu Oc Oc Oc Oc @@ -114,7 +114,9 @@ selects defaults for its questions to gu If partition data is going to be updated and the disk carries GUID Partition Tables, .Nm -will remove both primary and backup GPT headers from the disk. +will remove both primary and backup GPT headers from the disk unless the +.Fl g +flag is specified. See .Xr gpt 8 for information on how to manipulate GUID Partition Tables. @@ -262,6 +264,8 @@ and fields .Pq only Ar start No and Ar size No can be specified by Fl s No option . They will be automatically computed using the BIOS geometry. +.It Fl g +Preserve existing GPT headers when updating partitions. .It Fl I Ignore errors from overlapping partitions. Some devices (cameras CHDK) require overlapping partitions to support Index: src/sbin/fdisk/fdisk.c diff -u src/sbin/fdisk/fdisk.c:1.157 src/sbin/fdisk/fdisk.c:1.158 --- src/sbin/fdisk/fdisk.c:1.157 Mon Oct 7 20:56:07 2019 +++ src/sbin/fdisk/fdisk.c Sun May 24 18:42:48 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: fdisk.c,v 1.157 2019/10/07 20:56:07 christos Exp $ */ +/* $NetBSD: fdisk.c,v 1.158 2020/05/24 18:42:48 jmcneill Exp $ */ /* * Mach Operating System @@ -39,7 +39,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: fdisk.c,v 1.157 2019/10/07 20:56:07 christos Exp $"); +__RCSID("$NetBSD: fdisk.c,v 1.158 2020/05/24 18:42:48 jmcneill Exp $"); #endif /* not lint */ #define MBRPTYPENAMES @@ -141,7 +141,7 @@ static char *boot_path = NULL; /* name #define BOOTSEL_OPTIONS #define change_part(e, p, id, st, sz, bm) change__part(e, p, id, st, sz) #endif -#define OPTIONS BOOTSEL_OPTIONS "0123FSafiIluvA:b:c:E:r:s:w:z:" +#define OPTIONS BOOTSEL_OPTIONS "0123FSafgiIluvA:b:c:E:r:s:w:z:" /* * Disk geometry and partition alignment. @@ -215,6 +215,7 @@ static int u_flag; /* update partition static int v_flag; /* more verbose */ static int sh_flag; /* Output data as shell defines */ static int f_flag; /* force --not interactive */ +static int g_flag; /* preserve GPT headers */ static int s_flag; /* set id,offset,size */ static int b_flag; /* Set cyl, heads, secs (as c/h/s) */ static int B_flag; /* Edit/install bootselect code */ @@ -430,6 +431,9 @@ main(int argc, char *argv[]) case 'f': /* Non interactive */ f_flag = 1; break; + case 'g': /* Preserve GPT headers */ + g_flag = 1; + break; case 'i': /* Always update bootcode */ i_flag = 1; break; @@ -3058,6 +3062,9 @@ delete_gpt(struct gpt_hdr *gptp) char buf[512]; struct gpt_hdr *hdr = (void *)buf; + if (g_flag) + return 0; /* preserve existing GPT headers */ + if (gptp->hdr_size == 0) return 0;