From owner-freebsd-fs@FreeBSD.ORG Thu Feb 21 20:53:56 2008 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5F67816A400; Thu, 21 Feb 2008 20:53:56 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from falcon.cybervisiontech.com (falcon.cybervisiontech.com [217.20.163.9]) by mx1.freebsd.org (Postfix) with ESMTP id C70D713C46E; Thu, 21 Feb 2008 20:53:55 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from localhost (localhost [127.0.0.1]) by falcon.cybervisiontech.com (Postfix) with ESMTP id 7F1C4744007; Thu, 21 Feb 2008 22:53:54 +0200 (EET) X-Virus-Scanned: Debian amavisd-new at falcon.cybervisiontech.com Received: from falcon.cybervisiontech.com ([127.0.0.1]) by localhost (falcon.cybervisiontech.com [127.0.0.1]) (amavisd-new, port 10027) with ESMTP id INKj9A8S7SWX; Thu, 21 Feb 2008 22:53:54 +0200 (EET) Received: from [10.74.70.239] (unknown [193.138.145.53]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by falcon.cybervisiontech.com (Postfix) with ESMTP id 1FA35744006; Thu, 21 Feb 2008 22:53:52 +0200 (EET) Message-ID: <47BDE4D7.9000007@icyb.net.ua> Date: Thu, 21 Feb 2008 22:53:43 +0200 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.9 (X11/20071208) MIME-Version: 1.0 To: freebsd-geom@freebsd.org, freebsd-fs@freebsd.org, freebsd-current@freebsd.org References: <47B81D07.7090208@icyb.net.ua> <47BD6F39.7080105@icyb.net.ua> In-Reply-To: <47BD6F39.7080105@icyb.net.ua> Content-Type: multipart/mixed; boundary="------------070705030706070407090301" Cc: Subject: Re: newfs_msdos and dvd-ram (fwsectors, fwheads) X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Feb 2008 20:53:56 -0000 This is a multi-part message in MIME format. --------------070705030706070407090301 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Please found attached a patch to newfs_msdos that allows it to work on media for which CHS parameters do not make sense (e.g. DVD-RAM disks). First, newfs_msdos would not try to query parameters for which a user has provided override values via command line options. Second, newfs_msdos would fake values for CHS parameters like "sectors per track", "number of heads" which are not supported by the media and for which the user has not provided any values. These numbers/logic are borrowed from bsdlabel.c P.S. a line in the patch marked with XXX is a legacy of current code, not a new addition. P.S. this is not as extensive patch as that by Bruce Evans; its only merit is much smaller changeset versus current code/behavior. on 21/02/2008 14:31 Andriy Gapon said the following: > on 17/02/2008 13:39 Andriy Gapon said the following: >> Should newfs_msdos be able to work on "whole" cdX/acdX device ? >> [ufs/ffs] newfs can do it. >> But with newfs_msdos I had to run disklabel first and then I could >> create a filesystem on cdXa, but I couldn't do it on the whole disk. > > It seems that the reason for this newfs_msdos behavior is in the > following lines: > if (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)); > > While a failure to get sector size is a serious situation indeed, number > of sectors per track and number of heads are just relics of the past and > are not applicable to all types of should-be-supported media. > What's even more funny is that those values can be set via command line > options and in that case values from ioctl are not used at all. > > Because those numbers are used by msdosfs on-disk structures we have to > provide some reasonable values for them even if they are meaningless > with respect to physical media organization. > An example of simple calculations can be found in bsdlabel.c. > I see two approaches: > 1) fake those properties in device drivers, primarily cd(4) and acd(4); > benefit: this can help other utilities besides newfs_msdos > 2) fake those properties in newfs_msdof; > benefit: this would help with other physical devices that can host > FAT; > > Or maybe do both. > -- Andriy Gapon --------------070705030706070407090301 Content-Type: text/x-patch; name="newfs-chs.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="newfs-chs.patch" --- 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; --------------070705030706070407090301--