blob: 6d23b98e49966d890450af2b4ab4815896e11b3d [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
7 * License, *EXCEPT* that it may not be included in the Debian
8 * distribution. (Yes, this violates the Debian Free Software
9 * Guidelines. That's the point. I don't want this program being
10 * distributed in Debian, because I don't care to support it, and the
11 * maintainer, Yann Dirson, doesn't seem to pay attention to my wishes
12 * on this matter. So I'm deliberately adding this clause so it
13 * violates the Debian Free Software Guidelines to force him to take
14 * it out. (What part of THIS IS FOR MY OWN USE don't you understand?
15 * And no, I'm going to write a man page for it either. And don't
16 * file a bug about it or bug me about it.) If this doesn't work,
17 * I'll have to remove it from the upstream source distribution on the
18 * next release. So there. :-)
Theodore Ts'o3839e651997-04-26 13:21:57 +000019 */
20
21#include <stdio.h>
22#include <string.h>
23#include <unistd.h>
24#include <stdlib.h>
25#include <fcntl.h>
26#include <sys/ioctl.h>
Theodore Ts'oadfca562000-09-12 21:24:36 +000027#include "../misc/nls-enable.h"
Theodore Ts'o3839e651997-04-26 13:21:57 +000028
Theodore Ts'o3839e651997-04-26 13:21:57 +000029#ifdef __STDC__
30#define NOARGS void
31#else
32#define NOARGS
33#define const
34#endif
35
Theodore Ts'obf2d4992000-12-09 14:46:20 +000036/* For Linux/i386, define BLKFLSBUF */
37#if (!defined(BLKFLSBUF) && defined(__i386__))
38#define BLKFLSBUF 0x1261 /* flush buffer cache */
39#endif
40
Theodore Ts'o3839e651997-04-26 13:21:57 +000041const char *progname;
42
43static void usage(NOARGS)
44{
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000045 fprintf(stderr, _("Usage: %s disk\n"), progname);
Theodore Ts'o3839e651997-04-26 13:21:57 +000046 exit(1);
47}
48
49int main(int argc, char **argv)
50{
51 int fd;
52
53 progname = argv[0];
54 if (argc != 2)
55 usage();
56
57 fd = open(argv[1], O_RDONLY, 0);
58 if (fd < 0) {
59 perror("open");
60 exit(1);
61 }
62 /*
63 * Note: to reread the partition table, use the ioctl
64 * BLKRRPART instead of BLKFSLBUF.
65 */
Theodore Ts'o50e1e101997-04-26 13:58:21 +000066#ifdef BLKFLSBUF
Theodore Ts'o3839e651997-04-26 13:21:57 +000067 if (ioctl(fd, BLKFLSBUF, 0) < 0) {
Theodore Ts'o50e1e101997-04-26 13:58:21 +000068 perror("ioctl BLKFLSBUF");
Theodore Ts'o3839e651997-04-26 13:21:57 +000069 exit(1);
70 }
71 return 0;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000072#else
73 fprintf(stderr,
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000074 _("BLKFLSBUF ioctl not supported! Can't flush buffers.\n"));
Theodore Ts'o50e1e101997-04-26 13:58:21 +000075 return 1;
76#endif
Theodore Ts'o3839e651997-04-26 13:21:57 +000077}