]> Zhao Yanbai Git Server - minix.git/commitdiff
diskctl(8) tool
authorDavid van Moolenbroek <david@minix3.org>
Thu, 12 Aug 2010 14:11:28 +0000 (14:11 +0000)
committerDavid van Moolenbroek <david@minix3.org>
Thu, 12 Aug 2010 14:11:28 +0000 (14:11 +0000)
commands/diskctl/Makefile [new file with mode: 0644]
commands/diskctl/diskctl.c [new file with mode: 0644]
man/man8/Makefile
man/man8/diskctl.8 [new file with mode: 0644]

diff --git a/commands/diskctl/Makefile b/commands/diskctl/Makefile
new file mode 100644 (file)
index 0000000..7f923d9
--- /dev/null
@@ -0,0 +1,4 @@
+PROG=  diskctl
+MAN=
+
+.include <bsd.prog.mk>
diff --git a/commands/diskctl/diskctl.c b/commands/diskctl/diskctl.c
new file mode 100644 (file)
index 0000000..aae8b9b
--- /dev/null
@@ -0,0 +1,100 @@
+/* diskctl - control disk device driver parameters - by D.C. van Moolenbroek */
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+static char *name, *dev;
+
+static void usage(void)
+{
+       fprintf(stderr, "usage: %s <device> <command> [args]\n"
+                       "\n"
+                       "supported commands:\n"
+                       "  getwcache           return write cache status\n"
+                       "  setwcache [on|off]  set write cache status\n"
+                       "  flush               flush write cache\n",
+                       name);
+
+       exit(EXIT_FAILURE);
+}
+
+static int open_dev(int flags)
+{
+       int fd;
+
+       fd = open(dev, flags);
+
+       if (fd < 0) {
+               perror("open");
+
+               exit(EXIT_FAILURE);
+       }
+
+       return fd;
+}
+
+int main(int argc, char **argv)
+{
+       int fd, val;
+
+       name = argv[0];
+
+       if (argc < 3) usage();
+
+       dev = argv[1];
+
+       if (!strcasecmp(argv[2], "getwcache")) {
+               if (argc != 3) usage();
+
+               fd = open_dev(O_RDONLY);
+
+               if (ioctl(fd, DIOCGETWC, &val) != 0) {
+                       perror("ioctl");
+
+                       return EXIT_FAILURE;
+               }
+
+               close(fd);
+
+               printf("write cache is %s\n", val ? "on" : "off");
+       }
+       else if (!strcasecmp(argv[2], "setwcache")) {
+               if (argc != 4) usage();
+
+               fd = open_dev(O_WRONLY);
+
+               if (!strcasecmp(argv[3], "on")) val = 1;
+               else if (!strcasecmp(argv[3], "off")) val = 0;
+               else usage();
+
+               if (ioctl(fd, DIOCSETWC, &val) != 0) {
+                       perror("ioctl");
+
+                       return EXIT_FAILURE;
+               }
+
+               close(fd);
+
+               printf("write cache %sabled\n", val ? "en" : "dis");
+       }
+       else if (!strcasecmp(argv[2], "flush")) {
+               if (argc != 3) usage();
+
+               fd = open_dev(O_WRONLY);
+
+               if (ioctl(fd, DIOCFLUSH, NULL) != 0) {
+                       perror("ioctl");
+
+                       return EXIT_FAILURE;
+               }
+
+               close(fd);
+
+               printf("write cache flushed\n");
+       }
+       else usage();
+
+       return EXIT_SUCCESS;
+}
index fddea57fd6015297f08474eeb2de3db3af3e87c4..3804d471aeaacb5f430c6bc7f560b39c56472711 100644 (file)
@@ -1,6 +1,6 @@
 MAN=   add_route.8 adduser.8 backup.8 badblocks.8 boot.8 \
        cdprobe.8 checkhier.8 chown.8 cleantmp.8 config.8 cron.8 \
-       dhcpd.8 dosminix.8 elvprsv.8 fdisk.8 fingerd.8 ftpd.8 \
+       dhcpd.8 diskctl.8 dosminix.8 elvprsv.8 fdisk.8 fingerd.8 ftpd.8 \
        getty.8 halt.8 hgfs.8 httpd.8 ifconfig.8 inet.8 init.8 \
        installboot.8 intr.8 irdpd.8 loadramdisk.8 MAKEDEV.8 \
        mkdist.8 mknod.8 monitor.8 netconf.8 newroot.8 nonamed.8 \
diff --git a/man/man8/diskctl.8 b/man/man8/diskctl.8
new file mode 100644 (file)
index 0000000..7bdac70
--- /dev/null
@@ -0,0 +1,33 @@
+.TH DISKCTL 8
+.SH NAME
+diskctl \- control disk drive
+.SH SYNOPSIS
+\fBdiskctl\fR \fIdevice\fR \fIcommand\fR [\fIarguments\fR]
+.SH DESCRIPTION
+The \fBdiskctl\fR tool allows one to view and manage settings of,
+and perform actions on, disk drives. The following paragraph lists the
+commands that are currently supported by this tool.
+Please note that not all disks and drivers support all commands.
+.SH COMMANDS
+.TP 10
+\fBgetwcache\fR
+Retrieve the status (on or off) of the write cache on the device.
+.TP 10
+\fBsetwcache\fR [\fBon\fR|\fBoff\fR]
+Enable or disable the write cache on the device.
+Disabling the write cache typically also triggers a cache flush.
+.TP 10
+\fBflush\fR
+Tell the device to flush its write cache.
+The call will not return until the cache flush has completed.
+.SH EXAMPLES
+.TP 20
+.B diskctl /dev/c0d0 setwcache on
+# Turn on the write cache on c0d0.
+.TP 20
+.B diskctl /dev/c1d2 flush
+# Trigger a cache flush on c1d2.
+.SH "SEE ALSO"
+.BR controller (4).
+.SH AUTHOR
+David van Moolenbroek <dcvmoole@cs.vu.nl>