how to know if invalid PDO

Hi all,

How could I know if a device object is a valid PDO? I am calling IoGetDeviceProperty, but I need a valid PDO to call IoGetDeviceProperty and not get a BSOD under Windows 2000.

Thanks in advance,

Eugenio Barahona Marciel

There is no exported kernel interface to ask if a device object is a
PDO, instead you have to know where you got this device object from, and
from that knowledge understand if it is a PDO or not.

Typically your AddDevice routine is your friend here:

NTSTATUS
XxxAddDevice(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
);

That last parameter is a device object that is a PDO.

There is (obviously) an internal test within the Io Manager for the PDO
attribute of a device object. Unfortunately it is not exported to
drivers and more unfortunately some flavors of Windows prefer to crash
rather than error out when handed a non PDO device object to an
interface such as IoGetDeviceProperty.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of ebarahona@ya.com
Sent: Tuesday, October 30, 2007 7:50 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] how to know if invalid PDO

Hi all,

How could I know if a device object is a valid PDO? I am calling
IoGetDeviceProperty, but I need a valid PDO to call IoGetDeviceProperty
and not get a BSOD under Windows 2000.

Thanks in advance,

Eugenio Barahona Marciel


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

Just to add what Mark said: There’s really no way to distinguish a PDO from an FDO via a driver. Remember, they’re both just “device objects” and PDO or FDO is in fact just a role, a usage, that the device object plays.

Having said that, there are a few heuristics that you can use to GUESS about whether a given device is a PDO or an FDO. My preferred method is the DO_BUS_ENUMERATED_DEVICE bit. You’ll typically find this set for PDOs and not for FDOs. But, as I said, this is an heuristic – a rule of thumb – not a Windows architectural requirement.

Peter
OSR

Hello,

I’ve found this thread (it’s in Russian):
http://translate.google.com/translate?hl=en&sl=ru&u=http://wasm.ru/forum/viewtopic.php%3Fpid%3D147618

It seems like WDK’s definition of DEVOBJ_EXTENSION is incomplete as it also contains a member “DeviceNode” among other ones.

According to this thread, DeviceNode is always NULL for non-PDOs, so the check could be as easy as:

if (DeviceObject->DeviceObjectExtension->DeviceNode) {
// PDO!
} else {
// non-PDO!
}

Albeit completely undocumented…

I wouldn’t use the word “incomplete” – More correctly, I’d say the fields that are not part of WDM.H or NTDDK.H are private data to the I/O Manager or PnP Manager.

As Mr. Roddy said, the I/O Manager obviously knows whether a Device Object’s role is as a PDO or as an FDO. So, that there’s some field somewhere that helps define this isn’t exactly “news”.

I don’t suggest you start fooling with or relying on O/S private, unexported, undocumented, data structures. It’s just not good engineering… unless you’re talking about some internal-use-only hack-and-whack diagnostic crap. In which case, hey… anything goes.

Peter
OSR

Thanks a lot for your answers.

I have tried the solution suggested by Peter (using the DO_BUS_ENUMERATED_DEVICE bit) and it solves my problem under Windows 2000.

Eugenio Barahona

[sigh]. Whenever I see this question, I have to ask why don’t you know a priori? It is usually due to one of two reasons:

  1. The person is writing a bus driver and wants to know when the PDO they create is really a PDO after it is reported via IRP_MN_QUERY_DEVICE_RELATIONS(QDR)/BusRelations. I wrote about when it becomes a PDO here http://blogs.msdn.com/doronh/archive/2006/06/12/629120.aspx

  2. the person “found” the device object. Could have been found through a legit API call (like IoGetDeviceObjectPointer) or by hackery (like finding another driver’s PDRIVER_OBJECT and walking the devobj list). There is a legit way to see if a devobj is a PDO, send a QDR/TargetDeviceRelation (and remember to deref the resulting PDEVICE_OBJECT in the relations list when you are done!). Upon success, the resulting devobj in the QDR will be the PDO for the device object you have. No need to touch undocumented fields (DevNode in the DEVOBJ_EXTENSION) nor undocumented flags (DO_BUS_ENUMERATED_DEVICE).

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Tuesday, October 30, 2007 9:20 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] how to know if invalid PDO

I wouldn’t use the word “incomplete” – More correctly, I’d say the fields that are not part of WDM.H or NTDDK.H are private data to the I/O Manager or PnP Manager.

As Mr. Roddy said, the I/O Manager obviously knows whether a Device Object’s role is as a PDO or as an FDO. So, that there’s some field somewhere that helps define this isn’t exactly “news”.

I don’t suggest you start fooling with or relying on O/S private, unexported, undocumented, data structures. It’s just not good engineering… unless you’re talking about some internal-use-only hack-and-whack diagnostic crap. In which case, hey… anything goes.

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

Please read my other response on how to do this properly and in a documented way (QDR/TargetDeviceRelations). Please do not rely on an undocumented flag to do make this decision.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of ebarahona@ya.com
Sent: Tuesday, October 30, 2007 9:29 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] how to know if invalid PDO

Thanks a lot for your answers.

I have tried the solution suggested by Peter (using the DO_BUS_ENUMERATED_DEVICE bit) and it solves my problem under Windows 2000.

Eugenio Barahona


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

> Having said that, there are a few heuristics that you can use to GUESS about

whether a given device is a PDO or an FDO. My preferred method is the
DO_BUS_ENUMERATED_DEVICE bit.

->DeviceObjectExtension is usually non-NULL for PDOs and NULL for non PDOs.


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

After checking Microsoft’s preliminary documentation of DEVICE_OBJECT,
I’d prefer the method Peter Viscarola suggested.

It states:
“DO_BUS_ENUMERATED_DEVICE
The system sets this flag in each physical device object (PDO). Drivers must not modify this flag.”

xxxxx@hushmail.com wrote:

After checking Microsoft’s preliminary documentation of DEVICE_OBJECT,
I’d prefer the method Peter Viscarola suggested.

It states:
“DO_BUS_ENUMERATED_DEVICE
The system sets this flag in each physical device object (PDO). Drivers must not modify this flag.”

Didn’t Doron give an documented solution to this problem?

mm

MM wrote:

Didn’t Doron give an documented solution to this problem?
He mainly questioned the reason(s) behind this necessity.

DO_BUS_ENUMERATED_DEVICE is easy and documented, so safe to use.

wrote in message news:xxxxx@ntdev…
> MM wrote:
>> Didn’t Doron give an documented solution to this problem?
> He mainly questioned the reason(s) behind this necessity.
>
> DO_BUS_ENUMERATED_DEVICE is easy and documented, so safe to use.
>
Documented but not guaranteed, so you can be nailed.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

My point still stands about why you need to know. Why do you have a random device object whose role you don’t know?

The problem here is that the presence of this flag does not mean it is an /INITIALIZED/ PDO, either from the perspective of the driver who enumerated it OR the pnp subsystem. This flag can be set before (the aforementioned) devnode structure is allocated for it, it is this devnode structure which makes some APIs which require a PDO functional (e.g. they dereference this in the function).

Why do you have a random device that you want to test?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hushmail.com
Sent: Friday, November 02, 2007 11:21 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] how to know if invalid PDO

MM wrote:

Didn’t Doron give an documented solution to this problem?
He mainly questioned the reason(s) behind this necessity.

DO_BUS_ENUMERATED_DEVICE is easy and documented, so safe to use.


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 Holan wrote:

Why do you have a random device that you want to test?

In case you asked me, I don’t want to. My interest in this thread is merely of educational nature.