First, rights are managed by the file system, so the file system mediates
sharing. I have always acceped “Magic” as the right explanation.
However, CreateFile is not the only way handles come into existence.
DuplicateHandle creates /another/ handle, which must also be closed
byCloseHandle. But this handle /shares/ the FileObject, so a single
FileObject can have multiple handles. There is an implicit
DuplicateHandle which takes care of handle inheritance. So for ever
CreateFile call, there are a potentially very large number of CloseHandle
calls.
Then there’s the issue that CloseHandle closed all kinds of handles:
thread handles, process handles, mutex handles, semaphore hadles, and
event handles, and that all these handles can be duplicated or inherited
(this list is not mean to be exhaustive; there are many other kinds of
handles, and not all objects of type HANDLE are closed with CloseHandle,
but I think you can safely ignore those.
But measuring handle lifetime from create-to-close is not going to tell
you what you think; for example, pipe handles to a child process may
appear to have an extremely short lifetime, but you are seeing only half
the problem (a handle represents just one end of a pipe), and you have to
be cocerned with the inherited handles to get a good idea of the lifetime.
Consider this program, count.c
void main()
{
int i;
for(i = 1; i > 0; i++)
printf(“%d\n”, i);
}
which should print out all the positive integers from 1 to 2.4…G (ok,
it’s sloppy programming, but I wanted a trivial example). If I invoke it
as
count > data.txt
Then the shell has a CreateFile/CloseHandle lifetime of something
conveniently measured in milliseconds, but the file object (accessed via
the inherited handle) has a lifetime (and somebody else can do the math
here) conveniently measured in days or weeks, or maybe even months. Make
that a LONGLONG and the units are millenia (I can tell that one easily).
So CreateFile and CloseHandle are irrelevant. You would want to measure
the time from an IRP_MJ_CREATE to an IRP_MJ_CLOSE.
joe
Hi Bill Wandel,
so every CreateFile call ( even on the same file or not ) will create a
new file object? how are things like share rights solved then?
NTFSD is sponsored by OSR
For our schedule of debugging and file system seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer