Re: proposed bsdlabel patch

From: Julian Elischer <julian_at_elischer.org>
Date: Mon, 29 Mar 2004 16:51:30 -0800 (PST)
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
> _at__at_ -139,7 +139,7 _at__at_
>  
>  
>  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[])
>  {
> _at__at_ -147,7 +147,7 _at__at_
>  	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;
> _at__at_ -158,6 +158,9 _at__at_
>  			case 'b':
>  				xxboot = optarg;
>  				break;
> +			case 'f':
> +				is_file=1;
> +				break;
>  			case 'm':
>  				if (!strcmp(optarg, "i386") ||
>  				    !strcmp(optarg, "amd64") ||
> _at__at_ -214,6 +217,8 _at__at_
>  
>  	/* 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 {
> _at__at_ -446,6 +441,10 _at__at_
>  	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)) {
> _at__at_ -1329,6 +1328,10 _at__at_
>  		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_at_freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe_at_freebsd.org"
> 
Received on Mon Mar 29 2004 - 14:42:31 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:49 UTC