blob: 6da1c229204418dc05c6762fea9a6312ffa73fd4 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * flushb.c --- This routine flushes the disk buffers for a disk
3 */
4
5#include <stdio.h>
6#include <string.h>
7#include <unistd.h>
8#include <stdlib.h>
9#include <fcntl.h>
10#include <sys/ioctl.h>
11
Theodore Ts'o3839e651997-04-26 13:21:57 +000012#ifdef __STDC__
13#define NOARGS void
14#else
15#define NOARGS
16#define const
17#endif
18
19const char *progname;
20
21static void usage(NOARGS)
22{
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000023 fprintf(stderr, _("Usage: %s disk\n"), progname);
Theodore Ts'o3839e651997-04-26 13:21:57 +000024 exit(1);
25}
26
27int main(int argc, char **argv)
28{
29 int fd;
30
31 progname = argv[0];
32 if (argc != 2)
33 usage();
34
35 fd = open(argv[1], O_RDONLY, 0);
36 if (fd < 0) {
37 perror("open");
38 exit(1);
39 }
40 /*
41 * Note: to reread the partition table, use the ioctl
42 * BLKRRPART instead of BLKFSLBUF.
43 */
Theodore Ts'o50e1e101997-04-26 13:58:21 +000044#ifdef BLKFLSBUF
Theodore Ts'o3839e651997-04-26 13:21:57 +000045 if (ioctl(fd, BLKFLSBUF, 0) < 0) {
Theodore Ts'o50e1e101997-04-26 13:58:21 +000046 perror("ioctl BLKFLSBUF");
Theodore Ts'o3839e651997-04-26 13:21:57 +000047 exit(1);
48 }
49 return 0;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000050#else
51 fprintf(stderr,
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000052 _("BLKFLSBUF ioctl not supported! Can't flush buffers.\n"));
Theodore Ts'o50e1e101997-04-26 13:58:21 +000053 return 1;
54#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000055}