From avg@kiev.net.ua  Thu Feb 28 19:38:47 2008
Return-Path: <avg@kiev.net.ua>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E585B1065670
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Feb 2008 19:38:47 +0000 (UTC)
	(envelope-from avg@kiev.net.ua)
Received: from hosted.kievnet.com (hosted.kievnet.com [193.138.144.10])
	by mx1.freebsd.org (Postfix) with ESMTP id 8F6048FC1B
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Feb 2008 19:38:47 +0000 (UTC)
	(envelope-from avg@kiev.net.ua)
Received: from [91.193.172.111] (helo=edge)
	by hosted.kievnet.com with esmtpa (Exim 4.62)
	(envelope-from <avg@kiev.net.ua>)
	id 1JUoab-000DUF-4H
	for FreeBSD-gnats-submit@freebsd.org; Thu, 28 Feb 2008 21:38:45 +0200
Received: from edge (localhost [127.0.0.1])
	by edge (8.14.2/8.14.2) with ESMTP id m1SJccxx020758
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Feb 2008 21:38:38 +0200 (EET)
	(envelope-from avg@edge)
Received: (from avg@localhost)
	by edge (8.14.2/8.14.2/Submit) id m1SJcbkU020757;
	Thu, 28 Feb 2008 21:38:37 +0200 (EET)
	(envelope-from avg)
Message-Id: <200802281938.m1SJcbkU020757@edge>
Date: Thu, 28 Feb 2008 21:38:37 +0200 (EET)
From: Andriy Gapon <avg@icyb.net.ua>
To: FreeBSD-gnats-submit@freebsd.org
Subject: newfs_msdos should supports devices without CHS characteristics
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         121182
>Category:       bin
>Synopsis:       [patch] newfs_msdos(8) should supports devices without CHS characteristics
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 28 19:40:01 UTC 2008
>Closed-Date:    Sun Jan 03 13:27:24 UTC 2010
>Last-Modified:  Sun Jan 03 13:27:24 UTC 2010
>Originator:     Andriy Gapon
>Release:        FreeBSD 7.0-RC1 i386
>Organization:
>Environment:
System: FreeBSD 7.0-RC1 i386


	
>Description:
Currently newfs_msdos strictly requires that a device provides CHS characteristics.
And this is the case even if a user provided values for those parameters via
command line options.
First, in a modern world CHS requirements are no longer valid.
Second, user-provided overrides should be honored and undoubted.

>How-To-Repeat:
Try to format a DVD-RAM disk to FAT, e.g. FAT32:
newfs_msdos -F 32 /dev/acd1

>Fix:
The logic for faking CHS parameters is borrowed from bsdlabel code.

--- newfs-chs.patch begins here ---
--- newfs_msdos.c.orig	2008-02-21 21:35:00.000000000 +0200
+++ newfs_msdos.c	2008-02-21 21:56:13.000000000 +0200
@@ -739,13 +739,25 @@
     /* Maybe it's a fixed drive */
     if (lp == NULL) {
 	if (ioctl(fd, DIOCGDINFO, &dlp) == -1) {
-	    if (ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1)
+	    if (bpb->bps == 0 && ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1)
 		errx(1, "Cannot get sector size, %s", strerror(errno));
-	    if (ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1)
-		errx(1, "Cannot get number of sectors, %s", strerror(errno));
-	    if (ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks)== -1)
-		errx(1, "Cannot get number of heads, %s", strerror(errno));
+
+	    /* XXX Should we use bpb->bps if it's set? */
 	    dlp.d_secperunit = ms / dlp.d_secsize;
+
+	    if (bpb->spt == 0 && ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1) {
+		warnx("Cannot get number of sectors per track, %s", strerror(errno));
+		dlp.d_nsectors = 63;
+	    }
+	    if (bpb->hds == 0 && ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks) == -1) {
+		warnx("Cannot get number of heads, %s", strerror(errno));
+		if (dlp.d_secperunit <= 63*1*1024)
+		    dlp.d_ntracks = 1;
+		else if (dlp.d_secperunit <= 63*16*1024)
+		    dlp.d_ntracks = 16;
+		else
+		    dlp.d_ntracks = 255;
+	    }
 	}
 
 	hs = (ms / dlp.d_secsize) - dlp.d_secperunit;
--- newfs-chs.patch ends here ---


>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/121182: commit references a PR
Date: Fri, 27 Feb 2009 17:30:08 +0000 (UTC)

 Author: avg
 Date: Fri Feb 27 17:29:48 2009
 New Revision: 189112
 URL: http://svn.freebsd.org/changeset/base/189112
 
 Log:
   newfs_msdos: allow to work with media that doesn't have any CHS params
   
   Either use parameters provided by user or make them up.
   The code for faking CHS params is borrowed from disklabel code.
   The logic for using user-provided and auto-guessed parameters is not
   perfect, so to speak.
   
   PR:		bin/121182
   Approved by:	jhb (mentor)
 
 Modified:
   head/sbin/newfs_msdos/newfs_msdos.c
 
 Modified: head/sbin/newfs_msdos/newfs_msdos.c
 ==============================================================================
 --- head/sbin/newfs_msdos/newfs_msdos.c	Fri Feb 27 17:29:31 2009	(r189111)
 +++ head/sbin/newfs_msdos/newfs_msdos.c	Fri Feb 27 17:29:48 2009	(r189112)
 @@ -793,13 +793,25 @@ getdiskinfo(int fd, const char *fname, c
      /* Maybe it's a fixed drive */
      if (lp == NULL) {
  	if (ioctl(fd, DIOCGDINFO, &dlp) == -1) {
 -	    if (ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1)
 +	    if (bpb->bps == 0 && ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1)
  		errx(1, "Cannot get sector size, %s", strerror(errno));
 -	    if (ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1)
 -		errx(1, "Cannot get number of sectors, %s", strerror(errno));
 -	    if (ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks)== -1)
 -		errx(1, "Cannot get number of heads, %s", strerror(errno));
 +
 +	    /* XXX Should we use bpb->bps if it's set? */
  	    dlp.d_secperunit = ms / dlp.d_secsize;
 +
 +	    if (bpb->spt == 0 && ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1) {
 +		warnx("Cannot get number of sectors per track, %s", strerror(errno));
 +		dlp.d_nsectors = 63;
 +	    }
 +	    if (bpb->hds == 0 && ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks) == -1) {
 +		warnx("Cannot get number of heads, %s", strerror(errno));
 +		if (dlp.d_secperunit <= 63*1*1024)
 +		    dlp.d_ntracks = 1;
 +		else if (dlp.d_secperunit <= 63*16*1024)
 +		    dlp.d_ntracks = 16;
 +		else
 +		    dlp.d_ntracks = 255;
 +	    }
  	}
  
  	hs = (ms / dlp.d_secsize) - dlp.d_secperunit;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: emaste 
State-Changed-When: Thu Mar 19 19:59:42 UTC 2009 
State-Changed-Why:  
Appears the patch has been applied. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121182 

From: Alexander Best <alexbestms@math.uni-muenster.de>
To: <bug-followup@FreeBSD.org>,
 <avg@icyb.net.ua>
Cc:  
Subject: Re: bin/121182: [patch] newfs_msdos(8) should supports devices
 without CHS characteristics
Date: Tue, 03 Nov 2009 01:54:38 +0100 (CET)

 indeed it has.
 
 patch is in 9-current (r189112), 8-stable (r189112) and 7-stable (r194032).
 missing in 6-stable.
 
 alex
State-Changed-From-To: patched->closed 
State-Changed-By: gavin 
State-Changed-When: Sun Jan 3 13:27:00 UTC 2010 
State-Changed-Why:  
I think this can be closed, it's fixed in HEAD, 8.x and 7.x. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121182 
>Unformatted:
