OSDN Git Service

Automated import from //branches/master/...@142325,142325
[android-x86/external-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  * WARNING: use of flushb on some older 2.2 kernels on a heavily loaded
7  * system will corrupt filesystems.  This program is not really useful
8  * beyond for benchmarking scripts.
9  *
10  * %Begin-Header%
11  * This file may be redistributed under the terms of the GNU Public
12  * License.
13  * %End-Header%
14  */
15
16 #include <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
19 #include <stdlib.h>
20 #include <fcntl.h>
21 #include <sys/ioctl.h>
22 #include <sys/mount.h>
23 #include "../misc/nls-enable.h"
24
25 /* For Linux, define BLKFLSBUF if necessary */
26 #if (!defined(BLKFLSBUF) && defined(__linux__))
27 #define BLKFLSBUF       _IO(0x12,97)    /* flush buffer cache */
28 #endif
29
30 const char *progname;
31
32 static void usage(void)
33 {
34         fprintf(stderr, _("Usage: %s disk\n"), progname);
35         exit(1);
36 }       
37         
38 int main(int argc, char **argv)
39 {
40         int     fd;
41         
42         progname = argv[0];
43         if (argc != 2)
44                 usage();
45
46         fd = open(argv[1], O_RDONLY, 0);
47         if (fd < 0) {
48                 perror("open");
49                 exit(1);
50         }
51         /*
52          * Note: to reread the partition table, use the ioctl
53          * BLKRRPART instead of BLKFSLBUF.
54          */
55 #ifdef BLKFLSBUF
56         if (ioctl(fd, BLKFLSBUF, 0) < 0) {
57                 perror("ioctl BLKFLSBUF");
58                 exit(1);
59         }
60         return 0;
61 #else
62         fprintf(stderr,
63                 _("BLKFLSBUF ioctl not supported!  Can't flush buffers.\n"));
64         return 1;
65 #endif
66 }