2 * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgements:
15 * This product includes software developed by Jason R. Thorpe
16 * for And Communications, http://www.and.com/
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#) Copyright (c) 1996 Jason R. Thorpe. All rights reserved.
33 * $NetBSD: chio.c,v 1.6 1998/01/04 23:53:58 thorpej Exp $
34 * $FreeBSD: src/bin/chio/chio.c,v 1.15.2.3 2001/07/28 19:22:01 mikeh Exp $
37 * Additional Copyright (c) 1997, by Matthew Jacob, for NASA/Ames Research Ctr.
38 * Addidional Copyright (c) 2000, by C. Stephen Gunn, Waterspout Communications
42 #include <sys/param.h>
52 #include "pathnames.h"
54 extern char *__progname; /* from crt0.o */
56 static void usage (void);
57 static void cleanup (void);
58 static int parse_element_type (char *);
59 static int parse_element_unit (char *);
60 static const char * element_type_name (int et);
61 static int parse_special (char *);
62 static int is_special (char *);
63 static const char *bits_to_string (ces_status_flags, const char *);
65 static void find_element (char *, u_int16_t *, u_int16_t *);
66 static struct changer_element_status *get_element_status
67 (unsigned int, unsigned int);
69 static int do_move (const char *, int, char **);
70 static int do_exchange (const char *, int, char **);
71 static int do_position (const char *, int, char **);
72 static int do_params (const char *, int, char **);
73 static int do_getpicker (const char *, int, char **);
74 static int do_setpicker (const char *, int, char **);
75 static int do_status (const char *, int, char **);
76 static int do_ielem (const char *, int, char **);
77 static int do_return (const char *, int, char **);
78 static int do_voltag (const char *, int, char **);
81 #define CHET_VT 10 /* Completely Arbitrary */
84 /* Valid changer element types. */
85 static const struct element_type elements[] = {
87 { "picker", CHET_MT },
88 { "portal", CHET_IE },
90 { "voltag", CHET_VT }, /* Select tapes by barcode */
95 static const struct changer_command commands[] = {
96 { "exchange", do_exchange },
97 { "getpicker", do_getpicker },
98 { "ielem", do_ielem },
100 { "params", do_params },
101 { "position", do_position },
102 { "setpicker", do_setpicker },
103 { "status", do_status },
104 { "return", do_return },
105 { "voltag", do_voltag },
109 /* Valid special words. */
110 static const struct special_word specials[] = {
111 { "inv", SW_INVERT },
112 { "inv1", SW_INVERT1 },
113 { "inv2", SW_INVERT2 },
117 static int changer_fd;
118 static const char *changer_name;
121 main(int argc, char **argv)
125 while ((ch = getopt(argc, argv, "f:")) != -1) {
128 changer_name = optarg;
140 /* Get the default changer if not already specified. */
141 if (changer_name == NULL)
142 if ((changer_name = getenv(CHANGER_ENV_VAR)) == NULL)
143 changer_name = _PATH_CH;
145 /* Open the changer device. */
146 if ((changer_fd = open(changer_name, O_RDWR, 0600)) == -1)
147 err(1, "%s: open", changer_name);
149 /* Register cleanup function. */
151 err(1, "can't register cleanup function");
153 /* Find the specified command. */
154 for (i = 0; commands[i].cc_name != NULL; ++i)
155 if (strcmp(*argv, commands[i].cc_name) == 0)
157 if (commands[i].cc_name == NULL) {
158 /* look for abbreviation */
159 for (i = 0; commands[i].cc_name != NULL; ++i)
160 if (strncmp(*argv, commands[i].cc_name,
165 if (commands[i].cc_name == NULL)
166 errx(1, "unknown command: %s", *argv);
168 exit ((*commands[i].cc_handler)(commands[i].cc_name, argc, argv));
173 do_move(const char *cname, int argc, char **argv)
175 struct changer_move cmd;
179 * On a move command, we expect the following:
181 * <from ET> <from EU> <to ET> <to EU> [inv]
183 * where ET == element type and EU == element unit.
189 warnx("%s: too few arguments", cname);
191 } else if (argc > 5) {
192 warnx("%s: too many arguments", cname);
195 memset(&cmd, 0, sizeof(cmd));
198 cmd.cm_fromtype = parse_element_type(*argv);
201 /* Check for voltag virtual type */
202 if (CHET_VT == cmd.cm_fromtype) {
203 find_element(*argv, &cmd.cm_fromtype, &cmd.cm_fromunit);
206 cmd.cm_fromunit = parse_element_unit(*argv);
211 cmd.cm_totype = parse_element_type(*argv);
214 /* Check for voltag virtual type, and report error */
215 if (CHET_VT == cmd.cm_totype)
216 errx(1,"%s: voltag only makes sense as an element source",
220 cmd.cm_tounit = parse_element_unit(*argv);
223 /* Deal with optional command modifier. */
225 val = parse_special(*argv);
228 cmd.cm_flags |= CM_INVERT;
232 errx(1, "%s: inappropriate modifier `%s'",
238 /* Send command to changer. */
239 if (ioctl(changer_fd, CHIOMOVE, &cmd))
240 err(1, "%s: CHIOMOVE", changer_name);
245 fprintf(stderr, "usage: %s %s "
246 "<from ET> <from EU> <to ET> <to EU> [inv]\n", __progname, cname);
251 do_exchange(const char *cname, int argc, char **argv)
253 struct changer_exchange cmd;
257 * On an exchange command, we expect the following:
259 * <src ET> <src EU> <dst1 ET> <dst1 EU> [<dst2 ET> <dst2 EU>] [inv1] [inv2]
261 * where ET == element type and EU == element unit.
267 warnx("%s: too few arguments", cname);
269 } else if (argc > 8) {
270 warnx("%s: too many arguments", cname);
273 memset(&cmd, 0, sizeof(cmd));
276 cmd.ce_srctype = parse_element_type(*argv);
279 /* Check for voltag virtual type */
280 if (CHET_VT == cmd.ce_srctype) {
281 find_element(*argv, &cmd.ce_srctype, &cmd.ce_srcunit);
284 cmd.ce_srcunit = parse_element_unit(*argv);
289 cmd.ce_fdsttype = parse_element_type(*argv);
292 /* Check for voltag virtual type */
293 if (CHET_VT == cmd.ce_fdsttype) {
294 find_element(*argv, &cmd.ce_fdsttype, &cmd.ce_fdstunit);
297 cmd.ce_fdstunit = parse_element_unit(*argv);
302 * If the next token is a special word or there are no more
303 * arguments, then this is a case of simple exchange.
306 if ((argc == 0) || is_special(*argv)) {
307 cmd.ce_sdsttype = cmd.ce_srctype;
308 cmd.ce_sdstunit = cmd.ce_srcunit;
313 cmd.ce_sdsttype = parse_element_type(*argv);
316 if (CHET_VT == cmd.ce_sdsttype)
317 errx(1,"%s %s: voltag only makes sense as an element source",
321 cmd.ce_sdstunit = parse_element_unit(*argv);
325 /* Deal with optional command modifiers. */
327 val = parse_special(*argv);
331 cmd.ce_flags |= CE_INVERT1;
335 cmd.ce_flags |= CE_INVERT2;
339 errx(1, "%s: inappropriate modifier `%s'",
345 /* Send command to changer. */
346 if (ioctl(changer_fd, CHIOEXCHANGE, &cmd))
347 err(1, "%s: CHIOEXCHANGE", changer_name);
353 "usage: %s %s <src ET> <src EU> <dst1 ET> <dst1 EU>\n"
354 " [<dst2 ET> <dst2 EU>] [inv1] [inv2]\n",
360 do_position(const char *cname, int argc, char **argv)
362 struct changer_position cmd;
366 * On a position command, we expect the following:
368 * <to ET> <to EU> [inv]
370 * where ET == element type and EU == element unit.
376 warnx("%s: too few arguments", cname);
378 } else if (argc > 3) {
379 warnx("%s: too many arguments", cname);
382 memset(&cmd, 0, sizeof(cmd));
385 cmd.cp_type = parse_element_type(*argv);
389 cmd.cp_unit = parse_element_unit(*argv);
392 /* Deal with optional command modifier. */
394 val = parse_special(*argv);
397 cmd.cp_flags |= CP_INVERT;
401 errx(1, "%s: inappropriate modifier `%s'",
407 /* Send command to changer. */
408 if (ioctl(changer_fd, CHIOPOSITION, &cmd))
409 err(1, "%s: CHIOPOSITION", changer_name);
414 fprintf(stderr, "usage: %s %s <to ET> <to EU> [inv]\n",
421 do_params(const char *cname, int argc, char **argv)
423 struct changer_params data;
426 /* No arguments to this command. */
431 warnx("%s: no arguments expected", cname);
435 /* Get params from changer and display them. */
436 memset(&data, 0, sizeof(data));
437 if (ioctl(changer_fd, CHIOGPARAMS, &data))
438 err(1, "%s: CHIOGPARAMS", changer_name);
440 printf("%s: %d slot%s, %d drive%s, %d picker%s",
442 data.cp_nslots, (data.cp_nslots > 1) ? "s" : "",
443 data.cp_ndrives, (data.cp_ndrives > 1) ? "s" : "",
444 data.cp_npickers, (data.cp_npickers > 1) ? "s" : "");
445 if (data.cp_nportals)
446 printf(", %d portal%s", data.cp_nportals,
447 (data.cp_nportals > 1) ? "s" : "");
449 /* Get current picker from changer and display it. */
450 if (ioctl(changer_fd, CHIOGPICKER, &picker))
451 err(1, "%s: CHIOGPICKER", changer_name);
453 printf("\n%s: current picker: %d\n", changer_name, picker);
458 fprintf(stderr, "usage: %s %s\n", __progname, cname);
464 do_getpicker(const char *cname, int argc, char **argv)
468 /* No arguments to this command. */
473 warnx("%s: no arguments expected", cname);
477 /* Get current picker from changer and display it. */
478 if (ioctl(changer_fd, CHIOGPICKER, &picker))
479 err(1, "%s: CHIOGPICKER", changer_name);
481 printf("%s: current picker: %d\n", changer_name, picker);
486 fprintf(stderr, "usage: %s %s\n", __progname, cname);
491 do_setpicker(const char *cname, int argc, char **argv)
498 warnx("%s: too few arguments", cname);
500 } else if (argc > 1) {
501 warnx("%s: too many arguments", cname);
505 picker = parse_element_unit(*argv);
507 /* Set the changer picker. */
508 if (ioctl(changer_fd, CHIOSPICKER, &picker))
509 err(1, "%s: CHIOSPICKER", changer_name);
514 fprintf(stderr, "usage: %s %s <picker>\n", __progname, cname);
519 do_status(const char *cname, int argc, char **argv)
521 struct changer_params cp;
522 struct changer_element_status_request cesr;
523 int i, count, base, chet, schet, echet;
524 const char *description;
537 optind = optreset = 1;
538 while ((c = getopt(argc, argv, "vVsSbaI")) != -1) {
559 pvoltag = avoltag = source = sense = scsi = intaddr = 1;
562 warnx("%s: bad option", cname);
571 * On a status command, we expect the following:
573 * [<ET> [<start> [<end>] ] ]
575 * where ET == element type, start == first element to report,
576 * end == number of elements to report
578 * If we get no arguments, we get the status of all
579 * known element types.
582 warnx("%s: too many arguments", cname);
587 * Get params from changer. Specifically, we need the element
590 if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
591 err(1, "%s: CHIOGPARAMS", changer_name);
594 schet = echet = parse_element_type(argv[0]);
600 base = atol(argv[1]);
604 count = atol(argv[2]) - base + 1;
606 if (base < 0 || count < 0)
607 errx(1, "bad arguments");
609 for (chet = schet; chet <= echet; ++chet) {
613 count = cp.cp_npickers;
614 else if (count > cp.cp_npickers)
615 errx(1, "not that many pickers in device");
616 description = "picker";
621 count = cp.cp_nslots;
622 else if (count > cp.cp_nslots)
623 errx(1, "not that many slots in device");
624 description = "slot";
629 count = cp.cp_nportals;
630 else if (count > cp.cp_nportals)
631 errx(1, "not that many portals in device");
632 description = "portal";
637 count = cp.cp_ndrives;
638 else if (count > cp.cp_ndrives)
639 errx(1, "not that many drives in device");
640 description = "drive";
644 /* To appease gcc -Wuninitialized. */
653 printf("%s: no %s elements\n",
654 changer_name, description);
659 bzero(&cesr, sizeof(cesr));
660 cesr.cesr_element_type = chet;
661 cesr.cesr_element_base = base;
662 cesr.cesr_element_count = count;
663 /* Allocate storage for the status structures. */
664 cesr.cesr_element_status =
665 (struct changer_element_status *)
666 calloc((size_t)count, sizeof(struct changer_element_status));
668 if (!cesr.cesr_element_status)
669 errx(1, "can't allocate status storage");
671 if (avoltag || pvoltag)
672 cesr.cesr_flags |= CESR_VOLTAGS;
674 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr)) {
675 free(cesr.cesr_element_status);
676 err(1, "%s: CHIOGSTATUS", changer_name);
679 /* Dump the status for each reported element. */
680 for (i = 0; i < count; ++i) {
681 struct changer_element_status *ces =
682 &(cesr.cesr_element_status[i]);
683 printf("%s %d: %s", description, ces->ces_addr,
684 bits_to_string(ces->ces_flags,
687 printf(" sense: <0x%02x/0x%02x>",
691 printf(" voltag: <%s:%d>",
692 ces->ces_pvoltag.cv_volid,
693 ces->ces_pvoltag.cv_serial);
695 printf(" avoltag: <%s:%d>",
696 ces->ces_avoltag.cv_volid,
697 ces->ces_avoltag.cv_serial);
699 if (ces->ces_flags & CES_SOURCE_VALID)
700 printf(" source: <%s %d>",
702 ces->ces_source_type),
703 ces->ces_source_addr);
705 printf(" source: <>");
708 printf(" intaddr: <%d>", ces->ces_int_addr);
711 if (ces->ces_flags & CES_SCSIID_VALID)
712 printf("%d", ces->ces_scsi_id);
716 if (ces->ces_flags & CES_LUN_VALID)
717 printf("%d", ces->ces_scsi_lun);
725 free(cesr.cesr_element_status);
732 fprintf(stderr, "usage: %s %s [-vVsSbaA] [<element type> [<start-addr> [<end-addr>] ] ]\n",
738 do_ielem(const char *cname, int argc, char **argv)
743 timeout = atol(argv[1]);
744 } else if (argc > 1) {
745 warnx("%s: too many arguments", cname);
749 if (ioctl(changer_fd, CHIOIELEM, &timeout))
750 err(1, "%s: CHIOIELEM", changer_name);
755 fprintf(stderr, "usage: %s %s [<timeout>]\n",
761 do_voltag(const char *cname, int argc, char **argv)
767 struct changer_set_voltag_request csvr;
769 bzero(&csvr, sizeof(csvr));
771 optind = optreset = 1;
772 while ((c = getopt(argc, argv, "fca")) != -1) {
784 warnx("%s: bad option", cname);
793 warnx("%s: missing element specification", cname);
797 csvr.csvr_type = parse_element_type(argv[0]);
798 csvr.csvr_addr = atol(argv[1]);
801 if (argc < 3 || argc > 4) {
802 warnx("%s: missing argument", cname);
807 csvr.csvr_flags = CSVR_MODE_REPLACE;
809 csvr.csvr_flags = CSVR_MODE_SET;
811 if (strlen(argv[2]) > sizeof(csvr.csvr_voltag.cv_volid)) {
812 warnx("%s: volume label too long", cname);
816 strlcpy((char *)csvr.csvr_voltag.cv_volid, argv[2],
817 sizeof(csvr.csvr_voltag.cv_volid));
820 csvr.csvr_voltag.cv_serial = atol(argv[3]);
824 warnx("%s: unexpected argument", cname);
827 csvr.csvr_flags = CSVR_MODE_CLEAR;
831 csvr.csvr_flags |= CSVR_ALTERNATE;
834 if (ioctl(changer_fd, CHIOSETVOLTAG, &csvr))
835 err(1, "%s: CHIOSETVOLTAG", changer_name);
839 fprintf(stderr, "usage: %s %s [-fca] <element> [<voltag> [<vsn>] ]\n",
845 parse_element_type(char *cp)
849 for (i = 0; elements[i].et_name != NULL; ++i)
850 if (strcmp(elements[i].et_name, cp) == 0)
851 return (elements[i].et_type);
853 errx(1, "invalid element type `%s'", cp);
858 element_type_name(int et)
862 for (i = 0; elements[i].et_name != NULL; i++)
863 if (elements[i].et_type == et)
864 return elements[i].et_name;
870 parse_element_unit(char *cp)
875 i = (int)strtol(cp, &p, 10);
876 if ((i < 0) || (*p != '\0'))
877 errx(1, "invalid unit number `%s'", cp);
883 parse_special(char *cp)
887 val = is_special(cp);
891 errx(1, "invalid modifier `%s'", cp);
900 for (i = 0; specials[i].sw_name != NULL; ++i)
901 if (strcmp(specials[i].sw_name, cp) == 0)
902 return (specials[i].sw_value);
908 bits_to_string(ces_status_flags v, const char *cp)
912 static char buf[128];
915 memset(buf, 0, sizeof(buf));
917 for (sep = '<'; (f = *cp++) != 0; cp = np) {
918 for (np = cp; *np >= ' ';)
920 if ((v & (1 << (f - 1))) == 0)
922 snprintf(bp, sizeof(buf) - (bp - &buf[0]),
923 "%c%.*s", sep, (int)(long)(np - cp), cp);
935 * Given an element reference, ask the changer/picker to move that
936 * element back to its source slot.
939 do_return(const char *cname, int argc, char **argv)
941 struct changer_element_status *ces;
942 struct changer_move cmd;
943 u_int16_t type, element;
948 warnx("%s: too few arguments", cname);
950 } else if (argc > 3) {
951 warnx("%s: too many arguments", cname);
955 type = parse_element_type(*argv);
958 /* Handle voltag virtual Changer Element Type */
959 if (CHET_VT == type) {
960 find_element(*argv, &type, &element);
962 element = parse_element_unit(*argv);
967 ces = get_element_status((unsigned int)type, (unsigned int)element);
970 errx(1, "%s: null element status pointer", cname);
972 if (!(ces->ces_flags & CES_SOURCE_VALID))
973 errx(1, "%s: no source information", cname);
975 memset(&cmd, 0, sizeof(cmd));
977 cmd.cm_fromtype = type;
978 cmd.cm_fromunit = element;
979 cmd.cm_totype = ces->ces_source_type;
980 cmd.cm_tounit = ces->ces_source_addr;
982 if (ioctl(changer_fd, CHIOMOVE, &cmd) == -1)
983 err(1, "%s: CHIOMOVE", changer_name);
989 fprintf(stderr, "usage: %s %s "
990 "<from ET> <from EU>\n", __progname, cname);
995 * get_element_status()
997 * return a *cesr for the specified changer element. This
998 * routing will malloc()/calloc() the memory. The caller
999 * should free() it when done.
1001 static struct changer_element_status *
1002 get_element_status(unsigned int type, unsigned int element)
1004 struct changer_element_status_request cesr;
1005 struct changer_element_status *ces;
1007 ces = (struct changer_element_status *)
1008 calloc((size_t)1, sizeof(struct changer_element_status));
1011 errx(1, "can't allocate status storage");
1013 memset(&cesr, 0, sizeof(cesr));
1015 cesr.cesr_element_type = (u_int16_t)type;
1016 cesr.cesr_element_base = (u_int16_t)element;
1017 cesr.cesr_element_count = 1; /* Only this one element */
1018 cesr.cesr_flags |= CESR_VOLTAGS; /* Grab voltags as well */
1019 cesr.cesr_element_status = ces;
1021 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1023 err(1, "%s: CHIOGSTATUS", changer_name);
1034 * Given a <voltag> find the chager element and unit, or exit
1035 * with an error if it isn't found. We grab the changer status
1036 * and iterate until we find a match, or crap out.
1039 find_element(char *voltag, u_int16_t *et, u_int16_t *eu)
1041 struct changer_params cp;
1042 struct changer_element_status_request cesr = { .cesr_flags = 0 };
1043 struct changer_element_status *ch_ces, *ces;
1045 size_t elem, total_elem;
1048 * Get the changer parameters, we're interested in the counts
1049 * for all types of elements to perform our search.
1051 if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
1052 err(1, "%s: CHIOGPARAMS", changer_name);
1054 /* Allocate some memory for the results */
1055 total_elem = (cp.cp_nslots + cp.cp_ndrives
1056 + cp.cp_npickers + cp.cp_nportals);
1058 ch_ces = (struct changer_element_status *)
1059 calloc(total_elem, sizeof(struct changer_element_status));
1062 errx(1, "can't allocate status storage");
1066 /* Read in the changer slots */
1067 if (cp.cp_nslots > 0) {
1068 cesr.cesr_element_type = CHET_ST;
1069 cesr.cesr_element_base = 0;
1070 cesr.cesr_element_count = cp.cp_nslots;
1071 cesr.cesr_flags |= CESR_VOLTAGS;
1072 cesr.cesr_element_status = ces;
1074 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1076 err(1, "%s: CHIOGSTATUS", changer_name);
1078 ces += cp.cp_nslots;
1081 /* Read in the drive information */
1082 if (cp.cp_ndrives > 0 ) {
1084 memset(&cesr, 0, sizeof(cesr));
1085 cesr.cesr_element_type = CHET_DT;
1086 cesr.cesr_element_base = 0;
1087 cesr.cesr_element_count = cp.cp_ndrives;
1088 cesr.cesr_flags |= CESR_VOLTAGS;
1089 cesr.cesr_element_status = ces;
1091 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1093 err(1, "%s: CHIOGSTATUS", changer_name);
1095 ces += cp.cp_ndrives;
1098 /* Read in the portal information */
1099 if (cp.cp_nportals > 0 ) {
1100 memset(&cesr, 0, sizeof(cesr));
1101 cesr.cesr_element_type = CHET_IE;
1102 cesr.cesr_element_base = 0;
1103 cesr.cesr_element_count = cp.cp_nportals;
1104 cesr.cesr_flags |= CESR_VOLTAGS;
1105 cesr.cesr_element_status = ces;
1107 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1109 err(1, "%s: CHIOGSTATUS", changer_name);
1111 ces += cp.cp_nportals;
1114 /* Read in the picker information */
1115 if (cp.cp_npickers > 0) {
1116 memset(&cesr, 0, sizeof(cesr));
1117 cesr.cesr_element_type = CHET_MT;
1118 cesr.cesr_element_base = 0;
1119 cesr.cesr_element_count = cp.cp_npickers;
1120 cesr.cesr_flags |= CESR_VOLTAGS;
1121 cesr.cesr_element_status = ces;
1123 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1125 err(1, "%s: CHIOGSTATUS", changer_name);
1130 * Now search the list the specified <voltag>
1132 for (elem = 0; elem <= total_elem; ++elem) {
1134 ces = &ch_ces[elem];
1136 /* Make sure we have a tape in this element */
1137 if ((ces->ces_flags & (CES_STATUS_ACCESS|CES_STATUS_FULL))
1138 != (CES_STATUS_ACCESS|CES_STATUS_FULL))
1141 /* Check to see if it is our target */
1142 if (strcasecmp(voltag,
1143 (const char *)ces->ces_pvoltag.cv_volid) == 0) {
1144 *et = ces->ces_type;
1145 *eu = ces->ces_addr;
1151 errx(1, "%s: unable to locate voltag: %s", changer_name,
1161 /* Simple enough... */
1168 fprintf(stderr, "usage: %s [-f changer] command [-<flags>] "
1169 "arg1 arg2 [arg3 [...]]\n", __progname);