summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Peereboom <marco@cvs.openbsd.org>2005-04-04 22:43:08 +0000
committerMarco Peereboom <marco@cvs.openbsd.org>2005-04-04 22:43:08 +0000
commite068b33461fe4314ddd73634b9801621a1ef8372 (patch)
tree5617414b0b903ef00daacd65f2bef183f4a341a0
parentb8cf5a59c4b9c5133225a1632b01dd52d86f7fc1 (diff)
Add initial blink/unblink harness.
Fix INQUIRY namespace polution. Little clean up and new debug messages.
-rw-r--r--sbin/bioctl/bioctl.86
-rw-r--r--sbin/bioctl/bioctl.c97
-rw-r--r--sbin/bioctl/bioctl.h11
3 files changed, 94 insertions, 20 deletions
diff --git a/sbin/bioctl/bioctl.8 b/sbin/bioctl/bioctl.8
index f793c592a2f..482c8f1b4f3 100644
--- a/sbin/bioctl/bioctl.8
+++ b/sbin/bioctl/bioctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: bioctl.8,v 1.4 2005/04/01 15:59:20 jmc Exp $
+.\" $OpenBSD: bioctl.8,v 1.5 2005/04/04 22:43:07 marco Exp $
.\"
.\" Copyright (c) 2004, 2005 Marco Peereboom
.\"
@@ -46,6 +46,10 @@ The options are as follows:
Get or set alarm state.
Supported functions are: silence/quiet, enable, disable, get, and test.
Or use the first letter of the function.
+.It Fl b Ar function
+Blink or unblink hard drive LED, if supported by the enclosure.
+Supported functions are: blink and unblink.
+Or use the first letter of the function.
.It Fl D
Enable debug output.
.It Fl d Ar device
diff --git a/sbin/bioctl/bioctl.c b/sbin/bioctl/bioctl.c
index c8c69ba295b..3c64075f691 100644
--- a/sbin/bioctl/bioctl.c
+++ b/sbin/bioctl/bioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bioctl.c,v 1.3 2005/04/04 17:37:17 marco Exp $ */
+/* $OpenBSD: bioctl.c,v 1.4 2005/04/04 22:43:07 marco Exp $ */
/*
* Copyright (c) 2004, 2005 Marco Peereboom
* All rights reserved.
@@ -26,6 +26,7 @@
*
*/
+#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -35,6 +36,7 @@
#include <sys/param.h>
#include <sys/queue.h>
#include <scsi/scsi_disk.h>
+#include <scsi/scsi_all.h>
#include <dev/biovar.h>
#include "bioctl.h"
@@ -81,12 +83,16 @@ main(int argc, char *argv[])
atexit(cleanup);
- while ((ch = getopt(argc, argv, "a:Dd:ehl:pst:u:")) != -1) {
+ while ((ch = getopt(argc, argv, "a:b:Dd:ehl:pst:u:")) != -1) {
switch (ch) {
case 'a': /* alarm */
func |= BIOC_ALARM;
al_arg = optarg;
break;
+ case 'b': /* LED blink/unblink */
+ func |= BIOC_BLINK;
+ al_arg = optarg;
+ break;
case 'D': /* enable debug */
debug = 1;
@@ -98,7 +104,7 @@ main(int argc, char *argv[])
case 'e': /* enumerate */
func |= BIOC_SCSICMD;
- subfunc |= ENUM;
+ subfunc |= F_ENUM;
break;
case 'l': /* device list, separated for now use one dev only*/
@@ -157,6 +163,15 @@ main(int argc, char *argv[])
else
warnx("alarms are not supported.");
+ if (func & BIOC_BLINK)
+ if (bc.ioctls & BIOC_BLINK)
+ SLIST_FOREACH(delm, &ul, next) {
+ bio_blink(al_arg, delm->channel,
+ delm->target);
+ }
+ else
+ warnx("blink is not supported.");
+
if (func & BIOC_PING)
if (bc.ioctls & BIOC_PING)
bio_ping();
@@ -182,28 +197,28 @@ main(int argc, char *argv[])
if (func & BIOC_SCSICMD) {
if (bc.ioctls & BIOC_SCSICMD) {
- if (subfunc & READCAP) {
+ if (subfunc & F_READCAP) {
SLIST_FOREACH(delm, &ul, next) {
bio_pt_readcap(delm->channel,
delm->target);
}
}
- if (subfunc & INQUIRY) {
+ if (subfunc & F_INQUIRY) {
SLIST_FOREACH(delm, &ul, next) {
bio_pt_inquire(delm->channel,
delm->target, &inq[0]);
}
}
- if (subfunc & TUR) {
+ if (subfunc & F_TUR) {
SLIST_FOREACH(delm, &ul, next) {
bio_pt_tur(delm->channel,
delm->target);
}
}
- if (subfunc & ENUM)
+ if (subfunc & F_ENUM)
bio_pt_enum();
} else
warnx("passthrough not supported.");
@@ -218,8 +233,13 @@ usage(void)
{
extern char *__progname;
- fprintf(stderr, "usage: %s [-Dehpt] [-a alarm function] [-s get status]"
- "[-t passthrough] [-l device list] [-u go/stop function ] "
+ fprintf(stderr, "usage: %s [-Dehpt] "
+ "[-a alarm function] "
+ "[-b blink function] "
+ "[-s get status] "
+ "[-t passthrough] "
+ "[-l device list] "
+ "[-u go/stop function ] "
"-d raid device\n", __progname);
exit(1);
@@ -263,22 +283,22 @@ parse_passthru(char *f)
case 'i': /* INQUIRY */
if (debug)
printf("inquiry\n");
- return (INQUIRY);
+ return (F_INQUIRY);
case 'e': /* ENUMERATE, not a pass through hmmm */
if (debug)
printf("enumerate\n");
- return (ENUM);
+ return (F_ENUM);
case 'r': /* READ CAPACITY */
if (debug)
printf("read cap\n");
- return (READCAP);
+ return (F_READCAP);
case 't': /* TUR */
if (debug)
printf("TUR\n");
- return (TUR);
+ return (F_TUR);
default:
errx(1, "invalid pass through function");
@@ -422,6 +442,47 @@ bio_alarm(char *arg)
}
void
+bio_blink(char * arg, u_int8_t c, u_int8_t t)
+{
+ int rv;
+ bioc_blink bb;
+
+ if (debug)
+ printf("blink in: %s, ", arg);
+
+ bb.cookie = bl.cookie;
+
+ switch (arg[0]) {
+ case 'b': /* blink hdd */
+ if (debug)
+ printf("blink\n");
+ bb.opcode = BIOCSBLINK_BLINK;
+ break;
+
+ case 'u': /* unblink hdd */
+ if (debug)
+ printf("unblink\n");
+ bb.opcode = BIOCSBLINK_UNBLINK;
+ break;
+
+ default:
+ warnx("invalid blink function: %s", arg);
+ return;
+ }
+
+ rv = ioctl(devh, BIOCBLINK, &bb);
+ if (rv == -1) {
+ if (errno == EOPNOTSUPP) {
+ /* operation is not supported in kernel, do it here */
+ if (debug)
+ printf("doing blink in userland\n");
+ }
+ else
+ warnx("bioc_ioctl() call failed");
+ }
+}
+
+void
bio_ping(void)
{
int rv;
@@ -531,6 +592,9 @@ bio_pt_readcap(u_int8_t c, u_int8_t t)
else if (bpt.status) {
if (bpt.sensebuf[0] == 0x70 || bpt.sensebuf[0] == 0x71)
print_sense(&bpt.sensebuf[0], bpt.senselen);
+ else
+ printf("read capacity failed without sense data\n");
+
return (0);
}
@@ -574,6 +638,8 @@ bio_pt_inquire(u_int8_t c, u_int8_t t, u_int8_t *inq)
else if (bpt.status) {
if (bpt.sensebuf[0] == 0x70 || bpt.sensebuf[0] == 0x71)
print_sense(&bpt.sensebuf[0], bpt.senselen);
+ else
+ printf("inquiry failed without sense data\n");
return 0;
}
@@ -608,6 +674,7 @@ bio_pt_tur(u_int8_t c, u_int8_t t)
bpt.channel = c;
bpt.target = t;
bpt.cdblen = 6;
+ bpt.cdb[0] = TEST_UNIT_READY;
bpt.direction = BIOC_DIRNONE;
rv = ioctl(devh, BIOCSCSICMD, &bpt);
if (rv == -1) {
@@ -618,6 +685,8 @@ bio_pt_tur(u_int8_t c, u_int8_t t)
if (bpt.status) {
if (bpt.sensebuf[0] == 0x70 || bpt.sensebuf[0] == 0x71)
print_sense(&bpt.sensebuf[0], bpt.senselen);
+ else
+ printf("tur failed without sense data\n");
return (0);
}
@@ -636,7 +705,7 @@ bio_pt_enum(void)
bioc_scsicmd bpt;
u_int32_t c, t, i, d;
int rv;
- unsigned char inq[36];
+ u_int8_t inq[36];
struct dev *delm;
diff --git a/sbin/bioctl/bioctl.h b/sbin/bioctl/bioctl.h
index 2ed3e9c6d09..6dbec8aeb82 100644
--- a/sbin/bioctl/bioctl.h
+++ b/sbin/bioctl/bioctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bioctl.h,v 1.1 2005/04/04 17:36:46 marco Exp $ */
+/* $OpenBSD: bioctl.h,v 1.2 2005/04/04 22:43:07 marco Exp $ */
/*
* Copyright (c) 2004, 2005 Marco Peereboom
* All rights reserved.
@@ -28,10 +28,10 @@
#ifndef _BIOCTL_H_
#define _BIOCTL_H_
-#define READCAP 0x01
-#define ENUM 0x02
-#define TUR 0x04
-#define INQUIRY 0x08
+#define F_READCAP 0x01
+#define F_ENUM 0x02
+#define F_TUR 0x04
+#define F_INQUIRY 0x08
#define PARSELIST (0x8000000000000000llu)
@@ -56,6 +56,7 @@ void print_sense(u_int8_t *, u_int8_t);
int bio_get_capabilities(bioc_capabilities *);
void bio_alarm(char *);
+void bio_blink(char *, u_int8_t, u_int8_t);
void bio_ping(void);
void bio_startstop(char *, u_int8_t, u_int8_t);
void bio_status(void);