Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Mar 2004 16:51:30 -0800 (PST)
From:      Julian Elischer <julian@elischer.org>
To:        Luigi Rizzo <rizzo@icir.org>
Cc:        current@freebsd.org
Subject:   Re: proposed bsdlabel patch
Message-ID:  <Pine.BSF.4.21.0403291650090.29660-100000@InterJet.elischer.org>
In-Reply-To: <20040329163926.A38109@xorpc.icir.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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"
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0403291650090.29660-100000>