-/* $OpenBSD: mbr.c,v 1.120 2022/07/25 17:45:16 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.121 2022/07/26 14:30:37 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
const uint64_t lba_firstembr, struct mbr *mbr)
{
struct dos_partition dos_parts[NDOSPART];
- int i;
+ uint8_t *p;
+ unsigned int i;
+
+ p = (uint8_t *)dmbr;
+ mbr->mbr_dmbrzeros = 0;
+ for (i = 0; i < sizeof(struct dos_mbr) && *p == 0; i++, p++)
+ mbr->mbr_dmbrzeros++;
memcpy(mbr->mbr_code, dmbr->dmbr_boot, sizeof(mbr->mbr_code));
mbr->mbr_lba_self = lba_self;
unsigned int i, nprt;
unsigned char id;
+ if (mbr->mbr_dmbrzeros == sizeof(struct dos_mbr))
+ return 1; /* All zeros struct dos_mbr is editable. */
+
nprt = 0;
for (i = 0; i < NDOSPART; i++) {
bs = mbr->mbr_prt[i].prt_bs;
-/* $OpenBSD: mbr.h,v 1.43 2022/07/25 17:45:16 krw Exp $ */
+/* $OpenBSD: mbr.h,v 1.44 2022/07/26 14:30:37 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
unsigned char mbr_code[DOSPARTOFF];
struct prt mbr_prt[NDOSPART];
uint16_t mbr_signature;
+ unsigned int mbr_dmbrzeros;
};
extern struct dos_mbr default_dmbr;