From: Maxim S. Shatskih on
Once more - in Windows, if the disk is not registered in BIOS, then H=63
and S=255.
Also, if the disk is registered in BIOS as LBA, then once again - H=63 and
S=255 by definition.

CHS values are no more used for IO since around 2000, neither in Windows
nor in Linux. Their only use is to fill the obsolete MBR values. BTW, Linux
boots and works fine with nonsense CHS values in the MBR :-) it was Linux
kernel 2.2.

Why do you ever need CHS? It is absolutely sure that, for a flash drive,
they are fake, used only to satisfy MS-DOS. All real IO is done using LBA.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim(a)storagecraft.com
http://www.storagecraft.com

<alexbohner(a)yahoo.com> wrote in message
news:1138021986.336106.86960(a)g43g2000cwa.googlegroups.com...
> Ok, so if the MBR is effectively obsolete on removable media under
> Windows, which explains my findings, what is the best method for
> determining the equivalent 'CHS' and partition information from the USB
> disk?
>
> Thanks,
> Alex
>

From: alexbohner on
Thanks for the clarification. I think I jumped the gun and didn't ask
the proper questions to resolve the problem.

- Assuming H=63 and S=255, will the calulated disk size always be
correct when using the cylinder count found with
IOCTL_DISK_GET_DRIVE_GEOMETRY?

- Can a RemovableMedia hold multiple partitions? If there is no MBR,
yet it works fine in both Linux and Windows machines I'm not sure how
this would be handled?

- Is it possible for a RemovableMedia device (or partition) to be set
active (bootable) like a fixed disk?

- Without an MBR, what is the proper method for reading the partition
information from the disk (eg, type, size, sectors, etc)?

Thanks,
Alex

From: Maxim S. Shatskih on
> - Assuming H=63 and S=255, will the calulated disk size always be
> correct when using the cylinder count found with
> IOCTL_DISK_GET_DRIVE_GEOMETRY?

A bit incorrect.

IOCTL_DISK_GET_PARTITION_INFO (sent to the single partition device, and not to
the whole disk) is a better way to get the disk size at the level below the
filesystem.

At filesystem level, you have GetDiskFreeSpaceEx (by name) and undocumented
NtQueryVolumeInformationFile/FileFsSizeInformation (by handle). In fact,
GetDiskFreeSpaceEx depends upon NtQueryVolumeInformationFile internally.

> - Can a RemovableMedia hold multiple partitions?

Yes, but Windows will ignore all but first :) if you have DDK - see the
comments in Disk driver source - they only create 1 partition device object for
removable media.

If the media has no MBR - then IoReadPartitionTable code below Disk will "cook"
the partition table information with 1 huge partition. This is called
"super-floppy".

If the media has MBR - then IoReadPartitionTable will really translate the MBR
to some Windows-defined structures (common to all possible on-disk PT layouts).

Then Disk will interpret the data from IoReadPartitionTable and create the
child device objects for partitions, and, for removable media, it will always
create 1.

Also the removable media devices cannot participate in software RAIDs, and
their drive letters (and volume mount points) depend only on their bus
connection position. For fixed disks, the partition drive letters depends on
MBR signature value and the partition start offset, and NOT on the bus
connection position of the drive.

Dunno on Linux.

> - Is it possible for a RemovableMedia device (or partition) to be set
> active (bootable) like a fixed disk?

Depends on BIOS mainly.

> - Without an MBR, what is the proper method for reading the partition
> information from the disk (eg, type, size, sectors, etc)?

Without an MBR, IoReadPartitionTable will respond "the disk has 1 partition of
the whole disk size". Then the Disk.sys driver will do the same.

Also IOCTL_SCSI_PASS_THROUGH with SCSIOP_READ_CAPACITY :) this is even below
the partition queries and work for all connection buses. It is mapped to
bus-specific hardware "get size" request. For SCSI, it is not mapped at all :)

Also for IDE/ATA/SATA only, you can read the 512 bytes of disk IDENTIFY data
(this is IOCTL_SCSI_MINIPORT/SMART_RCV_DRIVE_DATA, do not be confused with SCSI
and SMART here - this couple works from NT4 up for SMARTless IDE disks) - and
the UserAddressableSectors field (defined by ATA spec) is the disk size.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim(a)storagecraft.com
http://www.storagecraft.com