Module Name: src Committed By: martin Date: Wed Jun 19 17:32:31 UTC 2019
Modified Files: src/usr.sbin/sysinst: mbr.c mbr.h src/usr.sbin/sysinst/arch/i386: md.c Log Message: Deal with manualy set disk geometries more carefully to avoid a division by zero. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/sysinst/mbr.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/sysinst/mbr.h cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/sysinst/arch/i386/md.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/sysinst/mbr.c diff -u src/usr.sbin/sysinst/mbr.c:1.13 src/usr.sbin/sysinst/mbr.c:1.14 --- src/usr.sbin/sysinst/mbr.c:1.13 Sat Jun 15 08:20:33 2019 +++ src/usr.sbin/sysinst/mbr.c Wed Jun 19 17:32:31 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: mbr.c,v 1.13 2019/06/15 08:20:33 martin Exp $ */ +/* $NetBSD: mbr.c,v 1.14 2019/06/19 17:32:31 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -243,7 +243,7 @@ set_bios_geom_with_mbr_guess(struct disk msg_display(MSG_nobiosgeom, pm->dlcyl, pm->dlhead, pm->dlsec); if (guess_biosgeom_from_parts(parts, &cyl, &head, &sec) >= 0) msg_display_add(MSG_biosguess, cyl, head, sec); - set_bios_geom(parts, cyl, head, sec); + set_bios_geom(parts, &cyl, &head, &sec); if (parts->pscheme->change_disk_geom) parts->pscheme->change_disk_geom(parts, cyl, head, sec); @@ -267,7 +267,7 @@ mbr_init_chs(struct mbr_disk_partitions * store in globals. */ void -set_bios_geom(struct disk_partitions *parts, int cyl, int head, int sec) +set_bios_geom(struct disk_partitions *parts, int *cyl, int *head, int *sec) { char res[80]; int bsec, bhead, bcyl; @@ -279,13 +279,13 @@ set_bios_geom(struct disk_partitions *pa msg_display_add(MSG_setbiosgeom); do { - snprintf(res, 80, "%d", sec); + snprintf(res, 80, "%d", *sec); msg_prompt_add(MSG_sectors, res, res, 80); bsec = atoi(res); } while (bsec <= 0 || bsec > MAXSECTOR); do { - snprintf(res, 80, "%d", head); + snprintf(res, 80, "%d", *head); msg_prompt_add(MSG_heads, res, res, 80); bhead = atoi(res); } while (bhead <= 0 || bhead > MAXHEAD); @@ -297,7 +297,10 @@ set_bios_geom(struct disk_partitions *pa bcyl = MAXCYL; pm->max_chs = (unsigned long)bcyl * bhead * bsec; pm->current_cylsize = bhead * bsec; - parts->pscheme->change_disk_geom(parts, cyl, head, sec); + parts->pscheme->change_disk_geom(parts, bcyl, bhead, bsec); + *cyl = bcyl; + *head = bhead; + *sec = bsec; } static int @@ -915,12 +918,19 @@ mbr_write_to_disk(struct disk_partitions { struct mbr_disk_partitions *parts = (struct mbr_disk_partitions *)new_state; - unsigned long bsec = parts->geo_sec, - bhead = parts->ext_ptn_alignment / bsec, - bcyl; + unsigned long bsec, bhead, bcyl; daddr_t t; + assert(parts->geo_sec != 0); + if (parts->geo_sec != 0) { + bsec = parts->geo_sec; + bhead = parts->ext_ptn_alignment / bsec; + } else { + bsec = MAXSECTOR; + bhead = MAXHEAD; + } t = bsec * bhead; + assert(t != 0); if ((daddr_t)(1UL<<10) * t <= parts->dp.disk_size) bcyl = (1UL<<10) - 1; else Index: src/usr.sbin/sysinst/mbr.h diff -u src/usr.sbin/sysinst/mbr.h:1.2 src/usr.sbin/sysinst/mbr.h:1.3 --- src/usr.sbin/sysinst/mbr.h:1.2 Wed Jun 12 06:20:17 2019 +++ src/usr.sbin/sysinst/mbr.h Wed Jun 19 17:32:31 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: mbr.h,v 1.2 2019/06/12 06:20:17 martin Exp $ */ +/* $NetBSD: mbr.h,v 1.3 2019/06/19 17:32:31 martin Exp $ */ /* * Copyright 1997, 1988 Piermont Information Systems Inc. @@ -99,7 +99,7 @@ int partsoverlap(struct mbr_partition * int guess_biosgeom_from_parts(struct disk_partitions*, int *, int *, int *); bool set_bios_geom_with_mbr_guess(struct disk_partitions*); -void set_bios_geom(struct disk_partitions *, int cyl, int head, int sec); +void set_bios_geom(struct disk_partitions *, int *cyl, int *head, int *sec); int otherpart(int); int ourpart(int); void edit_ptn_bounds(void); Index: src/usr.sbin/sysinst/arch/i386/md.c diff -u src/usr.sbin/sysinst/arch/i386/md.c:1.16 src/usr.sbin/sysinst/arch/i386/md.c:1.17 --- src/usr.sbin/sysinst/arch/i386/md.c:1.16 Mon Jun 17 14:18:32 2019 +++ src/usr.sbin/sysinst/arch/i386/md.c Wed Jun 19 17:32:31 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: md.c,v 1.16 2019/06/17 14:18:32 martin Exp $ */ +/* $NetBSD: md.c,v 1.17 2019/06/19 17:32:31 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -533,7 +533,8 @@ get_bios_info(const char *dev, struct di if (nip == NULL || nip->ni_nmatches == 0) { nogeom: if (nip != NULL) - msg_display(MSG_nobiosgeom, pm->dlcyl, pm->dlhead, pm->dlsec); + msg_display(MSG_nobiosgeom, pm->dlcyl, pm->dlhead, + pm->dlsec); if (guess_biosgeom_from_parts(parts, &cyl, &head, &sec) >= 0 && nip != NULL) msg_display_add(MSG_biosguess, cyl, head, sec); @@ -571,13 +572,11 @@ nogeom: } } if (biosdisk == NULL) { - if (nip != NULL) { - set_bios_geom(parts, cyl, head, sec); - } else { - *bcyl = cyl; - *bhead = head; - *bsec = sec; - } + *bcyl = cyl; + *bhead = head; + *bsec = sec; + if (nip != NULL) + set_bios_geom(parts, bcyl, bhead, bsec); } else { *bcyl = biosdisk->bi_cyl; *bhead = biosdisk->bi_head;