Re: CreateFile() and FILE_FLAG_WRITE_THROUGH

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Tim

Thanks for replying, you're confirming my experiences.

Luckily, my code which is trying to write out a log of events to be used to handle recovery of power failures
operates by pre-writing its data in blocks and then writing over parts of those blocks with real log data , so I can use
write-through to do this as long as I call FlushFileBuffers() to update the metadata each time a new block is added.

I still think I'd like the documentation to hammer home the fact that write-through updates do not update
the metadata and are therefore only useful in the scenario I've described if overwriting existing data, and
not if writing out new data. I think the average Joe in the street (me, for instance) would otherwise assume that if data
is written with write through, and if the power then fails, the data is available to be read on restart.

Thanks again

Nick


"Tim Roberts" <timr@xxxxxxxxx> wrote in message news:rq7hc45haldosm8kanfg4l38nihdo1jn99@xxxxxxxxxx
"Nick Tucker" <nick.tucker@xxxxxxxxxxxxxxxxx> wrote:

If I create a file using CreateFile(), specifying the
FILE_FLAG_WRITE_THROUGH flag, then write to that file, the file still shows
as zero bytes long in the directory and in Windows Explorer, and if I then
turn the power off, that file is still zero bytes long on restart, so the
data I wrote is unavailable. I have tried this test on a variety of
operating systems including Vista, XP and Windows Server 2003/2008 using a
variety of hardware platforms with both SATA and SCSI disk systems, and they
all behave the same way.

Surely the whole point of specifying that flag is that I want the data to be
written to disk, together with it's corresponding metadata, so if a
catastrophic failure occurs, the data is available to me on restart.

"...together with it's corresponding metadata" is wishful thinking on your
part. Such a promise never hinted at in the documentation. If you had,
for example, created a file with 4096 empty bytes and closed it, then
opened the file with FILE_FLAG_WRITE_THROUGH and done a Write, you'd see
that the data went straight to disk.

My researches of newsgroup articles on this subject suggest that if I want
this, then I also have to use FlushFileBuffers(), but if that is so then
surely I don't need to specify the write through flag since all file and
folder data will be committed to disk when I call that function.

Right.

So, what is the point of specifying the write-through flag in this scenario?

Writing metadata is expensive. There are many cases where you want the
data to be written immediately without having to pay the penalty for a
metadata update any time. When you're ready to pay the penalty, you use
FlushFileBuffers.

Also see http://support.microsoft.com/kb/99794

I think the documentation of CreateFile() could do with a little
clarification!

I'm not sure I agree, but there links at the bottom of the MSDN page that
allow you to add your own content, and to submit comments to Microsoft.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.

.



Relevant Pages

  • Re: CreateFile() and FILE_FLAG_WRITE_THROUGH
    ... variety of hardware platforms with both SATA and SCSI disk systems, ... Surely the whole point of specifying that flag is that I want the data to be ... "...together with it's corresponding metadata" is wishful thinking on your ...
    (microsoft.public.win32.programmer.kernel)
  • Re: CreateFile() and FILE_FLAG_WRITE_THROUGH
    ... I have tried this test on a variety of operating systems including Vista, XP and Windows Server 2003/2008 using a variety of hardware platforms with both SATA and SCSI disk systems, and they all behave the same way. ... Surely the whole point of specifying that flag is that I want the data to be written to disk, together with it's corresponding metadata, so if a catastrophic failure occurs, the data is available to me on restart. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: CreateFile() and FILE_FLAG_WRITE_THROUGH
    ... However, I have now proved to myself that file metadata is not written through, whatever flags you specify. ... >> variety of hardware platforms with both SATA and SCSI disk systems,>> and they ... >> Surely the whole point of specifying that flag is that I want the data>> to be ...
    (microsoft.public.win32.programmer.kernel)
  • Re: CreateFile() and FILE_FLAG_WRITE_THROUGH
    ... BUT this will not work UNLESS you specify the ... FILE_FLAG_NO_BUFFERING flag, ... I have now proved to myself that file metadata is not written ... disk structure to be consistent, this incurs a cost and that's why the ...
    (microsoft.public.win32.programmer.kernel)
  • LVM cant find devices after adding new disks
    ... the disk the system boots normally. ... with an alternate superblock: ... # This is an example configuration file for the LVM2 system. ... # Configuration of metadata backups and archiving. ...
    (Debian-User)