RES: How can I differ between two handles in my driver operations.

Thanks for all,

You’re right, I want maintain context between different
handles to my driver. And just clarifying, my driver is not a file
system filter. So it’s correct to affirm that:

  1. The FileObject pointer is valid on IRP_MJ_CREATE.

  2. I can STORE context information at FileObject->FsContext, for
    example:
    FileObject->FsContext = new MyContextStructure;

  3. I need release this context info at IRP_MJ_CLOSE.

Thanks in advance.
Fernando.

-----Mensagem original-----
De: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] Em nome de Anees M
Enviada em: sexta-feira, 1 de julho de 2005 09:40
Para: Windows System Software Devs Interest List
Assunto: Re: [ntdev] How can I differ between two handles in my driver
operations.

I think you can store some context information in
IO_STACK_LOCATION->FileObject->FsContext pointer when you get a
IRP_MJ_CREATE and then use this information in you other routines to
differentiate them.
On 7/1/05, Fernando Roberto wrote:
Hi all,

My question is very simple. If I have a driver and an
application gets a handle for it calling CreateFile API, my driver I
receive IRP_MJ_CREATE. But if the same application gets another handle
calling CreateFile API again, how can I differ between theses handles
when I receive IRP_MJ_READ for example?

Thanks in advance,
Fernando Roberto da Silva.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed
to ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a
blank email to xxxxx@lists.osr.com

Yes you can do that but only for create requests which are directly targeted
towards your drivers only. You should be careful in case if your driver is
some kind of filter and might encounter create requests for a driver which
is underneath you.
-Kiran


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Fernando Roberto
Sent: Friday, July 01, 2005 6:36 PM
To: Windows System Software Devs Interest List
Subject: RES: [ntdev] How can I differ between two handles in my driver
operations.

Thanks for all,

You’re right, I want maintain context between different handles
to my driver. And just clarifying, my driver is not a file system filter. So
it’s correct to affirm that:

  1. The FileObject pointer is valid on IRP_MJ_CREATE.

  2. I can STORE context information at FileObject->FsContext, for
    example:
    FileObject->FsContext = new MyContextStructure;

  3. I need release this context info at IRP_MJ_CLOSE.

Thanks in advance.
Fernando.

-----Mensagem original-----
De: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] Em nome de Anees M
Enviada em: sexta-feira, 1 de julho de 2005 09:40
Para: Windows System Software Devs Interest List
Assunto: Re: [ntdev] How can I differ between two handles in my driver
operations.

I think you can store some context information in
IO_STACK_LOCATION->FileObject->FsContext pointer when you get a
IRP_MJ_CREATE and then use this information in you other routines to
differentiate them.
On 7/1/05, Fernando Roberto wrote:
Hi all,

My question is very simple. If I have a driver and an
application gets a handle for it calling CreateFile API, my driver I receive
IRP_MJ_CREATE. But if the same application gets another handle calling
CreateFile API again, how can I differ between theses handles when I receive
IRP_MJ_READ for example?

Thanks in advance,
Fernando Roberto da Silva.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed to
ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email
to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Also realize that CreateFile is not the only way to create a handle;
DupHandle can also be used, but in that case while there are different
HANDLES they use the same file object. If the handle is set up to be
inherited, it will be duplicated between parent and child processes and
again will use the same file object.

Regards,

Tony

Tony Mason

Consulting Partner

OSR Open Systems Resources, Inc.

http://www.osr.com


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Fernando Roberto
Sent: Friday, July 01, 2005 9:06 AM
To: ntdev redirect
Subject: RES: [ntdev] How can I differ between two handles in my driver
operations.

Thanks for all,

You’re right, I want maintain context between different
handles to my driver. And just clarifying, my driver is not a file
system filter. So it’s correct to affirm that:

  1. The FileObject pointer is valid on IRP_MJ_CREATE.

  2. I can STORE context information at FileObject->FsContext, for
    example:

FileObject->FsContext = new MyContextStructure;

  1. I need release this context info at IRP_MJ_CLOSE.

Thanks in advance.

Fernando.

-----Mensagem original-----
De: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] Em nome de Anees M
Enviada em: sexta-feira, 1 de julho de 2005 09:40
Para: Windows System Software Devs Interest List
Assunto: Re: [ntdev] How can I differ between two handles in my driver
operations.

I think you can store some context information in
IO_STACK_LOCATION->FileObject->FsContext pointer when you get a
IRP_MJ_CREATE and then use this information in you other routines to
differentiate them.

On 7/1/05, Fernando Roberto wrote:

Hi all,

My question is very simple. If I have a driver and an
application gets a handle for it calling CreateFile API, my driver I
receive IRP_MJ_CREATE. But if the same application gets another handle
calling CreateFile API again, how can I differ between theses handles
when I receive IRP_MJ_READ for example?

Thanks in advance,

Fernando Roberto da Silva.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed
to ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a
blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Do not do this. Use ->FsContext2 instead. ->FsContext is for memory-mapped file support only.
Also note that filter drivers cannot use these fields - they belong to the functional driver.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: Anees M
To: Windows System Software Devs Interest List
Sent: Friday, July 01, 2005 4:40 PM
Subject: Re: [ntdev] How can I differ between two handles in my driver operations.

I think you can store some context information in IO_STACK_LOCATION->FileObject->FsContext pointer when you get a IRP_MJ_CREATE and then use this information in you other routines to differentiate them.

On 7/1/05, Fernando Roberto wrote:
Hi all,

My question is very simple. If I have a driver and an application gets a handle for it calling CreateFile API, my driver I receive IRP_MJ_CREATE. But if the same application gets another handle calling CreateFile API again, how can I differ between theses handles when I receive IRP_MJ_READ for example?

Thanks in advance,

Fernando Roberto da Silva.


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email to xxxxx@lists.osr.com

Wouldn’t FsContext usage for memory mapped files only be found on fileobjects which are backed by an FS? I don’t think you can create a memory mapped file from a device interface path.

d


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Friday, July 01, 2005 2:43 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can I differ between two handles in my driver operations.

??? Do not do this. Use ->FsContext2 instead. ->FsContext is for memory-mapped file support only.
??? Also note that filter drivers cannot use these fields - they belong to the functional driver.
?
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: Anees M
To: Windows System Software Devs Interest List
Sent: Friday, July 01, 2005 4:40 PM
Subject: Re: [ntdev] How can I differ between two handles in my driver operations.

I think you can store some context information in IO_STACK_LOCATION->FileObject->FsContext pointer when you get a IRP_MJ_CREATE and then use this information in you other routines to differentiate them.
On 7/1/05, Fernando Roberto wrote:
Hi all,
?
??? My question is very simple. If I have a driver and an application gets a handle for it calling CreateFile API, my driver I receive IRP_MJ_CREATE. But if the same application gets another handle calling CreateFile API again, how can I differ between theses handles when I receive IRP_MJ_READ for example?
?
Thanks in advance,
Fernando Roberto da Silva.


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Once I used ->FsContext in some driver of my own, not related to FSDs and
FSFs. I had BSODs due to Mm assuming that the structure are ->FsContext is
FSRTL_COMMON_FCB_HEADER.

Since that times, I never use ->FsContext for my custom structures anymore.

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

----- Original Message -----
From: “Doron Holan”
To: “Windows System Software Devs Interest List”
Sent: Saturday, July 02, 2005 1:59 AM
Subject: RE: [ntdev] How can I differ between two handles in my driver
operations.

Wouldn’t FsContext usage for memory mapped files only be found on fileobjects
which are backed by an FS? I don’t think you can create a memory mapped file
from a device interface path.

d

________________________________________
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Friday, July 01, 2005 2:43 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can I differ between two handles in my driver
operations.

Do not do this. Use ->FsContext2 instead. ->FsContext is for memory-mapped file
support only.
Also note that filter drivers cannot use these fields - they belong to the
functional driver.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: Anees M
To: Windows System Software Devs Interest List
Sent: Friday, July 01, 2005 4:40 PM
Subject: Re: [ntdev] How can I differ between two handles in my driver
operations.

I think you can store some context information in
IO_STACK_LOCATION->FileObject->FsContext pointer when you get a IRP_MJ_CREATE
and then use this information in you other routines to differentiate them.
On 7/1/05, Fernando Roberto wrote:
Hi all,

My question is very simple. If I have a driver and an application gets a handle
for it calling CreateFile API, my driver I receive IRP_MJ_CREATE. But if the
same application gets another handle calling CreateFile API again, how can I
differ between theses handles when I receive IRP_MJ_READ for example?

Thanks in advance,
Fernando Roberto da Silva.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed to
ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email to
xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Oi, Fernando,

This is all too complicated and may backfire on occasion. I
would just have the driver create multiple devices, or better, I
would register multiple interfaces with multiple GUIDs, and make
sure to only allow one open per interface. Something as easy as
a static member variable in the user side would suffice, bump it
every time a file gets opened, decrement it every time the
handle is closed, and use its current value to index into a
driver-supplied array of Devices or Interfaces. It’s very easy
for the app to get the array through an IoControl and to keep
track of the next available array item. With a little bit of
design, you might even be able to dynamically create new Devices
or Interfaces as need arises, and notify your app through a
shared event or semaphore.

I find it not a very good idea to burden a driver with user-side
considerations, and I feel this is more of an app issue than a
driver one. It can be solved through a healthy ring 3 design
strategy and a couple of bells and whistles here and there !

Abracos from New Hampshire,

Alberto.

----- Original Message -----
From: “Maxim S. Shatskih”
To: “Windows System Software Devs Interest List”

Sent: Saturday, July 02, 2005 7:24 AM
Subject: Re: [ntdev] How can I differ between two handles in my
driver operations.

> Once I used ->FsContext in some driver of my own, not
> related to FSDs and
> FSFs. I had BSODs due to Mm assuming that the structure
> are ->FsContext is
> FSRTL_COMMON_FCB_HEADER.
>
> Since that times, I never use ->FsContext for my custom
> structures anymore.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From: “Doron Holan”
> To: “Windows System Software Devs Interest List”
>
> Sent: Saturday, July 02, 2005 1:59 AM
> Subject: RE: [ntdev] How can I differ between two handles in
> my driver
> operations.
>
>
> Wouldn’t FsContext usage for memory mapped files only be found
> on fileobjects
> which are backed by an FS? I don’t think you can create a
> memory mapped file
> from a device interface path.
>
> d
>
> ________________________________________
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Maxim
> S. Shatskih
> Sent: Friday, July 01, 2005 2:43 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] How can I differ between two handles in
> my driver
> operations.
>
> Do not do this. Use ->FsContext2 instead. ->FsContext is for
> memory-mapped file
> support only.
> Also note that filter drivers cannot use these fields - they
> belong to the
> functional driver.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
> ----- Original Message -----
> From: Anees M
> To: Windows System Software Devs Interest List
> Sent: Friday, July 01, 2005 4:40 PM
> Subject: Re: [ntdev] How can I differ between two handles in
> my driver
> operations.
>
> I think you can store some context information in
> IO_STACK_LOCATION->FileObject->FsContext pointer when you get
> a IRP_MJ_CREATE
> and then use this information in you other routines to
> differentiate them.
> On 7/1/05, Fernando Roberto wrote:
> Hi all,
>
> My question is very simple. If I have a driver and an
> application gets a handle
> for it calling CreateFile API, my driver I receive
> IRP_MJ_CREATE. But if the
> same application gets another handle calling CreateFile API
> again, how can I
> differ between theses handles when I receive IRP_MJ_READ for
> example?
>
> Thanks in advance,
> Fernando Roberto da Silva.
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
> — Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256 You are currently
> subscribed to
> ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send
> a blank email to
> xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@ieee.org
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com

Friends,
From Windows DDK (FILE_OBJECT)

"
PVOID FsContext
Pointer to whatever optional state a driver maintains about the file object; otherwise, NULL.

PVOID FsContext2
Pointer to whatever additional state a driver maintains about the file object; otherwise, NULL.

Comments
Drivers can use the FsContext fields to maintain driver-determined state about an open file object. A driver cannot use these fields of a file object unless it is accessible in the driver’s I/O stack location of an IRP.

The remaining fields in a file object are opaque. They are reserved for use by the I/O Manager and file systems.
"

This documentation doesn’t make any restriction between these pointers. And just clarifying, my driver is not a FSD filter.

Thanks,
Fernando Roberto da Silva.

P.S.: Grande abra?o from Brazil Alberto.

-----Mensagem original-----
De: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] Em nome de Maxim S. Shatskih
Enviada em: s?bado, 2 de julho de 2005 08:24
Para: Windows System Software Devs Interest List
Assunto: Re: [ntdev] How can I differ between two handles in my driver operations.

Once I used ->FsContext in some driver of my own, not related to FSDs and
FSFs. I had BSODs due to Mm assuming that the structure are ->FsContext is
FSRTL_COMMON_FCB_HEADER.

Since that times, I never use ->FsContext for my custom structures anymore.

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

----- Original Message -----
From: “Doron Holan”
To: “Windows System Software Devs Interest List”
Sent: Saturday, July 02, 2005 1:59 AM
Subject: RE: [ntdev] How can I differ between two handles in my driver
operations.

Wouldn’t FsContext usage for memory mapped files only be found on fileobjects
which are backed by an FS? I don’t think you can create a memory mapped file
from a device interface path.

d

________________________________________
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Friday, July 01, 2005 2:43 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can I differ between two handles in my driver
operations.

Do not do this. Use ->FsContext2 instead. ->FsContext is for memory-mapped file
support only.
Also note that filter drivers cannot use these fields - they belong to the
functional driver.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: Anees M
To: Windows System Software Devs Interest List
Sent: Friday, July 01, 2005 4:40 PM
Subject: Re: [ntdev] How can I differ between two handles in my driver
operations.

I think you can store some context information in
IO_STACK_LOCATION->FileObject->FsContext pointer when you get a IRP_MJ_CREATE
and then use this information in you other routines to differentiate them.
On 7/1/05, Fernando Roberto wrote:
Hi all,

My question is very simple. If I have a driver and an application gets a handle
for it calling CreateFile API, my driver I receive IRP_MJ_CREATE. But if the
same application gets another handle calling CreateFile API again, how can I
differ between theses handles when I receive IRP_MJ_READ for example?

Thanks in advance,
Fernando Roberto da Silva.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed to
ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email to
xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@opencs.com.br
To unsubscribe send a blank email to xxxxx@lists.osr.com

Maybe, but for me, practice was different.

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

----- Original Message -----
From: “Fernando Roberto”
To: “Windows System Software Devs Interest List”
Sent: Saturday, July 02, 2005 5:54 PM
Subject: RES: [ntdev] How can I differ between two handles in my driver
operations.

Friends,
From Windows DDK (FILE_OBJECT)


PVOID FsContext
Pointer to whatever optional state a driver maintains about the file object;
otherwise, NULL.

PVOID FsContext2
Pointer to whatever additional state a driver maintains about the file object;
otherwise, NULL.



Comments
Drivers can use the FsContext fields to maintain driver-determined state about
an open file object. A driver cannot use these fields of a file object unless
it is accessible in the driver’s I/O stack location of an IRP.

The remaining fields in a file object are opaque. They are reserved for use by
the I/O Manager and file systems.


This documentation doesn’t make any restriction between these pointers. And
just clarifying, my driver is not a FSD filter.

Thanks,
Fernando Roberto da Silva.

P.S.: Grande abraço from Brazil Alberto.

-----Mensagem original-----
De: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] Em nome de Maxim S. Shatskih
Enviada em: sábado, 2 de julho de 2005 08:24
Para: Windows System Software Devs Interest List
Assunto: Re: [ntdev] How can I differ between two handles in my driver
operations.

Once I used ->FsContext in some driver of my own, not related to FSDs and
FSFs. I had BSODs due to Mm assuming that the structure are ->FsContext is
FSRTL_COMMON_FCB_HEADER.

Since that times, I never use ->FsContext for my custom structures anymore.

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

----- Original Message -----
From: “Doron Holan”
To: “Windows System Software Devs Interest List”
Sent: Saturday, July 02, 2005 1:59 AM
Subject: RE: [ntdev] How can I differ between two handles in my driver
operations.

Wouldn’t FsContext usage for memory mapped files only be found on fileobjects
which are backed by an FS? I don’t think you can create a memory mapped file
from a device interface path.

d

________________________________________
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Friday, July 01, 2005 2:43 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can I differ between two handles in my driver
operations.

Do not do this. Use ->FsContext2 instead. ->FsContext is for memory-mapped file
support only.
Also note that filter drivers cannot use these fields - they belong to the
functional driver.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: Anees M
To: Windows System Software Devs Interest List
Sent: Friday, July 01, 2005 4:40 PM
Subject: Re: [ntdev] How can I differ between two handles in my driver
operations.

I think you can store some context information in
IO_STACK_LOCATION->FileObject->FsContext pointer when you get a IRP_MJ_CREATE
and then use this information in you other routines to differentiate them.
On 7/1/05, Fernando Roberto wrote:
Hi all,

My question is very simple. If I have a driver and an application gets a handle
for it calling CreateFile API, my driver I receive IRP_MJ_CREATE. But if the
same application gets another handle calling CreateFile API again, how can I
differ between theses handles when I receive IRP_MJ_READ for example?

Thanks in advance,
Fernando Roberto da Silva.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

— Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed to
ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send a blank email to
xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@opencs.com.br
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

I realize that in your world following existing design patterns makes
you a spineless yes-man. But how in the world is this “simpler” than
stashing a context pointer in one of the locations the OS provides for
exactly this purpose?

* Create comes in - allocate a context and stash it in the file object
* Read comes in - grab the context from the file object and you know
what connection it is
* Close comes in - free the context

This seems much easier and safer than sharing globals between the driver
and app.

I’ll agree that it’s a bad idea to burden your driver with user-side
considerations. This does not sound like such a case to me -
maintaining connection state is a pretty standard driver-side task.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Alberto Moreira
Sent: Saturday, July 02, 2005 6:09 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How can I differ between two handles in my driver
operations.

Oi, Fernando,

This is all too complicated and may backfire on occasion. I would just
have the driver create multiple devices, or better, I would register
multiple interfaces with multiple GUIDs, and make sure to only allow one
open per interface. Something as easy as a static member variable in the
user side would suffice, bump it every time a file gets opened,
decrement it every time the handle is closed, and use its current value
to index into a driver-supplied array of Devices or Interfaces. It’s
very easy for the app to get the array through an IoControl and to keep
track of the next available array item. With a little bit of design, you
might even be able to dynamically create new Devices or Interfaces as
need arises, and notify your app through a shared event or semaphore.

I find it not a very good idea to burden a driver with user-side
considerations, and I feel this is more of an app issue than a driver
one. It can be solved through a healthy ring 3 design strategy and a
couple of bells and whistles here and there !

Abracos from New Hampshire,

Alberto.

----- Original Message -----
From: “Maxim S. Shatskih”
To: “Windows System Software Devs Interest List”

Sent: Saturday, July 02, 2005 7:24 AM
Subject: Re: [ntdev] How can I differ between two handles in my driver
operations.

> Once I used ->FsContext in some driver of my own, not related to
> FSDs and FSFs. I had BSODs due to Mm assuming that the structure are
> ->FsContext is FSRTL_COMMON_FCB_HEADER.
>
> Since that times, I never use ->FsContext for my custom structures
> anymore.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From: “Doron Holan”
> To: “Windows System Software Devs Interest List”
>
> Sent: Saturday, July 02, 2005 1:59 AM
> Subject: RE: [ntdev] How can I differ between two handles in my driver

> operations.
>
>
> Wouldn’t FsContext usage for memory mapped files only be found on
> fileobjects which are backed by an FS? I don’t think you can create a

> memory mapped file from a device interface path.
>
> d
>
> ________________________________________
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Maxim
> S. Shatskih
> Sent: Friday, July 01, 2005 2:43 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] How can I differ between two handles in
> my driver
> operations.
>
> Do not do this. Use ->FsContext2 instead. ->FsContext is for
> memory-mapped file
> support only.
> Also note that filter drivers cannot use these fields - they
> belong to the
> functional driver.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
> ----- Original Message -----
> From: Anees M
> To: Windows System Software Devs Interest List
> Sent: Friday, July 01, 2005 4:40 PM
> Subject: Re: [ntdev] How can I differ between two handles in
> my driver
> operations.
>
> I think you can store some context information in
> IO_STACK_LOCATION->FileObject->FsContext pointer when you get
> a IRP_MJ_CREATE
> and then use this information in you other routines to
> differentiate them.
> On 7/1/05, Fernando Roberto wrote:
> Hi all,
>
> My question is very simple. If I have a driver and an
> application gets a handle
> for it calling CreateFile API, my driver I receive
> IRP_MJ_CREATE. But if the
> same application gets another handle calling CreateFile API
> again, how can I
> differ between theses handles when I receive IRP_MJ_READ for
> example?
>
> Thanks in advance,
> Fernando Roberto da Silva.
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
> — Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256 You are currently
> subscribed to
> ntdev as: unknown lmsubst tag argument: ‘’ To unsubscribe send
> a blank email to
> xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@ieee.org
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com