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. BruceReceived on Mon Mar 29 2004 - 18:11:48 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:49 UTC