SQLite Forum

How to corrupt - windows
Login
The answer varies by the actual hardware and the version of Windows.  Assuming hardware which works correctly and Windows 10 / Server 2012 Windows has the following checky-box options for DASD devices:

**Enable write caching on the device** and a subselection **Turn off Windows write-cache buffer flushing on the device**

These options do EXACTLY and precisely what they say (which was not the case for any prior version of Windows).

So, in Windows, ALL DASD I/O, unless told otherwise when opening the file, is to the Windows Filesystem cache and not directly to the underlying hardware.  That is, all I/O is a Windows cache read/write, although you (the programmer) may choose to require a file handle (when opened) to use "direct I/O" and bypass the Windows Filesystem cache.  In practice, almost nothing does this.  SQLite3 does not request direct I/O either -- it does I/O in the ordinary course through the Windows filesystem cache.  You cannot even force this option because if you want to do direct-I/O you have to only do I/O on correct device data boundaries and SQLite3 does not do this, so even if you attempt to set direct-I/O mode it will fail due to mis-alignment of reads and writes.

Windows will "write" data from the Windows filesystem cache to the underlying hardware when it feels like it (it is basically an LRU cache with device idle flushing but no "intelligent" cache management features).  The various "FlushFileBuffers" calls force Windows to write dirty cache pages associated with a specific file to the underlying physical storage device.

The **Enable write caching on the device** allows device writes to return success as soon as the write data has been handed off from the Windows DASD driver to the physical device irrespective of whether or not the data is actually "written" to the device (that is, it allows the "physical device" to "do its own thing" with the data outside of the purview of the Windows I/O layer).  If this is disabled (unchecked) Windows attempts to require that the device driver not return success until the data is actually securely and irreversibly written to the storage media -- whether this actually happens is up to the underlying hardware and whether it is lying or telling the truth when it says the write is complete.  It is a problem of that hardware and not under anyone's control (well, technically, it is under the control of the person who is buying the hardware to only buy hardware which behaves properly and to allow companies selling lying hardware to go bankrupt).

Effectively, this controls the level of supervision that Windows exercises over data written to the DASD device.  If the box is unchecked, then Windows tells the device that it should not report success until success is achieved.  If the box is checked, then that means that the device may report success as soon as it has the data in hand, whether or not is has actually been written.

Whether this "does anything" or not is up to the particular hardware that you have purchased.  Higher-end hardware will "work properly" and low-end hardware will oftentimes "lie" in order to make the uneducated believe that they are getting Lamborghini like performance from a go-kart.

The sub-option **Turn off Windows write-cache buffer flushing on the device** is a further command to Windows on whether or not to pass through a FlushFileBuffer operation to the device or whether to run in "fake Lamborghini" mode by never passing though flush operations to the underlying hardware.

If the hardware is working correctly then the write-caching should be enabled (checked) and the turn off flushing disabled (unchecked) for maximum performance. (write-caching on the device is required in order for correctly working devices to do advanced things such as data-phase disconnect, command queueing, elevator seeks, etc).

Whether these checkboxes actually do anything at all is up to the individual device driver and individual hardware.