This Question is Assumed Answered

1 "correct" answer available (5 pts) 14 "helpful" answers available (3 pts)
3 Replies Last post: Nov 2, 2007 12:58 PM by wbardwell

How to get the partition info of hard disk?

Oct 30, 2007 7:03 PM

Click to view Tony's profile Level 2 Tony 26 posts since
Oct 17, 2007
Hello, guys:
I want to know how to get the partition info of hard disk, so I can display the info by DropdownList control. Do I need to use Windows API?

BTW : Our CDC is more beautiful than before.
Click to view wbardwell's profile Curl wbardwell 75 posts since
Oct 31, 2007
1. Re: How to get the partition info of hard disk? Oct 31, 2007 9:28 AM

You can not get real partition information without using Win32 APIs (using the interfaces in CURL.LANGUAGE.DLL-INTERFACE to get access

to the Win32 DLLs.)

You can list all of the drive letters on Win32 with:

{for v key k in {{url "file://"}.instantiate-Directory} do

|| Do whatever here...


}

Any of those things will require running privileged.

Click to view Tony's profile Level 2 Tony 26 posts since
Oct 17, 2007
2. Re: How to get the partition info of hard disk? Oct 31, 2007 5:43 PM
in response to: wbardwell

Wonderful, Thanks for your help.

I tried to uses the Win32 API to get the real partition infomation,but failed.

Can you give me a simple example which realizes listing all of the drive letters by Win32 APIs:)?

Click to view wbardwell's profile Curl wbardwell 75 posts since
Oct 31, 2007
3. Re: How to get the partition info of hard disk? Nov 2, 2007 12:58 PM
in response to: Tony

I don't have time to do a full sample, but the basic idea is to do the following. I have not

actually run any of this, but this is the basic idea...

{define-C-struct package PartitionInformation

field package starting-offset:int64

field package partition-length:int64

field package hidden-sectors:int

field package partition-number:int

field package partition-type:int8

field package boot-indicator:int8

field package recognized-partition:int8

field package rewrite-partition:int8

}

{define-dll-class package PartitionCalls

{defaults

calling-convention = stdcall,

string-rep = CStringUTF16

}

{constructor public {default}

{construct-super {SharedLibrary "kernel32"}}

{dll-method public {create-file ("CreateFileW")

filename:String, \\ desired-access:int, \\ share-mode:int, \\ security-attributes:CPointer, \\ creation-disposition:int, \\ flags:int, \\ template-file:int = 0 \\ }:int

}

{dll-method public {device-io-control ("DeviceIoControl")

device:int, \\ control-code:int, \\ in-buffer:CPointer \\ in-buffer-size:int \\ out-buffer:{Pointer-to PartitionInformation}, \\ out-buffer-size:int, \\ bytes-returns:{Pointer-to int}, \\ overlapped:CPointer

}:int

}

{let calls:PartitionCalls = {PartitionCalls}}

{for key k in {{url "file://"}.instantiate-Directory} do


let h:int = {calls.create-file k,...rest of the arguments...}

let dev-info:{Pointer-to DeviceInformation} = {new {Pointer-to DeviceInformation}}

let bytes-returned:{Pointer-to int} = {new {Pointer-to int}}

{calls.device-io-control h, <code>0x74004</code>|# IOCTL_DISK_GET_PARTITION_INFO #|, 0, 0, dev-info, 5 * 4, bytes-returned, 0}

}