You can find all File Objects with active handles by using “!handle 0 3 0 File”. If there are no handles then you could try enabling object tracking and then dumping with “!object 0 File”
@“Scott_Noone_(OSR)” said:
What’s the failure scenario?
You can find all File Objects with active handles by using “!handle 0 3 0 File”. If there are no handles then you could try enabling object tracking and then dumping with “!object 0 File”
But in either case you’re just going to know that there is a File Object, but not necessarily who owns it or created it.
If I recall correctly, a FILE_OBJECT is created for every usermode (CreateFile) or kernelmode (ZwCreateFile, FltCreateFile) handle that is opened on the target file, Correct? So if there is no open handle on a particular file, I assume I can’t find any FILE_OBJECT for that file right?
Objects have both handle and reference counts, so just because there are no handles doesn’t mean that there are no objects. That’s what the object tracking option is for.
@“Scott_Noone_(OSR)” said:
Objects have both handle and reference counts, so just because there are no handles doesn’t mean that there are no objects. That’s what the object tracking option is for.
So let’s say I have a file or folder like \Systemroot\Windows, what is the proper command to use to find every FILE_OBJECT (if any) of this file? Do I have to look through the entire output of !handle 0 3 0 File?
Also another side question: In Linux kernel, there is a inode struct which represent each file (no matter the open handles), and then there’s a file structure that represents an open file descriptor (similar to FILE_OBJECT), Is there anything similar to inode struct in Windows? Or if a file is not opened by anyone, then there’s no structure that is representing it? (Not talking about the structure that the underlying filesystem driver is using, but the structure that kernel itself is using no matter the underlying filesystem)
Well, inodes in Linux live on disk. A filesystem that doesn’t have the concept has to simulate them. There is no such file-system-independent structure in Windows, because it does not have the same universal namespace concept. All you get is the FILE_OBJECT. If a file is not opened, then the kernel doesn’t need to refer to it.
@brad_H said:
Also another side question: In Linux kernel, there is a inode struct which represent each file (no matter the open handles), and then there’s a file structure that represents an open file descriptor (similar to FILE_OBJECT), Is there anything similar to inode struct in Windows? Or if a file is not opened by anyone, then there’s no structure that is representing it? (Not talking about the structure that the underlying filesystem driver is using, but the structure that kernel itself is using no matter the underlying filesystem)
I’m not sure this helps with your question but I just wanted to clarify something:
The Windows equivalent to an in memory inode is the File Control Block (FSRTL_ADVANCED_FCB_HEADER) and is stored in the FsContext field of the FILE_OBJECT. So, for example, two File Objects to the same file on disk will have the same FsContext value*. It is the job of the File System to maintain this field as it’s the only one that really knows.
Note that this structure only exists in memory for as long as there is a File Object around that references it. When a file is memory mapped (or used for cached I/O) the Memory Manager will reference one of the File Objects used and keep it around long after the application closes the HANDLE. These references will only ever go away when there’s sufficient memory pressure on the machine or you do something like delete the file.
*It gets more complicated for NTFS because there we support multiple streams per-file. So, NTFS creates its own structure called the Stream Control Block and puts that in FsContext. However, because of the way the OS works the Stream Control Block still starts with an FSRTL_ADVANCED_FCB_HEADER structure).