I'm writing a software to communicate to a recording device that if connected to the pc via USB emulates a mass storage device. Some special features are accessed on that device by communicating on a special sector on that device. To get access on that sector on windows I need to:
- open a handle to the newly arrived drive
- fetch the physical drive number via deviceIOControl and IOCTLVolumeGetVolumeDiskExtents
- Open the physicaldrive found there and read and write to a special sector.
So far so good - everything is working fine but getting the first initial volume handle can take quite long.
what I'm doing is basically this:
var hdl : THandle;
start, stop, freq : INT64;
begin
hdl := INVALID_HANDLE_VALUE;
QueryPerformanceFrequency(freq);
QueryPerformanceCounter(start);
fHandle := CreateFile( PChar('\\.\' + fDriveLetter + ':'),
GENERIC_READ,
FILE_SHARE_WRITE or FILE_SHARE_READ,
nil,
OPEN_EXISTING,
0,
0);
QueryPerformanceCounter(stop);
OutputDebugString( PChar( Format('Open drive took %.3fms', [(stop - start)/freq*1000]) ));
if hdl = INVALID_HANDLE_VALUE then
raise EVolumeError.Create( 'Cannot Open Drive: '+fDriveLetter+#13#10+
SysErrorMessage(GetLastError));
end;
This call can take seconds right until the drive arrived.
My guess is that windows first reads the complete FAT which takes long on this little recording device which actually always creates files that reserves the complete disk space (4GB). Anyone has an idea how to speed up that process? I never need to read anything from the file system but rather I need the handle the get information about the underlying physicaldrive number and from there I do my read and write operations.