diff options
author | Marco Peereboom <marco@cvs.openbsd.org> | 2005-08-01 16:39:23 +0000 |
---|---|---|
committer | Marco Peereboom <marco@cvs.openbsd.org> | 2005-08-01 16:39:23 +0000 |
commit | dfc6bad51b90c0a2c39b15551e4fa13422bd16b9 (patch) | |
tree | 5a1ed8aa7f5de41041c0c304c733f7e398f457d1 /sbin | |
parent | c9621e5d79e4c8eacf6fb86ae67d7aa5b01651da (diff) |
Add alarm support.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/bioctl/bioctl.c | 75 | ||||
-rw-r--r-- | sbin/bioctl/bioctl.h | 3 |
2 files changed, 74 insertions, 4 deletions
diff --git a/sbin/bioctl/bioctl.c b/sbin/bioctl/bioctl.c index 08bc98bfa4a..6d536b2357f 100644 --- a/sbin/bioctl/bioctl.c +++ b/sbin/bioctl/bioctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bioctl.c,v 1.16 2005/07/29 16:01:18 marco Exp $ */ +/* $OpenBSD: bioctl.c,v 1.17 2005/08/01 16:39:22 marco Exp $ */ /* * Copyright (c) 2004, 2005 Marco Peereboom * All rights reserved. @@ -66,14 +66,20 @@ main(int argc, char *argv[]) char *bioc_dev = NULL; char *sd_dev = NULL; char *realname = NULL; + char *al_arg = NULL; /* argument to alarm */ if (argc < 2) usage(); atexit(cleanup); - while ((ch = getopt(argc, argv, "Dd:f:hi")) != -1) { + while ((ch = getopt(argc, argv, "a:Dd:f:hi")) != -1) { switch (ch) { + case 'a': /* alarm */ + func |= BIOC_ALARM; + al_arg = optarg; + break; + case 'D': /* debug */ debug = 1; break; @@ -123,6 +129,8 @@ main(int argc, char *argv[]) if (func & BIOC_INQ) { bio_inq(); + } else if (func == BIOC_ALARM) { + bio_alarm(al_arg); } return (0); @@ -133,7 +141,7 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-Dhi] [-d device | -f disk]\n", __progname); + fprintf(stderr, "usage: %s [-aDhi] [-d device | -f disk]\n", __progname); exit(1); } @@ -257,3 +265,64 @@ bio_inq(void) printf("\n"); } } + +void +bio_alarm(char *arg) +{ + int rv; + bioc_alarm ba; + + if (debug) + printf("alarm in: %s, ", arg); + + ba.cookie = bl.cookie; + + switch (arg[0]) { + case 'q': /* silence alarm */ + /* FALLTHROUGH */ + case 's': + if (debug) + printf("silence\n"); + ba.opcode = BIOC_SASILENCE; + break; + + case 'e': /* enable alarm */ + if (debug) + printf("enable\n"); + ba.opcode = BIOC_SAENABLE; + break; + + case 'd': /* disable alarm */ + if (debug) + printf("disable\n"); + ba.opcode = BIOC_SADISABLE; + break; + + case 't': /* test alarm */ + if (debug) + printf("test\n"); + ba.opcode = BIOC_SATEST; + break; + + case 'g': /* get alarm state */ + if (debug) + printf("get state\n"); + ba.opcode = BIOC_GASTATUS; + break; + + default: + warnx("invalid alarm function: %s", arg); + return; + } + + rv = ioctl(devh, BIOCALARM, &ba); + if (rv == -1) { + warnx("bioc_ioctl() call failed"); + return; + } + + if (arg[0] == 'g') { + printf("alarm is currently %s\n", + ba.status ? "enabled" : "disabled"); + } +} diff --git a/sbin/bioctl/bioctl.h b/sbin/bioctl/bioctl.h index 411c3ab67a4..21daec37792 100644 --- a/sbin/bioctl/bioctl.h +++ b/sbin/bioctl/bioctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bioctl.h,v 1.9 2005/07/29 16:01:18 marco Exp $ */ +/* $OpenBSD: bioctl.h,v 1.10 2005/08/01 16:39:22 marco Exp $ */ /* * Copyright (c) 2004, 2005 Marco Peereboom * All rights reserved. @@ -41,5 +41,6 @@ void usage(void); void cleanup(void); void bio_inq(void); +void bio_alarm(char *); #endif /* _BIOCTL_H_ */ |