From: pandeng@telepath.com (Steve Schafer (TeamB)) Subject: Re: Format a Disk with Delhpi: several O.S. Date: 28 Jan 1999 00:00:00 GMT Message-ID: <36b99d60.72495861@90.0.0.40> Content-Transfer-Encoding: 7bit References: <78nd20$2db1@forums.borland.com> Content-Type: text/plain; charset=us-ascii Organization: TeamB Mime-Version: 1.0 Reply-To: pandeng@telepath.com Newsgroups: borland.public.delphi.winapi On Wed, 27 Jan 1999 11:01:42 -0500, "Leonar Narvaez" wrote: >Thanks Steve, but I don't know how to implement these functions, and i don't >have this Guide, if you can send me a little sample code, i'll really >appreciate it, 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; -Steve