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.)
2001-01-11 18:48:50 +03:00
|
|
|
/*
|
|
|
|
* flushb.c --- Hides system-dependent information for both syncing a
|
|
|
|
* device to disk and to flush any buffers from disk cache.
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
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.)
2001-01-11 18:48:50 +03:00
|
|
|
* Copyright (C) 2000 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
2010-05-18 05:31:56 +04:00
|
|
|
* This file may be redistributed under the terms of the GNU Library
|
|
|
|
* General Public License, version 2.
|
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.)
2001-01-11 18:48:50 +03:00
|
|
|
* %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
|
2001-06-23 05:01:17 +04:00
|
|
|
#if HAVE_SYS_MOUNT_H
|
2003-12-28 20:21:26 +03:00
|
|
|
#include <sys/param.h>
|
2001-06-23 05:01:17 +04:00
|
|
|
#include <sys/mount.h> /* This may define BLKFLSBUF */
|
|
|
|
#endif
|
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.)
2001-01-11 18:48:50 +03:00
|
|
|
|
|
|
|
#include "ext2_fs.h"
|
|
|
|
#include "ext2fs.h"
|
|
|
|
|
|
|
|
/*
|
2008-08-28 07:07:54 +04:00
|
|
|
* For Linux, define BLKFLSBUF and FDFLUSH if necessary, since
|
2001-06-23 05:01:17 +04:00
|
|
|
* 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....
|
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.)
2001-01-11 18:48:50 +03:00
|
|
|
*/
|
2001-06-23 05:01:17 +04:00
|
|
|
#ifdef __linux__
|
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.)
2001-01-11 18:48:50 +03:00
|
|
|
#ifndef BLKFLSBUF
|
2001-06-23 05:01:17 +04:00
|
|
|
#define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
|
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.)
2001-01-11 18:48:50 +03:00
|
|
|
#endif
|
|
|
|
#ifndef FDFLUSH
|
2001-06-23 05:01:17 +04:00
|
|
|
#define FDFLUSH _IO(2,0x4b) /* flush floppy disk */
|
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.)
2001-01-11 18:48:50 +03:00
|
|
|
#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
|
2002-10-31 20:21:05 +03:00
|
|
|
if (ioctl (fd, BLKFLSBUF, 0) == 0)
|
|
|
|
return 0;
|
2011-06-11 19:50:01 +04:00
|
|
|
#elif defined(__linux__)
|
|
|
|
#warning BLKFLSBUF not defined
|
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.)
2001-01-11 18:48:50 +03:00
|
|
|
#endif
|
|
|
|
#ifdef FDFLUSH
|
2002-10-31 20:21:05 +03:00
|
|
|
ioctl (fd, FDFLUSH, 0); /* In case this is a floppy */
|
2011-06-11 19:50:01 +04:00
|
|
|
#elif defined(__linux__)
|
|
|
|
#warning FDFLUSH not defined
|
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.)
2001-01-11 18:48:50 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|