NetBSD Problem Report #37414

From martin@duskware.de  Wed Nov 21 10:07:42 2007
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 5B1E963B89A
	for <gnats-bugs@gnats.netbsd.org>; Wed, 21 Nov 2007 10:07:42 +0000 (UTC)
Message-Id: <20071121094320.7F83D63B88C@narn.NetBSD.org>
Date: Wed, 21 Nov 2007 09:43:20 +0000 (UTC)
From: rillig@NetBSD.org
Reply-To: rillig@NetBSD.org
To: netbsd-bugs-owner@NetBSD.org
Subject: fdisk suggests input formats it doesn't accept
X-Send-Pr-Version: www-1.0

>Number:         37414
>Category:       bin
>Synopsis:       fdisk suggests input formats it doesn't accept
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Nov 21 10:10:00 +0000 2007
>Closed-Date:    Wed Nov 04 22:26:29 +0000 2009
>Last-Modified:  Sat Nov 28 17:30:03 +0000 2009
>Originator:     Roland Illig
>Release:        NetBSD 4.99.30
>Organization:
>Environment:
>Description:

>How-To-Repeat:

Which partition do you want to change?: [none] 0
The data for partition 0 is:
Primary DOS with 32 bit FAT - LBA (sysid 12)
    start 63, size 976751937 (476930 MB, Cyls 0-60799)
sysid: [0..255 default: 12] 
start: [0..60801cyl default: 63, 0cyl, 0MB] 
size: [0..60801cyl default: 976751937, 60800cyl, 476930MB] 20480MB
20480MB is not a valid sector number.

The choices in the text suggested to me that I could input the size of the partition in megabytes, but fdisk doesn't accept that.

>Fix:
Allow user input in the formats that are specified in the brackets.

>Release-Note:

>Audit-Trail:
From: dieter roelants <dieter.NetBSD@pandora.be>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/37414: fdisk suggests input formats it doesn't accept
Date: Sun, 2 Dec 2007 17:26:35 +0100

 This is a multi-part message in MIME format.

 --Multipart=_Sun__2_Dec_2007_17_26_35_+0100_EzLel_04swsA1qx6
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit


 What about attached patch? It makes fdisk accept the full units as well
 as the first letter as before, and everything in between (c, cy, cyl).

 dieter


 --Multipart=_Sun__2_Dec_2007_17_26_35_+0100_EzLel_04swsA1qx6
 Content-Type: text/plain;
  name="patch2"
 Content-Disposition: attachment;
  filename="patch2"
 Content-Transfer-Encoding: base64

 SW5kZXg6IGZkaXNrLmMNCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT0NClJDUyBmaWxlOiAvY3Zzcm9vdC9zcmMvc2Jpbi9m
 ZGlzay9mZGlzay5jLHYNCnJldHJpZXZpbmcgcmV2aXNpb24gMS4xMTANCmRpZmYgLXUgLXIxLjEx
 MCBmZGlzay5jDQotLS0gZmRpc2suYwkyOSBOb3YgMjAwNyAyMzoxOToyNSAtMDAwMAkxLjExMA0K
 KysrIGZkaXNrLmMJMiBEZWMgMjAwNyAxNjowMzo1MiAtMDAwMA0KQEAgLTU2LDYgKzU2LDcgQEAN
 CiAjaW5jbHVkZSA8c3RkaW8uaD4NCiAjaW5jbHVkZSA8c3RkbGliLmg+DQogI2luY2x1ZGUgPHN0
 cmluZy5oPg0KKyNpbmNsdWRlIDxzdHJpbmdzLmg+DQogI2luY2x1ZGUgPHVuaXN0ZC5oPg0KICNp
 bmNsdWRlIDx2aXMuaD4NCiANCkBAIC0yNTY4LDEwICsyNTY5LDExIEBADQogZGVjaW1hbChjb25z
 dCBjaGFyICpwcm9tcHQsIGludCBkZmx0LCBpbnQgZmxhZ3MsIGludCBtaW52YWwsIGludCBtYXh2
 YWwpDQogew0KIAlpbnQgYWNjID0gMDsNCisJaW50IGxlbiwgbTsNCiAJY2hhciAqY3A7DQotCWNo
 YXIgY2g7DQogDQogCWZvciAoOzspIHsNCisJCW0gPSAxOw0KIAkJaWYgKGZsYWdzICYgREVDX1NF
 Qykgew0KIAkJCXBy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DQorCQkJCWlmICgobSAqPSBzdHJuY2FzZWNtcChjcCwgImN5bCIsIGxlbikpID09IDApIHsNCiAJ
 CQkJCWFjYyAqPSBkb3NfY3lsaW5kZXJzZWN0b3JzOw0KIAkJCQkJLyogYWRqdXN0bWVudHMgZm9y
 IGN5bGluZGVyIGJvdW5kYXJ5ICovDQogCQkJCQlpZiAoYWNjID09IDAgJiYgZmxhZ3MgJiBERUNf
 Uk5EXzApDQpAQCAtMjYyMCwxMSArMjYyMCwxMiBAQA0KIAkJCQkJaWYgKGZsYWdzICYgREVDX1JO
 RF9ET1dOXzIpDQogCQkJCQkJYWNjIC09IGRvc19zZWN0b3JzOw0KIAkJCQl9DQorCQkJCWNwICs9
 IGxlbjsNCiAJCQl9DQogCQl9DQogDQogCQljcCArPSBzdHJzcG4oY3AsICIgXHQiKTsNCi0JCWlm
 ICgqY3AgIT0gJ1wwJykgew0KKwkJaWYgKCgqY3AgIT0gJ1wwJykgfHwgKG0gIT0gMCkpIHsNCiAJ
 CQlwcmludGYoIiVzIGlzIG5vdCBhIHZhbGlkICVzIG51bWJlci5cbiIsIGxidWYsDQogCQkJICAg
 IGZsYWdzICYgREVDX1NFQyA/ICJzZWN0b3IiIDogImRlY2ltYWwiKTsNCiAJCQljb250aW51ZTsN
 Cg==

 --Multipart=_Sun__2_Dec_2007_17_26_35_+0100_EzLel_04swsA1qx6--

From: dieter roelants <dieter.NetBSD@pandora.be>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/37414: fdisk suggests input formats it doesn't accept
Date: Sun, 2 Dec 2007 17:55:40 +0100

 ... and here is the same patch inline, so people can read it after
 being through gnats:

 Index: fdisk.c
 ===================================================================
 RCS file: /cvsroot/src/sbin/fdisk/fdisk.c,v
 retrieving revision 1.110
 diff -u -r1.110 fdisk.c
 --- fdisk.c	29 Nov 2007 23:19:25 -0000	1.110
 +++ fdisk.c	2 Dec 2007 16:03:52 -0000
 @@ -56,6 +56,7 @@
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
 +#include <strings.h>
  #include <unistd.h>
  #include <vis.h>

 @@ -2568,10 +2569,11 @@
  decimal(const char *prompt, int dflt, int flags, int minval, int maxval)
  {
  	int acc = 0;
 +	int len, m;
  	char *cp;
 -	char ch;

  	for (;;) {
 +		m = 1;
  		if (flags & DEC_SEC) {
  			printf("%s: [%d..%dcyl default: %d, %dcyl, %uMB] ",
  			    prompt, SEC_TO_CYL(minval), SEC_TO_CYL(maxval),
 @@ -2594,21 +2596,19 @@

  		if (isdigit((unsigned char)*cp) || *cp == '-') {
  			acc = strtol(lbuf, &cp, 10);
 -			if (flags & DEC_SEC) {
 -				ch = *cp;
 -				if (ch == 'g' || ch == 'G') {
 +			len = strcspn(cp, " \t");
 +			m = 0;
 +			if (len && (flags & DEC_SEC)) {
 +				if ((m = strncasecmp(cp, "GB", len)) == 0) {
  					acc *= 1024;
 -					ch = 'm';
  				}
 -				if (ch == 'm' || ch == 'M') {
 +				if ((m *= strncasecmp(cp, "MB", len)) == 0) {
  					acc *= SEC_IN_1M;
  					/* round to whole number of cylinders */
  					acc += dos_cylindersectors / 2;
  					acc /= dos_cylindersectors;
 -					ch = 'c';
  				}
 -				if (ch == 'c' || ch == 'C') {
 -					cp++;
 +				if ((m *= strncasecmp(cp, "cyl", len)) == 0) {
  					acc *= dos_cylindersectors;
  					/* adjustments for cylinder boundary */
  					if (acc == 0 && flags & DEC_RND_0)
 @@ -2620,11 +2620,12 @@
  					if (flags & DEC_RND_DOWN_2)
  						acc -= dos_sectors;
  				}
 +				cp += len;
  			}
  		}

  		cp += strspn(cp, " \t");
 -		if (*cp != '\0') {
 +		if ((*cp != '\0') || (m != 0)) {
  			printf("%s is not a valid %s number.\n", lbuf,
  			    flags & DEC_SEC ? "sector" : "decimal");
  			continue;

 --
 dieter

From: Roland Illig <rillig@NetBSD.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/37414: fdisk suggests input formats it doesn't accept
Date: Sun, 02 Dec 2007 18:41:26 +0100

 dieter roelants wrote:
 > The following reply was made to PR bin/37414; it has been noted by GNATS.
 > 
 > From: dieter roelants <dieter.NetBSD@pandora.be>
 > To: gnats-bugs@NetBSD.org
 > Cc: 
 > Subject: Re: bin/37414: fdisk suggests input formats it doesn't accept
 > Date: Sun, 2 Dec 2007 17:55:40 +0100
 > 
 >  ... and here is the same patch inline, so people can read it after
 >  being through gnats:

 Looks good to me, although people that are used to the old format (400M) 
 cannot use that anymore.

 the m *= strncasecmp() expressions looked weird to me at the first 
 sight, but now I've understood them.

 Roland

From: dieter roelants <dieter.NetBSD@pandora.be>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/37414: fdisk suggests input formats it doesn't accept
Date: Sun, 2 Dec 2007 19:09:59 +0100

 On Sun,  2 Dec 2007 17:45:02 +0000 (UTC)
 Roland Illig <rillig@NetBSD.org> wrote:

 >  Looks good to me, although people that are used to the old format (400M) 
 >  cannot use that anymore.

 Yes they can, unless I've made a mistake. The len variable used by
 strncasecmp here is the length of cp until the next whitespace, so in
 the case of 400M, only one byte is checked.

 >  the m *= strncasecmp() expressions looked weird to me at the first 
 >  sight, but now I've understood them.

 It took me some time to understand the original code as well. :)

 dieter

From: Roland Illig <rillig@NetBSD.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/37414: fdisk suggests input formats it doesn't accept
Date: Sun, 02 Dec 2007 21:03:29 +0100

 dieter roelants wrote:
 >  Roland Illig <rillig@NetBSD.org> wrote:
 >  
 >  >  Looks good to me, although people that are used to the old format (400M) 
 >  >  cannot use that anymore.
 >  
 >  Yes they can, unless I've made a mistake. The len variable used by
 >  strncasecmp here is the length of cp until the next whitespace, so in
 >  the case of 400M, only one byte is checked.

 Bah, lots of tricks. But it sounds well. :)

 Roland

State-Changed-From-To: open->closed
State-Changed-By: dsl@NetBSD.org
State-Changed-When: Wed, 04 Nov 2009 22:26:29 +0000
State-Changed-Why:
simpler patch applied.


From: David Laight <dsl@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/37414 CVS commit: src/sbin/fdisk
Date: Wed, 4 Nov 2009 22:25:56 +0000

 Module Name:	src
 Committed By:	dsl
 Date:		Wed Nov  4 22:25:56 UTC 2009

 Modified Files:
 	src/sbin/fdisk: fdisk.c

 Log Message:
 Allow MB, GB and CYL (not just M, G and C) and lower case.
 Don't output a splurious 'd' before "cyl".
 Fixes PR/37414.
 Patch in PR is wrong!


 To generate a diff of this commit:
 cvs rdiff -u -r1.124 -r1.125 src/sbin/fdisk/fdisk.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Izumi Tsutsui <tsutsui@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/37414 CVS commit: src/sbin/fdisk
Date: Sat, 28 Nov 2009 17:25:46 +0000

 Module Name:	src
 Committed By:	tsutsui
 Date:		Sat Nov 28 17:25:46 UTC 2009

 Modified Files:
 	src/sbin/fdisk: fdisk.8

 Log Message:
 Update -u usage to follow changes in fdisk.c rev 1.125:
 >> Allow MB, GB and CYL (not just M, G and C) and lower case.
 >> Don't output a splurious 'd' before "cyl".
 >> Fixes PR/37414.

 XXX "NNcy" is also allowed?


 To generate a diff of this commit:
 cvs rdiff -u -r1.64 -r1.65 src/sbin/fdisk/fdisk.8

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

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.