1 /* diskctl - control disk device driver parameters - by D.C. van Moolenbroek */
8 static char *name
, *dev
;
10 static void usage(void)
12 fprintf(stderr
, "usage: %s <device> <command> [args]\n"
14 "supported commands:\n"
15 " getwcache return write cache status\n"
16 " setwcache [on|off] set write cache status\n"
17 " flush flush write cache\n",
23 static int open_dev(int flags
)
27 fd
= open(dev
, flags
);
38 int main(int argc
, char **argv
)
44 if (argc
< 3) usage();
48 if (!strcasecmp(argv
[2], "getwcache")) {
49 if (argc
!= 3) usage();
51 fd
= open_dev(O_RDONLY
);
53 if (ioctl(fd
, DIOCGETWC
, &val
) != 0) {
61 printf("write cache is %s\n", val
? "on" : "off");
63 else if (!strcasecmp(argv
[2], "setwcache")) {
64 if (argc
!= 4) usage();
66 fd
= open_dev(O_WRONLY
);
68 if (!strcasecmp(argv
[3], "on")) val
= 1;
69 else if (!strcasecmp(argv
[3], "off")) val
= 0;
72 if (ioctl(fd
, DIOCSETWC
, &val
) != 0) {
80 printf("write cache %sabled\n", val
? "en" : "dis");
82 else if (!strcasecmp(argv
[2], "flush")) {
83 if (argc
!= 3) usage();
85 fd
= open_dev(O_WRONLY
);
87 if (ioctl(fd
, DIOCFLUSH
, NULL
) != 0) {
95 printf("write cache flushed\n");