flushb.c revision 0c4a07264e55b42c6e30230e66b1dea7d4b94ea9
1/*
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
12#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{
23	fprintf(stderr, _("Usage: %s disk\n"), progname);
24	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	 */
44#ifdef BLKFLSBUF
45	if (ioctl(fd, BLKFLSBUF, 0) < 0) {
46		perror("ioctl BLKFLSBUF");
47		exit(1);
48	}
49	return 0;
50#else
51	fprintf(stderr,
52		_("BLKFLSBUF ioctl not supported!  Can't flush buffers.\n"));
53	return 1;
54#endif
55}
56