IoGetDeviceObjectPointer() fails with no return status

0

This is my code:

UNICODE_STRING  symbol;     
WCHAR ntNameBuffer[128];
swprintf(ntNameBuffer, L"\\Device\\Harddisk1\\Partition1");

RtlInitUnicodeString(&symbol, ntNameBuffer);
KdPrint(("OSNVss:symbol is %ws\n",symbol.Buffer));

status = IoGetDeviceObjectPointer(&symbol,                                                  
             FILE_READ_DATA,
             &pDiskFileObject,
             &pDiskDeviceObject);

My driver is next-lower-level of \\Device\\Harddisk1\\Partition1.

When I call IoGetDeviceObjectPointer it will fail and no status returns and it not continue do remaining code.

When I use windbg debug this, it will break with a intelpm.sys;

If I change the objectname to "\\Device\\Harddisk1\\Partition2" (the partition2 is really existing), it will success call

If I change objectname to "\\Device\\Harddisk1\\Partition3", (the partition3 is not existing), it failed and return status = 0xc0000034, mean objectname is not existing.

Does anybody know why when I use object "\\Device\\Harddisk1\\Partition1" it fails and no return status? thanks very much!

windows
winapi
driver
asked on Stack Overflow Nov 20, 2012 by Jay • edited Nov 20, 2012 by Alex K.

2 Answers

1

First and foremost: what are you trying to achieve and what driver model are you using? What bitness, what OS versions are targeted and on which OS version does it fail? Furthermore: you are at the correct IRQL for the call and is running inside a system thread, right? From which of your driver's entry points (IRP_MJ_*, DriverEntry ...) are you calling this code?

Anyway, was re-reading the docs on this function. Noting in particular the part:

The IoGetDeviceObjectPointer routine returns a pointer to the top object in the named device object's stack and a pointer to the corresponding file object, if the requested access to the objects can be granted.

and:

IoGetDeviceObjectPointer establishes a "connection" between the caller and the next-lower-level driver. A successful caller can use the returned device object pointer to initialize its own device objects. It can also be used as as an argument to IoAttachDeviceToDeviceStack, IoCallDriver, and any routine that creates IRPs for lower drivers. The returned pointer is a required argument to IoCallDriver.

You don't say, but if you are doing this on a 32bit system, it may be worthwhile tracking down what's going on with IrpTracker. However, my guess is that said "connection" or rather the request for it gets somehow swallowed by the next-lower-level driver or so.

It is also hard to say what kind of driver you are writing here (and yes, this can be important).

Try not just breaking at a particular point before or after the fact but rather follow the stack that the IRP would travel downwards in the target device object's stack.

But thinking about it, you probably aren't attached to the stack at all (for whatever reason). Could it be that you actually should be using IoGetDiskDeviceObject instead, in order to get the actual underlying device object (at the bottom of the stack) and not a reference to the top-level object attached?

Last but not least: don't forget you can also ask this question over on the OSR mailing lists. There are plenty of seasoned professionals there who may have run into the exact same problem (assuming you are doing all of the things correct that I asked about).

answered on Stack Overflow Nov 21, 2012 by 0xC0000022L
1

thanks everyone , I solve this problem; what cause this problem is it becoming synchronous; when I call IoGetDeviceObjectPointer , it will generate an new Irp IRP_MJ_WRITER which pass though from high level, when this irp reach my driver, my thread which handle IRP is the same thread whilch call IoGetDeviceObjectPointer ,so it become drop-dead halt;

answered on Stack Overflow Nov 26, 2012 by Jay

User contributions licensed under CC BY-SA 3.0