#include "stdafx.h" #ifdef OFFLINEDK extern "C"{ #include } #endif #ifdef BOOTIME #include "Offline.h" #else #include "Windows.h" #endif #include extern "C" { #include "SysStruc.h" } #include "ErrMacro.h" #include "DfrgCmn.h" #include "DfrgRes.h" #include "Alloc.h" #define THIS_MODULE 'U' #include "logfile.h" // // start of helpers for IsValidVolume functions below // ///////////////////////////////////////// // Is this a valid drive type? // Check if we have a drive that is even in the ball park. // static BOOL IsValidDriveType(UINT uDriveType) { //sks bug #211782 take out CDROM and RAMDISK to allow for DVD-RAM drives if (uDriveType == DRIVE_UNKNOWN || uDriveType == DRIVE_NO_ROOT_DIR || uDriveType == DRIVE_REMOTE ) { return FALSE; } return TRUE; } ///////////////////////////////////////// // Get a handle to a volume // static HANDLE GetVolumeHandle(PTCHAR cVolume) { HANDLE hVolume = INVALID_HANDLE_VALUE; // Get a handle to the volume UINT uiErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); hVolume = CreateFile(cVolume, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING, NULL); SetErrorMode(uiErrorMode); return hVolume; } ///////////////////////////////////////// // Is this volume valid (actual work routine) // // Note: volumeName is required to get volumeLabel and fileSystem // static BOOL IsValidVolumeCheck(HANDLE hVolume, // IN volume handle UINT uDriveType, // IN drive type PTCHAR volumeName, // IN volume name PTCHAR volumeLabel, // OUT volume label PTCHAR fileSystem) // OUT file system { require(hVolume != INVALID_HANDLE_VALUE && hVolume != NULL); require(volumeName != NULL); BOOL bReturn = FALSE; // assume not valid HANDLE hFsDevInfo = NULL; FILE_FS_DEVICE_INFORMATION * pFsDevInfo = NULL; // clear return values if (volumeLabel != NULL) { _tcscpy(volumeLabel, TEXT("")); } if (fileSystem != NULL) { _tcscpy(fileSystem, TEXT("")); } __try { // read-only, network, etc. check if (!AllocateMemory(sizeof(FILE_FS_DEVICE_INFORMATION) + MAX_PATH, &hFsDevInfo, (void**) &pFsDevInfo)) { EH(FALSE); __leave; } IO_STATUS_BLOCK IoStatus = {0}; NTSTATUS Status = NtQueryVolumeInformationFile(hVolume, &IoStatus, pFsDevInfo, sizeof(FILE_FS_DEVICE_INFORMATION) + 50, FileFsDeviceInformation); if (NT_SUCCESS(Status)) { if (pFsDevInfo->Characteristics & (FILE_READ_ONLY_DEVICE | FILE_WRITE_ONCE_MEDIA | FILE_REMOTE_DEVICE)) { __leave; } } else { __leave; } // media check if (uDriveType == DRIVE_REMOVABLE) { DISK_GEOMETRY medias[20]; DWORD nummedias = 0; DWORD numbytes; if (DeviceIoControl(hVolume, IOCTL_STORAGE_GET_MEDIA_TYPES, NULL, 0, medias, 20 * sizeof(DISK_GEOMETRY), &numbytes, NULL)) { nummedias = numbytes / sizeof(DISK_GEOMETRY); for (UINT i=0; i