Date: Mon, 29 Mar 2004 16:39:26 -0800 From: Luigi Rizzo <rizzo@icir.org> To: current@freebsd.org Subject: proposed bsdlabel patch Message-ID: <20040329163926.A38109@xorpc.icir.org>
next in thread | raw e-mail | index | archive | help
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)) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040329163926.A38109>