From 9545123711096d28e0ac75281e4735370b18a485 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Mon, 2 Apr 2018 14:29:02 +0100 Subject: [PATCH] [core] eliminate querying of floppy drives during enumeration --- src/drive.c | 14 ++++++++++++++ src/drive.h | 38 ++++++++++++++++++++++++++++++++------ src/rufus.rc | 10 +++++----- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/drive.c b/src/drive.c index 10ec2fd4..d881db86 100644 --- a/src/drive.c +++ b/src/drive.c @@ -53,6 +53,8 @@ const GUID PARTITION_SYSTEM_GUID = { 0xc12a7328L, 0xf81f, 0x11d2, {0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b} }; #endif +PF_TYPE_DECL(NTAPI, NTSTATUS, NtQueryVolumeInformationFile, (HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FS_INFORMATION_CLASS)); + /* * Globals */ @@ -401,10 +403,14 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT* BOOL r = FALSE; HANDLE hDrive = INVALID_HANDLE_VALUE; UINT _drive_type; + IO_STATUS_BLOCK io_status_block; + FILE_FS_DEVICE_INFORMATION file_fs_device_info; int i = 0, drive_number; char *drive, drives[26*4 + 1]; /* "D:\", "E:\", etc., plus one NUL */ char logical_drive[] = "\\\\.\\#:"; + PF_INIT(NtQueryVolumeInformationFile, Ntdll); + if (drive_letters != NULL) drive_letters[0] = 0; if (drive_type != NULL) @@ -451,6 +457,14 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT* continue; } + // Eliminate floppy drives + if ((pfNtQueryVolumeInformationFile != NULL) && + (pfNtQueryVolumeInformationFile(hDrive, &io_status_block, &file_fs_device_info, + sizeof(file_fs_device_info), FileFsDeviceInformation) == NO_ERROR) && + (file_fs_device_info.Characteristics & FILE_FLOPPY_DISKETTE) ) { + continue; + } + drive_number = GetDriveNumber(hDrive, logical_drive); safe_closehandle(hDrive); if (drive_number == DriveIndex) { diff --git a/src/drive.h b/src/drive.h index d41b624e..806ada39 100644 --- a/src/drive.h +++ b/src/drive.h @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * Drive access function calls - * Copyright © 2011-2016 Pete Batard + * Copyright © 2011-2018 Pete Batard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +19,8 @@ #include #include -#include // for DISK_GEOMETRY +#include // for DISK_GEOMETRY +#include #pragma once @@ -31,10 +32,28 @@ #define IOCTL_MOUNTMGR_SET_AUTO_MOUNT \ CTL_CODE(MOUNTMGRCONTROLTYPE, 16, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) -#define XP_MSR 0x01 -#define XP_EFI 0x02 -#define XP_UEFI_NTFS 0x04 -#define XP_COMPAT 0x08 +#define XP_MSR 0x01 +#define XP_EFI 0x02 +#define XP_UEFI_NTFS 0x04 +#define XP_COMPAT 0x08 + +#define FILE_FLOPPY_DISKETTE 0x00000004 + +#if !defined(__MINGW32__) +typedef enum _FSINFOCLASS { + FileFsVolumeInformation = 1, + FileFsLabelInformation, + FileFsSizeInformation, + FileFsDeviceInformation, + FileFsAttributeInformation, + FileFsControlInformation, + FileFsFullSizeInformation, + FileFsObjectIdInformation, + FileFsDriverPathInformation, + FileFsVolumeFlagsInformation, + FileFsMaximumInformation +} FS_INFORMATION_CLASS, *PFS_INFORMATION_CLASS; +#endif /* We need a redef of these MS structure */ typedef struct { @@ -49,6 +68,13 @@ typedef struct { DISK_EXTENT Extents[8]; } VOLUME_DISK_EXTENTS_REDEF; +#if !defined(__MINGW32__) +typedef struct _FILE_FS_DEVICE_INFORMATION { + DEVICE_TYPE DeviceType; + ULONG Characteristics; +} FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION; +#endif + static __inline BOOL UnlockDrive(HANDLE hDrive) { DWORD size; return DeviceIoControl(hDrive, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL); diff --git a/src/rufus.rc b/src/rufus.rc index 9ac52f91..1b66b6ab 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 232, 326 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 3.0.1238" +CAPTION "Rufus 3.0.1239" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -371,8 +371,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 2,18,1238,0 - PRODUCTVERSION 2,18,1238,0 + FILEVERSION 2,18,1239,0 + PRODUCTVERSION 2,18,1239,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -389,13 +389,13 @@ BEGIN BEGIN VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "2.18.1238" + VALUE "FileVersion", "2.18.1239" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "OriginalFilename", "rufus.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "2.18.1238" + VALUE "ProductVersion", "2.18.1239" END END BLOCK "VarFileInfo"