-/* $OpenBSD: cmd.c,v 1.149 2022/01/22 15:39:00 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.150 2022/01/27 16:26:32 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
edit(const int pn, struct mbr *mbr)
{
struct prt *pp;
+ uint64_t track;
unsigned char oldid;
pp = &mbr->mbr_prt[pn];
(pp->prt_scyl == pp->prt_ecyl && pp->prt_shead ==
pp->prt_ehead) ? pp->prt_ssect : 1, disk.dk_sectors);
- /* Fix up off/size values */
- PRT_fix_BN(pp, pn);
+ /* The ATA/ATAPI spec says LBA = (C × HPC + H) × SPT + (S − 1) */
+ track = (uint64_t)pp->prt_scyl * disk.dk_heads + pp->prt_shead;
+ pp->prt_bs = track * disk.dk_sectors + (pp->prt_ssect - 1);
+ track = (uint64_t)pp->prt_ecyl * disk.dk_heads + pp->prt_ehead;
+ pp->prt_ns = track * disk.dk_sectors + (pp->prt_esect - 1) -
+ pp->prt_bs + 1;
+
/* Fix up CHS values for LBA */
PRT_fix_CHS(pp);
} else {
-/* $OpenBSD: part.c,v 1.112 2022/01/21 17:29:24 krw Exp $ */
+/* $OpenBSD: part.c,v 1.113 2022/01/27 16:26:32 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
prt->prt_bs, size, ut->ut_abbr, ascii_id(prt->prt_id));
}
-void
-PRT_fix_BN(struct prt *prt, const int pn)
-{
- uint32_t spt, tpc, spc;
- uint32_t start = 0;
- uint32_t end = 0;
-
- if (prt->prt_id == DOSPTYP_UNUSED) {
- memset(prt, 0, sizeof(*prt));
- return;
- }
-
- spt = disk.dk_sectors;
- tpc = disk.dk_heads;
- spc = spt * tpc;
-
- start += prt->prt_scyl * spc;
- start += prt->prt_shead * spt;
- start += prt->prt_ssect - 1;
-
- end += prt->prt_ecyl * spc;
- end += prt->prt_ehead * spt;
- end += prt->prt_esect - 1;
-
- /* XXX - Should handle this... */
- if (start > end)
- warnx("Start of partition #%d after end!", pn);
-
- prt->prt_bs = start;
- prt->prt_ns = (end - start) + 1;
-}
-
void
PRT_fix_CHS(struct prt *prt)
{
-/* $OpenBSD: part.h,v 1.32 2022/01/21 17:29:24 krw Exp $ */
+/* $OpenBSD: part.h,v 1.33 2022/01/27 16:26:32 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
struct uuid *PRT_type_to_uuid(const int);
int PRT_protected_guid(const struct uuid *);
-/* This does CHS -> bs/ns */
-void PRT_fix_BN(struct prt *, const int);
-
/* This does bs/ns -> CHS */
void PRT_fix_CHS(struct prt *);