Page MenuHomeFreeBSD

D3544.id8395.diff
No OneTemporary

D3544.id8395.diff

Index: usr.sbin/Makefile
===================================================================
--- usr.sbin/Makefile
+++ usr.sbin/Makefile
@@ -74,6 +74,7 @@
rtprio \
service \
services_mkdb \
+ sesutil \
setfib \
setfmac \
setpmac \
Index: usr.sbin/sesutil/Makefile
===================================================================
--- /dev/null
+++ usr.sbin/sesutil/Makefile
@@ -0,0 +1,4 @@
+PROG= sesutil
+MAN= sesutil.8
+
+.include <bsd.prog.mk>
Index: usr.sbin/sesutil/sesutil.8
===================================================================
--- /dev/null
+++ usr.sbin/sesutil/sesutil.8
@@ -0,0 +1,73 @@
+.\" Copyright (c) 2015 Baptiste Daroussin <bapt@FreeBSD.org>
+.\" 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.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd September 1, 2015
+.Dt SESUTIL 8
+.Os
+.Sh NAME
+.Nm sesutil
+.Nd Utility for managing SCSI Enclosure Services (SES) device
+.Sh SYNOPSIS
+.Nm
+.Cm locate Ar disk Bq on|off
+.Sh DESCRIPTION
+The
+.Nm
+utility can be used to modify various parameter on SCSI Enclosure Services
+(SES) device.
+.Pp
+List of supported commands:
+.Bl -tag -width indent
+.It Cm locate Ar disk Bq on|off
+Change the state of the external LED associated with
+.Ar disk .
+.Ar disk
+Should be either the device name of the disk, like
+.Cm da12 ,
+or
+.Cm all .
+to indicate all disks attached to SES controllers.
+.El
+.Sh EXAMPLES
+Turn off all external LEDs:
+.Pp
+.Dl Nm Cm locate all off
+.Pp
+Turn on the external LED of drive
+.Pa da15 :
+.Pp
+.Dl Nm Cm locate da15 on
+.Sh SEE ALSO
+.Xr ses 4
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Fx 11.0 .
+.Sh AUTHORS
+The
+.Nm utility was written by
+.An Baptiste Daroussin Aq Mt bapt@FreeBSD.org .
Index: usr.sbin/sesutil/sesutil.c
===================================================================
--- /dev/null
+++ usr.sbin/sesutil/sesutil.c
@@ -0,0 +1,198 @@
+/*-
+ * Copyright (c) 2015 Baptiste Daroussin <bapt@FreeBSD.org>
+ * 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
+ * in this position and unchanged.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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(S) 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
+
+static int locate(int argc, char **argv);
+
+static struct command {
+ const char *name;
+ const char *desc;
+ int (*exec)(int argc, char **argv);
+} cmds[] = {
+ { "locate", "Change the state of the external LED associated with a"
+ " disk", locate} ,
+};
+
+static const unsigned int nbcmds = nitems(cmds);
+
+static void
+do_locate(int fd, unsigned int idx, unsigned int cmd)
+{
+ encioc_elm_status_t o;
+
+ o.elm_idx = idx;
+ o.cstat[0] = 0x80;
+ o.cstat[1] = 0x00;
+ o.cstat[2] = cmd;
+ o.cstat[3] = 0x00;
+
+ if (ioctl(fd, ENCIOC_SETELMSTAT, (caddr_t) &o) < 0) {
+ close(fd);
+ err(EXIT_FAILURE, "ENCIOC_SETELMSTAT");
+ }
+}
+
+static int
+locate(int argc, char **argv)
+{
+ int fd, nobj, i, j;
+ char sespath[MAXPATHLEN];
+ encioc_elm_devnames_t objdn, *obj = NULL;
+ encioc_element_t *objp;
+ encioc_elm_status_t o;
+ char *devname, *disk;
+ int locate;
+ bool all = false;
+
+ if (argc != 2) {
+ errx(EXIT_FAILURE, "usage: %s locate [disk] [on|off]",
+ getprogname());
+ }
+
+ disk = argv[0];
+
+ if (strcmp(argv[1], "on") == 0) {
+ locate = 0x02;
+ } else if (strcmp(argv[1], "off") == 0) {
+ locate = 0x00;
+ } else {
+ errx(EXIT_FAILURE, "usage: %s locate [disk] [on|off]",
+ getprogname());
+ }
+
+ if (strcmp(disk, "all") == 0) {
+ all = true;
+ }
+
+ i = 0;
+ for (;;) {
+ snprintf(sespath, sizeof(sespath), "/dev/ses%d", i);
+ if ((fd = open(sespath, O_RDWR)) < 0) {
+ if (errno == EACCES)
+ err(EXIT_FAILURE, "enable to access SES device");
+ break;
+ }
+
+ if (ioctl(fd, ENCIOC_GETNELM, (caddr_t) &nobj) < 0)
+ err(EXIT_FAILURE, "ENCIOC_GETNELM");
+
+ objp = calloc(nobj, sizeof(encioc_element_t));
+ if (objp == NULL)
+ err(EXIT_FAILURE, "calloc()");
+
+ if (ioctl(fd, ENCIOC_GETELMMAP, (caddr_t) objp) < 0)
+ err(EXIT_FAILURE, "ENCIOC_GETELMMAP");
+
+ for (j = 0; j < nobj; j++) {
+ memset(&objdn, 0, sizeof(objdn));
+ objdn.elm_idx = objp[j].elm_idx;
+ objdn.elm_names_size = 128;
+ objdn.elm_devnames = calloc(128, sizeof(char));
+ if (objdn.elm_devnames == NULL)
+ err(EXIT_FAILURE, "calloc()");
+ if (ioctl(fd, ENCIOC_GETELMDEVNAMES,
+ (caddr_t) &objdn) <0)
+ continue;
+ if (objdn.elm_names_len > 0) {
+ if (all) {
+ do_locate(fd, objdn.elm_idx, locate);
+ } else if ((devname = strstr(objdn.elm_devnames,
+ disk)) != NULL) {
+ if (strcmp(devname, disk) == 0) {
+ do_locate(fd, objdn.elm_idx,
+ locate);
+ break;
+ }
+ }
+ }
+ }
+ close(fd);
+ i++;
+ }
+
+ return (EXIT_SUCCESS);
+}
+
+static void
+usage(FILE *out)
+{
+ int i = 0;
+
+ fprintf(out, "Usage: %s [command] [options]\n", getprogname());
+ fprintf(out, "Commands supported:\n");
+ for (i = 0; i < nbcmds; i++)
+ fprintf(out, "\t%-15s%s\n", cmds[i].name, cmds[i].desc);
+}
+
+int
+main(int argc, char **argv)
+{
+ int i;
+ struct command *cmd = NULL;
+
+ if (argc < 2) {
+ warnx("Missing command");
+ usage(stderr);
+ return (EXIT_FAILURE);
+ }
+
+ for (i = 0; i < nbcmds; i++) {
+ if (strcmp(argv[1], cmds[i].name) == 0) {
+ cmd = &cmds[i];
+ break;
+ }
+ }
+
+ if (cmd == NULL) {
+ warnx("unknown command %s", argv[1]);
+ usage(stderr);
+ return (EXIT_FAILURE);
+ }
+
+ argc-=2;
+ argv+=2;
+
+ return (cmd->exec(argc, argv));
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Mar 26, 2:29 AM (8 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
30359989
Default Alt Text
D3544.id8395.diff (8 KB)

Event Timeline