Filtering ATA commands

Hi,
I have this project to intercept and change some of the ATA commands that are sent to a SATA fixed disk ( not my primary disk).

I have a lower disk class filter driver, but this driver only sees SCSI commands.
I need to have filter driver that stays below the driver that translate SCSI commands to ATA commands.
My questions are:
which driver does the translation to ATA?
Is it possible at all to write a filter that can intercept these commands?
How would I attach my filter to that driver?

Thanks for your help
pada

You don’t. The translation from scsi to ata/sata is internal to the
port/miniport driver.

On Wednesday, October 28, 2009, wrote:
> Hi,
> I have this project to intercept and change some of the ATA commands that are sent to a ? SATA fixed disk ( not my primary disk).
>
> I have a lower disk class filter driver, but this driver only sees SCSI commands.
> I need to have filter driver that stays below the driver that translate SCSI commands to ATA commands.
> My questions are:
> which driver does the translation to ATA?
> Is it possible at all to write a filter that can intercept these commands?
> How would I attach my filter to that driver?
>
> Thanks for your help
> pada
>
> —
> 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
>


Mark Roddy

Thanks for the reply.
Is it possible to have a filter driver between the port driver and mini port driver?

In general, could you please explain little bit more in detail how driver stack looks like for a SATA hard disk and what driver does what?

Thanks again
Pada

xxxxx@hotmail.com wrote:

Thanks for the reply.
Is it possible to have a filter driver between the port driver and mini port driver?

No. A miniport and its associated port driver are generally tightly
linked by DLL function calls. The pair are seen by the operating system
as a single driver.


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

How would you suggest to address the issue of intercepting and changing the ATA commands?

If I want to send a specific ATA command, can a lower class filter driver, sends ATA command to the port (or mini port) driver?

Can you also point me to a document to show stack driver for a disk device?

Thanks for your help
pada

xxxxx@hotmail.com wrote:

How would you suggest to address the issue of intercepting and changing the ATA commands?

Others with more disk experience should respond to this, but as far as I
know, it’s not possible. Inter-driver communication is done via SCSI
commands. It’s only at the lowest-level driver that the SCSI commands
are translated to ATA commands to send to the device. So, your question
is like asking “how can I intercept I/O port register writes done by the
VGA driver?” You can’t.

If you want to have an impact on the ATA commands, you need to alter the
SCSI-based ioctls to get the results you wish.

If I want to send a specific ATA command, can a lower class filter driver, sends ATA command to the port (or mini port) driver?

Some of the disk drivers support the SCSI “ATA passthrough” command.
Beyond that, a lower filter could send an ATA command directly to the
hardware.


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

Write a storport/ataport/scsiport miniport driver. There is no defined
interface for “intercepting and changing ATA commands”.

Mark Roddy

On Thu, Oct 29, 2009 at 1:24 PM, wrote:
>
> How would you suggest to address the ?issue of intercepting and changing the ATA commands?
>
> If I want to send a specific ATA command, can a lower class filter driver, sends ATA command to the port (or mini port) driver?
>
> Can you also point me to a document to show stack driver for a disk device?
>
> Thanks for your help
> pada
>
>
>
> —
> 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
>

AFAIK, It is the port driver that does the translation? If you are a miniport driver then you can see the translated (ATA) commands and change them before sending them to the device. I don’t think you can insert any filter between port driver and miniport driver. They work in tandem.

Thanks for all the reply.
OK, it seems that I can not write a filter to change the ATA commands.

How would I send a ATA command form a disk lower-class filter driver to the hardware?

Thanks
Pada

Which ATA commands are you inrterested in?

Sorry for late response.
In specific, Identify and the Spin down/up command.
But In general I would like to know how the ATA communication between a lower disk-class filter driver and mini-port driver happens.

Thanks
pada

There are two different models - scsi/storport and ataport. In the
scsi/storport case there is no defined msft interface for sending ATA
commands from a filter driver. In the ataport case there is support
for ata passthrough. See the documentation for IOCTL_ATA_PASS_THROUGH
and search this email list for discussions about using
IOCTL_ATA_PASS_THROUGH.

In both cases, other than the passthrough IOCTLS, all standard IO
requests are input to the port driver as SCSI SRBs. Translation to ATA
commands occurs internal to the Ataport driver for HBAs managed by
Ataport, and internal to the miniport driver for HBAs managed by
scsi/storport.

There is a SCSI equivalent for each of the ATA commands you listed.
You are focused on your desired solution method: modify ATA commands
directly, rather than the range of solution methods that will work
within the NT storage architecture. Consider modifying the scsi
commands.

Mark Roddy

On Tue, Nov 3, 2009 at 11:39 AM, wrote:
>
> Sorry for late response.
> In specific, Identify and the Spin down/up command.
> But In general I would like to know how the ATA communication between a lower disk-class filter driver and mini-port driver happens.
>
> Thanks
> pada
>
> —
> 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
>

Mark,Thanks for the reply.

So for a SATA based hard drive, ataport model is the one that is used used?
What devices uses scsi/storport model?

Also, wen I look at the windows registry, there are all these other classes like “IDE ATA/ATAPI controllers” or “SCSI and RAID controllers”. Where in driver stack they are located?
I can see that Bushound driver is attcahed to them so somehow commands to the devices goes through these calss drivers. But I don’t know the stack layer.

Thanks

> So for a SATA based hard drive, ataport model is the one that is used used?

Not necessarily. You are missing the design here. Disks are attached
to host bus adapters, host bus adapters are (generally) pci devices
and the drivers for those pci devices are either based on
scsi/storport or ataport. Requests are processed by the HBA driver for
all of the targets attached to the HBAs it manages. My guess is that
most SATA disks are actually plugged into scsi/storport drivers, not
ataport drivers. If you want to stare at the code that implements a
storport SAS/SATA miniport driver, the LSI driver code is in the Win 7
WDK and is a good example of just how far removed from actual wire
protocol issues an HBA miniport driver is.

SCSI is the common language. I keep urging you to think of a solution
that uses SCSI requests rather than trying to find a solution that
somehow uses ATA requests from a filter driver, but I don’t seem to be
getting through.

Mark Roddy

On Tue, Nov 3, 2009 at 12:26 PM, wrote:
> Mark,Thanks for the reply.
>
> So for a SATA based hard drive, ?ataport model is the one that is used used?
> What devices uses scsi/storport model?
>
> Also, wen I look at the windows registry, ?there are all these other classes like ?“IDE ATA/ATAPI controllers” or “SCSI and RAID controllers”. Where in driver stack they are located?
> I can see that Bushound driver is attcahed to them so somehow commands to the devices goes through these calss drivers. But I don’t know the stack layer.
>
> Thanks
>
> —
> 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
>

> In specific, Identify and the Spin down/up command.

INQUIRY and START STOP UNIT

But In general I would like to know how the ATA communication between a lower disk-class filter
driver and mini-port driver happens.

There is no ATA communication in the disk stack, only SCSI one.

Yes, Windows really treats ATA as a “kind of SCSI”, thus having issues with lots of ATA-specific stuff.


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

> So for a SATA based hard drive, ataport model is the one that is used used?

It does not depend on a drive. It depends on a controller.

A) For usual south-bridge PC/AT-compatible (0x1f0/0xf) controller, the old-style ATAPI.SYS is used, which is a full reimplementation of the SCSIPORT-style storage port talking to 0x1f0/0xf PC/AT controller.

ATAPI.SYS can have the decorator modules for DMA support - like PCIIDE.SYS, PCIIDEX.sys etc.

Without the decorators, ATAPI creates the “IDE channel” devnode with <= 2 bus children devnodes which are 2 disk or CD/DVD drives. DMA is not supported.

With the decorator, there is an “Intel PCI IDE controller”-style devnode created by the decorator, with possibly several “IDE channel” devnodes. For these latter ones, decorator is the PDO and ATAPI.SYS is the FDO. ATAPI.SYS running on such PDOs can support DMA.

B) In modern (Vista+) OSes, the suggested model for non PC/AT-compatible controllers is ATAPORT. The architecture is similar to STORPORT but supports lots of ATA-specific things.

IIRC ATAPORT code being implemented in the same STORPORT.SYS binary (I have doubts there is a separate ATAPORT.SYS).

The sample of the driver using ATAPORT is MSAHCI.SYS driver used for all AHCI controllers regardless of their vendor.

C) In pre-Vista OSes, for non PC/AT compatible controller (AHCI, HighPoint, Promise etc), the only model was SCSIPORT one. STORPORT could also be used, but it started from Server 2003 and is absent in XP, so it is hardly relevant here.

In this case, all translation of “emulated SCSI” commands to actual ATA commands is inside the vendor’s binary, MS does not know anything on this. And yes, the ATA controller looks as a SCSI controller in Device Manager, and its drives - as “SCSI Disk Device”.


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

Mark and Maxim, thanks for your good explanations.
I think I am starting to understand the design now. Sorry that some of my questions sounded naive, but I’m new in this field.

One more question that I have is with regards to “IDE ATA/ATAPI controllers” or “SCSI and RAID controllers” classes. What roles these drives plays in the storage stack?
I have noticed that Bus Hound install it’s filter driver as the upper filter for these drivers and this is how it can intercept commands, but I’m not sure where in the storage stack they belong to.

Thanks again

IDE ATA/ATAPI and SCSI or RAID are the two different models for HBA
adapter drivers that we have discussed. On recent systems IDE
ATA/ATAPI is an ataport based miniport driver, while SCSI or RAID will
be a storport based miniport driver.

But for you this doesn’t much matter - both ataport and storport speak
SCSI at their filterable interfaces. Plus there is no guarantee, as we
have discussed, that all SATA disks are controlled by an ataport based
HBA driver. Any SAS/SATA controller - one that can support both SAS
and SATA devices - for example, will be a storport based driver.

What Bus Hound does is also of little interest as it is not a good
model for a real product. It is a useful tool for what it does: trace
IO Requests.

Mark Roddy

On Wed, Nov 4, 2009 at 11:50 AM, wrote:
> Mark and Maxim, thanks for your good explanations.
> I think I am starting to understand the design now. Sorry that some of my questions sounded naive, but I’m new in this field.
>
> One more question that I have is with regards to “IDE ATA/ATAPI controllers” or “SCSI and RAID controllers” classes. What roles these drives plays in the storage stack?
> I have noticed that Bus Hound install it’s filter driver as the upper filter for these drivers and this is how it can intercept commands, but I’m not sure where in the storage stack they belong to.
>
> Thanks again
>
>
>
> —
> 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
>

Mark and Maxim, thank you for your help.