Q in the MSDN demo, the device name replaced "A:" Take a disk parameter, first read the disk with the Explorer, and then run the program can be successful, but a disk after the failure; change to "CDROM0"
Take CDROM parameters, no matter what. How can we solve this problem?
A takes the floppy disk parameter to read the formatted information from the floppy disk, that is, the read operation must be performed, which is different from the hard disk. You can change the access mode in CreateFile to Generic_read.
Ioctl_disk_get_drive_geometry this I/O control code, for floppy disk and hard disk, but for some removable media such as cd/dvd-rom, tape and so on no use. To take CDROM parameters, you have to do another. IOCTL_STORAGE_GET_MEDIA_TYPES_EX can help us solve the problem.
Q what type of input and output data format do I need to use these I/O control codes?
A DeviceIoControl do not need to enter data when using these two control codes.
Ioctl_disk_get_drive_geometry directly outputs a DISK_GEOMETRY structure:
typedef struct _DISK_GEOMETRY {
Large_integer cylinders; Number of cylinders
Media_type mediatype; Media type
DWORD Trackspercylinder; Number of tracks per cylinder
DWORD Sectorspertrack; Number of sectors per track
DWORD BytesPerSector; Number of bytes per sector
} disk_geometry;
IOCTL_STORAGE_GET_MEDIA_TYPES_EX output a get_media_types structure:
typedef struct _GET_MEDIA_TYPES {
DWORD DeviceType; Device type
DWORD Mediainfocount; Number of media information bars
Device_media_info Mediainfo[1]; Media information
} get_media_types;
Let's take a look at the definition of the DEVICE_MEDIA_INFO structure:
typedef struct _DEVICE_MEDIA_INFO {
Union {
struct {
Large_integer cylinders; Number of cylinders
Storage_media_type mediatype; Media type
DWORD Trackspercylinder; Number of tracks per cylinder
DWORD Sectorspertrack; Number of sectors per track
DWORD BytesPerSector; Number of bytes per sector
DWORD Numbermediasides; Number of media surface
DWORD Mediacharacteristics; Media characteristics
} DiskInfo; Hard drive information struct {
Large_integer cylinders; Number of cylinders
Storage_media_type mediatype; Media type
DWORD Trackspercylinder; Number of tracks per cylinder
DWORD Sectorspertrack; Number of sectors per track
DWORD BytesPerSector; Number of bytes per sector
DWORD Numbermediasides; Number of media surface
DWORD Mediacharacteristics; Media characteristics
} Removablediskinfo; "Removable disk" information
struct {
Storage_media_type mediatype; Media type
DWORD Mediacharacteristics; Media characteristics
DWORD currentblocksize; Size of the Block
} Tapeinfo; Tape information
} DeviceSpecific;
} Device_media_info;
where the CD-ROM belongs to the range of removable disks. Note that the GET_MEDIA_TYPES structure itself defines only one device_media_info, and the extra device_media_info requires additional space immediately following this structure.