Actual Combat DeviceIoControl Series II: Get Floppy/hard disk/CD parameters

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.