aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ext2fs/flushb.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2001-01-11 15:48:50 +0000
committerTheodore Ts'o <tytso@mit.edu>2001-01-11 15:48:50 +0000
commit4d0f3e17a5b7556505fe437680070fe3bb140d67 (patch)
tree6221fa498c4080920709c0dc565e3d9098b23089 /lib/ext2fs/flushb.c
parentbbabf8f7060dae9c4aebcf670b8641ed4bb2660f (diff)
downloadandroid_external_e2fsprogs-4d0f3e17a5b7556505fe437680070fe3bb140d67.tar.gz
android_external_e2fsprogs-4d0f3e17a5b7556505fe437680070fe3bb140d67.tar.bz2
android_external_e2fsprogs-4d0f3e17a5b7556505fe437680070fe3bb140d67.zip
ChangeLog, MCONFIG.in, configure, configure.in:
MCONFIG.in: Change --enable-gcc-wall handling so that it's no longer a configure option, but something which is done when the developer uses the command "make gcc-wall". configure.in: Remove test for ino_t, since we don't use it any more (we always use our own ext2_ino_t). Remove --enable-gcc-wall support. Add test for sys/ioctl.h .del-types.h.in~ca55114a: Remove definition of ino_t ChangeLog, Makefile.in, ext2fs.h, flushb.c, jump.funcs: flushb.c (ext2fs_sync_device): New function which centralizes all of the places which might try to use the BLKFLSBUF or FDFLUSH ioctls (and usually failing to define them since the system header files don't usually do this for us, and we're trying to avoid usage of kernel include files now.)
Diffstat (limited to 'lib/ext2fs/flushb.c')
-rw-r--r--lib/ext2fs/flushb.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/ext2fs/flushb.c b/lib/ext2fs/flushb.c
new file mode 100644
index 00000000..342576ba
--- /dev/null
+++ b/lib/ext2fs/flushb.c
@@ -0,0 +1,76 @@
+/*
+ * flushb.c --- Hides system-dependent information for both syncing a
+ * device to disk and to flush any buffers from disk cache.
+ *
+ * Copyright (C) 2000 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#include <stdio.h>
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#if HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+
+#if EXT2_FLAT_INCLUDES
+#include "ext2_fs.h"
+#else
+#include <linux/ext2_fs.h>
+#endif
+
+#include "ext2fs.h"
+
+/*
+ * For Linux/i386, define BLKFLSBUF and FDFLUSH if necessary, since
+ * no portable header file does so for us. This really should be
+ * fixed in the glibc header files. Until then....
+ */
+#if (defined(__i386__) && defined(__linux__))
+#ifndef BLKFLSBUF
+#define BLKFLSBUF 0x1261 /* flush buffer cache */
+#endif
+#ifndef FDFLUSH
+#define FDFLUSH 0x024b /* flush floppy disk */
+#endif
+#endif
+
+/*
+ * This function will sync a device/file, and optionally attempt to
+ * flush the buffer cache. The latter is basically only useful for
+ * system benchmarks and for torturing systems in burn-in tests. :)
+ */
+errcode_t ext2fs_sync_device(int fd, int flushb)
+{
+ /*
+ * We always sync the device in case we're running on old
+ * kernels for which we can lose data if we don't. (There
+ * still is a race condition for those kernels, but this
+ * reduces it greatly.)
+ */
+ if (fsync (fd) == -1)
+ return errno;
+
+ if (flushb) {
+
+#ifdef BLKFLSBUF
+ ioctl (fd, BLKFLSBUF, 0); /* In case this is a HD */
+#else
+ #warning BLKFLSBUF not defined
+#endif
+#ifdef FDFLUSH
+ ioctl (fd, FDFLUSH, 0); /* In case this is floppy */
+#else
+ #warning FDFLUSH not defined
+#endif
+ }
+ return 0;
+}