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 |
| 3 | */ |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <string.h> |
| 7 | #include <unistd.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <fcntl.h> |
| 10 | #include <sys/ioctl.h> |
| 11 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 12 | #ifdef __STDC__ |
| 13 | #define NOARGS void |
| 14 | #else |
| 15 | #define NOARGS |
| 16 | #define const |
| 17 | #endif |
| 18 | |
| 19 | const char *progname; |
| 20 | |
| 21 | static void usage(NOARGS) |
| 22 | { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame^] | 23 | fprintf(stderr, _("Usage: %s disk\n"), progname); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 24 | exit(1); |
| 25 | } |
| 26 | |
| 27 | int main(int argc, char **argv) |
| 28 | { |
| 29 | int fd; |
| 30 | |
| 31 | progname = argv[0]; |
| 32 | if (argc != 2) |
| 33 | usage(); |
| 34 | |
| 35 | fd = open(argv[1], O_RDONLY, 0); |
| 36 | if (fd < 0) { |
| 37 | perror("open"); |
| 38 | exit(1); |
| 39 | } |
| 40 | /* |
| 41 | * Note: to reread the partition table, use the ioctl |
| 42 | * BLKRRPART instead of BLKFSLBUF. |
| 43 | */ |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 44 | #ifdef BLKFLSBUF |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 45 | if (ioctl(fd, BLKFLSBUF, 0) < 0) { |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 46 | perror("ioctl BLKFLSBUF"); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 47 | exit(1); |
| 48 | } |
| 49 | return 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 50 | #else |
| 51 | fprintf(stderr, |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame^] | 52 | _("BLKFLSBUF ioctl not supported! Can't flush buffers.\n")); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 53 | return 1; |
| 54 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 55 | } |