Let’s create a hypothetical test program:
- Two threads
- Each thread allocates 1GB of memory
- Each thread fills its memory with a unique byte pattern
- Each thread opens a file for non-cached write access (share write)
- Each thread calls write file without using any synchronization
mechanism
This is simple, but it demonstrates the problem - each THREAD here is
synchronous, but the underlying OS presents each of these I/O operations
as a discrete asynchronous I/O operation.
Now, the question becomes: “If I pull the plug on the machine and then
examine the state of the file, is there a single valid state?” The
answer to this should be fairly clear to almost everyone: “no”.
The total set of possible states is going to depend upon details of the
file system implementation. We could, for example, have a file system
that serializes all I/O operations (but don’t run a database on such an
FSD because performance will be bad.) Perhaps the FSD breaks up these
I/O operations into multiple disjoint pieces (look in the WDK for
“Associated Irps” and look at the corresponding code in FAT (deviosup.c
as I recall) and see how it can take one operation and break it up into
multiple disjoint operations.
So, my quick conclusion from this thought experiment is that in fact
it’s probably possible that ALL combinations of states at the atomic
level of write could occur - and would be valid outcomes. Determining
specific of the probability cloud here would likely involve a thorough
understanding of the actual hardware.
Of course we have transactional systems available to us to help protect
against such non-deterministic behavior.
Tony
Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J. Clarke
Sent: Thursday, September 28, 2006 8:24 AM
To: ntfsd redirect
Subject: Re:[ntfsd] How to judge a file is been read by IRP_MJ_CREATE?
I hope we can capture you in this thread a little longer. On the
semantics
of the file systems in windows …
In the simplest case where the two writes are different data but the
exact
same byte range in the file^H^H^H^Hstream. Imagine on of the writes has
all
bytes set to ‘A’ and the other has all bytes set to ‘B’.
Two valid states are that the byte range of the file at the end contains
all
‘A’ or all ‘B’.
Are there valid states where some of the byte range in the file contains
‘A’
and some of the byte range in the file contains ‘B’?
Are there valid states where some of the byte range in the file contains
neither ‘A’ nor ‘B’?
[omitted quoted text]