blob: 16389b2dabc3420ca9579e173200639b858af770 [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * flushb.c --- This routine flushes the disk buffers for a disk
Theodore Ts'obf2d4992000-12-09 14:46:20 +00003 *
4 * Copyright 1997, 2000, by Theodore Ts'o.
5 *
6 * This program may be used under the provisions of the GNU Public
Theodore Ts'o26900ae2000-12-09 21:46:59 +00007 * License, *EXCEPT* that a binary copy of the executable may not be
8 * packaged as a part of binary package which is distributed as part
9 * of a Linux distribution. (Yes, this violates the Debian Free
10 * Software Guidelines of restricting its field of use. That's the
11 * point. I don't want this program being distributed in Debian,
12 * because I don't care to support it, and the maintainer, Yann
13 * Dirson, doesn't seem to pay attention to my wishes on this matter.
14 * So I'm deliberately adding this clause so it violates the Debian
15 * Free Software Guidelines to force him to take it out. (What part
16 * of THIS IS FOR MY OWN USE don't you understand? And no, I'm going
17 * to write a man page for it either. And don't file a bug about it
18 * or bug me about it.) If this doesn't work, I'll have to remove it
19 * from the upstream source distribution at the next release. End of
20 * Rant. :-)
21 *
22 * (BTW, use of flushb on some older 2.2 kernels on a heavily loaded
23 * system will corrupt filesystems.)
Theodore Ts'o3839e651997-04-26 13:21:57 +000024 */
25
26#include <stdio.h>
27#include <string.h>
28#include <unistd.h>
29#include <stdlib.h>
30#include <fcntl.h>
31#include <sys/ioctl.h>
Theodore Ts'oadfca562000-09-12 21:24:36 +000032#include "../misc/nls-enable.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000033
Theodore Ts'obf2d4992000-12-09 14:46:20 +000034/* For Linux/i386, define BLKFLSBUF */
35#if (!defined(BLKFLSBUF) && defined(__i386__))
36#define BLKFLSBUF 0x1261 /* flush buffer cache */
37#endif
38
Theodore Ts'o3839e651997-04-26 13:21:57 +000039const char *progname;
40
Theodore Ts'o5ba23cb2001-01-11 19:15:02 +000041static void usage(void)
Theodore Ts'o3839e651997-04-26 13:21:57 +000042{
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000043 fprintf(stderr, _("Usage: %s disk\n"), progname);
Theodore Ts'o3839e651997-04-26 13:21:57 +000044 exit(1);
45}
46
47int main(int argc, char **argv)
48{
49 int fd;
50
51 progname = argv[0];
52 if (argc != 2)
53 usage();
54
55 fd = open(argv[1], O_RDONLY, 0);
56 if (fd < 0) {
57 perror("open");
58 exit(1);
59 }
60 /*
61 * Note: to reread the partition table, use the ioctl
62 * BLKRRPART instead of BLKFSLBUF.
63 */
Theodore Ts'o50e1e101997-04-26 13:58:21 +000064#ifdef BLKFLSBUF
Theodore Ts'o3839e651997-04-26 13:21:57 +000065 if (ioctl(fd, BLKFLSBUF, 0) < 0) {
Theodore Ts'o50e1e101997-04-26 13:58:21 +000066 perror("ioctl BLKFLSBUF");
Theodore Ts'o3839e651997-04-26 13:21:57 +000067 exit(1);
68 }
69 return 0;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000070#else
71 fprintf(stderr,
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000072 _("BLKFLSBUF ioctl not supported! Can't flush buffers.\n"));
Theodore Ts'o50e1e101997-04-26 13:58:21 +000073 return 1;
74#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000075}