Search code examples
windowsdevice-driverwdk

Keeping data per open instance of a device


In a Windows device driver:

  • per-driver information is stored in global variables
  • per-device information is stored in the DEVICE_OBJECT.DeviceExtension

As far as I understand, a CreateFile constructs a FILE_OBJECT in the kernel space, so each open instance of a device has its own FILE_OBJECT. If so, can I keep my per-instance information in the IO_STACK_LOCATION.FileObject.FsContext field?


Solution

  • Reading the FsContext discription of the MSDN page says yes for FDOs and no for other types of drivers.

    NB: Do you implement your own IRP_MJ_CREATE function? If yes, you may use the member, due to you being the creator of the file object.