WdfDeviceRetrieveDeviceName error

I’m trying to get the device name of one of my devices. I call
WdfDeviceRetrieveDeviceName and always get 0xC000000D
STATUS_INVALID_PARAMETER. I’ve tried calling it from my create child
device call back on the PDO, from the Add device call back for the
function device and from the EvtDevicePrepareHardware call back for both
the PDO of the bus device and the FDO of the function device.

This driver is software only and is both its bus driver and the function
driver. The name is assigned automatically to the PDO by the kernel.
The frustrating thing is that DeviceTree show the device with its name.
In fact, I tell the bus driver to add a device, it adds the PDO and
then the Add Hardware wizard comes up. If I then run DeviceTree at this
point (before the function driver for the PDO has even been identified),
the device already shows its name.

Because it has a name in DeviceTree and because I get back
STATUS_INVALID_PARAMETER, I would assume my calling code is broken. I
searched the KMDF samples in the WDK and I can’t see anything different
between their code and mine.

I first tried this code:

fdoDevice is a WDFDEVICE.

WDF_OBJECT_ATTRIBUTES stringAttributes;
WDF_OBJECT_ATTRIBUTES_INIT(&stringAttributes);
stringAttributes.ParentObject = fdoDevice;
WDFSTRING deviceName;
NTSTATUS status = WdfStringCreate(NULL, &stringAttributes,
&deviceName);
if (!NT_SUCCESS(status))
{
return status;
}

status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
if (!NT_SUCCESS(status))
{
return status;
}

I then tried it without the object attributes like this:

fdoDevice is a WDFDEVICE.

WDFSTRING deviceName;
NTSTATUS status = WdfStringCreate(NULL,
WDF_NO_OBJECT_ATTRIBUTES,
&deviceName);
if (!NT_SUCCESS(status))
{
return status;
}

status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
if (!NT_SUCCESS(status))
{
return status;
}

No matter what I do, I get STATUS_INVALID_PARAMETER. Does anyone know
why this is happening?

Thanks,

Jonathan

BTW, the WDK docs seem to be incorrect for the sample code for this call:

NTSTATUS status;
WDFSTRING string;

status = WdfStringCreate(
WDF_NO_OBJECT_ATTRIBUTES,
NULL,
&string
);
if (NT_SUCCESS(status)) {
status = WdfDeviceRetrieveDeviceName(
Device,
string
);
if (!NT_SUCCESS(status)) {
return status;
}
}

I think

status = WdfStringCreate(
WDF_NO_OBJECT_ATTRIBUTES,
NULL,
&string
);

should be

status = WdfStringCreate(
NULL,
WDF_NO_OBJECT_ATTRIBUTES,
&string
);

Of course WDF_NO_OBJECT_ATTRIBUTES is NULL anyway so it would still
work. It may however lead someone to do this:

status = WdfStringCreate(
WDF_NO_OBJECT_ATTRIBUTES,
&unicodeString,
&string
);

Wow… nice find on both counts.

I don’t think it’s anything you’re doing wrong. From a cursory check, it seems that WdfDeviceRetrieveDeviceName may not be able to retrieve the name in all cases.

I might be wrong… I’ll shut up now and let somebody on the KMDF team comment,

Peter
OSR

RetrieveDeviceName works only for devices which you explicitly named. If you want the PDO’s name, then use WdfDeviceAllocAndQueryProperty(DevicePropertyPhysicalDeviceObjectName) and the WDFMEMORY will contain a null terminated string with the name. Typically in cases like these, !wdflogdump will tell you why the DDI failed, in this particular case, we do not log on error.

Why do you need the name though? The name of the PDO is not that interesting, it is typically linked to by a device interface or manual symbolic link (in the event that you create an unnamed FDO and then create a symbolic link, we use the PDO’s name internally as the target device object name).

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Jonathan Ludwig
Sent: Monday, January 14, 2008 11:05 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] WdfDeviceRetrieveDeviceName error

I’m trying to get the device name of one of my devices. I call
WdfDeviceRetrieveDeviceName and always get 0xC000000D
STATUS_INVALID_PARAMETER. I’ve tried calling it from my create child
device call back on the PDO, from the Add device call back for the
function device and from the EvtDevicePrepareHardware call back for both
the PDO of the bus device and the FDO of the function device.

This driver is software only and is both its bus driver and the function
driver. The name is assigned automatically to the PDO by the kernel.
The frustrating thing is that DeviceTree show the device with its name.
In fact, I tell the bus driver to add a device, it adds the PDO and
then the Add Hardware wizard comes up. If I then run DeviceTree at this
point (before the function driver for the PDO has even been identified),
the device already shows its name.

Because it has a name in DeviceTree and because I get back
STATUS_INVALID_PARAMETER, I would assume my calling code is broken. I
searched the KMDF samples in the WDK and I can’t see anything different
between their code and mine.

I first tried this code:

fdoDevice is a WDFDEVICE.

WDF_OBJECT_ATTRIBUTES stringAttributes;
WDF_OBJECT_ATTRIBUTES_INIT(&stringAttributes);
stringAttributes.ParentObject = fdoDevice;
WDFSTRING deviceName;
NTSTATUS status = WdfStringCreate(NULL, &stringAttributes,
&deviceName);
if (!NT_SUCCESS(status))
{
return status;
}

status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
if (!NT_SUCCESS(status))
{
return status;
}

I then tried it without the object attributes like this:

fdoDevice is a WDFDEVICE.

WDFSTRING deviceName;
NTSTATUS status = WdfStringCreate(NULL,
WDF_NO_OBJECT_ATTRIBUTES,
&deviceName);
if (!NT_SUCCESS(status))
{
return status;
}

status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
if (!NT_SUCCESS(status))
{
return status;
}

No matter what I do, I get STATUS_INVALID_PARAMETER. Does anyone know
why this is happening?

Thanks,

Jonathan

BTW, the WDK docs seem to be incorrect for the sample code for this call:

NTSTATUS status;
WDFSTRING string;

status = WdfStringCreate(
WDF_NO_OBJECT_ATTRIBUTES,
NULL,
&string
);
if (NT_SUCCESS(status)) {
status = WdfDeviceRetrieveDeviceName(
Device,
string
);
if (!NT_SUCCESS(status)) {
return status;
}
}

I think

status = WdfStringCreate(
WDF_NO_OBJECT_ATTRIBUTES,
NULL,
&string
);

should be

status = WdfStringCreate(
NULL,
WDF_NO_OBJECT_ATTRIBUTES,
&string
);

Of course WDF_NO_OBJECT_ATTRIBUTES is NULL anyway so it would still
work. It may however lead someone to do this:

status = WdfStringCreate(
WDF_NO_OBJECT_ATTRIBUTES,
&unicodeString,
&string
);


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Wrt the errors on the sample page, send feedback with the link on the bottom of the page and the doc writer will see the feedback

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Monday, January 14, 2008 12:01 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] WdfDeviceRetrieveDeviceName error

Wow… nice find on both counts.

I don’t think it’s anything you’re doing wrong. From a cursory check, it seems that WdfDeviceRetrieveDeviceName may not be able to retrieve the name in all cases.

I might be wrong… I’ll shut up now and let somebody on the KMDF team comment,

Peter
OSR


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Doron,

I’m writing a virtual volume driver. We need to support the
MOUNTDEV_MOUNTED_DEVICE_GUID interface so our virtual volumes can be
mounted under mount points. For this interface I need the device name
to support IOCTL_MOUNTDEV_QUERY_DEVICE_NAME ioctl. (Yes, I very
definitely want to assign mount points to these volumes.)

I would actually prefer giving it my own name for support and
debug-ability purposes, but when I try to assign a name to the PDO, the
PDO ends up with no name at all, even after the FDO has been created and
the hardware initialized.

From searching the forums, I see that assigning PDOs custom names it
not a recommended practice, so I decided to just use the generated name.
This is not necessarily related, but I would like to use my own names.
I understand the whole issue with names not being reusable, but my
architecture doesn’t care what the names are, I just increment a numeric
tail on the name with each device created. I would like to figure out
how to name my PDOs too, but I can just settle with the generated name.

I will change my code to call
WdfDeviceAllocAndQueryProperty(DevicePropertyPhysicalDeviceObjectName)
instead. When can I call this? Do I have to wait for
EvtDevicePrepareHardware, or can I call it from the add device callback
for my FDO device?

Thanks,

Jonathan

Doron Holan wrote:

RetrieveDeviceName works only for devices which you explicitly named. If you want the PDO’s name, then use WdfDeviceAllocAndQueryProperty(DevicePropertyPhysicalDeviceObjectName) and the WDFMEMORY will contain a null terminated string with the name. Typically in cases like these, !wdflogdump will tell you why the DDI failed, in this particular case, we do not log on error.
>
> Why do you need the name though? The name of the PDO is not that interesting, it is typically linked to by a device interface or manual symbolic link (in the event that you create an unnamed FDO and then create a symbolic link, we use the PDO’s name internally as the target device object name).
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Jonathan Ludwig
> Sent: Monday, January 14, 2008 11:05 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] WdfDeviceRetrieveDeviceName error
>
> I’m trying to get the device name of one of my devices. I call
> WdfDeviceRetrieveDeviceName and always get 0xC000000D
> STATUS_INVALID_PARAMETER. I’ve tried calling it from my create child
> device call back on the PDO, from the Add device call back for the
> function device and from the EvtDevicePrepareHardware call back for both
> the PDO of the bus device and the FDO of the function device.
>
> This driver is software only and is both its bus driver and the function
> driver. The name is assigned automatically to the PDO by the kernel.
> The frustrating thing is that DeviceTree show the device with its name.
> In fact, I tell the bus driver to add a device, it adds the PDO and
> then the Add Hardware wizard comes up. If I then run DeviceTree at this
> point (before the function driver for the PDO has even been identified),
> the device already shows its name.
>
> Because it has a name in DeviceTree and because I get back
> STATUS_INVALID_PARAMETER, I would assume my calling code is broken. I
> searched the KMDF samples in the WDK and I can’t see anything different
> between their code and mine.
>
> I first tried this code:
>
> fdoDevice is a WDFDEVICE.
>
> WDF_OBJECT_ATTRIBUTES stringAttributes;
> WDF_OBJECT_ATTRIBUTES_INIT(&stringAttributes);
> stringAttributes.ParentObject = fdoDevice;
> WDFSTRING deviceName;
> NTSTATUS status = WdfStringCreate(NULL, &stringAttributes,
> &deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> I then tried it without the object attributes like this:
>
>
> fdoDevice is a WDFDEVICE.
>
> WDFSTRING deviceName;
> NTSTATUS status = WdfStringCreate(NULL,
> WDF_NO_OBJECT_ATTRIBUTES,
> &deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> No matter what I do, I get STATUS_INVALID_PARAMETER. Does anyone know
> why this is happening?
>
>
> Thanks,
>
> Jonathan
>
>
> BTW, the WDK docs seem to be incorrect for the sample code for this call:
>
> NTSTATUS status;
> WDFSTRING string;
>
> status = WdfStringCreate(
> WDF_NO_OBJECT_ATTRIBUTES,
> NULL,
> &string
> );
> if (NT_SUCCESS(status)) {
> status = WdfDeviceRetrieveDeviceName(
> Device,
> string
> );
> if (!NT_SUCCESS(status)) {
> return status;
> }
> }
>
>
> I think
>
> status = WdfStringCreate(
> WDF_NO_OBJECT_ATTRIBUTES,
> NULL,
> &string
> );
>
>
> should be
>
> status = WdfStringCreate(
> NULL,
> WDF_NO_OBJECT_ATTRIBUTES,
> &string
> );
>
> Of course WDF_NO_OBJECT_ATTRIBUTES is NULL anyway so it would still
> work. It may however lead someone to do this:
>
>
>
> status = WdfStringCreate(
> WDF_NO_OBJECT_ATTRIBUTES,
> &unicodeString,
> &string
> );
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

The *WdfDeviceRetrieveDeviceName* method returns the device name that the
driver specified in a previous call to
*WdfDeviceInitAssignName*ms-help:
.
— the WDK.

I’m guessing that this is a device object that you did not name.

On Jan 14, 2008 2:04 PM, Jonathan Ludwig wrote:

> I’m trying to get the device name of one of my devices. I call
> WdfDeviceRetrieveDeviceName and always get 0xC000000D
> STATUS_INVALID_PARAMETER. I’ve tried calling it from my create child
> device call back on the PDO, from the Add device call back for the
> function device and from the EvtDevicePrepareHardware call back for both
> the PDO of the bus device and the FDO of the function device.
>
> This driver is software only and is both its bus driver and the function
> driver. The name is assigned automatically to the PDO by the kernel.
> The frustrating thing is that DeviceTree show the device with its name.
> In fact, I tell the bus driver to add a device, it adds the PDO and
> then the Add Hardware wizard comes up. If I then run DeviceTree at this
> point (before the function driver for the PDO has even been identified),
> the device already shows its name.
>
> Because it has a name in DeviceTree and because I get back
> STATUS_INVALID_PARAMETER, I would assume my calling code is broken. I
> searched the KMDF samples in the WDK and I can’t see anything different
> between their code and mine.
>
> I first tried this code:
>
> fdoDevice is a WDFDEVICE.
>
> WDF_OBJECT_ATTRIBUTES stringAttributes;
> WDF_OBJECT_ATTRIBUTES_INIT(&stringAttributes);
> stringAttributes.ParentObject = fdoDevice;
> WDFSTRING deviceName;
> NTSTATUS status = WdfStringCreate(NULL,
> &stringAttributes,
> &deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> I then tried it without the object attributes like this:
>
>
> fdoDevice is a WDFDEVICE.
>
> WDFSTRING deviceName;
> NTSTATUS status = WdfStringCreate(NULL,
> WDF_NO_OBJECT_ATTRIBUTES,
> &deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> No matter what I do, I get STATUS_INVALID_PARAMETER. Does anyone know
> why this is happening?
>
>
> Thanks,
>
> Jonathan
>
>
> BTW, the WDK docs seem to be incorrect for the sample code for this call:
>
> NTSTATUS status;
> WDFSTRING string;
>
> status = WdfStringCreate(
> WDF_NO_OBJECT_ATTRIBUTES,
> NULL,
> &string
> );
> if (NT_SUCCESS(status)) {
> status = WdfDeviceRetrieveDeviceName(
> Device,
> string
> );
> if (!NT_SUCCESS(status)) {
> return status;
> }
> }
>
>
> I think
>
> status = WdfStringCreate(
> WDF_NO_OBJECT_ATTRIBUTES,
> NULL,
> &string
> );
>
>
> should be
>
> status = WdfStringCreate(
> NULL,
> WDF_NO_OBJECT_ATTRIBUTES,
> &string
> );
>
> Of course WDF_NO_OBJECT_ATTRIBUTES is NULL anyway so it would still
> work. It may however lead someone to do this:
>
>
>
> status = WdfStringCreate(
> WDF_NO_OBJECT_ATTRIBUTES,
> &unicodeString,
> &string
> );
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Mark Roddy</ms-help:>

For an FDO, you can query the property on the underlying PDO at EvtDriverAddDevice time. For a PDO that you create, I don’t think you can query for your own name via the property until later (PrepareHardware is a good spot) b/c the PDO has not been recognized by pnp as a PDO yet which means you cannot pass it to an API which expects a PDO (isn’t that a mouthful of PDO? :slight_smile: ).

You should be able to assign a name to any PDO that you create in your driver. KMDF certainly lets you do this. I want to strongly back the docs, assigning your own name is not needed. Nobody cares about the format and all it will do is add more code to your project and be something that someone will have to maintain over time. IMHO, if works, just leave it alone :slight_smile:

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Jonathan Ludwig
Sent: Monday, January 14, 2008 12:41 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] WdfDeviceRetrieveDeviceName error

Doron,

I’m writing a virtual volume driver. We need to support the
MOUNTDEV_MOUNTED_DEVICE_GUID interface so our virtual volumes can be
mounted under mount points. For this interface I need the device name
to support IOCTL_MOUNTDEV_QUERY_DEVICE_NAME ioctl. (Yes, I very
definitely want to assign mount points to these volumes.)

I would actually prefer giving it my own name for support and
debug-ability purposes, but when I try to assign a name to the PDO, the
PDO ends up with no name at all, even after the FDO has been created and
the hardware initialized.

From searching the forums, I see that assigning PDOs custom names it
not a recommended practice, so I decided to just use the generated name.
This is not necessarily related, but I would like to use my own names.
I understand the whole issue with names not being reusable, but my
architecture doesn’t care what the names are, I just increment a numeric
tail on the name with each device created. I would like to figure out
how to name my PDOs too, but I can just settle with the generated name.

I will change my code to call
WdfDeviceAllocAndQueryProperty(DevicePropertyPhysicalDeviceObjectName)
instead. When can I call this? Do I have to wait for
EvtDevicePrepareHardware, or can I call it from the add device callback
for my FDO device?

Thanks,

Jonathan

Doron Holan wrote:

RetrieveDeviceName works only for devices which you explicitly named. If you want the PDO’s name, then use WdfDeviceAllocAndQueryProperty(DevicePropertyPhysicalDeviceObjectName) and the WDFMEMORY will contain a null terminated string with the name. Typically in cases like these, !wdflogdump will tell you why the DDI failed, in this particular case, we do not log on error.
>
> Why do you need the name though? The name of the PDO is not that interesting, it is typically linked to by a device interface or manual symbolic link (in the event that you create an unnamed FDO and then create a symbolic link, we use the PDO’s name internally as the target device object name).
>
> d
>
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Jonathan Ludwig
> Sent: Monday, January 14, 2008 11:05 AM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] WdfDeviceRetrieveDeviceName error
>
> I’m trying to get the device name of one of my devices. I call
> WdfDeviceRetrieveDeviceName and always get 0xC000000D
> STATUS_INVALID_PARAMETER. I’ve tried calling it from my create child
> device call back on the PDO, from the Add device call back for the
> function device and from the EvtDevicePrepareHardware call back for both
> the PDO of the bus device and the FDO of the function device.
>
> This driver is software only and is both its bus driver and the function
> driver. The name is assigned automatically to the PDO by the kernel.
> The frustrating thing is that DeviceTree show the device with its name.
> In fact, I tell the bus driver to add a device, it adds the PDO and
> then the Add Hardware wizard comes up. If I then run DeviceTree at this
> point (before the function driver for the PDO has even been identified),
> the device already shows its name.
>
> Because it has a name in DeviceTree and because I get back
> STATUS_INVALID_PARAMETER, I would assume my calling code is broken. I
> searched the KMDF samples in the WDK and I can’t see anything different
> between their code and mine.
>
> I first tried this code:
>
> fdoDevice is a WDFDEVICE.
>
> WDF_OBJECT_ATTRIBUTES stringAttributes;
> WDF_OBJECT_ATTRIBUTES_INIT(&stringAttributes);
> stringAttributes.ParentObject = fdoDevice;
> WDFSTRING deviceName;
> NTSTATUS status = WdfStringCreate(NULL, &stringAttributes,
> &deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> I then tried it without the object attributes like this:
>
>
> fdoDevice is a WDFDEVICE.
>
> WDFSTRING deviceName;
> NTSTATUS status = WdfStringCreate(NULL,
> WDF_NO_OBJECT_ATTRIBUTES,
> &deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
> if (!NT_SUCCESS(status))
> {
> return status;
> }
>
> No matter what I do, I get STATUS_INVALID_PARAMETER. Does anyone know
> why this is happening?
>
>
> Thanks,
>
> Jonathan
>
>
> BTW, the WDK docs seem to be incorrect for the sample code for this call:
>
> NTSTATUS status;
> WDFSTRING string;
>
> status = WdfStringCreate(
> WDF_NO_OBJECT_ATTRIBUTES,
> NULL,
> &string
> );
> if (NT_SUCCESS(status)) {
> status = WdfDeviceRetrieveDeviceName(
> Device,
> string
> );
> if (!NT_SUCCESS(status)) {
> return status;
> }
> }
>
>
> I think
>
> status = WdfStringCreate(
> WDF_NO_OBJECT_ATTRIBUTES,
> NULL,
> &string
> );
>
>
> should be
>
> status = WdfStringCreate(
> NULL,
> WDF_NO_OBJECT_ATTRIBUTES,
> &string
> );
>
> Of course WDF_NO_OBJECT_ATTRIBUTES is NULL anyway so it would still
> work. It may however lead someone to do this:
>
>
>
> status = WdfStringCreate(
> WDF_NO_OBJECT_ATTRIBUTES,
> &unicodeString,
> &string
> );
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Doron,

I’s just interesting that I cannot get a custom device name assigned. I
noticed other posts, but no good responses. I just know that if I try
to assign a name to my PDO in my child list’s create child callback,
before creating the PDO, WdfDeviceInitAssignName returns STATUS_SUCCESS,
DeviceTree shows no name and a subsequent call to
WdfDeviceRetrieveDeviceName fails. Like I said, it’s not that important
to me. It just makes debugging (particularly for a QA engineer much
easier.) I’ll just use the assigned name.

WdfDeviceAllocAndQueryProperty(DevicePropertyPhysicalDeviceObjectName)
works very well in the FDOs add device callback.

Thanks,

Jonathan

Doron Holan wrote:

For an FDO, you can query the property on the underlying PDO at EvtDriverAddDevice time. For a PDO that you create, I don’t think you can query for your own name via the property until later (PrepareHardware is a good spot) b/c the PDO has not been recognized by pnp as a PDO yet which means you cannot pass it to an API which expects a PDO (isn’t that a mouthful of PDO? :slight_smile: ).

You should be able to assign a name to any PDO that you create in your driver. KMDF certainly lets you do this. I want to strongly back the docs, assigning your own name is not needed. Nobody cares about the format and all it will do is add more code to your project and be something that someone will have to maintain over time. IMHO, if works, just leave it alone :slight_smile:

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Jonathan Ludwig
Sent: Monday, January 14, 2008 12:41 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] WdfDeviceRetrieveDeviceName error

Doron,

I’m writing a virtual volume driver. We need to support the
MOUNTDEV_MOUNTED_DEVICE_GUID interface so our virtual volumes can be
mounted under mount points. For this interface I need the device name
to support IOCTL_MOUNTDEV_QUERY_DEVICE_NAME ioctl. (Yes, I very
definitely want to assign mount points to these volumes.)

I would actually prefer giving it my own name for support and
debug-ability purposes, but when I try to assign a name to the PDO, the
PDO ends up with no name at all, even after the FDO has been created and
the hardware initialized.

From searching the forums, I see that assigning PDOs custom names it
not a recommended practice, so I decided to just use the generated name.
This is not necessarily related, but I would like to use my own names.
I understand the whole issue with names not being reusable, but my
architecture doesn’t care what the names are, I just increment a numeric
tail on the name with each device created. I would like to figure out
how to name my PDOs too, but I can just settle with the generated name.

I will change my code to call
WdfDeviceAllocAndQueryProperty(DevicePropertyPhysicalDeviceObjectName)
instead. When can I call this? Do I have to wait for
EvtDevicePrepareHardware, or can I call it from the add device callback
for my FDO device?

Thanks,

Jonathan

Doron Holan wrote:
> RetrieveDeviceName works only for devices which you explicitly named. If you want the PDO’s name, then use WdfDeviceAllocAndQueryProperty(DevicePropertyPhysicalDeviceObjectName) and the WDFMEMORY will contain a null terminated string with the name. Typically in cases like these, !wdflogdump will tell you why the DDI failed, in this particular case, we do not log on error.
>>
>> Why do you need the name though? The name of the PDO is not that interesting, it is typically linked to by a device interface or manual symbolic link (in the event that you create an unnamed FDO and then create a symbolic link, we use the PDO’s name internally as the target device object name).
>>
>> d
>>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Jonathan Ludwig
>> Sent: Monday, January 14, 2008 11:05 AM
>> To: Windows System Software Devs Interest List
>> Subject: [ntdev] WdfDeviceRetrieveDeviceName error
>>
>> I’m trying to get the device name of one of my devices. I call
>> WdfDeviceRetrieveDeviceName and always get 0xC000000D
>> STATUS_INVALID_PARAMETER. I’ve tried calling it from my create child
>> device call back on the PDO, from the Add device call back for the
>> function device and from the EvtDevicePrepareHardware call back for both
>> the PDO of the bus device and the FDO of the function device.
>>
>> This driver is software only and is both its bus driver and the function
>> driver. The name is assigned automatically to the PDO by the kernel.
>> The frustrating thing is that DeviceTree show the device with its name.
>> In fact, I tell the bus driver to add a device, it adds the PDO and
>> then the Add Hardware wizard comes up. If I then run DeviceTree at this
>> point (before the function driver for the PDO has even been identified),
>> the device already shows its name.
>>
>> Because it has a name in DeviceTree and because I get back
>> STATUS_INVALID_PARAMETER, I would assume my calling code is broken. I
>> searched the KMDF samples in the WDK and I can’t see anything different
>> between their code and mine.
>>
>> I first tried this code:
>>
>> fdoDevice is a WDFDEVICE.
>>
>> WDF_OBJECT_ATTRIBUTES stringAttributes;
>> WDF_OBJECT_ATTRIBUTES_INIT(&stringAttributes);
>> stringAttributes.ParentObject = fdoDevice;
>> WDFSTRING deviceName;
>> NTSTATUS status = WdfStringCreate(NULL, &stringAttributes,
>> &deviceName);
>> if (!NT_SUCCESS(status))
>> {
>> return status;
>> }
>>
>> status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
>> if (!NT_SUCCESS(status))
>> {
>> return status;
>> }
>>
>> I then tried it without the object attributes like this:
>>
>>
>> fdoDevice is a WDFDEVICE.
>>
>> WDFSTRING deviceName;
>> NTSTATUS status = WdfStringCreate(NULL,
>> WDF_NO_OBJECT_ATTRIBUTES,
>> &deviceName);
>> if (!NT_SUCCESS(status))
>> {
>> return status;
>> }
>>
>> status = WdfDeviceRetrieveDeviceName(fdoDevice, deviceName);
>> if (!NT_SUCCESS(status))
>> {
>> return status;
>> }
>>
>> No matter what I do, I get STATUS_INVALID_PARAMETER. Does anyone know
>> why this is happening?
>>
>>
>> Thanks,
>>
>> Jonathan
>>
>>
>> BTW, the WDK docs seem to be incorrect for the sample code for this call:
>>
>> NTSTATUS status;
>> WDFSTRING string;
>>
>> status = WdfStringCreate(
>> WDF_NO_OBJECT_ATTRIBUTES,
>> NULL,
>> &string
>> );
>> if (NT_SUCCESS(status)) {
>> status = WdfDeviceRetrieveDeviceName(
>> Device,
>> string
>> );
>> if (!NT_SUCCESS(status)) {
>> return status;
>> }
>> }
>>
>>
>> I think
>>
>> status = WdfStringCreate(
>> WDF_NO_OBJECT_ATTRIBUTES,
>> NULL,
>> &string
>> );
>>
>>
>> should be
>>
>> status = WdfStringCreate(
>> NULL,
>> WDF_NO_OBJECT_ATTRIBUTES,
>> &string
>> );
>>
>> Of course WDF_NO_OBJECT_ATTRIBUTES is NULL anyway so it would still
>> work. It may however lead someone to do this:
>>
>>
>>
>> status = WdfStringCreate(
>> WDF_NO_OBJECT_ATTRIBUTES,
>> &unicodeString,
>> &string
>> );
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

Jonathan Ludwig wrote:

I just know that if I try to assign a name to my PDO in my child
list’s create child callback, before creating the PDO,
WdfDeviceInitAssignName returns STATUS_SUCCESS, DeviceTree
shows no name and a subsequent call to
WdfDeviceRetrieveDeviceName fails.

I never got WdfDeviceInitAssignName() to work either[1]. I eventually just gave up also, presumably because it is rarely necessary (as I learned).

[1] http://www.osronline.com/showthread.cfm?link=104809

> I’s just interesting that I cannot get a custom device name assigned. I

noticed other posts, but no good responses. I just know that if I try
to assign a name to my PDO in my child list’s create child callback,

The standard way of assigning the names to the PDOs is in MN_START_DEVICE path
aka PrepareHardware KMDF event.

At this point in time, IoGetDeviceProperty can be used to get the autogenerated
device name and to assign symlinks to it.


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

BTW, we’re investigating this isue of it not working on PDOs [bug filed and all that good stuff]. I have confirmed it as a test hole.

Sorry we missed last year’s report from Chris Aseltine, but that’s one reason I occasionally flog the “if you could, just try one more time to contact one of us directly” approach. This list gets a lot of traffic, and while it’s not an official support vehicle we try to pay attention.

But we sometimes miss things like this (and even the backup could fail, which is when a support incident has merit- somebody’s job is supposed to include tracking your incident).