From owner-freebsd-current@FreeBSD.ORG Tue Nov 25 11:29:11 2008 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 548F41065670 for ; Tue, 25 Nov 2008 11:29:11 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 7855C8FC17 for ; Tue, 25 Nov 2008 11:29:10 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from odyssey.starpoint.kiev.ua (alpha-e.starpoint.kiev.ua [212.40.38.101]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id NAA19416; Tue, 25 Nov 2008 13:15:18 +0200 (EET) (envelope-from avg@icyb.net.ua) Message-ID: <492BDE44.7060402@icyb.net.ua> Date: Tue, 25 Nov 2008 13:15:16 +0200 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.17 (X11/20081106) MIME-Version: 1.0 To: Luigi Rizzo , current@freebsd.org References: <20081125094125.GA18669@onelab2.iet.unipi.it> In-Reply-To: <20081125094125.GA18669@onelab2.iet.unipi.it> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Subject: Re: small newfs_msdos addition X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Nov 2008 11:29:11 -0000 on 25/11/2008 11:41 Luigi Rizzo said the following: > If there are no objections I'd like to commit the small patch below > to newfs_msdos.c -- all it does is create a fake geometry if > it cannot get the media size, which is handy when you want to > create a filesystem image on a regular file. > > Before the patch you need to do > > newfs_msdos -h 32 -s 64 -o 0 -S 512 -s `du -k /the/file` /the/file > > after the patch it becomes > > newfs_msdos /the/file > > which is a bit more friendly especially if you have to type it manually. > > cheers > luigi > > >> svn diff head/sbin > Index: head/sbin/newfs_msdos/newfs_msdos.c > =================================================================== > --- head/sbin/newfs_msdos/newfs_msdos.c (revision 185290) > +++ head/sbin/newfs_msdos/newfs_msdos.c (working copy) > @@ -725,9 +725,20 @@ > > /* Maybe it's a floppy drive */ > if (lp == NULL) { > - if (ioctl(fd, DIOCGMEDIASIZE, &ms) == -1) > - errx(1, "Cannot get disk size, %s", strerror(errno)); > - if (ioctl(fd, FD_GTYPE, &type) != -1) { > + if (ioctl(fd, DIOCGMEDIASIZE, &ms) == -1) { > + struct stat st; > + > + bzero(&st, sizeof(st)); > + if (fstat(fd, &st)) > + err(1, "Cannot get disk size"); > + /* create a fake geometry for a file image */ > + ms = st.st_size; > + dlp.d_secsize = 512; > + dlp.d_nsectors = 64; > + dlp.d_ntracks = 32; > + dlp.d_secperunit = ms / dlp.d_secsize; > + lp = &dlp; > + } else if (ioctl(fd, FD_GTYPE, &type) != -1) { > dlp.d_secsize = 128 << type.secsize; > dlp.d_nsectors = type.sectrac; > dlp.d_ntracks = type.heads; Please also consider this PR: http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/121182 and this message from phk in a related thread: http://lists.freebsd.org/pipermail/freebsd-fs/2008-February/004483.html -- Andriy Gapon