2 * flushb.c --- Hides system-dependent information for both syncing a
3 * device to disk and to flush any buffers from disk cache.
5 * Copyright (C) 2000 Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
21 #include <sys/ioctl.h>
24 #include <sys/param.h>
25 #include <sys/mount.h> /* This may define BLKFLSBUF */
32 * For Linux, define BLKFLSBUF and FDFLUSH if necessary, since
33 * not all portable header file does so for us. This really should be
34 * fixed in the glibc header files. (Recent glibcs appear to define
35 * BLKFLSBUF in sys/mount.h, but FDFLUSH still doesn't seem to be
36 * defined anywhere portable.) Until then....
40 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
43 #define FDFLUSH _IO(2,0x4b) /* flush floppy disk */
48 * This function will sync a device/file, and optionally attempt to
49 * flush the buffer cache. The latter is basically only useful for
50 * system benchmarks and for torturing systems in burn-in tests. :)
52 errcode_t ext2fs_sync_device(int fd, int flushb)
55 * We always sync the device in case we're running on old
56 * kernels for which we can lose data if we don't. (There
57 * still is a race condition for those kernels, but this
58 * reduces it greatly.)
66 if (ioctl (fd, BLKFLSBUF, 0) == 0)
70 #warning BLKFLSBUF not defined
74 ioctl (fd, FDFLUSH, 0); /* In case this is a floppy */
77 #warning FDFLUSH not defined