From mark@whistle.com  Wed Dec  6 11:20:48 2000
Return-Path: <mark@whistle.com>
Received: from whistle.com (s205m131.whistle.com [207.76.205.131])
	by hub.freebsd.org (Postfix) with ESMTP id 5F81937B400
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  6 Dec 2000 11:20:48 -0800 (PST)
Received: (from smap@localhost)
	by whistle.com (8.10.0/8.10.0) id eB6JKlJ23601
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 6 Dec 2000 11:20:47 -0800 (PST)
Received: from shark.whistle.com( 207.76.205.40) by whistle.com via smap (V2.0)
	id xma023594; Wed, 6 Dec 2000 11:20:31 -0800
Received: (from mark@localhost)
	by shark.whistle.com (8.11.1/8.11.0) id eB6JKV901355;
	Wed, 6 Dec 2000 11:20:31 -0800 (PST)
	(envelope-from mark)
Message-Id: <200012061920.eB6JKV901355@shark.whistle.com>
Date: Wed, 6 Dec 2000 11:20:31 -0800 (PST)
From: Mark Peek <mark@whistle.com>
Reply-To: mark@whistle.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] Error messages from tunefs could be more informative
X-Send-Pr-Version: 3.2

>Number:         23335
>Category:       bin
>Synopsis:       [PATCH] Error messages from tunefs could be more informative
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 06 11:30:01 PST 2000
>Closed-Date:    Sun Dec 10 13:01:22 PST 2000
>Last-Modified:  Sun Dec 10 13:03:30 PST 2000
>Originator:     Mark Peek
>Release:        FreeBSD 5.O-CURRENT i386
>Organization:
Whistle Communications, Inc.
>Environment:
>Description:
Error messages from tunefs could be more informative. For instance, running
"tunefs -n enable" produces this error:
    tunefs: /dev//enable: No such file or directory

A standard usage message would be more useful.

>How-To-Repeat:
Run "tunefs -n enable"

>Fix:
The tunefs code assumed that the last argument was the device specification.
The patch below will parse the arguments first, then open the device (if
specified) and then apply the changes. This change will disallow the
(undocumented) use of multiple instances of the same argument on the
same command line for the sack of a better error message.

Index: tunefs.c
===================================================================
RCS file: /cvs/freebsd/src/sbin/tunefs/tunefs.c,v
retrieving revision 1.13
diff -r1.13 tunefs.c
94c94,96
< 	int Aflag = 0, active = 0;
---
> 	int Aflag = 0, pflag = 0, active = 0;
> 	int aflag = 0, dflag = 0, eflag = 0, mflag = 0, nflag = 0, oflag = 0;
> 	char *aopt, *dopt, *eopt, *mopt, *nopt, *oopt;
102a105,154
> 	found_arg = 0; /* at least one arg is required */
> 	while ((ch = getopt(argc, argv, "Aa:d:e:m:n:o:p")) != -1)
> 	  switch (ch) {
> 	  case 'A':
> 		found_arg = 1;
> 		Aflag++;
> 		break;
> 	  case 'a':
> 		found_arg = 1;
> 		aflag = 1;
> 		aopt = optarg;
> 		break;
> 	  case 'd':
> 		found_arg = 1;
> 		dflag = 1;
> 		dopt = optarg;
> 		break;
> 	  case 'e':
> 		found_arg = 1;
> 		eflag = 1;
> 		eopt = optarg;
> 		break;
> 	  case 'm':
> 		found_arg = 1;
> 		mflag = 1;
> 		mopt = optarg;
> 		break;
> 	  case 'n':
> 		found_arg = 1;
> 		nflag = 1;
> 		nopt = optarg;
>  		break;
> 	  case 'o':
> 		found_arg = 1;
> 		oflag = 1;
> 		oopt = optarg;
> 		break;
> 	  case 'p':
> 		found_arg = 1;
> 		pflag = 1;
> 		break;
> 	  default:
> 		usage();
> 	  }
> 	argc -= optind;
> 	argv += optind;
> 
> 	if (found_arg == 0 || argc != 1)
> 	  usage();
> 
128,136c180,185
< 	found_arg = 0; /* at least one arg is required */
< 	while ((ch = getopt(argc, argv, "Aa:d:e:m:n:o:p")) != -1)
< 	  switch (ch) {
< 	  case 'A':
< 		found_arg = 1;
< 		Aflag++;
< 		break;
< 	  case 'a':
< 		found_arg = 1;
---
> 	if (pflag) {
> 		printfs();
> 		exit(0);
> 	}
> 
> 	if (aflag) {
138c187
< 		i = atoi(optarg);
---
> 		i = atoi(aopt);
140c189
< 			errx(10, "%s must be >= 1 (was %s)", name, optarg);
---
> 			errx(10, "%s must be >= 1 (was %s)", name, aopt);
143c192,195
< 			break;
---
> 		} else {
> 			warnx("%s changes from %d to %d",
> 					 name, sblock.fs_maxcontig, i);
> 			sblock.fs_maxcontig = i;
145,149c197,199
< 		warnx("%s changes from %d to %d", name, sblock.fs_maxcontig, i);
< 		sblock.fs_maxcontig = i;
< 		break;
< 	  case 'd':
< 		found_arg = 1;
---
> 	}
> 
> 	if (dflag) {
151c201
< 		i = atoi(optarg);
---
> 		i = atoi(dopt);
154,156c204,205
< 			break;
< 		}
< 		warnx("%s changes from %dms to %dms",
---
> 		} else {
> 			warnx("%s changes from %dms to %dms",
158,161c207,211
< 		sblock.fs_rotdelay = i;
< 		break;
< 	  case 'e':
< 		found_arg = 1;
---
> 			sblock.fs_rotdelay = i;
> 		}
> 	}
> 
> 	if (eflag) {
163c213
< 		i = atoi(optarg);
---
> 		i = atoi(eopt);
165c215
< 			errx(10, "%s must be >= 1 (was %s)", name, optarg);
---
> 			errx(10, "%s must be >= 1 (was %s)", name, eopt);
168c218,221
< 			break;
---
> 		} else {
> 			warnx("%s changes from %d to %d",
> 					 name, sblock.fs_maxbpg, i);
> 			sblock.fs_maxbpg = i;
170,174c223,225
< 		warnx("%s changes from %d to %d", name, sblock.fs_maxbpg, i);
< 		sblock.fs_maxbpg = i;
< 		break;
< 	  case 'm':
< 		found_arg = 1;
---
> 	}
> 
> 	if (mflag) {
176c227
< 		i = atoi(optarg);
---
> 		i = atoi(mopt);
178c229
< 			errx(10, "bad %s (%s)", name, optarg);
---
> 			errx(10, "bad %s (%s)", name, mopt);
181,183c232,233
< 			break;
< 		}
< 		warnx("%s changes from %d%% to %d%%",
---
> 		} else {
> 			warnx("%s changes from %d%% to %d%%",
185,192c235,243
< 		sblock.fs_minfree = i;
< 		if (i >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
< 			warnx(OPTWARN, "time", ">=", MINFREE);
< 		if (i < MINFREE && sblock.fs_optim == FS_OPTTIME)
< 			warnx(OPTWARN, "space", "<", MINFREE);
< 		break;
< 	  case 'n':
< 		found_arg = 1;
---
> 			sblock.fs_minfree = i;
> 			if (i >= MINFREE && sblock.fs_optim == FS_OPTSPACE)
> 				warnx(OPTWARN, "time", ">=", MINFREE);
> 			if (i < MINFREE && sblock.fs_optim == FS_OPTTIME)
> 				warnx(OPTWARN, "space", "<", MINFREE);
> 		}
> 	}
> 
> 	if (nflag) {
194c245
<  		if (strcmp(optarg, "enable") == 0) {
---
>  		if (strcmp(nopt, "enable") == 0) {
197c248
<  		} else if (strcmp(optarg, "disable") == 0) {
---
>  		} else if (strcmp(nopt, "disable") == 0) {
205,207c256,258
<  		break;
< 	  case 'o':
< 		found_arg = 1;
---
> 	}
> 
> 	if (oflag) {
211c262
< 		if (strcmp(optarg, chg[FS_OPTSPACE]) == 0)
---
> 		if (strcmp(oopt, chg[FS_OPTSPACE]) == 0)
213c264
< 		else if (strcmp(optarg, chg[FS_OPTTIME]) == 0)
---
> 		else if (strcmp(oopt, chg[FS_OPTTIME]) == 0)
220,222c271,272
< 			break;
< 		}
< 		warnx("%s changes from %s to %s",
---
> 		} else {
> 			warnx("%s changes from %s to %s",
224,240c274,280
< 		sblock.fs_optim = i;
< 		if (sblock.fs_minfree >= MINFREE && i == FS_OPTSPACE)
< 			warnx(OPTWARN, "time", ">=", MINFREE);
< 		if (sblock.fs_minfree < MINFREE && i == FS_OPTTIME)
< 			warnx(OPTWARN, "space", "<", MINFREE);
< 		break;
< 	  case 'p':
< 		printfs();
< 		exit(0);
< 	  default:
< 		usage();
< 	  }
< 	argc -= optind;
< 	argv += optind;
< 
< 	if (found_arg == 0 || argc != 1)
< 	  usage();
---
> 			sblock.fs_optim = i;
> 			if (sblock.fs_minfree >= MINFREE && i == FS_OPTSPACE)
> 				warnx(OPTWARN, "time", ">=", MINFREE);
> 			if (sblock.fs_minfree < MINFREE && i == FS_OPTTIME)
> 				warnx(OPTWARN, "space", "<", MINFREE);
> 		}
> 	}

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: charnier 
State-Changed-When: Sun Dec 10 13:01:22 PST 2000 
State-Changed-Why:  
Changes applied in the 1.14 revision of tunefs.c 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23335 
>Unformatted:
 
