-/* $OpenBSD: cmd.c,v 1.117 2021/06/21 02:05:30 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.118 2021/06/28 19:50:30 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
if (dogpt) {
MBR_init_GPT(mbr);
- GPT_init();
+ GPT_init(GHANDGP, 0);
GPT_print("s", TERSE);
} else {
memset(&gh, 0, sizeof(gh));
-/* $OpenBSD: fdisk.c,v 1.113 2021/06/25 19:24:53 krw Exp $ */
+/* $OpenBSD: fdisk.c,v 1.114 2021/06/28 19:50:30 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
if (letoh64(gh.gh_sig) != GPTSIGNATURE)
errx(1, "-A requires a valid GPT");
else {
- MBR_init_GPT(&initial_mbr);
- GPT_init();
+ initial_mbr = mbr; /* Keep current MBR. */
+ GPT_init(GPONLY, b_sectors);
query = "Do you wish to write new GPT?";
}
} else if (i_flag) {
if (g_flag) {
MBR_init_GPT(&initial_mbr);
- GPT_init();
+ GPT_init(GHANDGP, b_sectors);
query = "Do you wish to write new GPT?";
} else {
memset(&gh, 0, sizeof(gh));
-/* $OpenBSD: gpt.c,v 1.33 2021/06/25 19:24:53 krw Exp $ */
+/* $OpenBSD: gpt.c,v 1.34 2021/06/28 19:50:30 krw Exp $ */
/*
* Copyright (c) 2015 Markus Muller <mmu@grummel.net>
* Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
int get_header(off_t);
int get_partition_table(void);
int init_gh(void);
-int init_gp(void);
+int init_gp(int, uint32_t);
int
get_header(off_t where)
}
int
-init_gp(void)
+init_gp(int how, uint32_t bootsectors)
{
- extern uint32_t b_sectors;
- extern int A_flag;
const uint8_t gpt_uuid_efi_system[] = GPT_UUID_EFI_SYSTEM;
const uint8_t gpt_uuid_openbsd[] = GPT_UUID_OPENBSD;
struct gpt_partition oldgp[NGPTPARTITIONS];
int pn, rslt;
memcpy(&oldgp, &gp, sizeof(oldgp));
- if (A_flag == 0)
+ if (how == GHANDGP)
memset(&gp, 0, sizeof(gp));
else {
for (pn = 0; pn < NGPTPARTITIONS; pn++) {
}
rslt = 0;
- if (b_sectors > 0) {
+ if (bootsectors > 0) {
rslt = add_partition(gpt_uuid_efi_system, "EFI System Area",
- b_sectors);
+ bootsectors);
}
if (rslt == 0)
rslt = add_partition(gpt_uuid_openbsd, "OpenBSD Area", 0);
}
int
-GPT_init(void)
+GPT_init(int how, uint32_t bootsectors)
{
- int rslt;
+ int rslt = 0;
- rslt = init_gh();
+ if (how == GHANDGP)
+ rslt = init_gh();
if (rslt == 0)
- rslt = init_gp();
+ rslt = init_gp(how, bootsectors);
return rslt;
}
uint64_t altgh, altgp, prigh, prigp, gpbytes;
/*
- * XXX Assume we always write full-size partition table.
* XXX Assume size of gp is multiple of sector size.
*/
- gpbytes = sizeof(gp);
+ gpbytes = letoh64(gh.gh_part_num) * letoh64(gh.gh_part_size);
prigh = GPTSECTOR;
prigp = prigh + 1;
-/* $OpenBSD: gpt.h,v 1.12 2021/06/16 15:40:47 krw Exp $ */
+/* $OpenBSD: gpt.h,v 1.13 2021/06/28 19:50:30 krw Exp $ */
/*
* Copyright (c) 2015 Markus Muller <mmu@grummel.net>
* Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
int GPT_get_lba_start(unsigned int);
int GPT_get_lba_end(unsigned int);
-int GPT_init(void);
+int GPT_init(int, uint32_t);
int GPT_write(void);
void GPT_zap_headers(void);
void GPT_print(char *, int);
#define TERSE 0
#define VERBOSE 1
+
+#define GHANDGP 0
+#define GPONLY 1