Discussion:
IOCTL_DISK_GET_DRIVE_GEOMETRY failed for CD-ROM
(too old to reply)
Igor Polevoy
2003-09-09 09:31:18 UTC
Permalink
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;
}
Ralf Buschmann
2003-09-09 11:04:17 UTC
Permalink
Post by Igor Polevoy
I'm trying to get Disk Geometry for the CD-ROM
drive. I'm getting the DeviceIoControl failing
with error code 1.
Well, that's ERROR_INVALID_FUNCTION. Obviously
IOCTL_DISK_GET_DRIVE_GEOMETRY is only for fixed hard disks. Try
IOCTL_STORAGE_GET_MEDIA_TYPES instead.

Ralf.
Jerry Coffin
2003-09-10 05:41:50 UTC
Permalink
Post by Igor Polevoy
Hi,
I'm trying to get Disk Geometry for the CD-ROM
drive. I'm getting the DeviceIoControl failing
with error code 1.
This isn't surprising: a CD-ROM simply does not have a "geometry" on the
sense that a normal hard disk or floppy disk does. A CD doesn't really
have separate tracks and sectors like a hard drive. It simply has one
long spiral all the way from the inside of the disk to the outside. For
the sanity of the computer, this long stream of data is broken up into a
(large) number of logical sectors, but that's about all the "geometry"
there is.
--
Later,
Jerry.

The universe is a figment of its own imagination.
Igor Polevoy
2003-09-10 11:11:40 UTC
Permalink
Post by Jerry Coffin
Post by Igor Polevoy
Hi,
I'm trying to get Disk Geometry for the CD-ROM
drive. I'm getting the DeviceIoControl failing
with error code 1.
This isn't surprising: a CD-ROM simply does not have a "geometry" on the
sense that a normal hard disk or floppy disk does. A CD doesn't really
have separate tracks and sectors like a hard drive. It simply has one
long spiral all the way from the inside of the disk to the outside. For
the sanity of the computer, this long stream of data is broken up into a
(large) number of logical sectors, but that's about all the "geometry"
there is.
Yes, I understand that this is probably the problem.
The thing is that all the MSDN articles I found state that it should work for
CD as well as for hard drives. Did it work for anyone? Maybe in other Windows
versions?
Actually I'm interested do get the CD parameters: sector size , number of
sectors and tracks and TOC.

Many thanks,
Igor.
Maxim S. Shatskih
2003-09-10 21:17:11 UTC
Permalink
Post by Igor Polevoy
Actually I'm interested do get the CD parameters: sector size , number of
sectors and tracks and TOC.
IOCTL_CDROM_READ_TOC can help.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
***@storagecraft.com
http://www.storagecraft.com
Jerry Coffin
2003-09-11 04:06:04 UTC
Permalink
In article <***@posting.google.com>,
***@intel.com says...

[ ... ]
Post by Igor Polevoy
Actually I'm interested do get the CD parameters: sector size , number of
sectors and tracks and TOC.
The sector size for any ISO 9660 compatible CD-ROM is always the same
(2048 bytes). AFAIK, the rest of the information is not available
directly from Windows -- the easiest way to get it is to open the disk
for raw reading, and chase through the structure to get to the TOC on
your own.

The information to do this is available for free as ECMA standard 119
(which has the same contents as ISO 9660). The only weakness is that
this was written more to be absolutely explicit than to be easy to read
or understand -- the information's all there, but it's not always easy
to dig out what you want. A single diagram showing what points to where
would have been almost unbelievably helpful, but it doesn't contain such
a thing...
--
Later,
Jerry.

The universe is a figment of its own imagination.
Alexander Grigoriev
2003-09-12 03:23:10 UTC
Permalink
Use IOCTL_CDROM_GET_DRIVE_GEOMETRY, and IOCTL_CDROM_READ_TOC(EX) (maybe
after IOCTL_CDROM_GET_LAST_SESSION).
Post by Igor Polevoy
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;
}
Igor Polevoy
2003-09-14 10:37:18 UTC
Permalink
Post by Alexander Grigoriev
Use IOCTL_CDROM_GET_DRIVE_GEOMETRY, and IOCTL_CDROM_READ_TOC(EX) (maybe
after IOCTL_CDROM_GET_LAST_SESSION).
Hi,
thanks all for your help. Things are started working - I use
IOCTL_CDROM_GET_DRIVE_GEOMETRY and then IOCTL_CDROM_READ_TOC_EX to get the TOC.
It works also for my Win2k, despite the fact that IOCTL_CDROM_READ_TOC_EX is
declared only in the WinXP DDK headers.

What the IOCTL_CDROM_GET_LAST_SESSION does? The DDK documentation I have says
only that "The driver determines whether a disc is multisession. It compares
the first and last session and the starting track of the last session".
There is also no info of what are the DeviceIoControl params. for it?


Many thanks,
Igor.
Alexander Grigoriev
2003-09-14 14:28:34 UTC
Permalink
Without GET_LAST_SESSION, READ_TOC will only return first session
information. See cdrom.sys sources for reference.
Post by Igor Polevoy
Post by Alexander Grigoriev
Use IOCTL_CDROM_GET_DRIVE_GEOMETRY, and IOCTL_CDROM_READ_TOC(EX) (maybe
after IOCTL_CDROM_GET_LAST_SESSION).
Hi,
thanks all for your help. Things are started working - I use
IOCTL_CDROM_GET_DRIVE_GEOMETRY and then IOCTL_CDROM_READ_TOC_EX to get the TOC.
It works also for my Win2k, despite the fact that IOCTL_CDROM_READ_TOC_EX is
declared only in the WinXP DDK headers.
What the IOCTL_CDROM_GET_LAST_SESSION does? The DDK documentation I have says
only that "The driver determines whether a disc is multisession. It compares
the first and last session and the starting track of the last session".
There is also no info of what are the DeviceIoControl params. for it?
Many thanks,
Igor.
Loading...