Page 1 of 1

How do I format floppy disks?

Posted: Mon Jun 10, 2002 5:53 am
by drizzt
I wanna write a program in assembly to format tracks heads & sector with floppy disks... (or hard disks). What can I do?

PS
I know interrupt 13, ah=5, etc. but I don't understand the meaning of ES:BX pointer address; what I must write in ES:BX :'(???

Re:How do I format floppy disks?

Posted: Mon Jun 10, 2002 8:44 am
by DynatOS
Straight out of a manual...

INT 13h - FORMAT DISKETTE TRACK
AH = 5
AL = NUMBER OF SECTORS
CH = TRACK NUMBER
CL = SECTOR NUMBER
DH = HEAD NUMBER
DL = DRIVE NUMBER
ES:BX = POINTER TO 4-BYTE ADDRESS FIELD
BYTE 1 = TRACK
BYTE 2 = HEAD
BYTE 3 = SECTOR
BYTE 4 = BYTES/SECTOR
Return: CF = SUCCESS/FAILURE SIGNAL
AH = STATUS CODE (SEE AH = 01)

If I'm not mistaken, this refers to a "low-level" format, newer harddrives are formatted around a P-CHS setup (x Cylinders, 16 Heads, 63 Sectors, 512 Bytes per Sector), and shouldn't be changed.

If you want to format in what is called a "high-level" format, just write a certain amount of specified data to a certain amount of sectors on the disk/diskette.

Re:How do I format floppy disks?

Posted: Mon Jun 10, 2002 10:14 am
by drizzt
Thanks !!! But in TRACK (...at ES:BX) I must write the track's size, and so for HEAD & SECTOR ??

Because about sector size I know that 1 byte sector size code is:

0 = 128 byte / sector
1 = 256 byte / sector
2 = 512 byte / sector
3 = 1024 byte / sector

And it's OK! But it seems stupid to write info about track and head... maybe TRACK & HEAD represent the total number of them in the disk?

(... sorry for my english...)

Re:How do I format floppy disks?

Posted: Mon Jun 10, 2002 11:41 am
by Dave_Hunt
Check the following link:

http://www.simtel.net/pub/msdos/diskutil/

There are a number of disk formatting utilities and many include source code (some ASM, some C).

Re:How do I format floppy disks?

Posted: Mon Jun 10, 2002 3:02 pm
by drizzt
thanks!!!

Re:How do I format floppy disks?

Posted: Mon Jun 10, 2002 3:26 pm
by Schol-R-LEA
Keep in mind that that function only formats the individual sectors or groups of sectors; you have deal with each track and head in turn. Also, this only prforms the minimum secotr formatting; you would still need to add the filesystem information (FATs or i-nodes or whatever) as well. Fortunately, FATs are easy enough to create.

For some reason, the simtel page seems to be down, so I don't know what they cover there.

Re:How do I format floppy disks?

Posted: Wed Jun 12, 2002 1:58 pm
by drizzt
OK!!! Well the pointer ES:BX specifies this:

1 byte (offset 00h) --> total number of track in the disk.
1 byte (offset 01h) --> total number of head (0-based) in the disk.
1 byte (offset 02h) --> number of sectors per track.
1 byte (offset 03h) --> sectors size.

In particular for sector size the contents is:

00h => 128 byte / sector
01h => 256 byte / sector
02h => 512 byte / sector
03h => 1024 byte / sector

...and you must specifie this for all sectors (head & track) in the disk you format.
The maximal number of sectors that will work depends on the media, for example about floppy:

5?" DD disk : 1-10 sectors (9 = DOS standard)
5?" HD disk : 11-18 sectors (15 is standard)

3?" DD disk : 1-10 sectors in DD drive (DOS puts 9)
    1-13 sectors in HD drive
    1-12 sectors on some HD drives (Sony ?)?

3?" HD disk : 14-21 sectors (18 = DOS standard)

If you specifie 82 tracks, 18 sectors / track (with sector size=512 byte) you can format a floppy to 1476K!!! ;)

Thanks to all...

Re:How do I format floppy disks?

Posted: Wed Jun 12, 2002 9:21 pm
by Anonymous
look at superformat in Linux fdutils:
http://fdutils.linux.lu/

it's in C instead of asm, and it programs the floppy chip directly instead of using the BIOS, but it might help

going above 80 tracks or 21 sectors / track is unreliable but 21 sectors / track gives you a 1.68 meg floppy