NetBSD Problem Report #31503

From wgstuken@s012.nagler-company.com  Fri Oct  7 12:23:35 2005
Return-Path: <wgstuken@s012.nagler-company.com>
Received: from s012.nagler-company.com (s012.nagler-company.com [212.222.97.133])
	by narn.netbsd.org (Postfix) with ESMTP id 85A0D63B8A6
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  7 Oct 2005 12:23:34 +0000 (UTC)
Message-Id: <200510071223.j97CNRIa026540@s012.nagler-company.com>
Date: Fri, 7 Oct 2005 14:23:27 +0200 (CEST)
From: Wolfgang Stukenbrock <wgstuken@s012.nagler-company.com>
Reply-To: wgstuken@s012.nagler-company.com
To: gnats-bugs@netbsd.org
Subject: feature/bug in fdisk on i386
X-Send-Pr-Version: 3.95

>Number:         31503
>Category:       port-i386
>Synopsis:       fdisk on i386 will fail to setup new empty disks
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    port-i386-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 07 12:24:00 +0000 2005
>Last-Modified:  Mon Oct 17 12:17:00 +0000 2005
>Originator:     Wolfgang Stukenbrock
>Release:        NetBSD 2.0.2
>Organization:
Dr. Nagler & Comapny GmbH
>Environment:


System: NetBSD s012 2.0_RC5 NetBSD 2.0_RC5 (S012) #6: Tue Nov 30 11:38:39 CET 2004 wgstuken@s012:/export/netbsd-2.0rc4/src/sys/arch/i386/compile/S012 i386
Architecture: i386
Machine: i386
>Description:
	If multiple new disks of different size are added to a system, fdisk will
	fail to setup theese disks.
	The problem is, that theese new disk have no valid sector 0 and are placed
	in the same "match-group" by the kernel when the diskinformation is retrieved
	by fdisk.
	fdisk will determine the correct number of disksectors from the NetBSD-disklabel,
	but will use always the first entry in the "match-group" of disks.
	If disks of different size are added, the first entry may have a wrong number of
	disksectors and so the dos-disksector variable will be wrong.
	If the retrieved entry is smaller than the selected disk, only a part of the disk
	may be setup by fdisk and the wrong number of disksectors will be stored in sector 0.
	The reamining space of the disk is lost forever ...

	This problem may be fixed be searching for an entry in the "match-group" with the
	same number of disksectors as retrieved from the NetBSD-disklabel.
	The BIOS-Information for the disk retrieved from the selected "match-entry" is only
	used to setup the number of heads etc. and this information is fictivious for all
	kind of acual disks on i386 platforms.

	The fix below added code to /usr/src/sbin/fdisk/fdisk.c to search for a disk with
	the same number of disksectors and gets the head, cyl and sector information from
	that disk.
	If none is found, a warning is printed and the first entry is slected as before.
	(perhaps fdisk should terminate if no match is found ...)

	Ths fix only affects a routine that belongs to the i386 and x86 port.
>How-To-Repeat:
	add several new emtpy disk to a i386 system, run fdisk and look ath the reported
	number of disksectors for NetBSD and BIOS label.
>Fix:
===================================================================
RCS file: RCS/fdisk.c,v
retrieving revision 1.1
diff -c -r1.1 fdisk.c
*** fdisk.c	2005/10/07 08:55:35	1.1
--- fdisk.c	2005/10/07 09:11:37
***************
*** 1034,1040 ****
  		 * just use them, we don't need to know which disk is which.
  		 */
  		if (nip->ni_nmatches != 0) {
! 			bip = &dl->dl_biosdisks[nip->ni_biosmatches[0]];
  			dos_cylinders = bip->bi_cyl;
  			dos_heads = bip->bi_head;
  			dos_sectors = bip->bi_sec;
--- 1034,1054 ----
  		 * just use them, we don't need to know which disk is which.
  		 */
  		if (nip->ni_nmatches != 0) {
! /* need to determine the correct index to use.
!  * there is a feature if we have empty disks, that all empty disk are placed in the same
!  * biosmatches group by the kernel.
!  * As a workaround we search for the correct number of blocks in the list an take that entry
!  */
! 			for (i = 0; i < nip->ni_nmatches; i++)
! 			  {
! 			    bip = &dl->dl_biosdisks[nip->ni_biosmatches[i]];
! 			    if (disksectors == bip->bi_lbasecs) break;
! 			  }
! 			if (i == nip->ni_nmatches)
! 			  {
! 			    bip = &dl->dl_biosdisks[nip->ni_biosmatches[0]];
! 			    printf("WARNING: no matching number of disksectors (%llu) found\n         reverting to old style and take first entry (%llu sectors)\n", disksectors, bip->bi_lbasecs);
! 			  }
  			dos_cylinders = bip->bi_cyl;
  			dos_heads = bip->bi_head;
  			dos_sectors = bip->bi_sec;

>Audit-Trail:
From: Wolfgang Stukenbrock <Wolfgang.Stukenbrock@nagler-company.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: port-i386/31503
Date: Mon, 17 Oct 2005 14:13:49 +0200

 Hi again,

 my previous fix will brak the "-S" option for scripts if the WARNING 
 messages is printed.
 Therefore the WARNING message may not be printed on stdout, it must go 
 to stderr.

 So the fix must look like the following.

 Sorry

 W. Stukenbrock.

 RCS file: RCS/fdisk.c,v
 retrieving revision 1.1
 diff -c -r1.1 fdisk.c
 *** fdisk.c	2005/10/07 08:55:35	1.1
 --- fdisk.c	2005/10/07 09:11:37
 ***************
 *** 1034,1040 ****
    		 * just use them, we don't need to know which disk is which.
    		 */
    		if (nip->ni_nmatches != 0) {
 ! 	 
 	bip = &dl->dl_biosdisks[nip->ni_biosmatches[0]];
    			dos_cylinders = bip->bi_cyl;
    			dos_heads = bip->bi_head;
    			dos_sectors = bip->bi_sec;
 --- 1034,1054 ----
    		 * just use them, we don't need to know which disk is which.
    		 */
    		if (nip->ni_nmatches != 0) {
 ! /* need to determine the correct index to use.
 !  * there is a feature if we have empty disks, that all empty disk are 
 placed in the same
 !  * biosmatches group by the kernel.
 !  * As a workaround we search for the correct number of blocks in the 
 list an take that entry
 !  */
 ! 	 
 	for (i = 0; i < nip->ni_nmatches; i++)
 ! 	 
 	  {
 ! 	 
 	    bip = &dl->dl_biosdisks[nip->ni_biosmatches[i]];
 ! 	 
 	    if (disksectors == bip->bi_lbasecs) break;
 ! 	 
 	  }
 ! 	 
 	if (i == nip->ni_nmatches)
 ! 	 
 	  {
 ! 	 
 	    bip = &dl->dl_biosdisks[nip->ni_biosmatches[0]];
 ! 	 
 	    fprintf(stderr, "WARNING: no matching number of disksectors (%llu) 
 found\n         reverting to old style and take first entry (%llu 
 sectors)\n", disksectors, bip->bi_lbasecs);
 ! 	 
 	  }
    			dos_cylinders = bip->bi_cyl;
    			dos_heads = bip->bi_head;
    			dos_sectors = bip->bi_sec;

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.