Hi gizmo,
i wouldn't dare say "you're a totally stupid", however and afaik some things do go wrong in your code.
In order to let your (previous attached) code work, please change the hard-coded array of 16 partitions, as it is wrong.
My code (hopefully) showed that increasing that buffer does get rid of the "122 error code".
I've experimented a little, and it seems that 32 entries for partitions does the trick (at least when i reserve enough memory for that my code still works).
But there's another 'problem' with the (previous) code you attached.
afaik the function DRIVE_LAYOUT_INFORMATION_EX, reads the whole drive layout, even when things are not formatted -> tested with mbr and seems to works like a charm as it reports the partition being raw in that case.
So, there's no need to read in the partition tables manually, as a single DRIVE_LAYOUT_INFORMATION_EX fills out the entire DrivelayoutInformationEx structure.
My current 'read data from HD' procedure reads:
Procedure DoSomeAction;
var
hDevice : THandle;
DriveLayoutInfo : PDrivelayoutInformationEx;
DriveLayoutSize : DWORD;
BytesReturned : DWORD;
begin
hDevice := jwawinbase.CreateFile
(
'\\.\PHYSICALDRIVE0',
GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,
nil, OPEN_EXISTING, 0, 0
);
if (hDevice <> INVALID_HANDLE_VALUE) then
begin
DriveLayoutSize := sizeof(DRIVE_LAYOUT_INFORMATION_EX) + MAX_NUM_PARTITIONS * sizeof(PARTITION_INFORMATION_EX);
DrivelayoutInfo := AllocMem(DriveLayoutSize);
if DeviceIoControl
(
hDevice, IOCTL_DISK_GET_DRIVE_LAYOUT_EX, nil, 0,
DriveLayoutInfo, DriveLayoutSize, @BytesReturned, nil
) then
begin
WriteLn('DeviceIoControl() call succeeded');
WriteLn(BytesReturned, ' bytes were returned');
DumpInfo(DriveLayoutInfo);
end
else WriteLn('failed with error nr: ', GetLastError);
FreeMem(DriveLayoutInfo);
CloseHandle(hDevice);
end
else WriteLn('unable to access partition');
end;
And The DumpInfo routine simply prints out the data that was read.
Attempting to read partition
DeviceIoControl() call succeeded
2928 bytes were returned
Sign = MBR (sig: REMOVED FOR PRIVACY)
This drive has 5 Partitions
---
Partition[ 0].PartitionStyle = MBR
Partition[ 0].StartingOffset = 32256
Partition[ 0].PartitionLength = 38165266944 (36397 MB)
Partition[ 0].PartitionNumber = 1
Partition[ 0].RewritePartition = FALSE
mbr info: used
Partition[ 0].mbr.PartitionType = PARTITION_IFS (#7)
Partition[ 0].mbr.BootIndicator = TRUE
Partition[ 0].mbr.RecognizedPartition = TRUE
Partition[ 0].mbr.HiddenSectors = 63
---
Partition[ 4].PartitionStyle = MBR
Partition[ 4].StartingOffset = 38165331456
Partition[ 4].PartitionLength = 150489690624 (143518 MB)
Partition[ 4].PartitionNumber = 2
Partition[ 4].RewritePartition = FALSE
mbr info: used
Partition[ 4].mbr.PartitionType = PARTITION_IFS (#7)
Partition[ 4].mbr.BootIndicator = FALSE
Partition[ 4].mbr.RecognizedPartition = TRUE
Partition[ 4].mbr.HiddenSectors = 63
---
Partition[ 8].PartitionStyle = MBR
Partition[ 8].StartingOffset = 188655054336
Partition[ 8].PartitionLength = 150489690624 (143518 MB)
Partition[ 8].PartitionNumber = 3
Partition[ 8].RewritePartition = FALSE
mbr info: used
Partition[ 8].mbr.PartitionType = PARTITION_IFS (#7)
Partition[ 8].mbr.BootIndicator = FALSE
Partition[ 8].mbr.RecognizedPartition = TRUE
Partition[ 8].mbr.HiddenSectors = 63
---
Partition[ 12].PartitionStyle = MBR
Partition[ 12].StartingOffset = 339144777216
Partition[ 12].PartitionLength = 150489690624 (143518 MB)
Partition[ 12].PartitionNumber = 4
Partition[ 12].RewritePartition = FALSE
mbr info: used
Partition[ 12].mbr.PartitionType = PARTITION_IFS (#7)
Partition[ 12].mbr.BootIndicator = FALSE
Partition[ 12].mbr.RecognizedPartition = TRUE
Partition[ 12].mbr.HiddenSectors = 63
---
Partition[ 16].PartitionStyle = MBR
Partition[ 16].StartingOffset = 489634500096
Partition[ 16].PartitionLength = 150489690624 (143518 MB)
Partition[ 16].PartitionNumber = 5
Partition[ 16].RewritePartition = FALSE
mbr info: used
Partition[ 16].mbr.PartitionType = PARTITION_IFS (#7)
Partition[ 16].mbr.BootIndicator = FALSE
Partition[ 16].mbr.RecognizedPartition = TRUE
Partition[ 16].mbr.HiddenSectors = 63
Nothing exciting going on in DumpInfo() routine, just interpreting the data from record DrivelayoutInformationEx and printing it to console.
Why don't you try telling what you want exactly instead of jumping left and right adjusting the question ?
The error 122 is fixed by simply increasing the array size to such extend that it can actually contain all the partition data gathered by the windows DeviceIoControl() function.
Sorry, i haven't looked at your latest snippet as the error is fixed.