Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DeviceIOControl from Delphi (disk,IOCTL,Drive)

1,285 views
Skip to first unread message

j.m.spit

unread,
Dec 5, 1999, 3:00:00 AM12/5/99
to
Help

I am trying to use the DeviceIOControl function. It seems that the relevant
windows API,
(winioctl.h) is not available under Delphi. The DeviceIOControl call itself
is located in windows.pas (dcu), but the constants required as parameters
are defined nowhere? There is no winioctl.pas?

For example, what is IOCTL_DISK_GET_DRIVE_GEOMETRY ? Whats its value?


Jan-Marten

j.m.spit

unread,
Dec 5, 1999, 3:00:00 AM12/5/99
to

j.m.spit

unread,
Dec 5, 1999, 3:00:00 AM12/5/99
to

Paddy Shepherd

unread,
Dec 5, 1999, 3:00:00 AM12/5/99
to
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)

#define IOCTL_DISK_GET_DRIVE_GEOMETRY CTL_CODE(IOCTL_DISK_BASE, 0x0000,
METHOD_BUFFERED, FILE_ANY_ACCESS)

From winioctl.h, Don't ask me to translate that to pascal :-) I'm not a
C++ programmer but from what I can make of the header file
IOCTL_DISK_GET_DRIVE_GEOMETRY is a combination of the following constants.

IOCTL_DISK_BASE as Device Type; { = 7 }
0 as Access { = 0 }
METHOD_BUFFERED as function { = 0 )
and FILE_ANY_ACCESS as Method. { = 0 }

Using the definition of CTL_CODE above I think you get.

((7)<<16) | ((0)<<14) | ((0)<<2)|(0)

Which I think evaluates to

0x70000 | 0 | 0 | 0 = 0x70000

Hope it helps and if I'm wrong then will someone please correct it :-).

BTW according to my help files the above is not applicable to Win9x. Hope
your using NT.


j.m.spit <j.m....@uptime.nl> wrote in message
news:82cg9t$d7g$1...@porthos.nl.uu.net...

j.m.spit

unread,
Dec 5, 1999, 3:00:00 AM12/5/99
to
Thanks alot Paddy (you where right),

The following code extracts Disk Geometry for NT:

TDiskGeometry = record
Cylinders : Int64;
Media_Type : longint;
TracksPerCylinder : cardinal;
SectorsPerTrack : cardinal;
BytesPerSector : cardinal;
end;

function GetDiskGeometry(Disk:string;var Geometry:TDiskGeometry):boolean;
var Device:THandle;
IOResult:boolean;
returned:cardinal;
begin
result:=false;
Device:=CreateFile( PChar('\\.\\'+Disk),
0,
FILE_SHARE_READ or FILE_SHARE_WRITE,
nil,
OPEN_EXISTING,
0,
0);
if Device<>INVALID_HANDLE_VALUE then
begin

result:=DeviceIOControl(Device,$70000,nil,0,@Geometry,sizeof(Geometry),retur
ned,nil);
CloseHandle(Device);
end;
end;

For example,

var d:TDiskGeometry;
begin
if GetDiskGeometry('PhysicalDrive0', d) then
....

The Disk string can either be the name of a device, or the name of a device
driver. It also works
with drive letters, as in GetDiskGeometry('A:', d) .

Note that the win32.hlp incorrectly states that the filename passed to
CreateFile should be
'\\\\.\\PhysicalDrive0', whereas it should be '\\.\\PhysicalDrive0'.

Ok,

Is it possible that you send me (or the group), the relevant portion of
winioctl.h? I dont need the record definitions (Disk_Geometry etc), can work
that out from win32.hlp, but i do need the values for the IOCTL_ constants
required for DeviceIOControl.

Result will be send back to ya!

Thanks, Jan-Marten

Paddy Shepherd wrote in message <82col1$tgk$1...@newsg1.svr.pol.co.uk>...


>#define CTL_CODE( DeviceType, Function, Method, Access )

Paddy Shepherd

unread,
Dec 5, 1999, 3:00:00 AM12/5/99
to
Hi Jan,

HTH, Conversation continued by email.

--
Paddy Shepherd


j.m.spit <j.m....@uptime.nl> wrote in message

news:82dmiu$ika$1...@porthos.nl.uu.net...


> Thanks alot Paddy (you where right),
>

<snip>

0 new messages