From: Steve Lumos Date: 2002-01-17T17:16:38+09:00 Subject: Re: [RCR] #59 Add fsync method to IO class matz@ruby-lang.org (Yukihiro Matsumoto) writes: > Hi, > > In message "[RCR] #59 Add fsync method to IO class" > on 02/01/17, Leslie Hensley writes: > > |Adding fsync and fdatasync methods to the IO class will allow Ruby to > |be used to address problem domains where it must be guaranteed that > |data has been written to the disk. Examples of these are logging for > |security purposes and transactional systems. The posix functions fsync > |and fdatasync guarantee that any data that the OS is buffering for a > |file is written to disk. This is distinct from IO#sync= which only > |addresses if Ruby buffers the data above the OS level. As for > |portability concerns, these methods seem just as reasonable as > |IO#fcntl. > > My concerns are: > > * how common are they? > * what if it's not defined on the platform? > > matz. I think fsync() is old POSIX and should be in every *nix. fdatasync() is part of realtime extensions in more recent POSIX and doesn't exist everywhere (not on FreeBSD, seems to be the same as fsync() on Linux (though I'm not a Linux person, and on Solaris 8 you have to define _XOPEN_REALTIME and link with librt to get it). DESCRIPTION The fdatasync() function forces all currently queued I/O operations associated with the file indicated by file descriptor fildes to the synchronized I/O completion state. The functionality is as described for fsync(3C) (with the symbol _XOPEN_REALTIME defined), with the exception that all I/O operations are completed as defined for synchronised I/O data integrity completion. and that sounds to me like it should be rb_notimplemented if it's not defined instead of passed-off to fsync() (let the Ruby code decide to use fsync() instead if that's really good enough. Also, the whole point of these functions is to get the file in a known state. If they fail then the file probably isn't in the known state which means that the return value should be checked and rb_sys_fail() on error IMO. Steve