From owner-freebsd-current@FreeBSD.ORG Mon Mar 29 16:42:31 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 0F80516A4CE for ; Mon, 29 Mar 2004 16:42:31 -0800 (PST) Received: from rwcrmhc13.comcast.net (rwcrmhc13.comcast.net [204.127.198.39]) by mx1.FreeBSD.org (Postfix) with ESMTP id E8E8243D48 for ; Mon, 29 Mar 2004 16:42:30 -0800 (PST) (envelope-from julian@elischer.org) Received: from interjet.elischer.org ([24.7.73.28]) by comcast.net (rwcrmhc13) with ESMTP id <20040330004230015007oq97e>; Tue, 30 Mar 2004 00:42:30 +0000 Received: from localhost (localhost.elischer.org [127.0.0.1]) by InterJet.elischer.org (8.9.1a/8.9.1) with ESMTP id QAA32159; Mon, 29 Mar 2004 16:51:32 -0800 (PST) Date: Mon, 29 Mar 2004 16:51:30 -0800 (PST) From: Julian Elischer To: Luigi Rizzo In-Reply-To: <20040329163926.A38109@xorpc.icir.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 00:42:31 -0000 certainly sounds fine to me, except I'm almost willing to believe that if the type of the target is "file" then it should just automatically do it.. Why does it need an argument? On Mon, 29 Mar 2004, 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. > > With this, and ports/sysutils/makefs, we will be able to > build a bootable image entirely without root privileges, > which should be of some interests for a number of applications > > cheers > luigi > > --- bsdlabel.c Mon Mar 15 23:10:34 2004 > +++ /usr/src/sbin/bsdlabel/bsdlabel.c Tue Mar 30 00:18:18 2004 > @@ -139,7 +139,7 @@ > > > static int disable_write; /* set to disable writing to disk label */ > - > +static int is_file; /* work on a file (abs. pathname), "-f" opt. */ > int > main(int argc, char *argv[]) > { > @@ -147,7 +147,7 @@ > int ch, error = 0; > char const *name = 0; > > - while ((ch = getopt(argc, argv, "ABb:em:nRrs:w")) != -1) > + while ((ch = getopt(argc, argv, "ABb:efm:nRrs:w")) != -1) > switch (ch) { > case 'A': > allfields = 1; > @@ -158,6 +158,9 @@ > case 'b': > xxboot = optarg; > break; > + case 'f': > + is_file=1; > + break; > case 'm': > if (!strcmp(optarg, "i386") || > !strcmp(optarg, "amd64") || > @@ -214,6 +217,8 @@ > > /* Figure out the names of the thing we're working on */ > if (argv[0][0] != '/') { > + if (is_file) > + errx(1, "-f requires an absolute pathname"); > dkname = argv[0]; > asprintf(&specname, "%s%s", _PATH_DEV, argv[0]); > } else { > @@ -446,6 +441,10 @@ > f = open(specname, O_RDONLY); > if (f < 0) > err(1, specname); > + if (is_file) { > + secsize = DEV_BSIZE; > + mediasize = lseek(f, (off_t)0, SEEK_END); > + } else > /* New world order */ > if ((ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0) || > (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) { > @@ -1329,6 +1328,10 @@ > return (NULL); > } > > + if (is_file) { > + secsize = DEV_BSIZE; > + mediasize = lseek(f, (off_t)0, SEEK_END); > + } else > /* New world order */ > if ((ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0) || > (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) { > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" >