IOCTL_DISK_GET_DRIVE_GEOMETRY failed for CD-ROM

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top