>
That seems somewhat fishy to me. What happens when the last handle is
closed between when FO_HANDLE_CREATED >is tested and ObOpenObjectByPointer
is called?
There is nothing fishy, if the OBJECT is a FILE_OBJECT, they functions have
to acquire the MainResource exclusively. Which one acquires it is the
winner.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Skywing
Sent: Wednesday, August 13, 2008 3:41 AM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Re:How to detect last handle getting closed for a
particular file ?
That seems somewhat fishy to me. What happens when the last handle is
closed between when FO_HANDLE_CREATED is tested and ObOpenObjectByPointer is
called?
Incidentally, and curiously enough, it seems that IopCloseFile *sets*
FO_HANDLE_CREATED before sending IRP_MJ_CLEANUP on down. (Though, one would
expect that this flag should have already been set to ever get into
IopCloseFile in the first place.)
The fact that this is done leads me to believe that FO_HANDLE_CREATED isn’t
magically unset after the fact, as it certainly won’t be unset down the
IRP_MJ_CLEANUP path. This begs the question of how you are supposed to
synchronize with cleanup processing with respect to calling
ObOpenObjectByPointer on PFILE_OBJECTs.
Then again, perhaps the close routine is synchronized with new handle
creation. Not sure that really helps you though, as there is still the
problem of you having a PFILE_OBJECT that you stashed away somewhere, which
then gets the last handle closed, and there not being a particularly great
way to synchronize with that happening to ensure that you never call into
ObOpenObjectByPointer with a PFILE_OBJECT that already has undergone
cleanup. To safely handle that case, you would need to synchronize with the
object manager close callout.
I’ll have to see about poking at this in a test driver. It seems that to
work safely (if safely -> not allow a handle to be reopened once
IopCloseFile is invoked), though, that IopCloseFile must be synchronized
with handle creation for PFILE_OBJECTs, and that it must test for
IopCloseFile having already been entered.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Bercea Gabriel
Sent: Tuesday, August 12, 2008 7:43 PM
To: Windows File Systems Devs Interest List
Subject: RE: [ntfsd] Re:How to detect last handle getting closed for a
particular file ?
Well, first let’s see what happens when a handles get closed. I/O manager
has an internal routine called IopCloseFile(), that has very little logical
steps involved:
- if the process has any other handles opened for the file object the
function simply returns
- the I/O manager checks whether it should call the FSD to make certain
byte range unlocks
- now if all handles to the file object are closed, the I/O manager makes
an IRP with IRP_MJ_CLEANUP as major function and invokes FSD
Logical steps involved in the CLEANUP:
- Synch the cleanup with the create by acquiring the VCB resource
exclusively during cleanup (so during cleanup you cannot create anything.
This also serializez all cleanup requests for a logical volume.
- if the cleanup is for a directory the cleaunup routine invokes the
FsRtlNotifyCleanup() routine to complete any pending IRP for the FileObject
- unlock any byte range locks acquired by the process in whose context the
cleanup routine was called
- update time stamps if file modified
- invoke CcUnitializeCacheMap for all FCB structure regardless whether
caching has been initialized or not
- set FO_CLEANUP_COMPLETE flag in FO flag member
- remove share acces, IoRemoveShareAccess()
Now comments on the ObOpenObjectbyPointer:
" If the Object parameter points to a file object (that is, a FILE_OBJECT
structure), ObOpenObjectByPointer can only be called after at least one
handle has been created for the file object. Callers can check the Flags
member of the FILE_OBJECT structure that the Object parameter points to. If
the FO_HANDLE_CREATED flag is set, this means that one or more handles have
been created for the file object, so it is safe to call
ObOpenObjectByPointer. "
Now your questions becomes pointless because IRP_MJ_CLEANUP being closed you
call to ObOpenObjectByPointer is not “safe to call” .
Now according to the logical steps involved in a cleanup request, and
knowing that the object manager has the ObCreateObjectType routine, the
Object Manager is “aware” of what object you are trying to re-create a
handle after it’s last handle was closed, to some you may be granted, the
access, to some no. Be aware the IRP_MJ_CLEANUP is only for file objects.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Lyndon J Clarke
Sent: Tuesday, August 12, 2008 11:04 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] Re:How to detect last handle getting closed for a
particular file ?
What a fascinating question! The related question, perhaps another great
question in filter interop, is what happens if a lower filter calls
ObOpenObjectByPointer, *before* the file system processes the IRP_MJ_CLEANUP
… blech!
“Skywing” wrote in message news:xxxxx@ntfsd…
Out of curiousity, what happens if someone calls ObOpenObjectByPointer to
open a new HANDLE after IRP_MJ_CLEANUP?
- S
-----Original Message-----
From: Lyndon J Clarke
Sent: Sunday, August 10, 2008 11:23
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] How to detect last handle getting closed for a
particular file ?
No so … IRM_MJ_CLEANUP will be sent when the last handle for a FILE_OBJECT
is closed.
This is quite different to the “last handle for a file” since of course
there can be, and often are, multiple FILE_OBJECT for the same file.
If you want to know if you receive the last IRP_MJ_CLEANUP for a file, in
other words IRP_MJ_CLEANUP for the last remaining FILE_OBJECT for the file,
you have no choice but to count file objects.
wrote in message news:xxxxx@ntfsd…
> Irp-mj-cleanup is called by i/o manager when the last outstanding handle
> for a file was closed.
>
—
NTFSD is sponsored by OSR
For our schedule debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars
You are currently subscribed to ntfsd as: xxxxx@valhallalegends.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
—
NTFSD is sponsored by OSR
For our schedule debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars
You are currently subscribed to ntfsd as: xxxxx@gmail.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
—
NTFSD is sponsored by OSR
For our schedule debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars
You are currently subscribed to ntfsd as: xxxxx@valhallalegends.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
—
NTFSD is sponsored by OSR
For our schedule debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars
You are currently subscribed to ntfsd as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com