bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Implementation of fsync for Windows


From: Richard W.M. Jones
Subject: [PATCH] Implementation of fsync for Windows
Date: Wed, 1 Oct 2008 15:52:23 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

This patch implements fsync for Windows.

I tested it using MinGW cross-compiler from a Fedora host, and wine
instead of Windows:

  ./gnulib-tool --create-testdir --dir=/tmp/testdir fsync

  [Verify it configures & builds normally on Linux, then ...]

  [Create a test program, test.c (attached).  Edit Makefile.am to
  compile the test program and link against libgnu.]

  autoreconf
  ./configure --host=i686-pc-mingw32
  make
  WINEDEBUG=+relay wine ./test.exe

  [Grep through the debugging output for calls to FlushFileBuffers]

I would like to add a test, but I couldn't work out how programs in
the tests/ subdirectory get run and what their environment is, which
is fairly crucial for this sort of system call.

As far as I can tell, Windows doesn't have anything which corresponds
to fdatasync(2).  The sqlite sources which I'm copying this from just
map this to fsync / FlushFileBuffers.  So perhaps a simple enhancement
to this would be to add this in the appropriate place:

  #define fdatasync fsync

Windows does have an equivalent to sync(2) but it has two significant
drawbacks.  Firstly it works on a per-volume basis, and you need to
grab a handle to the volume.  There is no easy way to just sync
everything, you'd need to enumerate available volumes.  Secondly and
more significantly it requires elevated privileges to do this
operation, unlike Unix where anyone can sync.

(Thanks to Jim Meyering for reviewing an earlier version of this
patch).

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/

Attachment: 0001-fsync-implementation.patch
Description: Text document

Attachment: test.c
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]