Getting the short file name of a topmost directory

Given a directory like ‘\foobar_long_name’, I’m trying to find its short file name by first calling FltCreateFileEx on its parent directory, '', and then calling FltQueryDirectoryFile with ‘foobar_long_name’. However, when I try FltCreateFileEx with '', I get STATUS_OBJECT_TYPE_MISMATCH. My call looks like:

status =
FltCreateFileEx(
ROFData.Filter,
pInst,
&hDirectory,
&pDirectoryObj,
FILE_LIST_DIRECTORY,
&oa,
&iostatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
FILE_OPEN,
FILE_DIRECTORY_FILE,
NULL,
0,
0);

Maybe the result means it’s not a directory, but I how do I get the root directory so I can call FltCreateFileEx on one of its child files or directories?

This is roughly what FltGetFileNameInformation does… Any reason why
you’re not using that function?

Thanks,
Alex.

My call isn’t in the context of a callback so I don’t have the PFLT_CALLBACK_DATA required to call FltGetFileNameInformation. I read the directory out of the registry but I need to get the short filename as well. My code works for any directory that isn’t the root of the volume, so I’m trying to figure out what to do in that one case.

In that case you might want to use FltGetFileNameInformationUnsafe. It is meant exactly for your scenario, which is to call FltGetFileNameInformation outside the context of an IO…