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
34 * Additional Copyright (c) 1997, by Matthew Jacob, for NASA/Ames Research Ctr.
35 * Addidional Copyright (c) 2000, by C. Stephen Gunn, Waterspout Communications
39 static const char copyright[] =
40 "@(#) Copyright (c) 1996 Jason R. Thorpe. All rights reserved.";
41 static const char rcsid[] =
42 "$FreeBSD: src/bin/chio/chio.c,v 1.15.2.3 2001/07/28 19:22:01 mikeh Exp $";
45 #include <sys/param.h>
55 #include "pathnames.h"
57 extern char *__progname; /* from crt0.o */
59 static void usage __P((void));
60 static void cleanup __P((void));
61 static int parse_element_type __P((char *));
62 static int parse_element_unit __P((char *));
63 static const char * element_type_name __P((int et));
64 static int parse_special __P((char *));
65 static int is_special __P((char *));
66 static const char *bits_to_string __P((ces_status_flags, const char *));
68 static void find_element __P((char *, u_int16_t *, u_int16_t *));
69 static struct changer_element_status *get_element_status
70 __P((unsigned int, unsigned int));
72 static int do_move __P((const char *, int, char **));
73 static int do_exchange __P((const char *, int, char **));
74 static int do_position __P((const char *, int, char **));
75 static int do_params __P((const char *, int, char **));
76 static int do_getpicker __P((const char *, int, char **));
77 static int do_setpicker __P((const char *, int, char **));
78 static int do_status __P((const char *, int, char **));
79 static int do_ielem __P((const char *, int, char **));
80 static int do_return __P((const char *, int, char **));
81 static int do_voltag __P((const char *, int, char **));
84 #define CHET_VT 10 /* Completely Arbitrary */
87 /* Valid changer element types. */
88 const struct element_type elements[] = {
90 { "picker", CHET_MT },
91 { "portal", CHET_IE },
93 { "voltag", CHET_VT }, /* Select tapes by barcode */
98 const struct changer_command commands[] = {
99 { "exchange", do_exchange },
100 { "getpicker", do_getpicker },
101 { "ielem", do_ielem },
103 { "params", do_params },
104 { "position", do_position },
105 { "setpicker", do_setpicker },
106 { "status", do_status },
107 { "return", do_return },
108 { "voltag", do_voltag },
112 /* Valid special words. */
113 const struct special_word specials[] = {
114 { "inv", SW_INVERT },
115 { "inv1", SW_INVERT1 },
116 { "inv2", SW_INVERT2 },
120 static int changer_fd;
121 static const char *changer_name;
130 while ((ch = getopt(argc, argv, "f:")) != -1) {
133 changer_name = optarg;
146 /* Get the default changer if not already specified. */
147 if (changer_name == NULL)
148 if ((changer_name = getenv(CHANGER_ENV_VAR)) == NULL)
149 changer_name = _PATH_CH;
151 /* Open the changer device. */
152 if ((changer_fd = open(changer_name, O_RDWR, 0600)) == -1)
153 err(1, "%s: open", changer_name);
155 /* Register cleanup function. */
157 err(1, "can't register cleanup function");
159 /* Find the specified command. */
160 for (i = 0; commands[i].cc_name != NULL; ++i)
161 if (strcmp(*argv, commands[i].cc_name) == 0)
163 if (commands[i].cc_name == NULL) {
164 /* look for abbreviation */
165 for (i = 0; commands[i].cc_name != NULL; ++i)
166 if (strncmp(*argv, commands[i].cc_name,
171 if (commands[i].cc_name == NULL)
172 errx(1, "unknown command: %s", *argv);
174 exit ((*commands[i].cc_handler)(commands[i].cc_name, argc, argv));
179 do_move(cname, argc, argv)
184 struct changer_move cmd;
188 * On a move command, we expect the following:
190 * <from ET> <from EU> <to ET> <to EU> [inv]
192 * where ET == element type and EU == element unit.
198 warnx("%s: too few arguments", cname);
200 } else if (argc > 5) {
201 warnx("%s: too many arguments", cname);
204 (void) memset(&cmd, 0, sizeof(cmd));
207 cmd.cm_fromtype = parse_element_type(*argv);
210 /* Check for voltag virtual type */
211 if (CHET_VT == cmd.cm_fromtype) {
212 find_element(*argv, &cmd.cm_fromtype, &cmd.cm_fromunit);
215 cmd.cm_fromunit = parse_element_unit(*argv);
220 cmd.cm_totype = parse_element_type(*argv);
223 /* Check for voltag virtual type, and report error */
224 if (CHET_VT == cmd.cm_totype)
225 errx(1,"%s: voltag only makes sense as an element source",
229 cmd.cm_tounit = parse_element_unit(*argv);
232 /* Deal with optional command modifier. */
234 val = parse_special(*argv);
237 cmd.cm_flags |= CM_INVERT;
241 errx(1, "%s: inappropriate modifier `%s'",
247 /* Send command to changer. */
248 if (ioctl(changer_fd, CHIOMOVE, &cmd))
249 err(1, "%s: CHIOMOVE", changer_name);
254 (void) fprintf(stderr, "usage: %s %s "
255 "<from ET> <from EU> <to ET> <to EU> [inv]\n", __progname, cname);
260 do_exchange(cname, argc, argv)
265 struct changer_exchange cmd;
269 * On an exchange command, we expect the following:
271 * <src ET> <src EU> <dst1 ET> <dst1 EU> [<dst2 ET> <dst2 EU>] [inv1] [inv2]
273 * where ET == element type and EU == element unit.
279 warnx("%s: too few arguments", cname);
281 } else if (argc > 8) {
282 warnx("%s: too many arguments", cname);
285 (void) memset(&cmd, 0, sizeof(cmd));
288 cmd.ce_srctype = parse_element_type(*argv);
291 /* Check for voltag virtual type */
292 if (CHET_VT == cmd.ce_srctype) {
293 find_element(*argv, &cmd.ce_srctype, &cmd.ce_srcunit);
296 cmd.ce_srcunit = parse_element_unit(*argv);
301 cmd.ce_fdsttype = parse_element_type(*argv);
304 /* Check for voltag virtual type */
305 if (CHET_VT == cmd.ce_fdsttype) {
306 find_element(*argv, &cmd.ce_fdsttype, &cmd.ce_fdstunit);
309 cmd.ce_fdstunit = parse_element_unit(*argv);
314 * If the next token is a special word or there are no more
315 * arguments, then this is a case of simple exchange.
318 if ((argc == 0) || is_special(*argv)) {
319 cmd.ce_sdsttype = cmd.ce_srctype;
320 cmd.ce_sdstunit = cmd.ce_srcunit;
325 cmd.ce_sdsttype = parse_element_type(*argv);
328 if (CHET_VT == cmd.ce_sdsttype)
329 errx(1,"%s %s: voltag only makes sense as an element source",
333 cmd.ce_sdstunit = parse_element_unit(*argv);
337 /* Deal with optional command modifiers. */
339 val = parse_special(*argv);
343 cmd.ce_flags |= CE_INVERT1;
347 cmd.ce_flags |= CE_INVERT2;
351 errx(1, "%s: inappropriate modifier `%s'",
357 /* Send command to changer. */
358 if (ioctl(changer_fd, CHIOEXCHANGE, &cmd))
359 err(1, "%s: CHIOEXCHANGE", changer_name);
364 (void) fprintf(stderr,
365 "usage: %s %s <src ET> <src EU> <dst1 ET> <dst1 EU>\n"
366 " [<dst2 ET> <dst2 EU>] [inv1] [inv2]\n",
372 do_position(cname, argc, argv)
377 struct changer_position cmd;
381 * On a position command, we expect the following:
383 * <to ET> <to EU> [inv]
385 * where ET == element type and EU == element unit.
391 warnx("%s: too few arguments", cname);
393 } else if (argc > 3) {
394 warnx("%s: too many arguments", cname);
397 (void) memset(&cmd, 0, sizeof(cmd));
400 cmd.cp_type = parse_element_type(*argv);
404 cmd.cp_unit = parse_element_unit(*argv);
407 /* Deal with optional command modifier. */
409 val = parse_special(*argv);
412 cmd.cp_flags |= CP_INVERT;
416 errx(1, "%s: inappropriate modifier `%s'",
422 /* Send command to changer. */
423 if (ioctl(changer_fd, CHIOPOSITION, &cmd))
424 err(1, "%s: CHIOPOSITION", changer_name);
429 (void) fprintf(stderr, "usage: %s %s <to ET> <to EU> [inv]\n",
436 do_params(cname, argc, argv)
441 struct changer_params data;
444 /* No arguments to this command. */
449 warnx("%s: no arguments expected", cname);
453 /* Get params from changer and display them. */
454 (void) memset(&data, 0, sizeof(data));
455 if (ioctl(changer_fd, CHIOGPARAMS, &data))
456 err(1, "%s: CHIOGPARAMS", changer_name);
458 (void) printf("%s: %d slot%s, %d drive%s, %d picker%s",
460 data.cp_nslots, (data.cp_nslots > 1) ? "s" : "",
461 data.cp_ndrives, (data.cp_ndrives > 1) ? "s" : "",
462 data.cp_npickers, (data.cp_npickers > 1) ? "s" : "");
463 if (data.cp_nportals)
464 (void) printf(", %d portal%s", data.cp_nportals,
465 (data.cp_nportals > 1) ? "s" : "");
467 /* Get current picker from changer and display it. */
468 if (ioctl(changer_fd, CHIOGPICKER, &picker))
469 err(1, "%s: CHIOGPICKER", changer_name);
471 (void) printf("\n%s: current picker: %d\n", changer_name, picker);
476 (void) fprintf(stderr, "usage: %s %s\n", __progname, cname);
482 do_getpicker(cname, argc, argv)
489 /* No arguments to this command. */
494 warnx("%s: no arguments expected", cname);
498 /* Get current picker from changer and display it. */
499 if (ioctl(changer_fd, CHIOGPICKER, &picker))
500 err(1, "%s: CHIOGPICKER", changer_name);
502 (void) printf("%s: current picker: %d\n", changer_name, picker);
507 (void) fprintf(stderr, "usage: %s %s\n", __progname, cname);
512 do_setpicker(cname, argc, argv)
522 warnx("%s: too few arguments", cname);
524 } else if (argc > 1) {
525 warnx("%s: too many arguments", cname);
529 picker = parse_element_unit(*argv);
531 /* Set the changer picker. */
532 if (ioctl(changer_fd, CHIOSPICKER, &picker))
533 err(1, "%s: CHIOSPICKER", changer_name);
538 (void) fprintf(stderr, "usage: %s %s <picker>\n", __progname, cname);
543 do_status(cname, argc, argv)
548 struct changer_params cp;
549 struct changer_element_status_request cesr;
550 int i, count, base, chet, schet, echet;
551 const char *description;
564 optind = optreset = 1;
565 while ((c = getopt(argc, argv, "vVsSbaI")) != -1) {
586 pvoltag = avoltag = source = sense = scsi = intaddr = 1;
589 warnx("%s: bad option", cname);
598 * On a status command, we expect the following:
600 * [<ET> [<start> [<end>] ] ]
602 * where ET == element type, start == first element to report,
603 * end == number of elements to report
605 * If we get no arguments, we get the status of all
606 * known element types.
609 warnx("%s: too many arguments", cname);
614 * Get params from changer. Specifically, we need the element
617 if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
618 err(1, "%s: CHIOGPARAMS", changer_name);
621 schet = echet = parse_element_type(argv[0]);
627 base = atol(argv[1]);
631 count = atol(argv[2]) - base + 1;
633 if (base < 0 || count < 0)
634 errx(1, "bad arguments");
636 for (chet = schet; chet <= echet; ++chet) {
640 count = cp.cp_npickers;
641 else if (count > cp.cp_npickers)
642 errx(1, "not that many pickers in device");
643 description = "picker";
648 count = cp.cp_nslots;
649 else if (count > cp.cp_nslots)
650 errx(1, "not that many slots in device");
651 description = "slot";
656 count = cp.cp_nportals;
657 else if (count > cp.cp_nportals)
658 errx(1, "not that many portals in device");
659 description = "portal";
664 count = cp.cp_ndrives;
665 else if (count > cp.cp_ndrives)
666 errx(1, "not that many drives in device");
667 description = "drive";
671 /* To appease gcc -Wuninitialized. */
680 printf("%s: no %s elements\n",
681 changer_name, description);
686 bzero(&cesr, sizeof(cesr));
687 cesr.cesr_element_type = chet;
688 cesr.cesr_element_base = base;
689 cesr.cesr_element_count = count;
690 /* Allocate storage for the status structures. */
691 cesr.cesr_element_status =
692 (struct changer_element_status *)
693 calloc((size_t)count, sizeof(struct changer_element_status));
695 if (!cesr.cesr_element_status)
696 errx(1, "can't allocate status storage");
698 if (avoltag || pvoltag)
699 cesr.cesr_flags |= CESR_VOLTAGS;
701 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr)) {
702 free(cesr.cesr_element_status);
703 err(1, "%s: CHIOGSTATUS", changer_name);
706 /* Dump the status for each reported element. */
707 for (i = 0; i < count; ++i) {
708 struct changer_element_status *ces =
709 &(cesr.cesr_element_status[i]);
710 printf("%s %d: %s", description, ces->ces_addr,
711 bits_to_string(ces->ces_flags,
714 printf(" sense: <0x%02x/0x%02x>",
718 printf(" voltag: <%s:%d>",
719 ces->ces_pvoltag.cv_volid,
720 ces->ces_pvoltag.cv_serial);
722 printf(" avoltag: <%s:%d>",
723 ces->ces_avoltag.cv_volid,
724 ces->ces_avoltag.cv_serial);
726 if (ces->ces_flags & CES_SOURCE_VALID)
727 printf(" source: <%s %d>",
729 ces->ces_source_type),
730 ces->ces_source_addr);
732 printf(" source: <>");
735 printf(" intaddr: <%d>", ces->ces_int_addr);
738 if (ces->ces_flags & CES_SCSIID_VALID)
739 printf("%d", ces->ces_scsi_id);
743 if (ces->ces_flags & CES_LUN_VALID)
744 printf("%d", ces->ces_scsi_lun);
752 free(cesr.cesr_element_status);
759 (void) fprintf(stderr, "usage: %s %s [-vVsSbaA] [<element type> [<start-addr> [<end-addr>] ] ]\n",
765 do_ielem(cname, argc, argv)
773 timeout = atol(argv[1]);
774 } else if (argc > 1) {
775 warnx("%s: too many arguments", cname);
779 if (ioctl(changer_fd, CHIOIELEM, &timeout))
780 err(1, "%s: CHIOIELEM", changer_name);
785 (void) fprintf(stderr, "usage: %s %s [<timeout>]\n",
791 do_voltag(cname, argc, argv)
800 struct changer_set_voltag_request csvr;
802 bzero(&csvr, sizeof(csvr));
804 optind = optreset = 1;
805 while ((c = getopt(argc, argv, "fca")) != -1) {
817 warnx("%s: bad option", cname);
826 warnx("%s: missing element specification", cname);
830 csvr.csvr_type = parse_element_type(argv[0]);
831 csvr.csvr_addr = atol(argv[1]);
834 if (argc < 3 || argc > 4) {
835 warnx("%s: missing argument", cname);
840 csvr.csvr_flags = CSVR_MODE_REPLACE;
842 csvr.csvr_flags = CSVR_MODE_SET;
844 if (strlen(argv[2]) > sizeof(csvr.csvr_voltag.cv_volid)) {
845 warnx("%s: volume label too long", cname);
849 strlcpy((char *)csvr.csvr_voltag.cv_volid, argv[2],
850 sizeof(csvr.csvr_voltag.cv_volid));
853 csvr.csvr_voltag.cv_serial = atol(argv[3]);
857 warnx("%s: unexpected argument", cname);
860 csvr.csvr_flags = CSVR_MODE_CLEAR;
864 csvr.csvr_flags |= CSVR_ALTERNATE;
867 if (ioctl(changer_fd, CHIOSETVOLTAG, &csvr))
868 err(1, "%s: CHIOSETVOLTAG", changer_name);
872 (void) fprintf(stderr,
873 "usage: %s %s [-fca] <element> [<voltag> [<vsn>] ]\n",
879 parse_element_type(cp)
884 for (i = 0; elements[i].et_name != NULL; ++i)
885 if (strcmp(elements[i].et_name, cp) == 0)
886 return (elements[i].et_type);
888 errx(1, "invalid element type `%s'", cp);
893 element_type_name(et)
898 for (i = 0; elements[i].et_name != NULL; i++)
899 if (elements[i].et_type == et)
900 return elements[i].et_name;
906 parse_element_unit(cp)
912 i = (int)strtol(cp, &p, 10);
913 if ((i < 0) || (*p != '\0'))
914 errx(1, "invalid unit number `%s'", cp);
925 val = is_special(cp);
929 errx(1, "invalid modifier `%s'", cp);
939 for (i = 0; specials[i].sw_name != NULL; ++i)
940 if (strcmp(specials[i].sw_name, cp) == 0)
941 return (specials[i].sw_value);
947 bits_to_string(v, cp)
953 static char buf[128];
956 (void) memset(buf, 0, sizeof(buf));
958 for (sep = '<'; (f = *cp++) != 0; cp = np) {
959 for (np = cp; *np >= ' ';)
961 if ((v & (1 << (f - 1))) == 0)
963 (void) snprintf(bp, sizeof(buf) - (bp - &buf[0]),
964 "%c%.*s", sep, (int)(long)(np - cp), cp);
976 * Given an element reference, ask the changer/picker to move that
977 * element back to its source slot.
980 do_return(cname, argc, argv)
985 struct changer_element_status *ces;
986 struct changer_move cmd;
987 u_int16_t type, element;
992 warnx("%s: too few arguments", cname);
994 } else if (argc > 3) {
995 warnx("%s: too many arguments", cname);
999 type = parse_element_type(*argv);
1002 /* Handle voltag virtual Changer Element Type */
1003 if (CHET_VT == type) {
1004 find_element(*argv, &type, &element);
1006 element = parse_element_unit(*argv);
1010 /* Get the status */
1011 ces = get_element_status((unsigned int)type, (unsigned int)element);
1014 errx(1, "%s: null element status pointer", cname);
1016 if (!(ces->ces_flags & CES_SOURCE_VALID))
1017 errx(1, "%s: no source information", cname);
1019 (void) memset(&cmd, 0, sizeof(cmd));
1021 cmd.cm_fromtype = type;
1022 cmd.cm_fromunit = element;
1023 cmd.cm_totype = ces->ces_source_type;
1024 cmd.cm_tounit = ces->ces_source_addr;
1026 if (ioctl(changer_fd, CHIOMOVE, &cmd) == -1)
1027 err(1, "%s: CHIOMOVE", changer_name);
1033 (void) fprintf(stderr, "usage: %s %s "
1034 "<from ET> <from EU>\n", __progname, cname);
1039 * get_element_status()
1041 * return a *cesr for the specified changer element. This
1042 * routing will malloc()/calloc() the memory. The caller
1043 * should free() it when done.
1045 static struct changer_element_status *
1046 get_element_status(type, element)
1048 unsigned int element;
1050 struct changer_element_status_request cesr;
1051 struct changer_element_status *ces;
1053 ces = (struct changer_element_status *)
1054 calloc((size_t)1, sizeof(struct changer_element_status));
1057 errx(1, "can't allocate status storage");
1059 (void)memset(&cesr, 0, sizeof(cesr));
1061 cesr.cesr_element_type = (u_int16_t)type;
1062 cesr.cesr_element_base = (u_int16_t)element;
1063 cesr.cesr_element_count = 1; /* Only this one element */
1064 cesr.cesr_flags |= CESR_VOLTAGS; /* Grab voltags as well */
1065 cesr.cesr_element_status = ces;
1067 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1069 err(1, "%s: CHIOGSTATUS", changer_name);
1080 * Given a <voltag> find the chager element and unit, or exit
1081 * with an error if it isn't found. We grab the changer status
1082 * and iterate until we find a match, or crap out.
1085 find_element(voltag, et, eu)
1090 struct changer_params cp;
1091 struct changer_element_status_request cesr;
1092 struct changer_element_status *ch_ces, *ces;
1094 size_t elem, total_elem;
1097 * Get the changer parameters, we're interested in the counts
1098 * for all types of elements to perform our search.
1100 if (ioctl(changer_fd, CHIOGPARAMS, (char *)&cp))
1101 err(1, "%s: CHIOGPARAMS", changer_name);
1103 /* Allocate some memory for the results */
1104 total_elem = (cp.cp_nslots + cp.cp_ndrives
1105 + cp.cp_npickers + cp.cp_nportals);
1107 ch_ces = (struct changer_element_status *)
1108 calloc(total_elem, sizeof(struct changer_element_status));
1111 errx(1, "can't allocate status storage");
1115 /* Read in the changer slots */
1116 if (cp.cp_nslots > 0) {
1117 cesr.cesr_element_type = CHET_ST;
1118 cesr.cesr_element_base = 0;
1119 cesr.cesr_element_count = cp.cp_nslots;
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);
1127 ces += cp.cp_nslots;
1130 /* Read in the drive information */
1131 if (cp.cp_ndrives > 0 ) {
1133 (void) memset(&cesr, 0, sizeof(cesr));
1134 cesr.cesr_element_type = CHET_DT;
1135 cesr.cesr_element_base = 0;
1136 cesr.cesr_element_count = cp.cp_ndrives;
1137 cesr.cesr_flags |= CESR_VOLTAGS;
1138 cesr.cesr_element_status = ces;
1140 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1142 err(1, "%s: CHIOGSTATUS", changer_name);
1144 ces += cp.cp_ndrives;
1147 /* Read in the portal information */
1148 if (cp.cp_nportals > 0 ) {
1149 (void) memset(&cesr, 0, sizeof(cesr));
1150 cesr.cesr_element_type = CHET_IE;
1151 cesr.cesr_element_base = 0;
1152 cesr.cesr_element_count = cp.cp_nportals;
1153 cesr.cesr_flags |= CESR_VOLTAGS;
1154 cesr.cesr_element_status = ces;
1156 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1158 err(1, "%s: CHIOGSTATUS", changer_name);
1160 ces += cp.cp_nportals;
1163 /* Read in the picker information */
1164 if (cp.cp_npickers > 0) {
1165 (void) memset(&cesr, 0, sizeof(cesr));
1166 cesr.cesr_element_type = CHET_MT;
1167 cesr.cesr_element_base = 0;
1168 cesr.cesr_element_count = cp.cp_npickers;
1169 cesr.cesr_flags |= CESR_VOLTAGS;
1170 cesr.cesr_element_status = ces;
1172 if (ioctl(changer_fd, CHIOGSTATUS, (char *)&cesr) == -1) {
1174 err(1, "%s: CHIOGSTATUS", changer_name);
1179 * Now search the list the specified <voltag>
1181 for (elem = 0; elem <= total_elem; ++elem) {
1183 ces = &ch_ces[elem];
1185 /* Make sure we have a tape in this element */
1186 if ((ces->ces_flags & (CES_STATUS_ACCESS|CES_STATUS_FULL))
1187 != (CES_STATUS_ACCESS|CES_STATUS_FULL))
1190 /* Check to see if it is our target */
1191 if (strcasecmp(voltag,
1192 (const char *)ces->ces_pvoltag.cv_volid) == 0) {
1193 *et = ces->ces_type;
1194 *eu = ces->ces_addr;
1200 errx(1, "%s: unable to locate voltag: %s", changer_name,
1210 /* Simple enough... */
1211 (void)close(changer_fd);
1217 (void) fprintf(stderr, "usage: %s [-f changer] command [-<flags>] "
1218 "arg1 arg2 [arg3 [...]]\n", __progname);