HANDLE/FILE_OBECT private driver data

Hi everybody,
is there any fast way to create and retrieve custom driver data on a per-HANDLE basic?
I read it is possibile to have a DEVICE_OBJECT private extension but it is global device resource. What I really need is a fast way to set a context during a IRP_MJ_CREATE and get it from any other IRP called on the same HANDLE (much like a file->private_data field on Linux). I looked into the associated FILE_OBJECT but i didn’t find any free driver-private pointer/storage.

Thanks in advance,

  • antibodi

You may use FsContext and/or FsContext2 to maintain your context.

But this is *not* for filtered file-objects. E.g. contexts for filtered
filesystem-file-objects are supported by FltSetStreamHandleContext

wrote news:xxxxx@ntdev…
> Hi everybody,
> is there any fast way to create and retrieve custom driver data on a
> per-HANDLE basic?
> I read it is possibile to have a DEVICE_OBJECT private extension but it is
> global device resource. What I really need is a fast way to set a context
> during a IRP_MJ_CREATE and get it from any other IRP called on the same
> HANDLE (much like a file->private_data field on Linux). I looked into the
> associated FILE_OBJECT but i didn’t find any free driver-private
> pointer/storage.
>
> Thanks in advance,
> - antibodi
>

Hi Frank,
tnx for your answer.
So, basically, if my driver is not a file system driver I can freely use those fields for private driver purpose? Any preference or they are interchangeable if not used by the stacked file-system drivers?

Thanks,
Antibodi

Yes you may choose freely among these two.

> is there any fast way to create and retrieve custom driver data on a per-HANDLE basic?

No.

Only per-FILE_OBJECT. Use FILE_OBJECT::FsContext2 for it.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

> So, basically, if my driver is not a file system driver I can freely use those fields for private driver

purpose?

FsContext2 is just the same as “private_data” in Linux.

FsContext must point to the FCB header with locks, otherwise, strange BSODs follow, so, do not use it outside the FSD scope.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Not true. FsContext can be anything outside of the storage / FS silo.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Tuesday, April 17, 2012 11:05 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] HANDLE/FILE_OBECT private driver data

So, basically, if my driver is not a file system driver I can freely
use those fields for private driver purpose?

FsContext2 is just the same as “private_data” in Linux.

FsContext must point to the FCB header with locks, otherwise, strange BSODs follow, so, do not use it outside the FSD scope.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com


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

Thank you very much to everybody,
this is definitely the best public community ever on the topic:)

  • Antibodi

>Not true. FsContext can be anything outside of the storage / FS silo.

What about calling MapViewOfFile on a file with custom FsContext? Would not it crash due to internal assumption in MmCreateSection that FsContext points to the FCB header?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

“Maxim S. Shatskih” wrote in message news:xxxxx@ntdev…

What about calling MapViewOfFile on a file with custom FsContext? Would not
it crash due to internal assumption in MmCreateSection that FsContext
>points to the FCB header?

You also have to have a valid SectionObjectPointer field to indicate that
you’re supporting the Mm interface, otherwise the user can’t create the
section. This saves you from inadvertently creating a security hole by using
FsContext.

Now, if you set SOP *and* you use a non-standard FsContext structure then
you get what you deserve. Though I have come across drivers out there that
try to get away with this and it’s a huge pain if you’re a filter.

-scott


Scott Noone
Consulting Associate and Chief System Problem Analyst
OSR Open Systems Resources, Inc.
http://www.osronline.com

> Now, if you set SOP *and* you use a non-standard FsContext structure then

I remember having a driver which has neither Cc interface nor mmaped file support, but was using FsContext.

There were some crashes due to Mm assuming any file with non-NULL FsContext to contain the FCB header.

Reworking the code to use FsContext2 immediately solved the crashes.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

“Maxim S. Shatskih” wrote in message news:xxxxx@ntdev…

I remember having a driver which has neither Cc interface nor mmaped file
support, but was using FsContext.
There were some crashes due to Mm assuming any file with non-NULL FsContext
to contain the FCB header.

I’d be curious to figure out how Mm found your file object in the first
place. A mystery lost in time at this point though I suppose.

-scott


Scott Noone
Consulting Associate and Chief System Problem Analyst
OSR Open Systems Resources, Inc.
http://www.osronline.com

> I’d be curious to figure out how Mm found your file object in the first

place. A mystery lost in time at this point though I suppose.

Yes, it was many years ago.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com