Reading physical sector size

Hi, I wonder if anyone knows how to get the disk physical sector size of a hard disk having 4k sector size.

There is a Microsoft example to read both logical and physical sector size in Vista/w7 but unfortunately this example does not work, it returns both logical and physical sector size of 512 bytes.

Here is the Micrsoft example:
http://msdn.microsoft.com/en-us/library/ff800831(v=VS.85).aspx

I wonder if there is an alternative method to read this value that will work on XP/Vista/W7.

Thanks.

Peter

Send extended “read capacity” SCSI command directly to the disk via say
SPTI.

Anton

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@becrypt.com
Sent: Tuesday, October 19, 2010 11:44 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Reading physical sector size

Hi, I wonder if anyone knows how to get the disk physical sector size of a
hard disk having 4k sector size.

There is a Microsoft example to read both logical and physical sector size
in Vista/w7 but unfortunately this example does not work, it returns both
logical and physical sector size of 512 bytes.

Here is the Micrsoft example:
http://msdn.microsoft.com/en-us/library/ff800831(v=VS.85).aspx

I wonder if there is an alternative method to read this value that will work
on XP/Vista/W7.

Thanks.

Peter


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

On Tue, 19 Oct 2010 04:44:04 -0400 (EDT)
xxxxx@becrypt.com wrote:

There is a Microsoft example to read both logical and physical sector
size in Vista/w7 but unfortunately this example does not work, it
returns both logical and physical sector size of 512 bytes.

If you’re running it on a WD EARS or the newer Samsung drive, both
report logical and physical sizes of 512 bytes, apparently for
compatibility - you can’t know, except by reading the model number,
that they really use 4KB sectors.

See
http://community.wdc.com/t5/Other-Ideas/Release-non-512-byte-sector-emulated-firmware-for-WD-EARS/idi-p/21347
for more information.


Bruce Cran

Thanks all for the reply.

Send extended “read capacity” SCSI command directly to the disk via say SPTI.

I am not familiar with the SCSI command, is it possible to explain a bit more of how to construct the PASS_THROUGH structure to retrieve the sector size?

If you’re running it on a WD EARS or the newer Samsung drive, both
report logical and physical sizes of 512 bytes, apparently for
compatibility - you can’t know, except by reading the model number,
that they really use 4KB sectors.

Yes, I am using one of the WD EARS drives. When install XP on it, the disk is running extremely slowly, this is because XP does not support this type of disk. However Windows 7 does support this type of disk, and I have noted that the disk runs much faster in Windows 7. In both cases, I did not use the jumper settings or run the WD tool.

Thanks.

On Tue, 19 Oct 2010 08:38:59 -0400 (EDT)
xxxxx@becrypt.com wrote:

Yes, I am using one of the WD EARS drives. When install XP on it, the
disk is running extremely slowly, this is because XP does not support
this type of disk. However Windows 7 does support this type of disk,
and I have noted that the disk runs much faster in Windows 7. In both
cases, I did not use the jumper settings or run the WD tool.

I don’t know about XP, but I think Windows 7 aligns partitions to 4MB
(i.e. partitions start at sector 8192 - so each filesystem cluster
read/write will be aligned.


Bruce Cran

THAT would be your problem.

Peter
OSR

>I am not familiar with the SCSI command, is it possible to explain a bit more of how to construct >the PASS_THROUGH structure to retrieve the sector size?

Look at a following sample from WDK:
\WinDDK\7600.16385.1\src\storage\tools\spti

It is the sample of user application to communicate with SCSI device.

Igor Sharovar

> I am not familiar with the SCSI command, is it possible to explain a bit more of how to construct the

PASS_THROUGH structure to retrieve the sector size?

In the disk filter stack, PASS_THROUGH is maybe an overkill.

Just read the Disk sample, look at how it is creating the SRBs/CDBs, and create your own SRB/CDB with the extended read capacity command.


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

Don’t you have to be below the class driver? Above and you will get
your IRP_MJ_SCSI request rejected. You could go around the class
driver, but that would be rude.

Mark Roddy

On Tue, Oct 19, 2010 at 1:10 PM, Maxim S. Shatskih
wrote:
>> I am not familiar with the SCSI command, is it possible to explain a bit more of how to construct the
>>PASS_THROUGH structure to retrieve the sector size?
>
> In the disk filter stack, PASS_THROUGH is maybe an overkill.
>
> Just read the Disk sample, look at how it is creating the SRBs/CDBs, and create your own SRB/CDB with the extended read capacity command.
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> —
> 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
>

No. SCSI_PASSTHROUGH_DIRECT and ATA_PASSTHROUGH_DIRECT are, as the name
implies, passed through.

Regards,

George.

“Mark Roddy” wrote in message news:xxxxx@ntdev…
> Don’t you have to be below the class driver? Above and you will get
> your IRP_MJ_SCSI request rejected. You could go around the class
> driver, but that would be rude.
>
> Mark Roddy
>
>
>
> On Tue, Oct 19, 2010 at 1:10 PM, Maxim S. Shatskih
> wrote:
>>> I am not familiar with the SCSI command, is it possible to explain a bit
>>> more of how to construct the
>>>PASS_THROUGH structure to retrieve the sector size?
>>
>> In the disk filter stack, PASS_THROUGH is maybe an overkill.
>>
>> Just read the Disk sample, look at how it is creating the SRBs/CDBs, and
>> create your own SRB/CDB with the extended read capacity command.
>>
>> –
>> Maxim S. Shatskih
>> Windows DDK MVP
>> xxxxx@storagecraft.com
>> http://www.storagecraft.com
>>
>>
>> —
>> 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
>>
>

True, disk.sys passes the IRP to lower DO.

Additionally if you pass it through disk.sys, I think it sets few minor things, without which lower layer will reject it. Obviously if sending it to port driver directly, one need to take care of all those bits.

Yes SPT is passed through. Maxim suggested simply formatting
IRP_MJ_SCSI requests and I think that will not work above the class
driver.

Mark Roddy

On Tue, Oct 19, 2010 at 6:48 PM, George M. Garner Jr.
wrote:
> No. ?SCSI_PASSTHROUGH_DIRECT and ATA_PASSTHROUGH_DIRECT are, as the name
> implies, passed through.
>
> Regards,
>
> George.
>
> “Mark Roddy” wrote in message news:xxxxx@ntdev…
>> Don’t you have to be below the class driver? Above and you will get
>> your IRP_MJ_SCSI request rejected. You could go around the class
>> driver, but that would be rude.
>>
>> Mark Roddy
>>
>>
>>
>> On Tue, Oct 19, 2010 at 1:10 PM, Maxim S. Shatskih
>> wrote:
>>>> I am not familiar with the SCSI command, is it possible to explain a bit
>>>> more of how to construct the
>>>>PASS_THROUGH structure to retrieve the sector size?
>>>
>>> In the disk filter stack, PASS_THROUGH is maybe an overkill.
>>>
>>> Just read the Disk sample, look at how it is creating the SRBs/CDBs, and
>>> create your own SRB/CDB with the extended read capacity command.
>>>
>>> –
>>> Maxim S. Shatskih
>>> Windows DDK MVP
>>> xxxxx@storagecraft.com
>>> http://www.storagecraft.com
>>>
>>>
>>> —
>>> 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
>>>
>>
>
>
>
> —
> 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 have been offline for a while and just noted there are new replies. Many thanks to all.

According WD’s instructions that the EARS drive works fine on Vista or Windows 7, there no need to use the jumper setting or run the WD alignment tool. This makes me think that Windows 7 should be able to detect this type of new disk, and reports the physical sector size correctly.

Unfornately querying STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR via IOCTL_STORAGE_QUERY_PROPERTY on Windows 7 does not return the correct physcial sector size.

Also sending SCSI read capacity (16) command through IOCTL_SCSI_PASS_THROUGH_DIRECT with no luck, no extended alignment information is returned.

I think Bruce Cran’s comment is correct, the only solution is to look at the drive’s model number to work out the physcial sector size.

Not sure if sending a request within a lower disk filter driver would give me the correct answer or not?

On Thu, 21 Oct 2010 04:31:04 -0400 (EDT)
xxxxx@becrypt.com wrote:

According WD’s instructions that the EARS drive works fine on Vista
or Windows 7, there no need to use the jumper setting or run the WD
alignment tool. This makes me think that Windows 7 should be able to
detect this type of new disk, and reports the physical sector size
correctly.

I very much doubt that Windows 7 is figuring out the sector size: I
think that instead it uses a default partition alignment that means
that partitions start on a 4KB boundary, so the first read of 4KB or
more will be aligned on disk. Since NTFS uses a block size which is a
multiple of 4KB all reads/writes will therefore be a multiple of the
sector size, so no unaligned IO will take place. The problem with XP is
that partitions may not be aligned and so the block IO may be
unaligned each time.


Bruce Cran

>… NTFS uses a block size which is a multiple of 4KB

IIRC, NTFS was always thinking in terms of 1K blocks. Did they change it to 4K in more recent versions, ot it is just a typo?

Anton Bassov

On Thu, 21 Oct 2010 05:50:21 -0400 (EDT)
xxxxx@hotmail.com wrote:

IIRC, NTFS was always thinking in terms of 1K blocks. Did they change
it to 4K in more recent versions, ot it is just a typo?

I had thought 4KB was the smallest size you could choose, but looking
at the Format options you can choose from an allocation size of 512,
1KB, 2KB, 4KB (default), etc.


Bruce Cran

Besides apparently not working, using SCSI pass to get the sector size is a pretty hackish approach and would be unfortunate if this was the only approach. For gosh sakes, this is a low level SCSI command. Why does a driver need to build a hardware dependent bit level command when the sector size is a high level and important item for drivers to query. This is just begging to break on new hardware or specific device stacks. Keep in mind knowledge of the sector size is required in order to use high level concepts like FILE_NO_INTERMEDIATE_BUFFERING. Hopefully Doron or someone can step in and give a reasonable approach. Surely something better exists?

wrote in message news:xxxxx@ntdev…
> Besides apparently not working, using SCSI pass to get the sector size is
> a pretty hackish approach and would be unfortunate if this was >the only
> approach. For gosh sakes, this is a low level SCSI command. Why does a
> driver need to build a hardware dependent bit level >command when the
> sector size is a high level and important item for drivers to query. This
> is just begging to break on new hardware or >specific device stacks. Keep
> in mind knowledge of the sector size is required in order to use high
> level concepts like >FILE_NO_INTERMEDIATE_BUFFERING.

This flag is more related to FS Cluster size (low level sector disk size is
a multiple of)/Mm page size alignement ?
I guess the problematic here is more related to full disk low level
encryption? I guess taking the smallest multiple (512) block size for
encryption is always a safe bet.

My two cents as always.

>Hopefully Doron or someone can step in and give a reasonable approach.
>Surely something better exists?
>
>
J.

> (FILE_NO_INTERMEDIATE_BUFFERING) is more related to FS Cluster size

FWIW, the WDK docs are very specific about this flag and say nothing about cluster size. Below are direct quotes:

Any optional ByteOffset passed to ZwReadFile or ZwWriteFile must be a multiple of the sector size.

The Length passed to ZwReadFile or ZwWriteFile must be an integral of the sector size.

Calls to ZwSetInformationFile with the FileInformationClass parameter set to FilePositionInformation must specify an offset that is a multiple of the sector size.

No, no… Mr. Kroeter is correct. It’s related to SECTOR size.

Folks need to keep in mind that these “new” drives have LOGICAL sector sizes and PHYSICAL sector sizes.

What you typically care about is the LOGICAL sector size. That’s what you need to pay attention to for alignment issues with FILE_NO_INTERMEDIATE_BUFFERING.

But the question was about PHYSICAL sector size… which is really a different issue.

Peter
OSR