1 /* $NetBSD: chio.c,v 1.6 1998/01/04 23:53:58 thorpej Exp $ */
3 * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgements:
16 * This product includes software developed by Jason R. Thorpe
17 * for And Communications, http://www.and.com/
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#) Copyright (c) 1996 Jason R. Thorpe. All rights reserved.
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.3 2003/09/21 04:17:25 drhodus 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
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 const struct element_type elements[] = {
87 { "picker", CHET_MT },
88 { "portal", CHET_IE },
90 { "voltag", CHET_VT }, /* Select tapes by barcode */
95 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 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;
127 while ((ch = getopt(argc, argv, "f:")) != -1) {
130 changer_name = optarg;
143 /* Get the default changer if not already specified. */
144 if (changer_name == NULL)
145 if ((changer_name = getenv(CHANGER_ENV_VAR)) == NULL)
146 changer_name = _PATH_CH;
148 /* Open the changer device. */
149 if ((changer_fd = open(changer_name, O_RDWR, 0600)) == -1)
150 err(1, "%s: open", changer_name);
152 /* Register cleanup function. */
154 err(1, "can't register cleanup function");
156 /* Find the specified command. */
157 for (i = 0; commands[i].cc_name != NULL; ++i)
158 if (strcmp(*argv, commands[i].cc_name) == 0)
160 if (commands[i].cc_name == NULL) {
161 /* look for abbreviation */
162 for (i = 0; commands[i].cc_name != NULL; ++i)
163 if (strncmp(*argv, commands[i].cc_name,
168 if (commands[i].cc_name == NULL)
169 errx(1, "unknown command: %s", *argv);
171 exit ((*commands[i].cc_handler)(commands[i].cc_name, argc, argv));
176 do_move(cname, argc, argv)
181 struct changer_move cmd;
185 * On a move command, we expect the following:
187 * <from ET> <from EU> <to ET> <to EU> [inv]
189 * where ET == element type and EU == element unit.
195 warnx("%s: too few arguments", cname);
197 } else if (argc > 5) {
198 warnx("%s: too many arguments", cname);
201 (void) memset(&cmd, 0, sizeof(cmd));
204 cmd.cm_fromtype = parse_element_type(*argv);
207 /* Check for voltag virtual type */
208 if (CHET_VT == cmd.cm_fromtype) {
209 find_element(*argv, &cmd.cm_fromtype, &cmd.cm_fromunit);
212 cmd.cm_fromunit = parse_element_unit(*argv);
217 cmd.cm_totype = parse_element_type(*argv);
220 /* Check for voltag virtual type, and report error */
221 if (CHET_VT == cmd.cm_totype)
222 errx(1,"%s: voltag only makes sense as an element source",
226 cmd.cm_tounit = parse_element_unit(*argv);
229 /* Deal with optional command modifier. */
231 val = parse_special(*argv);
234 cmd.cm_flags |= CM_INVERT;
238 errx(1, "%s: inappropriate modifier `%s'",
244 /* Send command to changer. */
245 if (ioctl(changer_fd, CHIOMOVE, &cmd))
246 err(1, "%s: CHIOMOVE", changer_name);
251 (void) fprintf(stderr, "usage: %s %s "
252 "<from ET> <from EU> <to ET> <to EU> [inv]\n", __progname, cname);
257 do_exchange(cname, argc, argv)
262 struct changer_exchange cmd;
266 * On an exchange command, we expect the following:
268 * <src ET> <src EU> <dst1 ET> <dst1 EU> [<dst2 ET> <dst2 EU>] [inv1] [inv2]
270 * where ET == element type and EU == element unit.
276 warnx("%s: too few arguments", cname);
278 } else if (argc > 8) {
279 warnx("%s: too many arguments", cname);
282 (void) memset(&cmd, 0, sizeof(cmd));
285 cmd.ce_srctype = parse_element_type(*argv);
288 /* Check for voltag virtual type */
289 if (CHET_VT == cmd.ce_srctype) {
290 find_element(*argv, &cmd.ce_srctype, &cmd.ce_srcunit);
293 cmd.ce_srcunit = parse_element_unit(*argv);
298 cmd.ce_fdsttype = parse_element_type(*argv);
301 /* Check for voltag virtual type */
302 if (CHET_VT == cmd.ce_fdsttype) {
303 find_element(*argv, &cmd.ce_fdsttype, &cmd.ce_fdstunit);
306 cmd.ce_fdstunit = parse_element_unit(*argv);
311 * If the next token is a special word or there are no more
312 * arguments, then this is a case of simple exchange.
315 if ((argc == 0) || is_special(*argv)) {
316 cmd.ce_sdsttype = cmd.ce_srctype;
317 cmd.ce_sdstunit = cmd.ce_srcunit;
322 cmd.ce_sdsttype = parse_element_type(*argv);
325 if (CHET_VT == cmd.ce_sdsttype)
326 errx(1,"%s %s: voltag only makes sense as an element source",
330 cmd.ce_sdstunit = parse_element_unit(*argv);
334 /* Deal with optional command modifiers. */
336 val = parse_special(*argv);
340 cmd.ce_flags |= CE_INVERT1;
344 cmd.ce_flags |= CE_INVERT2;
348 errx(1, "%s: inappropriate modifier `%s'",
354 /* Send command to changer. */
355 if (ioctl(changer_fd, CHIOEXCHANGE, &cmd))
356 err(1, "%s: CHIOEXCHANGE", changer_name);
361 (void) fprintf(stderr,
362 "usage: %s %s <src ET> <src EU> <dst1 ET> <dst1 EU>\n"
363 " [<dst2 ET> <dst2 EU>] [inv1] [inv2]\n",
369 do_position(cname, argc, argv)
374 struct changer_position cmd;
378 * On a position command, we expect the following:
380 * <to ET> <to EU> [inv]
382 * where ET == element type and EU == element unit.
388 warnx("%s: too few arguments", cname);
390 } else if (argc > 3) {
391 warnx("%s: too many arguments", cname);
394 (void) memset(&cmd, 0, sizeof(cmd));
397 cmd.cp_type = parse_element_type(*argv);
401 cmd.cp_unit = parse_element_unit(*argv);
404 /* Deal with optional command modifier. */
406 val = parse_special(*argv);
409 cmd.cp_flags |= CP_INVERT;
413 errx(1, "%s: inappropriate modifier `%s'",
419 /* Send command to changer. */
420 if (ioctl(changer_fd, CHIOPOSITION, &cmd))
421 err(1, "%s: CHIOPOSITION", changer_name);
426 (void) fprintf(stderr, "usage: %s %s <to ET> <to EU> [inv]\n",
433 do_params(cname, argc, argv)
438 struct changer_params data;
441 /* No arguments to this command. */
446 warnx("%s: no arguments expected", cname);
450 /* Get params from changer and display them. */
451 (void) memset(&data, 0, sizeof(data));
452 if (ioctl(changer_fd, CHIOGPARAMS, &data))
453 err(1, "%s: CHIOGPARAMS", changer_name);
455 (void) printf("%s: %d slot%s, %d drive%s, %d picker%s",
457 data.cp_nslots, (data.cp_nslots > 1) ? "s" : "",
458 data.cp_ndrives, (data.cp_ndrives > 1) ? "s" : "",
459 data.cp_npickers, (data.cp_npickers > 1) ? "s" : "");
460 if (data.cp_nportals)
461 (void) printf(", %d portal%s", data.cp_nportals,
462 (data.cp_nportals > 1) ? "s" : "");
464 /* Get current picker from changer and display it. */
465 if (ioctl(changer_fd, CHIOGPICKER, &picker))
466 err(1, "%s: CHIOGPICKER", changer_name);
468 (void) printf("\n%s: current picker: %d\n", changer_name, picker);
473 (void) fprintf(stderr, "usage: %s %s\n", __progname, cname);
479 do_getpicker(cname, argc, argv)
486 /* No arguments to this command. */
491 warnx("%s: no arguments expected", cname);
495 /* Get current picker from changer and display it. */
496 if (ioctl(changer_fd, CHIOGPICKER, &picker))
497 err(1, "%s: CHIOGPICKER", changer_name);
499 (void) printf("%s: current picker: %d\n", changer_name, picker);
504 (void) fprintf(stderr, "usage: %s %s\n", __progname, cname);
509 do_setpicker(cname, argc, argv)
519 warnx("%s: too few arguments", cname);
521 } else if (argc > 1) {
522 warnx("%s: too many arguments", cname);
526 picker = parse_element_unit(*argv);
528 /* Set the changer picker. */
529 if (ioctl(changer_fd, CHIOSPICKER, &picker))
530 err(1, "%s: CHIOSPICKER", changer_name);
535 (void) fprintf(stderr, "usage: %s %s <picker>\n", __progname, cname);
540 do_status(cname, argc, argv)
545 struct changer_params cp;
546 struct changer_element_status_request cesr;
547 int i, count, base, chet, schet, echet;
548 const char *description;
561 optind = optreset = 1;
562 while ((c = getopt(argc, argv, "vVsSbaI")) != -1) {
583 pvoltag = avoltag = source = sense = scsi = intaddr = 1;
586 warnx("%s: bad option", cname);
595 * On a status command, we expect the following:
597 * [<ET> [<start> [<end>] ] ]
599 * where ET == element type, start == first element to report,
600 * end == number of elements to report
602 * If we get no arguments, we get the status of all
603 * known element types.
606 warnx("%s: too many arguments", cname);
611 * Get params from changer. Specifically, we need the element
614 if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
615 err(1, "%s: CHIOGPARAMS", changer_name);
618 schet = echet = parse_element_type(argv[0]);
624 base = atol(argv[1]);
628 count = atol(argv[2]) - base + 1;
630 if (base < 0 || count < 0)
631 errx(1, "bad arguments");
633 for (chet = schet; chet <= echet; ++chet) {
637 count = cp.cp_npickers;
638 else if (count > cp.cp_npickers)
639 errx(1, "not that many pickers in device");
640 description = "picker";
645 count = cp.cp_nslots;
646 else if (count > cp.cp_nslots)
647 errx(1, "not that many slots in device");
648 description = "slot";
653 count = cp.cp_nportals;
654 else if (count > cp.cp_nportals)
655 errx(1, "not that many portals in device");
656 description = "portal";
661 count = cp.cp_ndrives;
662 else if (count > cp.cp_ndrives)
663 errx(1, "not that many drives in device");
664 description = "drive";
668 /* To appease gcc -Wuninitialized. */
677 printf("%s: no %s elements\n",
678 changer_name, description);
683 bzero(&cesr, sizeof(cesr));
684 cesr.cesr_element_type = chet;
685 cesr.cesr_element_base = base;
686 cesr.cesr_element_count = count;
687 /* Allocate storage for the status structures. */
688 cesr.cesr_element_status =
689 (struct changer_element_status *)
690 calloc((size_t)count, sizeof(struct changer_element_status));
692 if (!cesr.cesr_element_status)
693 errx(1, "can't allocate status storage");
695 if (avoltag || pvoltag)
696 cesr.cesr_flags |= CESR_VOLTAGS;
698 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr)) {
699 free(cesr.cesr_element_status);
700 err(1, "%s: CHIOGSTATUS", changer_name);
703 /* Dump the status for each reported element. */
704 for (i = 0; i < count; ++i) {
705 struct changer_element_status *ces =
706 &(cesr.cesr_element_status[i]);
707 printf("%s %d: %s", description, ces->ces_addr,
708 bits_to_string(ces->ces_flags,
711 printf(" sense: <0x%02x/0x%02x>",
715 printf(" voltag: <%s:%d>",
716 ces->ces_pvoltag.cv_volid,
717 ces->ces_pvoltag.cv_serial);
719 printf(" avoltag: <%s:%d>",
720 ces->ces_avoltag.cv_volid,
721 ces->ces_avoltag.cv_serial);
723 if (ces->ces_flags & CES_SOURCE_VALID)
724 printf(" source: <%s %d>",
726 ces->ces_source_type),
727 ces->ces_source_addr);
729 printf(" source: <>");
732 printf(" intaddr: <%d>", ces->ces_int_addr);
735 if (ces->ces_flags & CES_SCSIID_VALID)
736 printf("%d", ces->ces_scsi_id);
740 if (ces->ces_flags & CES_LUN_VALID)
741 printf("%d", ces->ces_scsi_lun);
749 free(cesr.cesr_element_status);
756 (void) fprintf(stderr, "usage: %s %s [-vVsSbaA] [<element type> [<start-addr> [<end-addr>] ] ]\n",
762 do_ielem(cname, argc, argv)
770 timeout = atol(argv[1]);
771 } else if (argc > 1) {
772 warnx("%s: too many arguments", cname);
776 if (ioctl(changer_fd, CHIOIELEM, &timeout))
777 err(1, "%s: CHIOIELEM", changer_name);
782 (void) fprintf(stderr, "usage: %s %s [<timeout>]\n",
788 do_voltag(cname, argc, argv)
797 struct changer_set_voltag_request csvr;
799 bzero(&csvr, sizeof(csvr));
801 optind = optreset = 1;
802 while ((c = getopt(argc, argv, "fca")) != -1) {
814 warnx("%s: bad option", cname);
823 warnx("%s: missing element specification", cname);
827 csvr.csvr_type = parse_element_type(argv[0]);
828 csvr.csvr_addr = atol(argv[1]);
831 if (argc < 3 || argc > 4) {
832 warnx("%s: missing argument", cname);
837 csvr.csvr_flags = CSVR_MODE_REPLACE;
839 csvr.csvr_flags = CSVR_MODE_SET;
841 if (strlen(argv[2]) > sizeof(csvr.csvr_voltag.cv_volid)) {
842 warnx("%s: volume label too long", cname);
846 strlcpy((char *)csvr.csvr_voltag.cv_volid, argv[2],
847 sizeof(csvr.csvr_voltag.cv_volid));
850 csvr.csvr_voltag.cv_serial = atol(argv[3]);
854 warnx("%s: unexpected argument", cname);
857 csvr.csvr_flags = CSVR_MODE_CLEAR;
861 csvr.csvr_flags |= CSVR_ALTERNATE;
864 if (ioctl(changer_fd, CHIOSETVOLTAG, &csvr))
865 err(1, "%s: CHIOSETVOLTAG", changer_name);
869 (void) fprintf(stderr,
870 "usage: %s %s [-fca] <element> [<voltag> [<vsn>] ]\n",
876 parse_element_type(cp)
881 for (i = 0; elements[i].et_name != NULL; ++i)
882 if (strcmp(elements[i].et_name, cp) == 0)
883 return (elements[i].et_type);
885 errx(1, "invalid element type `%s'", cp);
890 element_type_name(et)
895 for (i = 0; elements[i].et_name != NULL; i++)
896 if (elements[i].et_type == et)
897 return elements[i].et_name;
903 parse_element_unit(cp)
909 i = (int)strtol(cp, &p, 10);
910 if ((i < 0) || (*p != '\0'))
911 errx(1, "invalid unit number `%s'", cp);
922 val = is_special(cp);
926 errx(1, "invalid modifier `%s'", cp);
936 for (i = 0; specials[i].sw_name != NULL; ++i)
937 if (strcmp(specials[i].sw_name, cp) == 0)
938 return (specials[i].sw_value);
944 bits_to_string(v, cp)
950 static char buf[128];
953 (void) memset(buf, 0, sizeof(buf));
955 for (sep = '<'; (f = *cp++) != 0; cp = np) {
956 for (np = cp; *np >= ' ';)
958 if ((v & (1 << (f - 1))) == 0)
960 (void) snprintf(bp, sizeof(buf) - (bp - &buf[0]),
961 "%c%.*s", sep, (int)(long)(np - cp), cp);
973 * Given an element reference, ask the changer/picker to move that
974 * element back to its source slot.
977 do_return(cname, argc, argv)
982 struct changer_element_status *ces;
983 struct changer_move cmd;
984 u_int16_t type, element;
989 warnx("%s: too few arguments", cname);
991 } else if (argc > 3) {
992 warnx("%s: too many arguments", cname);
996 type = parse_element_type(*argv);
999 /* Handle voltag virtual Changer Element Type */
1000 if (CHET_VT == type) {
1001 find_element(*argv, &type, &element);
1003 element = parse_element_unit(*argv);
1007 /* Get the status */
1008 ces = get_element_status((unsigned int)type, (unsigned int)element);
1011 errx(1, "%s: null element status pointer", cname);
1013 if (!(ces->ces_flags & CES_SOURCE_VALID))
1014 errx(1, "%s: no source information", cname);
1016 (void) memset(&cmd, 0, sizeof(cmd));
1018 cmd.cm_fromtype = type;
1019 cmd.cm_fromunit = element;
1020 cmd.cm_totype = ces->ces_source_type;
1021 cmd.cm_tounit = ces->ces_source_addr;
1023 if (ioctl(changer_fd, CHIOMOVE, &cmd) == -1)
1024 err(1, "%s: CHIOMOVE", changer_name);
1030 (void) fprintf(stderr, "usage: %s %s "
1031 "<from ET> <from EU>\n", __progname, cname);
1036 * get_element_status()
1038 * return a *cesr for the specified changer element. This
1039 * routing will malloc()/calloc() the memory. The caller
1040 * should free() it when done.
1042 static struct changer_element_status *
1043 get_element_status(type, element)
1045 unsigned int element;
1047 struct changer_element_status_request cesr;
1048 struct changer_element_status *ces;
1050 ces = (struct changer_element_status *)
1051 calloc((size_t)1, sizeof(struct changer_element_status));
1054 errx(1, "can't allocate status storage");
1056 (void)memset(&cesr, 0, sizeof(cesr));
1058 cesr.cesr_element_type = (u_int16_t)type;
1059 cesr.cesr_element_base = (u_int16_t)element;
1060 cesr.cesr_element_count = 1; /* Only this one element */
1061 cesr.cesr_flags |= CESR_VOLTAGS; /* Grab voltags as well */
1062 cesr.cesr_element_status = ces;
1064 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1066 err(1, "%s: CHIOGSTATUS", changer_name);
1077 * Given a <voltag> find the chager element and unit, or exit
1078 * with an error if it isn't found. We grab the changer status
1079 * and iterate until we find a match, or crap out.
1082 find_element(voltag, et, eu)
1087 struct changer_params cp;
1088 struct changer_element_status_request cesr;
1089 struct changer_element_status *ch_ces, *ces;
1091 size_t elem, total_elem;
1094 * Get the changer parameters, we're interested in the counts
1095 * for all types of elements to perform our search.
1097 if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
1098 err(1, "%s: CHIOGPARAMS", changer_name);
1100 /* Allocate some memory for the results */
1101 total_elem = (cp.cp_nslots + cp.cp_ndrives
1102 + cp.cp_npickers + cp.cp_nportals);
1104 ch_ces = (struct changer_element_status *)
1105 calloc(total_elem, sizeof(struct changer_element_status));
1108 errx(1, "can't allocate status storage");
1112 /* Read in the changer slots */
1113 if (cp.cp_nslots > 0) {
1114 cesr.cesr_element_type = CHET_ST;
1115 cesr.cesr_element_base = 0;
1116 cesr.cesr_element_count = cp.cp_nslots;
1117 cesr.cesr_flags |= CESR_VOLTAGS;
1118 cesr.cesr_element_status = ces;
1120 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1122 err(1, "%s: CHIOGSTATUS", changer_name);
1124 ces += cp.cp_nslots;
1127 /* Read in the drive information */
1128 if (cp.cp_ndrives > 0 ) {
1130 (void) memset(&cesr, 0, sizeof(cesr));
1131 cesr.cesr_element_type = CHET_DT;
1132 cesr.cesr_element_base = 0;
1133 cesr.cesr_element_count = cp.cp_ndrives;
1134 cesr.cesr_flags |= CESR_VOLTAGS;
1135 cesr.cesr_element_status = ces;
1137 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1139 err(1, "%s: CHIOGSTATUS", changer_name);
1141 ces += cp.cp_ndrives;
1144 /* Read in the portal information */
1145 if (cp.cp_nportals > 0 ) {
1146 (void) memset(&cesr, 0, sizeof(cesr));
1147 cesr.cesr_element_type = CHET_IE;
1148 cesr.cesr_element_base = 0;
1149 cesr.cesr_element_count = cp.cp_nportals;
1150 cesr.cesr_flags |= CESR_VOLTAGS;
1151 cesr.cesr_element_status = ces;
1153 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1155 err(1, "%s: CHIOGSTATUS", changer_name);
1157 ces += cp.cp_nportals;
1160 /* Read in the picker information */
1161 if (cp.cp_npickers > 0) {
1162 (void) memset(&cesr, 0, sizeof(cesr));
1163 cesr.cesr_element_type = CHET_MT;
1164 cesr.cesr_element_base = 0;
1165 cesr.cesr_element_count = cp.cp_npickers;
1166 cesr.cesr_flags |= CESR_VOLTAGS;
1167 cesr.cesr_element_status = ces;
1169 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1171 err(1, "%s: CHIOGSTATUS", changer_name);
1176 * Now search the list the specified <voltag>
1178 for (elem = 0; elem <= total_elem; ++elem) {
1180 ces = &ch_ces[elem];
1182 /* Make sure we have a tape in this element */
1183 if ((ces->ces_flags & (CES_STATUS_ACCESS|CES_STATUS_FULL))
1184 != (CES_STATUS_ACCESS|CES_STATUS_FULL))
1187 /* Check to see if it is our target */
1188 if (strcasecmp(voltag,
1189 (const char *)ces->ces_pvoltag.cv_volid) == 0) {
1190 *et = ces->ces_type;
1191 *eu = ces->ces_addr;
1197 errx(1, "%s: unable to locate voltag: %s", changer_name,
1207 /* Simple enough... */
1208 (void)close(changer_fd);
1214 (void) fprintf(stderr, "usage: %s [-f changer] command [-<flags>] "
1215 "arg1 arg2 [arg3 [...]]\n", __progname);