Here are some sample functions that show how to make IOCTL codes from a Win32 application. Actually using these functions to format tracks, etc., is left as an exercise for the reader. You need to have detailed knowledge of all of the low-level details of how disks work before you can successfully use these functions. There is plenty of information available in books and downloadable from the Internet to get you started.
type
TDiocRegisters = record
EBX, EDX, ECX, EAX, EDI, ESI, Flags: DWORD;
end;
TVWin32CtlCode = (ccNone, ccVWin32IntIoctl, ccVWin32Int26,
ccVWin32Int25, ccVWin32Int13);
TBiosParamBlock = packed record
BytesPerSector: Word;
SectorsPerCluster: Byte;
ReservedSectors: Word;
NumFats: Byte;
NumRootEntries: Word;
NumSectors: Word;
MediaID: Byte;
SectorsPerFat: Word;
SectorsPerTrack: Word;
NumHeads: Word;
HiddenSectors: Word;
Dummy1: Word;
TotalSectors: LongInt;
Dummy2: array[0..5] of Byte;
end;
TDeviceParamBlock = packed record
Special: Byte;
DeviceType: Byte;
DeviceAttr: Word;
NumCylinders: Word;
MediaType: Byte;
BiosParamBlock: TBiosParamBlock;
end;
TFormatParamBlock = packed record
Reserved: Byte;
Head: Word;
Cylinder: Word;
end;
function VWin32(CtlCode: TVWin32CtlCode; var Regs: TDiocRegisters): Boolean;
var
hDevice: THandle;
Count: DWORD;
begin
hDevice := CreateFile('//./VWIN32', 0, 0, nil, 0,
FILE_FLAG_DELETE_ON_CLOSE, 0);
Result := DeviceIoControl(hDevice, Ord(CtlCode), @Regs, SizeOf(Regs), @Regs, SizeOf(Regs), Count, nil);
CloseHandle(hDevice);
end;
function GetDeviceParamBlock(Drive: Char;
var ParamBlock: TDeviceParamBlock): Word;
var
Regs: TDiocRegisters;
begin
with Regs do
begin
EAX := $440D;
EBX := Ord(UpCase(Drive)) - Ord('@');
ECX := $0860;
EDX := LongInt(@ParamBlock);
VWin32(ccVWin32IntIoctl, Regs);
if (Flags and 1) <> 0 then
Result := LoWord(EAX)
else
Result := 0;
end;
end;
function SetDeviceParamBlock(Drive: Char;
var ParamBlock: TDeviceParamBlock): Word;
var
Regs: TDiocRegisters;
begin
with Regs do
begin
EAX := $440D;
EBX := Ord(UpCase(Drive)) - Ord('@');
ECX := $0840;
EDX := LongInt(@ParamBlock);
VWin32(ccVWin32IntIoctl, Regs);
if (Flags and 1) <> 0 then
Result := LoWord(EAX)
else
Result := 0;
end;
end;
function FormatTrack(Drive: Char;
var ParamBlock: TFormatParamBlock): Word;
var
Regs: TDiocRegisters;
begin
with Regs do
begin
EAX := $440D;
EBX := Ord(UpCase(Drive)) - Ord('@');
ECX := $0842;
EDX := LongInt(@ParamBlock);
VWin32(ccVWin32IntIoctl, Regs);
if (Flags and 1) <> 0 then
Result := LoWord(EAX)
else
Result := 0;
end;
end;