How does HxD raw-read floppies?

General comments that are neither bug reports nor feature requests.
Post Reply
Videogamer555
Posts: 3
Joined: 16 Nov 2020 04:42

How does HxD raw-read floppies?

Post by Videogamer555 »

I posted this before but I think I posted it in the wrong section. So I've moved it here.

I'm trying to make my own software for reading raw sectors from floppy disks. I'm curious what API functions you use to raw-read from the floppy. I know with a harddrive I can read by opening it like a file with the function CreateFileA and using the file name "\\.\PhysicalDrive0" to read the whole disk (even before the first partition) or "\\.\C:" to read just the main partition. Using "\\.\PhysicalDrive0" is equivalent to "Physical disks, Hard Disk 1" in HxD, and "\\.\C:" is equivalent to "Logical disks, C:" in HxD.

But now what about floppies? I know that I can use CreateFileA and "\\.\A:" is equivalent to "Logical disks, Floppy Disk 1" in HxD, but I can't figure out how HxD accesses the PHYSICAL floppy drive. I know in HxD it's called "Logical disks, Floppy Disk 1", but what is the device name for this, as far as Windows API is concerned? I know there must be some name like "\\.\DeviceName" that corresponds to the floppy disk drive, but I don't know what that name is.

Maël
Site Admin
Posts: 1245
Joined: 12 Mar 2005 14:15

Re: How does HxD raw-read floppies?

Post by Maël »

Videogamer555 wrote:
17 Nov 2020 00:49
But now what about floppies? I know that I can use CreateFileA and "\\.\A:" is equivalent to "Logical disks, Floppy Disk 1" in HxD, but I can't figure out how HxD accesses the PHYSICAL floppy drive. I know in HxD it's called "Logical disks, Floppy Disk 1", but what is the device name for this, as far as Windows API is concerned? I know there must be some name like "\\.\DeviceName" that corresponds to the floppy disk drive, but I don't know what that name is.
There is no distinction like this under Windows NT and up. That's also why Windows NT is limited in the type of disk formats it can read, while there is more flexibility under Win9x/DOS. Edit: The major difference in HxD (in its WinNT+ version) between physical and logical floppies, is that it checks whether the filesystem on the floppy is recognized by Windows and if it can access it, if so, it will display it as logical disk and physical disk, otherwise just physical.

You can have a look at all the objects available under Windows NT+ with WinObj from Sysinternals: https://docs.microsoft.com/sysinternals ... ads/winobj

Under GLOBAL?? you will find all the objects that are accessible from "DOS" applications or the DOS namespace as the Windows API likes to call it, eventhough many objects there never existed under DOS, and it's really the Win32 namespace (which is different from the lower level NT namespace). You will find things like COM1, HarddiskVolume1, PhysicalDrive0, C:, and Floppy0 there. For USB-floppies it might be a bit different, they don't allow raw access under DOS and other systems, either.

I don't have a floppy installed anymore so this is just from memory, but I think the "original" device could be found under \Device\Floppy0, and A: would simply link to it from GLOBAL?? which is an alias for \\.\
That's why you have to enter \\.\PhysicalDrive0 which is the same as \GLOBAL??\PhysicalDrive0 which in turn maps to \Device\Harddisk0\DR0 .
As far as I know, you can only access objects from GLOBAL?? directly, otherwise you need to map it first with DefineDosDevice:
https://docs.microsoft.com/en-us/window ... dosdevicew

https://docs.microsoft.com/en-us/window ... dosdevicew

I found more info on the Device/NT namespace, here, which expands a bit on what I wrote above from memory (nice that they mention WinObj, I don't think they did when I made my research the first time):
https://docs.microsoft.com/en-us/window ... namespaces


If you find any way to fully access physical floppies under NT+, I'd appreciate if you report back here.

Videogamer555
Posts: 3
Joined: 16 Nov 2020 04:42

Re: How does HxD raw-read floppies?

Post by Videogamer555 »

Maël wrote:
17 Nov 2020 20:02
Videogamer555 wrote:
17 Nov 2020 00:49
But now what about floppies? I know that I can use CreateFileA and "\\.\A:" is equivalent to "Logical disks, Floppy Disk 1" in HxD, but I can't figure out how HxD accesses the PHYSICAL floppy drive. I know in HxD it's called "Logical disks, Floppy Disk 1", but what is the device name for this, as far as Windows API is concerned? I know there must be some name like "\\.\DeviceName" that corresponds to the floppy disk drive, but I don't know what that name is.
There is no distinction like this under Windows NT and up. That's also why Windows NT is limited in the type of disk formats it can read, while there is more flexibility under Win9x/DOS. Edit: The major difference in HxD (in its WinNT+ version) between physical and logical floppies, is that it checks whether the filesystem on the floppy is recognized by Windows and if it can access it, if so, it will display it as logical disk and physical disk, otherwise just physical.

You can have a look at all the objects available under Windows NT+ with WinObj from Sysinternals: https://docs.microsoft.com/sysinternals ... ads/winobj

Under GLOBAL?? you will find all the objects that are accessible from "DOS" applications or the DOS namespace as the Windows API likes to call it, eventhough many objects there never existed under DOS, and it's really the Win32 namespace (which is different from the lower level NT namespace). You will find things like COM1, HarddiskVolume1, PhysicalDrive0, C:, and Floppy0 there. For USB-floppies it might be a bit different, they don't allow raw access under DOS and other systems, either.

I don't have a floppy installed anymore so this is just from memory, but I think the "original" device could be found under \Device\Floppy0, and A: would simply link to it from GLOBAL?? which is an alias for \\.\
That's why you have to enter \\.\PhysicalDrive0 which is the same as \GLOBAL??\PhysicalDrive0 which in turn maps to \Device\Harddisk0\DR0 .
As far as I know, you can only access objects from GLOBAL?? directly, otherwise you need to map it first with DefineDosDevice:
https://docs.microsoft.com/en-us/window ... dosdevicew

https://docs.microsoft.com/en-us/window ... dosdevicew

I found more info on the Device/NT namespace, here, which expands a bit on what I wrote above from memory (nice that they mention WinObj, I don't think they did when I made my research the first time):
https://docs.microsoft.com/en-us/window ... namespaces


If you find any way to fully access physical floppies under NT+, I'd appreciate if you report back here.

When HxD is enumerating floppy drives, does it use DefineDosDevice (or other Windows API) to get the physical device? Or does HxD just use its own function to check if there is a recognizable system is present on the floppy, and then decide whether or not to list it as a logical disk or not, based on that check?

Maël
Site Admin
Posts: 1245
Joined: 12 Mar 2005 14:15

Re: How does HxD raw-read floppies?

Post by Maël »

The latter. You would want to enumerate the volumes, too.

https://docs.microsoft.com/en-us/window ... ng-volumes

Post Reply