Subject: install/17740: sysinst: cylinder size used in mbr/disklabel editor is incorrect
To: None <gnats-bugs@gnats.netbsd.org>
From: None <grant@netbsd.org>
List: netbsd-bugs
Date: 07/28/2002 19:26:50
>Number:         17740
>Category:       install
>Synopsis:       sysinst: cylinder size used in mbr/disklabel editor is incorrect
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    install-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jul 28 02:25:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     grant beattie
>Release:        NetBSD 1.6E
>Organization:
>Environment:
System: NetBSD mofo 1.6E NetBSD 1.6E (GENERIC) #0: Sat Jul 27 02:36:36 EST 2002 grant@mofo:/raid/netbsd/current/20020726/i386/obj/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
wd1: 38172 MB, 16383 cyl, 16 head, 63 sec, 512 bytes/sect x 78177792 sectors

While using the mbr or disklabel editor, sysinst reports that this
disk has 4866 cylinders.

This is because the cylinder size is calculated using the bogus BIOS
geometry, rather than the real disk geometry.

disks.c line 166:

<--
	sectorsize = disk->dd_secsize;
	if (disk->dd_totsec == 0)
		disk->dd_totsec = disk->dd_cyl * disk->dd_head * disk->dd_sec;
	dlcyl = disk->dd_cyl;
	dlhead = disk->dd_head;
	dlsec = disk->dd_sec;
	dlsize = disk->dd_totsec;
	dlcylsize = dlhead * dlsec;
-->

similarly, arch/i386/md.c line 562:

<--
	bcylsize = bhead * bsec;
-->

This is serious, as it results in the cylinder values being
completely wrong and therefore, rather useless.

>How-To-Repeat:
run sysinst, choose 'cylinder' size partition editing, compare with
how many cylinders the kernel says the disk has (and therefore, the
disklabel).

>Fix:
The following patch fixes this by using the real geometry to calculate
cylinder size. Tested on i386 only.

Index: disks.c
===================================================================
RCS file: /cvsroot/basesrc/distrib/utils/sysinst/disks.c,v
retrieving revision 1.45
diff -u -r1.45 disks.c
--- disks.c	2002/06/30 04:02:47	1.45
+++ disks.c	2002/07/28 09:00:09
@@ -170,7 +170,7 @@
 	dlhead = disk->dd_head;
 	dlsec = disk->dd_sec;
 	dlsize = disk->dd_totsec;
-	dlcylsize = dlhead * dlsec;
+	dlcylsize = dlsize / dlcyl;
 
 	return numdisks;
 }
Index: arch/i386/md.c
===================================================================
RCS file: /cvsroot/basesrc/distrib/utils/sysinst/arch/i386/md.c,v
retrieving revision 1.62
diff -u -r1.62 md.c
--- arch/i386/md.c	2002/07/26 00:42:04	1.62
+++ arch/i386/md.c	2002/07/28 09:00:16
@@ -559,7 +559,7 @@
 		bsize = dlsize;
 	else
 		bsize = bcyl * bhead * bsec;
-	bcylsize = bhead * bsec;
+	bcylsize = dlsize / dlcyl;
 	return 0;
 }
 
>Release-Note:
>Audit-Trail:
>Unformatted: