diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:49:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:49:25 +0000 |
commit | 464df1d5e5ab1322e2dd0a7796939fff1aeefa9a (patch) | |
tree | 6a403684e0978f0287d7f0ec0e5aab1fd31a59e1 /e2fsck/flushb.c | |
parent | Initial commit. (diff) | |
download | e2fsprogs-upstream.tar.xz e2fsprogs-upstream.zip |
Adding upstream version 1.47.0.upstream/1.47.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | e2fsck/flushb.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/e2fsck/flushb.c b/e2fsck/flushb.c new file mode 100644 index 0000000..6100fc6 --- /dev/null +++ b/e2fsck/flushb.c @@ -0,0 +1,67 @@ +/* + * flushb.c --- This routine flushes the disk buffers for a disk + * + * Copyright 1997, 2000, by Theodore Ts'o. + * + * WARNING: use of flushb on some older 2.2 kernels on a heavily loaded + * system will corrupt filesystems. This program is not really useful + * beyond for benchmarking scripts. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +#include "config.h" +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/mount.h> +#include "../misc/nls-enable.h" + +/* For Linux, define BLKFLSBUF if necessary */ +#if (!defined(BLKFLSBUF) && defined(__linux__)) +#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ +#endif + +const char *progname; + +static void usage(void) +{ + fprintf(stderr, _("Usage: %s disk\n"), progname); + exit(1); +} + +int main(int argc, char **argv) +{ + int fd; + + progname = argv[0]; + if (argc != 2) + usage(); + + fd = open(argv[1], O_RDONLY, 0); + if (fd < 0) { + perror("open"); + exit(1); + } + /* + * Note: to reread the partition table, use the ioctl + * BLKRRPART instead of BLKFSLBUF. + */ +#ifdef BLKFLSBUF + if (ioctl(fd, BLKFLSBUF, 0) < 0) { + perror("ioctl BLKFLSBUF"); + exit(1); + } + return 0; +#else + fprintf(stderr, + _("BLKFLSBUF ioctl not supported! Can't flush buffers.\n")); + return 1; +#endif +} |