Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi DeviceIoControl dauert lange (https://www.delphipraxis.net/132187-deviceiocontrol-dauert-lange.html)

WorstNightmare 7. Apr 2009 22:51


DeviceIoControl dauert lange
 
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?

soulies 8. Apr 2009 06:22

Re: DeviceIoControl dauert lange
 
hoi,

die Funktion GetVolumeInformation liefert doch als 7.parameter das Dateisystem der übergebenen Partition zurück

Im moment benutzt du es ja nicht, aber ich vermute du sparst einiges an code wenn du es nutzt ...

Delphi-Quellcode:
GetVolumeInformation(PChar(Drive), nil, 0, nil, NotUsed, Flags, FILESYSTEM, SIZEOF(FILESYSTEM))
cya

EDIT: hab net richtig gelesen -->
Zitat:

(nicht FAT oder NTFS)

WorstNightmare 8. Apr 2009 09:14

Re: DeviceIoControl dauert lange
 
Das GetVolumeInformation benutze ich nur, um festzustellen, ob es überhaupt ein Laufwerk mit dem Dateisystem sein kann, um die ganzen restlichen normalen Partitionen schonmal auszuschließen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:08 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz