IOCTL_DISK_GET_DRIVE_LAYOUT_EX (xp/vista)

Just starting out? Need help? Post your questions and find answers here.
User avatar
bingo
Enthusiast
Enthusiast
Posts: 210
Joined: Fri Apr 02, 2004 12:21 pm
Location: germany/thueringen
Contact:

IOCTL_DISK_GET_DRIVE_LAYOUT_EX (xp/vista)

Post by bingo »

...retrieves extended information for each entry in the partition tables for a disk

http://msdn2.microsoft.com/en-us/library/aa365174.aspx

Code: Select all

Structure PARTITION_INFORMATION_GPT
Partitiontype.GUID
PartitionId.GUID
Attributes.q
Name.b[36]
EndStructure

Structure PARTITION_INFORMATION_MBR
PartitionType.b
BootIndicator.b
RecognizedPartition.b
HiddenSectors.l
EndStructure
  
Structure PARTITION_INFORMATION_EX
PartitionStyle.l
StartingOffset.LARGE_INTEGER
PartitionLength.LARGE_INTEGER
PartitionNumber.l
RewritePartition.b
StructureUnion
ppmbr.PARTITION_INFORMATION_MBR
ppgpt.PARTITION_INFORMATION_GPT
EndStructureUnion
EndStructure

Structure DRIVE_LAYOUT_INFORMATION_GPT
DiskId.GUID
StartingUsableOffset.LARGE_INTEGER
UsableLength.LARGE_INTEGER
MaxPartitionCount.l
EndStructure

Structure DRIVE_LAYOUT_INFORMATION_MBR
Signature.l
EndStructure

Structure DRIVE_LAYOUT_INFORMATION_EX
PartitionStyle.l
PartitionCount.l
StructureUnion
pdmbr.DRIVE_LAYOUT_INFORMATION_MBR
pdgpt.DRIVE_LAYOUT_INFORMATION_GPT
EndStructureUnion
PartitionEntry.PARTITION_INFORMATION_EX[255]
EndStructure

pdl.DRIVE_LAYOUT_INFORMATION_EX

#IOCTL_DISK_BASE                = 7  
#METHOD_BUFFERED                = 0
#FILE_ANY_ACCESS                = 0

Procedure.l CTL_CODE(DeviceType, Function, Method, Access)
  ProcedureReturn ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)
EndProcedure


IOCTL_DISK_GET_DRIVE_LAYOUT_EX = CTL_CODE(#IOCTL_DISK_BASE,$14,#METHOD_BUFFERED,#FILE_ANY_ACCESS)

hDrive.l = CreateFile_("\\.\PHYSICALDRIVE0", #GENERIC_READ|#GENERIC_WRITE,#FILE_SHARE_READ|#FILE_SHARE_WRITE,0,#OPEN_EXISTING,0,0)

DeviceIoControl_(hDrive,IOCTL_DISK_GET_DRIVE_LAYOUT_EX,0,0,@pdl,SizeOf(pdl),@ret.l,0)

CloseHandle_(hDrive)

Debug pdl\PartitionCount
something is wrong ... :x

but should be possible with pb4 8)
["1:0>1"]
irishrose0312
New User
New User
Posts: 2
Joined: Wed Nov 28, 2007 6:40 pm
Location: Vicksburg, MS

Have you found what was wrong

Post by irishrose0312 »

I am trying to recreate this is vb.net. Have you figured out what was wrong and can you help me convert it? Thanks!
Hi-Toro
Enthusiast
Enthusiast
Posts: 269
Joined: Sat Apr 26, 2003 3:23 pm

Post by Hi-Toro »

What do you mean by "something is wrong"? It returns the value 4 here, and according to the MSDN docs for DRIVE_LAYOUT_INFORMATION_EX -> PartitionCount (http://msdn2.microsoft.com/en-us/library/aa364001.aspx):

"The number of partitions on the drive. On disks with the MBR layout, this value will always be a multiple of 4. Any partitions that are actually unused will have a partition type of PARTITION_ENTRY_UNUSED."

I *think* this means it's actually working! If you're also getting a value like 4, 8, etc, try iterating through the partitions and checking their types. Presumably this number is something to do with Primary/Extended partitions and Logical drives? Eg. I only have two drives under PHYSICALDRIVE0, but it returns 4, so I think you iterate through all four 'partition' entries to determine which ones are actual drives (?).

Could be wrong though. I'll experiment with this code!
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
irishrose0312
New User
New User
Posts: 2
Joined: Wed Nov 28, 2007 6:40 pm
Location: Vicksburg, MS

Where to start?

Post by irishrose0312 »

I guess I am totally lost. When I copy the code in to Visual Studio 2005 I get a bunch of errors. Can you tell me what program I should be using to view this code the way it should be viewed? Since I am new to this, I am totally lost and could use some step by step directions.

My ultimate goal is to be able to show the FAT of a pen drive.

Thanks.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

You most likely can not copy PB code into Visual Studio and expect it to work.

Is that what you're doing?

cheers
Post Reply