Einzelnen Beitrag anzeigen

WorstNightmare

Registriert seit: 6. Okt 2008
159 Beiträge
 
RAD-Studio 2010 Arc
 
#1

DeviceIoControl dauert lange

  Alt 7. Apr 2009, 22:51
Hi,

ich möchte gerne Partitionen daraufhin überprüfen, ob sie ein bestimmtes Dateisystem (nicht FAT oder NTFS) haben. Dazu hab ich mir folgenden Code zusammengebastelt:

Delphi-Quellcode:
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;
Er ist noch nicht ganz fertig, allerdings ist mir aufgefallen, dass das DeviceIoControl manchmal ziemlich lange braucht (bei ca. 4 Laufwerken die überprüft werden müssen, darunter sind Kartenleser, die "nicht bereit" sind, ca. 40s).
Lässt sich das irgendwie verkürzen?
  Mit Zitat antworten Zitat