Develop my own USBSTOR driver

Hi,
Nice to talk to you, every expert.

These days, I am developing my own USBSTOR driver, which will replace the Windows native USBSTOR.sys.
Two methods:
1st. filter driver
2nd. bus driver + disk.sys(for the LUN PDO)

I have the following questions:
For filter driver case:

disk.sys
|
usbstor.sys
|
usbhub.sys
|
usbehci.sys
|
P C I Bus
|
Hardware


  1. I develop a filter driver, which will hook the SRBs, when I install this filter driver as lower filter driver of disk.sys, the SRBs could be hooked in IRP_MJ_SCSI routin.
    but when I install this filter dirver as a upper filter driver of USBSTOR.sys, the SRBs could not hooked in IRP_MJ_SCSI, why?
    I think both filter driver(disk.sys lower ftiler and usbstor.sys upper filter) should hook the SRBs in their IRP_MJ_SCSI routin, because the IRPs is route from top to bottom.
  2. USBSTOR.SYS is the BOT(BULK ONLY transfer, two bulk pipe used) protocol driver for USB mass storage device, it must follow the “CBW->data(in or out)->CSW” sequence.
    But nowadsys, for USB3.0 mass storage device, there is a new protocol named UAS(USB attached SCSI, four bulk pipe used), which different from BOT, so the USBSTOR.sys could not used for UAS device.
    So I have the qeustion, if the filter method could be used for UAS device?
    I think compare to the second method “bus driver + disk driver(for LUN PDO)”, this method is more easy. Because you just need to deveop your own filter drivers, and don’t need to consider the creation of LUN PDO, loading the Disk.sys, and any other issues.
    But I am wonder, the USBSTOR.sys only process for BOT case, when the device is UAS, how to route the IRP receive by lower filter of Disk.sys or uppter filter of USBSTOR.sys to the lower filter of USBSTOR.sys, by pass the USBSTOR.sys? And in the lower filter of usbstor.sys I could do some thing compitable to UAS.
    If it is ok, so when the device is BOT, just let the IRPs route like the following:

disk.sys
|
lower filter of disk.sys or upper filter of usbstor.sys
|
usbstor.sys
|
lower filter of usbstor.sys
|
usbhub.sys
|
usbehci.sys
|
P C I Bus
|
Hardware


when the device is UAS, IRPs route like the following:

disk.sys
|
lower filter of disk.sys or upper filter of usbstor.sys
|
| (usbstor.sys is bypass)
|
lower filter of usbstor.sys
|
usbhub.sys
|
usbehci.sys
|
P C I Bus
|
Hardware


  1. I hear someone tell me, you should use upper filter driver of USBSTOR.SYS but not the lower filter driver of Disk.sys, his reason is that upper filter driver of USBSTOR.sys could queue the irps it received from upper level driver(in this case, the upper level driver is disk.sys, but I can not receive the IRP_MJ_SCSI from it, in question 1 ), but the lower filter driver of disk.sys could not queue the irps(while the lower filter driver of disk.sys could receive the IRP_MJ_SCSI from the upper level driver disk.sys)
    Is his reason right, and if both the fitler driver could receive the IRP_MJ_SCSI, which is more suitable?

For bus driver+ disk.sys driver(For LUN PDO)
In windows, the native driver USBSTOR.sys act as the software bus driver, it create the PDO for every LUN.
I get a sample driver, some body maybe familiar with it.
I have the followint questions:

  1. I use the Enum.exe to trigger the PDO creation, I want to know, when and where is correct to create the PDO for LUN? Pls give me the detail.
  2. after I create a PDO, Pnp manager send a series of IRPs such as device IDs, compatible IDs , text, location, and so on. Because I want to load the Disk.sys driver for this PDO, so I return the compatible ID “USBSTOR\Disk”, using this method, the pnp manager load the Disk.sys for this PDO(is this method right?), and the PDO is listed in the “Disk drive” category in the Device manager tool, but it with the exclemation, which means the driver load unsuccessfully.
    The bus driver print that: pnp start for the PDO, then the pnp remove for the PDO.
    Any one could tell me ,what should I do to make this driver load successfully?
  3. is this bus driver + disk.sys driver(for LUN PDO) method feasible for UAS driver?
    4.Ones the disk.sys driver is loaded successfully, I think ,the bus driver could receive the SRBs from the DISK.SYS in this bus driver IRP_MJ_SCSI routin, is it right?
  4. In fact, even though the disk.sys driver loading failed, but in the bus driver, I recevie a SRB SRB_FUNCTION_CLAIM_DEVICE, does it means, bus driver could receive the SRBs from the upper leverl disk.sys and what should I do for this SRB?

thank you,
Any suggestion is appreciated,
jeff

What problem are you really trying to solve?

What is your purpose for replacing USBSTOR?

What do you mean by “hook the SRBs”? Usually “hooking” refers to replacing
entry points directly, or detouring in the first instructions of the entry
points. SRB is just a data block. Do you mean that you want to record it?
Modify it?

Phil

Philip D. Barila (303) 776-1264

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of workingmailing
Sent: Wednesday, May 11, 2011 10:57 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Develop my own USBSTOR driver
Importance: High

Hi,

Nice to talk to you, every expert.

These days, I am developing my own USBSTOR driver, which will replace the
Windows native USBSTOR.sys.

Two methods:

1st. filter driver

2nd. bus driver + disk.sys(for the LUN PDO)

Thank you for your reply first.
—>What problem are you really trying to solve?
<—Develop my own USB storage port driver.
But I am not sure why the PDO load the Disk.sys, after pnp start, pnp remove come up with it?

—>What is your purpose for replacing USBSTOR?
<----USBSTOR is BOT, I want to develop UAS driver.

—>What do you mean by “hook the SRBs”? Usually “hooking” refers to replacing
entry points directly, or detouring in the first instructions of the entry
points. SRB is just a data block. Do you mean that you want to record it?
Modify it?
<—means that the IRP_MN_SCSI come to my UAS driver, then I can translate this SRBs to URBs.

> -----Original Message-----

From: xxxxx@lists.osr.com [mailto:bounce-453344-
xxxxx@lists.osr.com] On Behalf Of workingmailing@163.com
Sent: Thursday, May 12, 2011 7:27 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Develop my own USBSTOR driver

Thank you for your reply first.
—>What problem are you really trying to solve?
<—Develop my own USB storage port driver.

This is not the problem you are trying to solve. This is your solution to a
problem that this solution may or may not solve. What problem are you
trying to solve?

But I am not sure why the PDO load the Disk.sys, after pnp
start, pnp remove come up with it?

—>What is your purpose for replacing USBSTOR?
<----USBSTOR is BOT, I want to develop UAS driver.

This *may* almost be the answer to the previous question, what problem are
you trying to solve?

—>What do you mean by “hook the SRBs”? Usually “hooking” refers to
replacing
entry points directly, or detouring in the first instructions of
the entry
points. SRB is just a data block. Do you mean that you want to
record it?
Modify it?
<—means that the IRP_MN_SCSI come to my UAS driver, then I can
translate this SRBs to URBs.

OK, you’ve explained why you want to get the SRBs. Please answer the very
first question. What are you trying to solve?

An example: “USB BOT (Bulk Only Transport) doesn’t provide feature XYZ that
is defined in UAS (USB Attached SCSI), how can I provide support for feature
XYZ to [Application, OS, ???]?”

Once you have that statement, it’s possible that your proposed solution is
the right one, but possibly not.

Phil

Philip D. Barila (303) 776-1264

Philip D. Barila wrote:

What problem are you really trying to solve?

What is your purpose for replacing USBSTOR?

He’s trying to support a USB 3.0 mass storage device.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

workingmailing wrote:

These days, I am developing my own USBSTOR driver, which will replace
the Windows native USBSTOR.sys.
Two methods:
1st. filter driver
2nd. bus driver + disk.sys(for the LUN PDO)

I don’t see how a filter driver can solve your problem. Usbstor.sys
cannot handle your device, so you cannot allow any IRPs to flow through
it. I think you need to REPLACE usbstor.sys.

For bus driver+ disk.sys driver(For LUN PDO)
In windows, the native driver USBSTOR.sys act as the software bus
driver, it create the PDO for every LUN.
I get a sample driver, some body maybe familiar with it.
I have the followint questions:

  1. I use the Enum.exe to trigger the PDO creation, I want to know,
    when and where is correct to create the PDO for LUN? Pls give me the
    detail.

I told you this. Your driver should create the PDO(s) in AddDevice, as
soon as you know how many disks you have.

  1. after I create a PDO, Pnp manager send a series of IRPs such as
    device IDs, compatible IDs , text, location, and so on. Because I want
    to load the Disk.sys driver for this PDO, so I return the compatible
    ID “USBSTOR\Disk”, using this method, the pnp manager load the
    Disk.sys for this PDO(is this method right?), and the PDO is listed in
    the “Disk drive” category in the Device manager tool, but it with the
    exclemation, which means the driver load unsuccessfully.
    The bus driver print that: pnp start for the PDO, then the pnp remove
    for the PDO.
    Any one could tell me ,what should I do to make this driver load
    successfully?

This is probably because your driver is not responding like a disk
device. Disk.sys is going to send you disk requests, and you have to
respond like a disk.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Yeah I don’t think a filter will work here either. So perhaps the
correct route is the virtual storport model with a usb lower edge - a
hybrid virtual storport/usb function driver, similar conceptually to
the msiscsi driver.

Mark Roddy

On Thu, May 12, 2011 at 12:22 PM, Tim Roberts wrote:
> workingmailing wrote:
>>
>> These days, I am developing my own USBSTOR driver, which will replace
>> the Windows native USBSTOR.sys.
>> Two methods:
>> 1st. filter driver
>> 2nd. bus driver + disk.sys(for the LUN PDO)
>
> I don’t see how a filter driver can solve your problem. ?Usbstor.sys
> cannot handle your device, so you cannot allow any IRPs to flow through
> it. ?I think you need to REPLACE usbstor.sys.
>
>> For bus driver+ disk.sys driver(For LUN PDO)
>> In windows, the native driver USBSTOR.sys act as the software bus
>> driver, it create the PDO for every LUN.
>> I get a sample driver, some body maybe familiar with it.
>> I have the followint questions:
>> 1. I use the Enum.exe to trigger the PDO creation, I want to know,
>> when and where is correct to create the PDO for LUN? Pls give me the
>> detail.
>
> I told you this. ?Your driver should create the PDO(s) in AddDevice, as
> soon as you know how many disks you have.
>
>> 2. after I create a PDO, Pnp manager send a series of IRPs such as
>> device IDs, compatible IDs , text, location, and so on. Because I want
>> to load the Disk.sys driver for this PDO, so I return the compatible
>> ID “USBSTOR\Disk”, using this method, the pnp manager load the
>> Disk.sys for this PDO(is this method right?), and the PDO is listed in
>> the “Disk drive” category in the Device manager tool, but it with the
>> exclemation, which means the driver load unsuccessfully.
>> The bus driver print that: pnp start for the PDO, then the pnp remove
>> for the PDO.
>> Any one could tell me ,what should I do to make this driver load
>> successfully?
>
> This is probably because your driver is not responding like a disk
> device. ?Disk.sys is going to send you disk requests, and you have to
> respond like a disk.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

Thank you every body.

Hi, Phil Barila:
USBSTOR.sys only support BOT, so I will develop my own USBSTOR driver for UAS.

Conerete protocol processing is the next step.
The first step, I need to make sure that the Irp route from File system–>Disk.sys–>UAS driver–>USBHub.sys–>USBPort.sys is correct.

While in the first step I have to simulate the USBSTOR.sys, act as a bus driver role, create PDO for each LUN, make sure the PDO will load Disk.sys successfully, but failed in my code.

Hi, Tim Roberts:
—>This is probably because your driver is not responding like a disk device. Disk.sys is going to send you disk requests, and you have to respond like a disk.

<—I agree with your opinion.
But it seems that the difference between the two device log file I used with BUSHOUND catched, one is USBSTOR.sys created PDO “USB 2.0 SD/MMC Reader” and the other one “Microsoft_Eliyas_Toaster_01” create by my UAS driver changed from bus driver, located in “QUERY_PROPERTY”, but it is not a standard PNP irp.
In USB 2.0 SD/MMC Reader BUSHOUND log file, there are many “QUERY_PROPERTY” after PDO pnp start, then the deveice work normally.
But in Microsoft_Eliyas_Toaster_01 BUSHOUND log file, there is only one “QUERY_PROPERTY”, then the PDO pnp remove come up.

Maybe the disk requests is come from “QUERY_PROPERTY”, do you agree with me?

Hi, Mark Roddy:
MCCI develop their UAS driver, using this model:
WIN XP: SCSI port/miniport driver + USB WDM driver
WIN 7/VISTA: STOR port/miniport driver + USB WDM driver
But I am wonder why the port/miniport driver is necessory? What function they play in this model?

In my opinion, we can develop our own USBSTOR driver, same as USBSTOR.sys, the only difference is change the BOT protocol code into UAS protocol code.

And this driver mainly do the following works:

  1. receive ths SRBs from upper level Disk.sys
  2. translate the SRBs to URBs and send to USBD.sys

While another wonder.
If the upper level filter driver and lower filter driver for USBSTOR.sys, can we send the SRBs from upper level Disk.sys direect to lower filter driver, bypass the USBSTOR.sys?


disk.sys
|
lower filter of disk.sys or upper filter of usbstor.sys
|
| (usbstor.sys is bypass)
|
lower filter of usbstor.sys
|
usbhub.sys
|
usbehci.sys
|
P C I Bus
|
Hardware


I hear someone tell me, you should use upper filter driver of USBSTOR.SYS but
not the lower filter driver of Disk.sys, his reason is that upper filter driver
of USBSTOR.sys could queue the irps it received from upper level driver(in this
case, the upper level driver is disk.sys, but I can not receive the IRP_MJ_SCSI
from it, in question 1 ), but the lower filter driver of disk.sys could not
queue the irps(while the lower filter driver of disk.sys could receive the
IRP_MJ_SCSI from the upper level driver disk.sys)
Is his reason right, and if both the fitler driver could receive the
IRP_MJ_SCSI, which is more suitable?

Does any one see the same thing with me?

  1. Disk.sys–>disk.sys lower fitler driver–>usbstor.sys

  2. Disk.sys–>usbstor.sys upper filter driver–>usbstor.sys

the former two case, while the 1st case, the disk.sys lower fitler driver could see the IRP_MJ_SCSI from disk.sys
while the 2nd case, the usbstor.sys upper filter driver could not, why?

USBSTOR is a full scsi port driver. That is the point. Much of the
interface and implementation details of a scsi/stor port driver are
obscured, plus it is a LOT OF CODE, and difficult to get WHQLd. On the
other hand the storport virtual miniport model is documented, (well
semi-documented, plus OSR graciously published a complete driver
sample,) you get to leverage the existing storport code, and the WHQL
process is straight-forward.

Mark Roddy

On Fri, May 13, 2011 at 4:59 AM, wrote:
> Does any one see the same thing with me?
>
> 1. Disk.sys–>disk.sys lower fitler driver–>usbstor.sys
>
> 2. Disk.sys–>usbstor.sys upper filter driver–>usbstor.sys
>
> the former two case, while the 1st case, the disk.sys lower fitler driver could see the IRP_MJ_SCSI from disk.sys
> while the 2nd case, the usbstor.sys upper filter driver could not, why?
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
>

workingmailing@163.com wrote:

Hi, Tim Roberts:
—>This is probably because your driver is not responding like a disk device. Disk.sys is going to send you disk requests, and you have to respond like a disk.

<—I agree with your opinion.
But it seems that the difference between the two device log file I used with BUSHOUND catched, one is USBSTOR.sys created PDO “USB 2.0 SD/MMC Reader” and the other one “Microsoft_Eliyas_Toaster_01” create by my UAS driver changed from bus driver, located in “QUERY_PROPERTY”, but it is not a standard PNP irp.
In USB 2.0 SD/MMC Reader BUSHOUND log file, there are many “QUERY_PROPERTY” after PDO pnp start, then the deveice work normally.
But in Microsoft_Eliyas_Toaster_01 BUSHOUND log file, there is only one “QUERY_PROPERTY”, then the PDO pnp remove come up.

I don’t know what you mean by QUERY_PROPERTY. Do you mean
IOCTL_STORAGE_QUERY_PROPERTY? Are you actually handling that request?
If not, are you surprised that your device is rejected?

While another wonder.
If the upper level filter driver and lower filter driver for USBSTOR.sys, can we send the SRBs from upper level Disk.sys direect to lower filter driver, bypass the USBSTOR.sys?

No. The drivers underneath USBSTOR understand URBs. They do not
understand SRBs. If you are using an upper and a lower filter driver
to bypass USBSTOR completely, then there is absolutely no point in
keeping it around at all. Just replace USBSTOR.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

  1. Yes, it is IOCTL_STORAGE_QUERY_PROPERTY.
  2. Maybe, we can keep the USBSTOR.sys, so there are a lot of work could do by it, only the BOT transfer, such as CBW, CSW, Data In/out be handle by upper/lower filter driver, bypass the USBSTOR.sys, because I found some driver using upper + lower filter driver case to implement the UAS driver
  3. At first I want to use the QI for direct communication between two filter driver, but as I know, USBSTOR.sys is a bus driver, and QI will be completed, so the lower filter driver will not get the QI, any other method for communication between these two filter driver, while interevening PDO is exist?
  4. MCCI implement the UAS driver by scsi/stor port/miniport driver + USB driver, while USBSTOR.sys intergrated the SCSI function, as Mark Roddy said, so the replacement of USBSTOR.sys is a large project, because if I didn’t using the scsi/stor port/miniport driver, I will implement all the SCSI fucnion by myself?

> 4. MCCI implement the UAS driver by scsi/stor port/miniport driver + USB driver, while USBSTOR.sys

If you can forget XP - then write a virtual storport miniport which will do the job.

If you can’t - then you will need to do some hacks to SCSIPORT to make a virtual miniport out of it, there are several such.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

I want to process IOCTL_STORAGE_QUERY_PROPERTY in my IRP_MJ_SCSI/IRP_MJ_INTERNAL_DEVICE_CONTROL routin, but when I do like this:

////////////////////////////////////
for (i = 0; i < arraysize(DriverObject->MajorFunction); ++i)
DriverObject->MajorFunction[i] = FilterPass;
///////////////////////////////////

no dwControlCode equal to “IOCTL_STORAGE_QUERY_PROPERTY”.

Does anybody knows where I could hadle this IOCTL?

You process IOCTL_STORAGE_QUERY_PROPERTY in your IRP_MJ_DEVICE_CONTROL function.

1.—>You process IOCTL_STORAGE_QUERY_PROPERTY in your IRP_MJ_DEVICE_CONTROL function.

<—Sorry, I have try it, but in this driver routin, still could not catch the IOCTL.

  1. I found some UAS driver use the upper filter+USBSTOR.SYS+lower filter mothod.
    So it seems the method is feasbile for UAS driver.
    Can some figure out, how the dirvers of upper/lowr filter communication.
    QI is not feasible for USBSTOR.sys is bus driver.
    Does the symbolic useful?
  2. The following qeustion, will be decide which one I WILL use:
  3. Disk.sys–>disk.sys lower fitler driver–>usbstor.sys
  4. Disk.sys–>usbstor.sys upper filter driver–>usbstor.sys
    the former two case, while the 1st case, the disk.sys lower fitler driver could
    see the IRP_MJ_SCSI from disk.sys while the 2nd case, the usbstor.sys upper filter driver could not, why?
  5. If both the disk.sys lower fitler driver and usbstor.sys upper filter driver Could see the SRBs, which one should I USE for UAS driver?

workingmailing@163.com wrote:

  1. I found some UAS driver use the upper filter+USBSTOR.SYS+lower filter mothod.
    So it seems the method is feasbile for UAS driver.
    Can some figure out, how the dirvers of upper/lowr filter communication.
    QI is not feasible for USBSTOR.sys is bus driver.
    Does the symbolic useful?

You are a very frustrating person to help, because you keep ignoring all
of the advice you have been given. Sure, it’s possible to put filters
on both sides of usbstor.sys, and route all of the requests around it,
by shipping directly from the upper filter to the lower filter. But if
you do that, so that you are not using usbstor.sys at all, then that
would be a completely idiotic solution, and I don’t understand why you
can’t see that. You would be writing a complete usbstor.sys replacement
anyway, but you would have the ADDITIONAL work of splitting the driver
in two and making them filters.

Just because another vendor chose implementation method X does not mean
that method X is the best method. You HAVE to be able to use common
sense. If you can’t use common sense, then your attempt to write a
driver are doomed.

  1. The following qeustion, will be decide which one I WILL use:
  2. Disk.sys–>disk.sys lower fitler driver–>usbstor.sys
  3. Disk.sys–>usbstor.sys upper filter driver–>usbstor.sys
    the former two case, while the 1st case, the disk.sys lower fitler driver could
    see the IRP_MJ_SCSI from disk.sys while the 2nd case, the usbstor.sys upper filter driver could not, why?

My guess is that you did something wrong. If there are no other drivers
in between those two, then there is no difference between the two cases
you just described.

  1. If both the disk.sys lower fitler driver and usbstor.sys upper filter driver Could see the SRBs, which one should I USE for UAS driver?

It doesn’t matter one single bit.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

  1. Yes, there are both case for UAS driver as I known, MCCI : scsi/stor port/miniport driver + USB driver, and another vendor using upper/lower filter of USBSTOR.sys
    I am not searching the best method, but the easier, time saving.
    There for, both method, should be take into consideration, and compare between.

  2. To do a project, especially for me, have only Function driver experience, chang to bus driver, miniport driver, face a lot of questions is very common, so I come to NTDEV to inquiry all of your experts, because you have much experience

  3. even though some question still could not figure out, I will thank you for all of you, give me the advices, help me step to the aim more and more close.

thank you, very much.