Whamcloud - gitweb
misc: cleanup gcc -Wall warnings
[tools/e2fsprogs.git] / lib / ext2fs / flushb.c
index 342576b..98821fc 100644 (file)
@@ -1,15 +1,16 @@
 /*
  * 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.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #if HAVE_ERRNO_H
 #include <errno.h>
 #if HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
-
-#if EXT2_FLAT_INCLUDES
-#include "ext2_fs.h"
-#else
-#include <linux/ext2_fs.h>
+#if HAVE_SYS_MOUNT_H
+#include <sys/param.h>
+#include <sys/mount.h>         /* This may define BLKFLSBUF */
 #endif
 
+#include "ext2_fs.h"
 #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....
+ * For Linux, define BLKFLSBUF and FDFLUSH if necessary, since
+ * not all portable header file does so for us.  This really should be
+ * fixed in the glibc header files.  (Recent glibcs appear to define
+ * BLKFLSBUF in sys/mount.h, but FDFLUSH still doesn't seem to be
+ * defined anywhere portable.)  Until then....
  */
-#if (defined(__i386__) && defined(__linux__))
+#ifdef __linux__
 #ifndef BLKFLSBUF
-#define BLKFLSBUF      0x1261  /* flush buffer cache */
+#define BLKFLSBUF      _IO(0x12,97)    /* flush buffer cache */
 #endif
 #ifndef FDFLUSH
-#define FDFLUSH                0x024b  /* flush floppy disk */
+#define FDFLUSH                _IO(2,0x4b)     /* flush floppy disk */
 #endif
 #endif
 
@@ -62,14 +64,15 @@ errcode_t ext2fs_sync_device(int fd, int flushb)
        if (flushb) {
 
 #ifdef BLKFLSBUF
-               ioctl (fd, BLKFLSBUF, 0);   /* In case this is a HD */
-#else
- #warning BLKFLSBUF not defined
+               if (ioctl (fd, BLKFLSBUF, 0) == 0)
+                       return 0;
+#elif defined(__linux__)
+#warning BLKFLSBUF not defined
 #endif
 #ifdef FDFLUSH
-               ioctl (fd, FDFLUSH, 0);   /* In case this is floppy */
-#else
- #warning FDFLUSH not defined
+               return ioctl(fd, FDFLUSH, 0);   /* In case this is a floppy */
+#elif defined(__linux__)
+#warning FDFLUSH not defined
 #endif
        }
        return 0;