ZwQueryInformationFile

Hi all,
The DDK interface ZwQueryInformationFile does not return the drive letter if
the FileNameInformation is requested. Does, anyone know how to determine
this information??
Thanks,
Samarth

Hi all,
I trying to use ZwQueryInformationFile() KPI to get the relative path of a
file. However, the second member of the _FILE_NAME_INFORMATION structure
(WCHAR FileName[1]) is an array of just 1 byte. As a result a call to this
KPI returns with an insufficient buffer error and does not fill in the file
name.
What procedure is to be followed for extracting the correct filename using
this KPI??
Thank you,
Samarth

The FileName field is just a place holder for the file name. The idea
is that you allocate a buffer to contain the structure *and* the file
name in one block. You then pass the total buffer size to the
function and, if successful, you can then access the file name using
the FileName field.

An example (psuedo code)

PFILE_NAME_INFORMATION pFileInfo;
PVOID pBuffer;
ULONG dwSize;

dwSize = sizeof(FILE_NAME_INFORMATION) + (MAX_PATH * sizeof(WCHAR));

pBuffer = ExAllocatePool(NonPagedPool, size);

pFileInfo = (PFILE_NAME_INFORMATION) pBuffer;

ZwQueryInformation(… pFileInfo, dwSize, …);

DbgPrint(“File name = %S\n”, pFileInfo->FileName);

Shaun

Saturday, May 31, 2003, 1:03:27 PM, you wrote:

SS> Hi all,
SS> I trying to use ZwQueryInformationFile() KPI to get the relative path of a
SS> file. However, the second member of the _FILE_NAME_INFORMATION structure
SS> (WCHAR FileName[1]) is an array of just 1 byte. As a result a call to this
SS> KPI returns with an insufficient buffer error and does not fill in the file
SS> name.
SS> What procedure is to be followed for extracting the correct filename using
SS> this KPI??
SS> Thank you,
SS> Samarth

SS> —
SS> You are currently subscribed to ntdev as: xxxxx@sdlabs.net
SS> To unsubscribe send a blank email to xxxxx@lists.osr.com

Hi Shaun,
Thanks for the info. However, using this method causes my driver to give a
BSOD with a KMODE_EXCEPTION_NOT_HANDLED and PAGEFAULT_IN_NONPAGEDAREA. I am
freeing the memory that is allocated to pBuffer(> PVOID pBuffer;) in my
function.
Any idea as to why i’m getting such behaviour.
Thanks again,
Samarth

That error usually means a bad pointer somewhere. If you post the
your actual code, we may be able to spot the problem. You may want to
try stepping through it with a debugger or doing some DbgPrints
before each line of code to find out exactly where the fault happens.

Shaun

Monday, June 2, 2003, 8:28:35 AM, you wrote:

SS> Hi Shaun,
SS> Thanks for the info. However, using this method causes my driver to give a
SS> BSOD with a KMODE_EXCEPTION_NOT_HANDLED and PAGEFAULT_IN_NONPAGEDAREA. I am
SS> freeing the memory that is allocated to pBuffer(> PVOID pBuffer;) in my
SS> function.
SS> Any idea as to why i’m getting such behaviour.
SS> Thanks again,
SS> Samarth

thanks Shaun… i was able to debug the problem with the
zwqueryinformationfile()…
but i’m sure other problems will crop up soon…:slight_smile:
thanks
Samarth
“Shaun” wrote in message news:xxxxx@ntdev…
>
> That error usually means a bad pointer somewhere. If you post the
> your actual code, we may be able to spot the problem. You may want to
> try stepping through it with a debugger or doing some DbgPrints
> before each line of code to find out exactly where the fault happens.
>
> Shaun
>
> Monday, June 2, 2003, 8:28:35 AM, you wrote:
>
> SS> Hi Shaun,
> SS> Thanks for the info. However, using this method causes my driver to
give a
> SS> BSOD with a KMODE_EXCEPTION_NOT_HANDLED and PAGEFAULT_IN_NONPAGEDAREA.
I am
> SS> freeing the memory that is allocated to pBuffer(> PVOID pBuffer;) in
my
> SS> function.
> SS> Any idea as to why i’m getting such behaviour.
> SS> Thanks again,
> SS> Samarth
>
>
>
>