I don't know enough about Windows to tell you how to do this, but maybe this will help anyway:
There are three layers of buffering you need to overcome if you want your data physically written to disk.
- The Perl I/O buffer. This can be bypassed by using syswrite or setting $|.
- The OS disk cache. This is the one you want to bypass by opening O_SYNC. On *NIX, other ways to get around the disk cache would be to call the sync() or fsync() system calls or mount the filesystem in sync mode.
- The on-disk/controller write cache. This is the cache which the disk and/or disk controller use to speed up their operation (note these may actually be two different caches, but from your perspective they act as one). Most disks these days come with write-cache enabled by default and require a FLUSH CACHE(ATA) or SYNCHRONIZE CACHE(SCSI) command from the OS to actually write the data to platter. You'll have to check your OS and device driver to find out whether it does that. Further trouble is that many disks will silently ignore these command in order to speed up benchmarks. You should be able to disable the write cache in your system settings, but that will lead to a disk slowdown as well as a dramatically reduced MTBF.
This issue becomes even more interesting if you're dealing with battery-backed RAID devices which may completely ignore flush commands and keep data in RAM forever without flushing to disk.
There are ten types of people: those that understand binary and those that don't.