Querying for file size in PreCreate

Hi,
I am a rookie, and am playing with the Mini Filter Driver. This is a simple project that i am trying to do. The filter driver will take two directory paths : $Source and $Cache.
If the file exists in the Source directory and is of non-zero size, it should not do anything. On the other hand if somebody tries to open a file in the source directory which is of size zero, it should look up the Cache Directory for a file with the same name, and if it exists, it should replace the corresponding file in the source directory. On the other hands, if the file does not exist in the Cache Directory as well it should give an error to the end user application.

I have a mini-filter driver with callback registered for IRP_MJ_CREATE. I have both pre and post create methods.

> In the pre-create method, i check the file path, and see if this file is in the source directory.

Now I want to check the file-size of the file, to check if it is zero, and if i am interested in this. How can i achieve this? I guess if i try to do FltQueryInformationFile in the PreCreate of IRP_MJ_CREATE, it will not work.

Should i be doing this in the postcreate method?

In your precreate callback, open the file using FltCreateFile. And using the handle obtained call FltQueryInformationFile. Just remember to open the file with FILE_OPEN disposition flag.

Regards,
Ayush Gupta
http://windows-internals.blogspot.com/

Check out the all-new Messenger 9.0! Go to http://in.messenger.yahoo.com/