Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sysinst Deal with manualy set disk geometries more ...



details:   https://anonhg.NetBSD.org/src/rev/7d060982fd54
branches:  trunk
changeset: 452148:7d060982fd54
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Jun 19 17:32:31 2019 +0000

description:
Deal with manualy set disk geometries more carefully to avoid a division
by zero.

diffstat:

 usr.sbin/sysinst/arch/i386/md.c |  17 ++++++++---------
 usr.sbin/sysinst/mbr.c          |  28 +++++++++++++++++++---------
 usr.sbin/sysinst/mbr.h          |   4 ++--
 3 files changed, 29 insertions(+), 20 deletions(-)

diffs (134 lines):

diff -r cc6250e2959f -r 7d060982fd54 usr.sbin/sysinst/arch/i386/md.c
--- a/usr.sbin/sysinst/arch/i386/md.c   Wed Jun 19 16:14:07 2019 +0000
+++ b/usr.sbin/sysinst/arch/i386/md.c   Wed Jun 19 17:32:31 2019 +0000
@@ -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 @@
        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 @@
                }
        }
        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;
diff -r cc6250e2959f -r 7d060982fd54 usr.sbin/sysinst/mbr.c
--- a/usr.sbin/sysinst/mbr.c    Wed Jun 19 16:14:07 2019 +0000
+++ b/usr.sbin/sysinst/mbr.c    Wed Jun 19 17:32:31 2019 +0000
@@ -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 @@
        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 @@
  * 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 @@
        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 @@
                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 @@
 {
        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
diff -r cc6250e2959f -r 7d060982fd54 usr.sbin/sysinst/mbr.h
--- a/usr.sbin/sysinst/mbr.h    Wed Jun 19 16:14:07 2019 +0000
+++ b/usr.sbin/sysinst/mbr.h    Wed Jun 19 17:32:31 2019 +0000
@@ -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    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);



Home | Main Index | Thread Index | Old Index