1995-12-27 11:51:05 +01:00
|
|
|
/*
|
2003-06-09 21:25:07 +02:00
|
|
|
* Copyright (c) 2003 Poul-Henning Kamp
|
1995-12-27 11:51:05 +01:00
|
|
|
* Copyright (c) 1995 Jason R. Thorpe.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-05-03 20:41:59 +02:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1998-06-04 08:41:26 +02:00
|
|
|
|
1995-12-27 11:51:05 +01:00
|
|
|
#include <sys/param.h>
|
1999-07-05 01:42:32 +02:00
|
|
|
#include <sys/linker.h>
|
1999-04-05 08:30:12 +02:00
|
|
|
#include <sys/module.h>
|
1995-12-27 11:51:05 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
2000-12-09 10:35:55 +01:00
|
|
|
#include <paths.h>
|
1995-12-27 11:51:05 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2003-06-02 22:50:59 +02:00
|
|
|
#include <libgeom.h>
|
1995-12-27 11:51:05 +01:00
|
|
|
|
2003-06-09 21:25:07 +02:00
|
|
|
#define CCDF_UNIFORM 0x02 /* use LCCD of sizes for uniform interleave */
|
|
|
|
#define CCDF_MIRROR 0x04 /* use mirroring */
|
2006-04-13 22:35:31 +02:00
|
|
|
#define CCDF_NO_OFFSET 0x08 /* do not leave space in front */
|
|
|
|
#define CCDF_LINUX 0x10 /* use Linux compatibility mode */
|
1995-12-27 11:51:05 +01:00
|
|
|
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
|
|
|
static int lineno = 0;
|
|
|
|
static int verbose = 0;
|
2003-01-17 14:23:41 +01:00
|
|
|
static const char *ccdconf = _PATH_CCDCONF;
|
1995-12-27 11:51:05 +01:00
|
|
|
|
|
|
|
struct flagval {
|
2003-01-17 14:23:41 +01:00
|
|
|
const char *fv_flag;
|
2003-06-09 21:25:07 +02:00
|
|
|
int fv_val;
|
1995-12-27 11:51:05 +01:00
|
|
|
} flagvaltab[] = {
|
|
|
|
{ "CCDF_UNIFORM", CCDF_UNIFORM },
|
2003-06-09 21:25:07 +02:00
|
|
|
{ "uniform", CCDF_UNIFORM },
|
1996-01-30 23:25:24 +01:00
|
|
|
{ "CCDF_MIRROR", CCDF_MIRROR },
|
2003-06-09 21:25:07 +02:00
|
|
|
{ "mirror", CCDF_MIRROR },
|
2006-04-13 22:35:31 +02:00
|
|
|
{ "CCDF_NO_OFFSET", CCDF_NO_OFFSET },
|
|
|
|
{ "no_offset", CCDF_NO_OFFSET },
|
|
|
|
{ "CCDF_LINUX", CCDF_LINUX },
|
|
|
|
{ "linux", CCDF_LINUX },
|
2003-06-09 21:25:07 +02:00
|
|
|
{ "none", 0 },
|
1995-12-27 11:51:05 +01:00
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CCD_CONFIG 0 /* configure a device */
|
|
|
|
#define CCD_CONFIGALL 1 /* configure all devices */
|
|
|
|
#define CCD_UNCONFIG 2 /* unconfigure a device */
|
|
|
|
#define CCD_UNCONFIGALL 3 /* unconfigure all devices */
|
|
|
|
#define CCD_DUMP 4 /* dump a ccd's configuration */
|
|
|
|
|
2002-03-18 06:00:52 +01:00
|
|
|
static int do_single(int, char **, int);
|
|
|
|
static int do_all(int);
|
|
|
|
static int dump_ccd(int, char **);
|
|
|
|
static int flags_to_val(char *);
|
2003-01-17 14:23:41 +01:00
|
|
|
static int resolve_ccdname(char *);
|
2002-03-18 06:00:52 +01:00
|
|
|
static void usage(void);
|
1995-12-27 11:51:05 +01:00
|
|
|
|
|
|
|
int
|
2002-03-18 06:00:52 +01:00
|
|
|
main(int argc, char *argv[])
|
1995-12-27 11:51:05 +01:00
|
|
|
{
|
|
|
|
int ch, options = 0, action = CCD_CONFIG;
|
|
|
|
|
2001-09-11 11:49:36 +02:00
|
|
|
while ((ch = getopt(argc, argv, "cCf:guUv")) != -1) {
|
1995-12-27 11:51:05 +01:00
|
|
|
switch (ch) {
|
|
|
|
case 'c':
|
|
|
|
action = CCD_CONFIG;
|
|
|
|
++options;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
action = CCD_CONFIGALL;
|
|
|
|
++options;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
ccdconf = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'g':
|
|
|
|
action = CCD_DUMP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
action = CCD_UNCONFIG;
|
|
|
|
++options;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'U':
|
|
|
|
action = CCD_UNCONFIGALL;
|
|
|
|
++options;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (options > 1)
|
|
|
|
usage();
|
|
|
|
|
2003-06-09 21:25:07 +02:00
|
|
|
if (modfind("g_ccd") < 0) {
|
1999-04-05 08:30:12 +02:00
|
|
|
/* Not present in kernel, try loading it */
|
2003-06-09 23:50:41 +02:00
|
|
|
if (kldload("geom_ccd") < 0 || modfind("g_ccd") < 0)
|
|
|
|
warn("geom_ccd module not available!");
|
1999-04-05 08:30:12 +02:00
|
|
|
}
|
|
|
|
|
1995-12-27 11:51:05 +01:00
|
|
|
switch (action) {
|
|
|
|
case CCD_CONFIG:
|
|
|
|
case CCD_UNCONFIG:
|
|
|
|
exit(do_single(argc, argv, action));
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
|
|
|
case CCD_CONFIGALL:
|
|
|
|
case CCD_UNCONFIGALL:
|
|
|
|
exit(do_all(action));
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
|
|
|
case CCD_DUMP:
|
|
|
|
exit(dump_ccd(argc, argv));
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
1998-06-04 08:41:26 +02:00
|
|
|
return (0);
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-18 06:00:52 +01:00
|
|
|
do_single(int argc, char **argv, int action)
|
1995-12-27 11:51:05 +01:00
|
|
|
{
|
2003-06-09 21:25:07 +02:00
|
|
|
char *cp, *cp2;
|
|
|
|
int ccd, noflags = 0, i, ileave, flags = 0;
|
|
|
|
struct gctl_req *grq;
|
|
|
|
char const *errstr;
|
|
|
|
char buf1[BUFSIZ];
|
|
|
|
int ex;
|
1995-12-27 11:51:05 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If unconfiguring, all arguments are treated as ccds.
|
|
|
|
*/
|
|
|
|
if (action == CCD_UNCONFIG || action == CCD_UNCONFIGALL) {
|
2003-06-09 21:25:07 +02:00
|
|
|
ex = 0;
|
2010-06-11 19:03:04 +02:00
|
|
|
for (; argc != 0;) {
|
1995-12-27 11:51:05 +01:00
|
|
|
cp = *argv++; --argc;
|
2003-01-18 11:29:24 +01:00
|
|
|
if ((ccd = resolve_ccdname(cp)) < 0) {
|
1995-12-27 11:51:05 +01:00
|
|
|
warnx("invalid ccd name: %s", cp);
|
|
|
|
continue;
|
|
|
|
}
|
2003-06-09 21:25:07 +02:00
|
|
|
grq = gctl_get_handle();
|
|
|
|
gctl_ro_param(grq, "verb", -1, "destroy geom");
|
|
|
|
gctl_ro_param(grq, "class", -1, "CCD");
|
|
|
|
sprintf(buf1, "ccd%d", ccd);
|
|
|
|
gctl_ro_param(grq, "geom", -1, buf1);
|
|
|
|
errstr = gctl_issue(grq);
|
|
|
|
if (errstr == NULL) {
|
1995-12-27 11:51:05 +01:00
|
|
|
if (verbose)
|
|
|
|
printf("%s unconfigured\n", cp);
|
2003-06-09 21:25:07 +02:00
|
|
|
gctl_free(grq);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
warnx(
|
|
|
|
"%s\nor possibly kernel and ccdconfig out of sync",
|
|
|
|
errstr);
|
|
|
|
ex = 1;
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
2003-06-09 21:25:07 +02:00
|
|
|
return (ex);
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure there are enough arguments. */
|
1999-07-05 01:42:32 +02:00
|
|
|
if (argc < 4) {
|
1995-12-27 11:51:05 +01:00
|
|
|
if (argc == 3) {
|
|
|
|
/* Assume that no flags are specified. */
|
|
|
|
noflags = 1;
|
|
|
|
} else {
|
|
|
|
if (action == CCD_CONFIGALL) {
|
|
|
|
warnx("%s: bad line: %d", ccdconf, lineno);
|
|
|
|
return (1);
|
|
|
|
} else
|
|
|
|
usage();
|
|
|
|
}
|
1999-07-05 01:42:32 +02:00
|
|
|
}
|
1995-12-27 11:51:05 +01:00
|
|
|
|
|
|
|
/* First argument is the ccd to configure. */
|
|
|
|
cp = *argv++; --argc;
|
2003-01-18 11:29:24 +01:00
|
|
|
if ((ccd = resolve_ccdname(cp)) < 0) {
|
1995-12-27 11:51:05 +01:00
|
|
|
warnx("invalid ccd name: %s", cp);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next argument is the interleave factor. */
|
|
|
|
cp = *argv++; --argc;
|
|
|
|
errno = 0; /* to check for ERANGE */
|
|
|
|
ileave = (int)strtol(cp, &cp2, 10);
|
|
|
|
if ((errno == ERANGE) || (ileave < 0) || (*cp2 != '\0')) {
|
|
|
|
warnx("invalid interleave factor: %s", cp);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (noflags == 0) {
|
|
|
|
/* Next argument is the ccd configuration flags. */
|
|
|
|
cp = *argv++; --argc;
|
|
|
|
if ((flags = flags_to_val(cp)) < 0) {
|
|
|
|
warnx("invalid flags argument: %s", cp);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
2003-06-09 21:25:07 +02:00
|
|
|
grq = gctl_get_handle();
|
|
|
|
gctl_ro_param(grq, "verb", -1, "create geom");
|
|
|
|
gctl_ro_param(grq, "class", -1, "CCD");
|
|
|
|
gctl_ro_param(grq, "unit", sizeof(ccd), &ccd);
|
|
|
|
gctl_ro_param(grq, "ileave", sizeof(ileave), &ileave);
|
|
|
|
if (flags & CCDF_UNIFORM)
|
|
|
|
gctl_ro_param(grq, "uniform", -1, "");
|
|
|
|
if (flags & CCDF_MIRROR)
|
|
|
|
gctl_ro_param(grq, "mirror", -1, "");
|
2006-04-13 22:35:31 +02:00
|
|
|
if (flags & CCDF_NO_OFFSET)
|
|
|
|
gctl_ro_param(grq, "no_offset", -1, "");
|
|
|
|
if (flags & CCDF_LINUX)
|
|
|
|
gctl_ro_param(grq, "linux", -1, "");
|
2003-06-09 21:25:07 +02:00
|
|
|
gctl_ro_param(grq, "nprovider", sizeof(argc), &argc);
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
sprintf(buf1, "provider%d", i);
|
|
|
|
cp = argv[i];
|
|
|
|
if (!strncmp(cp, _PATH_DEV, strlen(_PATH_DEV)))
|
|
|
|
cp += strlen(_PATH_DEV);
|
|
|
|
gctl_ro_param(grq, buf1, -1, cp);
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
2003-06-09 21:25:07 +02:00
|
|
|
gctl_rw_param(grq, "output", sizeof(buf1), buf1);
|
|
|
|
errstr = gctl_issue(grq);
|
|
|
|
if (errstr == NULL) {
|
|
|
|
if (verbose) {
|
|
|
|
printf("%s", buf1);
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
2003-06-09 21:25:07 +02:00
|
|
|
gctl_free(grq);
|
|
|
|
return (0);
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
2003-06-09 21:25:07 +02:00
|
|
|
warnx(
|
|
|
|
"%s\nor possibly kernel and ccdconfig out of sync",
|
|
|
|
errstr);
|
|
|
|
return (1);
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-18 06:00:52 +01:00
|
|
|
do_all(int action)
|
1995-12-27 11:51:05 +01:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char line[_POSIX2_LINE_MAX];
|
|
|
|
char *cp, **argv;
|
|
|
|
int argc, rval;
|
1997-12-30 06:13:21 +01:00
|
|
|
gid_t egid;
|
1995-12-27 11:51:05 +01:00
|
|
|
|
1999-09-26 23:37:46 +02:00
|
|
|
rval = 0;
|
1997-12-30 06:13:21 +01:00
|
|
|
egid = getegid();
|
|
|
|
setegid(getgid());
|
1995-12-27 11:51:05 +01:00
|
|
|
if ((f = fopen(ccdconf, "r")) == NULL) {
|
1997-12-30 06:13:21 +01:00
|
|
|
setegid(egid);
|
1995-12-27 11:51:05 +01:00
|
|
|
warn("fopen: %s", ccdconf);
|
|
|
|
return (1);
|
|
|
|
}
|
1997-12-30 06:13:21 +01:00
|
|
|
setegid(egid);
|
1995-12-27 11:51:05 +01:00
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), f) != NULL) {
|
|
|
|
argc = 0;
|
|
|
|
argv = NULL;
|
|
|
|
++lineno;
|
|
|
|
if ((cp = strrchr(line, '\n')) != NULL)
|
|
|
|
*cp = '\0';
|
|
|
|
|
|
|
|
/* Break up the line and pass it's contents to do_single(). */
|
|
|
|
if (line[0] == '\0')
|
|
|
|
goto end_of_line;
|
|
|
|
for (cp = line; (cp = strtok(cp, " \t")) != NULL; cp = NULL) {
|
|
|
|
if (*cp == '#')
|
|
|
|
break;
|
|
|
|
if ((argv = realloc(argv,
|
|
|
|
sizeof(char *) * ++argc)) == NULL) {
|
|
|
|
warnx("no memory to configure ccds");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
argv[argc - 1] = cp;
|
|
|
|
/*
|
|
|
|
* If our action is to unconfigure all, then pass
|
|
|
|
* just the first token to do_single() and ignore
|
|
|
|
* the rest. Since this will be encountered on
|
|
|
|
* our first pass through the line, the Right
|
|
|
|
* Thing will happen.
|
|
|
|
*/
|
|
|
|
if (action == CCD_UNCONFIGALL) {
|
|
|
|
if (do_single(argc, argv, action))
|
|
|
|
rval = 1;
|
|
|
|
goto end_of_line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argc != 0)
|
|
|
|
if (do_single(argc, argv, action))
|
|
|
|
rval = 1;
|
|
|
|
|
|
|
|
end_of_line:
|
|
|
|
if (argv != NULL)
|
|
|
|
free(argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)fclose(f);
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-18 06:00:52 +01:00
|
|
|
resolve_ccdname(char *name)
|
1995-12-27 11:51:05 +01:00
|
|
|
{
|
|
|
|
|
2003-01-17 14:23:41 +01:00
|
|
|
if (!strncmp(name, _PATH_DEV, strlen(_PATH_DEV)))
|
|
|
|
name += strlen(_PATH_DEV);
|
|
|
|
if (strncmp(name, "ccd", 3))
|
|
|
|
return -1;
|
|
|
|
name += 3;
|
|
|
|
if (!isdigit(*name))
|
|
|
|
return -1;
|
|
|
|
return (strtoul(name, NULL, 10));
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-06-02 23:29:04 +02:00
|
|
|
dumpout(int unit)
|
1995-12-27 11:51:05 +01:00
|
|
|
{
|
2003-06-02 23:29:04 +02:00
|
|
|
static int v;
|
|
|
|
struct gctl_req *grq;
|
|
|
|
int ncp;
|
2003-01-17 14:23:41 +01:00
|
|
|
char *cp;
|
2003-06-02 22:50:59 +02:00
|
|
|
char const *errstr;
|
|
|
|
|
|
|
|
grq = gctl_get_handle();
|
2003-06-02 23:29:04 +02:00
|
|
|
ncp = 65536;
|
|
|
|
cp = malloc(ncp);
|
2003-06-02 22:50:59 +02:00
|
|
|
gctl_ro_param(grq, "verb", -1, "list");
|
|
|
|
gctl_ro_param(grq, "class", -1, "CCD");
|
2003-06-02 23:29:04 +02:00
|
|
|
gctl_ro_param(grq, "unit", sizeof(unit), &unit);
|
|
|
|
gctl_rw_param(grq, "output", ncp, cp);
|
2003-06-02 22:50:59 +02:00
|
|
|
errstr = gctl_issue(grq);
|
2003-06-02 23:29:04 +02:00
|
|
|
if (errstr != NULL)
|
|
|
|
errx(1, "%s\nor possibly kernel and ccdconfig out of sync",
|
|
|
|
errstr);
|
|
|
|
if (strlen(cp) == 0)
|
|
|
|
errx(1, "ccd%d not configured", unit);
|
|
|
|
if (verbose && !v) {
|
|
|
|
printf("# ccd\t\tileave\tflags\tcomponent devices\n");
|
|
|
|
v = 1;
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
2003-06-02 23:29:04 +02:00
|
|
|
printf("%s", cp);
|
|
|
|
free(cp);
|
1995-12-27 11:51:05 +01:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-06-02 23:29:04 +02:00
|
|
|
static int
|
|
|
|
dump_ccd(int argc, char **argv)
|
1995-12-27 11:51:05 +01:00
|
|
|
{
|
2003-08-07 21:10:35 +02:00
|
|
|
int i, error;
|
1995-12-27 11:51:05 +01:00
|
|
|
|
2003-06-02 23:29:04 +02:00
|
|
|
if (argc == 0) {
|
2003-08-07 21:10:35 +02:00
|
|
|
error = dumpout(-1);
|
2003-06-02 23:29:04 +02:00
|
|
|
} else {
|
2003-08-07 21:10:35 +02:00
|
|
|
error = 0;
|
|
|
|
for (i = 0; error == 0 && i < argc; i++)
|
|
|
|
error = dumpout(resolve_ccdname(argv[i]));
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
2003-08-07 21:10:35 +02:00
|
|
|
return (error);
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-18 06:00:52 +01:00
|
|
|
flags_to_val(char *flags)
|
1995-12-27 11:51:05 +01:00
|
|
|
{
|
|
|
|
char *cp, *tok;
|
2003-06-09 21:25:07 +02:00
|
|
|
int i, tmp, val;
|
1995-12-27 11:51:05 +01:00
|
|
|
|
2003-06-09 21:25:07 +02:00
|
|
|
errno = 0; /* to check for ERANGE */
|
|
|
|
val = (int)strtol(flags, &cp, 0);
|
|
|
|
if ((errno != ERANGE) && (*cp == '\0')) {
|
|
|
|
if (val & ~(CCDF_UNIFORM|CCDF_MIRROR))
|
|
|
|
return (-1);
|
|
|
|
return (val);
|
|
|
|
}
|
1995-12-27 11:51:05 +01:00
|
|
|
|
|
|
|
/* Check for values represented by strings. */
|
|
|
|
if ((cp = strdup(flags)) == NULL)
|
|
|
|
err(1, "no memory to parse flags");
|
|
|
|
tmp = 0;
|
|
|
|
for (tok = cp; (tok = strtok(tok, ",")) != NULL; tok = NULL) {
|
|
|
|
for (i = 0; flagvaltab[i].fv_flag != NULL; ++i)
|
|
|
|
if (strcmp(tok, flagvaltab[i].fv_flag) == 0)
|
|
|
|
break;
|
|
|
|
if (flagvaltab[i].fv_flag == NULL) {
|
|
|
|
free(cp);
|
2003-06-09 21:25:07 +02:00
|
|
|
return (-1);
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
|
|
|
tmp |= flagvaltab[i].fv_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get here, the string was ok. */
|
|
|
|
free(cp);
|
2003-06-09 21:25:07 +02:00
|
|
|
return (tmp);
|
1995-12-27 11:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-18 06:00:52 +01:00
|
|
|
usage(void)
|
1995-12-27 11:51:05 +01:00
|
|
|
{
|
1997-06-10 13:04:50 +02:00
|
|
|
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
|
2005-02-10 10:19:34 +01:00
|
|
|
"usage: ccdconfig [-cv] ccd ileave [flags] dev ...",
|
1997-06-10 13:04:50 +02:00
|
|
|
" ccdconfig -C [-v] [-f config_file]",
|
2005-02-10 10:19:34 +01:00
|
|
|
" ccdconfig -u [-v] ccd ...",
|
1997-06-10 13:04:50 +02:00
|
|
|
" ccdconfig -U [-v] [-f config_file]",
|
2005-02-10 10:19:34 +01:00
|
|
|
" ccdconfig -g [ccd ...]");
|
1995-12-27 11:51:05 +01:00
|
|
|
exit(1);
|
|
|
|
}
|