device name from device object

How can I get device name having a pointer to corresponding DEVICE_OBJECT?


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

There is undocumented function

NTSYSAPI
NTSTATUS
NTAPI ObQueryNameString(
POBJECT Object,
PUNICODE_STRING Name,
ULONG MaximumLength,
PULONG ActualLength );

Go to www.sysinternals.com and find the sample RegMon where this function is
used.


Bye,
SaB

-----Original Message-----
From: Alexey Logachyov [mailto:xxxxx@vba.com.by]
Sent: Monday, October 15, 2001 2:10 PM
To: NT Developers Interest List
Subject: [ntdev] device name from device object

How can I get device name having a pointer to corresponding
DEVICE_OBJECT?


You are currently subscribed to ntdev as: xxxxx@mastereye.kiev.ua
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You can use

NTKERNELAPI
NTSTATUS
ObQueryNameString(
IN PVOID Object, // pointer to device object here
OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
IN ULONG Length,
OUT PULONG ReturnLength
);

Regards,

Vadim

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Alexey Logachyov
Sent: Monday, October 15, 2001 4:10 PM
To: NT Developers Interest List
Subject: [ntdev] device name from device object

How can I get device name having a pointer to corresponding DEVICE_OBJECT?


You are currently subscribed to ntdev as: xxxxx@pcausa.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi,
To best of my knowledge, we cannot get this
information. Typically, driver writer will store the
device name and symbolic link in the device extension.
In this case use DEVICE_OBJECT to get pointer to
device extension and take the required.

Cheers,
Jay

— Alexey Logachyov wrote:
> How can I get device name having a pointer to
> corresponding DEVICE_OBJECT?
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You use DeviceObject->DriverObject->DriverName.

Gary G. Little
Staff Engineer
Broadband Storage, Inc.
xxxxx@broadstor.com

-----Original Message-----
From: jayadev m n [mailto:xxxxx@yahoo.com]
Sent: Monday, October 15, 2001 6:41 AM
To: NT Developers Interest List
Subject: [ntdev] Re: device name from device object

Hi,
To best of my knowledge, we cannot get this
information. Typically, driver writer will store the
device name and symbolic link in the device extension.
In this case use DEVICE_OBJECT to get pointer to
device extension and take the required.

Cheers,
Jay

— Alexey Logachyov wrote:
> How can I get device name having a pointer to
> corresponding DEVICE_OBJECT?
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com


You are currently subscribed to ntdev as: xxxxx@broadstor.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> -----Original Message-----

From: Gary Little [mailto:xxxxx@Broadstor.com]
Sent: Monday, October 15, 2001 5:27 PM
To: NT Developers Interest List
Subject: [ntdev] Re: device name from device object

You use DeviceObject->DriverObject->DriverName.

And you will find driver name, not device name!


Bye,
SaB


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Sorry, if I’m resending message, but I’m confused why it did come in the
list…

You can use

NTKERNELAPI
NTSTATUS
ObQueryNameString(
IN PVOID Object, // pointer to device object here
OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
IN ULONG Length,
OUT PULONG ReturnLength
);

Regards,

Vadim

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Alexey Logachyov
Sent: Monday, October 15, 2001 4:10 PM
To: NT Developers Interest List
Subject: [ntdev] device name from device object

How can I get device name having a pointer to corresponding DEVICE_OBJECT?


You are currently subscribed to ntdev as: xxxxx@pcausa.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Yes that’s very true, but then device names are optional, and in WDM may be
generated for the device when IoCreateDevice is called. Look at Oney’s book
as well as the toaster example. One solution is to call it what you want,
save the name in the extension and work out your own means of passing the
name between two drivers. If you haven’t control of one of the drivers, then
you’re at the mercy of they that wrote that driver, and if they didn’t name
it, then you are basically out of luck.

Gary G. Little
Staff Engineer
Broadband Storage, Inc.
xxxxx@broadstor.com

-----Original Message-----
From: xxxxx@Mastereye.KIEV.UA [mailto:xxxxx@Mastereye.KIEV.UA]
Sent: Monday, October 15, 2001 8:56 AM
To: NT Developers Interest List
Subject: [ntdev] Re: device name from device object

-----Original Message-----
From: Gary Little [ mailto:xxxxx@Broadstor.com
mailto:xxxxx ]
> Sent: Monday, October 15, 2001 5:27 PM
> To: NT Developers Interest List
> Subject: [ntdev] Re: device name from device object
>
>
> You use DeviceObject->DriverObject->DriverName.
>
And you will find driver name, not device name!
------
Bye,
SaB

You are currently subscribed to ntdev as: xxxxx@broadstor.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</mailto:xxxxx>

ObQueryNameString

----- Original Message -----
From: “Alexey Logachyov”
To: “NT Developers Interest List”
Sent: Monday, October 15, 2001 4:10 PM
Subject: [ntdev] device name from device object

> How can I get device name having a pointer to corresponding DEVICE_OBJECT?
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

This gets you the driver name, not the device name.

Jamey
xxxxx@storagecraft.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary Little
Sent: Monday, October 15, 2001 8:27 AM
To: NT Developers Interest List
Subject: [ntdev] Re: device name from device object

You use DeviceObject->DriverObject->DriverName.

Gary G. Little
Staff Engineer
Broadband Storage, Inc.
xxxxx@broadstor.com

-----Original Message-----
From: jayadev m n [mailto:xxxxx@yahoo.com]
Sent: Monday, October 15, 2001 6:41 AM
To: NT Developers Interest List
Subject: [ntdev] Re: device name from device object

Hi,
To best of my knowledge, we cannot get this
information. Typically, driver writer will store the
device name and symbolic link in the device extension.
In this case use DEVICE_OBJECT to get pointer to
device extension and take the required.

Cheers,
Jay

— Alexey Logachyov wrote:
> How can I get device name having a pointer to
> corresponding DEVICE_OBJECT?
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals. http://personals.yahoo.com


You are currently subscribed to ntdev as: xxxxx@broadstor.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@storagecraft.com To
unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I found this function before I received this message but thanks anyway. I’ve got some problem with it though. The following code works fine (almost):

BOOLEAN MyClassName::MyMethodName(IN PDEVICE_OBJECT DeviceObject,
IN PFILE_OBJECT FileObject,
IN POOL_TYPE PoolType)
{
WCHAR wsz[256];
OBJECT_NAME_INFORMATION oni;
oni.Name.Buffer = wsz;
oni.Name.Length = 0;
oni.Name.MaximumLength = sizeof(wsz) - sizeof(WCHAR);
ULONG len;
NTSTATUS ntStatus = ObQueryNameString(
FileObject->DeviceObject,
&oni,
oni.Name.MaximumLength
&len);
if (STATUS_SUCCESS == ntStatus)
{
oni.Name.Buffer[oni.Name.Length / sizeof(WCHAR)] = ‘\0’;
KdPrint((“device name = %ws\n”, oni.Name.Buffer));
KdPrint((“device name = %ws\n”, wsz));
}

}

Almost fine because if I print out wsz I can’t see first 2 letters and I cannot understand why. I can do with that but the following arrangement causes BSOD and I cannot do with it:

NTSTATUS Object_QueryNameString(IN PDEVICE_OBJECT DeviceObject,
OUT PWSTR DeviceName,
IN USHORT DeviceNameLength)
{
OBJECT_NAME_INFORMATION oni;
oni.Name.Buffer = DeviceName;
oni.Name.Length = 0;
oni.Name.MaximumLength = DeviceNameLength - sizeof(WCHAR);
ULONG len;
NTSTATUS ntStatus = ObQueryNameString(
DeviceObject,
&oni,
oni.Name.MaximumLength,
&len);
if (STATUS_SUCCESS == ntStatus)
{
oni.Name.Buffer[oni.Name.Length / sizeof(WCHAR)] = L’\0’;
KdPrint((“device name = %ws\n”, oni.Name.Buffer));
}
return ntStatus;
}

BOOLEAN MyClassName::MyMethodName(IN PDEVICE_OBJECT DeviceObject,
IN PFILE_OBJECT FileObject,
IN POOL_TYPE PoolType)
{
WCHAR wsz[256];
NTSTATUS ntStatus = Object_QueryNameString(
FileObject->DeviceObject,
wsz,
sizeof(wsz));
if (STATUS_SUCCESS == ntStatus)
{
KdPrint((“device name = %ws\n”, wsz));
}

}

BSOD is on ObQueryNameString call saying KMODE_UNHANDLED_EXCEPTION 0xC000005 0x00630069 0x00000000 0x00630069 or something. BSOD parameters are always the same. Watching stack with WinDbg does not give any results. Is that because of alignment? As far as I understand my code, all structers are aligned by DWORD (or aren’t they?). Is there any special requirements for ObQueryNameString?

----- Original Message -----
From: “Vadim Smirnov”
To: “NT Developers Interest List”
Sent: Monday, October 15, 2001 4:11 PM
Subject: [ntdev] RE: device name from device object

> You can use
>
> NTKERNELAPI
> NTSTATUS
> ObQueryNameString(
> IN PVOID Object, // pointer to device object here
> OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
> IN ULONG Length,
> OUT PULONG ReturnLength
> );
>
> Regards,
>
> Vadim
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Alexey Logachyov
> Sent: Monday, October 15, 2001 4:10 PM
> To: NT Developers Interest List
> Subject: [ntdev] device name from device object
>
>
> How can I get device name having a pointer to corresponding DEVICE_OBJECT?
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@pcausa.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@vba.com.by
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You are using function on the wrong way. Look at this portion of code

Status = ObQueryNameString ( pDeviceObject, NULL, 0, &NameLength );

if ( Status == STATUS_INFO_LENGTH_MISMATCH )
{
pObjectName = ExAllocatePoolWithTag ( NonPagedPool, NameLength,
‘TLFD’ );

if ( pObjectName )
{
Status = ObQueryNameString ( pDeviceObject, pObjectName, NameLength,
&NameLength );

if ( NT_SUCCESS ( Status ) )
{
// Save string here
}
}

ExFreePool ( pObjectName );
}

Hope no additional comments required.

Regards,

Vadim

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Alexey Logachyov
Sent: Wednesday, October 17, 2001 1:52 AM
To: NT Developers Interest List
Subject: [ntdev] RE: device name from device object

I found this function before I received this message but thanks anyway.
I’ve got some problem with it though. The following code works fine
(almost):

BOOLEAN MyClassName::MyMethodName(IN PDEVICE_OBJECT DeviceObject,
IN PFILE_OBJECT FileObject,
IN POOL_TYPE PoolType)
{
WCHAR wsz[256];
OBJECT_NAME_INFORMATION oni;
oni.Name.Buffer = wsz;
oni.Name.Length = 0;
oni.Name.MaximumLength = sizeof(wsz) - sizeof(WCHAR);
ULONG len;
NTSTATUS ntStatus = ObQueryNameString(
FileObject->DeviceObject,
&oni,
oni.Name.MaximumLength
&len);
if (STATUS_SUCCESS == ntStatus)
{
oni.Name.Buffer[oni.Name.Length / sizeof(WCHAR)] = ‘\0’;
KdPrint((“device name = %ws\n”, oni.Name.Buffer));
KdPrint((“device name = %ws\n”, wsz));
}

}

Almost fine because if I print out wsz I can’t see first 2 letters and I
cannot understand why. I can do with that but the following arrangement
causes BSOD and I cannot do with it:

NTSTATUS Object_QueryNameString(IN PDEVICE_OBJECT DeviceObject,
OUT PWSTR DeviceName,
IN USHORT DeviceNameLength)
{
OBJECT_NAME_INFORMATION oni;
oni.Name.Buffer = DeviceName;
oni.Name.Length = 0;
oni.Name.MaximumLength = DeviceNameLength - sizeof(WCHAR);
ULONG len;
NTSTATUS ntStatus = ObQueryNameString(
DeviceObject,
&oni,
oni.Name.MaximumLength,
&len);
if (STATUS_SUCCESS == ntStatus)
{
oni.Name.Buffer[oni.Name.Length / sizeof(WCHAR)] = L’\0’;
KdPrint((“device name = %ws\n”, oni.Name.Buffer));
}
return ntStatus;
}

BOOLEAN MyClassName::MyMethodName(IN PDEVICE_OBJECT DeviceObject,
IN PFILE_OBJECT FileObject,
IN POOL_TYPE PoolType)
{
WCHAR wsz[256];
NTSTATUS ntStatus = Object_QueryNameString(
FileObject->DeviceObject,
wsz,
sizeof(wsz));
if (STATUS_SUCCESS == ntStatus)
{
KdPrint((“device name = %ws\n”, wsz));
}

}

BSOD is on ObQueryNameString call saying KMODE_UNHANDLED_EXCEPTION
0xC000005 0x00630069 0x00000000 0x00630069 or something. BSOD parameters are
always the same. Watching stack with WinDbg does not give any results. Is
that because of alignment? As far as I understand my code, all structers are
aligned by DWORD (or aren’t they?). Is there any special requirements for
ObQueryNameString?

----- Original Message -----
From: “Vadim Smirnov”
To: “NT Developers Interest List”
Sent: Monday, October 15, 2001 4:11 PM
Subject: [ntdev] RE: device name from device object

> You can use
>
> NTKERNELAPI
> NTSTATUS
>

> IN PVOID Object, // pointer to device object here
> OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
> IN ULONG Length,
> OUT PULONG ReturnLength
> );
>
> Regards,
>
> Vadim
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Alexey Logachyov
> Sent: Monday, October 15, 2001 4:10 PM
> To: NT Developers Interest List
> Subject: [ntdev] device name from device object
>
>
> How can I get device name having a pointer to corresponding
DEVICE_OBJECT?
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@pcausa.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@vba.com.by
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
You are currently subscribed to ntdev as: xxxxx@pcausa.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I’m gonna check it in a while. But why I cannot use local buffer? And why sometimes it works and sometimes not? And how could you explain a behaviour of oni.Name.Buffer and wsz? And about your piece of code – Do I have to allocate memory from NonPagedPool? My piece of code runs at PASSIVE_LEVEL. And why I can’t give a pretty big buffer…

Stop. I’ve just understand everything. Thanks for support.
----- Original Message -----
From: Vadim Smirnov
To: NT Developers Interest List
Sent: Wednesday, October 17, 2001 10:28
Subject: [ntdev] RE: device name from device object

You are using function on the wrong way. Look at this portion of code

Status = ObQueryNameString ( pDeviceObject, NULL, 0, &NameLength );

if ( Status == STATUS_INFO_LENGTH_MISMATCH )
{
pObjectName = ExAllocatePoolWithTag ( NonPagedPool, NameLength, ‘TLFD’ );

if ( pObjectName )
{
Status = ObQueryNameString ( pDeviceObject, pObjectName, NameLength, &NameLength );

if ( NT_SUCCESS ( Status ) )
{
// Save string here
}
}

ExFreePool ( pObjectName );
}

Hope no additional comments required.

Regards,

Vadim

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]On Behalf Of Alexey Logachyov
Sent: Wednesday, October 17, 2001 1:52 AM
To: NT Developers Interest List
Subject: [ntdev] RE: device name from device object

I found this function before I received this message but thanks anyway. I’ve got some problem with it though. The following code works fine (almost):

BOOLEAN MyClassName::MyMethodName(IN PDEVICE_OBJECT DeviceObject,
IN PFILE_OBJECT FileObject,
IN POOL_TYPE PoolType)
{
WCHAR wsz[256];
OBJECT_NAME_INFORMATION oni;
oni.Name.Buffer = wsz;
oni.Name.Length = 0;
oni.Name.MaximumLength = sizeof(wsz) - sizeof(WCHAR);
ULONG len;
NTSTATUS ntStatus = ObQueryNameString(
FileObject->DeviceObject,
&oni,
oni.Name.MaximumLength
&len);
if (STATUS_SUCCESS == ntStatus)
{
oni.Name.Buffer[oni.Name.Length / sizeof(WCHAR)] = ‘\0’;
KdPrint((“device name = %ws\n”, oni.Name.Buffer));
KdPrint((“device name = %ws\n”, wsz));
}

}

Almost fine because if I print out wsz I can’t see first 2 letters and I cannot understand why. I can do with that but the following arrangement causes BSOD and I cannot do with it:

NTSTATUS Object_QueryNameString(IN PDEVICE_OBJECT DeviceObject,
OUT PWSTR DeviceName,
IN USHORT DeviceNameLength)
{
OBJECT_NAME_INFORMATION oni;
oni.Name.Buffer = DeviceName;
oni.Name.Length = 0;
oni.Name.MaximumLength = DeviceNameLength - sizeof(WCHAR);
ULONG len;
NTSTATUS ntStatus = ObQueryNameString(
DeviceObject,
&oni,
oni.Name.MaximumLength,
&len);
if (STATUS_SUCCESS == ntStatus)
{
oni.Name.Buffer[oni.Name.Length / sizeof(WCHAR)] = L’\0’;
KdPrint((“device name = %ws\n”, oni.Name.Buffer));
}
return ntStatus;
}

BOOLEAN MyClassName::MyMethodName(IN PDEVICE_OBJECT DeviceObject,
IN PFILE_OBJECT FileObject,
IN POOL_TYPE PoolType)
{
WCHAR wsz[256];
NTSTATUS ntStatus = Object_QueryNameString(
FileObject->DeviceObject,
wsz,
sizeof(wsz));
if (STATUS_SUCCESS == ntStatus)
{
KdPrint((“device name = %ws\n”, wsz));
}

}

BSOD is on ObQueryNameString call saying KMODE_UNHANDLED_EXCEPTION 0xC000005 0x00630069 0x00000000 0x00630069 or something. BSOD parameters are always the same. Watching stack with WinDbg does not give any results. Is that because of alignment? As far as I understand my code, all structers are aligned by DWORD (or aren’t they?). Is there any special requirements for ObQueryNameString?

----- Original Message -----
From: “Vadim Smirnov”
To: “NT Developers Interest List”
Sent: Monday, October 15, 2001 4:11 PM
Subject: [ntdev] RE: device name from device object

> You can use
>
> NTKERNELAPI
> NTSTATUS
> ObQueryNameString(
> IN PVOID Object, // pointer to device object here
> OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
> IN ULONG Length,
> OUT PULONG ReturnLength
> );
>
> Regards,
>
> Vadim
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Alexey Logachyov
> Sent: Monday, October 15, 2001 4:10 PM
> To: NT Developers Interest List
> Subject: [ntdev] device name from device object
>
>
> How can I get device name having a pointer to corresponding DEVICE_OBJECT?
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@pcausa.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@vba.com.by
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
You are currently subscribed to ntdev as: xxxxx@pcausa.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You are currently subscribed to ntdev as: xxxxx@vba.com.by
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You could try re-arranging a single code line…

WCHAR wsz[256];
ULONG len; // <— Put it here
OBJECT_NAME_INFORMATION oni;
oni.Name.Buffer = wsz;
oni.Name.Length = 0;
oni.Name.MaximumLength = sizeof(wsz) - sizeof(WCHAR);

But I don’t believe it will help much. OTOH, it *could* help
using ‘DeviceObject’ instead of ‘FileObject->DeviceObject’?!..

Miguel Monteiro
xxxxx@criticalsoftware.com

“Humour is God’s answer
to human weaknesses” =:o)8

----- Original Message -----
From: “Alexey Logachyov”
To: “NT Developers Interest List”
Sent: Tuesday, October 16, 2001 10:51 PM
Subject: [ntdev] RE: device name from device object

I found this function before I received this message but thanks anyway. I’ve got some problem with it though. The following code works fine (almost):

BOOLEAN MyClassName::MyMethodName(IN PDEVICE_OBJECT DeviceObject,
IN PFILE_OBJECT FileObject,
IN POOL_TYPE PoolType)
{
WCHAR wsz[256];
OBJECT_NAME_INFORMATION oni;
oni.Name.Buffer = wsz;
oni.Name.Length = 0;
oni.Name.MaximumLength = sizeof(wsz) - sizeof(WCHAR);
ULONG len;
NTSTATUS ntStatus = ObQueryNameString(
FileObject->DeviceObject,
&oni,
oni.Name.MaximumLength
&len);
if (STATUS_SUCCESS == ntStatus)
{
oni.Name.Buffer[oni.Name.Length / sizeof(WCHAR)] = ‘\0’;
KdPrint((“device name = %ws\n”, oni.Name.Buffer));
KdPrint((“device name = %ws\n”, wsz));
}

}

Almost fine because if I print out wsz I can’t see first 2 letters and I cannot understand why. I can do with that but the following arrangement causes BSOD and I cannot do with it:

NTSTATUS Object_QueryNameString(IN PDEVICE_OBJECT DeviceObject,
OUT PWSTR DeviceName,
IN USHORT DeviceNameLength)
{
OBJECT_NAME_INFORMATION oni;
oni.Name.Buffer = DeviceName;
oni.Name.Length = 0;
oni.Name.MaximumLength = DeviceNameLength - sizeof(WCHAR);
ULONG len;
NTSTATUS ntStatus = ObQueryNameString(
DeviceObject,
&oni,
oni.Name.MaximumLength,
&len);
if (STATUS_SUCCESS == ntStatus)
{
oni.Name.Buffer[oni.Name.Length / sizeof(WCHAR)] = L’\0’;
KdPrint((“device name = %ws\n”, oni.Name.Buffer));
}
return ntStatus;
}

BOOLEAN MyClassName::MyMethodName(IN PDEVICE_OBJECT DeviceObject,
IN PFILE_OBJECT FileObject,
IN POOL_TYPE PoolType)
{
WCHAR wsz[256];
NTSTATUS ntStatus = Object_QueryNameString(
FileObject->DeviceObject,
wsz,
sizeof(wsz));
if (STATUS_SUCCESS == ntStatus)
{
KdPrint((“device name = %ws\n”, wsz));
}

}

BSOD is on ObQueryNameString call saying KMODE_UNHANDLED_EXCEPTION 0xC000005 0x00630069 0x00000000 0x00630069 or something. BSOD parameters are always the same. Watching stack with WinDbg does not give any results. Is that because of alignment? As far as I understand my code, all structers are aligned by DWORD (or aren’t they?). Is there any special requirements for ObQueryNameString?

----- Original Message -----
From: “Vadim Smirnov”
To: “NT Developers Interest List”
Sent: Monday, October 15, 2001 4:11 PM
Subject: [ntdev] RE: device name from device object

> You can use
>
> NTKERNELAPI
> NTSTATUS
> ObQueryNameString(
> IN PVOID Object, // pointer to device object here
> OUT POBJECT_NAME_INFORMATION ObjectNameInfo,
> IN ULONG Length,
> OUT PULONG ReturnLength
> );
>
> Regards,
>
> Vadim
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com]On Behalf Of Alexey Logachyov
> Sent: Monday, October 15, 2001 4:10 PM
> To: NT Developers Interest List
> Subject: [ntdev] device name from device object
>
>
> How can I get device name having a pointer to corresponding DEVICE_OBJECT?
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@pcausa.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@vba.com.by
> To unsubscribe send a blank email to xxxxx@lists.osr.com


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

???y˫???+.n?+???u?ڲ˛??^r*D???kN???r??zǧu??jy???^j???ׯ??? 0?j?b??(??(