FsContext in FILE_OBJECT

Hi all,

I need to keep some info. about the fileobject. So I am trying to make use
of the FsContext field in the FILE_OBJECT. I keep the info in FsContext
field by allocating some memory from the nonpaged pool in IRP_MJ_CREATe.
But when I try to free the memory, in IRP_MJ_CLOSE, it crashes.

Why is this happening? Am I doing things in the right way?

Regards.

Use FsContext2 instead.

FsContext is suggested to point to common FCB header. If it is not
so - then you will have BSODs if any MM function will be called on the
file.

Max

----- Original Message -----
From:
To: “NT Developers Interest List”
Sent: Tuesday, June 11, 2002 1:33 PM
Subject: [ntdev] FsContext in FILE_OBJECT

> Hi all,
>
> I need to keep some info. about the fileobject. So I am trying to
make use
> of the FsContext field in the FILE_OBJECT. I keep the info in
FsContext
> field by allocating some memory from the nonpaged pool in
IRP_MJ_CREATe.
> But when I try to free the memory, in IRP_MJ_CLOSE, it crashes.
>
> Why is this happening? Am I doing things in the right way?
>
> Regards.
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to %%email.unsub%%
>

Unless you are an FSD, you can not easily use this field in the
fileobject. The underlying FSD will use it and thus overwrite your
value.

Pete

Peter Scott
xxxxx@KernelDrivers.com
http://www.KernelDrivers.com

>-----Original Message-----
>From: xxxxx@lists.osr.com [mailto:bounce-ntdev-
>xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
>Sent: Tuesday, June 11, 2002 3:34 AM
>To: NT Developers Interest List
>Subject: [ntdev] FsContext in FILE_OBJECT
>
>Hi all,
>
>I need to keep some info. about the fileobject. So I am trying to make
use
>of the FsContext field in the FILE_OBJECT. I keep the info in
FsContext
>field by allocating some memory from the nonpaged pool in
IRP_MJ_CREATe.
>But when I try to free the memory, in IRP_MJ_CLOSE, it crashes.
>
>Why is this happening? Am I doing things in the right way?
>
>Regards.
>
>—
>You are currently subscribed to ntdev as: xxxxx@KernelDrivers.com
>To unsubscribe send a blank email to %%email.unsub%%

actually the file system often uses FsContext2 as well so if there’s a
file system involved that isn’t safe either.

what kind of driver are you writing? Is it a storage driver or
something else (storage is “special” when it comes to file objects and
creates and whatnot)

-p

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Thursday, June 13, 2002 12:11 AM
To: NT Developers Interest List
Subject: [ntdev] Re: FsContext in FILE_OBJECT

Use FsContext2 instead.

FsContext is suggested to point to common FCB header. If it is not so -
then you will have BSODs if any MM function will be called on the file.

Max

----- Original Message -----
From:
To: “NT Developers Interest List”
Sent: Tuesday, June 11, 2002 1:33 PM
Subject: [ntdev] FsContext in FILE_OBJECT

> Hi all,
>
> I need to keep some info. about the fileobject. So I am trying to
make use
> of the FsContext field in the FILE_OBJECT. I keep the info in
FsContext
> field by allocating some memory from the nonpaged pool in
IRP_MJ_CREATe.
> But when I try to free the memory, in IRP_MJ_CLOSE, it crashes.
>
> Why is this happening? Am I doing things in the right way?
>
> Regards.
>
> —
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com To
> unsubscribe send a blank email to %%email.unsub%%
>


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to %%email.unsub%%

If you are not an FSD, you still cannot use the FsContext2 easily. Even
Fat uses the FsContext2 as its store location for the Ccb.

Pete

Peter Scott
xxxxx@KernelDrivers.com
http://www.KernelDrivers.com

>-----Original Message-----
>From: xxxxx@lists.osr.com [mailto:bounce-ntdev-
>xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
>Sent: Thursday, June 13, 2002 1:11 AM
>To: NT Developers Interest List
>Subject: [ntdev] Re: FsContext in FILE_OBJECT
>
>Use FsContext2 instead.
>
>FsContext is suggested to point to common FCB header. If it is not
>so - then you will have BSODs if any MM function will be called on the
>file.
>
> Max
>
>----- Original Message -----
>From:
>>To: “NT Developers Interest List”
>>Sent: Tuesday, June 11, 2002 1:33 PM
>>Subject: [ntdev] FsContext in FILE_OBJECT
>>
>>
>>> Hi all,
>>>
>>> I need to keep some info. about the fileobject. So I am trying to
>>make use
>>> of the FsContext field in the FILE_OBJECT. I keep the info in
>>FsContext
>>> field by allocating some memory from the nonpaged pool in
>>IRP_MJ_CREATe.
>>> But when I try to free the memory, in IRP_MJ_CLOSE, it crashes.
>>>
>>> Why is this happening? Am I doing things in the right way?
>>>
>>> Regards.
>>>
>>> —
>>> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
>>> To unsubscribe send a blank email to %%email.unsub%%
>>>
>>
>>
>>—
>>You are currently subscribed to ntdev as: xxxxx@KernelDrivers.com
>>To unsubscribe send a blank email to %%email.unsub%%

The general strategy for drivers above the filesystem is to build a mapping
database where you plug in FsContext and get back whatever private data you
needed.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Peter Scott
Sent: Thursday, June 13, 2002 1:19 PM
To: NT Developers Interest List
Subject: [ntdev] Re: FsContext in FILE_OBJECT

If you are not an FSD, you still cannot use the FsContext2
easily. Even Fat uses the FsContext2 as its store location
for the Ccb.

Pete

Peter Scott
xxxxx@KernelDrivers.com
http://www.KernelDrivers.com

>>-----Original Message-----
>>From: xxxxx@lists.osr.com [mailto:bounce-ntdev-
>>xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
>>Sent: Thursday, June 13, 2002 1:11 AM
>>To: NT Developers Interest List
>>Subject: [ntdev] Re: FsContext in FILE_OBJECT
>>
>>Use FsContext2 instead.
>>
>>FsContext is suggested to point to common FCB header. If it
is not so
>>- then you will have BSODs if any MM function will be called on the
>>file.
>>
>> Max
>>
>>----- Original Message -----
>>From:
> >>To: “NT Developers Interest List”
> >>Sent: Tuesday, June 11, 2002 1:33 PM
> >>Subject: [ntdev] FsContext in FILE_OBJECT
> >>
> >>
> >>> Hi all,
> >>>
> >>> I need to keep some info. about the fileobject. So I am trying to
> >>make use
> >>> of the FsContext field in the FILE_OBJECT. I keep the info in
> >>FsContext
> >>> field by allocating some memory from the nonpaged pool in
> >>IRP_MJ_CREATe.
> >>> But when I try to free the memory, in IRP_MJ_CLOSE, it crashes.
> >>>
> >>> Why is this happening? Am I doing things in the right way?
> >>>
> >>> Regards.
> >>>
> >>> —
> >>> You are currently subscribed to ntdev as:
> xxxxx@storagecraft.com To
> >>> unsubscribe send a blank email to %%email.unsub%%
> >>>
> >>
> >>
> >>—
> >>You are currently subscribed to ntdev as:
> xxxxx@KernelDrivers.com To
> >>unsubscribe send a blank email to %%email.unsub%%
>
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@hollistech.com To unsubscribe send a blank email to
> %%email.unsub%%
>
>

>actually the file system often uses FsContext2 as well so if there’s
a

file system involved that isn’t safe either.

For FS filters - yes.

For standalone non-FS drivers which want to have per-file context -
FsContext2 is fine, while FsContext causes BSOD - the OS assumes that
FsContext points to common FCB header.

Strange a bit since I cannot understand who can try to memory-map or
cache-map my driver’s file :slight_smile:

Max

If you are writing for XP only, then the OS finally supports a query to see
if a file was flagged during create as being of interest to your driver. I
would write using that logic and for non-XP systems, have a function to
return the same information. This is a good reason for overloading even if
it is a home grown implementation.

----- Original Message -----
From: “Roddy, Mark”
To: “NT Developers Interest List”
Sent: Friday, June 14, 2002 7:54 AM
Subject: [ntdev] Re: FsContext in FILE_OBJECT

> The general strategy for drivers above the filesystem is to build a
mapping
> database where you plug in FsContext and get back whatever private data
you
> needed.
>
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Peter Scott
> > Sent: Thursday, June 13, 2002 1:19 PM
> > To: NT Developers Interest List
> > Subject: [ntdev] Re: FsContext in FILE_OBJECT
> >
> >
> >
> > If you are not an FSD, you still cannot use the FsContext2
> > easily. Even Fat uses the FsContext2 as its store location
> > for the Ccb.
> >
> > Pete
> >
> > Peter Scott
> > xxxxx@KernelDrivers.com
> > http://www.KernelDrivers.com
> >
> >
> > >>-----Original Message-----
> > >>From: xxxxx@lists.osr.com [mailto:bounce-ntdev-
> > >>xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
> > >>Sent: Thursday, June 13, 2002 1:11 AM
> > >>To: NT Developers Interest List
> > >>Subject: [ntdev] Re: FsContext in FILE_OBJECT
> > >>
> > >>Use FsContext2 instead.
> > >>
> > >>FsContext is suggested to point to common FCB header. If it
> > is not so
> > >>- then you will have BSODs if any MM function will be called on the
> > >>file.
> > >>
> > >> Max
> > >>
> > >>----- Original Message -----
> > >>From:
> > >>To: “NT Developers Interest List”
> > >>Sent: Tuesday, June 11, 2002 1:33 PM
> > >>Subject: [ntdev] FsContext in FILE_OBJECT
> > >>
> > >>
> > >>> Hi all,
> > >>>
> > >>> I need to keep some info. about the fileobject. So I am trying to
> > >>make use
> > >>> of the FsContext field in the FILE_OBJECT. I keep the info in
> > >>FsContext
> > >>> field by allocating some memory from the nonpaged pool in
> > >>IRP_MJ_CREATe.
> > >>> But when I try to free the memory, in IRP_MJ_CLOSE, it crashes.
> > >>>
> > >>> Why is this happening? Am I doing things in the right way?
> > >>>
> > >>> Regards.
> > >>>
> > >>> —
> > >>> You are currently subscribed to ntdev as:
> > xxxxx@storagecraft.com To
> > >>> unsubscribe send a blank email to %%email.unsub%%
> > >>>
> > >>
> > >>
> > >>—
> > >>You are currently subscribed to ntdev as:
> > xxxxx@KernelDrivers.com To
> > >>unsubscribe send a blank email to %%email.unsub%%
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as:
> > xxxxx@hollistech.com To unsubscribe send a blank email to
> > %%email.unsub%%
> >
> >
>
> —
> You are currently subscribed to ntdev as: xxxxx@yoshimuni.com
> To unsubscribe send a blank email to %%email.unsub%%