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
38 #include <sys/ioctl.h>
42 extern char *geteltnm __P((int));
43 extern char *stat2ascii __P((int, u_char *));
52 int fd, nobj, f, i, verbose, quiet, errors;
56 fprintf(stderr, "usage: %s [ -v ] device [ device ... ]\n", *v);
59 errors = quiet = verbose = 0;
60 if (strcmp(v[1], "-V") == 0) {
63 } else if (strcmp(v[1], "-v") == 0) {
66 } else if (strcmp(v[1], "-q") == 0) {
73 fd = open(*v, O_RDONLY);
78 if (ioctl(fd, SESIOC_GETNOBJ, (caddr_t) &nobj) < 0) {
79 perror("SESIOC_GETNOBJ");
83 if (ioctl(fd, SESIOC_GETENCSTAT, (caddr_t) &estat) < 0) {
84 perror("SESIOC_GETENCSTAT");
88 if ((verbose == 0 || quiet == 1) && estat == 0) {
90 fprintf(stdout, "%s: Enclosure OK\n", *v);
94 fprintf(stdout, "%s: Enclosure Status ", *v);
96 fprintf(stdout, "<OK");
100 if (estat & SES_ENCSTAT_INFO) {
101 fprintf(stdout, "%cINFO", f);
104 if (estat & SES_ENCSTAT_NONCRITICAL) {
105 fprintf(stdout, "%cNONCRITICAL", f);
108 if (estat & SES_ENCSTAT_CRITICAL) {
109 fprintf(stdout, "%cCRITICAL", f);
112 if (estat & SES_ENCSTAT_UNRECOV) {
113 fprintf(stdout, "%cUNRECOV", f);
117 fprintf(stdout, ">\n");
118 objp = calloc(nobj, sizeof (ses_object));
124 if (ioctl(fd, SESIOC_GETOBJMAP, (caddr_t) objp) < 0) {
125 perror("SESIOC_GETOBJMAP");
129 for (i = 0; i < nobj; i++) {
130 ob.obj_id = objp[i].obj_id;
131 if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t) &ob) < 0) {
132 perror("SESIOC_GETOBJSTAT");
136 if ((ob.cstat[0] & 0xf) == SES_OBJSTAT_OK) {
139 "Element 0x%x: %s OK (%s)\n",
141 geteltnm(objp[i].object_type),
142 stat2ascii(objp[i].object_type,
147 fprintf(stdout, "Element 0x%x: %s, %s\n",
148 ob.obj_id, geteltnm(objp[i].object_type),
149 stat2ascii(objp[i].object_type, ob.cstat));