jeurk
asked on
[D5|NT4+|Winapi] IOCTL_DISK_GET_DRIVE_LAYOUT and DeviceIoControl
Hi,
Is there someone outta there that knows how to use IOCTL_DISK_GET_DRIVE_LAYOU T with DeviceIoControl to retrieve the features of each partition. What I want is to get information about partitions on all the disks in my computer.
in fact I'm particularly interessed in getting
DWORD PartitionNumber;
BYTE PartitionType;
BOOLEAN BootIndicator;
from the PARTITION_INFORMATION structure.
Can someone submit me a sample that shows how to call that ? I know it's only for NT. But this is enought for me.
thanks for your help.
If you know how to do, but don't have a sample, I will give you some more points to write me something.
Thanks in advance.
John.
Is there someone outta there that knows how to use IOCTL_DISK_GET_DRIVE_LAYOU
in fact I'm particularly interessed in getting
DWORD PartitionNumber;
BYTE PartitionType;
BOOLEAN BootIndicator;
from the PARTITION_INFORMATION structure.
Can someone submit me a sample that shows how to call that ? I know it's only for NT. But this is enought for me.
thanks for your help.
If you know how to do, but don't have a sample, I will give you some more points to write me something.
Thanks in advance.
John.
ASKER
I would say it's not declared at all.
two links on msdn would be http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/winbase/devio_2eb6.htm
and
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/winbase/devio_69yq.htm
thanks for helping
two links on msdn would be http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/winbase/devio_2eb6.htm
and
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/winbase/devio_69yq.htm
thanks for helping
Hi jeurk,
The code bellow, I hope, is what you want.
const
IOCTL_DISK_GET_DRIVE_LAYOU T = 475148; // 7400C (hex).
type
TPARTITION_INFORMATION = packed record
StartingOffset : LARGE_INTEGER ;
PartitionLength : LARGE_INTEGER ;
HiddenSectors : DWORD;
PartitionNumber : DWORD;
PartitionType : BYTE;
BootIndicator : BOOLEAN ;
RecognizedPartition : BOOLEAN;
RewritePartition : BOOLEAN;
end;
TDRIVE_LAYOUT_INFORMATION = packed record
PartitionCount : DWORD;
Signature : DWORD;
PartitionEntry : array[0..31] of TPARTITION_INFORMATION;
end;
procedure TForm1.SpeedButton1Click(S ender: TObject);
var HNDL : integer; // hDevice
INF : TDRIVE_LAYOUT_INFORMATION;
RET : cardinal; // only for compatibilty
OVR : TOverlapped; // only for compatibilty
begin
FillChar(INF,SizeOf(INF),0 ); // clean input buffer
RET:=0; // recived bytes counter
//
// "\\.\PHYSICALDRIVEx" - your phisical drive number = x.
// 0 - first, 1-second end so on...
//
HNDL:=CreateFile('\\.\PHYS ICALDRIVE0 ',FILE_SHA RE_WRITE,0 ,nil,OPEN_ EXISTING,0 ,0);
if HNDL > 0 then
if DeviceIOControl(HNDL,IOCTL _DISK_GET_ DRIVE_LAYO UT,nil,0,@ INF,SizeOf (INF),RET, @OVR) then
begin
//
// do something here.
//
// You can read INF.PartitionCount
// INF.PartitionEntry[0..31] - detailed info about every partition.
//
//
end;
end;
Cheers,
Igor.
The code bellow, I hope, is what you want.
const
IOCTL_DISK_GET_DRIVE_LAYOU
type
TPARTITION_INFORMATION = packed record
StartingOffset : LARGE_INTEGER ;
PartitionLength : LARGE_INTEGER ;
HiddenSectors : DWORD;
PartitionNumber : DWORD;
PartitionType : BYTE;
BootIndicator : BOOLEAN ;
RecognizedPartition : BOOLEAN;
RewritePartition : BOOLEAN;
end;
TDRIVE_LAYOUT_INFORMATION = packed record
PartitionCount : DWORD;
Signature : DWORD;
PartitionEntry : array[0..31] of TPARTITION_INFORMATION;
end;
procedure TForm1.SpeedButton1Click(S
var HNDL : integer; // hDevice
INF : TDRIVE_LAYOUT_INFORMATION;
RET : cardinal; // only for compatibilty
OVR : TOverlapped; // only for compatibilty
begin
FillChar(INF,SizeOf(INF),0
RET:=0; // recived bytes counter
//
// "\\.\PHYSICALDRIVEx" - your phisical drive number = x.
// 0 - first, 1-second end so on...
//
HNDL:=CreateFile('\\.\PHYS
if HNDL > 0 then
if DeviceIOControl(HNDL,IOCTL
begin
//
// do something here.
//
// You can read INF.PartitionCount
// INF.PartitionEntry[0..31] - detailed info about every partition.
//
//
end;
end;
Cheers,
Igor.
ASKER
I'll try this out...
If something wrong, just let me know.
Regards,
Igor.
Regards,
Igor.
ASKER
something is wrong ;) I'll tell you in a minute
ASKER
I get 'an acces denied' for the DeviceIOControl...
Is this working for you ?
Is this working for you ?
ASKER
do i need to be administrator under my computer ? with NT ?
Yes, you need. Text bellow is from Delphi help:
Disk Devices
Windows NT: You can use the CreateFile function to open a disk drive or a partition on a disk drive. The function returns a handle to the disk device; that handle can be used with the DeviceIOControl function. The following requirements must be met in order for such a call to succeed:
· The caller must have administrative privileges for the operation to succeed on a hard disk drive.
.....etc...
for more details see "CreateFile"
Disk Devices
Windows NT: You can use the CreateFile function to open a disk drive or a partition on a disk drive. The function returns a handle to the disk device; that handle can be used with the DeviceIOControl function. The following requirements must be met in order for such a call to succeed:
· The caller must have administrative privileges for the operation to succeed on a hard disk drive.
.....etc...
for more details see "CreateFile"
ASKER
is there a problem with the parameters of
CreateFile('\\.\PHYSICALDR IVE0',FILE _SHARE_WRI TE,0,nil,O PEN_EXISTI NG,0,0);
maybe it should be something like :
HNDL := CreateFile('\\.\PHYSICALDR IVE0', 0, FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
but even that is not working...
if it is working on your computer I'll try this at home...
But maybe you can give me the right parameters to make it work everywhere ?
Thanks
CreateFile('\\.\PHYSICALDR
maybe it should be something like :
HNDL := CreateFile('\\.\PHYSICALDR
but even that is not working...
if it is working on your computer I'll try this at home...
But maybe you can give me the right parameters to make it work everywhere ?
Thanks
just a moment....
ASKER
ok. Let me know.
I tried it as an administrator.
The createfiel is ok but I still have an access denied when calling deviceiocontrol...
I tried it as an administrator.
The createfiel is ok but I still have an access denied when calling deviceiocontrol...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That would be cool if you could do this for me. Thank you. Let me know.
ASKER
hello,
the solution is (thanks to madshi)
HNDL := CreateFile('\\.\PHYSICALDR IVE0', GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0);
if HNDL <> INVALID_HANDLE_VALUE then
if DeviceIOControl(HNDL, IOCTL_DISK_GET_DRIVE_LAYOU T, nil, 0, @INF, SizeOf(INF), RET, nil) then
;)
Maybe you can find me something else ?
How can I know for a given partition number which letter it is associated ?
Thanks...
the solution is (thanks to madshi)
HNDL := CreateFile('\\.\PHYSICALDR
if HNDL <> INVALID_HANDLE_VALUE then
if DeviceIOControl(HNDL, IOCTL_DISK_GET_DRIVE_LAYOU
;)
Maybe you can find me something else ?
How can I know for a given partition number which letter it is associated ?
Thanks...
ASKER
Hello,
Let's say that I accept the answer to clean stuff around.
What you gave is not the solution to what I asked. Or at least in is not working correctly.
But you gave time for that and I thank you.
Regards.
Let's say that I accept the answer to clean stuff around.
What you gave is not the solution to what I asked. Or at least in is not working correctly.
But you gave time for that and I thank you.
Regards.
thanks, it helped me a lot too ;)))))
Cheers,
Igor.
PS: I have some demo code, but can't compile it :(