1995-12-27 10:51:05 +00:00
|
|
|
/* $NetBSD: ccdconfig.c,v 1.2.2.1 1995/11/11 02:43:35 thorpej Exp $ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 18:41:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1998-06-04 06:41:26 +00:00
|
|
|
|
1995-12-27 10:51:05 +00:00
|
|
|
#include <sys/param.h>
|
1999-07-04 23:42:32 +00:00
|
|
|
#include <sys/linker.h>
|
1995-12-27 10:51:05 +00:00
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/stat.h>
|
1999-04-05 06:30:12 +00:00
|
|
|
#include <sys/module.h>
|
1995-12-27 10:51:05 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
2000-12-09 09:35:55 +00:00
|
|
|
#include <paths.h>
|
1995-12-27 10:51:05 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1998-09-15 08:15:30 +00:00
|
|
|
#include <sys/devicestat.h>
|
1995-12-27 10:57:20 +00:00
|
|
|
#include <sys/ccdvar.h>
|
1995-12-27 10:51:05 +00:00
|
|
|
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
|
|
|
static int lineno = 0;
|
|
|
|
static int verbose = 0;
|
2003-01-17 13:23:41 +00:00
|
|
|
static const char *ccdconf = _PATH_CCDCONF;
|
1995-12-27 10:51:05 +00:00
|
|
|
|
|
|
|
struct flagval {
|
2003-01-17 13:23:41 +00:00
|
|
|
const char *fv_flag;
|
1995-12-27 10:51:05 +00:00
|
|
|
int fv_val;
|
|
|
|
} flagvaltab[] = {
|
|
|
|
{ "CCDF_UNIFORM", CCDF_UNIFORM },
|
1996-01-30 22:25:24 +00:00
|
|
|
{ "CCDF_MIRROR", CCDF_MIRROR },
|
1995-12-27 10:51:05 +00: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 05:00:52 +00:00
|
|
|
static int checkdev(char *);
|
2003-01-17 13:23:41 +00:00
|
|
|
static int do_io(int, u_long, struct ccd_ioctl *);
|
2002-03-18 05:00:52 +00: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 *);
|
|
|
|
static void print_ccd_info(struct ccd_s *);
|
2003-01-17 13:23:41 +00:00
|
|
|
static int resolve_ccdname(char *);
|
2002-03-18 05:00:52 +00:00
|
|
|
static void usage(void);
|
1995-12-27 10:51:05 +00:00
|
|
|
|
|
|
|
int
|
2002-03-18 05:00:52 +00:00
|
|
|
main(int argc, char *argv[])
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
|
|
|
int ch, options = 0, action = CCD_CONFIG;
|
|
|
|
|
2001-09-11 09:49:36 +00:00
|
|
|
while ((ch = getopt(argc, argv, "cCf:guUv")) != -1) {
|
1995-12-27 10:51:05 +00: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();
|
|
|
|
|
1999-04-05 06:30:12 +00:00
|
|
|
if (modfind("ccd") < 0) {
|
|
|
|
/* Not present in kernel, try loading it */
|
|
|
|
if (kldload("ccd") < 0 || modfind("ccd") < 0)
|
|
|
|
warn("ccd module not available!");
|
|
|
|
}
|
|
|
|
|
1995-12-27 10:51:05 +00: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 06:41:26 +00:00
|
|
|
return (0);
|
1995-12-27 10:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-18 05:00:52 +00:00
|
|
|
do_single(int argc, char **argv, int action)
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
|
|
|
struct ccd_ioctl ccio;
|
2003-01-17 13:23:41 +00:00
|
|
|
char *cp, *cp2, **disks;
|
|
|
|
int ccd, noflags = 0, i, ileave, flags = 0, j;
|
|
|
|
u_int u;
|
1995-12-27 10:51:05 +00:00
|
|
|
|
|
|
|
bzero(&ccio, sizeof(ccio));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If unconfiguring, all arguments are treated as ccds.
|
|
|
|
*/
|
|
|
|
if (action == CCD_UNCONFIG || action == CCD_UNCONFIGALL) {
|
|
|
|
for (i = 0; argc != 0; ) {
|
|
|
|
cp = *argv++; --argc;
|
2003-01-18 10:29:24 +00:00
|
|
|
if ((ccd = resolve_ccdname(cp)) < 0) {
|
1995-12-27 10:51:05 +00:00
|
|
|
warnx("invalid ccd name: %s", cp);
|
|
|
|
i = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2003-01-17 14:53:53 +00:00
|
|
|
ccio.ccio_size = ccd;
|
1995-12-27 10:51:05 +00:00
|
|
|
if (do_io(ccd, CCDIOCCLR, &ccio))
|
|
|
|
i = 1;
|
|
|
|
else
|
|
|
|
if (verbose)
|
|
|
|
printf("%s unconfigured\n", cp);
|
|
|
|
}
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure there are enough arguments. */
|
1999-07-04 23:42:32 +00:00
|
|
|
if (argc < 4) {
|
1995-12-27 10:51:05 +00: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-04 23:42:32 +00:00
|
|
|
}
|
1995-12-27 10:51:05 +00:00
|
|
|
|
|
|
|
/* First argument is the ccd to configure. */
|
|
|
|
cp = *argv++; --argc;
|
2003-01-18 10:29:24 +00:00
|
|
|
if ((ccd = resolve_ccdname(cp)) < 0) {
|
1995-12-27 10:51:05 +00: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next is the list of disks to make the ccd from. */
|
|
|
|
disks = malloc(argc * sizeof(char *));
|
|
|
|
if (disks == NULL) {
|
|
|
|
warnx("no memory to configure ccd");
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
for (i = 0; argc != 0; ) {
|
|
|
|
cp = *argv++; --argc;
|
|
|
|
if ((j = checkdev(cp)) == 0)
|
|
|
|
disks[i++] = cp;
|
|
|
|
else {
|
|
|
|
warnx("%s: %s", cp, strerror(j));
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in the ccio. */
|
|
|
|
ccio.ccio_disks = disks;
|
|
|
|
ccio.ccio_ndisks = i;
|
|
|
|
ccio.ccio_ileave = ileave;
|
|
|
|
ccio.ccio_flags = flags;
|
2003-01-17 14:53:53 +00:00
|
|
|
ccio.ccio_size = ccd;
|
1995-12-27 10:51:05 +00:00
|
|
|
|
|
|
|
if (do_io(ccd, CCDIOCSET, &ccio)) {
|
|
|
|
free(disks);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
printf("ccd%d: %d components ", ccio.ccio_unit,
|
|
|
|
ccio.ccio_ndisks);
|
2003-01-17 13:23:41 +00:00
|
|
|
for (u = 0; u < ccio.ccio_ndisks; ++u) {
|
|
|
|
if ((cp2 = strrchr(disks[u], '/')) != NULL)
|
1995-12-27 10:51:05 +00:00
|
|
|
++cp2;
|
|
|
|
else
|
2003-01-17 13:23:41 +00:00
|
|
|
cp2 = disks[u];
|
1995-12-27 10:51:05 +00:00
|
|
|
printf("%c%s%c",
|
2003-01-17 13:23:41 +00:00
|
|
|
u == 0 ? '(' : ' ', cp2,
|
|
|
|
u == ccio.ccio_ndisks - 1 ? ')' : ',');
|
1995-12-27 10:51:05 +00:00
|
|
|
}
|
1999-07-04 23:42:32 +00:00
|
|
|
printf(", %lu blocks ", (u_long)ccio.ccio_size);
|
1995-12-27 10:51:05 +00:00
|
|
|
if (ccio.ccio_ileave != 0)
|
|
|
|
printf("interleaved at %d blocks\n", ccio.ccio_ileave);
|
|
|
|
else
|
|
|
|
printf("concatenated\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
free(disks);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-18 05:00:52 +00:00
|
|
|
do_all(int action)
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char line[_POSIX2_LINE_MAX];
|
|
|
|
char *cp, **argv;
|
|
|
|
int argc, rval;
|
1997-12-30 05:13:21 +00:00
|
|
|
gid_t egid;
|
1995-12-27 10:51:05 +00:00
|
|
|
|
1999-09-26 21:37:46 +00:00
|
|
|
rval = 0;
|
1997-12-30 05:13:21 +00:00
|
|
|
egid = getegid();
|
|
|
|
setegid(getgid());
|
1995-12-27 10:51:05 +00:00
|
|
|
if ((f = fopen(ccdconf, "r")) == NULL) {
|
1997-12-30 05:13:21 +00:00
|
|
|
setegid(egid);
|
1995-12-27 10:51:05 +00:00
|
|
|
warn("fopen: %s", ccdconf);
|
|
|
|
return (1);
|
|
|
|
}
|
1997-12-30 05:13:21 +00:00
|
|
|
setegid(egid);
|
1995-12-27 10:51:05 +00: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 05:00:52 +00:00
|
|
|
checkdev(char *path)
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(path, &st) != 0)
|
|
|
|
return (errno);
|
|
|
|
|
|
|
|
if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-18 05:00:52 +00:00
|
|
|
resolve_ccdname(char *name)
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
|
|
|
|
2003-01-17 13:23:41 +00: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 10:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-01-17 13:23:41 +00:00
|
|
|
do_io(int unit, u_long cmd, struct ccd_ioctl *cciop)
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char *cp;
|
2003-01-17 13:23:41 +00:00
|
|
|
char *path;
|
|
|
|
|
2003-01-17 14:53:53 +00:00
|
|
|
asprintf(&path, "%s%s", _PATH_DEV, _PATH_CCDCTL);
|
1995-12-27 10:51:05 +00:00
|
|
|
|
|
|
|
if ((fd = open(path, O_RDWR, 0640)) < 0) {
|
2003-01-17 14:53:53 +00:00
|
|
|
asprintf(&path, "%sccd%dc", _PATH_DEV, unit);
|
|
|
|
if ((fd = open(path, O_RDWR, 0640)) < 0) {
|
|
|
|
warn("open: %s", path);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
fprintf(stderr,
|
|
|
|
"***WARNING***: Kernel older than ccdconfig(8), please upgrade it.\n");
|
|
|
|
fprintf(stderr,
|
|
|
|
"***WARNING***: Continuing in 30 seconds\n");
|
|
|
|
sleep(30);
|
1995-12-27 10:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, cmd, cciop) < 0) {
|
|
|
|
switch (cmd) {
|
|
|
|
case CCDIOCSET:
|
|
|
|
cp = "CCDIOCSET";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CCDIOCCLR:
|
|
|
|
cp = "CCDIOCCLR";
|
|
|
|
break;
|
|
|
|
|
2001-09-04 09:19:48 +00:00
|
|
|
case CCDCONFINFO:
|
|
|
|
cp = "CCDCONFINFO";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CCDCPPINFO:
|
|
|
|
cp = "CCDCPPINFO";
|
|
|
|
break;
|
|
|
|
|
1995-12-27 10:51:05 +00:00
|
|
|
default:
|
|
|
|
cp = "unknown";
|
|
|
|
}
|
|
|
|
warn("ioctl (%s): %s", cp, path);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-18 05:00:52 +00:00
|
|
|
dump_ccd(int argc, char **argv)
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
2003-01-17 13:23:41 +00:00
|
|
|
char *cp;
|
1995-12-27 10:51:05 +00:00
|
|
|
int i, error, numccd, numconfiged = 0;
|
2001-09-04 09:19:48 +00:00
|
|
|
struct ccdconf conf;
|
2003-01-17 13:23:41 +00:00
|
|
|
int ccd;
|
1995-12-27 10:51:05 +00:00
|
|
|
|
2001-09-04 09:19:48 +00:00
|
|
|
/*
|
|
|
|
* Read the ccd configuration data from the kernel and dump
|
|
|
|
* it to stdout.
|
|
|
|
*/
|
2003-01-17 13:23:41 +00:00
|
|
|
if ((ccd = resolve_ccdname("ccd0")) < 0) { /* XXX */
|
2001-09-04 09:19:48 +00:00
|
|
|
warnx("invalid ccd name: %s", cp);
|
1995-12-27 10:51:05 +00:00
|
|
|
return (1);
|
|
|
|
}
|
2001-09-04 09:19:48 +00:00
|
|
|
conf.size = 0;
|
|
|
|
if (do_io(ccd, CCDCONFINFO, (struct ccd_ioctl *) &conf))
|
|
|
|
return (1);
|
|
|
|
if (conf.size == 0) {
|
|
|
|
printf("no concatenated disks configured\n");
|
|
|
|
return (0);
|
1995-12-27 10:51:05 +00:00
|
|
|
}
|
|
|
|
/* Allocate space for the configuration data. */
|
2001-09-04 09:19:48 +00:00
|
|
|
conf.buffer = alloca(conf.size);
|
|
|
|
if (conf.buffer == NULL) {
|
1995-12-27 10:51:05 +00:00
|
|
|
warnx("no memory for configuration data");
|
2001-09-04 09:19:48 +00:00
|
|
|
return (1);
|
1995-12-27 10:51:05 +00:00
|
|
|
}
|
2001-09-04 09:19:48 +00:00
|
|
|
if (do_io(ccd, CCDCONFINFO, (struct ccd_ioctl *) &conf))
|
|
|
|
return (1);
|
1995-12-27 10:51:05 +00:00
|
|
|
|
2001-09-04 09:19:48 +00:00
|
|
|
numconfiged = conf.size / sizeof(struct ccd_s);
|
1995-12-27 10:51:05 +00:00
|
|
|
|
|
|
|
if (argc == 0) {
|
2001-09-04 09:19:48 +00:00
|
|
|
for (i = 0; i < numconfiged; i++)
|
|
|
|
print_ccd_info(&(conf.buffer[i]));
|
1995-12-27 10:51:05 +00:00
|
|
|
} else {
|
|
|
|
while (argc) {
|
|
|
|
cp = *argv++; --argc;
|
2003-01-17 13:23:41 +00:00
|
|
|
if ((ccd = resolve_ccdname(cp)) < 0) {
|
1995-12-27 10:51:05 +00:00
|
|
|
warnx("invalid ccd name: %s", cp);
|
|
|
|
continue;
|
|
|
|
}
|
2001-09-04 09:19:48 +00:00
|
|
|
error = 1;
|
|
|
|
for (i = 0; i < numconfiged; i++) {
|
2003-01-17 13:23:41 +00:00
|
|
|
if (conf.buffer[i].sc_unit == ccd) {
|
2001-09-04 09:19:48 +00:00
|
|
|
print_ccd_info(&(conf.buffer[i]));
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
warnx("ccd%d not configured", numccd);
|
1995-12-27 10:51:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2001-09-04 09:19:48 +00:00
|
|
|
}
|
1995-12-27 10:51:05 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-18 05:00:52 +00:00
|
|
|
print_ccd_info(struct ccd_s *cs)
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
2003-01-17 13:23:41 +00:00
|
|
|
char *cp;
|
1995-12-27 10:51:05 +00:00
|
|
|
static int header_printed = 0;
|
2001-09-04 09:19:48 +00:00
|
|
|
struct ccdcpps cpps;
|
2003-01-17 13:23:41 +00:00
|
|
|
int ccd;
|
1995-12-27 10:51:05 +00:00
|
|
|
|
2001-09-04 09:19:48 +00:00
|
|
|
/* Print out header if necessary*/
|
1995-12-27 10:51:05 +00:00
|
|
|
if (header_printed == 0 && verbose) {
|
|
|
|
printf("# ccd\t\tileave\tflags\tcompnent devices\n");
|
|
|
|
header_printed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dump out softc information. */
|
|
|
|
printf("ccd%d\t\t%d\t%d\t", cs->sc_unit, cs->sc_ileave,
|
|
|
|
cs->sc_cflags & CCDF_USERMASK);
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
/* Read in the component info. */
|
2003-03-06 06:31:49 +00:00
|
|
|
asprintf(&cp, "ccd%d", cs->sc_unit);
|
2001-09-04 09:19:48 +00:00
|
|
|
if (cp == NULL) {
|
|
|
|
printf("\n");
|
|
|
|
warn("ccd%d: can't allocate memory",
|
|
|
|
cs->sc_unit);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-01-17 13:23:41 +00:00
|
|
|
if ((ccd = resolve_ccdname(cp)) < 0) {
|
2001-09-04 09:19:48 +00:00
|
|
|
printf("\n");
|
|
|
|
warnx("can't read component info: invalid ccd name: %s", cp);
|
|
|
|
return;
|
|
|
|
}
|
2003-01-17 14:53:53 +00:00
|
|
|
cpps.size = 1024;
|
2001-09-04 09:19:48 +00:00
|
|
|
cpps.buffer = alloca(cpps.size);
|
2003-01-17 14:53:53 +00:00
|
|
|
memcpy(cpps.buffer, &ccd, sizeof ccd);
|
2001-09-04 09:19:48 +00:00
|
|
|
if (do_io(ccd, CCDCPPINFO, (struct ccd_ioctl *) &cpps)) {
|
|
|
|
printf("\n");
|
|
|
|
warnx("can't read component info");
|
|
|
|
return;
|
1995-12-27 10:51:05 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 09:19:48 +00:00
|
|
|
/* Display component info. */
|
2003-01-17 14:53:53 +00:00
|
|
|
for (cp = cpps.buffer; *cp && cp - cpps.buffer < cpps.size; cp += strlen(cp) + 1) {
|
2001-09-04 09:19:48 +00:00
|
|
|
printf((cp + strlen(cp) + 1) < (cpps.buffer + cpps.size) ?
|
2003-01-17 14:53:53 +00:00
|
|
|
"%s " : "%s", cp);
|
1995-12-27 10:51:05 +00:00
|
|
|
}
|
2003-01-17 14:53:53 +00:00
|
|
|
printf("\n");
|
2001-09-04 09:19:48 +00:00
|
|
|
return;
|
1995-12-27 10:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-03-18 05:00:52 +00:00
|
|
|
flags_to_val(char *flags)
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
|
|
|
char *cp, *tok;
|
|
|
|
int i, tmp, val = ~CCDF_USERMASK;
|
|
|
|
size_t flagslen;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The most common case is that of NIL flags, so check for
|
|
|
|
* those first.
|
|
|
|
*/
|
|
|
|
if (strcmp("none", flags) == 0 || strcmp("0x0", flags) == 0 ||
|
|
|
|
strcmp("0", flags) == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
flagslen = strlen(flags);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
goto bad_string;
|
|
|
|
}
|
|
|
|
tmp |= flagvaltab[i].fv_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get here, the string was ok. */
|
|
|
|
free(cp);
|
|
|
|
val = tmp;
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
bad_string:
|
|
|
|
|
|
|
|
/* Check for values represented in hex. */
|
|
|
|
if (flagslen > 2 && flags[0] == '0' && flags[1] == 'x') {
|
|
|
|
errno = 0; /* to check for ERANGE */
|
|
|
|
val = (int)strtol(&flags[2], &cp, 16);
|
|
|
|
if ((errno == ERANGE) || (*cp != '\0'))
|
|
|
|
return (-1);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for values represented in decimal. */
|
|
|
|
errno = 0; /* to check for ERANGE */
|
|
|
|
val = (int)strtol(flags, &cp, 10);
|
|
|
|
if ((errno == ERANGE) || (*cp != '\0'))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return (((val & ~CCDF_USERMASK) == 0) ? val : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-18 05:00:52 +00:00
|
|
|
usage(void)
|
1995-12-27 10:51:05 +00:00
|
|
|
{
|
1997-06-10 11:04:50 +00:00
|
|
|
fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
|
|
|
|
"usage: ccdconfig [-cv] ccd ileave [flags] dev [...]",
|
|
|
|
" ccdconfig -C [-v] [-f config_file]",
|
|
|
|
" ccdconfig -u [-v] ccd [...]",
|
|
|
|
" ccdconfig -U [-v] [-f config_file]",
|
2001-09-04 09:19:48 +00:00
|
|
|
" ccdconfig -g [ccd [...]]");
|
1995-12-27 10:51:05 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1997-06-10 11:04:50 +00:00
|
|
|
|
1995-12-27 10:57:20 +00:00
|
|
|
/* Local Variables: */
|
|
|
|
/* c-argdecl-indent: 8 */
|
|
|
|
/* c-indent-level: 8 */
|
|
|
|
/* End: */
|