Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * flushb.c --- This routine flushes the disk buffers for a disk |
Theodore Ts'o | bf2d499 | 2000-12-09 14:46:20 +0000 | [diff] [blame^] | 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 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'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 19 | */ |
| 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'o | adfca56 | 2000-09-12 21:24:36 +0000 | [diff] [blame] | 27 | #include "../misc/nls-enable.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 28 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 29 | #ifdef __STDC__ |
| 30 | #define NOARGS void |
| 31 | #else |
| 32 | #define NOARGS |
| 33 | #define const |
| 34 | #endif |
| 35 | |
Theodore Ts'o | bf2d499 | 2000-12-09 14:46:20 +0000 | [diff] [blame^] | 36 | /* For Linux/i386, define BLKFLSBUF */ |
| 37 | #if (!defined(BLKFLSBUF) && defined(__i386__)) |
| 38 | #define BLKFLSBUF 0x1261 /* flush buffer cache */ |
| 39 | #endif |
| 40 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 41 | const char *progname; |
| 42 | |
| 43 | static void usage(NOARGS) |
| 44 | { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 45 | fprintf(stderr, _("Usage: %s disk\n"), progname); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 46 | exit(1); |
| 47 | } |
| 48 | |
| 49 | int 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'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 66 | #ifdef BLKFLSBUF |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 67 | if (ioctl(fd, BLKFLSBUF, 0) < 0) { |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 68 | perror("ioctl BLKFLSBUF"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 69 | exit(1); |
| 70 | } |
| 71 | return 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 72 | #else |
| 73 | fprintf(stderr, |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 74 | _("BLKFLSBUF ioctl not supported! Can't flush buffers.\n")); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 75 | return 1; |
| 76 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 77 | } |