const
IOCTL_DISK_GET_DRIVE_GEOMETRY = $00070000;
type
_DISK_GEOMETRY =
packed record
Cylinders: Int64;
MediaType: Integer;
TracksPerCylinder: DWORD;
SectorsPerTrack: DWORD;
BytesPerSector: DWORD;
end;
DISK_GEOMETRY = _DISK_GEOMETRY;
[...]
function IsRightFS(Drive:
string): Boolean;
var
NotUsed, Flags, Bytes: DWORD;
DrivePath:
string;
handle: THandle;
dg: DISK_GEOMETRY;
begin
// Basic check
if (GetVolumeInformation(PChar(Drive),
nil, 0,
nil, NotUsed, Flags,
nil, 0))
or (Drive = '
A:\')
or (
not (GetDriveType(PChar(Drive))
in [DRIVE_FIXED, DRIVE_REMOVABLE]))
then
Exit(False);
DrivePath := '
\\.\' + Drive[1] + '
:';
handle := CreateFile(PChar(DrivePath), GENERIC_READ
or GENERIC_WRITE, 0,
nil, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, 0);
if handle = INVALID_HANDLE_VALUE
then
Exit(False);
if not DeviceIoControl(
handle, IOCTL_DISK_GET_DRIVE_GEOMETRY,
nil, 0, @dg, SizeOf(DISK_GEOMETRY), bytes,
nil)
then
Exit(False);
CloseHandle(
handle);
Result := True;
end;