diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2016-01-06 02:10:04 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2016-01-06 02:10:04 +0000 |
commit | 35bb0b4212bfd9dbebfe59e5a996bf5b54f0c6bf (patch) | |
tree | 87a39dac71f5c3f01f154f56c81a5be23fe0a6d2 /sys | |
parent | 11933600925cacbdbefcc2ad9fc5dff97ca6d2d6 (diff) |
Bring efidev.c goodness into softraid.c by returning and displaying
the same error messages on GPT processing failures.
Add a message about failed GPT entry checksum error to both. This
was inadvertantly deleted in the switch to one entry at a time
processing.
tweaks & ok yasuoka@ jsing@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/amd64/stand/efiboot/efidev.c | 10 | ||||
-rw-r--r-- | sys/arch/amd64/stand/libsa/softraid.c | 38 |
2 files changed, 35 insertions, 13 deletions
diff --git a/sys/arch/amd64/stand/efiboot/efidev.c b/sys/arch/amd64/stand/efiboot/efidev.c index e6bd1014305..22a6463f80f 100644 --- a/sys/arch/amd64/stand/efiboot/efidev.c +++ b/sys/arch/amd64/stand/efiboot/efidev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efidev.c,v 1.15 2016/01/03 15:01:31 krw Exp $ */ +/* $OpenBSD: efidev.c,v 1.16 2016/01/06 02:10:03 krw Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -387,8 +387,12 @@ findopenbsd_gpt(efi_diskinfo_t ed, const char **err) found = 1; } } - if (found && new_csum == letoh32(gh.gh_part_csum)) - return letoh64(gp.gp_lba_start); + if (new_csum != letoh32(gh.gh_part_csum)) { + *err = "bad GPT entries checksum\n"; + return (-1); + } + if (found) + return (letoh64(gp.gp_lba_start)); return (-1); } diff --git a/sys/arch/amd64/stand/libsa/softraid.c b/sys/arch/amd64/stand/libsa/softraid.c index 63129387168..01091e3db17 100644 --- a/sys/arch/amd64/stand/libsa/softraid.c +++ b/sys/arch/amd64/stand/libsa/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.23 2016/01/04 02:31:18 krw Exp $ */ +/* $OpenBSD: softraid.c,v 1.24 2016/01/06 02:10:03 krw Exp $ */ /* * Copyright (c) 2012 Joel Sing <jsing@openbsd.org> @@ -47,7 +47,7 @@ SLIST_HEAD(sr_boot_keydisk_head, sr_boot_keydisk); struct sr_boot_keydisk_head sr_keydisks; static int gpt_chk_mbr(struct dos_partition *, u_int64_t); -static uint64_t findopenbsd_gpt(struct sr_boot_volume *); +static uint64_t findopenbsd_gpt(struct sr_boot_volume *, const char **); void srprobe_meta_opt_load(struct sr_metadata *sm, struct sr_meta_opt_head *som) @@ -436,7 +436,7 @@ gpt_chk_mbr(struct dos_partition *dp, u_int64_t dsize) } static uint64_t -findopenbsd_gpt(struct sr_boot_volume *bv) +findopenbsd_gpt(struct sr_boot_volume *bv, const char **err) { struct gpt_header gh; int i, part, found; @@ -470,23 +470,31 @@ findopenbsd_gpt(struct sr_boot_volume *bv) memcpy(&gh, buf, sizeof(gh)); /* Check signature */ - if (letoh64(gh.gh_sig) != GPTSIGNATURE) + if (letoh64(gh.gh_sig) != GPTSIGNATURE) { + *err = "bad GPT signature\n"; return (-1); + } - if (letoh32(gh.gh_rev) != GPTREVISION) + if (letoh32(gh.gh_rev) != GPTREVISION) { + *err = "bad GPT revision\n"; return (-1); + } ghsize = letoh32(gh.gh_size); - if (ghsize < GPTMINHDRSIZE || ghsize > sizeof(struct gpt_header)) + if (ghsize < GPTMINHDRSIZE || ghsize > sizeof(struct gpt_header)) { + *err = "bad GPT header size\n"; return (-1); + } /* Check checksum */ orig_csum = gh.gh_csum; gh.gh_csum = 0; new_csum = crc32(0, (unsigned char *)&gh, ghsize); gh.gh_csum = orig_csum; - if (letoh32(orig_csum) != new_csum) + if (letoh32(orig_csum) != new_csum) { + *err = "bad GPT header checksum\n"; return (-1); + } lba = letoh64(gh.gh_part_lba); ghpartsize = letoh32(gh.gh_part_size); @@ -511,8 +519,12 @@ findopenbsd_gpt(struct sr_boot_volume *bv) found = 1; } } - if (found && new_csum == letoh32(gh.gh_part_csum)) - return letoh64(gp.gp_lba_start); + if (new_csum != letoh32(gh.gh_part_csum)) { + *err = "bad GPT entries checksum\n"; + return (-1); + } + if (found) + return (letoh64(gp.gp_lba_start)); return (-1); } @@ -522,6 +534,7 @@ sr_getdisklabel(struct sr_boot_volume *bv, struct disklabel *label) { struct dos_partition *dp; struct dos_mbr mbr; + const char *err = NULL; u_int start = 0; char buf[DEV_BSIZE]; int i; @@ -530,7 +543,12 @@ sr_getdisklabel(struct sr_boot_volume *bv, struct disklabel *label) bzero(&mbr, sizeof(mbr)); sr_strategy(bv, F_READ, DOSBBSECTOR, sizeof(mbr), &mbr, NULL); if (gpt_chk_mbr(mbr.dmbr_parts, bv->sbv_size) == 0) { - start = findopenbsd_gpt(bv); + start = findopenbsd_gpt(bv, &err); + if (start == (u_int)-1) { + if (err != NULL) + return (err); + return "no OpenBSD partition\n"; + } } else if (mbr.dmbr_sign == DOSMBR_SIGNATURE) { /* Search for OpenBSD partition */ |