need to pass the value to MBR_write().
Let MBR_write() do the translation from struct mbr to the
struct dos_mbr that will be written to the disk. Thus
eliminating unnecessary struct dos_mbr variables and the
parsing thereof.
No intentional functional change.
-/* $OpenBSD: cmd.c,v 1.132 2021/07/17 21:47:56 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.133 2021/07/19 19:23:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
int
Xwrite(char *args, struct mbr *mbr)
{
- struct dos_mbr dos_mbr;
int efi, i, n;
for (i = 0, n = 0; i < NDOSPART; i++)
return CMD_CONT;
}
- MBR_make(mbr, &dos_mbr);
-
printf("Writing MBR at offset %lld.\n", (long long)mbr->mbr_lba_self);
- if (MBR_write(mbr->mbr_lba_self, &dos_mbr) == -1) {
+ if (MBR_write(mbr) == -1) {
warn("error writing MBR");
return CMD_CONT;
}
GPT_zap_headers();
}
- /* Refresh in memory copy to reflect what was just written. */
- MBR_parse(&dos_mbr, mbr->mbr_lba_self, mbr->mbr_lba_firstembr, mbr);
-
return CMD_CLEAN;
}
-/* $OpenBSD: mbr.c,v 1.90 2021/07/19 14:30:08 krw Exp $ */
+/* $OpenBSD: mbr.c,v 1.91 2021/07/19 19:23:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
}
int
-MBR_write(const uint64_t sector, const struct dos_mbr *dos_mbr)
+MBR_write(const struct mbr *mbr)
{
+ struct dos_mbr dos_mbr;
char *secbuf;
- secbuf = DISK_readsector(sector);
+ secbuf = DISK_readsector(mbr->mbr_lba_self);
if (secbuf == NULL)
return -1;
- memcpy(secbuf, dos_mbr, sizeof(*dos_mbr));
- DISK_writesector(secbuf, sector);
+ MBR_make(mbr, &dos_mbr);
+ memcpy(secbuf, &dos_mbr, sizeof(dos_mbr));
+
+ DISK_writesector(secbuf, mbr->mbr_lba_self);
/* Refresh in-kernel disklabel from the updated disk information. */
ioctl(disk.dk_fd, DIOCRLDINFO, 0);
-/* $OpenBSD: mbr.h,v 1.37 2021/07/18 21:40:13 krw Exp $ */
+/* $OpenBSD: mbr.h,v 1.38 2021/07/19 19:23:50 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
void MBR_init(struct mbr *);
void MBR_init_GPT(struct mbr *);
int MBR_read(const uint64_t, const uint64_t, struct mbr *);
-int MBR_write(const uint64_t, const struct dos_mbr *);
+int MBR_write(const struct mbr *);
int MBR_protective_mbr(struct mbr *);
#endif /* _MBR_H */