]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - e2fsck/flushb.c
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / e2fsck / flushb.c
CommitLineData
3839e657
TT
1/*
2 * flushb.c --- This routine flushes the disk buffers for a disk
bf2d4999
TT
3 *
4 * Copyright 1997, 2000, by Theodore Ts'o.
efc6f628 5 *
16fa86b9
TT
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%
3839e657
TT
14 */
15
d1154eb4 16#include "config.h"
3839e657
TT
17#include <stdio.h>
18#include <string.h>
19#include <unistd.h>
20#include <stdlib.h>
21#include <fcntl.h>
22#include <sys/ioctl.h>
d90f3494 23#include <sys/mount.h>
adfca56f 24#include "../misc/nls-enable.h"
3839e657 25
d90f3494
TT
26/* For Linux, define BLKFLSBUF if necessary */
27#if (!defined(BLKFLSBUF) && defined(__linux__))
28#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
bf2d4999
TT
29#endif
30
3839e657
TT
31const char *progname;
32
5ba23cb1 33static void usage(void)
3839e657 34{
0c4a0726 35 fprintf(stderr, _("Usage: %s disk\n"), progname);
3839e657 36 exit(1);
efc6f628
TT
37}
38
3839e657
TT
39int main(int argc, char **argv)
40{
41 int fd;
efc6f628 42
3839e657
TT
43 progname = argv[0];
44 if (argc != 2)
45 usage();
46
47 fd = open(argv[1], O_RDONLY, 0);
48 if (fd < 0) {
49 perror("open");
50 exit(1);
51 }
52 /*
53 * Note: to reread the partition table, use the ioctl
54 * BLKRRPART instead of BLKFSLBUF.
55 */
50e1e10f 56#ifdef BLKFLSBUF
3839e657 57 if (ioctl(fd, BLKFLSBUF, 0) < 0) {
50e1e10f 58 perror("ioctl BLKFLSBUF");
3839e657
TT
59 exit(1);
60 }
61 return 0;
50e1e10f
TT
62#else
63 fprintf(stderr,
0c4a0726 64 _("BLKFLSBUF ioctl not supported! Can't flush buffers.\n"));
50e1e10f
TT
65 return 1;
66#endif
3839e657 67}