-/* $OpenBSD: part.c,v 1.162 2023/05/17 12:59:37 krw Exp $ */
+/* $OpenBSD: part.c,v 1.163 2023/05/21 17:29:33 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
{ 0xFF, 0xFF, "Xenix BBT", NULL },
};
+void chs_to_dp(const unsigned char, const struct chs *,
+ uint8_t *, uint8_t *, uint8_t *);
const struct gpt_type *find_gpt_type(const struct uuid *);
const struct menu_item *find_gpt_menuitem(const struct gpt_type *);
const char *find_gpt_desc(const struct gpt_type *);
int nth_menu_item(int (*)(const unsigned int),
const unsigned int, unsigned int);
+void
+chs_to_dp(const unsigned char prt_id, const struct chs *chs, uint8_t *dp_cyl,
+ uint8_t *dp_hd, uint8_t *dp_sect)
+{
+ uint64_t cyl = chs->chs_cyl;
+ uint32_t head = chs->chs_head;
+ uint32_t sect = chs->chs_sect;
+
+ if (head > 254 || sect > 63 || cyl > 1023) {
+ /* Set max values to trigger LBA. */
+ head = (prt_id == DOSPTYP_EFI) ? 255 : 254;
+ sect = 63;
+ cyl = 1023;
+ }
+
+ *dp_hd = head & 0xFF;
+ *dp_sect = (sect & 0x3F) | ((cyl & 0x300) >> 2);
+ *dp_cyl = cyl & 0xFF;
+}
+
const struct gpt_type *
find_gpt_type(const struct uuid *uuid)
{
else
off = lba_self;
- if (PRT_lba_to_chs(prt, &start, &end) == 0) {
- dp->dp_shd = start.chs_head & 0xFF;
- dp->dp_ssect = (start.chs_sect & 0x3F) | ((start.chs_cyl & 0x300) >> 2);
- dp->dp_scyl = start.chs_cyl & 0xFF;
- dp->dp_ehd = end.chs_head & 0xFF;
- dp->dp_esect = (end.chs_sect & 0x3F) | ((end.chs_cyl & 0x300) >> 2);
- dp->dp_ecyl = end.chs_cyl & 0xFF;
- } else {
- memset(dp, 0xFF, sizeof(*dp));
- }
+ PRT_lba_to_chs(prt, &start, &end);
+ chs_to_dp(prt->prt_id, &start, &dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect);
+ chs_to_dp(prt->prt_id, &end, &dp->dp_ecyl, &dp->dp_ehd, &dp->dp_esect);
dp->dp_flag = prt->prt_flag & 0xFF;
dp->dp_typ = prt->prt_id & 0xFF;
disk.dk_name);
}
-int
+void
PRT_lba_to_chs(const struct prt *prt, struct chs *start, struct chs *end)
{
uint64_t lba;
if (prt->prt_ns == 0 || prt->prt_id == DOSPTYP_UNUSED) {
memset(start, 0, sizeof(*start));
memset(end, 0, sizeof(*end));
- return -1;
+ return;
}
/*
end->chs_cyl = lba / (disk.dk_sectors * disk.dk_heads);
end->chs_head = (lba / disk.dk_sectors) % disk.dk_heads;
end->chs_sect = (lba % disk.dk_sectors) + 1;
-
- if (start->chs_head > 255 || end->chs_head > 255 ||
- start->chs_sect > 63 || end->chs_sect > 63 ||
- start->chs_cyl > 1023 || end->chs_cyl > 1023)
- return -1;
-
- return 0;
}
const char *
-/* $OpenBSD: part.h,v 1.46 2023/05/17 12:59:37 krw Exp $ */
+/* $OpenBSD: part.h,v 1.47 2023/05/21 17:29:33 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
void PRT_print_gptmenu(char *, size_t);
void PRT_dp_to_prt(const struct dos_partition *, const uint64_t,
const uint64_t, struct prt *);
-void PRT_prt_to_dp(const struct prt *,const uint64_t, const uint64_t,
- struct dos_partition *);
+void PRT_prt_to_dp(const struct prt *,const uint64_t,
+ const uint64_t, struct dos_partition *);
void PRT_print_part(const int, const struct prt *, const char *);
void PRT_print_parthdr(void);
const char *PRT_uuid_to_desc(const struct uuid *);
char *PRT_uuid_to_menudflt(const struct uuid *);
const char *PRT_menuid_to_guid(const int);
int PRT_protected_uuid(const struct uuid *);
-int PRT_lba_to_chs(const struct prt*, struct chs *, struct chs*);
+void PRT_lba_to_chs(const struct prt *, struct chs *, struct chs *);