1 /* diskctl - control disk device driver parameters - by D.C. van Moolenbroek */
13 "usage: %s <device> <command> [args]\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",
25 open_dev(const char * dev
, int flags
)
29 fd
= open(dev
, flags
);
41 main(int argc
, char ** argv
)
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) {
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"))
69 else if (!strcasecmp(argv
[3], "off"))
74 fd
= open_dev(argv
[1], O_WRONLY
);
76 if (ioctl(fd
, DIOCSETWC
, &val
) != 0) {
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) {
99 printf("write cache flushed\n");