2014-01-05 01:39:41 +00:00
|
|
|
/*
|
|
|
|
* Rufus: The Reliable USB Formatting Utility
|
|
|
|
* Drive access function calls
|
2016-02-25 18:21:31 +00:00
|
|
|
* Copyright © 2011-2016 Pete Batard <pete@akeo.ie>
|
2014-01-05 01:39:41 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdint.h>
|
2016-02-25 18:21:31 +00:00
|
|
|
#include <winioctl.h> // for DISK_GEOMETRY
|
2014-01-05 01:39:41 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-11-11 19:17:39 +00:00
|
|
|
#define RUFUS_EXTRA_PARTITION_TYPE 0xea
|
|
|
|
#define MOUNTMGRCONTROLTYPE ((ULONG)'m')
|
|
|
|
#define MOUNTMGR_DOS_DEVICE_NAME "\\\\.\\MountPointManager"
|
|
|
|
#define IOCTL_MOUNTMGR_QUERY_AUTO_MOUNT \
|
2016-02-25 18:21:31 +00:00
|
|
|
CTL_CODE(MOUNTMGRCONTROLTYPE, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
2014-11-11 19:17:39 +00:00
|
|
|
#define IOCTL_MOUNTMGR_SET_AUTO_MOUNT \
|
|
|
|
CTL_CODE(MOUNTMGRCONTROLTYPE, 16, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
|
2014-01-14 20:10:09 +00:00
|
|
|
|
2015-01-20 02:56:17 +00:00
|
|
|
#define XP_MSR 0x01
|
|
|
|
#define XP_EFI 0x02
|
2015-03-16 20:34:04 +00:00
|
|
|
#define XP_UEFI_NTFS 0x04
|
2015-01-20 21:50:24 +00:00
|
|
|
#define XP_COMPAT 0x08
|
2015-01-20 02:56:17 +00:00
|
|
|
|
2014-02-27 19:53:53 +00:00
|
|
|
/* We need a redef of these MS structure */
|
|
|
|
typedef struct {
|
|
|
|
DWORD DeviceType;
|
|
|
|
ULONG DeviceNumber;
|
|
|
|
ULONG PartitionNumber;
|
|
|
|
} STORAGE_DEVICE_NUMBER_REDEF;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DWORD NumberOfDiskExtents;
|
|
|
|
// The one from MS uses ANYSIZE_ARRAY, which can lead to all kind of problems
|
|
|
|
DISK_EXTENT Extents[8];
|
|
|
|
} VOLUME_DISK_EXTENTS_REDEF;
|
|
|
|
|
2016-02-25 18:21:31 +00:00
|
|
|
static __inline BOOL UnlockDrive(HANDLE hDrive) {
|
|
|
|
DWORD size;
|
|
|
|
return DeviceIoControl(hDrive, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL);
|
|
|
|
}
|
|
|
|
#define safe_unlockclose(h) do {if ((h != INVALID_HANDLE_VALUE) && (h != NULL)) {UnlockDrive(h); CloseHandle(h); h = INVALID_HANDLE_VALUE;}} while(0)
|
|
|
|
|
|
|
|
/* Current drive info */
|
|
|
|
typedef struct {
|
|
|
|
LONGLONG DiskSize;
|
2016-05-23 11:19:11 +00:00
|
|
|
DWORD DeviceNumber;
|
|
|
|
DWORD SectorsPerTrack;
|
|
|
|
DWORD SectorSize;
|
2016-07-07 17:13:01 +00:00
|
|
|
DWORD FirstDataSector;
|
2016-05-23 11:19:11 +00:00
|
|
|
MEDIA_TYPE MediaType;
|
2016-02-25 18:21:31 +00:00
|
|
|
int PartitionType;
|
|
|
|
int nPartitions; // number of partitions we actually care about
|
|
|
|
int FSType;
|
2016-05-23 11:19:11 +00:00
|
|
|
char proposed_label[16];
|
2016-02-25 18:21:31 +00:00
|
|
|
BOOL has_protective_mbr;
|
|
|
|
BOOL has_mbr_uefi_marker;
|
|
|
|
struct {
|
|
|
|
ULONG Allowed;
|
|
|
|
ULONG Default;
|
|
|
|
} ClusterSize[FS_MAX];
|
|
|
|
} RUFUS_DRIVE_INFO;
|
|
|
|
extern RUFUS_DRIVE_INFO SelectedDrive;
|
|
|
|
|
2014-11-11 19:17:39 +00:00
|
|
|
BOOL SetAutoMount(BOOL enable);
|
|
|
|
BOOL GetAutoMount(BOOL* enabled);
|
2014-01-05 01:39:41 +00:00
|
|
|
char* GetPhysicalName(DWORD DriveIndex);
|
|
|
|
HANDLE GetPhysicalHandle(DWORD DriveIndex, BOOL bWriteAccess, BOOL bLockDrive);
|
|
|
|
char* GetLogicalName(DWORD DriveIndex, BOOL bKeepTrailingBackslash, BOOL bSilent);
|
|
|
|
BOOL WaitForLogical(DWORD DriveIndex);
|
2017-02-16 14:13:30 +00:00
|
|
|
HANDLE GetLogicalHandle(DWORD DriveIndex, BOOL bWriteAccess, BOOL bLockDrive, BOOL bWriteShare);
|
2014-02-27 19:53:53 +00:00
|
|
|
int GetDriveNumber(HANDLE hDrive, char* path);
|
2014-01-14 20:17:07 +00:00
|
|
|
BOOL GetDriveLetters(DWORD DriveIndex, char* drive_letters);
|
2014-01-05 01:39:41 +00:00
|
|
|
UINT GetDriveTypeFromIndex(DWORD DriveIndex);
|
|
|
|
char GetUnusedDriveLetter(void);
|
|
|
|
BOOL GetDriveLabel(DWORD DriveIndex, char* letter, char** label);
|
|
|
|
uint64_t GetDriveSize(DWORD DriveIndex);
|
|
|
|
BOOL IsMediaPresent(DWORD DriveIndex);
|
2014-02-09 02:54:07 +00:00
|
|
|
BOOL AnalyzeMBR(HANDLE hPhysicalDrive, const char* TargetName);
|
2014-01-05 01:39:41 +00:00
|
|
|
BOOL AnalyzePBR(HANDLE hLogicalVolume);
|
2014-08-07 00:45:46 +00:00
|
|
|
BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSystemNameSize, BOOL bSilent);
|
2014-01-05 01:39:41 +00:00
|
|
|
BOOL UnmountVolume(HANDLE hDrive);
|
|
|
|
BOOL MountVolume(char* drive_name, char *drive_guid);
|
2015-01-20 02:56:17 +00:00
|
|
|
BOOL AltUnmountVolume(const char* drive_name);
|
|
|
|
char* AltMountVolume(const char* drive_name, uint8_t part_nr);
|
2014-01-05 01:39:41 +00:00
|
|
|
BOOL RemountVolume(char* drive_name);
|
2015-01-20 02:56:17 +00:00
|
|
|
BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL mbr_uefi_marker, uint8_t extra_partitions);
|
2016-05-21 15:34:34 +00:00
|
|
|
BOOL InitializeDisk(HANDLE hDrive);
|
2014-08-07 00:45:46 +00:00
|
|
|
BOOL RefreshDriveLayout(HANDLE hDrive);
|
2014-01-05 01:39:41 +00:00
|
|
|
const char* GetPartitionType(BYTE Type);
|