2004-06-25 18:27:57 +04:00
|
|
|
/* $NetBSD: chio.c,v 1.25 2004/06/25 14:27:57 wiz Exp $ */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
1999-09-10 03:24:29 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996, 1998, 1999 The NetBSD Foundation, Inc.
|
1996-04-03 04:34:38 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1999-09-10 03:24:29 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
1996-04-03 04:34:38 +04:00
|
|
|
* 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
|
1999-09-10 03:24:29 +04:00
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1996-04-03 04:34:38 +04:00
|
|
|
*
|
1999-09-10 03:24:29 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``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 FOUNDATION OR CONTRIBUTORS
|
|
|
|
* 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.
|
1996-04-03 04:34:38 +04:00
|
|
|
*/
|
1999-09-10 03:24:29 +04:00
|
|
|
|
1997-09-29 21:32:23 +04:00
|
|
|
/*
|
|
|
|
* Additional Copyright (c) 1997, by Matthew Jacob, for NASA/Ames Research Ctr.
|
|
|
|
*/
|
1996-04-03 04:34:38 +04:00
|
|
|
|
1997-07-20 08:44:53 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
1998-07-13 16:06:18 +04:00
|
|
|
__COPYRIGHT(
|
1999-09-10 03:24:29 +04:00
|
|
|
"@(#) Copyright (c) 1996, 1998, 1999\
|
|
|
|
The NetBSD Foundation, Inc. All rights reserved.");
|
2004-06-25 18:27:57 +04:00
|
|
|
__RCSID("$NetBSD: chio.c,v 1.25 2004/06/25 14:27:57 wiz Exp $");
|
1997-07-20 08:44:53 +04:00
|
|
|
#endif
|
|
|
|
|
1996-04-03 04:34:38 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
2002-05-02 17:07:01 +04:00
|
|
|
#include <sys/chio.h>
|
1998-07-13 16:06:18 +04:00
|
|
|
#include <sys/cdio.h> /* for ATAPI CD changer; too bad it uses a lame API */
|
2001-09-13 14:00:44 +04:00
|
|
|
|
1999-09-10 03:24:29 +04:00
|
|
|
#include <ctype.h>
|
1996-04-03 04:34:38 +04:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
2001-09-13 14:00:44 +04:00
|
|
|
int main(int, char *[]);
|
|
|
|
static void usage(void);
|
|
|
|
static void cleanup(void);
|
|
|
|
static int parse_element_type(const char *);
|
|
|
|
static int parse_element_unit(const char *);
|
|
|
|
static int parse_special(const char *);
|
|
|
|
static int is_special(const char *);
|
|
|
|
static const char *bits_to_string(int, const char *);
|
|
|
|
|
|
|
|
static int do_move(const char *, int, char **);
|
|
|
|
static int do_exchange(const char *, int, char **);
|
|
|
|
static int do_position(const char *, int, char **);
|
|
|
|
static int do_params(const char *, int, char **);
|
|
|
|
static int do_getpicker(const char *, int, char **);
|
|
|
|
static int do_setpicker(const char *, int, char **);
|
|
|
|
static int do_status(const char *, int, char **);
|
|
|
|
static int do_ielem(const char *, int, char **);
|
|
|
|
static int do_cdlu(const char *, int, char **);
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
/* Valid changer element types. */
|
|
|
|
const struct element_type elements[] = {
|
|
|
|
{ "picker", CHET_MT },
|
|
|
|
{ "slot", CHET_ST },
|
|
|
|
{ "portal", CHET_IE },
|
|
|
|
{ "drive", CHET_DT },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Valid commands. */
|
|
|
|
const struct changer_command commands[] = {
|
1999-09-08 08:57:37 +04:00
|
|
|
{ "move", " <from ET> <from EU> <to ET> <to EU> [inv]",
|
|
|
|
do_move },
|
|
|
|
|
1999-08-05 06:47:09 +04:00
|
|
|
{ "exchange", " <src ET> <src EU> <dst1 ET> <dst1 EU>\n"
|
2002-05-02 17:07:01 +04:00
|
|
|
"\t\t [<dst2 ET> <dst2 EU>] [inv1] [inv2]",
|
1999-09-08 08:57:37 +04:00
|
|
|
do_exchange },
|
|
|
|
|
|
|
|
{ "position", " <to ET> <to EU> [inv]", do_position },
|
|
|
|
|
|
|
|
{ "params", "",
|
|
|
|
do_params },
|
|
|
|
|
|
|
|
{ "getpicker", "",
|
|
|
|
do_getpicker },
|
|
|
|
|
|
|
|
{ "setpicker", " <picker>",
|
|
|
|
do_setpicker },
|
|
|
|
|
1999-09-10 03:24:29 +04:00
|
|
|
{ "status", " [<ET> [unit [count]]] [voltags]",
|
1999-09-08 08:57:37 +04:00
|
|
|
do_status },
|
|
|
|
|
|
|
|
{ "ielem", "",
|
|
|
|
do_ielem },
|
|
|
|
|
1999-08-05 06:47:09 +04:00
|
|
|
{ "cdlu", " load|unload <slot>\n"
|
2002-05-02 17:07:01 +04:00
|
|
|
"\t abort",
|
1999-09-08 08:57:37 +04:00
|
|
|
do_cdlu },
|
|
|
|
|
|
|
|
{ NULL, NULL,
|
|
|
|
NULL },
|
1996-04-03 04:34:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Valid special words. */
|
|
|
|
const struct special_word specials[] = {
|
|
|
|
{ "inv", SW_INVERT },
|
|
|
|
{ "inv1", SW_INVERT1 },
|
|
|
|
{ "inv2", SW_INVERT2 },
|
1999-09-10 03:24:29 +04:00
|
|
|
{ "voltags", SW_VOLTAGS },
|
1996-04-03 04:34:38 +04:00
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2001-09-13 14:00:44 +04:00
|
|
|
static const char *changer_name;
|
|
|
|
static int changer_fd;
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
int
|
2001-09-13 14:00:44 +04:00
|
|
|
main(int argc, char *argv[])
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
|
|
|
int ch, i;
|
|
|
|
|
2001-09-16 16:13:33 +04:00
|
|
|
setprogname(argv[0]);
|
1996-04-03 04:34:38 +04:00
|
|
|
while ((ch = getopt(argc, argv, "f:")) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'f':
|
|
|
|
changer_name = optarg;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
|
1996-04-03 04:34:38 +04:00
|
|
|
/* Get the default changer if not already specified. */
|
|
|
|
if (changer_name == NULL)
|
|
|
|
if ((changer_name = getenv(CHANGER_ENV_VAR)) == NULL)
|
|
|
|
changer_name = _PATH_CH;
|
|
|
|
|
|
|
|
/* Open the changer device. */
|
|
|
|
if ((changer_fd = open(changer_name, O_RDWR, 0600)) == -1)
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: open", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
/* Register cleanup function. */
|
|
|
|
if (atexit(cleanup))
|
2003-08-05 02:31:21 +04:00
|
|
|
err(EXIT_FAILURE, "can't register cleanup function");
|
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
/* Find the specified command. */
|
|
|
|
for (i = 0; commands[i].cc_name != NULL; ++i)
|
|
|
|
if (strcmp(*argv, commands[i].cc_name) == 0)
|
|
|
|
break;
|
|
|
|
if (commands[i].cc_name == NULL)
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "unknown command: %s", *argv);
|
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
/* Skip over the command name and call handler. */
|
|
|
|
++argv; --argc;
|
2002-05-02 17:07:01 +04:00
|
|
|
exit((*commands[i].cc_handler)(commands[i].cc_name, argc, argv));
|
1998-01-05 02:53:58 +03:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
do_move(const char *cname, int argc, char **argv)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
1999-09-10 03:24:29 +04:00
|
|
|
struct changer_move_request cmd;
|
1996-04-03 04:34:38 +04:00
|
|
|
int val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On a move command, we expect the following:
|
|
|
|
*
|
|
|
|
* <from ET> <from EU> <to ET> <to EU> [inv]
|
|
|
|
*
|
|
|
|
* where ET == element type and EU == element unit.
|
|
|
|
*/
|
|
|
|
if (argc < 4) {
|
|
|
|
warnx("%s: too few arguments", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
} else if (argc > 5) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)memset(&cmd, 0, sizeof(cmd));
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
/* <from ET> */
|
|
|
|
cmd.cm_fromtype = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <from EU> */
|
|
|
|
cmd.cm_fromunit = parse_element_unit(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <to ET> */
|
|
|
|
cmd.cm_totype = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <to EU> */
|
|
|
|
cmd.cm_tounit = parse_element_unit(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* Deal with optional command modifier. */
|
|
|
|
if (argc) {
|
|
|
|
val = parse_special(*argv);
|
|
|
|
switch (val) {
|
|
|
|
case SW_INVERT:
|
|
|
|
cmd.cm_flags |= CM_INVERT;
|
|
|
|
break;
|
|
|
|
default:
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "%s: inappropriate modifier `%s'",
|
1996-04-03 04:34:38 +04:00
|
|
|
cname, *argv);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send command to changer. */
|
1998-01-05 02:53:58 +03:00
|
|
|
if (ioctl(changer_fd, CHIOMOVE, &cmd))
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CHIOMOVE", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
do_exchange(const char *cname, int argc, char **argv)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
1999-09-10 03:24:29 +04:00
|
|
|
struct changer_exchange_request cmd;
|
1996-04-03 04:34:38 +04:00
|
|
|
int val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On an exchange command, we expect the following:
|
|
|
|
*
|
|
|
|
* <src ET> <src EU> <dst1 ET> <dst1 EU> [<dst2 ET> <dst2 EU>] [inv1] [inv2]
|
|
|
|
*
|
|
|
|
* where ET == element type and EU == element unit.
|
|
|
|
*/
|
|
|
|
if (argc < 4) {
|
|
|
|
warnx("%s: too few arguments", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
} else if (argc > 8) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)memset(&cmd, 0, sizeof(cmd));
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
/* <src ET> */
|
|
|
|
cmd.ce_srctype = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <src EU> */
|
|
|
|
cmd.ce_srcunit = parse_element_unit(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <dst1 ET> */
|
|
|
|
cmd.ce_fdsttype = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <dst1 EU> */
|
|
|
|
cmd.ce_fdstunit = parse_element_unit(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the next token is a special word or there are no more
|
|
|
|
* arguments, then this is a case of simple exchange.
|
|
|
|
* dst2 == src.
|
|
|
|
*/
|
|
|
|
if ((argc == 0) || is_special(*argv)) {
|
|
|
|
cmd.ce_sdsttype = cmd.ce_srctype;
|
|
|
|
cmd.ce_sdstunit = cmd.ce_srcunit;
|
|
|
|
goto do_special;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* <dst2 ET> */
|
|
|
|
cmd.ce_sdsttype = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <dst2 EU> */
|
|
|
|
cmd.ce_sdstunit = parse_element_unit(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
do_special:
|
|
|
|
/* Deal with optional command modifiers. */
|
|
|
|
while (argc) {
|
|
|
|
val = parse_special(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
switch (val) {
|
|
|
|
case SW_INVERT1:
|
|
|
|
cmd.ce_flags |= CE_INVERT1;
|
|
|
|
break;
|
|
|
|
case SW_INVERT2:
|
|
|
|
cmd.ce_flags |= CE_INVERT2;
|
|
|
|
break;
|
|
|
|
default:
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "%s: inappropriate modifier `%s'",
|
1996-04-03 04:34:38 +04:00
|
|
|
cname, *argv);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send command to changer. */
|
1998-01-05 02:53:58 +03:00
|
|
|
if (ioctl(changer_fd, CHIOEXCHANGE, &cmd))
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CHIOEXCHANGE", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
do_position(const char *cname, int argc, char **argv)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
1999-09-10 03:24:29 +04:00
|
|
|
struct changer_position_request cmd;
|
1996-04-03 04:34:38 +04:00
|
|
|
int val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On a position command, we expect the following:
|
|
|
|
*
|
|
|
|
* <to ET> <to EU> [inv]
|
|
|
|
*
|
|
|
|
* where ET == element type and EU == element unit.
|
|
|
|
*/
|
|
|
|
if (argc < 2) {
|
|
|
|
warnx("%s: too few arguments", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
} else if (argc > 3) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)memset(&cmd, 0, sizeof(cmd));
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
/* <to ET> */
|
|
|
|
cmd.cp_type = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <to EU> */
|
|
|
|
cmd.cp_unit = parse_element_unit(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* Deal with optional command modifier. */
|
|
|
|
if (argc) {
|
|
|
|
val = parse_special(*argv);
|
|
|
|
switch (val) {
|
|
|
|
case SW_INVERT:
|
|
|
|
cmd.cp_flags |= CP_INVERT;
|
|
|
|
break;
|
|
|
|
default:
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "%s: inappropriate modifier `%s'",
|
1996-04-03 04:34:38 +04:00
|
|
|
cname, *argv);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send command to changer. */
|
1998-01-05 02:53:58 +03:00
|
|
|
if (ioctl(changer_fd, CHIOPOSITION, &cmd))
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CHIOPOSITION", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-01-05 02:53:58 +03:00
|
|
|
/* ARGSUSED */
|
1996-04-03 04:34:38 +04:00
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
do_params(const char *cname, int argc, char **argv)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
|
|
|
struct changer_params data;
|
|
|
|
|
|
|
|
/* No arguments to this command. */
|
|
|
|
if (argc) {
|
|
|
|
warnx("%s: no arguements expected", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
2003-08-05 02:31:21 +04:00
|
|
|
|
1996-04-03 04:34:38 +04:00
|
|
|
/* Get params from changer and display them. */
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)memset(&data, 0, sizeof(data));
|
1998-01-05 02:53:58 +03:00
|
|
|
if (ioctl(changer_fd, CHIOGPARAMS, &data))
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CHIOGPARAMS", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
1999-09-10 03:24:29 +04:00
|
|
|
#define PLURAL(n) (n) > 1 ? "s" : ""
|
|
|
|
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf("%s: %d slot%s, %d drive%s, %d picker%s",
|
2003-09-14 23:20:16 +04:00
|
|
|
changer_name,
|
1999-09-10 03:24:29 +04:00
|
|
|
data.cp_nslots, PLURAL(data.cp_nslots),
|
|
|
|
data.cp_ndrives, PLURAL(data.cp_ndrives),
|
|
|
|
data.cp_npickers, PLURAL(data.cp_npickers));
|
1996-04-03 04:34:38 +04:00
|
|
|
if (data.cp_nportals)
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf(", %d portal%s", data.cp_nportals,
|
1999-09-10 03:24:29 +04:00
|
|
|
PLURAL(data.cp_nportals));
|
|
|
|
|
|
|
|
#undef PLURAL
|
|
|
|
|
2003-09-14 23:20:16 +04:00
|
|
|
(void)printf("\n%s: current picker: %d\n", changer_name, data.cp_curpicker);
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-01-05 02:53:58 +03:00
|
|
|
/* ARGSUSED */
|
1996-04-03 04:34:38 +04:00
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
do_getpicker(const char *cname, int argc, char **argv)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
|
|
|
int picker;
|
|
|
|
|
|
|
|
/* No arguments to this command. */
|
|
|
|
if (argc) {
|
|
|
|
warnx("%s: no arguments expected", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get current picker from changer and display it. */
|
1998-01-05 02:53:58 +03:00
|
|
|
if (ioctl(changer_fd, CHIOGPICKER, &picker))
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CHIOGPICKER", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
2003-09-14 23:20:16 +04:00
|
|
|
(void)printf("%s: current picker: %d\n", changer_name, picker);
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
do_setpicker(const char *cname, int argc, char **argv)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
|
|
|
int picker;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
warnx("%s: too few arguments", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
} else if (argc > 1) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
picker = parse_element_unit(*argv);
|
|
|
|
|
|
|
|
/* Set the changer picker. */
|
1998-01-05 02:53:58 +03:00
|
|
|
if (ioctl(changer_fd, CHIOSPICKER, &picker))
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CHIOSPICKER", changer_name);
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
do_status(const char *cname, int argc, char **argv)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
1999-09-10 03:24:29 +04:00
|
|
|
struct changer_element_status_request cmd;
|
1996-04-03 04:34:38 +04:00
|
|
|
struct changer_params data;
|
1999-09-10 03:24:29 +04:00
|
|
|
struct changer_element_status *ces;
|
2001-09-13 14:00:44 +04:00
|
|
|
int i, chet, count, echet, flags, have_ucount, have_unit;
|
|
|
|
int schet, ucount, unit;
|
1999-09-10 03:24:29 +04:00
|
|
|
size_t size;
|
2002-05-02 17:07:01 +04:00
|
|
|
|
2001-09-13 14:00:44 +04:00
|
|
|
flags = 0;
|
|
|
|
have_ucount = 0;
|
|
|
|
have_unit = 0;
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* On a status command, we expect the following:
|
|
|
|
*
|
1999-09-10 03:24:29 +04:00
|
|
|
* [<ET> [unit [count]]] [voltags]
|
1996-04-03 04:34:38 +04:00
|
|
|
*
|
|
|
|
* where ET == element type.
|
|
|
|
*
|
1999-09-10 03:24:29 +04:00
|
|
|
* If we get no element-related arguments, we get the status of all
|
1996-04-03 04:34:38 +04:00
|
|
|
* known element types.
|
|
|
|
*/
|
1999-09-10 03:24:29 +04:00
|
|
|
if (argc > 4) {
|
1996-04-03 04:34:38 +04:00
|
|
|
warnx("%s: too many arguments", cname);
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get params from changer. Specifically, we need the element
|
|
|
|
* counts.
|
|
|
|
*/
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)memset(&data, 0, sizeof(data));
|
1998-01-05 02:53:58 +03:00
|
|
|
if (ioctl(changer_fd, CHIOGPARAMS, &data))
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CHIOGPARAMS", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
1999-09-10 03:24:29 +04:00
|
|
|
schet = CHET_MT;
|
|
|
|
echet = CHET_DT;
|
|
|
|
|
|
|
|
for (; argc != 0; argc--, argv++) {
|
|
|
|
/*
|
|
|
|
* If we have the voltags modifier, it must be the
|
|
|
|
* last argument.
|
|
|
|
*/
|
|
|
|
if (is_special(argv[0])) {
|
|
|
|
if (argc != 1) {
|
|
|
|
warnx("%s: malformed command line", cname);
|
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1999-09-10 03:24:29 +04:00
|
|
|
}
|
|
|
|
if (parse_special(argv[0]) != SW_VOLTAGS)
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
"%s: inappropriate special word: %s",
|
1999-09-10 03:24:29 +04:00
|
|
|
cname, argv[0]);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1999-09-10 03:24:29 +04:00
|
|
|
flags |= CESR_VOLTAGS;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we get an element type, we can't have specified
|
|
|
|
* anything else.
|
|
|
|
*/
|
|
|
|
if (isdigit(*argv[0]) == 0) {
|
|
|
|
if (schet == echet || flags != 0 || have_unit ||
|
|
|
|
have_ucount) {
|
|
|
|
warnx("%s: malformed command line", cname);
|
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1999-09-10 03:24:29 +04:00
|
|
|
}
|
|
|
|
schet = echet = parse_element_type(argv[0]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We know we have a digit here. If we do, we must
|
|
|
|
* have specified an element type.
|
|
|
|
*/
|
|
|
|
if (schet != echet) {
|
|
|
|
warnx("%s: malformed command line", cname);
|
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1999-09-10 03:24:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
i = parse_element_unit(argv[0]);
|
|
|
|
|
|
|
|
if (have_unit == 0) {
|
|
|
|
unit = i;
|
|
|
|
have_unit = 1;
|
|
|
|
} else if (have_ucount == 0) {
|
|
|
|
ucount = i;
|
|
|
|
have_ucount = 1;
|
|
|
|
} else {
|
|
|
|
warnx("%s: malformed command line", cname);
|
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1999-09-10 03:24:29 +04:00
|
|
|
}
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (chet = schet; chet <= echet; ++chet) {
|
|
|
|
switch (chet) {
|
|
|
|
case CHET_MT:
|
|
|
|
count = data.cp_npickers;
|
|
|
|
break;
|
|
|
|
case CHET_ST:
|
|
|
|
count = data.cp_nslots;
|
|
|
|
break;
|
|
|
|
case CHET_IE:
|
|
|
|
count = data.cp_nportals;
|
|
|
|
break;
|
|
|
|
case CHET_DT:
|
|
|
|
count = data.cp_ndrives;
|
|
|
|
break;
|
1997-07-20 08:44:53 +04:00
|
|
|
default:
|
|
|
|
/* To appease gcc -Wuninitialized. */
|
|
|
|
count = 0;
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0) {
|
1999-09-10 03:24:29 +04:00
|
|
|
if (schet != echet)
|
1996-04-03 04:34:38 +04:00
|
|
|
continue;
|
|
|
|
else {
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf("%s: no %s elements\n",
|
2003-09-14 23:20:16 +04:00
|
|
|
changer_name,
|
1999-09-10 03:24:29 +04:00
|
|
|
elements[chet].et_name);
|
1996-04-03 04:34:38 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-10 03:24:29 +04:00
|
|
|
/*
|
|
|
|
* If we have a unit, we may or may not have a count.
|
|
|
|
* If we don't have a unit, we don't have a count, either.
|
|
|
|
*
|
|
|
|
* Make sure both are initialized.
|
|
|
|
*/
|
|
|
|
if (have_unit) {
|
|
|
|
if (have_ucount == 0)
|
|
|
|
ucount = 1;
|
|
|
|
} else {
|
|
|
|
unit = 0;
|
|
|
|
ucount = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((unit + ucount) > count)
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "%s: unvalid unit/count %d/%d",
|
1999-09-10 03:24:29 +04:00
|
|
|
cname, unit, ucount);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1999-09-10 03:24:29 +04:00
|
|
|
|
|
|
|
size = ucount * sizeof(struct changer_element_status);
|
|
|
|
|
1996-04-03 04:34:38 +04:00
|
|
|
/* Allocate storage for the status bytes. */
|
1999-09-10 03:24:29 +04:00
|
|
|
if ((ces = malloc(size)) == NULL)
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "can't allocate status storage");
|
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)memset(ces, 0, size);
|
|
|
|
(void)memset(&cmd, 0, sizeof(cmd));
|
1996-04-03 04:34:38 +04:00
|
|
|
|
1999-09-10 03:24:29 +04:00
|
|
|
cmd.cesr_type = chet;
|
|
|
|
cmd.cesr_unit = unit;
|
|
|
|
cmd.cesr_count = ucount;
|
|
|
|
cmd.cesr_flags = flags;
|
|
|
|
cmd.cesr_data = ces;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Should we deal with this eventually?
|
|
|
|
*/
|
|
|
|
cmd.cesr_vendor_data = NULL;
|
1996-04-03 04:34:38 +04:00
|
|
|
|
1998-01-05 02:53:58 +03:00
|
|
|
if (ioctl(changer_fd, CHIOGSTATUS, &cmd)) {
|
1999-09-10 03:24:29 +04:00
|
|
|
free(ces);
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CHIOGSTATUS", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Dump the status for each element of this type. */
|
1999-09-10 03:24:29 +04:00
|
|
|
for (i = 0; i < ucount; i++) {
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf("%s %d: ", elements[chet].et_name,
|
1999-09-10 03:24:29 +04:00
|
|
|
unit + i);
|
|
|
|
if ((ces[i].ces_flags & CESTATUS_STATUS_VALID) == 0) {
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf("status not available\n");
|
1999-09-10 03:24:29 +04:00
|
|
|
continue;
|
|
|
|
}
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf("%s", bits_to_string(ces[i].ces_flags,
|
1999-09-10 03:24:29 +04:00
|
|
|
CESTATUS_BITS));
|
|
|
|
if (ces[i].ces_flags & CESTATUS_XNAME_VALID)
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf(" (%s)", ces[i].ces_xname);
|
|
|
|
(void)printf("\n");
|
1999-09-10 03:24:29 +04:00
|
|
|
if (ces[i].ces_flags & CESTATUS_PVOL_VALID)
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf("\tPrimary volume tag: %s "
|
1999-09-10 03:24:29 +04:00
|
|
|
"ver. %d\n",
|
|
|
|
ces[i].ces_pvoltag.cv_tag,
|
|
|
|
ces[i].ces_pvoltag.cv_serial);
|
|
|
|
if (ces[i].ces_flags & CESTATUS_AVOL_VALID)
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf("\tAlternate volume tag: %s "
|
1999-09-10 03:24:29 +04:00
|
|
|
"ver. %d\n",
|
|
|
|
ces[i].ces_avoltag.cv_tag,
|
|
|
|
ces[i].ces_avoltag.cv_serial);
|
|
|
|
if (ces[i].ces_flags & CESTATUS_FROM_VALID)
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf("\tFrom: %s %d\n",
|
1999-09-10 03:24:29 +04:00
|
|
|
elements[ces[i].ces_from_type].et_name,
|
|
|
|
ces[i].ces_from_unit);
|
1999-09-10 03:32:10 +04:00
|
|
|
if (ces[i].ces_vendor_len)
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)printf("\tVendor-specific data size: "
|
1999-09-10 03:32:10 +04:00
|
|
|
"%lu\n", (u_long)ces[i].ces_vendor_len);
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
1999-09-10 03:24:29 +04:00
|
|
|
free(ces);
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-01-05 02:53:58 +03:00
|
|
|
/* ARGSUSED */
|
1997-09-29 21:32:23 +04:00
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
do_ielem(const char *cname, int argc, char **argv)
|
1997-09-29 21:32:23 +04:00
|
|
|
{
|
2002-05-02 17:07:01 +04:00
|
|
|
|
1998-01-05 02:53:58 +03:00
|
|
|
if (ioctl(changer_fd, CHIOIELEM, NULL))
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CHIOIELEM", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1997-09-29 21:32:23 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-09-10 03:24:29 +04:00
|
|
|
/* ARGSUSED */
|
1998-07-13 16:06:18 +04:00
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
do_cdlu(const char *cname, int argc, char **argv)
|
1998-07-13 16:06:18 +04:00
|
|
|
{
|
|
|
|
static const struct special_word cdlu_subcmds[] = {
|
|
|
|
{ "load", CD_LU_LOAD },
|
|
|
|
{ "unload", CD_LU_UNLOAD },
|
|
|
|
{ "abort", CD_LU_ABORT },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
2001-09-13 14:00:44 +04:00
|
|
|
struct ioc_load_unload cmd;
|
|
|
|
int i;
|
1998-07-13 16:06:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This command is a little different, since we are mostly dealing
|
|
|
|
* with ATAPI CD changers, which have a lame API (since ATAPI doesn't
|
|
|
|
* have LUNs).
|
|
|
|
*
|
|
|
|
* We have 3 sub-commands: "load", "unload", and "abort". The
|
|
|
|
* first two take a slot number. The latter does not.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (argc < 1 || argc > 2)
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1998-07-13 16:06:18 +04:00
|
|
|
|
|
|
|
for (i = 0; cdlu_subcmds[i].sw_name != NULL; i++) {
|
|
|
|
if (strcmp(argv[0], cdlu_subcmds[i].sw_name) == 0) {
|
|
|
|
cmd.options = cdlu_subcmds[i].sw_value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cdlu_subcmds[i].sw_name == NULL)
|
1999-08-05 06:47:09 +04:00
|
|
|
usage();
|
2003-08-05 02:31:21 +04:00
|
|
|
/*NOTREACHED*/
|
1998-07-13 16:06:18 +04:00
|
|
|
|
|
|
|
if (strcmp(argv[0], "abort") == 0)
|
|
|
|
cmd.slot = 0;
|
|
|
|
else
|
|
|
|
cmd.slot = parse_element_unit(argv[1]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Should maybe do something different with the device
|
|
|
|
* XXX handling for cdlu; think about this some more.
|
|
|
|
*/
|
|
|
|
if (ioctl(changer_fd, CDIOCLOADUNLOAD, &cmd))
|
2003-09-14 23:20:16 +04:00
|
|
|
err(EXIT_FAILURE, "%s: CDIOCLOADUNLOAD", changer_name);
|
2003-08-05 02:31:21 +04:00
|
|
|
/* NOTREACHED */
|
1998-07-13 16:06:18 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
1997-09-29 21:32:23 +04:00
|
|
|
|
1996-04-03 04:34:38 +04:00
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
parse_element_type(const char *cp)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; elements[i].et_name != NULL; ++i)
|
|
|
|
if (strcmp(elements[i].et_name, cp) == 0)
|
|
|
|
return (elements[i].et_type);
|
|
|
|
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "invalid element type `%s'", cp);
|
1998-01-05 02:53:58 +03:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
parse_element_unit(const char *cp)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
|
|
|
char *p;
|
2001-09-13 14:00:44 +04:00
|
|
|
int i;
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
i = (int)strtol(cp, &p, 10);
|
|
|
|
if ((i < 0) || (*p != '\0'))
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "invalid unit number `%s'", cp);
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
parse_special(const char *cp)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = is_special(cp);
|
|
|
|
if (val)
|
|
|
|
return (val);
|
|
|
|
|
2003-08-05 02:31:21 +04:00
|
|
|
errx(EXIT_FAILURE, "invalid modifier `%s'", cp);
|
1998-01-05 02:53:58 +03:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-13 14:00:44 +04:00
|
|
|
is_special(const char *cp)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; specials[i].sw_name != NULL; ++i)
|
|
|
|
if (strcmp(specials[i].sw_name, cp) == 0)
|
|
|
|
return (specials[i].sw_value);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-07-27 19:25:06 +04:00
|
|
|
static const char *
|
2001-09-13 14:00:44 +04:00
|
|
|
bits_to_string(int v, const char *cp)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
2001-09-13 14:00:44 +04:00
|
|
|
static char buf[128];
|
1996-04-03 04:34:38 +04:00
|
|
|
const char *np;
|
2001-09-13 14:00:44 +04:00
|
|
|
char *bp, f;
|
1998-07-27 19:25:06 +04:00
|
|
|
int first;
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
bp = buf;
|
1998-07-27 19:25:06 +04:00
|
|
|
*bp++ = '<';
|
|
|
|
for (first = 1; (f = *cp++) != 0; cp = np) {
|
1996-04-03 04:34:38 +04:00
|
|
|
for (np = cp; *np >= ' ';)
|
|
|
|
np++;
|
|
|
|
if ((v & (1 << (f - 1))) == 0)
|
|
|
|
continue;
|
1998-07-27 19:25:06 +04:00
|
|
|
if (first)
|
|
|
|
first = 0;
|
|
|
|
else
|
|
|
|
*bp++ = ',';
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)memcpy(bp, cp, np - cp);
|
1998-07-27 19:25:06 +04:00
|
|
|
bp += np - cp;
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|
1998-07-27 19:25:06 +04:00
|
|
|
*bp++ = '>';
|
|
|
|
*bp = '\0';
|
1996-04-03 04:34:38 +04:00
|
|
|
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-09-13 14:00:44 +04:00
|
|
|
cleanup(void)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
2002-05-02 17:07:01 +04:00
|
|
|
|
1996-04-03 04:34:38 +04:00
|
|
|
/* Simple enough... */
|
|
|
|
(void)close(changer_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-09-13 14:00:44 +04:00
|
|
|
usage(void)
|
1996-04-03 04:34:38 +04:00
|
|
|
{
|
1999-08-05 06:47:09 +04:00
|
|
|
int i;
|
1996-04-03 04:34:38 +04:00
|
|
|
|
2004-06-25 18:27:57 +04:00
|
|
|
(void)fprintf(stderr,
|
|
|
|
"usage: %s [-f changer] command arg1 arg2 [arg3 [...]]\n",
|
2001-02-20 01:39:39 +03:00
|
|
|
getprogname());
|
2002-05-02 17:07:01 +04:00
|
|
|
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)fprintf(stderr, "Where command (and args) are:\n");
|
1999-09-10 03:24:29 +04:00
|
|
|
for (i = 0; commands[i].cc_name != NULL; i++)
|
2001-09-13 14:00:44 +04:00
|
|
|
(void)fprintf(stderr, "\t%s%s\n", commands[i].cc_name,
|
1999-09-10 03:24:29 +04:00
|
|
|
commands[i].cc_args);
|
1996-04-03 04:34:38 +04:00
|
|
|
exit(1);
|
1998-07-28 09:31:22 +04:00
|
|
|
/* NOTREACHED */
|
1996-04-03 04:34:38 +04:00
|
|
|
}
|