From owner-freebsd-current@FreeBSD.ORG Mon Mar 29 16:39:27 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 BDA8716A4CE for ; Mon, 29 Mar 2004 16:39:27 -0800 (PST) Received: from xorpc.icir.org (xorpc.icir.org [192.150.187.68]) by mx1.FreeBSD.org (Postfix) with ESMTP id AE0BF43D39 for ; Mon, 29 Mar 2004 16:39:27 -0800 (PST) (envelope-from rizzo@icir.org) Received: from xorpc.icir.org (localhost [127.0.0.1]) by xorpc.icir.org (8.12.9p1/8.12.8) with ESMTP id i2U0dQgd038826; Mon, 29 Mar 2004 16:39:26 -0800 (PST) (envelope-from rizzo@xorpc.icir.org) Received: (from rizzo@localhost) by xorpc.icir.org (8.12.9p1/8.12.3/Submit) id i2U0dQmh038825; Mon, 29 Mar 2004 16:39:26 -0800 (PST) (envelope-from rizzo) Date: Mon, 29 Mar 2004 16:39:26 -0800 From: Luigi Rizzo To: current@freebsd.org Message-ID: <20040329163926.A38109@xorpc.icir.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i Subject: 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:39:27 -0000 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)) {