Alright...the one well known DISKIO problem/challenge stems due to the fact that any removable storage devices, these being primarily connected through USB, cause DISKIO to error when no actual media is mounted.
AFAIU at the start of execution DISKIO simply asks DosPhysicalDisk API for a number of partitionable disks using this API call:
DosPhysicalDisk (INFO_COUNT_PARTITIONABLE_DISKS, &nDisks, sizeof(nDisks), 0, 0)
Sure enough, ALL devices defined as storage media, whether these are currently mounted and accessible, show up in that list.
Further on, DosPhysicalDisk is called again but this time in order to obtain the device handle for DosDevIOCtl32 calls later on:
DosPhysicalDisk (INFO_GETIOCTLHANDLE, &usPhysical, sizeof(usPhysical)
OK, so far so good, only one caveat here: "...The handle returned for the specified partitionable disk can only be used with the DosDevIOCtl function for the Category 09h Physical Disk Control IOCtl Commands...".
Now DISKIO proceeds to query the device parameters by calling DosDevIOCtl32:
DosDevIOCtl32 (&dpb, sizeof(dpb), &bCmd, sizeof(bCmd), DSK_GETDEVICEPARAMS, hfHandle)
Here is the thing: I think it ONLY gets the parameters but doesn't actually do any checking to see if the media can actually be accessed. It assumes that since the storage device was found it can therefore be tested.
What I am not sure about however is how to interpret the meaning of the logic that decides whether to retrieve the DEVICEPARAMETERBLOCK or BIOSPARAMETERBLOCK record structures.
In other words, the IF statement check "if (hfHandle & PHYSICAL)" below, where we have the following defines:
#define PHYSICAL 0x1000
#define CDROM 0x2000
...does that mean that hfHandle will be BIT anded with PHYSICAL and if they MATCH the device we are querying must therefore be a mounted storage media?
I see we distinguish between PHYSICAL & CDROM, perhaps USB attached should have a different define as well?
// now check if we have a valid physical file handle
if (hfHandle & PHYSICAL)
{
// get the info for DEVICEPARAMETERBLOCK
if (DosDevIOCtl32 (&dpb, sizeof(dpb), &bCmd, sizeof(bCmd), DSK_GETDEVICEPARAMS, hfHandle))
{
DosPhysicalDisk (INFO_FREEIOCTLHANDLE, NULL, 0, &usPhysical, sizeof(usPhysical));
return (-1);
}
*lSectors = dpb.cSectorsPerTrack;
*lTracks = dpb.cCylinders;
*lSides = dpb.cHeads;
*lSector = DSK_DEFAULT_SECTOR_SIZE;
#ifdef DEBUG
printf("\n DEBUG => found the disk and storing in DEVICEPARAMETERBLOCK...\n");
#endif /* DEBUG */
}
else
{
// get the info for BIOSPARAMETERBLOCK
if (DosDevIOCtl32 (&bpb, sizeof(bpb), &bCmd, sizeof(bCmd), DSK_GETDEVICEPARAMS, hfHandle))
{
DosClose (hfHandle);
return (-1);
}
*lSectors = bpb.usSectorsPerTrack;
*lTracks = bpb.cCylinders;
*lSides = bpb.cHeads;
*lSector = bpb.usBytesPerSector;
#ifdef DEBUG
printf("\n DEBUG => found the disk and storing in BIOSPARAMETERBLOCK...\n");
#endif /* DEBUG */
}
Anyways...a LOT of detail there, and so I'm going to run some debug sessions to understand this a tad better. In the meantime, any hints would of course be greatly appreciated!!!