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
40 static const char copyright
[] =
41 "@(#) Copyright (c) 1996 Jason R. Thorpe. All rights reserved.";
45 #include <sys/cdefs.h>
46 __FBSDID("$FreeBSD$");
48 #include <sys/param.h>
59 #include "pathnames.h"
61 static void usage(void);
62 static void cleanup(void);
63 static u_int16_t
parse_element_type(char *);
64 static u_int16_t
parse_element_unit(char *);
65 static const char * element_type_name(int et
);
66 static int parse_special(char *);
67 static int is_special(char *);
68 static const char *bits_to_string(ces_status_flags
, const char *);
70 static void find_element(char *, uint16_t *, uint16_t *);
71 static struct changer_element_status
*get_element_status
72 (unsigned int, unsigned int);
74 static int do_move(const char *, int, char **);
75 static int do_exchange(const char *, int, char **);
76 static int do_position(const char *, int, char **);
77 static int do_params(const char *, int, char **);
78 static int do_getpicker(const char *, int, char **);
79 static int do_setpicker(const char *, int, char **);
80 static int do_status(const char *, int, char **);
81 static int do_ielem(const char *, int, char **);
82 static int do_return(const char *, int, char **);
83 static int do_voltag(const char *, int, char **);
86 #define CHET_VT 10 /* Completely Arbitrary */
89 /* Valid changer element types. */
90 const struct element_type elements
[] = {
92 { "picker", CHET_MT
},
93 { "portal", CHET_IE
},
95 { "voltag", CHET_VT
}, /* Select tapes by barcode */
100 const struct changer_command commands
[] = {
101 { "exchange", do_exchange
},
102 { "getpicker", do_getpicker
},
103 { "ielem", do_ielem
},
105 { "params", do_params
},
106 { "position", do_position
},
107 { "setpicker", do_setpicker
},
108 { "status", do_status
},
109 { "return", do_return
},
110 { "voltag", do_voltag
},
114 /* Valid special words. */
115 const struct special_word specials
[] = {
116 { "inv", SW_INVERT
},
117 { "inv1", SW_INVERT1
},
118 { "inv2", SW_INVERT2
},
122 static int changer_fd
;
123 static const char *changer_name
;
126 main(int argc
, char **argv
)
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(const char *cname
, int argc
, char **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", getprogname(), cname
);
257 do_exchange(const char *cname
, int argc
, char **argv
)
259 struct changer_exchange cmd
;
263 * On an exchange command, we expect the following:
265 * <src ET> <src EU> <dst1 ET> <dst1 EU> [<dst2 ET> <dst2 EU>] [inv1] [inv2]
267 * where ET == element type and EU == element unit.
273 warnx("%s: too few arguments", cname
);
275 } else if (argc
> 8) {
276 warnx("%s: too many arguments", cname
);
279 (void) memset(&cmd
, 0, sizeof(cmd
));
282 cmd
.ce_srctype
= parse_element_type(*argv
);
285 /* Check for voltag virtual type */
286 if (CHET_VT
== cmd
.ce_srctype
) {
287 find_element(*argv
, &cmd
.ce_srctype
, &cmd
.ce_srcunit
);
290 cmd
.ce_srcunit
= parse_element_unit(*argv
);
295 cmd
.ce_fdsttype
= parse_element_type(*argv
);
298 /* Check for voltag virtual type */
299 if (CHET_VT
== cmd
.ce_fdsttype
) {
300 find_element(*argv
, &cmd
.ce_fdsttype
, &cmd
.ce_fdstunit
);
303 cmd
.ce_fdstunit
= parse_element_unit(*argv
);
308 * If the next token is a special word or there are no more
309 * arguments, then this is a case of simple exchange.
312 if ((argc
== 0) || is_special(*argv
)) {
313 cmd
.ce_sdsttype
= cmd
.ce_srctype
;
314 cmd
.ce_sdstunit
= cmd
.ce_srcunit
;
319 cmd
.ce_sdsttype
= parse_element_type(*argv
);
322 if (CHET_VT
== cmd
.ce_sdsttype
)
323 errx(1,"%s %s: voltag only makes sense as an element source",
327 cmd
.ce_sdstunit
= parse_element_unit(*argv
);
331 /* Deal with optional command modifiers. */
333 val
= parse_special(*argv
);
337 cmd
.ce_flags
|= CE_INVERT1
;
341 cmd
.ce_flags
|= CE_INVERT2
;
345 errx(1, "%s: inappropriate modifier `%s'",
351 /* Send command to changer. */
352 if (ioctl(changer_fd
, CHIOEXCHANGE
, &cmd
))
353 err(1, "%s: CHIOEXCHANGE", changer_name
);
358 (void) fprintf(stderr
,
359 "usage: %s %s <src ET> <src EU> <dst1 ET> <dst1 EU>\n"
360 " [<dst2 ET> <dst2 EU>] [inv1] [inv2]\n",
361 getprogname(), cname
);
366 do_position(const char *cname
, int argc
, char **argv
)
368 struct changer_position cmd
;
372 * On a position command, we expect the following:
374 * <to ET> <to EU> [inv]
376 * where ET == element type and EU == element unit.
382 warnx("%s: too few arguments", cname
);
384 } else if (argc
> 3) {
385 warnx("%s: too many arguments", cname
);
388 (void) memset(&cmd
, 0, sizeof(cmd
));
391 cmd
.cp_type
= parse_element_type(*argv
);
395 cmd
.cp_unit
= parse_element_unit(*argv
);
398 /* Deal with optional command modifier. */
400 val
= parse_special(*argv
);
403 cmd
.cp_flags
|= CP_INVERT
;
407 errx(1, "%s: inappropriate modifier `%s'",
413 /* Send command to changer. */
414 if (ioctl(changer_fd
, CHIOPOSITION
, &cmd
))
415 err(1, "%s: CHIOPOSITION", changer_name
);
420 (void) fprintf(stderr
, "usage: %s %s <to ET> <to EU> [inv]\n",
421 getprogname(), cname
);
427 do_params(const char *cname
, int argc
, char **argv
)
429 struct changer_params data
;
432 /* No arguments to this command. */
437 warnx("%s: no arguments expected", cname
);
441 /* Get params from changer and display them. */
442 (void) memset(&data
, 0, sizeof(data
));
443 if (ioctl(changer_fd
, CHIOGPARAMS
, &data
))
444 err(1, "%s: CHIOGPARAMS", changer_name
);
446 (void) printf("%s: %d slot%s, %d drive%s, %d picker%s",
448 data
.cp_nslots
, (data
.cp_nslots
> 1) ? "s" : "",
449 data
.cp_ndrives
, (data
.cp_ndrives
> 1) ? "s" : "",
450 data
.cp_npickers
, (data
.cp_npickers
> 1) ? "s" : "");
451 if (data
.cp_nportals
)
452 (void) printf(", %d portal%s", data
.cp_nportals
,
453 (data
.cp_nportals
> 1) ? "s" : "");
455 /* Get current picker from changer and display it. */
456 if (ioctl(changer_fd
, CHIOGPICKER
, &picker
))
457 err(1, "%s: CHIOGPICKER", changer_name
);
459 (void) printf("\n%s: current picker: %d\n", changer_name
, picker
);
464 (void) fprintf(stderr
, "usage: %s %s\n", getprogname(), cname
);
470 do_getpicker(const char *cname
, int argc
, char **argv
)
474 /* No arguments to this command. */
479 warnx("%s: no arguments expected", cname
);
483 /* Get current picker from changer and display it. */
484 if (ioctl(changer_fd
, CHIOGPICKER
, &picker
))
485 err(1, "%s: CHIOGPICKER", changer_name
);
487 (void) printf("%s: current picker: %d\n", changer_name
, picker
);
492 (void) fprintf(stderr
, "usage: %s %s\n", getprogname(), cname
);
497 do_setpicker(const char *cname
, int argc
, char **argv
)
504 warnx("%s: too few arguments", cname
);
506 } else if (argc
> 1) {
507 warnx("%s: too many arguments", cname
);
511 picker
= parse_element_unit(*argv
);
513 /* Set the changer picker. */
514 if (ioctl(changer_fd
, CHIOSPICKER
, &picker
))
515 err(1, "%s: CHIOSPICKER", changer_name
);
520 (void) fprintf(stderr
, "usage: %s %s <picker>\n", getprogname(), cname
);
525 do_status(const char *cname
, int argc
, char **argv
)
527 struct changer_params cp
;
528 struct changer_element_status_request cesr
;
530 u_int16_t base
, count
, chet
, schet
, echet
;
531 const char *description
;
544 optind
= optreset
= 1;
545 while ((c
= getopt(argc
, argv
, "vVsSbaI")) != -1) {
566 pvoltag
= avoltag
= source
= sense
= scsi
= intaddr
= 1;
569 warnx("%s: bad option", cname
);
578 * On a status command, we expect the following:
580 * [<ET> [<start> [<end>] ] ]
582 * where ET == element type, start == first element to report,
583 * end == number of elements to report
585 * If we get no arguments, we get the status of all
586 * known element types.
589 warnx("%s: too many arguments", cname
);
594 * Get params from changer. Specifically, we need the element
597 if (ioctl(changer_fd
, CHIOGPARAMS
, (char *)&cp
))
598 err(1, "%s: CHIOGPARAMS", changer_name
);
601 schet
= echet
= parse_element_type(argv
[0]);
607 base
= (u_int16_t
)atol(argv
[1]);
611 count
= (u_int16_t
)atol(argv
[2]) - base
+ 1;
613 for (chet
= schet
; chet
<= echet
; ++chet
) {
617 count
= cp
.cp_npickers
;
618 else if (count
> cp
.cp_npickers
)
619 errx(1, "not that many pickers in device");
620 description
= "picker";
625 count
= cp
.cp_nslots
;
626 else if (count
> cp
.cp_nslots
)
627 errx(1, "not that many slots in device");
628 description
= "slot";
633 count
= cp
.cp_nportals
;
634 else if (count
> cp
.cp_nportals
)
635 errx(1, "not that many portals in device");
636 description
= "portal";
641 count
= cp
.cp_ndrives
;
642 else if (count
> cp
.cp_ndrives
)
643 errx(1, "not that many drives in device");
644 description
= "drive";
648 /* To appease gcc -Wuninitialized. */
657 printf("%s: no %s elements\n",
658 changer_name
, description
);
663 bzero(&cesr
, sizeof(cesr
));
664 cesr
.cesr_element_type
= chet
;
665 cesr
.cesr_element_base
= base
;
666 cesr
.cesr_element_count
= count
;
667 /* Allocate storage for the status structures. */
668 cesr
.cesr_element_status
=
669 (struct changer_element_status
*)
670 calloc((size_t)count
, sizeof(struct changer_element_status
));
672 if (!cesr
.cesr_element_status
)
673 errx(1, "can't allocate status storage");
675 if (avoltag
|| pvoltag
)
676 cesr
.cesr_flags
|= CESR_VOLTAGS
;
678 if (ioctl(changer_fd
, CHIOGSTATUS
, (char *)&cesr
)) {
679 free(cesr
.cesr_element_status
);
680 err(1, "%s: CHIOGSTATUS", changer_name
);
683 /* Dump the status for each reported element. */
684 for (i
= 0; i
< count
; ++i
) {
685 struct changer_element_status
*ces
=
686 &(cesr
.cesr_element_status
[i
]);
687 printf("%s %d: %s", description
, ces
->ces_addr
,
688 bits_to_string(ces
->ces_flags
,
691 printf(" sense: <0x%02x/0x%02x>",
695 printf(" voltag: <%s:%d>",
696 ces
->ces_pvoltag
.cv_volid
,
697 ces
->ces_pvoltag
.cv_serial
);
699 printf(" avoltag: <%s:%d>",
700 ces
->ces_avoltag
.cv_volid
,
701 ces
->ces_avoltag
.cv_serial
);
703 if (ces
->ces_flags
& CES_SOURCE_VALID
)
704 printf(" source: <%s %d>",
706 ces
->ces_source_type
),
707 ces
->ces_source_addr
);
709 printf(" source: <>");
712 printf(" intaddr: <%d>", ces
->ces_int_addr
);
715 if (ces
->ces_flags
& CES_SCSIID_VALID
)
716 printf("%d", ces
->ces_scsi_id
);
720 if (ces
->ces_flags
& CES_LUN_VALID
)
721 printf("%d", ces
->ces_scsi_lun
);
729 free(cesr
.cesr_element_status
);
736 (void) fprintf(stderr
, "usage: %s %s [-vVsSbaA] [<element type> [<start-addr> [<end-addr>] ] ]\n",
737 getprogname(), cname
);
742 do_ielem(const char *cname
, int argc
, char **argv
)
747 timeout
= atol(argv
[1]);
748 } else if (argc
> 1) {
749 warnx("%s: too many arguments", cname
);
753 if (ioctl(changer_fd
, CHIOIELEM
, &timeout
))
754 err(1, "%s: CHIOIELEM", changer_name
);
759 (void) fprintf(stderr
, "usage: %s %s [<timeout>]\n",
760 getprogname(), cname
);
765 do_voltag(const char *cname
, int argc
, char **argv
)
771 struct changer_set_voltag_request csvr
;
773 bzero(&csvr
, sizeof(csvr
));
775 optind
= optreset
= 1;
776 while ((c
= getopt(argc
, argv
, "fca")) != -1) {
788 warnx("%s: bad option", cname
);
797 warnx("%s: missing element specification", cname
);
801 csvr
.csvr_type
= parse_element_type(argv
[0]);
802 csvr
.csvr_addr
= (u_int16_t
)atol(argv
[1]);
805 if (argc
< 3 || argc
> 4) {
806 warnx("%s: missing argument", cname
);
811 csvr
.csvr_flags
= CSVR_MODE_REPLACE
;
813 csvr
.csvr_flags
= CSVR_MODE_SET
;
815 if (strlen(argv
[2]) > sizeof(csvr
.csvr_voltag
.cv_volid
)) {
816 warnx("%s: volume label too long", cname
);
820 strlcpy((char *)csvr
.csvr_voltag
.cv_volid
, argv
[2],
821 sizeof(csvr
.csvr_voltag
.cv_volid
));
824 csvr
.csvr_voltag
.cv_serial
= (u_int16_t
)atol(argv
[3]);
828 warnx("%s: unexpected argument", cname
);
831 csvr
.csvr_flags
= CSVR_MODE_CLEAR
;
835 csvr
.csvr_flags
|= CSVR_ALTERNATE
;
838 if (ioctl(changer_fd
, CHIOSETVOLTAG
, &csvr
))
839 err(1, "%s: CHIOSETVOLTAG", changer_name
);
843 (void) fprintf(stderr
,
844 "usage: %s %s [-fca] <element> [<voltag> [<vsn>] ]\n",
845 getprogname(), cname
);
850 parse_element_type(char *cp
)
854 for (i
= 0; elements
[i
].et_name
!= NULL
; ++i
)
855 if (strcmp(elements
[i
].et_name
, cp
) == 0)
856 return ((u_int16_t
)elements
[i
].et_type
);
858 errx(1, "invalid element type `%s'", cp
);
863 element_type_name(int et
)
867 for (i
= 0; elements
[i
].et_name
!= NULL
; i
++)
868 if (elements
[i
].et_type
== et
)
869 return elements
[i
].et_name
;
875 parse_element_unit(char *cp
)
880 i
= (int)strtol(cp
, &p
, 10);
881 if ((i
< 0) || (*p
!= '\0'))
882 errx(1, "invalid unit number `%s'", cp
);
884 return ((u_int16_t
)i
);
888 parse_special(char *cp
)
892 val
= is_special(cp
);
896 errx(1, "invalid modifier `%s'", cp
);
905 for (i
= 0; specials
[i
].sw_name
!= NULL
; ++i
)
906 if (strcmp(specials
[i
].sw_name
, cp
) == 0)
907 return (specials
[i
].sw_value
);
913 bits_to_string(ces_status_flags v
, const char *cp
)
917 static char buf
[128];
920 (void) memset(buf
, 0, sizeof(buf
));
922 for (sep
= '<'; (f
= *cp
++) != 0; cp
= np
) {
923 for (np
= cp
; *np
>= ' ';)
925 if (((int)v
& (1 << (f
- 1))) == 0)
927 (void) snprintf(bp
, sizeof(buf
) - (size_t)(bp
- &buf
[0]),
928 "%c%.*s", sep
, (int)(long)(np
- cp
), cp
);
940 * Given an element reference, ask the changer/picker to move that
941 * element back to its source slot.
944 do_return(const char *cname
, int argc
, char **argv
)
946 struct changer_element_status
*ces
;
947 struct changer_move cmd
;
948 uint16_t type
, element
;
953 warnx("%s: too few arguments", cname
);
955 } else if (argc
> 3) {
956 warnx("%s: too many arguments", cname
);
960 type
= parse_element_type(*argv
);
963 /* Handle voltag virtual Changer Element Type */
964 if (CHET_VT
== type
) {
965 find_element(*argv
, &type
, &element
);
967 element
= parse_element_unit(*argv
);
972 ces
= get_element_status((unsigned int)type
, (unsigned int)element
);
975 errx(1, "%s: null element status pointer", cname
);
977 if (!(ces
->ces_flags
& CES_SOURCE_VALID
))
978 errx(1, "%s: no source information", cname
);
980 (void) memset(&cmd
, 0, sizeof(cmd
));
982 cmd
.cm_fromtype
= type
;
983 cmd
.cm_fromunit
= element
;
984 cmd
.cm_totype
= ces
->ces_source_type
;
985 cmd
.cm_tounit
= ces
->ces_source_addr
;
987 if (ioctl(changer_fd
, CHIOMOVE
, &cmd
) == -1)
988 err(1, "%s: CHIOMOVE", changer_name
);
994 (void) fprintf(stderr
, "usage: %s %s "
995 "<from ET> <from EU>\n", getprogname(), cname
);
1000 * get_element_status()
1002 * return a *cesr for the specified changer element. This
1003 * routing will malloc()/calloc() the memory. The caller
1004 * should free() it when done.
1006 static struct changer_element_status
*
1007 get_element_status(unsigned int type
, unsigned int element
)
1009 struct changer_element_status_request cesr
;
1010 struct changer_element_status
*ces
;
1012 ces
= (struct changer_element_status
*)
1013 calloc((size_t)1, sizeof(struct changer_element_status
));
1016 errx(1, "can't allocate status storage");
1018 (void)memset(&cesr
, 0, sizeof(cesr
));
1020 cesr
.cesr_element_type
= (uint16_t)type
;
1021 cesr
.cesr_element_base
= (uint16_t)element
;
1022 cesr
.cesr_element_count
= 1; /* Only this one element */
1023 cesr
.cesr_flags
|= CESR_VOLTAGS
; /* Grab voltags as well */
1024 cesr
.cesr_element_status
= ces
;
1026 if (ioctl(changer_fd
, CHIOGSTATUS
, (char *)&cesr
) == -1) {
1028 err(1, "%s: CHIOGSTATUS", changer_name
);
1039 * Given a <voltag> find the chager element and unit, or exit
1040 * with an error if it isn't found. We grab the changer status
1041 * and iterate until we find a match, or crap out.
1044 find_element(char *voltag
, uint16_t *et
, uint16_t *eu
)
1046 struct changer_params cp
;
1047 struct changer_element_status_request cesr
;
1048 struct changer_element_status
*ch_ces
, *ces
;
1050 size_t elem
, total_elem
;
1053 * Get the changer parameters, we're interested in the counts
1054 * for all types of elements to perform our search.
1056 if (ioctl(changer_fd
, CHIOGPARAMS
, (char *)&cp
))
1057 err(1, "%s: CHIOGPARAMS", changer_name
);
1059 /* Allocate some memory for the results */
1060 total_elem
= (cp
.cp_nslots
+ cp
.cp_ndrives
1061 + cp
.cp_npickers
+ cp
.cp_nportals
);
1063 ch_ces
= (struct changer_element_status
*)
1064 calloc(total_elem
, sizeof(struct changer_element_status
));
1067 errx(1, "can't allocate status storage");
1071 /* Read in the changer slots */
1072 if (cp
.cp_nslots
> 0) {
1073 cesr
.cesr_element_type
= CHET_ST
;
1074 cesr
.cesr_element_base
= 0;
1075 cesr
.cesr_element_count
= cp
.cp_nslots
;
1076 cesr
.cesr_flags
|= CESR_VOLTAGS
;
1077 cesr
.cesr_element_status
= ces
;
1079 if (ioctl(changer_fd
, CHIOGSTATUS
, (char *)&cesr
) == -1) {
1081 err(1, "%s: CHIOGSTATUS", changer_name
);
1083 ces
+= cp
.cp_nslots
;
1086 /* Read in the drive information */
1087 if (cp
.cp_ndrives
> 0 ) {
1089 (void) memset(&cesr
, 0, sizeof(cesr
));
1090 cesr
.cesr_element_type
= CHET_DT
;
1091 cesr
.cesr_element_base
= 0;
1092 cesr
.cesr_element_count
= cp
.cp_ndrives
;
1093 cesr
.cesr_flags
|= CESR_VOLTAGS
;
1094 cesr
.cesr_element_status
= ces
;
1096 if (ioctl(changer_fd
, CHIOGSTATUS
, (char *)&cesr
) == -1) {
1098 err(1, "%s: CHIOGSTATUS", changer_name
);
1100 ces
+= cp
.cp_ndrives
;
1103 /* Read in the portal information */
1104 if (cp
.cp_nportals
> 0 ) {
1105 (void) memset(&cesr
, 0, sizeof(cesr
));
1106 cesr
.cesr_element_type
= CHET_IE
;
1107 cesr
.cesr_element_base
= 0;
1108 cesr
.cesr_element_count
= cp
.cp_nportals
;
1109 cesr
.cesr_flags
|= CESR_VOLTAGS
;
1110 cesr
.cesr_element_status
= ces
;
1112 if (ioctl(changer_fd
, CHIOGSTATUS
, (char *)&cesr
) == -1) {
1114 err(1, "%s: CHIOGSTATUS", changer_name
);
1116 ces
+= cp
.cp_nportals
;
1119 /* Read in the picker information */
1120 if (cp
.cp_npickers
> 0) {
1121 (void) memset(&cesr
, 0, sizeof(cesr
));
1122 cesr
.cesr_element_type
= CHET_MT
;
1123 cesr
.cesr_element_base
= 0;
1124 cesr
.cesr_element_count
= cp
.cp_npickers
;
1125 cesr
.cesr_flags
|= CESR_VOLTAGS
;
1126 cesr
.cesr_element_status
= ces
;
1128 if (ioctl(changer_fd
, CHIOGSTATUS
, (char *)&cesr
) == -1) {
1130 err(1, "%s: CHIOGSTATUS", changer_name
);
1135 * Now search the list the specified <voltag>
1137 for (elem
= 0; elem
<= total_elem
; ++elem
) {
1139 ces
= &ch_ces
[elem
];
1141 /* Make sure we have a tape in this element */
1142 if ((ces
->ces_flags
& (CES_STATUS_ACCESS
|CES_STATUS_FULL
))
1143 != (CES_STATUS_ACCESS
|CES_STATUS_FULL
))
1146 /* Check to see if it is our target */
1147 if (strcasecmp(voltag
,
1148 (const char *)ces
->ces_pvoltag
.cv_volid
) == 0) {
1149 *et
= ces
->ces_type
;
1150 *eu
= ces
->ces_addr
;
1156 errx(1, "%s: unable to locate voltag: %s", changer_name
,
1166 /* Simple enough... */
1167 (void)close(changer_fd
);
1173 (void)fprintf(stderr
, "usage: %s [-f changer] command [-<flags>] "
1174 "arg1 arg2 [arg3 [...]]\n", getprogname());