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 $
35 * $DragonFly: src/bin/chio/chio.c,v 1.5 2004/08/25 01:13:05 dillon Exp $
38 * Additional Copyright (c) 1997, by Matthew Jacob, for NASA/Ames Research Ctr.
39 * Addidional Copyright (c) 2000, by C. Stephen Gunn, Waterspout Communications
43 #include <sys/param.h>
53 #include "pathnames.h"
55 extern char *__progname; /* from crt0.o */
57 static void usage (void);
58 static void cleanup (void);
59 static int parse_element_type (char *);
60 static int parse_element_unit (char *);
61 static const char * element_type_name (int et);
62 static int parse_special (char *);
63 static int is_special (char *);
64 static const char *bits_to_string (ces_status_flags, const char *);
66 static void find_element (char *, u_int16_t *, u_int16_t *);
67 static struct changer_element_status *get_element_status
68 (unsigned int, unsigned int);
70 static int do_move (const char *, int, char **);
71 static int do_exchange (const char *, int, char **);
72 static int do_position (const char *, int, char **);
73 static int do_params (const char *, int, char **);
74 static int do_getpicker (const char *, int, char **);
75 static int do_setpicker (const char *, int, char **);
76 static int do_status (const char *, int, char **);
77 static int do_ielem (const char *, int, char **);
78 static int do_return (const char *, int, char **);
79 static int do_voltag (const char *, int, char **);
82 #define CHET_VT 10 /* Completely Arbitrary */
85 /* Valid changer element types. */
86 const struct element_type elements[] = {
88 { "picker", CHET_MT },
89 { "portal", CHET_IE },
91 { "voltag", CHET_VT }, /* Select tapes by barcode */
96 const struct changer_command commands[] = {
97 { "exchange", do_exchange },
98 { "getpicker", do_getpicker },
99 { "ielem", do_ielem },
101 { "params", do_params },
102 { "position", do_position },
103 { "setpicker", do_setpicker },
104 { "status", do_status },
105 { "return", do_return },
106 { "voltag", do_voltag },
110 /* Valid special words. */
111 const struct special_word specials[] = {
112 { "inv", SW_INVERT },
113 { "inv1", SW_INVERT1 },
114 { "inv2", SW_INVERT2 },
118 static int changer_fd;
119 static const char *changer_name;
122 main(int argc, char **argv)
126 while ((ch = getopt(argc, argv, "f:")) != -1) {
129 changer_name = optarg;
141 /* Get the default changer if not already specified. */
142 if (changer_name == NULL)
143 if ((changer_name = getenv(CHANGER_ENV_VAR)) == NULL)
144 changer_name = _PATH_CH;
146 /* Open the changer device. */
147 if ((changer_fd = open(changer_name, O_RDWR, 0600)) == -1)
148 err(1, "%s: open", changer_name);
150 /* Register cleanup function. */
152 err(1, "can't register cleanup function");
154 /* Find the specified command. */
155 for (i = 0; commands[i].cc_name != NULL; ++i)
156 if (strcmp(*argv, commands[i].cc_name) == 0)
158 if (commands[i].cc_name == NULL) {
159 /* look for abbreviation */
160 for (i = 0; commands[i].cc_name != NULL; ++i)
161 if (strncmp(*argv, commands[i].cc_name,
166 if (commands[i].cc_name == NULL)
167 errx(1, "unknown command: %s", *argv);
169 exit ((*commands[i].cc_handler)(commands[i].cc_name, argc, argv));
174 do_move(const char *cname, int argc, char **argv)
176 struct changer_move cmd;
180 * On a move command, we expect the following:
182 * <from ET> <from EU> <to ET> <to EU> [inv]
184 * where ET == element type and EU == element unit.
190 warnx("%s: too few arguments", cname);
192 } else if (argc > 5) {
193 warnx("%s: too many arguments", cname);
196 memset(&cmd, 0, sizeof(cmd));
199 cmd.cm_fromtype = parse_element_type(*argv);
202 /* Check for voltag virtual type */
203 if (CHET_VT == cmd.cm_fromtype) {
204 find_element(*argv, &cmd.cm_fromtype, &cmd.cm_fromunit);
207 cmd.cm_fromunit = parse_element_unit(*argv);
212 cmd.cm_totype = parse_element_type(*argv);
215 /* Check for voltag virtual type, and report error */
216 if (CHET_VT == cmd.cm_totype)
217 errx(1,"%s: voltag only makes sense as an element source",
221 cmd.cm_tounit = parse_element_unit(*argv);
224 /* Deal with optional command modifier. */
226 val = parse_special(*argv);
229 cmd.cm_flags |= CM_INVERT;
233 errx(1, "%s: inappropriate modifier `%s'",
239 /* Send command to changer. */
240 if (ioctl(changer_fd, CHIOMOVE, &cmd))
241 err(1, "%s: CHIOMOVE", changer_name);
246 fprintf(stderr, "usage: %s %s "
247 "<from ET> <from EU> <to ET> <to EU> [inv]\n", __progname, cname);
252 do_exchange(const char *cname, int argc, char **argv)
254 struct changer_exchange cmd;
258 * On an exchange command, we expect the following:
260 * <src ET> <src EU> <dst1 ET> <dst1 EU> [<dst2 ET> <dst2 EU>] [inv1] [inv2]
262 * where ET == element type and EU == element unit.
268 warnx("%s: too few arguments", cname);
270 } else if (argc > 8) {
271 warnx("%s: too many arguments", cname);
274 memset(&cmd, 0, sizeof(cmd));
277 cmd.ce_srctype = parse_element_type(*argv);
280 /* Check for voltag virtual type */
281 if (CHET_VT == cmd.ce_srctype) {
282 find_element(*argv, &cmd.ce_srctype, &cmd.ce_srcunit);
285 cmd.ce_srcunit = parse_element_unit(*argv);
290 cmd.ce_fdsttype = parse_element_type(*argv);
293 /* Check for voltag virtual type */
294 if (CHET_VT == cmd.ce_fdsttype) {
295 find_element(*argv, &cmd.ce_fdsttype, &cmd.ce_fdstunit);
298 cmd.ce_fdstunit = parse_element_unit(*argv);
303 * If the next token is a special word or there are no more
304 * arguments, then this is a case of simple exchange.
307 if ((argc == 0) || is_special(*argv)) {
308 cmd.ce_sdsttype = cmd.ce_srctype;
309 cmd.ce_sdstunit = cmd.ce_srcunit;
314 cmd.ce_sdsttype = parse_element_type(*argv);
317 if (CHET_VT == cmd.ce_sdsttype)
318 errx(1,"%s %s: voltag only makes sense as an element source",
322 cmd.ce_sdstunit = parse_element_unit(*argv);
326 /* Deal with optional command modifiers. */
328 val = parse_special(*argv);
332 cmd.ce_flags |= CE_INVERT1;
336 cmd.ce_flags |= CE_INVERT2;
340 errx(1, "%s: inappropriate modifier `%s'",
346 /* Send command to changer. */
347 if (ioctl(changer_fd, CHIOEXCHANGE, &cmd))
348 err(1, "%s: CHIOEXCHANGE", changer_name);
354 "usage: %s %s <src ET> <src EU> <dst1 ET> <dst1 EU>\n"
355 " [<dst2 ET> <dst2 EU>] [inv1] [inv2]\n",
361 do_position(const char *cname, int argc, char **argv)
363 struct changer_position cmd;
367 * On a position command, we expect the following:
369 * <to ET> <to EU> [inv]
371 * where ET == element type and EU == element unit.
377 warnx("%s: too few arguments", cname);
379 } else if (argc > 3) {
380 warnx("%s: too many arguments", cname);
383 memset(&cmd, 0, sizeof(cmd));
386 cmd.cp_type = parse_element_type(*argv);
390 cmd.cp_unit = parse_element_unit(*argv);
393 /* Deal with optional command modifier. */
395 val = parse_special(*argv);
398 cmd.cp_flags |= CP_INVERT;
402 errx(1, "%s: inappropriate modifier `%s'",
408 /* Send command to changer. */
409 if (ioctl(changer_fd, CHIOPOSITION, &cmd))
410 err(1, "%s: CHIOPOSITION", changer_name);
415 fprintf(stderr, "usage: %s %s <to ET> <to EU> [inv]\n",
422 do_params(const char *cname, int argc, char **argv)
424 struct changer_params data;
427 /* No arguments to this command. */
432 warnx("%s: no arguments expected", cname);
436 /* Get params from changer and display them. */
437 memset(&data, 0, sizeof(data));
438 if (ioctl(changer_fd, CHIOGPARAMS, &data))
439 err(1, "%s: CHIOGPARAMS", changer_name);
441 printf("%s: %d slot%s, %d drive%s, %d picker%s",
443 data.cp_nslots, (data.cp_nslots > 1) ? "s" : "",
444 data.cp_ndrives, (data.cp_ndrives > 1) ? "s" : "",
445 data.cp_npickers, (data.cp_npickers > 1) ? "s" : "");
446 if (data.cp_nportals)
447 printf(", %d portal%s", data.cp_nportals,
448 (data.cp_nportals > 1) ? "s" : "");
450 /* Get current picker from changer and display it. */
451 if (ioctl(changer_fd, CHIOGPICKER, &picker))
452 err(1, "%s: CHIOGPICKER", changer_name);
454 printf("\n%s: current picker: %d\n", changer_name, picker);
459 fprintf(stderr, "usage: %s %s\n", __progname, cname);
465 do_getpicker(const char *cname, int argc, char **argv)
469 /* No arguments to this command. */
474 warnx("%s: no arguments expected", cname);
478 /* Get current picker from changer and display it. */
479 if (ioctl(changer_fd, CHIOGPICKER, &picker))
480 err(1, "%s: CHIOGPICKER", changer_name);
482 printf("%s: current picker: %d\n", changer_name, picker);
487 fprintf(stderr, "usage: %s %s\n", __progname, cname);
492 do_setpicker(const char *cname, int argc, char **argv)
499 warnx("%s: too few arguments", cname);
501 } else if (argc > 1) {
502 warnx("%s: too many arguments", cname);
506 picker = parse_element_unit(*argv);
508 /* Set the changer picker. */
509 if (ioctl(changer_fd, CHIOSPICKER, &picker))
510 err(1, "%s: CHIOSPICKER", changer_name);
515 fprintf(stderr, "usage: %s %s <picker>\n", __progname, cname);
520 do_status(const char *cname, int argc, char **argv)
522 struct changer_params cp;
523 struct changer_element_status_request cesr;
524 int i, count, base, chet, schet, echet;
525 const char *description;
538 optind = optreset = 1;
539 while ((c = getopt(argc, argv, "vVsSbaI")) != -1) {
560 pvoltag = avoltag = source = sense = scsi = intaddr = 1;
563 warnx("%s: bad option", cname);
572 * On a status command, we expect the following:
574 * [<ET> [<start> [<end>] ] ]
576 * where ET == element type, start == first element to report,
577 * end == number of elements to report
579 * If we get no arguments, we get the status of all
580 * known element types.
583 warnx("%s: too many arguments", cname);
588 * Get params from changer. Specifically, we need the element
591 if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
592 err(1, "%s: CHIOGPARAMS", changer_name);
595 schet = echet = parse_element_type(argv[0]);
601 base = atol(argv[1]);
605 count = atol(argv[2]) - base + 1;
607 if (base < 0 || count < 0)
608 errx(1, "bad arguments");
610 for (chet = schet; chet <= echet; ++chet) {
614 count = cp.cp_npickers;
615 else if (count > cp.cp_npickers)
616 errx(1, "not that many pickers in device");
617 description = "picker";
622 count = cp.cp_nslots;
623 else if (count > cp.cp_nslots)
624 errx(1, "not that many slots in device");
625 description = "slot";
630 count = cp.cp_nportals;
631 else if (count > cp.cp_nportals)
632 errx(1, "not that many portals in device");
633 description = "portal";
638 count = cp.cp_ndrives;
639 else if (count > cp.cp_ndrives)
640 errx(1, "not that many drives in device");
641 description = "drive";
645 /* To appease gcc -Wuninitialized. */
654 printf("%s: no %s elements\n",
655 changer_name, description);
660 bzero(&cesr, sizeof(cesr));
661 cesr.cesr_element_type = chet;
662 cesr.cesr_element_base = base;
663 cesr.cesr_element_count = count;
664 /* Allocate storage for the status structures. */
665 cesr.cesr_element_status =
666 (struct changer_element_status *)
667 calloc((size_t)count, sizeof(struct changer_element_status));
669 if (!cesr.cesr_element_status)
670 errx(1, "can't allocate status storage");
672 if (avoltag || pvoltag)
673 cesr.cesr_flags |= CESR_VOLTAGS;
675 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr)) {
676 free(cesr.cesr_element_status);
677 err(1, "%s: CHIOGSTATUS", changer_name);
680 /* Dump the status for each reported element. */
681 for (i = 0; i < count; ++i) {
682 struct changer_element_status *ces =
683 &(cesr.cesr_element_status[i]);
684 printf("%s %d: %s", description, ces->ces_addr,
685 bits_to_string(ces->ces_flags,
688 printf(" sense: <0x%02x/0x%02x>",
692 printf(" voltag: <%s:%d>",
693 ces->ces_pvoltag.cv_volid,
694 ces->ces_pvoltag.cv_serial);
696 printf(" avoltag: <%s:%d>",
697 ces->ces_avoltag.cv_volid,
698 ces->ces_avoltag.cv_serial);
700 if (ces->ces_flags & CES_SOURCE_VALID)
701 printf(" source: <%s %d>",
703 ces->ces_source_type),
704 ces->ces_source_addr);
706 printf(" source: <>");
709 printf(" intaddr: <%d>", ces->ces_int_addr);
712 if (ces->ces_flags & CES_SCSIID_VALID)
713 printf("%d", ces->ces_scsi_id);
717 if (ces->ces_flags & CES_LUN_VALID)
718 printf("%d", ces->ces_scsi_lun);
726 free(cesr.cesr_element_status);
733 fprintf(stderr, "usage: %s %s [-vVsSbaA] [<element type> [<start-addr> [<end-addr>] ] ]\n",
739 do_ielem(const char *cname, int argc, char **argv)
744 timeout = atol(argv[1]);
745 } else if (argc > 1) {
746 warnx("%s: too many arguments", cname);
750 if (ioctl(changer_fd, CHIOIELEM, &timeout))
751 err(1, "%s: CHIOIELEM", changer_name);
756 fprintf(stderr, "usage: %s %s [<timeout>]\n",
762 do_voltag(const char *cname, int argc, char **argv)
768 struct changer_set_voltag_request csvr;
770 bzero(&csvr, sizeof(csvr));
772 optind = optreset = 1;
773 while ((c = getopt(argc, argv, "fca")) != -1) {
785 warnx("%s: bad option", cname);
794 warnx("%s: missing element specification", cname);
798 csvr.csvr_type = parse_element_type(argv[0]);
799 csvr.csvr_addr = atol(argv[1]);
802 if (argc < 3 || argc > 4) {
803 warnx("%s: missing argument", cname);
808 csvr.csvr_flags = CSVR_MODE_REPLACE;
810 csvr.csvr_flags = CSVR_MODE_SET;
812 if (strlen(argv[2]) > sizeof(csvr.csvr_voltag.cv_volid)) {
813 warnx("%s: volume label too long", cname);
817 strlcpy((char *)csvr.csvr_voltag.cv_volid, argv[2],
818 sizeof(csvr.csvr_voltag.cv_volid));
821 csvr.csvr_voltag.cv_serial = atol(argv[3]);
825 warnx("%s: unexpected argument", cname);
828 csvr.csvr_flags = CSVR_MODE_CLEAR;
832 csvr.csvr_flags |= CSVR_ALTERNATE;
835 if (ioctl(changer_fd, CHIOSETVOLTAG, &csvr))
836 err(1, "%s: CHIOSETVOLTAG", changer_name);
840 fprintf(stderr, "usage: %s %s [-fca] <element> [<voltag> [<vsn>] ]\n",
846 parse_element_type(char *cp)
850 for (i = 0; elements[i].et_name != NULL; ++i)
851 if (strcmp(elements[i].et_name, cp) == 0)
852 return (elements[i].et_type);
854 errx(1, "invalid element type `%s'", cp);
859 element_type_name(int et)
863 for (i = 0; elements[i].et_name != NULL; i++)
864 if (elements[i].et_type == et)
865 return elements[i].et_name;
871 parse_element_unit(char *cp)
876 i = (int)strtol(cp, &p, 10);
877 if ((i < 0) || (*p != '\0'))
878 errx(1, "invalid unit number `%s'", cp);
884 parse_special(char *cp)
888 val = is_special(cp);
892 errx(1, "invalid modifier `%s'", cp);
901 for (i = 0; specials[i].sw_name != NULL; ++i)
902 if (strcmp(specials[i].sw_name, cp) == 0)
903 return (specials[i].sw_value);
909 bits_to_string(ces_status_flags v, const char *cp)
913 static char buf[128];
916 memset(buf, 0, sizeof(buf));
918 for (sep = '<'; (f = *cp++) != 0; cp = np) {
919 for (np = cp; *np >= ' ';)
921 if ((v & (1 << (f - 1))) == 0)
923 snprintf(bp, sizeof(buf) - (bp - &buf[0]),
924 "%c%.*s", sep, (int)(long)(np - cp), cp);
936 * Given an element reference, ask the changer/picker to move that
937 * element back to its source slot.
940 do_return(const char *cname, int argc, char **argv)
942 struct changer_element_status *ces;
943 struct changer_move cmd;
944 u_int16_t type, element;
949 warnx("%s: too few arguments", cname);
951 } else if (argc > 3) {
952 warnx("%s: too many arguments", cname);
956 type = parse_element_type(*argv);
959 /* Handle voltag virtual Changer Element Type */
960 if (CHET_VT == type) {
961 find_element(*argv, &type, &element);
963 element = parse_element_unit(*argv);
968 ces = get_element_status((unsigned int)type, (unsigned int)element);
971 errx(1, "%s: null element status pointer", cname);
973 if (!(ces->ces_flags & CES_SOURCE_VALID))
974 errx(1, "%s: no source information", cname);
976 memset(&cmd, 0, sizeof(cmd));
978 cmd.cm_fromtype = type;
979 cmd.cm_fromunit = element;
980 cmd.cm_totype = ces->ces_source_type;
981 cmd.cm_tounit = ces->ces_source_addr;
983 if (ioctl(changer_fd, CHIOMOVE, &cmd) == -1)
984 err(1, "%s: CHIOMOVE", changer_name);
990 fprintf(stderr, "usage: %s %s "
991 "<from ET> <from EU>\n", __progname, cname);
996 * get_element_status()
998 * return a *cesr for the specified changer element. This
999 * routing will malloc()/calloc() the memory. The caller
1000 * should free() it when done.
1002 static struct changer_element_status *
1003 get_element_status(unsigned int type, unsigned int element)
1005 struct changer_element_status_request cesr;
1006 struct changer_element_status *ces;
1008 ces = (struct changer_element_status *)
1009 calloc((size_t)1, sizeof(struct changer_element_status));
1012 errx(1, "can't allocate status storage");
1014 memset(&cesr, 0, sizeof(cesr));
1016 cesr.cesr_element_type = (u_int16_t)type;
1017 cesr.cesr_element_base = (u_int16_t)element;
1018 cesr.cesr_element_count = 1; /* Only this one element */
1019 cesr.cesr_flags |= CESR_VOLTAGS; /* Grab voltags as well */
1020 cesr.cesr_element_status = ces;
1022 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1024 err(1, "%s: CHIOGSTATUS", changer_name);
1035 * Given a <voltag> find the chager element and unit, or exit
1036 * with an error if it isn't found. We grab the changer status
1037 * and iterate until we find a match, or crap out.
1040 find_element(char *voltag, u_int16_t *et, u_int16_t *eu)
1042 struct changer_params cp;
1043 struct changer_element_status_request cesr;
1044 struct changer_element_status *ch_ces, *ces;
1046 size_t elem, total_elem;
1049 * Get the changer parameters, we're interested in the counts
1050 * for all types of elements to perform our search.
1052 if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
1053 err(1, "%s: CHIOGPARAMS", changer_name);
1055 /* Allocate some memory for the results */
1056 total_elem = (cp.cp_nslots + cp.cp_ndrives
1057 + cp.cp_npickers + cp.cp_nportals);
1059 ch_ces = (struct changer_element_status *)
1060 calloc(total_elem, sizeof(struct changer_element_status));
1063 errx(1, "can't allocate status storage");
1067 /* Read in the changer slots */
1068 if (cp.cp_nslots > 0) {
1069 cesr.cesr_element_type = CHET_ST;
1070 cesr.cesr_element_base = 0;
1071 cesr.cesr_element_count = cp.cp_nslots;
1072 cesr.cesr_flags |= CESR_VOLTAGS;
1073 cesr.cesr_element_status = ces;
1075 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1077 err(1, "%s: CHIOGSTATUS", changer_name);
1079 ces += cp.cp_nslots;
1082 /* Read in the drive information */
1083 if (cp.cp_ndrives > 0 ) {
1085 memset(&cesr, 0, sizeof(cesr));
1086 cesr.cesr_element_type = CHET_DT;
1087 cesr.cesr_element_base = 0;
1088 cesr.cesr_element_count = cp.cp_ndrives;
1089 cesr.cesr_flags |= CESR_VOLTAGS;
1090 cesr.cesr_element_status = ces;
1092 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1094 err(1, "%s: CHIOGSTATUS", changer_name);
1096 ces += cp.cp_ndrives;
1099 /* Read in the portal information */
1100 if (cp.cp_nportals > 0 ) {
1101 memset(&cesr, 0, sizeof(cesr));
1102 cesr.cesr_element_type = CHET_IE;
1103 cesr.cesr_element_base = 0;
1104 cesr.cesr_element_count = cp.cp_nportals;
1105 cesr.cesr_flags |= CESR_VOLTAGS;
1106 cesr.cesr_element_status = ces;
1108 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1110 err(1, "%s: CHIOGSTATUS", changer_name);
1112 ces += cp.cp_nportals;
1115 /* Read in the picker information */
1116 if (cp.cp_npickers > 0) {
1117 memset(&cesr, 0, sizeof(cesr));
1118 cesr.cesr_element_type = CHET_MT;
1119 cesr.cesr_element_base = 0;
1120 cesr.cesr_element_count = cp.cp_npickers;
1121 cesr.cesr_flags |= CESR_VOLTAGS;
1122 cesr.cesr_element_status = ces;
1124 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1126 err(1, "%s: CHIOGSTATUS", changer_name);
1131 * Now search the list the specified <voltag>
1133 for (elem = 0; elem <= total_elem; ++elem) {
1135 ces = &ch_ces[elem];
1137 /* Make sure we have a tape in this element */
1138 if ((ces->ces_flags & (CES_STATUS_ACCESS|CES_STATUS_FULL))
1139 != (CES_STATUS_ACCESS|CES_STATUS_FULL))
1142 /* Check to see if it is our target */
1143 if (strcasecmp(voltag,
1144 (const char *)ces->ces_pvoltag.cv_volid) == 0) {
1145 *et = ces->ces_type;
1146 *eu = ces->ces_addr;
1152 errx(1, "%s: unable to locate voltag: %s", changer_name,
1162 /* Simple enough... */
1169 fprintf(stderr, "usage: %s [-f changer] command [-<flags>] "
1170 "arg1 arg2 [arg3 [...]]\n", __progname);