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 IOCTL_DISK_SET_PARTITION_INFO_EX und Fehler 31 (https://www.delphipraxis.net/164499-ioctl_disk_set_partition_info_ex-und-fehler-31-a.html)

Alter Mann 15. Nov 2011 18:28

IOCTL_DISK_SET_PARTITION_INFO_EX und Fehler 31
 
Hallo,

ich möchte mit dem nachfolgenden Code Partitionsinformationen auf eine HDD schreiben,
aber leider bekomme ich immer die Fehlermeldung:
Fehler 31, "Ein an das System angeschlossenes Gerät funktioniert nicht".

Delphi-Quellcode:
  function SetPartitionInfoEx : Boolean;
  var
    PartitionInfoEx : TPartitionInformationEx;
    PartInfoMBR    : TPartitionInformationMbr;
    lpBytesReturned : Cardinal;
  begin
    ZeroMemory(@PartInfoMBR, SizeOf(TPartitionInformationMbr));
    PartInfoMBR.PartitionType      := PARTITION_IFS;
    PartInfoMBR.BootIndicator      := false;
    PartInfoMBR.HiddenSectors      := 0;
    PartInfoMBR.RecognizedPartition := true;

    ZeroMemory(@PartitionInfoEx, SizeOf(TPartitionInformationEx));
    PartitionInfoEx.PartitionStyle         := PARTITION_STYLE_MBR;
    PartitionInfoEx.StartingOffset.QuadPart := 63 * FBytesPerSector;
    PartitionInfoEx.PartitionLength.QuadPart:= FDeviceLength - 1;
    PartitionInfoEx.PartitionNumber        := 1;
    PartitionInfoEx.RewritePartition       := true;
    PartitionInfoEx.Mbr                    := PartInfoMBR;

    Result := DeviceIOControl(FDeviceHandle,
                              IOCTL_DISK_SET_PARTITION_INFO_EX,
                              @PartitionInfoEx,
                              SizeOf(TPartitionInformationEx),
                              nil, 0, lpBytesReturned, nil);
    if not Result then DoWipeError(GetLastError);
  end;
Die Angaben wie FBytesPerSector, FDeviceLength usw. hole ich vorher mit
IOCTL_DISK_GET_DRIVE_GEOMETRY und IOCTL_DISK_GET_LENGTH_INFO.
Was mich ein wenig irritiert ist die Tatsache das IOCTL_DISK_CREATE_DISK und
IOCTL_DISK_SET_DRIVE_LAYOUT_EX ohne Fehler durchlaufen.

Die Reihenfolge ist diese:
CreateDisk
UpdateProperties
SetDriveLayoutEx
UpdateProperties
SetPartitionInfoEx
UpdateProperties

Hat jemand einen Tipp woran es liegen könnte?


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:57 Uhr.

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