EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Determine whether a file exists and is a directory [Crash]

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#25282
Posted: 06/13/2013 09:35:28
by Vladimir Cherniga (EldoS Corp.)

Quote
...whether it is a regular file (as opposed to a directory)

You may check the flags indicate in CreateOptions - FILE_NON_DIRECTORY_FILE = 0x00000040 and FILE_DIRECTORY_FILE = 0x00000001, they indicate the desired access of opening file. In order to request file attributes, you must use a handle, obtained with CallbackFilter::OpenFile() api, otherwise it may lock within callbacks.
#25284
Posted: 06/13/2013 10:02:03
by david bennett (Standard support level)
Joined: 03/29/2013
Posts: 50

Quote
Vladimir Cherniga wrote:
Quote
You may check the flags indicate in CreateOptions - FILE_NON_DIRECTORY_FILE = 0x00000040 and FILE_DIRECTORY_FILE = 0x00000001, they indicate the desired access of opening file. In order to request file attributes, you must use a handle, obtained with CallbackFilter::OpenFile() api, otherwise it may lock within callbacks.


I tried this. This doesn't work unless the caller actually tells you that the file is a directory. If they are just trying to open an existing file, these values are not set. I don't just need to know whether the caller thinks they are opening a regular file or directory, but whether the file is *actually* a file or directory.
#25285
Posted: 06/13/2013 10:05:22
by Vladimir Cherniga (EldoS Corp.)

Do you need to check the file attribute in pre-create path ? Can you check it in postcreate/postopen ?
#25286
Posted: 06/13/2013 10:22:33
by david bennett (Standard support level)
Joined: 03/29/2013
Posts: 50

Quote
Vladimir Cherniga wrote:
Do you need to check the file attribute in pre-create path ? Can you check it in postcreate/postopen ?


This is a good question, but unfortunately I need to know in the precreate path because I use this information to decide whether to use the Reparsed filename or not.
#25287
Posted: 06/13/2013 10:25:40
by Vladimir Cherniga (EldoS Corp.)

I will check the problem in a short. Move question to helpdesk.
#25288
Posted: 06/13/2013 10:27:43
by Eugene Mayevski (EldoS Corp.)

Did you have a chance to try FindFirstFile? This might be an easier way.


Sincerely yours
Eugene Mayevski
#25289
Posted: 06/13/2013 10:33:49
by david bennett (Standard support level)
Joined: 03/29/2013
Posts: 50

Checking against the correct value for INVALID_HANDLE_VALUE has improved the situation. It no longer hangs. I'm not yet able to correctly determine whether the file is a directory, but I will try the FindFirstFile experiment and let you know.
#25290
Posted: 06/13/2013 10:41:49
by Vladimir Cherniga (EldoS Corp.)

Do you check FILE_ATTRIBUTE_DIRECTORY flag in FileAttributes parameter for the files exists ?
#25291
Posted: 06/13/2013 11:06:39
by david bennett (Standard support level)
Joined: 03/29/2013
Posts: 50

Quote
Vladimir Cherniga wrote:
Do you check FILE_ATTRIBUTE_DIRECTORY flag in FileAttributes parameter for the files exists ?


This bit doesn't seem to be set in all cases. It would have been nice if it were. I suspect it's a guess on the part of the calling app rather than being set by the OS before OnOpenFileC is called.
#25292
Posted: 06/13/2013 13:07:40
by david bennett (Standard support level)
Joined: 03/29/2013
Posts: 50

The FindFirstFile fix works. I was hoping for a less expensive alternative but at least I am getting what I need.

So there were really two issues: 1) I was checking the handle against NULL(per the documentation) rather than INVALID_FILE_HANDLE and 2) GetFileInformationByHandle() just doesn't work with the handle returned by CallbackFilter::OpenFile().

I think I am ready to find the next problem! Thanks for your help!
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 7639 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!