If you're talking about a USB mass storage device without any assigned drive letter then it's just a volume without a mount point. You'll need to mount the volume before reading/writing it.
You can use the Volume Management Functions :
Here is a quickly-written example in C that list all the existing volumes, mount the unmounted ones and show some information about each volume :
char volumeID[256], volumePathName[256], volumeName[256], volumeFS[256];
char newMountPoint[4] = " :\\";
unsigned long volumeSerialNumber;
unsigned long size;
HANDLE handle = FindFirstVolume(volumeID, 256);
do {
printf("Volume GUID = %s\n", volumeID);
GetVolumePathNamesForVolumeName(volumeID, volumePathName, 256, &size);
if(strlen(volumePathName) == 0) {
printf("Not mounted\n");
newMountPoint[0] = firstFreeLetter();
if(SetVolumeMountPoint(newMountPoint, volumeID)) {
GetVolumePathNamesForVolumeName(volumeID, volumePathName, 256, &size);
printf("Now mounted on %s\n", volumePathName);
}
}
else {
printf("Mounted on %s\n", volumePathName);
}
GetVolumeInformation(volumePathName, volumeName, 256, &volumeSerialNumber,
NULL, NULL, volumeFS, 256);
printf("Volume name = %s, FS = %s, serial = %lu\n\n",
volumeName, volumeFS, volumeSerialNumber);
}while(FindNextVolume(handle, volumeID, 256));
FindVolumeClose(handle);
I deliberetely simplify this example, but a volume can have multiple mount points (volumePathName
is actually a multi-string). It uses this function to get the first available letter (after 'C'
) to mount a drive :
char firstFreeLetter() {
unsigned long freeLetters = GetLogicalDrives();
if(freeLetters < 4) return 0;
char letter = 'C';
for(unsigned long i=4; (freeLetters & i) != 0; ++letter, i <<= 1);
return letter;
}