Whamcloud - gitweb
ChangeLog, journal.c:
[tools/e2fsprogs.git] / e2fsck / flushb.c
1 /*
2  * flushb.c --- This routine flushes the disk buffers for a disk
3  *
4  * Copyright 1997, 2000, by Theodore Ts'o.
5  * 
6  * This program may be used under the provisions of the GNU Public
7  * 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.)
24  */
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>
32 #include "../misc/nls-enable.h"
33
34 /* For Linux/i386, define BLKFLSBUF */
35 #if (!defined(BLKFLSBUF) && defined(__i386__))
36 #define BLKFLSBUF  0x1261       /* flush buffer cache */
37 #endif
38
39 const char *progname;
40
41 static void usage(void)
42 {
43         fprintf(stderr, _("Usage: %s disk\n"), progname);
44         exit(1);
45 }       
46         
47 int 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          */
64 #ifdef BLKFLSBUF
65         if (ioctl(fd, BLKFLSBUF, 0) < 0) {
66                 perror("ioctl BLKFLSBUF");
67                 exit(1);
68         }
69         return 0;
70 #else
71         fprintf(stderr,
72                 _("BLKFLSBUF ioctl not supported!  Can't flush buffers.\n"));
73         return 1;
74 #endif
75 }