How does WMI determine geometry?

Looking at an issue that seems centered around what wmi is returning for disk geometry…

Background: Disk (SCSI) where Int13/48h reports:
Flags = 1 (bit 1 = 0 which implies geometry information is not valid)
Physical Cylinders = 16383
Physical Heads = 16
Physical Sectors Per Track = 63
Absolute Number of Sectors = 252,110,848

wmic diskdrive list reports the following:
SectorsPerTrack = 63
Size = 129,076,093,440
TotalCylinders = 18965
TotalHeads = 211
TotalSectors = 252,101,745
TotalTracks = 4001615

I have two questions:

  1. If int13 is reporting one value for total number of sectors, why does wmi have a different value?
  2. In the absence of valid geometry information, how does wmi calculate sectors per track, total heads, and total cylinders?

As an aside, during a WinPE install of Win7 X64, I have a log that shows two different sets of values at two different stages for the same physical disk…

Thanks!

-JT

Because int13 has limitations

I hate to be “that guy”… but why do you care about this?

The whole cyls/tracks/heads report data is basically outdated. What’s reported as the drive layout is almost always wrong and in general irrelevant.

If you’re reading/writing in the legacy pre-boot environment, you want to be using Extended Int 13h (function 42h) in any case, right?

Peter
OSR
@OSRDrivers

I care because my client cares… :slight_smile:

I agree that CHS addressing is really out of date but that’s what the client uses and the tool happens to care about cylinder boundaries. The issue is causing unused space to be left after partitioning, as well as the capacity not being what’s reported. (If you tell a client the disk is size X, then they want to use all X, not (X - Y)). Anyways, they want a definitive root cause analysis.

With enough money and time I’m sure the tools could be re-written and the process re-validated but really, that’s not going to happen.

[Put yourself in their shoes – If you reported an issue to your vendor and they responded “Who knows? It’s all outdated and you need to change your processes.” – what’s your reaction going to be?]

I don’t care about reading/writing - that all works just fine given a valid LBA. What I care about is why BIOS reports one value and WMI proceeds to use something different when it claims to be using that same BIOS value.

[The documentation for the Win32_DiskDrive class (http://msdn.microsoft.com/en-us/library/aa394132(v=vs.85).aspx) states that:
TotalCylinders - Total number of cylinders on the physical disk drive. Note: the value for this property is obtained through extended functions of BIOS interrupt 13h.]

So, if the extended Int13 call reports the geometry is invalid (more correctly, it doesn’t report that it is valid), where did this value come from? The values between the Int13 return and the Win32_DiskDrive class are different so WMI is not just ignoring the valid bit and using it anyway, it’s either retrieving the value using some other means or it’s somehow calculating a value itself…

I’ll ask again:

  1. If int13 is reporting one value for total number of sectors, why does wmi
    have a different value?
  2. In the absence of valid geometry information, how does wmi calculate
    sectors per track, total heads, and total cylinders?

Thanks.

-JT

OK…

What does IOCTL_DISK_GET_DRIVE_GEOMETRY return?

Peter
OSR
@OSRDrivers

IOCTL_DISK_GET_DRIVE_GEOMETRY returns the same values as WMI – cylinders = 18965, tracks/cylinder = 211, sectors/track = 63, disk size = 129,076,093,440.

(I grabbed the example code from http://msdn.microsoft.com/en-us/library/windows/desktop/aa363147(v=vs.85).aspx.)

-JT

OK… which version of Windows do you care about? This code has changed in the past several years.

You should take a look at \Disk Class Driver\c++\src\geometry.c in the WDK 8.1 samples for some info on how this is handled in recent versions of Windows, including the follow gem from pnp.c in that same driver:

if (diskData->GeometrySource == DiskGeometryUnknown)
{
//
// Neither the BIOS nor the port driver could provide us with a reliable
// geometry. Before we use the default, look to see if it was partitioned
// under Windows NT4 [or earlier] and apply the one that was used back then
//

if (DiskIsNT4Geometry(fdoExtension))
{
diskData->RealGeometry = fdoExtension->DiskGeometry;
diskData->RealGeometry.SectorsPerTrack = 0x20;
diskData->RealGeometry.TracksPerCylinder = 0x40;
fdoExtension->DiskGeometry = diskData->RealGeometry;

diskData->GeometrySource = DiskGeometryFromNT4;
}
}

Peter
OSR
@OSRDrivers

The client’s interested in Win7 and newer…

Thanks for the pointers Peter!

-JT

Next the client will be asking why Windows reports one disk size (in binary units), and Apple is reporting different (in decimal units). Or why Windows reports size less than stated on the drive.

Sometimes you just have to say “because it’s how it works and you need to accept that”.

> [Put yourself in their shoes – If you reported an issue to your vendor and they responded “Who knows? It’s all outdated and you need to change your processes.” – what’s your reaction going to be?]

Perhaps a better reply would be to tell them you do know what?s happening, and for about the last decade or two, sponging physical disks use a variable number of sectors per track, so it?s not possible to report a correct CHS geometry. Some drives may be able to tell you their actual geometry if you issue the correct mode page request. My memory is geometry is generally broken up into zones, there is a list of LBA x to y has geometry z values.

If the goal is to pick a value for aligning partition start addresses, there are a couple of opinions on what the optimal value would be. You could report a value for heads and sectors per track such that the two multiplied give a appropriate alignment value. The classic problem with this is the the maximum disk size you can describe is vastly smaller than current drives, so setting H and S to their largest allowed values gave you the largest possible disk, which still is way smaller than current disks sizes, which is why we use LBAs now and not CHS.

CHS in it?s bios field width form, can?t come close to describing modern sizes of disks. CHS was originally used because it matched up with some control registers for an ancient IDE disk controller in the ?80s.

In general, disks know a lot more about how to optimize their own performance than naive software, so there is a good argument you should just treat the disk at a linear array of block addresses (and know the block size), and let the drive do any performance optimizing.

The partition alignment probably matters based on what RAID striping is applied, and one could view that some alignments are better for the RAID controller.

There also is the modern issue of Flash memory chunk sizes. Flash memory can?t be updated on 512/4096 by boundaries, so you should likely align a partition on a natural boundary of the flash block size. If you write a lot of chunks a lot smaller than the native block size, you get write amplification and it uses up the limited number of writes each flash block can do. Writing 512 bytes every 128K or so is probably a great way to wear out your flash drive. I don?t think OSs or file systems really know how to use write block sizes other than 512/4096 bytes, even though a value like 128K is likely a lot better for flash storage life. This is one argument of why flash storage should talk in terms of file I/O requests, not blocks. If you do file I/O requests to a device, it can optimize it?s performance and wear. It might for example use a write mostly file file system, and store up changes in NVRAM buffers until a full flash block can be written. This offhand seems way more optimal than what we do now.

A lot of storage is controlled by some complex storage controller, which may for example deal with blocks of some size unrelated to the physical disks. If you do write operations then span two storage controller blocks, it may give non-optimal performance. The virtual blocks you get from a complex storage controller (like from EMS/Netapp/etc), may report info about the optimal block alignment via mode pages.

Jan

I’m not sure SCSI drives ever report their actual or fictional geometry. Whatever INT13 reports for them is completely made up.

Worse, I think Windows is going to shift to decimal. So it will be “which
version of windows and why are they different?”.

Mark Roddy

On Mon, Aug 4, 2014 at 3:53 PM, wrote:

> Next the client will be asking why Windows reports one disk size (in
> binary units), and Apple is reporting different (in decimal units). Or why
> Windows reports size less than stated on the drive.
>
> Sometimes you just have to say “because it’s how it works and you need to
> accept that”.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>

INT13 has reported totally fictitious values for a long time. Some disk drives did have mode pages you could query to find out about the actual geometry. A quick Google search finds an old paper about the topic of drive geometry http://www.hpl.hp.com/techreports/97/HPL-97-02.pdf

Jan

On Aug 4, 2014, at 2:06 PM, xxxxx@broadcom.com wrote:

I’m not sure SCSI drives ever report their actual or fictional geometry. Whatever INT13 reports for them is completely made up.

>LBAs are a fiction on physical media too.

That’s why it’s *L*BA.

> [Put yourself in their shoes – If you reported an issue to your vendor and they responded

“Who knows? It’s all outdated and you need to change your processes.” – what’s your reaction going to be?]

Well, it depends…

If they are able to provide me with a reasonable and technically sound explanation of their position, there is a good chance that I will just listen to what they say. Look - the tools that your clients are using rely upon
the methodology that had been, from the technical standpoint, totally irrelevant for at least a couple of decades. As it had been pointed out already, the physical layout that is reported by BIOS is totally fictitious and does not correspond to the actual drive geometry that is known only to the disk’s firmware. Therefore, a modern tool that relies upon this info firmly belongs to “broken by design” class, don’t you think…

Anton Bassov

(While everything that folks have stated so far is correct, and perhaps even useful for the archives, you guys know that the OP got a helpful answer and almost certainly stopped listening a couple of days back, right?)

Thread locked, just because the discussion has become irrelevant to the initial post and we’re talking to ourselves.

OP: Feel free to open a new thread if you require any more guidance or in the very unlikely case that you want to discuss the merits of C/H/S addressing in the twenty first century.

(darn, I clicked the “Post” button instead of the “Lock” button)