DeviceIoControl

C

Chefprog

HI!
Ich hab mal gefragt, wie ich in Delphi 5 die Partitionen eines Rechners auslesen kann! Man hat mir den Befehl DeviceIoControl gegeben. Das dumme is nur, dass ich damit gar nix anfangen kann.
Kann mir jemand helfen???
Ciao, Chefprog:confused: :-)
 
Ein Blick in die MSDN verrät dir folgendes:



The DeviceIoControl function sends a control code directly to a specified device driver, causing the corresponding device to perform the specified operation.

BOOL DeviceIoControl(

HANDLE hDevice, // handle to device of interest
DWORD dwIoControlCode, // control code of operation to perform
LPVOID lpInBuffer, // pointer to buffer to supply input data
DWORD nInBufferSize, // size of input buffer
LPVOID lpOutBuffer, // pointer to buffer to receive output data
DWORD nOutBufferSize, // size of output buffer
LPDWORD lpBytesReturned, // pointer to variable to receive output byte count
LPOVERLAPPED lpOverlapped // pointer to overlapped structure for asynchronous operation
);
Parameters

hDevice

Handle to the device that is to perform the operation. Call the CreateFile function to obtain a device handle.

dwIoControlCode

Specifies the control code for the operation. This value identifies the specific operation to be performed and the type of device on which the operation is to be performed. The following values are defined:

Value Meaning

[...]

IOCTL_DISK_GET_PARTITION_INFO Obtains disk partition information.

[...]

lpInBuffer

Pointer to a buffer that contains the data required to perform the operation.
This parameter can be NULL if the dwIoControlCode parameter specifies an operation that does not require input data.

nInBufferSize

Specifies the size, in bytes, of the buffer pointed to by lpInBuffer.

lpOutBuffer

Pointer to a buffer that receives the operation’s output data.
This parameter can be NULL if the dwIoControlCode parameter specifies an operation that does not produce output data.

nOutBufferSize

Specifies the size, in bytes, of the buffer pointed to by lpOutBuffer.

lpBytesReturned

Pointer to a variable that receives the size, in bytes, of the data stored into the buffer pointed to by lpOutBuffer.
If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation produces no output data, and lpOutBuffer can be NULL, the DeviceIoControl function makes use of the variable pointed to by lpBytesReturned. After such an operation, the value of the variable is without meaning.
If lpOverlapped is not NULL, lpBytesReturned can be NULL. If this is an overlapped operation, you can get the number of bytes returned by calling GetOverlappedResult. If hDevice is associated with an I/O completion port, you can get the number of bytes returned by calling GetQueuedCompletionStatus.

lpOverlapped

Pointer to an OVERLAPPED structure.
If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, this parameter must point to a valid OVERLAPPED structure. In this case, DeviceIoControl is performed as an overlapped (asynchronous) operation. If the device was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function fails in unpredictable ways.
If hDevice was opened without specifying the FILE_FLAG_OVERLAPPED flag, this parameter is ignored and the DeviceIoControl function does not return until the operation has been completed, or an error occurs.

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

-------------------------------------------------------

The IOCTL_DISK_GET_PARTITION_INFO DeviceIoControl operation returns information about the type, size, and nature of a disk partition.

dwIoControlCode = IOCTL_DISK_GET_PARTITION_INFO ; // operation code
lpInBuffer = NULL; // address of input buffer; not used; must be NULL
nInBufferSize = 0; // size of input buffer; not used; must be zero
lpOutBuffer; // address of output buffer
nOutBufferSize; // size of output buffer
lpBytesReturned; // address of actual bytes of output


Parameters

lpInBuffer

Points to an input buffer. Not used with this operation. Set to NULL.

nInBufferSize

Specifies the size, in bytes, of the buffer pointed to by lpInBuffer. Not used with this operation. Set to zero.

lpOutBuffer

Points to a buffer that will receive a PARTITION_INFORMATION data structure.

nOutBufferSize

Specifies the size, in bytes, of the buffer pointed to by lpOutBuffer, which must be large enough to contain a PARTITION_INFORMATION data structure.

lpBytesReturned

Points to a DWORD that receives the actual size, in bytes, of the data stored into lpOutBuffer.

Return Values

If the operation succeeds, DeviceIoControl returns TRUE.
If the operation fails, DeviceIoControl returns FALSE. To get extended error information, call GetLastError.

Remarks

This device I/O control operation is for disk devices. Floppy disk drivers, however, do not need to handle this operation.

--------------------------------------------------------

The PARTITION_INFORMATION structure provides information about a disk partition.

typedef struct _PARTITION_INFORMATION {
LARGE_INTEGER StartingOffset;
LARGE_INTEGER PartitionLength;
DWORD HiddenSectors;
DWORD PartitionNumber;
BYTE PartitionType;
BOOLEAN BootIndicator;
BOOLEAN RecognizedPartition;
BOOLEAN RewritePartition;
} PARTITION_INFORMATION, *PPARTITION_INFORMATION;


Members

StartingOffset

Specifies the starting offset of the partition.

PartitionLength

Specifies the length of the partition.

HiddenSectors

Specifies the number of hidden sectors in the partition.

PartitionNumber

Specifies the number of the partition (1-based).

PartitionType

Specifies the type of partition. This member can be one of the following values: Value Meaning
PARTITION_ENTRY_UNUSED Entry unused.
PARTITION_FAT_12 Specifies a partition with 12-bit FAT entries.
PARTITION_XENIX_1 Specifies a Xenix type 1 partition.
PARTITION_XENIX_2 Specifies a Xenix type 2 partition.
PARTITION_FAT_16 Specifies a partition with 16-bit FAT entries.
PARTITION_EXTENDED Specifies an extended partition entry.
PARTITION_HUGE Specifies an MS-DOS V4 huge partition.
PARTITION_IFS Specifies an IFS partition.
PARTITION_PREP Specifies a PowerPC Reference Platform partition.
PARTITION_UNIX Specifies a UNIX partition.
VALID_NTFT Specifies an NTFT partition.
PARTITION_XINT13 Specifies a Windows 95 partition that uses extended int13 services.
PARTITION_XINT13_EXTENDED Same as PARTITION_EXTENDED, but uses extended int13 services.
BootIndicator

Specifies whether the partition is bootable.

RecognizedPartition

Specifies whether the partition is recognized.

RewritePartition

Specifies whether the partition information has changed. When you change a partition (with IOCTL_DISK_SET_DRIVE_LAYOUT), the system uses this member to determine which partitions have changed and need their information rewritten.

Remarks

The DeviceIoControl function receives a PARTITION_INFORMATION structure in response to an IOCTL_DISK_GET_PARTITION_INFO or IOCTL_DISK_GET_DRIVE_LAYOUT device input and output control (IOCTL) operation. The DeviceIoControl function uses a PARTITION_INFORMATION structure as input to an IOCTL_DISK_SET_DRIVE_LAYOUT device IOCTL operation.
 
Zurück