1999-07-22 14:26:21 +00:00
|
|
|
/* $NetBSD: chio.c,v 1.6 1998/01/04 23:53:58 thorpej Exp $ */
|
2005-01-10 08:39:26 +00:00
|
|
|
/*-
|
1997-03-06 15:30:06 +00:00
|
|
|
* Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
|
|
|
|
* 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 acknowledgements:
|
|
|
|
* This product includes software developed by Jason R. Thorpe
|
|
|
|
* for And Communications, http://www.and.com/
|
|
|
|
* 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.
|
|
|
|
*/
|
1998-09-15 07:48:51 +00:00
|
|
|
/*
|
|
|
|
* Additional Copyright (c) 1997, by Matthew Jacob, for NASA/Ames Research Ctr.
|
2000-09-18 06:09:11 +00:00
|
|
|
* Addidional Copyright (c) 2000, by C. Stephen Gunn, Waterspout Communications
|
1998-09-15 07:48:51 +00:00
|
|
|
*/
|
1997-03-06 15:30:06 +00:00
|
|
|
|
2003-05-01 16:58:57 +00:00
|
|
|
#if 0
|
1998-05-06 06:51:42 +00:00
|
|
|
#ifndef lint
|
1999-06-21 13:23:23 +00:00
|
|
|
static const char copyright[] =
|
|
|
|
"@(#) Copyright (c) 1996 Jason R. Thorpe. All rights reserved.";
|
|
|
|
#endif /* not lint */
|
2003-05-01 16:58:57 +00:00
|
|
|
#endif
|
1998-05-06 06:51:42 +00:00
|
|
|
|
2002-03-24 14:56:55 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-05-13 07:19:45 +00:00
|
|
|
#include <sys/param.h>
|
1997-03-06 15:30:06 +00:00
|
|
|
#include <sys/chio.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
2002-03-05 05:28:49 +00:00
|
|
|
#include <stdint.h>
|
1997-03-06 15:30:06 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
2002-02-02 06:15:22 +00:00
|
|
|
static void usage(void);
|
|
|
|
static void cleanup(void);
|
2002-02-22 21:21:37 +00:00
|
|
|
static u_int16_t parse_element_type(char *);
|
|
|
|
static u_int16_t parse_element_unit(char *);
|
2002-02-02 06:15:22 +00:00
|
|
|
static const char * element_type_name(int et);
|
|
|
|
static int parse_special(char *);
|
|
|
|
static int is_special(char *);
|
|
|
|
static const char *bits_to_string(ces_status_flags, const char *);
|
|
|
|
|
2002-03-05 05:28:49 +00:00
|
|
|
static void find_element(char *, uint16_t *, uint16_t *);
|
2001-07-04 21:35:15 +00:00
|
|
|
static struct changer_element_status *get_element_status
|
2002-02-02 06:15:22 +00:00
|
|
|
(unsigned int, unsigned int);
|
|
|
|
|
|
|
|
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_return(const char *, int, char **);
|
|
|
|
static int do_voltag(const char *, int, char **);
|
1997-03-06 15:30:06 +00:00
|
|
|
|
2000-09-18 06:09:11 +00:00
|
|
|
#ifndef CHET_VT
|
|
|
|
#define CHET_VT 10 /* Completely Arbitrary */
|
|
|
|
#endif
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
/* Valid changer element types. */
|
|
|
|
const struct element_type elements[] = {
|
1999-06-07 13:53:57 +00:00
|
|
|
{ "drive", CHET_DT },
|
1997-03-06 15:30:06 +00:00
|
|
|
{ "picker", CHET_MT },
|
|
|
|
{ "portal", CHET_IE },
|
1999-06-07 13:53:57 +00:00
|
|
|
{ "slot", CHET_ST },
|
2000-09-18 06:09:11 +00:00
|
|
|
{ "voltag", CHET_VT }, /* Select tapes by barcode */
|
1997-03-06 15:30:06 +00:00
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Valid commands. */
|
|
|
|
const struct changer_command commands[] = {
|
|
|
|
{ "exchange", do_exchange },
|
|
|
|
{ "getpicker", do_getpicker },
|
1999-06-07 13:53:57 +00:00
|
|
|
{ "ielem", do_ielem },
|
|
|
|
{ "move", do_move },
|
|
|
|
{ "params", do_params },
|
|
|
|
{ "position", do_position },
|
1997-03-06 15:30:06 +00:00
|
|
|
{ "setpicker", do_setpicker },
|
|
|
|
{ "status", do_status },
|
2000-09-18 06:09:11 +00:00
|
|
|
{ "return", do_return },
|
1998-09-15 07:48:51 +00:00
|
|
|
{ "voltag", do_voltag },
|
1997-03-06 15:30:06 +00:00
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Valid special words. */
|
|
|
|
const struct special_word specials[] = {
|
|
|
|
{ "inv", SW_INVERT },
|
|
|
|
{ "inv1", SW_INVERT1 },
|
|
|
|
{ "inv2", SW_INVERT2 },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int changer_fd;
|
1999-06-21 13:23:23 +00:00
|
|
|
static const char *changer_name;
|
1997-03-06 15:30:06 +00:00
|
|
|
|
|
|
|
int
|
2002-02-02 06:15:22 +00:00
|
|
|
main(int argc, char **argv)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
int ch, i;
|
|
|
|
|
|
|
|
while ((ch = getopt(argc, argv, "f:")) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'f':
|
|
|
|
changer_name = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
err(1, "%s: open", changer_name);
|
|
|
|
|
|
|
|
/* Register cleanup function. */
|
|
|
|
if (atexit(cleanup))
|
|
|
|
err(1, "can't register cleanup function");
|
|
|
|
|
|
|
|
/* Find the specified command. */
|
|
|
|
for (i = 0; commands[i].cc_name != NULL; ++i)
|
|
|
|
if (strcmp(*argv, commands[i].cc_name) == 0)
|
|
|
|
break;
|
1999-06-07 13:53:57 +00:00
|
|
|
if (commands[i].cc_name == NULL) {
|
|
|
|
/* look for abbreviation */
|
|
|
|
for (i = 0; commands[i].cc_name != NULL; ++i)
|
|
|
|
if (strncmp(*argv, commands[i].cc_name,
|
|
|
|
strlen(*argv)) == 0)
|
|
|
|
break;
|
1999-06-21 13:23:23 +00:00
|
|
|
}
|
1999-06-07 13:53:57 +00:00
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
if (commands[i].cc_name == NULL)
|
|
|
|
errx(1, "unknown command: %s", *argv);
|
|
|
|
|
1999-06-21 13:23:23 +00:00
|
|
|
exit ((*commands[i].cc_handler)(commands[i].cc_name, argc, argv));
|
1998-09-15 07:48:51 +00:00
|
|
|
/* NOTREACHED */
|
1997-03-06 15:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_move(const char *cname, int argc, char **argv)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
struct changer_move cmd;
|
|
|
|
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.
|
|
|
|
*/
|
1998-09-15 07:48:51 +00:00
|
|
|
|
|
|
|
++argv; --argc;
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
if (argc < 4) {
|
|
|
|
warnx("%s: too few arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
} else if (argc > 5) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
}
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) memset(&cmd, 0, sizeof(cmd));
|
1997-03-06 15:30:06 +00:00
|
|
|
|
|
|
|
/* <from ET> */
|
|
|
|
cmd.cm_fromtype = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
2000-09-18 06:09:11 +00:00
|
|
|
/* Check for voltag virtual type */
|
|
|
|
if (CHET_VT == cmd.cm_fromtype) {
|
|
|
|
find_element(*argv, &cmd.cm_fromtype, &cmd.cm_fromunit);
|
|
|
|
} else {
|
|
|
|
/* <from EU> */
|
|
|
|
cmd.cm_fromunit = parse_element_unit(*argv);
|
|
|
|
}
|
1997-03-06 15:30:06 +00:00
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <to ET> */
|
|
|
|
cmd.cm_totype = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
2000-09-18 06:09:11 +00:00
|
|
|
/* Check for voltag virtual type, and report error */
|
|
|
|
if (CHET_VT == cmd.cm_totype)
|
|
|
|
errx(1,"%s: voltag only makes sense as an element source",
|
|
|
|
cname);
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
/* <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:
|
|
|
|
errx(1, "%s: inappropriate modifier `%s'",
|
|
|
|
cname, *argv);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send command to changer. */
|
1998-09-15 07:48:51 +00:00
|
|
|
if (ioctl(changer_fd, CHIOMOVE, &cmd))
|
1997-03-06 15:30:06 +00:00
|
|
|
err(1, "%s: CHIOMOVE", changer_name);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
usage:
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) fprintf(stderr, "usage: %s %s "
|
2002-03-24 14:56:55 +00:00
|
|
|
"<from ET> <from EU> <to ET> <to EU> [inv]\n", getprogname(), cname);
|
1997-03-06 15:30:06 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_exchange(const char *cname, int argc, char **argv)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
struct changer_exchange cmd;
|
|
|
|
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.
|
|
|
|
*/
|
1998-09-15 07:48:51 +00:00
|
|
|
|
|
|
|
++argv; --argc;
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
if (argc < 4) {
|
|
|
|
warnx("%s: too few arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
} else if (argc > 8) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
}
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) memset(&cmd, 0, sizeof(cmd));
|
1997-03-06 15:30:06 +00:00
|
|
|
|
|
|
|
/* <src ET> */
|
|
|
|
cmd.ce_srctype = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
2000-09-18 06:09:11 +00:00
|
|
|
/* Check for voltag virtual type */
|
|
|
|
if (CHET_VT == cmd.ce_srctype) {
|
|
|
|
find_element(*argv, &cmd.ce_srctype, &cmd.ce_srcunit);
|
|
|
|
} else {
|
|
|
|
/* <from EU> */
|
|
|
|
cmd.ce_srcunit = parse_element_unit(*argv);
|
|
|
|
}
|
1997-03-06 15:30:06 +00:00
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* <dst1 ET> */
|
|
|
|
cmd.ce_fdsttype = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
2000-09-18 06:09:11 +00:00
|
|
|
/* Check for voltag virtual type */
|
|
|
|
if (CHET_VT == cmd.ce_fdsttype) {
|
|
|
|
find_element(*argv, &cmd.ce_fdsttype, &cmd.ce_fdstunit);
|
|
|
|
} else {
|
|
|
|
/* <from EU> */
|
|
|
|
cmd.ce_fdstunit = parse_element_unit(*argv);
|
|
|
|
}
|
1997-03-06 15:30:06 +00:00
|
|
|
++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;
|
|
|
|
|
2000-09-18 06:09:11 +00:00
|
|
|
if (CHET_VT == cmd.ce_sdsttype)
|
|
|
|
errx(1,"%s %s: voltag only makes sense as an element source",
|
|
|
|
cname, *argv);
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
/* <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:
|
|
|
|
errx(1, "%s: inappropriate modifier `%s'",
|
|
|
|
cname, *argv);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send command to changer. */
|
1998-09-15 07:48:51 +00:00
|
|
|
if (ioctl(changer_fd, CHIOEXCHANGE, &cmd))
|
1997-03-06 15:30:06 +00:00
|
|
|
err(1, "%s: CHIOEXCHANGE", changer_name);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
usage:
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) fprintf(stderr,
|
|
|
|
"usage: %s %s <src ET> <src EU> <dst1 ET> <dst1 EU>\n"
|
|
|
|
" [<dst2 ET> <dst2 EU>] [inv1] [inv2]\n",
|
2002-03-24 14:56:55 +00:00
|
|
|
getprogname(), cname);
|
1997-03-06 15:30:06 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_position(const char *cname, int argc, char **argv)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
struct changer_position cmd;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* On a position command, we expect the following:
|
|
|
|
*
|
|
|
|
* <to ET> <to EU> [inv]
|
|
|
|
*
|
|
|
|
* where ET == element type and EU == element unit.
|
|
|
|
*/
|
1998-09-15 07:48:51 +00:00
|
|
|
|
|
|
|
++argv; --argc;
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
if (argc < 2) {
|
|
|
|
warnx("%s: too few arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
} else if (argc > 3) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
}
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) memset(&cmd, 0, sizeof(cmd));
|
1997-03-06 15:30:06 +00: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:
|
|
|
|
errx(1, "%s: inappropriate modifier `%s'",
|
|
|
|
cname, *argv);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send command to changer. */
|
1998-09-15 07:48:51 +00:00
|
|
|
if (ioctl(changer_fd, CHIOPOSITION, &cmd))
|
1997-03-06 15:30:06 +00:00
|
|
|
err(1, "%s: CHIOPOSITION", changer_name);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
usage:
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) fprintf(stderr, "usage: %s %s <to ET> <to EU> [inv]\n",
|
2002-03-24 14:56:55 +00:00
|
|
|
getprogname(), cname);
|
1997-03-06 15:30:06 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
/* ARGSUSED */
|
1997-03-06 15:30:06 +00:00
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_params(const char *cname, int argc, char **argv)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
struct changer_params data;
|
1998-10-01 23:30:14 +00:00
|
|
|
int picker;
|
1997-03-06 15:30:06 +00:00
|
|
|
|
|
|
|
/* No arguments to this command. */
|
1998-09-15 07:48:51 +00:00
|
|
|
|
|
|
|
++argv; --argc;
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
if (argc) {
|
1998-12-07 10:16:58 +00:00
|
|
|
warnx("%s: no arguments expected", cname);
|
1997-03-06 15:30:06 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get params from changer and display them. */
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) memset(&data, 0, sizeof(data));
|
|
|
|
if (ioctl(changer_fd, CHIOGPARAMS, &data))
|
1997-03-06 15:30:06 +00:00
|
|
|
err(1, "%s: CHIOGPARAMS", changer_name);
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) printf("%s: %d slot%s, %d drive%s, %d picker%s",
|
1997-03-06 15:30:06 +00:00
|
|
|
changer_name,
|
|
|
|
data.cp_nslots, (data.cp_nslots > 1) ? "s" : "",
|
|
|
|
data.cp_ndrives, (data.cp_ndrives > 1) ? "s" : "",
|
|
|
|
data.cp_npickers, (data.cp_npickers > 1) ? "s" : "");
|
|
|
|
if (data.cp_nportals)
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) printf(", %d portal%s", data.cp_nportals,
|
1997-03-06 15:30:06 +00:00
|
|
|
(data.cp_nportals > 1) ? "s" : "");
|
|
|
|
|
1998-10-01 23:30:14 +00:00
|
|
|
/* Get current picker from changer and display it. */
|
|
|
|
if (ioctl(changer_fd, CHIOGPICKER, &picker))
|
|
|
|
err(1, "%s: CHIOGPICKER", changer_name);
|
|
|
|
|
|
|
|
(void) printf("\n%s: current picker: %d\n", changer_name, picker);
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
usage:
|
2002-03-24 14:56:55 +00:00
|
|
|
(void) fprintf(stderr, "usage: %s %s\n", getprogname(), cname);
|
1997-03-06 15:30:06 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
/* ARGSUSED */
|
1997-03-06 15:30:06 +00:00
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_getpicker(const char *cname, int argc, char **argv)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
int picker;
|
|
|
|
|
|
|
|
/* No arguments to this command. */
|
1998-09-15 07:48:51 +00:00
|
|
|
|
|
|
|
++argv; --argc;
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
if (argc) {
|
|
|
|
warnx("%s: no arguments expected", cname);
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get current picker from changer and display it. */
|
1998-09-15 07:48:51 +00:00
|
|
|
if (ioctl(changer_fd, CHIOGPICKER, &picker))
|
1997-03-06 15:30:06 +00:00
|
|
|
err(1, "%s: CHIOGPICKER", changer_name);
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) printf("%s: current picker: %d\n", changer_name, picker);
|
1997-03-06 15:30:06 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
usage:
|
2002-03-24 14:56:55 +00:00
|
|
|
(void) fprintf(stderr, "usage: %s %s\n", getprogname(), cname);
|
1997-03-06 15:30:06 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_setpicker(const char *cname, int argc, char **argv)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
int picker;
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
++argv; --argc;
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
if (argc < 1) {
|
|
|
|
warnx("%s: too few arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
} else if (argc > 1) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
picker = parse_element_unit(*argv);
|
|
|
|
|
|
|
|
/* Set the changer picker. */
|
1998-09-15 07:48:51 +00:00
|
|
|
if (ioctl(changer_fd, CHIOSPICKER, &picker))
|
1997-03-06 15:30:06 +00:00
|
|
|
err(1, "%s: CHIOSPICKER", changer_name);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
usage:
|
2002-03-24 14:56:55 +00:00
|
|
|
(void) fprintf(stderr, "usage: %s %s <picker>\n", getprogname(), cname);
|
1997-03-06 15:30:06 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_status(const char *cname, int argc, char **argv)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
1998-09-15 07:48:51 +00:00
|
|
|
struct changer_params cp;
|
|
|
|
struct changer_element_status_request cesr;
|
2002-02-22 21:21:37 +00:00
|
|
|
int i;
|
|
|
|
u_int16_t base, count, chet, schet, echet;
|
2001-07-03 03:22:49 +00:00
|
|
|
const char *description;
|
1998-09-15 07:48:51 +00:00
|
|
|
int pvoltag = 0;
|
|
|
|
int avoltag = 0;
|
|
|
|
int sense = 0;
|
|
|
|
int scsi = 0;
|
|
|
|
int source = 0;
|
|
|
|
int intaddr = 0;
|
|
|
|
int c;
|
1997-06-02 06:25:19 +00:00
|
|
|
|
|
|
|
count = 0;
|
1998-09-15 07:48:51 +00:00
|
|
|
base = 0;
|
1997-06-02 06:25:19 +00:00
|
|
|
description = NULL;
|
1997-03-06 15:30:06 +00:00
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
optind = optreset = 1;
|
1999-05-23 23:24:26 +00:00
|
|
|
while ((c = getopt(argc, argv, "vVsSbaI")) != -1) {
|
1998-09-15 07:48:51 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'v':
|
|
|
|
pvoltag = 1;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
avoltag = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sense = 1;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
source = 1;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
scsi = 1;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
intaddr = 1;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
pvoltag = avoltag = source = sense = scsi = intaddr = 1;
|
|
|
|
break;
|
|
|
|
default:
|
1998-12-07 10:16:58 +00:00
|
|
|
warnx("%s: bad option", cname);
|
1998-09-15 07:48:51 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1997-03-06 15:30:06 +00:00
|
|
|
/*
|
|
|
|
* On a status command, we expect the following:
|
|
|
|
*
|
1998-09-15 07:48:51 +00:00
|
|
|
* [<ET> [<start> [<end>] ] ]
|
1997-03-06 15:30:06 +00:00
|
|
|
*
|
1998-09-15 07:48:51 +00:00
|
|
|
* where ET == element type, start == first element to report,
|
|
|
|
* end == number of elements to report
|
1997-03-06 15:30:06 +00:00
|
|
|
*
|
|
|
|
* If we get no arguments, we get the status of all
|
|
|
|
* known element types.
|
|
|
|
*/
|
1998-09-15 07:48:51 +00:00
|
|
|
if (argc > 3) {
|
1997-03-06 15:30:06 +00:00
|
|
|
warnx("%s: too many arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get params from changer. Specifically, we need the element
|
|
|
|
* counts.
|
|
|
|
*/
|
1998-09-15 07:48:51 +00:00
|
|
|
if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
|
1997-03-06 15:30:06 +00:00
|
|
|
err(1, "%s: CHIOGPARAMS", changer_name);
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
if (argc > 0)
|
|
|
|
schet = echet = parse_element_type(argv[0]);
|
1997-03-06 15:30:06 +00:00
|
|
|
else {
|
|
|
|
schet = CHET_MT;
|
|
|
|
echet = CHET_DT;
|
|
|
|
}
|
1998-09-15 07:48:51 +00:00
|
|
|
if (argc > 1) {
|
2002-02-22 21:21:37 +00:00
|
|
|
base = (u_int16_t)atol(argv[1]);
|
1998-09-15 07:48:51 +00:00
|
|
|
count = 1;
|
|
|
|
}
|
|
|
|
if (argc > 2)
|
2002-02-22 21:21:37 +00:00
|
|
|
count = (u_int16_t)atol(argv[2]) - base + 1;
|
1997-03-06 15:30:06 +00:00
|
|
|
|
|
|
|
for (chet = schet; chet <= echet; ++chet) {
|
|
|
|
switch (chet) {
|
|
|
|
case CHET_MT:
|
1998-09-15 07:48:51 +00:00
|
|
|
if (count == 0)
|
|
|
|
count = cp.cp_npickers;
|
|
|
|
else if (count > cp.cp_npickers)
|
|
|
|
errx(1, "not that many pickers in device");
|
1997-03-06 15:30:06 +00:00
|
|
|
description = "picker";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHET_ST:
|
1998-09-15 07:48:51 +00:00
|
|
|
if (count == 0)
|
|
|
|
count = cp.cp_nslots;
|
|
|
|
else if (count > cp.cp_nslots)
|
|
|
|
errx(1, "not that many slots in device");
|
1997-03-06 15:30:06 +00:00
|
|
|
description = "slot";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHET_IE:
|
1998-09-15 07:48:51 +00:00
|
|
|
if (count == 0)
|
|
|
|
count = cp.cp_nportals;
|
|
|
|
else if (count > cp.cp_nportals)
|
|
|
|
errx(1, "not that many portals in device");
|
1997-03-06 15:30:06 +00:00
|
|
|
description = "portal";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHET_DT:
|
1998-09-15 07:48:51 +00:00
|
|
|
if (count == 0)
|
|
|
|
count = cp.cp_ndrives;
|
|
|
|
else if (count > cp.cp_ndrives)
|
|
|
|
errx(1, "not that many drives in device");
|
1997-03-06 15:30:06 +00:00
|
|
|
description = "drive";
|
|
|
|
break;
|
1998-09-15 07:48:51 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* To appease gcc -Wuninitialized. */
|
|
|
|
count = 0;
|
|
|
|
description = NULL;
|
1997-03-06 15:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
if (argc == 0)
|
|
|
|
continue;
|
|
|
|
else {
|
|
|
|
printf("%s: no %s elements\n",
|
|
|
|
changer_name, description);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
bzero(&cesr, sizeof(cesr));
|
|
|
|
cesr.cesr_element_type = chet;
|
|
|
|
cesr.cesr_element_base = base;
|
|
|
|
cesr.cesr_element_count = count;
|
|
|
|
/* Allocate storage for the status structures. */
|
2000-09-18 06:09:11 +00:00
|
|
|
cesr.cesr_element_status =
|
|
|
|
(struct changer_element_status *)
|
2001-07-04 21:35:15 +00:00
|
|
|
calloc((size_t)count, sizeof(struct changer_element_status));
|
1998-09-15 07:48:51 +00:00
|
|
|
|
|
|
|
if (!cesr.cesr_element_status)
|
1997-03-06 15:30:06 +00:00
|
|
|
errx(1, "can't allocate status storage");
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
if (avoltag || pvoltag)
|
|
|
|
cesr.cesr_flags |= CESR_VOLTAGS;
|
1997-03-06 15:30:06 +00:00
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr)) {
|
|
|
|
free(cesr.cesr_element_status);
|
1997-03-06 15:30:06 +00:00
|
|
|
err(1, "%s: CHIOGSTATUS", changer_name);
|
|
|
|
}
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
/* Dump the status for each reported element. */
|
1997-03-06 15:30:06 +00:00
|
|
|
for (i = 0; i < count; ++i) {
|
1998-09-15 07:48:51 +00:00
|
|
|
struct changer_element_status *ces =
|
|
|
|
&(cesr.cesr_element_status[i]);
|
|
|
|
printf("%s %d: %s", description, ces->ces_addr,
|
|
|
|
bits_to_string(ces->ces_flags,
|
|
|
|
CESTATUS_BITS));
|
|
|
|
if (sense)
|
|
|
|
printf(" sense: <0x%02x/0x%02x>",
|
|
|
|
ces->ces_sensecode,
|
|
|
|
ces->ces_sensequal);
|
|
|
|
if (pvoltag)
|
|
|
|
printf(" voltag: <%s:%d>",
|
|
|
|
ces->ces_pvoltag.cv_volid,
|
|
|
|
ces->ces_pvoltag.cv_serial);
|
|
|
|
if (avoltag)
|
|
|
|
printf(" avoltag: <%s:%d>",
|
|
|
|
ces->ces_avoltag.cv_volid,
|
|
|
|
ces->ces_avoltag.cv_serial);
|
1999-04-25 21:13:34 +00:00
|
|
|
if (source) {
|
1998-09-15 07:48:51 +00:00
|
|
|
if (ces->ces_flags & CES_SOURCE_VALID)
|
|
|
|
printf(" source: <%s %d>",
|
|
|
|
element_type_name(
|
|
|
|
ces->ces_source_type),
|
|
|
|
ces->ces_source_addr);
|
|
|
|
else
|
|
|
|
printf(" source: <>");
|
1999-04-25 21:13:34 +00:00
|
|
|
}
|
1998-09-15 07:48:51 +00:00
|
|
|
if (intaddr)
|
|
|
|
printf(" intaddr: <%d>", ces->ces_int_addr);
|
|
|
|
if (scsi) {
|
|
|
|
printf(" scsi: <");
|
|
|
|
if (ces->ces_flags & CES_SCSIID_VALID)
|
|
|
|
printf("%d", ces->ces_scsi_id);
|
|
|
|
else
|
|
|
|
putchar('?');
|
|
|
|
putchar(':');
|
|
|
|
if (ces->ces_flags & CES_LUN_VALID)
|
|
|
|
printf("%d", ces->ces_scsi_lun);
|
|
|
|
else
|
|
|
|
putchar('?');
|
|
|
|
putchar('>');
|
|
|
|
}
|
|
|
|
putchar('\n');
|
1997-03-06 15:30:06 +00:00
|
|
|
}
|
|
|
|
|
1998-09-15 07:48:51 +00:00
|
|
|
free(cesr.cesr_element_status);
|
|
|
|
count = 0;
|
1997-03-06 15:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
usage:
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) fprintf(stderr, "usage: %s %s [-vVsSbaA] [<element type> [<start-addr> [<end-addr>] ] ]\n",
|
2002-03-24 14:56:55 +00:00
|
|
|
getprogname(), cname);
|
1997-03-06 15:30:06 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_ielem(const char *cname, int argc, char **argv)
|
1998-09-15 07:48:51 +00:00
|
|
|
{
|
|
|
|
int timeout = 0;
|
|
|
|
|
|
|
|
if (argc == 2) {
|
|
|
|
timeout = atol(argv[1]);
|
|
|
|
} else if (argc > 1) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(changer_fd, CHIOIELEM, &timeout))
|
|
|
|
err(1, "%s: CHIOIELEM", changer_name);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
usage:
|
|
|
|
(void) fprintf(stderr, "usage: %s %s [<timeout>]\n",
|
2002-03-24 14:56:55 +00:00
|
|
|
getprogname(), cname);
|
1998-09-15 07:48:51 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_voltag(const char *cname, int argc, char **argv)
|
1998-09-15 07:48:51 +00:00
|
|
|
{
|
|
|
|
int force = 0;
|
|
|
|
int clear = 0;
|
|
|
|
int alternate = 0;
|
|
|
|
int c;
|
|
|
|
struct changer_set_voltag_request csvr;
|
|
|
|
|
|
|
|
bzero(&csvr, sizeof(csvr));
|
|
|
|
|
|
|
|
optind = optreset = 1;
|
1999-05-23 23:24:26 +00:00
|
|
|
while ((c = getopt(argc, argv, "fca")) != -1) {
|
1998-09-15 07:48:51 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
force = 1;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
clear = 1;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
alternate = 1;
|
|
|
|
break;
|
|
|
|
default:
|
1998-12-07 10:16:58 +00:00
|
|
|
warnx("%s: bad option", cname);
|
1998-09-15 07:48:51 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
1998-12-07 10:16:58 +00:00
|
|
|
warnx("%s: missing element specification", cname);
|
1998-09-15 07:48:51 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
csvr.csvr_type = parse_element_type(argv[0]);
|
2002-02-22 21:21:37 +00:00
|
|
|
csvr.csvr_addr = (u_int16_t)atol(argv[1]);
|
1998-09-15 07:48:51 +00:00
|
|
|
|
|
|
|
if (!clear) {
|
|
|
|
if (argc < 3 || argc > 4) {
|
1998-12-07 10:16:58 +00:00
|
|
|
warnx("%s: missing argument", cname);
|
1998-09-15 07:48:51 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (force)
|
|
|
|
csvr.csvr_flags = CSVR_MODE_REPLACE;
|
|
|
|
else
|
|
|
|
csvr.csvr_flags = CSVR_MODE_SET;
|
|
|
|
|
|
|
|
if (strlen(argv[2]) > sizeof(csvr.csvr_voltag.cv_volid)) {
|
1998-12-07 10:16:58 +00:00
|
|
|
warnx("%s: volume label too long", cname);
|
1998-09-15 07:48:51 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
2001-07-04 21:35:15 +00:00
|
|
|
strlcpy((char *)csvr.csvr_voltag.cv_volid, argv[2],
|
1998-09-15 07:48:51 +00:00
|
|
|
sizeof(csvr.csvr_voltag.cv_volid));
|
|
|
|
|
|
|
|
if (argc == 4) {
|
2002-02-22 21:21:37 +00:00
|
|
|
csvr.csvr_voltag.cv_serial = (u_int16_t)atol(argv[3]);
|
1998-09-15 07:48:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (argc != 2) {
|
1998-12-07 10:16:58 +00:00
|
|
|
warnx("%s: unexpected argument", cname);
|
1998-09-15 07:48:51 +00:00
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
csvr.csvr_flags = CSVR_MODE_CLEAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alternate) {
|
|
|
|
csvr.csvr_flags |= CSVR_ALTERNATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(changer_fd, CHIOSETVOLTAG, &csvr))
|
|
|
|
err(1, "%s: CHIOSETVOLTAG", changer_name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
usage:
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"usage: %s %s [-fca] <element> [<voltag> [<vsn>] ]\n",
|
2002-03-24 14:56:55 +00:00
|
|
|
getprogname(), cname);
|
1998-09-15 07:48:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-02-22 21:21:37 +00:00
|
|
|
static u_int16_t
|
2002-02-02 06:15:22 +00:00
|
|
|
parse_element_type(char *cp)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; elements[i].et_name != NULL; ++i)
|
|
|
|
if (strcmp(elements[i].et_name, cp) == 0)
|
2002-02-22 21:21:37 +00:00
|
|
|
return ((u_int16_t)elements[i].et_type);
|
1997-03-06 15:30:06 +00:00
|
|
|
|
|
|
|
errx(1, "invalid element type `%s'", cp);
|
1998-09-15 07:48:51 +00:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2002-02-02 06:15:22 +00:00
|
|
|
element_type_name(int et)
|
1998-09-15 07:48:51 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; elements[i].et_name != NULL; i++)
|
|
|
|
if (elements[i].et_type == et)
|
|
|
|
return elements[i].et_name;
|
|
|
|
|
|
|
|
return "unknown";
|
1997-03-06 15:30:06 +00:00
|
|
|
}
|
|
|
|
|
2002-02-22 21:21:37 +00:00
|
|
|
static u_int16_t
|
2002-02-02 06:15:22 +00:00
|
|
|
parse_element_unit(char *cp)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
i = (int)strtol(cp, &p, 10);
|
|
|
|
if ((i < 0) || (*p != '\0'))
|
|
|
|
errx(1, "invalid unit number `%s'", cp);
|
|
|
|
|
2002-02-22 21:21:37 +00:00
|
|
|
return ((u_int16_t)i);
|
1997-03-06 15:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
parse_special(char *cp)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = is_special(cp);
|
|
|
|
if (val)
|
|
|
|
return (val);
|
|
|
|
|
|
|
|
errx(1, "invalid modifier `%s'", cp);
|
1998-09-15 07:48:51 +00:00
|
|
|
/* NOTREACHED */
|
1997-03-06 15:30:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
is_special(char *cp)
|
1997-03-06 15:30:06 +00: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);
|
|
|
|
}
|
|
|
|
|
1999-06-21 13:23:23 +00:00
|
|
|
static const char *
|
2002-02-02 06:15:22 +00:00
|
|
|
bits_to_string(ces_status_flags v, const char *cp)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
const char *np;
|
|
|
|
char f, sep, *bp;
|
|
|
|
static char buf[128];
|
|
|
|
|
|
|
|
bp = buf;
|
1998-09-15 07:48:51 +00:00
|
|
|
(void) memset(buf, 0, sizeof(buf));
|
1997-03-06 15:30:06 +00:00
|
|
|
|
|
|
|
for (sep = '<'; (f = *cp++) != 0; cp = np) {
|
|
|
|
for (np = cp; *np >= ' ';)
|
|
|
|
np++;
|
2002-02-22 21:21:37 +00:00
|
|
|
if (((int)v & (1 << (f - 1))) == 0)
|
1997-03-06 15:30:06 +00:00
|
|
|
continue;
|
2002-02-22 21:21:37 +00:00
|
|
|
(void) snprintf(bp, sizeof(buf) - (size_t)(bp - &buf[0]),
|
1999-06-21 13:23:23 +00:00
|
|
|
"%c%.*s", sep, (int)(long)(np - cp), cp);
|
1999-06-07 13:53:57 +00:00
|
|
|
bp += strlen(bp);
|
1997-03-06 15:30:06 +00:00
|
|
|
sep = ',';
|
|
|
|
}
|
|
|
|
if (sep != '<')
|
|
|
|
*bp = '>';
|
|
|
|
|
|
|
|
return (buf);
|
|
|
|
}
|
2000-09-18 06:09:11 +00:00
|
|
|
/*
|
|
|
|
* do_return()
|
|
|
|
*
|
|
|
|
* Given an element reference, ask the changer/picker to move that
|
|
|
|
* element back to its source slot.
|
|
|
|
*/
|
|
|
|
static int
|
2002-02-02 06:15:22 +00:00
|
|
|
do_return(const char *cname, int argc, char **argv)
|
2000-09-18 06:09:11 +00:00
|
|
|
{
|
|
|
|
struct changer_element_status *ces;
|
|
|
|
struct changer_move cmd;
|
2002-03-05 05:28:49 +00:00
|
|
|
uint16_t type, element;
|
2000-09-18 06:09:11 +00:00
|
|
|
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
warnx("%s: too few arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
} else if (argc > 3) {
|
|
|
|
warnx("%s: too many arguments", cname);
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = parse_element_type(*argv);
|
|
|
|
++argv; --argc;
|
|
|
|
|
|
|
|
/* Handle voltag virtual Changer Element Type */
|
|
|
|
if (CHET_VT == type) {
|
|
|
|
find_element(*argv, &type, &element);
|
|
|
|
} else {
|
|
|
|
element = parse_element_unit(*argv);
|
|
|
|
}
|
|
|
|
++argv; --argc;
|
|
|
|
|
2001-07-04 21:35:15 +00:00
|
|
|
/* Get the status */
|
|
|
|
ces = get_element_status((unsigned int)type, (unsigned int)element);
|
2000-09-18 06:09:11 +00:00
|
|
|
|
|
|
|
if (NULL == ces)
|
|
|
|
errx(1, "%s: null element status pointer", cname);
|
|
|
|
|
|
|
|
if (!(ces->ces_flags & CES_SOURCE_VALID))
|
|
|
|
errx(1, "%s: no source information", cname);
|
|
|
|
|
|
|
|
(void) memset(&cmd, 0, sizeof(cmd));
|
|
|
|
|
|
|
|
cmd.cm_fromtype = type;
|
|
|
|
cmd.cm_fromunit = element;
|
|
|
|
cmd.cm_totype = ces->ces_source_type;
|
|
|
|
cmd.cm_tounit = ces->ces_source_addr;
|
|
|
|
|
|
|
|
if (ioctl(changer_fd, CHIOMOVE, &cmd) == -1)
|
|
|
|
err(1, "%s: CHIOMOVE", changer_name);
|
|
|
|
free(ces);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
usage:
|
|
|
|
(void) fprintf(stderr, "usage: %s %s "
|
2002-03-24 14:56:55 +00:00
|
|
|
"<from ET> <from EU>\n", getprogname(), cname);
|
2000-09-18 06:09:11 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_element_status()
|
|
|
|
*
|
|
|
|
* return a *cesr for the specified changer element. This
|
|
|
|
* routing will malloc()/calloc() the memory. The caller
|
|
|
|
* should free() it when done.
|
|
|
|
*/
|
|
|
|
static struct changer_element_status *
|
2002-02-02 06:15:22 +00:00
|
|
|
get_element_status(unsigned int type, unsigned int element)
|
2000-09-18 06:09:11 +00:00
|
|
|
{
|
|
|
|
struct changer_element_status_request cesr;
|
|
|
|
struct changer_element_status *ces;
|
|
|
|
|
|
|
|
ces = (struct changer_element_status *)
|
2001-07-04 21:35:15 +00:00
|
|
|
calloc((size_t)1, sizeof(struct changer_element_status));
|
2000-09-18 06:09:11 +00:00
|
|
|
|
|
|
|
if (NULL == ces)
|
|
|
|
errx(1, "can't allocate status storage");
|
|
|
|
|
|
|
|
(void)memset(&cesr, 0, sizeof(cesr));
|
|
|
|
|
2002-03-05 05:28:49 +00:00
|
|
|
cesr.cesr_element_type = (uint16_t)type;
|
|
|
|
cesr.cesr_element_base = (uint16_t)element;
|
2000-09-18 06:09:11 +00:00
|
|
|
cesr.cesr_element_count = 1; /* Only this one element */
|
|
|
|
cesr.cesr_flags |= CESR_VOLTAGS; /* Grab voltags as well */
|
|
|
|
cesr.cesr_element_status = ces;
|
|
|
|
|
|
|
|
if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
|
|
|
|
free(ces);
|
|
|
|
err(1, "%s: CHIOGSTATUS", changer_name);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
return ces;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find_element()
|
|
|
|
*
|
|
|
|
* Given a <voltag> find the chager element and unit, or exit
|
|
|
|
* with an error if it isn't found. We grab the changer status
|
|
|
|
* and iterate until we find a match, or crap out.
|
|
|
|
*/
|
|
|
|
static void
|
2002-03-05 05:28:49 +00:00
|
|
|
find_element(char *voltag, uint16_t *et, uint16_t *eu)
|
2000-09-18 06:09:11 +00:00
|
|
|
{
|
|
|
|
struct changer_params cp;
|
|
|
|
struct changer_element_status_request cesr;
|
|
|
|
struct changer_element_status *ch_ces, *ces;
|
2001-07-04 21:35:15 +00:00
|
|
|
int found = 0;
|
|
|
|
size_t elem, total_elem;
|
2000-09-18 06:09:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the changer parameters, we're interested in the counts
|
|
|
|
* for all types of elements to perform our search.
|
|
|
|
*/
|
|
|
|
if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
|
|
|
|
err(1, "%s: CHIOGPARAMS", changer_name);
|
|
|
|
|
|
|
|
/* Allocate some memory for the results */
|
|
|
|
total_elem = (cp.cp_nslots + cp.cp_ndrives
|
|
|
|
+ cp.cp_npickers + cp.cp_nportals);
|
|
|
|
|
|
|
|
ch_ces = (struct changer_element_status *)
|
|
|
|
calloc(total_elem, sizeof(struct changer_element_status));
|
|
|
|
|
|
|
|
if (NULL == ch_ces)
|
|
|
|
errx(1, "can't allocate status storage");
|
|
|
|
|
|
|
|
ces = ch_ces;
|
|
|
|
|
|
|
|
/* Read in the changer slots */
|
|
|
|
if (cp.cp_nslots > 0) {
|
|
|
|
cesr.cesr_element_type = CHET_ST;
|
|
|
|
cesr.cesr_element_base = 0;
|
|
|
|
cesr.cesr_element_count = cp.cp_nslots;
|
|
|
|
cesr.cesr_flags |= CESR_VOLTAGS;
|
|
|
|
cesr.cesr_element_status = ces;
|
|
|
|
|
|
|
|
if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
|
|
|
|
free(ch_ces);
|
|
|
|
err(1, "%s: CHIOGSTATUS", changer_name);
|
|
|
|
}
|
|
|
|
ces += cp.cp_nslots;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in the drive information */
|
|
|
|
if (cp.cp_ndrives > 0 ) {
|
|
|
|
|
|
|
|
(void) memset(&cesr, 0, sizeof(cesr));
|
|
|
|
cesr.cesr_element_type = CHET_DT;
|
|
|
|
cesr.cesr_element_base = 0;
|
|
|
|
cesr.cesr_element_count = cp.cp_ndrives;
|
|
|
|
cesr.cesr_flags |= CESR_VOLTAGS;
|
|
|
|
cesr.cesr_element_status = ces;
|
|
|
|
|
|
|
|
if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
|
|
|
|
free(ch_ces);
|
|
|
|
err(1, "%s: CHIOGSTATUS", changer_name);
|
|
|
|
}
|
|
|
|
ces += cp.cp_ndrives;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in the portal information */
|
|
|
|
if (cp.cp_nportals > 0 ) {
|
|
|
|
(void) memset(&cesr, 0, sizeof(cesr));
|
|
|
|
cesr.cesr_element_type = CHET_IE;
|
|
|
|
cesr.cesr_element_base = 0;
|
|
|
|
cesr.cesr_element_count = cp.cp_nportals;
|
|
|
|
cesr.cesr_flags |= CESR_VOLTAGS;
|
|
|
|
cesr.cesr_element_status = ces;
|
|
|
|
|
|
|
|
if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
|
|
|
|
free(ch_ces);
|
|
|
|
err(1, "%s: CHIOGSTATUS", changer_name);
|
|
|
|
}
|
|
|
|
ces += cp.cp_nportals;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in the picker information */
|
|
|
|
if (cp.cp_npickers > 0) {
|
|
|
|
(void) memset(&cesr, 0, sizeof(cesr));
|
|
|
|
cesr.cesr_element_type = CHET_MT;
|
|
|
|
cesr.cesr_element_base = 0;
|
|
|
|
cesr.cesr_element_count = cp.cp_npickers;
|
|
|
|
cesr.cesr_flags |= CESR_VOLTAGS;
|
|
|
|
cesr.cesr_element_status = ces;
|
|
|
|
|
|
|
|
if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
|
|
|
|
free(ch_ces);
|
|
|
|
err(1, "%s: CHIOGSTATUS", changer_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now search the list the specified <voltag>
|
|
|
|
*/
|
|
|
|
for (elem = 0; elem <= total_elem; ++elem) {
|
|
|
|
|
|
|
|
ces = &ch_ces[elem];
|
|
|
|
|
|
|
|
/* Make sure we have a tape in this element */
|
|
|
|
if ((ces->ces_flags & (CES_STATUS_ACCESS|CES_STATUS_FULL))
|
|
|
|
!= (CES_STATUS_ACCESS|CES_STATUS_FULL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Check to see if it is our target */
|
2001-07-04 21:35:15 +00:00
|
|
|
if (strcasecmp(voltag,
|
|
|
|
(const char *)ces->ces_pvoltag.cv_volid) == 0) {
|
2000-09-18 06:09:11 +00:00
|
|
|
*et = ces->ces_type;
|
|
|
|
*eu = ces->ces_addr;
|
|
|
|
++found;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
errx(1, "%s: unable to locate voltag: %s", changer_name,
|
|
|
|
voltag);
|
|
|
|
}
|
|
|
|
free(ch_ces);
|
|
|
|
return;
|
|
|
|
}
|
1997-03-06 15:30:06 +00:00
|
|
|
|
|
|
|
static void
|
2002-02-02 06:15:22 +00:00
|
|
|
cleanup(void)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
|
|
|
/* Simple enough... */
|
|
|
|
(void)close(changer_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-02-02 06:15:22 +00:00
|
|
|
usage(void)
|
1997-03-06 15:30:06 +00:00
|
|
|
{
|
2002-02-02 06:15:22 +00:00
|
|
|
(void)fprintf(stderr, "usage: %s [-f changer] command [-<flags>] "
|
2002-03-24 14:56:55 +00:00
|
|
|
"arg1 arg2 [arg3 [...]]\n", getprogname());
|
1997-03-06 15:30:06 +00:00
|
|
|
exit(1);
|
|
|
|
}
|