-/* $OpenBSD: cmd.c,v 1.115 2021/06/14 17:34:06 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.116 2021/06/16 15:40:47 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
Xreinit(char *args, struct mbr *mbr)
{
struct dos_mbr dos_mbr;
- int efi, dogpt;
+ int dogpt;
- efi = MBR_protective_mbr(mbr);
+ dogpt = 0;
if (strncasecmp(args, "gpt", 3) == 0)
dogpt = 1;
else if (strlen(args) > 0) {
printf("Unrecognized modifier '%s'\n", args);
return (CMD_CONT);
- } else if (efi != -1)
- dogpt = 1;
- else
- dogpt = 0;
+ }
MBR_make(&initial_mbr, &dos_mbr);
MBR_parse(&dos_mbr, mbr->offset, mbr->reloffset, mbr);
return (CMD_CONT);
}
} else {
- /* Ensure any on-disk GPT headers are zeroed. */
- MBR_zapgpt(&dos_mbr, DL_GETDSIZE(&dl) - 1);
+ GPT_zap_headers();
}
/* Refresh in memory copy to reflect what was just written. */
-.\" $OpenBSD: fdisk.8,v 1.96 2021/01/30 15:15:20 naddy Exp $
+.\" $OpenBSD: fdisk.8,v 1.97 2021/06/16 15:40:47 krw Exp $
.\"
.\"
.\" Copyright (c) 1997 Tobias Weingartner
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 30 2021 $
+.Dd $Mdocdate: June 16 2021 $
.Dt FDISK 8
.Os
.Sh NAME
.It Cm reinit Op Cm gpt | Cm mbr
Initialize the currently selected, in-memory copy of the
boot block.
+.Pp
+By default an MBR is initialized.
If
.Cm gpt
is specified a protective MBR and a GPT are initialized.
-If
-.Cm mbr
-is specified only an MBR is initialized.
-If neither
-.Cm mbr
-nor
-.Cm gpt
-are specified then a protective MBR and a GPT are initialized if a protective
-MBR already exists.
-Otherwise only an MBR is initialized.
.It Cm disk
Display the current drive geometry that
.Nm
-/* $OpenBSD: gpt.c,v 1.29 2021/06/14 12:46:47 krw Exp $ */
+/* $OpenBSD: gpt.c,v 1.30 2021/06/16 15:40:47 krw Exp $ */
/*
* Copyright (c) 2015 Markus Muller <mmu@grummel.net>
* Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
return rslt;
}
+void
+GPT_zap_headers(void)
+{
+ char *secbuf;
+ uint64_t sig;
+
+ secbuf = DISK_readsector(GPTSECTOR);
+ if (secbuf == NULL)
+ return;
+
+ memcpy(&sig, secbuf, sizeof(sig));
+ if (letoh64(sig) == GPTSIGNATURE) {
+ memset(secbuf, 0, dl.d_secsize);
+ DISK_writesector(secbuf, GPTSECTOR);
+ }
+ free(secbuf);
+
+ secbuf = DISK_readsector(DL_GETDSIZE(&dl) - 1);
+ if (secbuf == NULL)
+ return;
+
+ memcpy(&sig, secbuf, sizeof(sig));
+ if (letoh64(sig) == GPTSIGNATURE) {
+ memset(secbuf, 0, dl.d_secsize);
+ DISK_writesector(secbuf, DL_GETDSIZE(&dl) - 1);
+ }
+ free(secbuf);
+}
+
int
GPT_write(void)
{
-/* $OpenBSD: gpt.h,v 1.11 2021/06/12 17:19:13 krw Exp $ */
+/* $OpenBSD: gpt.h,v 1.12 2021/06/16 15:40:47 krw Exp $ */
/*
* Copyright (c) 2015 Markus Muller <mmu@grummel.net>
* Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
int GPT_init(void);
int GPT_write(void);
+void GPT_zap_headers(void);
void GPT_print(char *, int);
void GPT_print_part(int, char *, int);
void GPT_print_parthdr(int);
-/* $OpenBSD: mbr.c,v 1.75 2021/06/10 15:30:49 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.76 2021/06/16 15:40:47 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
return (0);
}
-/*
- * If *dos_mbr has a 0xee or 0xef partition, nothing needs to happen. If no
- * such partition is present but the first or last sector on the disk has a
- * GPT, zero the GPT to ensure the MBR takes priority and fewer BIOSes get
- * confused.
- */
-void
-MBR_zapgpt(struct dos_mbr *dos_mbr, uint64_t lastsec)
-{
- struct dos_partition dos_parts[NDOSPART];
- char *secbuf;
- uint64_t sig;
- int i;
-
- memcpy(dos_parts, dos_mbr->dmbr_parts, sizeof(dos_parts));
-
- for (i = 0; i < NDOSPART; i++)
- if ((dos_parts[i].dp_typ == DOSPTYP_EFI) ||
- (dos_parts[i].dp_typ == DOSPTYP_EFISYS))
- return;
-
- secbuf = DISK_readsector(GPTSECTOR);
- if (secbuf == NULL)
- return;
-
- memcpy(&sig, secbuf, sizeof(sig));
- if (letoh64(sig) == GPTSIGNATURE) {
- memset(secbuf, 0, sizeof(sig));
- DISK_writesector(secbuf, GPTSECTOR);
- }
- free(secbuf);
-
- secbuf = DISK_readsector(lastsec);
- if (secbuf == NULL)
- return;
-
- memcpy(&sig, secbuf, sizeof(sig));
- if (letoh64(sig) == GPTSIGNATURE) {
- memset(secbuf, 0, sizeof(sig));
- DISK_writesector(secbuf, lastsec);
- }
- free(secbuf);
-}
-
/*
* Return the index into dp[] of the EFI GPT (0xEE) partition, or -1 if no such
* partition exists.
-/* $OpenBSD: mbr.h,v 1.30 2021/05/20 14:27:14 krw Exp $ */
+/* $OpenBSD: mbr.h,v 1.31 2021/06/16 15:40:47 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
void MBR_init_GPT(struct mbr *);
int MBR_read(off_t, struct dos_mbr *);
int MBR_write(off_t, struct dos_mbr *);
-void MBR_zapgpt(struct dos_mbr *, uint64_t);
int MBR_protective_mbr(struct mbr *);
#endif /* _MBR_H */