Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


Kernel mode driver: How do I know who issued a CreateFile() ?

OSR_Community_UserOSR_Community_User Member Posts: 110,217
Hi!

I'm writing a small driver, and I have a problem:

I'm holding a buffer inside the driver, and I want multiple
clients to be using it. Every time a client issues a read
operation (ReadFile) - I want to give him the data from were he
stopped-getting
it the last time.

For this purpose, I wrote an interface for a buffer that
holds 1 "writing" pointer, and 'n' "reading" pointers - one for each
of the n clients.

The problem: How do I associate a read request with a client?
In other words: How do I know which pointer is associated with
which client?

thanks in advance,

- Barak



--
----------------------------------------------------
Barak Mandelovich Mercury Interactive ltd.
[email protected] 19 Shabazi st.
Tel: +972 3 539 9286 Yehud, 56100
Fax: +972 3 533 1617 Israel
----------------------------------------------------

Comments

  • Don_Burn_1Don_Burn_1 Member Posts: 4,311
    Barak,

    I assume a client is defined by a process. If so use
    PsGetCurrentProcess()
    to get the process of the caller of the dispatch routine, ie the read, write
    or create.
    Note: that if someone places a filter driver above your driver, they could
    cause
    problems with this approach.

    Don Burn

    ----- Original Message -----
    From: "Barak Mandelovich" <[email protected]>
    To: "NT Developers Interest List" <[email protected]>
    Sent: Sunday, March 19, 2000 11:24 AM
    Subject: [ntdev] Kernel mode driver: How do I know who issued a CreateFile()
    ?


    > Hi!
    >
    > I'm writing a small driver, and I have a problem:
    >
    > I'm holding a buffer inside the driver, and I want multiple
    > clients to be using it. Every time a client issues a read
    > operation (ReadFile) - I want to give him the data from were he
    > stopped-getting
    > it the last time.
    >
    > For this purpose, I wrote an interface for a buffer that
    > holds 1 "writing" pointer, and 'n' "reading" pointers - one for each
    > of the n clients.
    >
    > The problem: How do I associate a read request with a client?
    > In other words: How do I know which pointer is associated with
    > which client?
    >
    > thanks in advance,
    >
    > - Barak
    >
    >
    >
    > --
    > ----------------------------------------------------
    > Barak Mandelovich Mercury Interactive ltd.
    > [email protected] 19 Shabazi st.
    > Tel: +972 3 539 9286 Yehud, 56100
    > Fax: +972 3 533 1617 Israel
    > ----------------------------------------------------
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    From: "Barak Mandelovich" <[email protected]>
    Sent: Sunday, March 19, 2000 11:24 AM


    > Hi!
    >
    > I'm writing a small driver, and I have a problem:
    >
    > I'm holding a buffer inside the driver, and I want multiple
    > clients to be using it. Every time a client issues a read
    > operation (ReadFile) - I want to give him the data from were he
    > stopped-getting
    > it the last time.
    >
    > For this purpose, I wrote an interface for a buffer that
    > holds 1 "writing" pointer, and 'n' "reading" pointers - one for each
    > of the n clients.
    >
    > The problem: How do I associate a read request with a client?
    > In other words: How do I know which pointer is associated with
    > which client?

    Generally, each request processed by a driver comes with a FILE_OBJECT
    pointed to by the 'FileObject' member of your driver's IO_STACK_LOCATION.
    Each FILE_OBJECT, in a sense, represents "one" client of your driver.

    During each client's IRP_MJ_CREATE, you can store a pointer to a per-client
    data structure in the associated FILE_OBJECT's 'FsContext' or 'FsContext2'
    fields. Then, when each client calls back (during some other IRP_xxx), you
    can retrieve the client data struct from the FILE_OBJECT.

    When you process IRP_MJ_CLOSE for a particular client, you can likewise free
    the data structure for that client.

    In any case, you can now store the state of each client's "read" and "write"
    pointers in the associated data client structure and update it on each read
    or write request from that client.


    Regards,

    Matt Arnold
    Professional Music Products
    Mark of the Unicorn, Inc.
    http://www.motu.com

    To obtain my real address, please replace "biteme" with "motu". My use of a
    fake address is an anti-spam tactic. Sorry for the inconvenience.
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    > The problem: How do I associate a read request with a client?
    > In other words: How do I know which pointer is associated with
    > which client?

    Use one of the "get current process/thread" functions in IRP_MJ_CREATE
    path.

    Max
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 January 2023 Live, Online
Developing Minifilters 20 March 2023 Live, Online
Internals & Software Drivers 17 April 2023 Live, Online
Writing WDF Drivers 22 May 2023 Live, Online