Remove building with NOCRYPTO option
[minix3.git] / minix / usr.sbin / diskctl / diskctl.c
blob849d5b95038452f16c9e077a21980b6ef7b89791
1 /* diskctl - control disk device driver parameters - by D.C. van Moolenbroek */
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <sys/ioctl.h>
6 #include <unistd.h>
7 #include <fcntl.h>
9 static void __dead
10 usage(void)
12 fprintf(stderr,
13 "usage: %s <device> <command> [args]\n"
14 "\n"
15 "supported commands:\n"
16 " getwcache return write cache status\n"
17 " setwcache [on|off] set write cache status\n"
18 " flush flush write cache\n",
19 getprogname());
21 exit(EXIT_FAILURE);
24 static int
25 open_dev(const char * dev, int flags)
27 int fd;
29 fd = open(dev, flags);
31 if (fd < 0) {
32 perror("open");
34 exit(EXIT_FAILURE);
37 return fd;
40 int
41 main(int argc, char ** argv)
43 int fd, val;
45 setprogname(argv[0]);
47 if (argc < 3) usage();
49 if (!strcasecmp(argv[2], "getwcache")) {
50 if (argc != 3) usage();
52 fd = open_dev(argv[1], O_RDONLY);
54 if (ioctl(fd, DIOCGETWC, &val) != 0) {
55 perror("ioctl");
57 return EXIT_FAILURE;
60 close(fd);
62 printf("write cache is %s\n", val ? "on" : "off");
64 } else if (!strcasecmp(argv[2], "setwcache")) {
65 if (argc != 4) usage();
67 if (!strcasecmp(argv[3], "on"))
68 val = 1;
69 else if (!strcasecmp(argv[3], "off"))
70 val = 0;
71 else
72 usage();
74 fd = open_dev(argv[1], O_WRONLY);
76 if (ioctl(fd, DIOCSETWC, &val) != 0) {
77 perror("ioctl");
79 return EXIT_FAILURE;
82 close(fd);
84 printf("write cache %sabled\n", val ? "en" : "dis");
86 } else if (!strcasecmp(argv[2], "flush")) {
87 if (argc != 3) usage();
89 fd = open_dev(argv[1], O_WRONLY);
91 if (ioctl(fd, DIOCFLUSH, NULL) != 0) {
92 perror("ioctl");
94 return EXIT_FAILURE;
97 close(fd);
99 printf("write cache flushed\n");
101 } else
102 usage();
104 return EXIT_SUCCESS;