2

Let's sketch the picture.

Windows provides SCSI port (bus) driver. Driver creates FDO for bus (FILE_DEVICE_BUS_EXTENDER) and PDO for each device connected to bus (FILE_DEVICE_MASS_STORAGE). We "connect" mass storage devices to bus device inside PnP request handler.

Windows also provides class driver (for each device class) that is layered on top of port driver. It forms device stack with FDO on top of PDO for each child device.

Class driver sends internal ioctls to port driver; major function code is IRP_MJ_SCSI, minor function code is IRP_MN_SCSI_CLASS, SCSI_REQUEST_BLOCK structure is filled in with request-specific information.

Port driver handles the communication with the device (move data from SRB to device/move data from device to SRB) and completes the request.

Now imagine we want to emulate scsi device. We need to develop "virtual SCSI port (bus)" driver. This driver will create FDO for bus (FILE_DEVICE_BUS_EXTENDER) and PDO for each device that we will create (FILE_DEVICE_MASS_STORAGE). We will handle internal ioctls, do irp queue management, move data to/from SRB, etc.

I want to understand what "condition" must be met in order to make Windows "think" that SCSI device is real (so that it will appear inside explorer, etc). Will class driver automatically send internal ioctls as soon as we create device or we need to emulate these requests either?

My questions might be silly but I need to grasp whats going on to understand more. Thank you for your help.

igntec
  • 1,006
  • 10
  • 24

1 Answers1

1

So it seems simple.

IRP_MN_QUERY_DEVICE_RELATIONS request (sent to bus FDO) handler "connects" child PDO to bus FDO.

IRP_MN_QUERY_ID request (sent to child PDO) handler reports device identifiers, including device type. See https://learn.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-scsi-devices

Now Windows can select appropriate class driver to put it on top. So the stack will look like this:

{User App}

[File System Driver]

[Class Driver]

[Bus Driver]

{Physical/Virtual Device}

Then class driver will send internal ioctls to our bus driver. We still can send this ioctl by ourselves, e.g. bypass class driver. See IOCTL_SCSI_PASS_THROUGH and IOCTL_SCSI_PASS_THROUGH_DIRECT control codes docs; it makes it clear that we can bypass class driver.

igntec
  • 1,006
  • 10
  • 24