Getting disk size - W2K and XP

Hi All
I’ve noticed a strange difference between Windows 2000 and Windows XP. In my
disk filter driver I need to check the size of the disk. Windows XP has
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX that explicitly provides the disk size
information and works fine. On Windows 2000 we have only
IOCTL_DISK_GET_DRIVE_GEOMETRY, that does not return the disk size
explicitly, but we can calculate it by multiplying the values in
DISK_GEOMETRY structure. Now comes the funny part: for removable media the
result of the multiplication is smaller than the actual disk size by several
MB. However, if we use IOCTL_DISK_GET_DRIVE_LAYOUT to get the partition
info, the returned partition size is the real disk size (removable media can
have only one partition).
Can anyone explain why do we get wrong information from
IOCTL_DISK_GET_DRIVE_GEOMETRY?

Thanks,
Gregory

Yes. Not more than 8MB? Try 63 * 256 * 512 as a clue. Don’t use CHS!

“Gregory Dardyk” wrote in message news:xxxxx@ntdev…
> Hi All
> I’ve noticed a strange difference between Windows 2000 and Windows XP. In
> my
> disk filter driver I need to check the size of the disk. Windows XP has
> IOCTL_DISK_GET_DRIVE_GEOMETRY_EX that explicitly provides the disk size
> information and works fine. On Windows 2000 we have only
> IOCTL_DISK_GET_DRIVE_GEOMETRY, that does not return the disk size
> explicitly, but we can calculate it by multiplying the values in
> DISK_GEOMETRY structure. Now comes the funny part: for removable media the
> result of the multiplication is smaller than the actual disk size by
> several
> MB. However, if we use IOCTL_DISK_GET_DRIVE_LAYOUT to get the partition
> info, the returned partition size is the real disk size (removable media
> can
> have only one partition).
> Can anyone explain why do we get wrong information from
> IOCTL_DISK_GET_DRIVE_GEOMETRY?
>
> Thanks,
> Gregory
>
>

On Tue, 21 Jun 2005 09:08:32 -0700, “David J. Craig” wrote:

Yes. Not more than 8MB? Try 63 * 256 * 512 as a clue. Don’t use CHS!

Weeell, can you elaborate a bit more about this? I happened to run
into the same eerie thing just yesterday. Funny coincidence :slight_smile: If one
shouldn’t use CHS, how to determine the proper values? Remember that
W2K does not support IOCTL_DISK_GET_DRIVE_GEOMETRY_EX. What API can I
use to determine the size in LBAs? As long as I can work with a
partition, everything is quite fine, but what about raw access to the
physical device?

I hope you can shed some light on this :slight_smile:

Kind regards,
Andre

I once had a bug in a disk encryption system where even
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX didn’t work,
because the disk firmware returned the wrong answer to the size enquiry.
Because we believed the answer, some of the disk wasn’t encrypted.

In this case, the only reliable solution was to probe up the disk until it
failed and then binary chop
between the last good sector and the first failure to get the highest good
sector. It can take some time
because of disk class driver retries on the failing (nonexistent) sectors.

If you really really want to know the exact capacity of the disk and you
have a client that is paranoid (for instance because he wants the assurance
that ALL of his disk is encrypted) this is probably the only truly reliable
way to do it.

Having said that, of all the disks we tested, only one had this fault and it
was dependant on the rev of the firmware
on the disk. But, as I said, it depends on the paranoia level of your
client.

To be fair to the client in the case I’ve described (which is an agency
described by a small
number of capital letters), the world probably is out to get them :slight_smile:

Don

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Andre Tertling
Sent: 22 June 2005 18:03
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Getting disk size - W2K and XP

On Tue, 21 Jun 2005 09:08:32 -0700, “David J. Craig” wrote:

>Yes. Not more than 8MB? Try 63 * 256 * 512 as a clue.
Don’t use CHS!

Weeell, can you elaborate a bit more about this? I happened
to run into the same eerie thing just yesterday. Funny
coincidence :slight_smile: If one shouldn’t use CHS, how to determine the
proper values? Remember that W2K does not support
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX. What API can I use to
determine the size in LBAs? As long as I can work with a
partition, everything is quite fine, but what about raw
access to the physical device?

I hope you can shed some light on this :slight_smile:

Kind regards,
Andre


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@careful.co.uk
To unsubscribe send a blank email to xxxxx@lists.osr.com

I believe ioctl_disk_Query_partition_information sent to partition 0
will get you the size of the whole disk in LBA.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Andre Tertling
Sent: Wednesday, June 22, 2005 10:03 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Getting disk size - W2K and XP

On Tue, 21 Jun 2005 09:08:32 -0700, “David J. Craig” wrote:

Yes. Not more than 8MB? Try 63 * 256 * 512 as a clue. Don’t use CHS!

Weeell, can you elaborate a bit more about this? I happened to run into
the same eerie thing just yesterday. Funny coincidence :slight_smile: If one
shouldn’t use CHS, how to determine the proper values? Remember that W2K
does not support IOCTL_DISK_GET_DRIVE_GEOMETRY_EX. What API can I use to
determine the size in LBAs? As long as I can work with a partition,
everything is quite fine, but what about raw access to the physical
device?

I hope you can shed some light on this :slight_smile:

Kind regards,
Andre


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

disk shouldn’t have retried I/O on non-existant sectors if the drive was
returning an appropriate error message. Of course not all drives
return sane errors.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Don Ward
Sent: Wednesday, June 22, 2005 10:11 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Getting disk size - W2K and XP

I once had a bug in a disk encryption system where even
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX didn’t work, because the disk firmware
returned the wrong answer to the size enquiry.
Because we believed the answer, some of the disk wasn’t encrypted.

In this case, the only reliable solution was to probe up the disk until
it failed and then binary chop between the last good sector and the
first failure to get the highest good sector. It can take some time
because of disk class driver retries on the failing (nonexistent)
sectors.

If you really really want to know the exact capacity of the disk and you
have a client that is paranoid (for instance because he wants the
assurance that ALL of his disk is encrypted) this is probably the only
truly reliable way to do it.

Having said that, of all the disks we tested, only one had this fault
and it was dependant on the rev of the firmware on the disk. But, as I
said, it depends on the paranoia level of your client.

To be fair to the client in the case I’ve described (which is an agency
described by a small number of capital letters), the world probably is
out to get them :slight_smile:

Don

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Andre Tertling
Sent: 22 June 2005 18:03
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Getting disk size - W2K and XP

On Tue, 21 Jun 2005 09:08:32 -0700, “David J. Craig” wrote:

>Yes. Not more than 8MB? Try 63 * 256 * 512 as a clue.
Don’t use CHS!

Weeell, can you elaborate a bit more about this? I happened to run
into the same eerie thing just yesterday. Funny coincidence :slight_smile: If one
shouldn’t use CHS, how to determine the proper values? Remember that
W2K does not support IOCTL_DISK_GET_DRIVE_GEOMETRY_EX. What API can I
use to determine the size in LBAs? As long as I can work with a
partition, everything is quite fine, but what about raw access to the
physical device?

I hope you can shed some light on this :slight_smile:

Kind regards,
Andre


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@careful.co.uk To
unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

That is the correct query to use that is Windows 2000 and later compatible.
I don’t care about NT4. I wrote a format program to handle SmartMedia and
large FAT32 partitions on removable drives and it is what I used. I just
wish some of the other commands worked properly for USB & 1394 as they do
for SCSI and ATAPI. Getting the drive’s serial number for a standard ATAPI
drive in a 1394 and/or USB enclosure is far more difficult that it should
be. Also getting the serial number of flash memory in a standard USB reader
is far too hard.

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
I believe ioctl_disk_Query_partition_information sent to partition 0
will get you the size of the whole disk in LBA.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Andre Tertling
Sent: Wednesday, June 22, 2005 10:03 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Getting disk size - W2K and XP

On Tue, 21 Jun 2005 09:08:32 -0700, “David J. Craig” wrote:

>Yes. Not more than 8MB? Try 63 * 256 * 512 as a clue. Don’t use CHS!

Weeell, can you elaborate a bit more about this? I happened to run into
the same eerie thing just yesterday. Funny coincidence :slight_smile: If one
shouldn’t use CHS, how to determine the proper values? Remember that W2K
does not support IOCTL_DISK_GET_DRIVE_GEOMETRY_EX. What API can I use to
determine the size in LBAs? As long as I can work with a partition,
everything is quite fine, but what about raw access to the physical
device?

I hope you can shed some light on this :slight_smile:

Kind regards,
Andre


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Use SPTI and hand-crafted SCSI commands (get capacity/read10) to access raw
volume, don’t use IOCTLs. And don’t ask WHY.

P.S. When you’ll see your boss - say “hello” to him. He still has to pay
around $10K (?) to me and I would be kind enough not to charge him for
answering this particular question from you.

P.P.S. I wonder - who’s that “brigh guy” who supports whole bunch of stuff
me and Andrew Naiden from Daemon Tools wrote for your company? Is it you? If
yes - my congratulations. You’ll have a lot to learn…

Good luck!

Regards,
Anton Kolomyeytsev

CEO, Rocket Division Software

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Andre Tertling
Sent: Wednesday, June 22, 2005 8:03 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Getting disk size - W2K and XP

On Tue, 21 Jun 2005 09:08:32 -0700, “David J. Craig” wrote:

Yes. Not more than 8MB? Try 63 * 256 * 512 as a clue. Don’t use CHS!

Weeell, can you elaborate a bit more about this? I happened to run into the
same eerie thing just yesterday. Funny coincidence :slight_smile: If one shouldn’t use
CHS, how to determine the proper values? Remember that W2K does not support
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX. What API can I use to determine the size
in LBAs? As long as I can work with a partition, everything is quite fine,
but what about raw access to the physical device?

I hope you can shed some light on this :slight_smile:

Kind regards,
Andre


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@voliacable.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

I’ve noticed that in Windows XP Pro setup there is always some space left over if you attempt partition the whole drive. I always thought this was related in some way to the GUID partitioning scheme, but apparently that’s a 64-bit only mechanism.

A little searching eventually lead to something which may be enlightening though.

“Windows XP Professional and Windows 2000 automatically reserve 1 MB or one cylinder, whichever is greater, when creating partitions on a disk.”

This is from
http://www.microsoft.com/resources/documentation/Windows/XP/all/reskit/en-us/Default.asp?url=/resources/documentation/Windows/XP/all/reskit/en-us/prkb_cnc_hsdc.asp

However, dynamic disks can’t be removable, so perhaps this doesn’t apply. But if it works out that the size discrepancy is the size of one cylinder then it might make sense for IOCTL_DISK_GET_DRIVE_GEOMETRY_EX to hide the “untouchable” last cylinder.

Then again I might be completely off base. Oh well.

Richard

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Andre Tertling
Sent: Thursday, 23 June 2005 2:33 AM
To: Windows System Software Devs Interest List
Subject: [Spam Detected] Re:[ntdev] Getting disk size - W2K and XP

On Tue, 21 Jun 2005 09:08:32 -0700, “David J. Craig” wrote:

Yes. Not more than 8MB? Try 63 * 256 * 512 as a clue. Don’t use CHS!

Weeell, can you elaborate a bit more about this? I happened to run
into the same eerie thing just yesterday. Funny coincidence :slight_smile: If one
shouldn’t use CHS, how to determine the proper values? Remember that
W2K does not support. What API can I
use to determine the size in LBAs? As long as I can work with a
partition, everything is quite fine, but what about raw access to the
physical device?

I hope you can shed some light on this :slight_smile:

Kind regards,
Andre


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@dsto.defence.gov.au
To unsubscribe send a blank email to xxxxx@lists.osr.com

Someone else posted the correct solution. Use partition zero and get the
info for it. It works well. I did not write a format utility for internal
drives, but only for external media that can only have one partition.
SmartMedia, now obsolete, requires a specific format to ensure each cluster
does not span a physical block on the media. If you don’t do this most
writes will require two reads, two erases, and two writes for each cluster
being written. That would double the wear on the media because flash memory
can only be written some limited number of times. That is three hundred
thousand times or so the last time I was associated with that area. I just
have a old camera that uses SmartMedia and sometime I wanted to format them
in my reader.

I also have some external USB 2 and 1394 cases that I put hard drives into
or bought intact and I don’t want to use NTFS when I need FAT for Ghost.

That space at the end of internal drives is just to allow them to be made
into dynamic drives and that is for internal non-removable drives only.
Normally Windows formats drives at 63 sectors per track and 255 tracks per
cylinder. That is why you won’t have more than 8MB of data missing from the
drive if you don’t have a MBR that might get it wrong. I frequently use DOS
to fdisk and format FAT32 partitions on my ATAPI and SATA drives when I need
them larger than 32GB.

“McNally, Richard” wrote in message
news:xxxxx@ntdev…
> I’ve noticed that in Windows XP Pro setup there is always some space left
> over if you attempt partition the whole drive. I always thought this was
> related in some way to the GUID partitioning scheme, but apparently that’s
> a 64-bit only mechanism.
>
> A little searching eventually lead to something which may be enlightening
> though.
>
> “Windows XP Professional and Windows 2000 automatically reserve 1 MB or
> one cylinder, whichever is greater, when creating partitions on a disk.”
>
> This is from
> http://www.microsoft.com/resources/documentation/Windows/XP/all/reskit/en-us/Default.asp?url=/resources/documentation/Windows/XP/all/reskit/en-us/prkb_cnc_hsdc.asp
>
> However, dynamic disks can’t be removable, so perhaps this doesn’t apply.
> But if it works out that the size discrepancy is the size of one cylinder
> then it might make sense for IOCTL_DISK_GET_DRIVE_GEOMETRY_EX to hide the
> “untouchable” last cylinder.
>
> Then again I might be completely off base. Oh well.
>
> Richard
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Andre Tertling
> Sent: Thursday, 23 June 2005 2:33 AM
> To: Windows System Software Devs Interest List
> Subject: [Spam Detected] Re:[ntdev] Getting disk size - W2K and XP
>
> On Tue, 21 Jun 2005 09:08:32 -0700, “David J. Craig” wrote:
>
>>Yes. Not more than 8MB? Try 63 * 256 * 512 as a clue. Don’t use CHS!
>
> Weeell, can you elaborate a bit more about this? I happened to run
> into the same eerie thing just yesterday. Funny coincidence :slight_smile: If one
> shouldn’t use CHS, how to determine the proper values? Remember that
> W2K does not support. What API can I
> use to determine the size in LBAs? As long as I can work with a
> partition, everything is quite fine, but what about raw access to the
> physical device?
>
> I hope you can shed some light on this :slight_smile:
>
> Kind regards,
> Andre
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@dsto.defence.gov.au
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>