[Mono-dev] Cross-platform fsync()

Paolo Molaro lupus at ximian.com
Thu Jan 11 05:25:50 EST 2007


On 01/10/07 Robert Jordan wrote:
> Patrick Earl wrote:
> > Greetings all.  I've recently run into the need for a cross platform
> > fsync() call.  As far as I know, all of the flavors of unix that mono
> > supports provide the fsync call themselves.  On windows, there is a
> > _commit() function that does the same thing.  It seems like the
> > underlying platform support is there, but I'm not sure how to bring
> > that back up into the .net world so we can, for example, perform some
> > sort of flush to disk operation on a FileStream.  Suggestions?  Ideas?
> 
> On MS.NET and Mono for Windows, the proper function is WIN32's
> FlushFileBuffers()that can be called via p/invoke from kernel32.dll
> either on FileStream.Handle, or (.NET 2.0) on FileStream.SafeFileHandle.
> 
> On Linux, FlushFileBuffers() is provided by Mono's WAPI layer
> that calls fsync(2) internally, but I don't know how it can be
> called from managed code. Maybe like this (untested):
> 
> [DllImport("__Internal")]
> public static bool FlushFileBuffers (IntPtr handle);
> 
> For .NET 2.0:
> [DllImport("__Internal")]
> public static bool FlushFileBuffers (SafeFileHandle handle);

Using the io-layer symbols with DllImport ("__Internal") is not
supported: they are not available and can go away at any time.
DllImport ("__Internal") can only be used for symbols that the user
exports for example when embedding mono.
In this case people would need to have two pinvoke methods and call the
right one depending on the platform.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list