KMDF: Is there a traversable relationship from FileObject->FsContext to WDFFILEOBJECT that can be u

When a KMDF driver uses the FsContext pointer in the WDM FILE_OBJECT to
store the relationship between WDM FILE_OBJECT and WDFFILEOBJECT is the
?value? placed in the FsContext field reliably meaningful to a WDM
PreProcess routine?

Take for instance the case where a WDM PreProcess routine would like some
information from the context associated with a WDFFILEOBJECT.? Is it
possible through supported mechanisms to traverse from the PFILE_OBJECT in
the current stack location to the WDFFILEOBJECT without resorting to hackery
or inefficiency?

The only scheme I can see at present would be to tell KMDF to *not* use the
FsContext slot and to manually stash the WDFFILEOBJECT ?context? pointer (or
handle, or whatever) in the FsContext field.? That way a WDM pre-process
routine can be assured of the interpretation of the value.?? The terrible
down-side is that KMDF must then resort to some internal indexing or some
such to map a PFILE_OBJECT to a WDFFILEOBJECT since it cannot simply stuff
its own pointer in there.

It would be really quite useful if the value placed into the FsContext field
was something that could be fed back to KMDF to retrieve the
WDFFILEOBJECT.?? Is it by any chance a ?context? pointer?? It sure is not a
WDFHANDLE but instead appears to be the WDFOBJECT (FxFileObject).? AFAIK,
this value is entirely useless to a KMDF driver.

If the best scheme is to store the context address in the FsContext field
and use WdfObjectContextGetObject() to ‘get back’ to the WDFFILEOBJECT, what
(and in what paths) is the penalty for managing or searching the ‘index’ to
map PFILE_OBJECT to WDFFILEOBJECT?

Regards,
Dave Cattley

how about WdfDeviceGetFileObject

__drv_maxIRQL(DISPATCH_LEVEL)
WDFFILEOBJECT
FORCEINLINE
WdfDeviceGetFileObject(
__in
WDFDEVICE Device,
__in
PFILE_OBJECT FileObject
)

you can’t interpret it directly, but we will give it back to you through this API

d

Wow! That would be fine. I guess I need a better pair of reading glasses
or a WDK index in large type.

I assume then that if KMDF is allowed to use the FsContext field that
this is a fast dererence to the WDFFILEOBJECT?

Thanks,
-dave

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@Microsoft.com
Sent: Monday, July 13, 2009 3:24 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] KMDF: Is there a traversable relationship from
FileObject->FsContext to WDFFILEOBJECT that can be used in WDM
PreProcessing?

how about WdfDeviceGetFileObject

__drv_maxIRQL(DISPATCH_LEVEL)
WDFFILEOBJECT
FORCEINLINE
WdfDeviceGetFileObject(
__in
WDFDEVICE Device,
__in
PFILE_OBJECT FileObject
)

you can’t interpret it directly, but we will give it back to you through
this API

d


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

Yes, it is a straight look up, no locks or indexing if you let KDMF use FsContext or FsContext2

d