Check floppy drive

To get removable drives, I used the GetDriveType () function

Can I check if the disk is a floppy disk or not?

Please let me know your suggestions about this.

Thanks for any help

+3
source share
3 answers

Internally, Microsoft Windows holds the so-called feature flags (defined in wdm.h) for each device. If the device corresponding to the letter of the disk has a flag FILE_FLOPPY_DISKETTE, then the disk is a floppy disk:

//
// Define the various device characteristics flags (defined in wdm.h)
//
#define FILE_REMOVABLE_MEDIA                    0x00000001
#define FILE_READ_ONLY_DEVICE                   0x00000002
#define FILE_FLOPPY_DISKETTE                    0x00000004
#define FILE_WRITE_ONCE_MEDIA                   0x00000008
#define FILE_REMOTE_DEVICE                      0x00000010
#define FILE_DEVICE_IS_MOUNTED                  0x00000020
#define FILE_VIRTUAL_VOLUME                     0x00000040
#define FILE_AUTOGENERATED_DEVICE_NAME          0x00000080
#define FILE_DEVICE_SECURE_OPEN                 0x00000100
#define FILE_CHARACTERISTIC_PNP_DEVICE          0x00000800
#define FILE_CHARACTERISTIC_TS_DEVICE           0x00001000
#define FILE_CHARACTERISTIC_WEBDAV_DEVICE       0x00002000

, API. NtQueryVolumeInformationFile ntdll.dll. Windows7 - 32- , API.

UPDATE: NtQueryVolumeInformationFile IOCTL_STORAGE_GET_DEVICE_NUMBER IOCTL_STORAGE_QUERY_PROPERTY, .

2: , GetDriveType . , GetDriveType , FILE_REMOVABLE_MEDIA. SetupDiGetDeviceRegistryProperty SPDRP_REMOVAL_POLICY . CM_REMOVAL_POLICY_EXPECT_SURPRISE_REMOVAL CM_REMOVAL_POLICY_EXPECT_ORDERLY_REMOVAL, Windows7 - 32- .

+4

- .

+2

The best chance that I know is to check if the drive letter is A: or B :. I have not tried connecting three USB floppy drives to a single PC, so I don’t know if a floppy disk can have a higher drive letter. Other quirks are possible. But this test is almost reliable enough for some purposes.

-1
source

Source: https://habr.com/ru/post/1752592/


All Articles