Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Dec 2000 11:20:31 -0800 (PST)
From:      Mark Peek <mark@whistle.com>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/23335: [PATCH] Error messages from tunefs could be more informative
Message-ID:  <200012061920.eB6JKV901355@shark.whistle.com>
Resent-Message-ID: <200012061930.eB6JU1l72737@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 06 11:30:01 PST 2000
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:
 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200012061920.eB6JKV901355>