3 * Copyright (c) 2000 by Matthew Jacob
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 * without modification, immediately at the beginning of the file.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * Alternatively, this software may be distributed under the terms of the
16 * the GNU Public License ("GPL").
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #include <sys/ioctl.h>
43 #include <cam/scsi/scsi_all.h>
44 #include <cam/scsi/scsi_enc.h>
51 encioc_element_t *objp;
52 encioc_elm_status_t ob;
53 encioc_elm_desc_t objd;
54 encioc_elm_devnames_t objdn;
55 int fd, nobj, f, i, verbose, quiet, errors;
59 fprintf(stderr, "usage: %s [ -v ] device [ device ... ]\n", *v);
62 errors = quiet = verbose = 0;
63 if (strcmp(v[1], "-V") == 0) {
66 } else if (strcmp(v[1], "-v") == 0) {
69 } else if (strcmp(v[1], "-q") == 0) {
76 fd = open(*v, O_RDONLY);
81 if (ioctl(fd, ENCIOC_GETNELM, (caddr_t) &nobj) < 0) {
82 perror("ENCIOC_GETNELM");
86 if (ioctl(fd, ENCIOC_GETENCSTAT, (caddr_t) &estat) < 0) {
87 perror("ENCIOC_GETENCSTAT");
91 if ((verbose == 0 || quiet == 1) && estat == 0) {
93 fprintf(stdout, "%s: Enclosure OK\n", *v);
97 fprintf(stdout, "%s: Enclosure Status ", *v);
99 fprintf(stdout, "<OK");
103 if (estat & SES_ENCSTAT_INFO) {
104 fprintf(stdout, "%cINFO", f);
107 if (estat & SES_ENCSTAT_NONCRITICAL) {
108 fprintf(stdout, "%cNONCRITICAL", f);
111 if (estat & SES_ENCSTAT_CRITICAL) {
112 fprintf(stdout, "%cCRITICAL", f);
115 if (estat & SES_ENCSTAT_UNRECOV) {
116 fprintf(stdout, "%cUNRECOV", f);
120 fprintf(stdout, ">\n");
121 objp = calloc(nobj, sizeof (encioc_element_t));
127 if (ioctl(fd, ENCIOC_GETELMMAP, (caddr_t) objp) < 0) {
128 perror("ENCIOC_GETELMMAP");
132 for (i = 0; i < nobj; i++) {
133 ob.elm_idx = objp[i].elm_idx;
134 if (ioctl(fd, ENCIOC_GETELMSTAT, (caddr_t) &ob) < 0) {
135 perror("ENCIOC_GETELMSTAT");
139 bzero(&objd, sizeof(objd));
140 objd.elm_idx = objp[i].elm_idx;
141 objd.elm_desc_len = UINT16_MAX;
142 objd.elm_desc_str = calloc(UINT16_MAX, sizeof(char));
143 if (objd.elm_desc_str == NULL) {
148 if (ioctl(fd, ENCIOC_GETELMDESC, (caddr_t)&objd) < 0) {
149 perror("ENCIOC_GETELMDESC");
153 bzero(&objdn, sizeof(objdn));
154 objdn.elm_idx = objp[i].elm_idx;
155 objdn.elm_names_size = 128;
156 objdn.elm_devnames = calloc(128, sizeof(char));
157 if (objdn.elm_devnames == NULL) {
163 * This ioctl isn't critical and has a good chance
166 (void)ioctl(fd, ENCIOC_GETELMDEVNAMES, (caddr_t)&objdn);
167 fprintf(stdout, "Element 0x%x: %s", ob.elm_idx,
168 geteltnm(objp[i].elm_type));
169 fprintf(stdout, ", %s",
170 stat2ascii(objp[i].elm_type, ob.cstat));
171 if (objd.elm_desc_len > 0)
172 fprintf(stdout, ", descriptor: '%s'",
174 if (objdn.elm_names_len > 0)
175 fprintf(stdout, ", dev: '%s'",
177 fprintf(stdout, "\n");
178 free(objdn.elm_devnames);