Add a minimal example set of how to use the SES ioctls to monitor
SES/SAF-TE devices. It's usable enough (in chpmon) to be alerted as you'd like to be if a powersupply goes south.
This commit is contained in:
parent
9c1f8f49ec
commit
60f2f4e3df
61
share/examples/ses/Makefile
Normal file
61
share/examples/ses/Makefile
Normal file
@ -0,0 +1,61 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
CFLAGS = -O
|
||||
|
||||
SUB = eltsub.o
|
||||
ALL = getnobj getobjmap getencstat inienc setencstat \
|
||||
setobjstat getobjstat chpmon
|
||||
|
||||
all: ${ALL} ${SUB}
|
||||
|
||||
getnobj: getnobj.o ${SUB}
|
||||
$(CC) -o $@ $@.o ${SUB}
|
||||
|
||||
getobjmap: getobjmap.o ${SUB}
|
||||
$(CC) -o $@ $@.o ${SUB}
|
||||
|
||||
getencstat: getencstat.o ${SUB}
|
||||
$(CC) -o $@ $@.o ${SUB}
|
||||
|
||||
inienc: inienc.o ${SUB}
|
||||
$(CC) -o $@ $@.o ${SUB}
|
||||
|
||||
chpmon: chpmon.o ${SUB}
|
||||
$(CC) -o $@ $@.o ${SUB}
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
-rm -f *.o ${ALL}
|
126
share/examples/ses/chpmon.c
Normal file
126
share/examples/ses/chpmon.c
Normal file
@ -0,0 +1,126 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* 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 <cam/scsi/scsi_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);
|
||||
}
|
||||
memset(carray, 0, 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 */
|
||||
}
|
163
share/examples/ses/eltsub.c
Normal file
163
share/examples/ses/eltsub.c
Normal file
@ -0,0 +1,163 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* 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 <sys/ioctl.h>
|
||||
#include <cam/scsi/scsi_ses.h>
|
||||
|
||||
char *
|
||||
geteltnm(int type)
|
||||
{
|
||||
static char rbuf[132];
|
||||
|
||||
switch (type) {
|
||||
case SESTYP_UNSPECIFIED:
|
||||
sprintf(rbuf, "Unspecified");
|
||||
break;
|
||||
case SESTYP_DEVICE:
|
||||
sprintf(rbuf, "Device");
|
||||
break;
|
||||
case SESTYP_POWER:
|
||||
sprintf(rbuf, "Power supply");
|
||||
break;
|
||||
case SESTYP_FAN:
|
||||
sprintf(rbuf, "Cooling element");
|
||||
break;
|
||||
case SESTYP_THERM:
|
||||
sprintf(rbuf, "Temperature sensors");
|
||||
break;
|
||||
case SESTYP_DOORLOCK:
|
||||
sprintf(rbuf, "Door Lock");
|
||||
break;
|
||||
case SESTYP_ALARM:
|
||||
sprintf(rbuf, "Audible alarm");
|
||||
break;
|
||||
case SESTYP_ESCC:
|
||||
sprintf(rbuf, "Enclosure services controller electronics");
|
||||
break;
|
||||
case SESTYP_SCC:
|
||||
sprintf(rbuf, "SCC controller electronics");
|
||||
break;
|
||||
case SESTYP_NVRAM:
|
||||
sprintf(rbuf, "Nonvolatile cache");
|
||||
break;
|
||||
case SESTYP_UPS:
|
||||
sprintf(rbuf, "Uninterruptible power supply");
|
||||
break;
|
||||
case SESTYP_DISPLAY:
|
||||
sprintf(rbuf, "Display");
|
||||
break;
|
||||
case SESTYP_KEYPAD:
|
||||
sprintf(rbuf, "Key pad entry device");
|
||||
break;
|
||||
case SESTYP_SCSIXVR:
|
||||
sprintf(rbuf, "SCSI port/transceiver");
|
||||
break;
|
||||
case SESTYP_LANGUAGE:
|
||||
sprintf(rbuf, "Language");
|
||||
break;
|
||||
case SESTYP_COMPORT:
|
||||
sprintf(rbuf, "Communication Port");
|
||||
break;
|
||||
case SESTYP_VOM:
|
||||
sprintf(rbuf, "Voltage Sensor");
|
||||
break;
|
||||
case SESTYP_AMMETER:
|
||||
sprintf(rbuf, "Current Sensor");
|
||||
break;
|
||||
case SESTYP_SCSI_TGT:
|
||||
sprintf(rbuf, "SCSI target port");
|
||||
break;
|
||||
case SESTYP_SCSI_INI:
|
||||
sprintf(rbuf, "SCSI initiator port");
|
||||
break;
|
||||
case SESTYP_SUBENC:
|
||||
sprintf(rbuf, "Simple sub-enclosure");
|
||||
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, "status not supported");
|
||||
break;
|
||||
case SES_OBJSTAT_OK:
|
||||
sprintf(rbuf, "ok");
|
||||
break;
|
||||
case SES_OBJSTAT_CRIT:
|
||||
sprintf(rbuf, "critical");
|
||||
break;
|
||||
case SES_OBJSTAT_NONCRIT:
|
||||
sprintf(rbuf, "non-critical");
|
||||
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 status");
|
||||
break;
|
||||
case SES_OBJSTAT_NOTAVAIL:
|
||||
sprintf(rbuf, "status not available");
|
||||
break;
|
||||
default:
|
||||
sprintf(rbuf, "unknown status code %x", code & 0xf);
|
||||
break;
|
||||
}
|
||||
return (rbuf);
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
stat2ascii(int eletype, u_char *cstat)
|
||||
{
|
||||
static char ebuf[256], *scode;
|
||||
|
||||
scode = scode2ascii(cstat[0]);
|
||||
sprintf(ebuf, "Status=%s (bytes=0x%02x 0x%02x 0x%02x 0x%02x)",
|
||||
scode, cstat[0], cstat[1], cstat[2], cstat[3]);
|
||||
return (ebuf);
|
||||
}
|
153
share/examples/ses/getencstat.c
Normal file
153
share/examples/ses/getencstat.c
Normal file
@ -0,0 +1,153 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* 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 <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <cam/scsi/scsi_ses.h>
|
||||
|
||||
extern char *geteltnm(int);
|
||||
extern char *stat2ascii(int, u_char *);
|
||||
|
||||
int
|
||||
main(int a, char **v)
|
||||
{
|
||||
ses_object *objp;
|
||||
ses_objstat ob;
|
||||
int fd, nobj, f, i, verbose, quiet, errors;
|
||||
u_char estat;
|
||||
|
||||
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 (ioctl(fd, SESIOC_GETNOBJ, (caddr_t) &nobj) < 0) {
|
||||
perror("SESIOC_GETNOBJ");
|
||||
(void) close(fd);
|
||||
continue;
|
||||
}
|
||||
if (ioctl(fd, SESIOC_GETENCSTAT, (caddr_t) &estat) < 0) {
|
||||
perror("SESIOC_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 (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++) {
|
||||
ob.obj_id = objp[i].obj_id;
|
||||
if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t) &ob) < 0) {
|
||||
perror("SESIOC_GETOBJSTAT");
|
||||
(void) close(fd);
|
||||
break;
|
||||
}
|
||||
if ((ob.cstat[0] & 0xf) == SES_OBJSTAT_OK) {
|
||||
if (verbose) {
|
||||
fprintf(stdout,
|
||||
"%s Element(%x): OK (%s)\n",
|
||||
geteltnm(objp[i].object_type),
|
||||
ob.obj_id,
|
||||
stat2ascii(objp[i].object_type,
|
||||
ob.cstat));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
fprintf(stdout, "%s Element(%x): %s\n",
|
||||
geteltnm(objp[i].object_type), ob.obj_id,
|
||||
stat2ascii(objp[i].object_type, ob.cstat));
|
||||
}
|
||||
free(objp);
|
||||
(void) close(fd);
|
||||
}
|
||||
return (errors);
|
||||
}
|
64
share/examples/ses/getnobj.c
Normal file
64
share/examples/ses/getnobj.c
Normal file
@ -0,0 +1,64 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* 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 <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.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);
|
||||
}
|
85
share/examples/ses/getobjmap.c
Normal file
85
share/examples/ses/getobjmap.c
Normal file
@ -0,0 +1,85 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* 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 <sys/ioctl.h>
|
||||
#include <cam/scsi/scsi_ses.h>
|
||||
|
||||
extern char *geteltnm(int);
|
||||
|
||||
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);
|
||||
}
|
74
share/examples/ses/getobjstat.c
Normal file
74
share/examples/ses/getobjstat.c
Normal file
@ -0,0 +1,74 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* 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 <sys/ioctl.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);
|
||||
}
|
59
share/examples/ses/inienc.c
Normal file
59
share/examples/ses/inienc.c
Normal file
@ -0,0 +1,59 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* 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 <sys/ioctl.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);
|
||||
}
|
82
share/examples/ses/setencstat.c
Normal file
82
share/examples/ses/setencstat.c
Normal file
@ -0,0 +1,82 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* 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 <sys/ioctl.h>
|
||||
#include <cam/scsi/scsi_ses.h>
|
||||
|
||||
int
|
||||
main(int a, char **v)
|
||||
{
|
||||
int fd;
|
||||
u_char stat;
|
||||
|
||||
if (a != 3) {
|
||||
fprintf(stderr, "usage: %s device {enclosure_status|-p}\n", *v);
|
||||
return (1);
|
||||
}
|
||||
fd = open(v[1], O_RDWR);
|
||||
if (fd < 0) {
|
||||
perror(v[1]);
|
||||
return (1);
|
||||
}
|
||||
if (strcmp(v[2], "-p") == 0) {
|
||||
/*
|
||||
* First clear any enclosure status, in case it is
|
||||
* a latched status.
|
||||
*/
|
||||
stat = 0;
|
||||
if (ioctl(fd, SESIOC_SETENCSTAT, (caddr_t) &stat) < 0) {
|
||||
perror("SESIOC_SETENCSTAT (pre)");
|
||||
return (1);
|
||||
}
|
||||
/*
|
||||
* Now get the actual current enclosure status.
|
||||
*/
|
||||
if (ioctl(fd, SESIOC_GETENCSTAT, (caddr_t) &stat) < 0) {
|
||||
perror("SESIOC_GETENCSTAT");
|
||||
return (1);
|
||||
}
|
||||
} else {
|
||||
stat = atoi(v[2]);
|
||||
}
|
||||
if (ioctl(fd, SESIOC_SETENCSTAT, (caddr_t) &stat) < 0) {
|
||||
perror("SESIOC_SETENCSTAT");
|
||||
}
|
||||
(void) close(fd);
|
||||
return (0);
|
||||
}
|
81
share/examples/ses/setobjstat.c
Normal file
81
share/examples/ses/setobjstat.c
Normal file
@ -0,0 +1,81 @@
|
||||
/* $FreeBSD$ */
|
||||
/*
|
||||
* 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 <sys/ioctl.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 != 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.obj_id = 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, SESIOC_SETOBJSTAT, (caddr_t) &obj) < 0) {
|
||||
perror("SESIOC_SETOBJSTAT");
|
||||
}
|
||||
(void) close(fd);
|
||||
return (0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user