Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by George
George
Sun Jan 21 02:52:01 CST 2007
Thanks Chris!
From your reply, I am more aware of what are the key features/differences
between FAT and TFAT.
Two more simple questions,
1. You are an expert of FAT and TFAT area. Do you have any technical
documents to recommend? I want to learn more about the internal
design/implementation and best practices.
2. Is TFAT truly implemented or just some beta version released? Is it a
part of the OS or a part of the file system driver? (i.e. who is responsible
for implementing this, Microsoft Windows Mobile OS?)
regards,
George
"<ctacke/>" wrote:
> If power is lost during a write, the data being written will be incomplete
> and therefore corrupt. Period. No matter what you have going on, that is a
> fact. If you have a TFAT, when the system comes back up it will recognize
> that it happened and either commit the transaction again or roll it back,
> depending on where exactly in the transaction it was when the failure
> occurred. If it has enough info to be able to recreate the write it will -
> if not the write is lost forever.
>
> FAT has no transactions. It just writes. The next time it comes up it will
> mount the volume as normal (as long as the corruption didn't destroy the FAT
> or sector 0). What it sees at the location of the interrupted write could
> be anything, and it has no way to either redo or undo it.
>
>
> --
> Chris Tacke
> OpenNETCF Consulting
> Managed Code in the Embedded World
> www.opennetcf.com
> --
>
>
> "George" <George@discussions.microsoft.com> wrote in message
> news:E8863B92-37D7-46A3-A2E5-A48802E951E9@microsoft.com...
> > Thanks Chris!
> >
> >
> > After reading your comments, I agree with you and I think we are talking
> > about two different things -- I am talking about logical reliability and
> > you
> > are more interested in physical reliability.
> >
> > I am interested that TFAT will still make data lost in your description?
> > Is
> > that right? I think your points are TFAT is able to recover the data next
> > time when system starts if system errors occur (like power), but FAT does
> > not
> > such feature. And at the point when system error occurs, both TFAT and FAT
> > will cause data inconsistency at that time. In my understanding correct?
> >
> > I am wondering what is the reason normal FAT will lose data? Is it because
> > cached (buffered) data is not written to disk when system error occurs?
> >
> >
> > regards,
> > George
> >
> > "<ctacke/>" wrote:
> >
> >> No, I do not agree. It doesn't matter what flag you set - the operation
> >> is
> >> not atomic and you will lose data if a write operation is interrupted if
> >> you
> >> don't have a transactional filesystem (as I said before, even TFAT loses
> >> the
> >> data, it's just able to get it back after the fact). The nature of the
> >> loss
> >> depends on what was being written. If it was actually writing to the FAT
> >> itself I've seen entire disks get corrupted (meaning a loss of all data
> >> on
> >> the volume). There is no "fix" for that short of bending the laws of
> >> physics.
> >>
> >>
> >> --
> >> Chris Tacke
> >> OpenNETCF Consulting
> >> Managed Code in the Embedded World
> >> www.opennetcf.com
> >> --
> >>
> >>
> >> "George" <George@discussions.microsoft.com> wrote in message
> >> news:DD722AD2-4FF5-4B2D-B721-23C0ED5BE7B2@microsoft.com...
> >> > Thanks Chris!
> >> >
> >> >
> >> > I think you are talking about the case when we issue write without
> >> > FILE_FLAG_WRITE_THROUGH flag set, right?
> >> >
> >> > I think in the following two scenarios, it should be ensured by OS that
> >> > no
> >> > data is lost.
> >> >
> >> > 1. FILE_FLAG_WRITE_THROUGH is set;
> >> > 2. FILE_FLAG_WRITE_THROUGH is not set, but we invoke flush.
> >> >
> >> > Do you agree or have any comments?
> >> >
> >> >
> >> > regards,
> >> > George
> >> >
> >> > "<ctacke/>" wrote:
> >> >
> >> >> I'd say a resounding no. Unless the device has a transactional
> >> >> filesystem,
> >> >> any power interruption during a write can lead to corruption. Flash
> >> >> writes
> >> >> are *not* atomic operations, and writing file data often takes several
> >> >> writes. If you lose power during a write, you *will* have corruption.
> >> >> There's no way around that. If you have a TFAT it can at least
> >> >> recover
> >> >> from
> >> >> the corruption.
> >> >>
> >> >>
> >> >> --
> >> >> Chris Tacke
> >> >> OpenNETCF Consulting
> >> >> Managed Code in the Embedded World
> >> >> www.opennetcf.com
> >> >> --
> >> >>
> >> >>
> >> >>
> >> >> "George" <George@discussions.microsoft.com> wrote in message
> >> >> news:CD6ECCB2-DCC9-4C21-AB76-B83AD83F31DA@microsoft.com...
> >> >> > Thanks Michael!
> >> >> >
> >> >> >
> >> >> > I think whether or not FILE_FLAG_WRITE_THROUGH flag is set, if we
> >> >> > invoke
> >> >> > flush API (FileFlushBuffers), the data cached in buffer will be
> >> >> > ensured
> >> >> > to
> >> >> > be
> >> >> > on disk. Do you agree?
> >> >> >
> >> >> > If you agree, why there will be data lost issue when power is off?
> >> >> >
> >> >> >
> >> >> > regards,
> >> >> > George
> >> >> >
> >> >> > "Michael J. Salamone" wrote:
> >> >> >
> >> >> >> There can be data loss if, for example, you lose power.
> >> >> >>
> >> >> >> --
> >> >> >> Michael Salamone [eMVP]
> >> >> >> Entrek Software, Inc.
> >> >> >> www.entrek.com
> >> >> >>
> >> >> >>
> >> >> >> "George" <George@discussions.microsoft.com> wrote in message
> >> >> >> news:EC37932C-0EBB-48E1-8D35-253A3D6E03D0@microsoft.com...
> >> >> >> > Thanks Chris!
> >> >> >> >
> >> >> >> >> Rather than talk about hypothetical situations, how about you
> >> >> >> >> explain
> >> >> >> >> what
> >> >> >> >> you're either trying to do or what failure you're seeing and we
> >> >> >> >> can
> >> >> >> >> help
> >> >> >> >> you
> >> >> >> >> work through it.
> >> >> >> >
> >> >> >> > I am writing an application which needs to do I/O frequently (in
> >> >> >> > other
> >> >> >> > words, it means I/O is a performance bottleneck), and I am
> >> >> >> > studying
> >> >> >> > some
> >> >> >> > technologies to improve I/O performance.
> >> >> >> >
> >> >> >> > I have read some articles which briefly introduce that disable
> >> >> >> > FILE_FLAG_WRITE_THROUGH flag will improve performance, but it
> >> >> >> > will
> >> >> >> > be
> >> >> >> > prone
> >> >> >> > to data lost issues when application is not terminated properly?
> >> >> >> > I
> >> >> >> > have
> >> >> >> > not
> >> >> >> > found the reason why there will be data lost issue, so I am
> >> >> >> > asking
> >> >> >> > for
> >> >> >> > help
> >> >> >> > here to explain the reason and how to prevent from data lost.
> >> >> >> >
> >> >> >> > Any help are appreciated.
> >> >> >> >
> >> >> >> >
> >> >> >> > regards,
> >> >> >> > George
> >> >> >>
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>