diff options
Diffstat (limited to 'share/examples/ses/srcs')
-rw-r--r-- | share/examples/ses/srcs/chpmon.c | 125 | ||||
-rw-r--r-- | share/examples/ses/srcs/eltsub.c | 189 | ||||
-rw-r--r-- | share/examples/ses/srcs/eltsub.h | 35 | ||||
-rw-r--r-- | share/examples/ses/srcs/getencstat.c | 195 | ||||
-rw-r--r-- | share/examples/ses/srcs/getnobj.c | 66 | ||||
-rw-r--r-- | share/examples/ses/srcs/getobjmap.c | 87 | ||||
-rw-r--r-- | share/examples/ses/srcs/getobjstat.c | 76 | ||||
-rw-r--r-- | share/examples/ses/srcs/inienc.c | 61 | ||||
-rw-r--r-- | share/examples/ses/srcs/sesd.c | 176 | ||||
-rw-r--r-- | share/examples/ses/srcs/setencstat.c | 68 | ||||
-rw-r--r-- | share/examples/ses/srcs/setobjstat.c | 83 |
11 files changed, 1161 insertions, 0 deletions
diff --git a/share/examples/ses/srcs/chpmon.c b/share/examples/ses/srcs/chpmon.c new file mode 100644 index 000000000000..40574e16cf0f --- /dev/null +++ b/share/examples/ses/srcs/chpmon.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <sys/ioctl.h> +#include "ses.h" + +/* + * Continuously monitor all named SES devices + * and turn all but INFO enclosure status + * values into CRITICAL enclosure status. + */ +#define BADSTAT \ + (SES_ENCSTAT_UNRECOV|SES_ENCSTAT_CRITICAL|SES_ENCSTAT_NONCRITICAL) +int +main(int a, char **v) +{ + int fd, delay, dev; + ses_encstat stat, *carray; + + if (a < 3) { + fprintf(stderr, "usage: %s polling-interval device " + "[ device ... ]\n", *v); + return (1); + } + delay = atoi(v[1]); + carray = malloc(a); + if (carray == NULL) { + perror("malloc"); + return (1); + } + bzero((void *)carray, a); + + for (;;) { + for (dev = 2; dev < a; dev++) { + fd = open(v[dev], O_RDWR); + if (fd < 0) { + perror(v[dev]); + continue; + } + /* + * First clear any enclosure status, in case it is + * a latched status. + */ + stat = 0; + if (ioctl(fd, SESIOC_SETENCSTAT, (caddr_t) &stat) < 0) { + fprintf(stderr, "%s: SESIOC_SETENCSTAT1: %s\n", + v[dev], strerror(errno)); + (void) close(fd); + continue; + } + /* + * Now get the actual current enclosure status. + */ + if (ioctl(fd, SESIOC_GETENCSTAT, (caddr_t) &stat) < 0) { + fprintf(stderr, "%s: SESIOC_GETENCSTAT: %s\n", + v[dev], strerror(errno)); + (void) close(fd); + continue; + } + + if ((stat & BADSTAT) == 0) { + if (carray[dev]) { + fprintf(stdout, "%s: Clearing CRITICAL " + "condition\n", v[dev]); + carray[dev] = 0; + } + (void) close(fd); + continue; + } + carray[dev] = 1; + fprintf(stdout, "%s: Setting CRITICAL from:", v[dev]); + if (stat & SES_ENCSTAT_UNRECOV) + fprintf(stdout, " UNRECOVERABLE"); + + if (stat & SES_ENCSTAT_CRITICAL) + fprintf(stdout, " CRITICAL"); + + if (stat & SES_ENCSTAT_NONCRITICAL) + fprintf(stdout, " NONCRITICAL"); + putchar('\n'); + stat = SES_ENCSTAT_CRITICAL; + if (ioctl(fd, SESIOC_SETENCSTAT, (caddr_t) &stat) < 0) { + fprintf(stderr, "%s: SESIOC_SETENCSTAT 2: %s\n", + v[dev], strerror(errno)); + } + (void) close(fd); + } + sleep(delay); + } + /* NOTREACHED */ +} diff --git a/share/examples/ses/srcs/eltsub.c b/share/examples/ses/srcs/eltsub.c new file mode 100644 index 000000000000..4173eba4997f --- /dev/null +++ b/share/examples/ses/srcs/eltsub.c @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ + +#include <unistd.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <sys/ioctl.h> +#include <cam/scsi/scsi_all.h> +#include <cam/scsi/scsi_enc.h> + +#include "eltsub.h" + +char * +geteltnm(int type) +{ + static char rbuf[132]; + + switch (type) { + case ELMTYP_UNSPECIFIED: + sprintf(rbuf, "Unspecified"); + break; + case ELMTYP_DEVICE: + sprintf(rbuf, "Device Slot"); + break; + case ELMTYP_POWER: + sprintf(rbuf, "Power Supply"); + break; + case ELMTYP_FAN: + sprintf(rbuf, "Cooling"); + break; + case ELMTYP_THERM: + sprintf(rbuf, "Temperature Sensor"); + break; + case ELMTYP_DOORLOCK: + sprintf(rbuf, "Door Lock"); + break; + case ELMTYP_ALARM: + sprintf(rbuf, "Audible alarm"); + break; + case ELMTYP_ESCC: + sprintf(rbuf, "Enclosure Services Controller Electronics"); + break; + case ELMTYP_SCC: + sprintf(rbuf, "SCC Controller Electronics"); + break; + case ELMTYP_NVRAM: + sprintf(rbuf, "Nonvolatile Cache"); + break; + case ELMTYP_INV_OP_REASON: + sprintf(rbuf, "Invalid Operation Reason"); + break; + case ELMTYP_UPS: + sprintf(rbuf, "Uninterruptible Power Supply"); + break; + case ELMTYP_DISPLAY: + sprintf(rbuf, "Display"); + break; + case ELMTYP_KEYPAD: + sprintf(rbuf, "Key Pad Entry"); + break; + case ELMTYP_ENCLOSURE: + sprintf(rbuf, "Enclosure"); + break; + case ELMTYP_SCSIXVR: + sprintf(rbuf, "SCSI Port/Transceiver"); + break; + case ELMTYP_LANGUAGE: + sprintf(rbuf, "Language"); + break; + case ELMTYP_COMPORT: + sprintf(rbuf, "Communication Port"); + break; + case ELMTYP_VOM: + sprintf(rbuf, "Voltage Sensor"); + break; + case ELMTYP_AMMETER: + sprintf(rbuf, "Current Sensor"); + break; + case ELMTYP_SCSI_TGT: + sprintf(rbuf, "SCSI Target Port"); + break; + case ELMTYP_SCSI_INI: + sprintf(rbuf, "SCSI Initiator Port"); + break; + case ELMTYP_SUBENC: + sprintf(rbuf, "Simple Subenclosure"); + break; + case ELMTYP_ARRAY_DEV: + sprintf(rbuf, "Array Device Slot"); + break; + case ELMTYP_SAS_EXP: + sprintf(rbuf, "SAS Expander"); + break; + case ELMTYP_SAS_CONN: + sprintf(rbuf, "SAS Connector"); + break; + default: + (void) sprintf(rbuf, "<Type 0x%x>", type); + break; + } + return (rbuf); +} + +static char * +scode2ascii(u_char code) +{ + static char rbuf[32]; + switch (code & 0xf) { + case SES_OBJSTAT_UNSUPPORTED: + sprintf(rbuf, "Unsupported"); + break; + case SES_OBJSTAT_OK: + sprintf(rbuf, "OK"); + break; + case SES_OBJSTAT_CRIT: + sprintf(rbuf, "Critical"); + break; + case SES_OBJSTAT_NONCRIT: + sprintf(rbuf, "Noncritical"); + break; + case SES_OBJSTAT_UNRECOV: + sprintf(rbuf, "Unrecoverable"); + break; + case SES_OBJSTAT_NOTINSTALLED: + sprintf(rbuf, "Not Installed"); + break; + case SES_OBJSTAT_UNKNOWN: + sprintf(rbuf, "Unknown"); + break; + case SES_OBJSTAT_NOTAVAIL: + sprintf(rbuf, "Not Available"); + break; + case SES_OBJSTAT_NOACCESS: + sprintf(rbuf, "No Access Allowed"); + break; + default: + sprintf(rbuf, "<Status 0x%x>", code & 0xf); + break; + } + return (rbuf); +} + + +char * +stat2ascii(int eletype __unused, u_char *cstat) +{ + static char ebuf[256], *scode; + + scode = scode2ascii(cstat[0]); + sprintf(ebuf, "status: %s%s%s%s (0x%02x 0x%02x 0x%02x 0x%02x)", + scode, + (cstat[0] & 0x40) ? ", Prd.Fail" : "", + (cstat[0] & 0x20) ? ", Disabled" : "", + (cstat[0] & 0x10) ? ", Swapped" : "", + cstat[0], cstat[1], cstat[2], cstat[3]); + return (ebuf); +} diff --git a/share/examples/ses/srcs/eltsub.h b/share/examples/ses/srcs/eltsub.h new file mode 100644 index 000000000000..0623b4ac1e5c --- /dev/null +++ b/share/examples/ses/srcs/eltsub.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ + +char * geteltnm(int); +char * stat2ascii(int, u_char *); diff --git a/share/examples/ses/srcs/getencstat.c b/share/examples/ses/srcs/getencstat.c new file mode 100644 index 000000000000..55a7a0e8edc4 --- /dev/null +++ b/share/examples/ses/srcs/getencstat.c @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ + +#include <unistd.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <cam/scsi/scsi_all.h> +#include <cam/scsi/scsi_enc.h> + +#include "eltsub.h" + +int +main(int a, char **v) +{ + encioc_string_t stri; + encioc_element_t *objp; + encioc_elm_status_t ob; + encioc_elm_desc_t objd; + encioc_elm_devnames_t objdn; + int fd, nobj, f, i, verbose, quiet, errors; + u_char estat; + char str[32]; + + if (a < 2) { + fprintf(stderr, "usage: %s [ -v ] device [ device ... ]\n", *v); + return (1); + } + errors = quiet = verbose = 0; + if (strcmp(v[1], "-V") == 0) { + verbose = 2; + v++; + } else if (strcmp(v[1], "-v") == 0) { + verbose = 1; + v++; + } else if (strcmp(v[1], "-q") == 0) { + quiet = 1; + verbose = 0; + v++; + } + while (*++v) { + + fd = open(*v, O_RDONLY); + if (fd < 0) { + perror(*v); + continue; + } + if (verbose > 1) { + stri.bufsiz = sizeof(str); + stri.buf = &str[0]; + if (ioctl(fd, ENCIOC_GETENCNAME, (caddr_t) &stri) == 0) + printf("%s: Enclosure Name: %s\n", *v, stri.buf); + stri.bufsiz = sizeof(str); + stri.buf = &str[0]; + if (ioctl(fd, ENCIOC_GETENCID, (caddr_t) &stri) == 0) + printf("%s: Enclosure ID: %s\n", *v, stri.buf); + } + if (ioctl(fd, ENCIOC_GETNELM, (caddr_t) &nobj) < 0) { + perror("ENCIOC_GETNELM"); + (void) close(fd); + continue; + } + if (ioctl(fd, ENCIOC_GETENCSTAT, (caddr_t) &estat) < 0) { + perror("ENCIOC_GETENCSTAT"); + (void) close(fd); + continue; + } + if ((verbose == 0 || quiet == 1) && estat == 0) { + if (quiet == 0) + fprintf(stdout, "%s: Enclosure OK\n", *v); + (void) close(fd); + continue; + } + fprintf(stdout, "%s: Enclosure Status ", *v); + if (estat == 0) { + fprintf(stdout, "<OK"); + } else { + errors++; + f = '<'; + if (estat & SES_ENCSTAT_INFO) { + fprintf(stdout, "%cINFO", f); + f = ','; + } + if (estat & SES_ENCSTAT_NONCRITICAL) { + fprintf(stdout, "%cNONCRITICAL", f); + f = ','; + } + if (estat & SES_ENCSTAT_CRITICAL) { + fprintf(stdout, "%cCRITICAL", f); + f = ','; + } + if (estat & SES_ENCSTAT_UNRECOV) { + fprintf(stdout, "%cUNRECOV", f); + f = ','; + } + } + fprintf(stdout, ">\n"); + objp = calloc(nobj, sizeof (encioc_element_t)); + if (objp == NULL) { + perror("calloc"); + (void) close(fd); + continue; + } + if (ioctl(fd, ENCIOC_GETELMMAP, (caddr_t) objp) < 0) { + perror("ENCIOC_GETELMMAP"); + (void) close(fd); + continue; + } + for (i = 0; i < nobj; i++) { + ob.elm_idx = objp[i].elm_idx; + if (ioctl(fd, ENCIOC_GETELMSTAT, (caddr_t) &ob) < 0) { + perror("ENCIOC_GETELMSTAT"); + (void) close(fd); + break; + } + bzero(&objd, sizeof(objd)); + objd.elm_idx = objp[i].elm_idx; + objd.elm_desc_len = UINT16_MAX; + objd.elm_desc_str = calloc(UINT16_MAX, sizeof(char)); + if (objd.elm_desc_str == NULL) { + perror("calloc"); + (void) close(fd); + continue; + } + if (ioctl(fd, ENCIOC_GETELMDESC, (caddr_t)&objd) < 0) { + perror("ENCIOC_GETELMDESC"); + (void) close(fd); + break; + } + bzero(&objdn, sizeof(objdn)); + objdn.elm_idx = objp[i].elm_idx; + objdn.elm_names_size = 128; + objdn.elm_devnames = calloc(128, sizeof(char)); + if (objdn.elm_devnames == NULL) { + perror("calloc"); + (void) close(fd); + break; + } + /* + * This ioctl isn't critical and has a good chance + * of returning -1. + */ + (void)ioctl(fd, ENCIOC_GETELMDEVNAMES, (caddr_t)&objdn); + fprintf(stdout, "Element 0x%x: %s", ob.elm_idx, + geteltnm(objp[i].elm_type)); + fprintf(stdout, ", %s", + stat2ascii(objp[i].elm_type, ob.cstat)); + if (objd.elm_desc_len > 0) + fprintf(stdout, ", descriptor: '%s'", + objd.elm_desc_str); + if (objdn.elm_names_len > 0) + fprintf(stdout, ", dev: '%s'", + objdn.elm_devnames); + fprintf(stdout, "\n"); + free(objdn.elm_devnames); + } + free(objp); + (void) close(fd); + } + return (errors); +} diff --git a/share/examples/ses/srcs/getnobj.c b/share/examples/ses/srcs/getnobj.c new file mode 100644 index 000000000000..6ad1bc892717 --- /dev/null +++ b/share/examples/ses/srcs/getnobj.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ + +#include <unistd.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <cam/scsi/scsi_all.h> +#include <cam/scsi/scsi_ses.h> + +int +main(int argc, char **argv) +{ + unsigned int nobj; + int fd; + + while (*++argv != NULL) { + char *name = *argv; + fd = open(name, O_RDONLY); + if (fd < 0) { + perror(name); + continue; + } + if (ioctl(fd, SESIOC_GETNOBJ, (caddr_t) &nobj) < 0) { + perror("SESIOC_GETNOBJ"); + } else { + fprintf(stdout, "%s: %d objects\n", name, nobj); + } + close (fd); + } + return (0); +} diff --git a/share/examples/ses/srcs/getobjmap.c b/share/examples/ses/srcs/getobjmap.c new file mode 100644 index 000000000000..a52484185d0e --- /dev/null +++ b/share/examples/ses/srcs/getobjmap.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ + +#include <unistd.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <cam/scsi/scsi_all.h> +#include <cam/scsi/scsi_ses.h> + +#include "eltsub.h" + +int +main(int a, char **v) +{ + ses_object *objp; + int nobj, fd, i; + + while (*++v) { + fd = open(*v, O_RDONLY); + if (fd < 0) { + perror(*v); + continue; + } + if (ioctl(fd, SESIOC_GETNOBJ, (caddr_t) &nobj) < 0) { + perror("SESIOC_GETNOBJ"); + (void) close(fd); + continue; + } + fprintf(stdout, "%s: %d objects\n", *v, nobj); + if (nobj == 0) { + (void) close(fd); + continue; + } + objp = calloc(nobj, sizeof (ses_object)); + if (objp == NULL) { + perror("calloc"); + (void) close(fd); + continue; + } + if (ioctl(fd, SESIOC_GETOBJMAP, (caddr_t) objp) < 0) { + perror("SESIOC_GETOBJMAP"); + (void) close(fd); + continue; + } + for (i = 0; i < nobj; i++) { + printf(" Object %d: ID 0x%x Type '%s'\n", i, + objp[i].obj_id, geteltnm((int)objp[i].object_type)); + } + free(objp); + (void) close(fd); + } + return (0); +} diff --git a/share/examples/ses/srcs/getobjstat.c b/share/examples/ses/srcs/getobjstat.c new file mode 100644 index 000000000000..83a5e6462961 --- /dev/null +++ b/share/examples/ses/srcs/getobjstat.c @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ +#include <unistd.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <cam/scsi/scsi_all.h> +#include <cam/scsi/scsi_ses.h> + +int +main(int a, char **v) +{ + int fd; + int i; + ses_objstat obj; + long cvt; + char *x; + + if (a != 3) { +usage: + fprintf(stderr, "usage: %s device objectid\n", *v); + return (1); + } + fd = open(v[1], O_RDONLY); + if (fd < 0) { + perror(v[1]); + return (1); + } + x = v[2]; + cvt = strtol(v[2], &x, 0); + if (x == v[2]) { + goto usage; + } + obj.obj_id = cvt; + if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t) &obj) < 0) { + perror("SESIOC_GETOBJSTAT"); + return (1); + } + fprintf(stdout, "Object 0x%x: 0x%x 0x%x 0x%x 0x%x\n", obj.obj_id, + obj.cstat[0], obj.cstat[1], obj.cstat[2], obj.cstat[3]); + (void) close(fd); + return (0); +} diff --git a/share/examples/ses/srcs/inienc.c b/share/examples/ses/srcs/inienc.c new file mode 100644 index 000000000000..f72e71552f7b --- /dev/null +++ b/share/examples/ses/srcs/inienc.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ + +#include <unistd.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <cam/scsi/scsi_all.h> +#include <cam/scsi/scsi_ses.h> + +int +main(int a, char **v) +{ + int fd; + + while (*++v) { + fd = open(*v, O_RDWR); + if (fd < 0) { + perror(*v); + continue; + } + if (ioctl(fd, SESIOC_INIT, NULL) < 0) { + perror("SESIOC_GETNOBJ"); + } + (void) close(fd); + } + return (0); +} diff --git a/share/examples/ses/srcs/sesd.c b/share/examples/ses/srcs/sesd.c new file mode 100644 index 000000000000..9a6cb8cfe34a --- /dev/null +++ b/share/examples/ses/srcs/sesd.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ +#include <unistd.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <syslog.h> +#include <unistd.h> +#include <sys/ioctl.h> +#include <cam/scsi/scsi_all.h> +#include <cam/scsi/scsi_enc.h> + +#define ALLSTAT (SES_ENCSTAT_UNRECOV | SES_ENCSTAT_CRITICAL | \ + SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO) + +/* + * Monitor named SES devices and note (via syslog) any changes in status. + */ + +int +main(int a, char **v) +{ + static const char *usage = + "usage: %s [ -c ] [ -d ] [ -t pollinterval ] device [ device ]\n"; + int fd, polltime, dev, nodaemon, clear, c; + encioc_enc_status_t stat, nstat, *carray; + + if (a < 2) { + fprintf(stderr, usage, *v); + return (1); + } + + nodaemon = 0; + polltime = 30; + clear = 0; + while ((c = getopt(a, v, "cdt:")) != -1) { + switch (c) { + case 'c': + clear = 1; + break; + case 'd': + nodaemon = 1; + break; + case 't': + polltime = atoi(optarg); + break; + default: + fprintf(stderr, usage, *v); + return (1); + } + } + + carray = malloc(a); + if (carray == NULL) { + perror("malloc"); + return (1); + } + for (dev = optind; dev < a; dev++) + carray[dev] = (encioc_enc_status_t) -1; + + /* + * Check to make sure we can open all devices + */ + for (dev = optind; dev < a; dev++) { + fd = open(v[dev], O_RDWR); + if (fd < 0) { + perror(v[dev]); + return (1); + } + if (ioctl(fd, ENCIOC_INIT, NULL) < 0) { + fprintf(stderr, "%s: ENCIOC_INIT fails- %s\n", + v[dev], strerror(errno)); + return (1); + } + (void) close(fd); + } + if (nodaemon == 0) { + if (daemon(0, 0) < 0) { + perror("daemon"); + return (1); + } + openlog("sesd", LOG_CONS, LOG_USER); + } else { + openlog("sesd", LOG_CONS|LOG_PERROR, LOG_USER); + } + + for (;;) { + for (dev = optind; dev < a; dev++) { + fd = open(v[dev], O_RDWR); + if (fd < 0) { + syslog(LOG_ERR, "%s: %m", v[dev]); + continue; + } + + /* + * Get the actual current enclosure status. + */ + if (ioctl(fd, ENCIOC_GETENCSTAT, (caddr_t) &stat) < 0) { + syslog(LOG_ERR, + "%s: ENCIOC_GETENCSTAT- %m", v[dev]); + (void) close(fd); + continue; + } + if (stat != 0 && clear) { + nstat = 0; + if (ioctl(fd, ENCIOC_SETENCSTAT, + (caddr_t) &nstat) < 0) { + syslog(LOG_ERR, + "%s: ENCIOC_SETENCSTAT- %m", v[dev]); + } + } + (void) close(fd); + + if (stat == carray[dev]) + continue; + + carray[dev] = stat; + if ((stat & ALLSTAT) == 0) { + syslog(LOG_NOTICE, + "%s: Enclosure Status OK", v[dev]); + } + if (stat & SES_ENCSTAT_INFO) { + syslog(LOG_NOTICE, + "%s: Enclosure Has Information", v[dev]); + } + if (stat & SES_ENCSTAT_NONCRITICAL) { + syslog(LOG_WARNING, + "%s: Enclosure Non-Critical", v[dev]); + } + if (stat & SES_ENCSTAT_CRITICAL) { + syslog(LOG_CRIT, + "%s: Enclosure Critical", v[dev]); + } + if (stat & SES_ENCSTAT_UNRECOV) { + syslog(LOG_ALERT, + "%s: Enclosure Unrecoverable", v[dev]); + } + } + sleep(polltime); + } + /* NOTREACHED */ +} diff --git a/share/examples/ses/srcs/setencstat.c b/share/examples/ses/srcs/setencstat.c new file mode 100644 index 000000000000..dbfbaf27aacb --- /dev/null +++ b/share/examples/ses/srcs/setencstat.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ + +#include <unistd.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <cam/scsi/scsi_all.h> +#include <cam/scsi/scsi_enc.h> + +int +main(int a, char **v) +{ + int fd; + long val; + encioc_enc_status_t stat; + + if (a != 3) { + fprintf(stderr, "usage: %s device enclosure_status\n", *v); + return (1); + } + fd = open(v[1], O_RDWR); + if (fd < 0) { + perror(v[1]); + return (1); + } + + val = strtol(v[2], NULL, 0); + stat = (encioc_enc_status_t)val; + if (ioctl(fd, ENCIOC_SETENCSTAT, (caddr_t) &stat) < 0) { + perror("ENCIOC_SETENCSTAT"); + } + (void) close(fd); + return (0); +} diff --git a/share/examples/ses/srcs/setobjstat.c b/share/examples/ses/srcs/setobjstat.c new file mode 100644 index 000000000000..e5d374e5252a --- /dev/null +++ b/share/examples/ses/srcs/setobjstat.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2000 by Matthew Jacob + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification, immediately at the beginning of the file. + * 2. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * the GNU Public License ("GPL"). + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Matthew Jacob + * Feral Software + * mjacob@feral.com + */ + +#include <unistd.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <cam/scsi/scsi_all.h> +#include <cam/scsi/scsi_enc.h> + +int +main(int a, char **v) +{ + int fd; + int i; + encioc_elm_status_t obj; + long cvt; + char *x; + + if (a != 7) { +usage: + fprintf(stderr, + "usage: %s device objectid stat0 stat1 stat2 stat3\n", *v); + return (1); + } + fd = open(v[1], O_RDWR); + if (fd < 0) { + perror(v[1]); + return (1); + } + x = v[2]; + cvt = strtol(v[2], &x, 0); + if (x == v[2]) { + goto usage; + } + obj.elm_idx = cvt; + for (i = 0; i < 4; i++) { + x = v[3 + i]; + cvt = strtol(v[3 + i], &x, 0); + if (x == v[3 + i]) { + goto usage; + } + obj.cstat[i] = cvt; + } + if (ioctl(fd, ENCIOC_SETELMSTAT, (caddr_t) &obj) < 0) { + perror("ENCIOC_SETELMSTAT"); + } + (void) close(fd); + return (0); +} |