Windows 7 SCSI unmap command

Hi all,

I’m currently modifying a Windows 7 (32-bits) SCSI driver.

I’m wondering does Windows 7 issue the unmap command to SCSI drives?
If it does but not by default, is there any way to get it to issue the command?

Right now I’ve tried copy&deleting files, and also emptying the Recycle Bin, but all I can see are WRITE10 commands.

Thanks,
Justin

What you mean by unmap command? I don’t see any command like that in storport.h. I think Windows never issues it.

xxxxx@gmail.com wrote:

Hi all,

I’m currently modifying a Windows 7 (32-bits) SCSI driver.

I’m wondering does Windows 7 issue the unmap command to SCSI drives?
If it does but not by default, is there any way to get it to issue the command?

Right now I’ve tried copy&deleting files, and also emptying the Recycle Bin, but all I can see are WRITE10 commands.

What do you mean by “the unmap command”? Unless I’m way behind the
times, there is no such SCSI command.

You are only slightly behind the times :). UNMAP is the SCSI equivalent of ATA trim for SSD.

In Win7 storage stack, there is no UNMAP command sent down directly from class driver. You’ll need to translate IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES (with DeviceDsmAction_Trim) into UNMAP command in a filter driver.

Hi all,
Thanks for the quick replies.
Yes SCSI UNMAP is similar (not sure is it equivalent or not) to ATA’s TRIM command.
I’ve tried to set up different intercepts. I checked if it’s a SCSI UNMAP command, and I checked if it’s a ATA passthrough with the DATA_SET_MANAGEMENT (with the TRIM bit enabled).
But neither commands were called by the OS, so I’m wondering is there anything special I have to set for the OS to enable TRIM or SCSI UNMAP.

Thanks,
Justin

I don’t think Windows 7 standard components will issue this command. If they did, it would’ve been defined in storport.h

The IOCTL mentioned above (IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES)
is sent to all storage stacks in circa win7 releases. Some storage
stacks know what to do with it, others don’t. As was mentioned a
filter driver that intercepted the IOCTL and issued an UNMAP srb in
response might be the best approach.

Mark Roddy

On Mon, May 2, 2011 at 1:49 PM, wrote:
> I don’t think Windows 7 standard components will issue this command. If they did, it would’ve been defined in storport.h
>
>
> —
> 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:

The IOCTL mentioned above
(IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES) is sent to all storage
stacks in circa win7 releases. Some storage stacks know what to do with it,
others don’t.

So does that mean that win7 will issue the above IOCTL command regardless of driver type and drive class?

I was under the impression (from reading other forums) that the TRIM command is only sent to SSDs that supports it; and not, sending the command to all drives and wait for responds before sending another type of ‘erase’ command if TRIM failed/not supported

Thanks in advance for clarification,
Justin

IOCTL_STORAGE_QUERY_PROPERTY type StorageDeviceTrimProperty flows
through the (disk) class driver to the port driver where the trim
capability of the device (and the ability of the port driver to
support trim requests) is indicated in response.

This is all from memory as I no longer have source access, so *I think
it works this way*, but you can validate that classpnp forwards
StorageDeviceTrimProperty queries from the WDK sources. I could up the
tracing in my port upper filter to verify this again, but I recall
having done this already and that I convinced myself that I could
emulate trim support by messing with the property and the trim
requests in a filter driver.

Mark Roddy

On Tue, May 3, 2011 at 1:12 PM, wrote:
> @Mark:
>>The IOCTL mentioned above
>>(IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES) is sent to all storage
>>stacks in circa win7 releases. Some storage stacks know what to do with it,
>>others don’t.
>
> So does that mean that win7 will issue the above IOCTL command regardless of driver type and drive class?
>
> I was under the impression (from reading other forums) that the TRIM command is only sent to SSDs that supports it; and not, sending the command to all drives and wait for responds before sending another type of ‘erase’ command if TRIM failed/not supported
>
> Thanks in advance for clarification,
> Justin
>
>
>
>
> —
> 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
>

>I was under the impression (from reading other forums) that the TRIM command is only sent to >SSDs that supports it; and not, sending the command to all drives and wait for responds before >sending another type of ‘erase’ command if TRIM failed/not supported
If you have a monolithic storage driver you could get TRIM in Windows 7 because TRIM issue only on IOCTL base. If you have a miniport driver either SCSI or storport you could not get TRIM. You need to work around to implement TRIM in miniport driver.

Igor Sharovar

>If you have a monolithic storage driver you could get TRIM in Windows 7

because TRIM issue only on IOCTL base. If you have a miniport driver either
SCSI or storport you could not get TRIM. You need to work around to
implement TRIM in miniport driver

Yes, my driver is going through storport right now.
Does this mean TRIM doesn’t get pass through storport or it still passes the
IOCTL commands to the driver?

Any suggestion on how to implement a workaround?
Maybe I’m looking at the wrong level of the driver code,
but I can’t intercept any ATA’s DATA_MANAGEMENT_SET with TRIM,
SCSI’s UNMAP, or WRITE_SAME (10,16,or 32). All I get are WRITE10
(this is when I try to use the Recycle Bin and empty trash)

Thanks in advance,
Justin

>Yes, my driver is going through storport right now. Does this mean TRIM doesn’t get pass >through storport or it still passes the IOCTL commands to the driver?

Miniport storport driver could not get any TRIM command. Look at the end of this discussion.
http://www.osronline.com/showThread.cfm?link=188255

Igor Sharovar

For something like the fourth time in this thread: the suggestion is
to implement a filter driver ABOVE the port driver to handle the trim
IOCTLS that WILL NOT BE DELIVERED IN ANY FORM to your storport
miniport because the storport port driver does not support them.

I don’t know how to make this clearer. BOLD? HUGE FONTS? COLOR?

Mark Roddy

On Wed, May 4, 2011 at 12:35 PM, wrote:
>>If you have a monolithic storage driver you could get TRIM in Windows 7
>>because TRIM issue only on IOCTL base. If you have a miniport driver either
>>SCSI or storport you could not get TRIM. You need to work around to
>>implement TRIM in miniport driver
>
> Yes, my driver is going through storport right now.
> Does this mean TRIM doesn’t get pass through storport or it still passes the
> IOCTL commands to the driver?
>
> Any suggestion on how to implement a workaround?
> Maybe I’m looking at the wrong level of the driver code,
> but I can’t intercept any ATA’s DATA_MANAGEMENT_SET with TRIM,
> ?SCSI’s UNMAP, or WRITE_SAME (10,16,or 32). All I ?get are WRITE10
> (this is when I try to use the Recycle Bin and empty trash)
>
> Thanks in advance,
> Justin
>
>
>
>
> —
> 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
>

@Igor
Thanks for the reference

@Mark
Sorry, I actually thought you meant to implement the filter within the driver
that I’m working on, which is ‘below’ the storport driver.

Thank you all, I will do as Mark suggest and change my approach,
current idea:
Filter driver *ABOVE* storport -> intercept trim and create scsi passthrough
-> pass to storport -> pass to current driver.

If this is the wrong interpretation of what I’m suppose/could to do,
please let me know now before I go on another wild goose chase :slight_smile:

Thanks,
Justin