Retrieving full pathname from handle

Hi.

I am trying to populate the full pathname of a file or directory by
supplying only the file/dir handle to my function.
It can currently populate only the relative path without the drive letter
name (for example C:).

I would like the output format to be a Unicode string with a syntax that is
somewhat like “C:\SomeDir\SomeOtherDir\file.ext”.
I’ve included my function’s source in this message. Any help will be
appreciated.

Thanks in advance,

Gleb

//-------------------------------------------------------------------

NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,
OUT PUNICODE_STRING FileName)
{
PIO_STATUS_BLOCK pioStatusBlock;
PFILE_NAME_INFORMATION fniFileInfo;
NTSTATUS status;

//
// Allocating memory for pioStatusBlock
//
pioStatusBlock = (PIO_STATUS_BLOCK)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(IO_STATUS_BLOCK),
INDEXER_POOL_TAG
);
if(pioStatusBlock == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
memory for pioStatusBlock");

return status;
}

//
// Allocating memory for fniFileInfo
//
fniFileInfo = (PFILE_NAME_INFORMATION)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
INDEXER_POOL_TAG
);
if(fniFileInfo == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
memory for fniFileInfo");

return status;
}

//
// Populating file name
//
status = ZwQueryInformationFile(FileHandle,
pioStatusBlock,
fniFileInfo,
(ULONG)sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
FileNameInformation);
if(status != STATUS_SUCCESS)
{
ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x", status);

return status;
}

FileName->MaximumLength = fniFileInfo->FileNameLength;
FileName->Length = fniFileInfo->FileNameLength;
FileName->Buffer = fniFileInfo->FileName;
RtlCopyMemory(FileName->Buffer,
&fniFileInfo->FileName,
fniFileInfo->FileNameLength);

ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);

status = STATUS_SUCCESS;

return status;
}

Don’t know about the functionality aspect of your code, but there is no
reason to allocate a IO_STATUS_BLOCK from the heap. You can just
declare the structure on the stack.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Sunday, December 11, 2005 2:54 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Retrieving full pathname from handle

Hi.

I am trying to populate the full pathname of a file or directory by
supplying only the file/dir handle to my function.
It can currently populate only the relative path without the drive
letter
name (for example C:).

I would like the output format to be a Unicode string with a syntax that
is
somewhat like “C:\SomeDir\SomeOtherDir\file.ext”.
I’ve included my function’s source in this message. Any help will be
appreciated.

Thanks in advance,

Gleb

//-------------------------------------------------------------------

NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE
FileHandle,

OUT PUNICODE_STRING FileName)
{
PIO_STATUS_BLOCK pioStatusBlock;
PFILE_NAME_INFORMATION fniFileInfo;
NTSTATUS status;

//
// Allocating memory for pioStatusBlock
//
pioStatusBlock = (PIO_STATUS_BLOCK)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(IO_STATUS_BLOCK),
INDEXER_POOL_TAG
);
if(pioStatusBlock == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION":
Failed to allocate
memory for pioStatusBlock");

return status;
}

//
// Allocating memory for fniFileInfo
//
fniFileInfo = (PFILE_NAME_INFORMATION)ExAllocatePoolWithTag(
NonPagedPool,

sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
INDEXER_POOL_TAG
);
if(fniFileInfo == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION":
Failed to allocate
memory for fniFileInfo");

return status;
}

//
// Populating file name
//
status = ZwQueryInformationFile(FileHandle,
pioStatusBlock,
fniFileInfo,

(ULONG)sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
FileNameInformation);
if(status != STATUS_SUCCESS)
{
ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–.
STATUS %x", status);

return status;
}

FileName->MaximumLength = fniFileInfo->FileNameLength;
FileName->Length = fniFileInfo->FileNameLength;
FileName->Buffer = fniFileInfo->FileName;
RtlCopyMemory(FileName->Buffer,
&fniFileInfo->FileName,
fniFileInfo->FileNameLength);

ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);

status = STATUS_SUCCESS;

return status;
}


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

It’s your duty to get drive letters by other way. Have a look at FileMon.

But, note that drive letter is not enough since a volume could be mounted to
a folder. You can have a practice by mounting a volume to C:\Mounted in Disk
Management.

Regards,
ZG [@ Sydney]
Windows Driver Developer

wrote in message news:xxxxx@ntdev…
> Hi.
>
> I am trying to populate the full pathname of a file or directory by
> supplying only the file/dir handle to my function.
> It can currently populate only the relative path without the drive letter
> name (for example C:).
>
> I would like the output format to be a Unicode string with a syntax that
> is
> somewhat like “C:\SomeDir\SomeOtherDir\file.ext”.
> I’ve included my function’s source in this message. Any help will be
> appreciated.
>
> Thanks in advance,
>
> Gleb
>
> //-------------------------------------------------------------------
>
> NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,
> OUT PUNICODE_STRING FileName)
> {
> PIO_STATUS_BLOCK pioStatusBlock;
> PFILE_NAME_INFORMATION fniFileInfo;
> NTSTATUS status;
>
> //
> // Allocating memory for pioStatusBlock
> //
> pioStatusBlock = (PIO_STATUS_BLOCK)ExAllocatePoolWithTag(
> NonPagedPool,
> sizeof(IO_STATUS_BLOCK),
> INDEXER_POOL_TAG
> );
> if(pioStatusBlock == NULL)
> {
> status = STATUS_INSUFFICIENT_RESOURCES;
>
> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
> memory for pioStatusBlock");
>
> return status;
> }
>
> //
> // Allocating memory for fniFileInfo
> //
> fniFileInfo = (PFILE_NAME_INFORMATION)ExAllocatePoolWithTag(
> NonPagedPool,
> sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
> INDEXER_POOL_TAG
> );
> if(fniFileInfo == NULL)
> {
> status = STATUS_INSUFFICIENT_RESOURCES;
>
> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
>
> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
> memory for fniFileInfo");
>
> return status;
> }
>
> //
> // Populating file name
> //
> status = ZwQueryInformationFile(FileHandle,
> pioStatusBlock,
> fniFileInfo,
> (ULONG)sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
> FileNameInformation);
> if(status != STATUS_SUCCESS)
> {
> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
>
> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x", status);
>
> return status;
> }
>
> FileName->MaximumLength = fniFileInfo->FileNameLength;
> FileName->Length = fniFileInfo->FileNameLength;
> FileName->Buffer = fniFileInfo->FileName;
> RtlCopyMemory(FileName->Buffer,
> &fniFileInfo->FileName,
> fniFileInfo->FileNameLength);
>
>
> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
>
> status = STATUS_SUCCESS;
>
> return status;
> }
>

Design your product in a way so it will only use Volume GUIDs internally
and not the drive letters. The drive letters will appear in the UI only.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From:
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Monday, December 12, 2005 1:53 AM
Subject: [ntdev] Retrieving full pathname from handle

> Hi.
>
> I am trying to populate the full pathname of a file or directory by
> supplying only the file/dir handle to my function.
> It can currently populate only the relative path without the drive letter
> name (for example C:).
>
> I would like the output format to be a Unicode string with a syntax that is
> somewhat like “C:\SomeDir\SomeOtherDir\file.ext”.
> I’ve included my function’s source in this message. Any help will be
> appreciated.
>
> Thanks in advance,
>
> Gleb
>
> //-------------------------------------------------------------------
>
> NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,
> OUT PUNICODE_STRING FileName)
> {
> PIO_STATUS_BLOCK pioStatusBlock;
> PFILE_NAME_INFORMATION fniFileInfo;
> NTSTATUS status;
>
> //
> // Allocating memory for pioStatusBlock
> //
> pioStatusBlock = (PIO_STATUS_BLOCK)ExAllocatePoolWithTag(
> NonPagedPool,
> sizeof(IO_STATUS_BLOCK),
> INDEXER_POOL_TAG
> );
> if(pioStatusBlock == NULL)
> {
> status = STATUS_INSUFFICIENT_RESOURCES;
>
> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
> memory for pioStatusBlock");
>
> return status;
> }
>
> //
> // Allocating memory for fniFileInfo
> //
> fniFileInfo = (PFILE_NAME_INFORMATION)ExAllocatePoolWithTag(
> NonPagedPool,
> sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
> INDEXER_POOL_TAG
> );
> if(fniFileInfo == NULL)
> {
> status = STATUS_INSUFFICIENT_RESOURCES;
>
> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
>
> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
> memory for fniFileInfo");
>
> return status;
> }
>
> //
> // Populating file name
> //
> status = ZwQueryInformationFile(FileHandle,
> pioStatusBlock,
> fniFileInfo,
> (ULONG)sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
> FileNameInformation);
> if(status != STATUS_SUCCESS)
> {
> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
>
> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x", status);
>
> return status;
> }
>
> FileName->MaximumLength = fniFileInfo->FileNameLength;
> FileName->Length = fniFileInfo->FileNameLength;
> FileName->Buffer = fniFileInfo->FileName;
> RtlCopyMemory(FileName->Buffer,
> &fniFileInfo->FileName,
> fniFileInfo->FileNameLength);
>
>
> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
>
> status = STATUS_SUCCESS;
>
> return status;
> }
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

I am writing a driver that makes a list of file creation/deletion events for
a fast index search utility. I have to pass the string in a DOS file name
format to the application.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> Design your product in a way so it will only use Volume GUIDs
> internally
> and not the drive letters. The drive letters will appear in the UI only.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From:
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Monday, December 12, 2005 1:53 AM
> Subject: [ntdev] Retrieving full pathname from handle
>
>
>> Hi.
>>
>> I am trying to populate the full pathname of a file or directory by
>> supplying only the file/dir handle to my function.
>> It can currently populate only the relative path without the drive letter
>> name (for example C:).
>>
>> I would like the output format to be a Unicode string with a syntax that
>> is
>> somewhat like “C:\SomeDir\SomeOtherDir\file.ext”.
>> I’ve included my function’s source in this message. Any help will be
>> appreciated.
>>
>> Thanks in advance,
>>
>> Gleb
>>
>> //-------------------------------------------------------------------
>>
>> NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,
>> OUT PUNICODE_STRING FileName)
>> {
>> PIO_STATUS_BLOCK pioStatusBlock;
>> PFILE_NAME_INFORMATION fniFileInfo;
>> NTSTATUS status;
>>
>> //
>> // Allocating memory for pioStatusBlock
>> //
>> pioStatusBlock = (PIO_STATUS_BLOCK)ExAllocatePoolWithTag(
>> NonPagedPool,
>> sizeof(IO_STATUS_BLOCK),
>> INDEXER_POOL_TAG
>> );
>> if(pioStatusBlock == NULL)
>> {
>> status = STATUS_INSUFFICIENT_RESOURCES;
>>
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
>> memory for pioStatusBlock");
>>
>> return status;
>> }
>>
>> //
>> // Allocating memory for fniFileInfo
>> //
>> fniFileInfo = (PFILE_NAME_INFORMATION)ExAllocatePoolWithTag(
>> NonPagedPool,
>> sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
>> INDEXER_POOL_TAG
>> );
>> if(fniFileInfo == NULL)
>> {
>> status = STATUS_INSUFFICIENT_RESOURCES;
>>
>> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
>>
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
>> memory for fniFileInfo");
>>
>> return status;
>> }
>>
>> //
>> // Populating file name
>> //
>> status = ZwQueryInformationFile(FileHandle,
>> pioStatusBlock,
>> fniFileInfo,
>> (ULONG)sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
>> FileNameInformation);
>> if(status != STATUS_SUCCESS)
>> {
>> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
>>
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x",
>> status);
>>
>> return status;
>> }
>>
>> FileName->MaximumLength = fniFileInfo->FileNameLength;
>> FileName->Length = fniFileInfo->FileNameLength;
>> FileName->Buffer = fniFileInfo->FileName;
>> RtlCopyMemory(FileName->Buffer,
>> &fniFileInfo->FileName,
>> fniFileInfo->FileNameLength);
>>
>>
>> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
>>
>> status = STATUS_SUCCESS;
>>
>> return status;
>> }
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>

So your fast index search utility has to build a map from volume guid to
volume mountpoints.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gleb Suhatski
Sent: Thursday, December 15, 2005 6:00 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Retrieving full pathname from handle

I am writing a driver that makes a list of file creation/deletion events
for
a fast index search utility. I have to pass the string in a DOS file
name
format to the application.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
> Design your product in a way so it will only use Volume GUIDs
> internally
> and not the drive letters. The drive letters will appear in the UI
only.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From:
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Monday, December 12, 2005 1:53 AM
> Subject: [ntdev] Retrieving full pathname from handle
>
>
>> Hi.
>>
>> I am trying to populate the full pathname of a file or directory by
>> supplying only the file/dir handle to my function.
>> It can currently populate only the relative path without the drive
letter
>> name (for example C:).
>>
>> I would like the output format to be a Unicode string with a syntax
that
>> is
>> somewhat like “C:\SomeDir\SomeOtherDir\file.ext”.
>> I’ve included my function’s source in this message. Any help will be
>> appreciated.
>>
>> Thanks in advance,
>>
>> Gleb
>>
>> //-------------------------------------------------------------------
>>
>> NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,
>> OUT PUNICODE_STRING FileName)
>> {
>> PIO_STATUS_BLOCK pioStatusBlock;
>> PFILE_NAME_INFORMATION fniFileInfo;
>> NTSTATUS status;
>>
>> //
>> // Allocating memory for pioStatusBlock
>> //
>> pioStatusBlock = (PIO_STATUS_BLOCK)ExAllocatePoolWithTag(
>> NonPagedPool,
>> sizeof(IO_STATUS_BLOCK),
>> INDEXER_POOL_TAG
>> );
>> if(pioStatusBlock == NULL)
>> {
>> status = STATUS_INSUFFICIENT_RESOURCES;
>>
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to
allocate
>> memory for pioStatusBlock");
>>
>> return status;
>> }
>>
>> //
>> // Allocating memory for fniFileInfo
>> //
>> fniFileInfo = (PFILE_NAME_INFORMATION)ExAllocatePoolWithTag(
>> NonPagedPool,
>> sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
>> INDEXER_POOL_TAG
>> );
>> if(fniFileInfo == NULL)
>> {
>> status = STATUS_INSUFFICIENT_RESOURCES;
>>
>> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
>>
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to
allocate
>> memory for fniFileInfo");
>>
>> return status;
>> }
>>
>> //
>> // Populating file name
>> //
>> status = ZwQueryInformationFile(FileHandle,
>> pioStatusBlock,
>> fniFileInfo,
>> (ULONG)sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
>> FileNameInformation);
>> if(status != STATUS_SUCCESS)
>> {
>> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
>>
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x",
>> status);
>>
>> return status;
>> }
>>
>> FileName->MaximumLength = fniFileInfo->FileNameLength;
>> FileName->Length = fniFileInfo->FileNameLength;
>> FileName->Buffer = fniFileInfo->FileName;
>> RtlCopyMemory(FileName->Buffer,
>> &fniFileInfo->FileName,
>> fniFileInfo->FileNameLength);
>>
>>
>> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
>>
>> status = STATUS_SUCCESS;
>>
>> return status;
>> }
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to
xxxxx@lists.osr.com
>
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Pass the Volume GUID to the app, and let the app map it to drive letter.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Gleb Suhatski”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Thursday, December 15, 2005 2:00 PM
Subject: Re:[ntdev] Retrieving full pathname from handle

> I am writing a driver that makes a list of file creation/deletion events for
> a fast index search utility. I have to pass the string in a DOS file name
> format to the application.
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntdev…
> > Design your product in a way so it will only use Volume GUIDs
> > internally
> > and not the drive letters. The drive letters will appear in the UI only.
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
> >
> > ----- Original Message -----
> > From:
> > Newsgroups: ntdev
> > To: “Windows System Software Devs Interest List”
> > Sent: Monday, December 12, 2005 1:53 AM
> > Subject: [ntdev] Retrieving full pathname from handle
> >
> >
> >> Hi.
> >>
> >> I am trying to populate the full pathname of a file or directory by
> >> supplying only the file/dir handle to my function.
> >> It can currently populate only the relative path without the drive letter
> >> name (for example C:).
> >>
> >> I would like the output format to be a Unicode string with a syntax that
> >> is
> >> somewhat like “C:\SomeDir\SomeOtherDir\file.ext”.
> >> I’ve included my function’s source in this message. Any help will be
> >> appreciated.
> >>
> >> Thanks in advance,
> >>
> >> Gleb
> >>
> >> //-------------------------------------------------------------------
> >>
> >> NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,
> >> OUT PUNICODE_STRING FileName)
> >> {
> >> PIO_STATUS_BLOCK pioStatusBlock;
> >> PFILE_NAME_INFORMATION fniFileInfo;
> >> NTSTATUS status;
> >>
> >> //
> >> // Allocating memory for pioStatusBlock
> >> //
> >> pioStatusBlock = (PIO_STATUS_BLOCK)ExAllocatePoolWithTag(
> >> NonPagedPool,
> >> sizeof(IO_STATUS_BLOCK),
> >> INDEXER_POOL_TAG
> >> );
> >> if(pioStatusBlock == NULL)
> >> {
> >> status = STATUS_INSUFFICIENT_RESOURCES;
> >>
> >> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
> >> memory for pioStatusBlock");
> >>
> >> return status;
> >> }
> >>
> >> //
> >> // Allocating memory for fniFileInfo
> >> //
> >> fniFileInfo = (PFILE_NAME_INFORMATION)ExAllocatePoolWithTag(
> >> NonPagedPool,
> >> sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
> >> INDEXER_POOL_TAG
> >> );
> >> if(fniFileInfo == NULL)
> >> {
> >> status = STATUS_INSUFFICIENT_RESOURCES;
> >>
> >> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
> >>
> >> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
> >> memory for fniFileInfo");
> >>
> >> return status;
> >> }
> >>
> >> //
> >> // Populating file name
> >> //
> >> status = ZwQueryInformationFile(FileHandle,
> >> pioStatusBlock,
> >> fniFileInfo,
> >> (ULONG)sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),
> >> FileNameInformation);
> >> if(status != STATUS_SUCCESS)
> >> {
> >> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
> >> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
> >>
> >> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x",
> >> status);
> >>
> >> return status;
> >> }
> >>
> >> FileName->MaximumLength = fniFileInfo->FileNameLength;
> >> FileName->Length = fniFileInfo->FileNameLength;
> >> FileName->Buffer = fniFileInfo->FileName;
> >> RtlCopyMemory(FileName->Buffer,
> >> &fniFileInfo->FileName,
> >> fniFileInfo->FileNameLength);
> >>
> >>
> >> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);
> >> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);
> >>
> >> status = STATUS_SUCCESS;
> >>
> >> return status;
> >> }
> >>
> >> —
> >> Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >>
> >> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> >> To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Unfortunately I cannot use this method in this particular driver.

Anyhow, I checked OSR lists archive and Google and found a way to do it.
I wrote a function that receives a handle and returns a drive letter, ex. C:
but it crashes.
(By the way, I’m aware that this is a legacy driver and that it should be a
file system driver. nevertheless, I have to sort this
problem out since it’s part of my current project.)

Does anyone see what’s wrong with this function?

Thanks in advance.

NTSTATUS FileDirectoryHandleToUnicodeDosDriveName(IN HANDLE Handle,
OUT PUNICODE_STRING pUnicodeName)
{
IO_STATUS_BLOCK ioStatusBlock;
POBJECT_NAME_INFORMATION pobjObjectNameInfo;
NTSTATUS status;
ULONG ulLength = 0;
PFILE_OBJECT pFileObject;
PDEVICE_OBJECT pDeviceObject;

IndexerDebugPrint(DBG_INIT, DBG_TRACE, FUNCTION"++");

//
// Allocating memory for pobjObjectNameInfo
//
pobjObjectNameInfo = (POBJECT_NAME_INFORMATION)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(OBJECT_NAME_INFORMATION) + (MAX_PATH*2),
INDEXER_POOL_TAG
);
if(pobjObjectNameInfo == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
memory for pobjObjectNameInfo");

return status;
}

//
// Allocating memory for pFileObject
//
pFileObject = (PFILE_OBJECT)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(FILE_OBJECT),
INDEXER_POOL_TAG
);
if(pFileObject == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
memory for pFileObject");

return status;
}

//
// Allocating memory for pDeviceObject
//
pDeviceObject = (PDEVICE_OBJECT)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(DEVICE_OBJECT),
INDEXER_POOL_TAG
);
if(pDeviceObject == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
memory for pDeviceObject");

return status;
}

//
// Getting file object
//
status = ObReferenceObjectByHandle(Handle,
GENERIC_READ,
NULL,
KernelMode,
&pFileObject,
NULL);
if(status != STATUS_SUCCESS)
{
IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x", status);

ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG);

return status;
}

//
// getting file object name
//
status = ObQueryNameString(pFileObject,
pobjObjectNameInfo,
sizeof(OBJECT_NAME_INFORMATION) + (MAX_PATH*2),
&ulLength);
if(status != STATUS_SUCCESS)
{
IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x", status);

ObDereferenceObject(pFileObject);
ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG);

return status;
}

//
// Getting device object pointer
//
IoGetDeviceObjectPointer(/*&pFileObject->FileName*/&pobjObjectNameInfo->Name, FILE_READ_DATA, &pFileObject, &pDeviceObject); if(status != STATUS_SUCCESS) { IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x", status); ObDereferenceObject(pFileObject); ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG); ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG); ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG); return status; } // // converting to C:\ format // IoVolumeDeviceToDosName(pFileObject->DeviceObject, pUnicodeName); // // must dereference File Object // ObDereferenceObject(pFileObject); // // cleaning up // ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG); ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG); ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG); status = STATUS_SUCCESS; return status;}“Roddy, Mark” wrote in message news:xxxxx@ntdev…So your fast index search utility has to build a map from volume guid tovolume mountpoints.-----Original Message-----From: xxxxx@lists.osr.com[mailto:xxxxx@lists.osr.com] On Behalf Of Gleb SuhatskiSent: Thursday, December 15, 2005 6:00 AMTo: Windows System Software Devs Interest ListSubject: Re:[ntdev] Retrieving full pathname from handleI am writing a driver that makes a list of file creation/deletion eventsfora fast index search utility. I have to pass the string in a DOS filenameformat to the application.“Maxim S. Shatskih” wrote in messagenews:xxxxx@ntdev…> Design your product in a way so it will only use Volume GUIDs> internally> and not the drive letters. The drive letters will appear in the UIonly.>> Maxim Shatskih, Windows DDK MVP> StorageCraft Corporation> xxxxx@storagecraft.com> http://www.storagecraft.com>> ----- Original Message -----> From: > Newsgroups: ntdev> To: “Windows System Software Devs Interest List” > Sent: Monday, December 12, 2005 1:53 AM> Subject: [ntdev] Retrieving full pathname from handle>>>> Hi.>>>> I am trying to populate the full pathname of a file or directory by>> supplying only the file/dir handle to my function.>> It can currently populate only the relative path without the driveletter>> name (for example C:).>>>> I would like the output format to be a Unicode string with a syntaxthat>> is>> somewhat like “C:\SomeDir\SomeOtherDir\file.ext”.>> I’ve included my function’s source in this message. Any help will be>> appreciated.>>>> Thanks in advance,>>>> Gleb>>>> //------------------------------------------------------------------->>>> NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,>> OUT PUNICODE_STRING FileName)>> {>> PIO_STATUS_BLOCK pioStatusBlock;>> PFILE_NAME_INFORMATION fniFileInfo;>> NTSTATUS status;>>>> //>> // Allocating memory for pioStatusBlock>> //>> pioStatusBlock = (PIO_STATUS_BLOCK)ExAllocatePoolWithTag(>> NonPagedPool,>> sizeof(IO_STATUS_BLOCK),>> INDEXER_POOL_TAG>> );>> if(pioStatusBlock == NULL)>> {>> status = STATUS_INSUFFICIENT_RESOURCES;>>>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed toallocate>> memory for pioStatusBlock");>>>> return status;>> }>>>> //>> // Allocating memory for fniFileInfo>> //>> fniFileInfo = (PFILE_NAME_INFORMATION)ExAllocatePoolWithTag(>> NonPagedPool,>> sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),>> INDEXER_POOL_TAG>> );>> if(fniFileInfo == NULL)>> {>> status = STATUS_INSUFFICIENT_RESOURCES;>>>> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);>>>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed toallocate>> memory for fniFileInfo");>>>> return status;>> }>>>> //>> // Populating file name>> //>> status = ZwQueryInformationFile(FileHandle,>> pioStatusBlock,>> fniFileInfo,>> (ULONG)sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),>> FileNameInformation);>> if(status != STATUS_SUCCESS)>> {>> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);>> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);>>>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x",>> status);>>>> return status;>> }>>>> FileName->MaximumLength = fniFileInfo->FileNameLength;>> FileName->Length = fniFileInfo->FileNameLength;>> FileName->Buffer = fniFileInfo->FileName;>> RtlCopyMemory(FileName->Buffer,>> &fniFileInfo->FileName,>> fniFileInfo->FileNameLength);>>>>>> ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);>> ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);>>>> status = STATUS_SUCCESS;>>>> return status;>> }>>>> —>> Questions? First check the Kernel Driver FAQ at> http://www.osronline.com/article.cfm?id=256>>>> You are currently subscribed to ntdev as: xxxxx@storagecraft.com>> To unsubscribe send a blank email xxxxx@lists.osr.com>>>—Questions? First check the Kernel Driver FAQ athttp://www.osronline.com/article.cfm?id=256You are currently subscribed to ntdev as: xxxxx@stratus.comTo unsubscribe send a blank email to xxxxx@lists.osr.com

>Unfortunately I cannot use this method in this particular driver.

Yes, you can, and you should. People who clearly know a LOT more than you
do are telling you how to do it and you should listen. Drive letters in
kernel mode aren’t worth much. A volume might not have a drive
letter. Drive letter maps can be different in different sessions. Pass
the volume GUID to user mode.

(By the way, I’m aware that this is a legacy driver and that it should be a
file system driver. nevertheless, I have to sort this
problem out since it’s part of my current project.)

Does anyone see what’s wrong with this function?

There’s so much wrong that I don’t know where to start, but the crash is
probably happening when you try to call ExFreePoolWithTag on a file object.

  • Dan.
    At 07:32 PM 12/15/2005 +0200, you wrote:

Unfortunately I cannot use this method in this particular driver.

Anyhow, I checked OSR lists archive and Google and found a way to do it.
I wrote a function that receives a handle and returns a drive letter, ex. C:
but it crashes.
(By the way, I’m aware that this is a legacy driver and that it should be a
file system driver. nevertheless, I have to sort this
problem out since it’s part of my current project.)

Does anyone see what’s wrong with this function?

Thanks in advance.

NTSTATUS FileDirectoryHandleToUnicodeDosDriveName(IN HANDLE Handle,
OUT PUNICODE_STRING pUnicodeName)
{
IO_STATUS_BLOCK ioStatusBlock;
POBJECT_NAME_INFORMATION pobjObjectNameInfo;
NTSTATUS status;
ULONG ulLength = 0;
PFILE_OBJECT pFileObject;
PDEVICE_OBJECT pDeviceObject;

IndexerDebugPrint(DBG_INIT, DBG_TRACE, FUNCTION"++");

//
// Allocating memory for pobjObjectNameInfo
//
pobjObjectNameInfo = (POBJECT_NAME_INFORMATION)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(OBJECT_NAME_INFORMATION) + (MAX_PATH*2),
INDEXER_POOL_TAG
);
if(pobjObjectNameInfo == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
memory for pobjObjectNameInfo");

return status;
}

//
// Allocating memory for pFileObject
//
pFileObject = (PFILE_OBJECT)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(FILE_OBJECT),
INDEXER_POOL_TAG
);
if(pFileObject == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
memory for pFileObject");

return status;
}

//
// Allocating memory for pDeviceObject
//
pDeviceObject = (PDEVICE_OBJECT)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(DEVICE_OBJECT),
INDEXER_POOL_TAG
);
if(pDeviceObject == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
memory for pDeviceObject");

return status;
}

//
// Getting file object
//
status = ObReferenceObjectByHandle(Handle,
GENERIC_READ,
NULL,
KernelMode,
&pFileObject,
NULL);
if(status != STATUS_SUCCESS)
{
IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x", status);

ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG);

return status;
}

//
// getting file object name
//
status = ObQueryNameString(pFileObject,
pobjObjectNameInfo,
sizeof(OBJECT_NAME_INFORMATION) + (MAX_PATH*2),
&ulLength);
if(status != STATUS_SUCCESS)
{
IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x", status);

ObDereferenceObject(pFileObject);
ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG);

return status;
}

//
// Getting device object pointer
//

IoGetDeviceObjectPointer(/*&pFileObject->FileName*/&pobjObjectNameInfo->Name,
FILE_READ_DATA, &pFileObject, &pDeviceObject); if(status !=
STATUS_SUCCESS) { IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–.
STATUS %x",
status); ObDereferenceObject(pFileObject);
ExFreePoolWithTag(pobjObjectNameInfo,
INDEXER_POOL_TAG); ExFreePoolWithTag(pFileObject,
INDEXER_POOL_TAG); ExFreePoolWithTag(pDeviceObject,
INDEXER_POOL_TAG); return status; } // // converting to C:\ format //
IoVolumeDeviceToDosName(pFileObject->DeviceObject, pUnicodeName); //
// must dereference File Object // ObDereferenceObject(pFileObject); // //
cleaning up // ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG); status =
STATUS_SUCCESS; return status;}“Roddy, Mark”
>wrote in message news:xxxxx@ntdev…So your fast index search utility has
>to build a map from volume guid tovolume mountpoints.-----Original
>Message-----From:
>xxxxx@lists.osr.com[mailto:xxxxx@lists.osr.com]
>On Behalf Of Gleb SuhatskiSent: Thursday, December 15, 2005 6:00 AMTo:
>Windows System Software Devs Interest ListSubject: Re:[ntdev] Retrieving
>full pathname from handleI am writing a driver that makes a list of file
>creation/deletion eventsfora fast index search utility. I have to pass the
>string in a DOS filenameformat to the application.“Maxim S. Shatskih”
> wrote in messagenews:xxxxx@ntdev…> Design
>your product in a way so it will only use Volume GUIDs> internally> and
>not the drive letters. The drive letters will appear in the UIonly.>>
>Maxim Shatskih, Windows DDK MVP> StorageCraft Corporation>
>xxxxx@storagecraft.com> http://www.storagecraft.com>> ----- Original
>Message -----> From: > Newsgroups: ntdev> To:
>“Windows System Software Devs Interest List” > Sent:
>Monday, December 12, 2005 1:53 AM> Subject: [ntdev] Retrieving full
>pathname from handle>>>> Hi.>>>> I am trying to populate the full pathname
>of a file or directory by>> supplying only the file/dir handle to my
>function.>> It can currently populate only the relative path without the
>driveletter>> name (for example C:).>>>> I would like the output format to
>be a Unicode string with a syntaxthat>> is>> somewhat like
>“C:\SomeDir\SomeOtherDir\file.ext”.>> I’ve included my function’s source
>in this message. Any help will be>> appreciated.>>>> Thanks in
>advance,>>>> Gleb>>>>
>//------------------------------------------------------------------->>>>
>NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,>> OUT
>PUNICODE_STRING FileName)>> {>> PIO_STATUS_BLOCK pioStatusBlock;>>
>PFILE_NAME_INFORMATION fniFileInfo;>> NTSTATUS status;>>>> //>> //
>Allocating memory for pioStatusBlock>> //>> pioStatusBlock =
>(PIO_STATUS_BLOCK)ExAllocatePoolWithTag(>> NonPagedPool,>>
>sizeof(IO_STATUS_BLOCK),>> INDEXER_POOL_TAG>> );>> if(pioStatusBlock ==
>NULL)>> {>> status = STATUS_INSUFFICIENT_RESOURCE
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@privtek.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com

You should not allocate the DEVICE_OBJECT or FILE_OBJECT. This is why
you pass a pointer to a pointer to these functions. They return to you
a valid pointer value. You are then freeing that value, which you are
not allowed to free since you are freeing an NT object (which also means
you are leaking the 2 allocations since you lose them on successful
calls to Ob.

D

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gleb Suhatski
Sent: Thursday, December 15, 2005 9:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Retrieving full pathname from handle

Unfortunately I cannot use this method in this particular driver.

Anyhow, I checked OSR lists archive and Google and found a way to do it.
I wrote a function that receives a handle and returns a drive letter,
ex. C:
but it crashes.
(By the way, I’m aware that this is a legacy driver and that it should
be a
file system driver. nevertheless, I have to sort this
problem out since it’s part of my current project.)

Does anyone see what’s wrong with this function?

Thanks in advance.

NTSTATUS FileDirectoryHandleToUnicodeDosDriveName(IN HANDLE Handle,
OUT PUNICODE_STRING pUnicodeName)
{
IO_STATUS_BLOCK ioStatusBlock;
POBJECT_NAME_INFORMATION pobjObjectNameInfo;
NTSTATUS status;
ULONG ulLength = 0;
PFILE_OBJECT pFileObject;
PDEVICE_OBJECT pDeviceObject;

IndexerDebugPrint(DBG_INIT, DBG_TRACE, FUNCTION"++");

//
// Allocating memory for pobjObjectNameInfo
//
pobjObjectNameInfo = (POBJECT_NAME_INFORMATION)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(OBJECT_NAME_INFORMATION) + (MAX_PATH*2),
INDEXER_POOL_TAG
);
if(pobjObjectNameInfo == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate

memory for pobjObjectNameInfo");

return status;
}

//
// Allocating memory for pFileObject
//
pFileObject = (PFILE_OBJECT)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(FILE_OBJECT),
INDEXER_POOL_TAG
);
if(pFileObject == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate

memory for pFileObject");

return status;
}

//
// Allocating memory for pDeviceObject
//
pDeviceObject = (PDEVICE_OBJECT)ExAllocatePoolWithTag(
NonPagedPool,
sizeof(DEVICE_OBJECT),
INDEXER_POOL_TAG
);
if(pDeviceObject == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;

ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);

IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate

memory for pDeviceObject");

return status;
}

//
// Getting file object
//
status = ObReferenceObjectByHandle(Handle,
GENERIC_READ,
NULL,
KernelMode,
&pFileObject,
NULL);
if(status != STATUS_SUCCESS)
{
IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x",
status);

ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG);

return status;
}

//
// getting file object name
//
status = ObQueryNameString(pFileObject,
pobjObjectNameInfo,
sizeof(OBJECT_NAME_INFORMATION) + (MAX_PATH*2),
&ulLength);
if(status != STATUS_SUCCESS)
{
IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x",
status);

ObDereferenceObject(pFileObject);
ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG);

return status;
}

//
// Getting device object pointer
//

IoGetDeviceObjectPointer(/*&pFileObject->FileName*/&pobjObjectNameInfo->
Name, FILE_READ_DATA, &pFileObject, &pDeviceObject);
if(status != STATUS_SUCCESS) { IndexerDebugPrint(DBG_INIT, DBG_ERR,
FUNCTION"–. STATUS %x", status); ObDereferenceObject(pFileObject);
ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG); return status; } //
// converting to C:\ format //
IoVolumeDeviceToDosName(pFileObject->DeviceObject, pUnicodeName);
// // must dereference File Object // ObDereferenceObject(pFileObject);
// // cleaning up // ExFreePoolWithTag(pobjObjectNameInfo,
INDEXER_POOL_TAG); ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG); status =
STATUS_SUCCESS; return status;}“Roddy, Mark”
wrote in message news:xxxxx@ntdev…So your fast index search utility
has to build a map from volume guid tovolume mountpoints.-----Original
Message-----From:
xxxxx@lists.osr.com[mailto:xxxxx@lists.osr.com
] On Behalf Of Gleb SuhatskiSent: Thursday, December 15, 2005 6:00 AMTo:
Windows System Software Devs Interest ListSubject: Re:[ntdev] Retrieving
full pathname from handleI am writing a driver that makes a list of file
creation/deletion eventsfora fast index search utility. I have to pass
the string in a DOS filenameformat to the application.“Maxim S.
Shatskih” wrote in messagenews:xxxxx@ntdev…>
Design your product in a way so it will only use Volume GUIDs>
internally> and not the drive letters. The drive letters will appear in
the UIonly.>> Maxim Shatskih, Windows DDK MVP> StorageCraft Corporation>
xxxxx@storagecraft.com> http://www.storagecraft.com>> ----- Original
Message -----> From: > Newsgroups: ntdev> To:
“Windows System Software Devs Interest List” >
Sent: Monday, December 12, 2005 1:53 AM> Subject: [ntdev] Retrieving
full pathname from handle>>>> Hi.>>>> I am trying to populate the full
pathname of a file or directory by>> supplying only the file/dir handle
to my function.>> It can currently populate only the relative path
without the driveletter>> name (for example C:).>>>> I would like the
output format to be a Unicode string with a syntaxthat>> is>> somewhat
like “C:\SomeDir\SomeOtherDir\file.ext”.>> I’ve included my function’s
source in this message. Any help will be>> appreciated.>>>> Thanks in
advance,>>>> Gleb>>>>
//------------------------------------------------------------------->>>
> NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,>> OUT
PUNICODE_STRING FileName)>> {>> PIO_STATUS_BLOCK pioStatusBlock;>>
PFILE_NAME_INFORMATION fniFileInfo;>> NTSTATUS status;>>>> //>> //
Allocating memory for pioStatusBlock>> //>> pioStatusBlock =
(PIO_STATUS_BLOCK)ExAllocatePoolWithTag(>> NonPagedPool,>>
sizeof(IO_STATUS_BLOCK),>> INDEXER_POOL_TAG>> );>> if(pioStatusBlock ==
NULL)>> {>> status = STATUS_INSUFFICIENT_RESOURCES;>>>>
IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed toallocate>>
memory for pioStatusBlock");>>>> return status;>> }>>>> //>> //
Allocating memory for fniFileInfo>> //>> fniFileInfo =
(PFILE_NAME_INFORMATION)ExAllocatePoolWithTag(>> NonPagedPool,>>
sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),>> INDEXER_POOL_TAG>> );>>
if(fniFileInfo == NULL)>> {>> status =
STATUS_INSUFFICIENT_RESOURCES;>>>> ExFreePoolWithTag(pioStatusBlock,
INDEXER_POOL_TAG);>>>> IndexerDebugPrint(DBG_INIT, DBG_ERR,
FUNCTION": Failed toallocate>> memory for fniFileInfo");>>>> return
status;>> }>>>> //>> // Populating file name>> //>> status =
ZwQueryInformationFile(FileHandle,>> pioStatusBlock,>> fniFileInfo,>>
(ULONG)sizeof(FILE_NAME_INFORMATION) + (MAX_PATH-1),>>
FileNameInformation);>> if(status != STATUS_SUCCESS)>> {>>
ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);>>
ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);>>>>
IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x",>>
status);>>>> return status;>> }>>>> FileName->MaximumLength =
fniFileInfo->FileNameLength;>> FileName->Length =
fniFileInfo->FileNameLength;>> FileName->Buffer =
fniFileInfo->FileName;>> RtlCopyMemory(FileName->Buffer,>>
&fniFileInfo->FileName,>> fniFileInfo->FileNameLength);>>>>>>
ExFreePoolWithTag(pioStatusBlock, INDEXER_POOL_TAG);>>
ExFreePoolWithTag(fniFileInfo, INDEXER_POOL_TAG);>>>> status =
STATUS_SUCCESS;>>>> return status;>> }>>>> —>> Questions? First check
the Kernel Driver FAQ at>
http://www.osronline.com/article.cfm?id=256>>>> You are currently
subscribed to ntdev as: xxxxx@storagecraft.com>> To unsubscribe send a
blank email xxxxx@lists.osr.com>>>—Questions? First
check the Kernel Driver FAQ
athttp://www.osronline.com/article.cfm?id=256You are currently
subscribed to ntdev as: xxxxx@stratus.comTo unsubscribe send a
blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

My driver is supposed to gather file names and paths each time one has been
captured (=hook)
and store them in a lookasideList, after which the user mode service reads
from the kernel mode queue
and appends the results into a DB.
When I get a file deletion event, the service removes the entry from the DB
and the other way around.

What exactly do I get from the Volume GUID?

Also, my searches doesn’t need to show/log the exact path of the file or
folder but exactly the way
you’d see it in My Computer. Even if it’s a mapped folder I recall?

Advice would be appreciated.
Thanks.

“Dan Kyler” wrote in message news:xxxxx@ntdev…
> >Unfortunately I cannot use this method in this particular driver.
>
> Yes, you can, and you should. People who clearly know a LOT more than you
> do are telling you how to do it and you should listen. Drive letters in
> kernel mode aren’t worth much. A volume might not have a drive letter.
> Drive letter maps can be different in different sessions. Pass the volume
> GUID to user mode.
>
>>(By the way, I’m aware that this is a legacy driver and that it should be
>>a
>>file system driver. nevertheless, I have to sort this
>>problem out since it’s part of my current project.)
>>
>>Does anyone see what’s wrong with this function?
>
> There’s so much wrong that I don’t know where to start, but the crash is
> probably happening when you try to call ExFreePoolWithTag on a file
> object.
>
> - Dan.
> At 07:32 PM 12/15/2005 +0200, you wrote:
>>Unfortunately I cannot use this method in this particular driver.
>>
>>Anyhow, I checked OSR lists archive and Google and found a way to do it.
>>I wrote a function that receives a handle and returns a drive letter, ex.
>>C:
>>but it crashes.
>>(By the way, I’m aware that this is a legacy driver and that it should be
>>a
>>file system driver. nevertheless, I have to sort this
>>problem out since it’s part of my current project.)
>>
>>Does anyone see what’s wrong with this function?
>>
>>Thanks in advance.
>>
>>NTSTATUS FileDirectoryHandleToUnicodeDosDriveName(IN HANDLE Handle,
>> OUT PUNICODE_STRING pUnicodeName)
>>{
>> IO_STATUS_BLOCK ioStatusBlock;
>> POBJECT_NAME_INFORMATION pobjObjectNameInfo;
>> NTSTATUS status;
>> ULONG ulLength = 0;
>> PFILE_OBJECT pFileObject;
>> PDEVICE_OBJECT pDeviceObject;
>>
>> IndexerDebugPrint(DBG_INIT, DBG_TRACE, FUNCTION"++“);
>>
>> //
>> // Allocating memory for pobjObjectNameInfo
>> //
>> pobjObjectNameInfo = (POBJECT_NAME_INFORMATION)ExAllocatePoolWithTag(
>> NonPagedPool,
>> sizeof(OBJECT_NAME_INFORMATION) + (MAX_PATH2),
>> INDEXER_POOL_TAG
>> );
>> if(pobjObjectNameInfo == NULL)
>> {
>> status = STATUS_INSUFFICIENT_RESOURCES;
>>
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
>>memory for pobjObjectNameInfo");
>>
>> return status;
>> }
>>
>> //
>> // Allocating memory for pFileObject
>> //
>> pFileObject = (PFILE_OBJECT)ExAllocatePoolWithTag(
>> NonPagedPool,
>> sizeof(FILE_OBJECT),
>> INDEXER_POOL_TAG
>> );
>> if(pFileObject == NULL)
>> {
>> status = STATUS_INSUFFICIENT_RESOURCES;
>>
>> ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
>>
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
>>memory for pFileObject");
>>
>> return status;
>> }
>>
>> //
>> // Allocating memory for pDeviceObject
>> //
>> pDeviceObject = (PDEVICE_OBJECT)ExAllocatePoolWithTag(
>> NonPagedPool,
>> sizeof(DEVICE_OBJECT),
>> INDEXER_POOL_TAG
>> );
>> if(pDeviceObject == NULL)
>> {
>> status = STATUS_INSUFFICIENT_RESOURCES;
>>
>> ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
>>
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION": Failed to allocate
>>memory for pDeviceObject");
>>
>> return status;
>> }
>>
>> //
>> // Getting file object
>> //
>> status = ObReferenceObjectByHandle(Handle,
>> GENERIC_READ,
>> NULL,
>> KernelMode,
>> &pFileObject,
>> NULL);
>> if(status != STATUS_SUCCESS)
>> {
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–. STATUS %x",
>> status);
>>
>> ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG);
>>
>> return status;
>> }
>>
>> //
>> // getting file object name
>> //
>> status = ObQueryNameString(pFileObject,
>> pobjObjectNameInfo,
>> sizeof(OBJECT_NAME_INFORMATION) + (MAX_PATH
2),
>> &ulLength);
>> if(status != STATUS_SUCCESS)
>> {
>> IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION”–. STATUS %x",
>> status);
>>
>> ObDereferenceObject(pFileObject);
>> ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG);
>>
>> return status;
>> }
>>
>> //
>> // Getting device object pointer
>> //
>> IoGetDeviceObjectPointer(/&pFileObject->FileName/&pobjObjectNameInfo->Name,
>> FILE_READ_DATA, &pFileObject, &pDeviceObject); if(status !=
>> STATUS_SUCCESS) { IndexerDebugPrint(DBG_INIT, DBG_ERR, FUNCTION"–.
>> STATUS %x", status); ObDereferenceObject(pFileObject);
>> ExFreePoolWithTag(pobjObjectNameInfo, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG); return status; } //
>> // converting to C:\ format //
>> IoVolumeDeviceToDosName(pFileObject->DeviceObject, pUnicodeName);
>> // // must dereference File Object // ObDereferenceObject(pFileObject);
>> // // cleaning up // ExFreePoolWithTag(pobjObjectNameInfo,
>> INDEXER_POOL_TAG); ExFreePoolWithTag(pFileObject, INDEXER_POOL_TAG);
>> ExFreePoolWithTag(pDeviceObject, INDEXER_POOL_TAG); status =
>> STATUS_SUCCESS; return status;}“Roddy, Mark”
>> wrote in message news:xxxxx@ntdev…So your fast index search utility has
>> to build a map from volume guid tovolume mountpoints.-----Original
>> Message-----From:
>> xxxxx@lists.osr.com[mailto:xxxxx@lists.osr.com]
>> On Behalf Of Gleb SuhatskiSent: Thursday, December 15, 2005 6:00 AMTo:
>> Windows System Software Devs Interest ListSubject: Re:[ntdev] Retrieving
>> full pathname from handleI am writing a driver that makes a list of file
>> creation/deletion eventsfora fast index search utility. I have to pass
>> the string in a DOS filenameformat to the application.“Maxim S. Shatskih”
>> wrote in messagenews:xxxxx@ntdev…> Design
>> your product in a way so it will only use Volume GUIDs> internally> and
>> not the drive letters. The drive letters will appear in the UIonly.>>
>> Maxim Shatskih, Windows DDK MVP> StorageCraft Corporation>
>> xxxxx@storagecraft.com> http://www.storagecraft.com>> ----- Original
>> Message -----> From: > Newsgroups: ntdev> To:
>> “Windows System Software Devs Interest List” > Sent:
>> Monday, December 12, 2005 1:53 AM> Subject: [ntdev] Retrieving full
>> pathname from handle>>>> Hi.>>>> I am trying to populate the full
>> pathname of a file or directory by>> supplying only the file/dir handle
>> to my function.>> It can currently populate only the relative path
>> without the driveletter>> name (for example C:).>>>> I would like the
>> output format to be a Unicode string with a syntaxthat>> is>> somewhat
>> like “C:\SomeDir\SomeOtherDir\file.ext”.>> I’ve included my function’s
>> source in this message. Any help will be>> appreciated.>>>> Thanks in
>> advance,>>>> Gleb>>>>
>> //------------------------------------------------------------------->>>>
>> NTSTATUS FileHandleToUNICODE_STRING(IN HANDLE FileHandle,>> OUT
>> PUNICODE_STRING FileName)>> {>> PIO_STATUS_BLOCK pioStatusBlock;>>
>> PFILE_NAME_INFORMATION fniFileInfo;>> NTSTATUS status;>>>> //>> //
>> Allocating memory for pioStatusBlock>> //>> pioStatusBlock =
>> (PIO_STATUS_BLOCK)ExAllocatePoolWithTag(>> NonPagedPool,>>
>> sizeof(IO_STATUS_BLOCK),>> INDEXER_POOL_TAG>> );>> if(pioStatusBlock ==
>> NULL)>> {>> status = STATUS_INSUFFICIENT_RESOURCE
>>
>>—
>>Questions? First check the Kernel Driver FAQ at
>>http://www.osronline.com/article.cfm?id=256
>>
>>You are currently subscribed to ntdev as: xxxxx@privtek.com
>>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>

> Anyhow, I checked OSR lists archive and Google and found a way to do it.

I wrote a function that receives a handle and returns a drive letter, ex. C:
but it crashes.

You’re going the very, very wrong way. The volume can be mounted as a mount
point, and in this case your indexer will be broken.

Design all your components to deal with volume GUIDs and not drive letters. The
drive letters should appear in the UI only, and the mapping between GUIDs and
drive letters should be done using the FindFirstVolume and related calls from
the UI component of your product.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

> My driver is supposed to gather file names and paths each time one has been

captured (=hook)
and store them in a lookasideList, after which the user mode service reads
from the kernel mode queue
and appends the results into a DB.

Yes, and the DB table must have the columns of VolumeGUID +
PathnameRelativeToVolume.

When I get a file deletion event, the service removes the entry from the DB
and the other way around.

What exactly do I get from the Volume GUID?

Same as from the drive letter. Drive letters serve only the UI purpose in
modern Windows. The real work within the kernel is with volume GUIDs.

Also, my searches doesn’t need to show/log the exact path of the file or
folder but exactly the way
you’d see it in My Computer.

With my usual Windows shell settings, I see full pathnames in address and title
bars of the Explorer window :slight_smile:

So, you must support full pathnames anyway to be compatible with different
Windows settings.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Perhaps the third or fourth time “don’t do it that way, do it this way”
has been repeated the OP will have an epiphany?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Thursday, December 15, 2005 4:23 PM
To: Windows System Software Devs Interest List
Subject: Re: Re:[ntdev] Retrieving full pathname from handle

Anyhow, I checked OSR lists archive and Google and found a way to do
it.
I wrote a function that receives a handle and returns a drive letter,
ex. C:
but it crashes.

You’re going the very, very wrong way. The volume can be mounted as a
mount
point, and in this case your indexer will be broken.

Design all your components to deal with volume GUIDs and not drive
letters. The
drive letters should appear in the UI only, and the mapping between
GUIDs and
drive letters should be done using the FindFirstVolume and related calls
from
the UI component of your product.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Dream on buddy :slight_smile:

“Roddy, Mark” wrote in message news:xxxxx@ntdev…
Perhaps the third or fourth time “don’t do it that way, do it this way”
has been repeated the OP will have an epiphany?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Thursday, December 15, 2005 4:23 PM
To: Windows System Software Devs Interest List
Subject: Re: Re:[ntdev] Retrieving full pathname from handle

> Anyhow, I checked OSR lists archive and Google and found a way to do
it.
> I wrote a function that receives a handle and returns a drive letter,
ex. C:
> but it crashes.

You’re going the very, very wrong way. The volume can be mounted as a
mount
point, and in this case your indexer will be broken.

Design all your components to deal with volume GUIDs and not drive
letters. The
drive letters should appear in the UI only, and the mapping between
GUIDs and
drive letters should be done using the FindFirstVolume and related calls
from
the UI component of your product.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I see.
So the structure I will pass to user mode will have the Unicode string for
the relative path and file name
and a GUID.
How do I get the volume guid by file handle though?

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> My driver is supposed to gather file names and paths each time one has
>> been
>> captured (=hook)
>> and store them in a lookasideList, after which the user mode service
>> reads
>> from the kernel mode queue
>> and appends the results into a DB.
>
> Yes, and the DB table must have the columns of VolumeGUID +
> PathnameRelativeToVolume.
>
>> When I get a file deletion event, the service removes the entry from the
>> DB
>> and the other way around.
>>
>> What exactly do I get from the Volume GUID?
>
> Same as from the drive letter. Drive letters serve only the UI purpose in
> modern Windows. The real work within the kernel is with volume GUIDs.
>
>> Also, my searches doesn’t need to show/log the exact path of the file or
>> folder but exactly the way
>> you’d see it in My Computer.
>
> With my usual Windows shell settings, I see full pathnames in address and
> title
> bars of the Explorer window :slight_smile:
>
> So, you must support full pathnames anyway to be compatible with different
> Windows settings.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>

I decided to change the way it works and I agree with you all.
It will use a Volume GUID and a relative path to the file/dir.
Question: How do I actually get the Volume GUID?

“Lyndon J Clarke” wrote in message
news:xxxxx@ntdev…
> Dream on buddy :slight_smile:
>
> “Roddy, Mark” wrote in message
> news:xxxxx@ntdev…
> Perhaps the third or fourth time “don’t do it that way, do it this way”
> has been repeated the OP will have an epiphany?
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
> Sent: Thursday, December 15, 2005 4:23 PM
> To: Windows System Software Devs Interest List
> Subject: Re: Re:[ntdev] Retrieving full pathname from handle
>
>> Anyhow, I checked OSR lists archive and Google and found a way to do
> it.
>> I wrote a function that receives a handle and returns a drive letter,
> ex. C:
>> but it crashes.
>
> You’re going the very, very wrong way. The volume can be mounted as a
> mount
> point, and in this case your indexer will be broken.
>
> Design all your components to deal with volume GUIDs and not drive
> letters. The
> drive letters should appear in the UI only, and the mapping between
> GUIDs and
> drive letters should be done using the FindFirstVolume and related calls
> from
> the UI component of your product.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@stratus.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>

I guess you must know on what device your receive the Irp?

“Gleb Suhatski” wrote in message
news:xxxxx@ntdev…
>I decided to change the way it works and I agree with you all.
> It will use a Volume GUID and a relative path to the file/dir.
> Question: How do I actually get the Volume GUID?
>
>
>
> “Lyndon J Clarke” wrote in message
> news:xxxxx@ntdev…
>> Dream on buddy :slight_smile:
>>
>> “Roddy, Mark” wrote in message
>> news:xxxxx@ntdev…
>> Perhaps the third or fourth time “don’t do it that way, do it this way”
>> has been repeated the OP will have an epiphany?
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
>> Sent: Thursday, December 15, 2005 4:23 PM
>> To: Windows System Software Devs Interest List
>> Subject: Re: Re:[ntdev] Retrieving full pathname from handle
>>
>>> Anyhow, I checked OSR lists archive and Google and found a way to do
>> it.
>>> I wrote a function that receives a handle and returns a drive letter,
>> ex. C:
>>> but it crashes.
>>
>> You’re going the very, very wrong way. The volume can be mounted as a
>> mount
>> point, and in this case your indexer will be broken.
>>
>> Design all your components to deal with volume GUIDs and not drive
>> letters. The
>> drive letters should appear in the UI only, and the mapping between
>> GUIDs and
>> drive letters should be done using the FindFirstVolume and related calls
>> from
>> the UI component of your product.
>>
>> Maxim Shatskih, Windows DDK MVP
>> StorageCraft Corporation
>> xxxxx@storagecraft.com
>> http://www.storagecraft.com
>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as: xxxxx@stratus.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>>
>>
>>
>>
>
>
>

> So the structure I will pass to user mode will have the Unicode string for

the relative path and file name
and a GUID.
How do I get the volume guid by file handle though?

I assume you have an FS filter in the kernel, correct? Then
FltGetVolumeGuidName. For pre-FltMgr filters, try IOCTL_MOUNTMGR_QUERY_POINTS.

In user mode, use GetVolumeNameForVolumeMountPoint.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Frankly, it’s a legacy hooking driver.
It should be an FS filter, yes, I’m aware. It’s only a temporary thing.

How do I retrieve the Volume GUID by handle in a legacy driver?

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> So the structure I will pass to user mode will have the Unicode string
>> for
>> the relative path and file name
>> and a GUID.
>> How do I get the volume guid by file handle though?
>
> I assume you have an FS filter in the kernel, correct? Then
> FltGetVolumeGuidName. For pre-FltMgr filters, try
> IOCTL_MOUNTMGR_QUERY_POINTS.
>
> In user mode, use GetVolumeNameForVolumeMountPoint.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>