From owner-freebsd-current@FreeBSD.ORG Mon Mar 29 20:11:48 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4666016A4CE for ; Mon, 29 Mar 2004 20:11:48 -0800 (PST) Received: from mailout2.pacific.net.au (mailout2.pacific.net.au [61.8.0.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id 824B043D39 for ; Mon, 29 Mar 2004 20:11:47 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.0.86])i2U4Bk5v003035; Tue, 30 Mar 2004 14:11:46 +1000 Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) i2U4BgGQ003642; Tue, 30 Mar 2004 14:11:44 +1000 Date: Tue, 30 Mar 2004 14:11:42 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Marcel Moolenaar In-Reply-To: <20040330005013.GA53546@ns1.xcllnt.net> Message-ID: <20040330120730.S7821@gamplex.bde.org> References: <20040329163926.A38109@xorpc.icir.org> <20040330005013.GA53546@ns1.xcllnt.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: Luigi Rizzo cc: current@freebsd.org Subject: Re: proposed bsdlabel patch X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 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, 30 Mar 2004 04:11:48 -0000 On Mon, 29 Mar 2004, Marcel Moolenaar wrote: > On Mon, Mar 29, 2004 at 04:39:26PM -0800, Luigi Rizzo wrote: > > if there are no strong objections, I'd like to commit > > the following minor patch to bsdlabel (and associated bsdlabel.8 > > changes) to implement a '-f' option which enables bsdlabel to > > work on an image file too. > > As Julian mentioned, why not use stat(2) and DTRT without options? > That also removes the gratuitous requirement that the filename has > to be an absolute path. See also the implementation of gpt(8)... I suggested this too (for the RELENG_4 version). lseek to the end is a very bad way to determine the size of a file, especially when it is used without error checking. Both versions also have lots of style bugs. I also suggested using a shell script to generate a protofile or disktab entry and only fixing actual bugs in disklabel. It is very easy to generate a dummy label in text form using stat(1) to get the file size, although not so easy to do the error checking corresponding to what the implementation using lseek doesn't do (the script would have to look at the file type and not operate except for files whose size according to stat(1) is valid). Here is a a simple version that works with my version of disklabel. %%% #!/bin/sh # filelabel -- apply a simple disk label to a regular file. secsize=512 secpertrack=1 trackpercyl=1 if test $# -ne 1 then echo "usage filelabel file" exit 1 fi filename="$1" if test ! -f "$filename" then echo "'$filename' doesn't exist or isn't a regular file" exit 1 fi # XXX: the file name must be absolute to work around bugs in disklabel. # This is not checked for. filesize=`/usr/bin/stat -f %z "$filename"` secperunit=$(($filesize / $secsize)) cylperunit=$(($secperunit / $secpertrack / $trackpercyl)) echo " # # Minimal set of fields for my version of disklabel. Add/delete/modify # fields as necessary. # bytes/sector: $secsize sectors/track: $secpertrack tracks/cylinder: $trackpercyl sectors/unit: $secperunit cylinders: $cylperunit rpm: 7200 8 partitions: c: $secperunit 0 unused 0 0 " | disklabel -Rr "$filename" /dev/stdin %%% This requires minor fixes to disklabel to work in RELENG_4 (ignore errors from some ioctls if ioctl() sets errno to ENOTTY). Unfortunately, it is far from working with bsdlabel, since it depends critically on -r and support for -r has been axed in bsdlabel. Bruce