關於“IRP_MJ_CREATE ” 的Dispatch中判斷FileObject是文件還是目錄問題

當Ring3 CreateFile發起對某個文件對象的請求時,如:C:/Program Files/Microsoft Visual Studio/VC98/LIB/LIBC.lib"。請求進入Ring0,Fs會把該請求生成多個IRP_MJ_CREATE,逐層的打開目錄對象,直至到目標文件LIBC.lib,所以在
IRP_MJ_CREATE的Dispatch中的IrpSp->Parameters.Create.Options & FILE_DIRECTORY_FILE可以判斷到達目標文件對象前的那些請求,肯定就是目錄。

 

    注意:但在IRP_MJ_CREATE的Dispatch中無法使用IrpSp->Parameters.Create.Options & FILE_DIRECTORY_FILE來判斷目標文件對象(LIBC.lib)是文件還是目錄,得將IRP傳遞到底層後,在完成例程中判斷目標文件對象是文件還是目錄。而上述是因爲目標文件前的一定是目錄,所以可以判斷。
待續~


參考:

Osr

Q58 How do I determine if the FILE_OBJECT represents a file or a directory from my filter driver? Can I rely upon the FILE_DIRECTORY_FILE bit? 
http://www.osronline.com/article.cfm?article=17#Q58

 

The determination of whether or not a given FILE_OBJECT represents a directory is the sole domain of the file system driver. Thus, for a file system filter driver to determine if a file is a directory, it must ask the file system. This can be done by querying the attributes of the file (e.g., after it has been successfully opened by the underlying file system) or by examining the attributes within the directory, which can be done before the underlying file has been opened.

Options specified during create are not adequate for determining if a file is, in fact, a directory. For example, an application may optionally specify that the file being opened must be a directory by setting the FILE_DIRECTORY_FILE option as part of create (this is a bit in the I/O Stack location, Parameters.Create.Options, the low 24 bits of which are used for file options). If the file creation is successful, the file system filter driver can conclude that the FILE_OBJECT does represent a directory. If the file creation is successful and the caller did not specify FILE_DIRECTORY_FILE, however, the caller cannot presume that the file is a directory. The FILE_NON_DIRECTORY_FILE bit can similarly be used to determine that the given FILE_OBJECT does not represent a file.

There is one complication for those writing a file system filter driver - they must keep in mind that some file options now combine these two bits. For example FILE_COPY_STRUCTURED_STORAGE (which is not used but is still present in ntifs.h for Windows XP) is defined as FILE_DIRECTORY_FILE and FILE_NON_DIRECTORY_FILE.

Thus, the safest way to determine if a FILE_OBJECT represents a directory remains to ask the underlying file system.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章