Hello everyone,


Suppose I have a file created with FILE_ATTRIBUTE_NORMAL attribute. I think
it means attribute FILE_FLAG_WRITE_THROUGH is not enabled. Is my
understanding correct?

And I think if I do not enable the FILE_FLAG_WRITE_THROUGH attribute, even
if flush operation (function call) will not *truly* dump data to disk. Is my
understanding also correct?

So, my question is, when will the data be dumped to disk -- only when we
close the file?


thanks in advance,
George

Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by Michael

Michael
Tue Jan 16 08:26:24 CST 2007

FILE_ATTRIBUTE_NORMAL is a property of a file. FILE_FLAG_WRITE_THROUGH is a
property of a handle. You can open any write-able file with
FILE_FLAG_WRITE_THROUGH.

The OS will flush all writes if you have FILE_FLAG_WRITE_THROUGH turned on.

If FILE_FLAG_WRITE_THROUGH is not turned on, then it is up to the FSD to
either cache or go directly to media.

You can always force a flush by calling FlushFileBuffers.


--
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com


"George" <George@discussions.microsoft.com> wrote in message
news:C9F4D9AB-7C6D-4A1B-AB19-7EEB6888F29E@microsoft.com...
> Hello everyone,
>
>
> Suppose I have a file created with FILE_ATTRIBUTE_NORMAL attribute. I
> think
> it means attribute FILE_FLAG_WRITE_THROUGH is not enabled. Is my
> understanding correct?
>
> And I think if I do not enable the FILE_FLAG_WRITE_THROUGH attribute, even
> if flush operation (function call) will not *truly* dump data to disk. Is
> my
> understanding also correct?
>
> So, my question is, when will the data be dumped to disk -- only when we
> close the file?
>
>
> thanks in advance,
> George



Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by ctacke/>

ctacke/>
Tue Jan 16 09:43:05 CST 2007

> Do you mean even if I only invoke write API (without flush) when in
> FILE_FLAG_WRITE_THROUGH mode, the OS buffer and the physical content on
> disk
> are the same?

No, it means that the OS will flush all writes. The driver for the media
where that file will determine if that means physically writing it. In most
cases it will, but there are flash SOCs and external controllers that may
have something to say about it - as they may be doing wear levelling or
performance caching internally.

> Another question is, if FILE_FLAG_WRITE_THROUGH mode is not enabled, how
> will data lose? (I think if FILE_FLAG_WRITE_THROUGH is not enabled, we
> could
> invoke flush, and whether or not FILE_FLAG_WRITE_THROUGH is enebled, flush
> will definitely write OS buffer data to external disk. Is my understanding
> correct?)

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.

--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--



Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by George

George
Tue Jan 16 20:18:01 CST 2007

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

Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by Michael

Michael
Thu Jan 18 09:45:23 CST 2007

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



Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by George

George
Thu Jan 18 20:31:01 CST 2007

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
>
>
>

Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by ctacke/>

ctacke/>
Thu Jan 18 22:34:32 CST 2007

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
>>
>>
>>



Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by ctacke/>

ctacke/>
Fri Jan 19 15:03:15 CST 2007

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
>> >>
>> >>
>> >>
>>
>>
>>



Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by George

George
Sat Jan 20 04:35:00 CST 2007

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
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by ctacke/>

ctacke/>
Sat Jan 20 08:09:46 CST 2007

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
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>



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
> >> >> >>
> >> >> >>
> >> >> >>
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>

Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by ctacke/>

ctacke/>
Sun Jan 21 08:14:10 CST 2007

> 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.

There's a lot of info on the web Google will get you there. JFFS in Linux
is the same premise, so that might get you accessto source if you really
want to see the guts of how it works. My guess is Wikipedia probably has a
decent explanation of how it works from a higher level. Unless you're
writing the filesystem, which is highly unlikely as there are companies that
make a business out of just this, then that's really all you need.

>
> 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?)
>

Transactional (or journaling) filesystems are a generic thing. There are
many implementations. Microsoft has TFAT and CE has support for it. I have
no idea if WM uses it, though I'd think it's unlikely as they have
batteries, and a power loss is pretty rare. If it's not there you can't add
it unless you're an OEM.

If it is there, it's only going to be used for the on-board flash - external
media (like an inserted card) will be FAT. If it were TFAT, the desktop
couldn't read it.


--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--




Re: question about CreateFile and FILE_FLAG_WRITE_THROUGH by George

George
Sun Jan 21 22:39:00 CST 2007

Thanks Chris,


> Transactional (or journaling) filesystems are a generic thing. There are
> many implementations. Microsoft has TFAT and CE has support for it. I have
> no idea if WM uses it, though I'd think it's unlikely as they have
> batteries, and a power loss is pretty rare. If it's not there you can't add
> it unless you're an OEM.
>
> If it is there, it's only going to be used for the on-board flash - external
> media (like an inserted card) will be FAT. If it were TFAT, the desktop
> couldn't read it.
>
>
> --
> Chris Tacke
> OpenNETCF Consulting
> Managed Code in the Embedded World
> www.opennetcf.com

You mean only mobile device's internal storage is TFAT (for example,
internal RAM/Flash), and external storage like SD/CF card are using standard
FAT?

I am surprised that you mentioned that TFAT is not compatible with FAT --
since you mentioned that normal desktop could not read TFAT file system. Is
my understanding correct?


regards,
George