IOCTL_DISK_GET_DRIVE_GEOMETRY failed for CD-ROM

  • Thread starter Thread starter Igor
  • Start date Start date
I

Igor

Hi,
I'm trying to get Disk Geometry for the CD-ROM
drive. I'm getting the DeviceIoControl failing
with error code 1.
For any other device - hard drive partition "c:",
floppy "a:" or just "\\PhysicalDrive0" it works.
Below is the code I'm using. I'm running Win2000
with SP 3.
Any help would be greatly appreciated.

Igor.


string disk = "d:";
disk = "\\\\.\\"+disk;
hFile = CreateFile( disk.c_str(),

GENERIC_READ ,

FILE_SHARE_READ|FILE_SHARE_WRITE,

0,

OPEN_EXISTING,

0,

NULL);

if( hFile == INVALID_HANDLE_VALUE ){
res = GetLastError();
cerr << "CreateFile for CD failed: " <<
res << endl;
return 1;
}

int ret = 0;
DWORD offset = 0;
DWORD dwNotUsed;
DISK_GEOMETRY dgCDROM;
PREVENT_MEDIA_REMOVAL pmrLockCDROM;

BOOL stat = TRUE;
DWORD bytesTotal = 0;
DWORD NumberOfBytesRead;
DWORD NumberOfBytesWrote;
DWORD length ;
// Get sector size of compact disc
if( !DeviceIoControl (hFile,
IOCTL_DISK_GET_DRIVE_GEOMETRY ,
NULL, 0, &dgCDROM, sizeof(dgCDROM),
&dwNotUsed, NULL) ){
res = GetLastError();
cerr << "DeviceIoControl failed: " << res << endl;
ret = 1;
goto End;
}
 
Back
Top