Low level hard disk programming 

Newsgroups: comp.os.linux, comp.lang.asm.x86
Date: 2002-09-02 10:55:11 PST
>I looked for information about hard disk's low level format on various
>groups (eg. comp.lang.asm.x86,comp.os.linux), but my search only took
>me to posts like: "don4t do it", "it's hardware vendor specific", "the
>new ide doesn4t make a real low level format".
>Now, I will make a few questions that involves low level programming
>and I like to see professional answers, not the simple answers like
>the above mentioned.
>Then, my questions are:
>- How is implemented the Int13,function 5 actually for hard disks?

This is not fully done on new systems because the IDE interface does not use this information anymore.

The modern drives of the IDE/ATA variety actually use the LBA absolute sector number for everything, No matter how you address the drive.

To do the format like you are talking about you must first tell the drive to use your CHS cylinder, head, sector values.

Then you just go ahead and find the appropriate commands in the list IDE/ATA low level stuff and send it.

>- How is implemented the bad sector marking on a hard disk? (not the
>FFF7h cluster mark in the FAT), but the real table management that
>knows which physical sector is really bad, something like the "track
>address fields" for a floppy disk format.

These are generically known as P&G tables. Permanent and gathered errors table or list.

This idea comes from SCSI which is where much of the modern improvments in IDE have come from. Approximatly 3% of the drive on a physical track by physical track basis is set aside to catch gathered errors as they occur.

In order to fully under stand this look at a modern drive size.

162000 * 16 * 63 done on an actual 2 platter or 4 Head system. (~80-Gig)

this means that you actually deal with the following.

648000 * 4 *63 is the first step.

Then you factor in the 6000Tpi of tracks per inch density. the track are the same as cylinders (concentric rings goinf outward.) You actually have about an inch of track width on a 3 1/2 drv. so you actually get something like.

6000 * 4 * 6804 is where you end up.

Now if it was me I would just use the 6144 (1024 * 6) as my SPT (Sectors per track) or about 3Megs per physical track on the media.

This illustrate the departure of the IDE/ATA technology from it's FM / MFM / RLL / ESDI roots. The sector address no longer represented the physical address of the sector. This now represented a virtual position and could be changed at will by the onboard electronics for data preservation. All commands to access the P&G tables are vendor specific.

>- How does the BIOS low level format work and which are the supported
>disks (it means, vendor, capacity, etc).

Please see the above then add this to it.

Modern drives use a two layer approach to a format. The sector boundary's are no longer variable.

Now there is an inner layer of hard coded sectors that the onboard electronics can only read nor write. Then there is the soft coded parts that contain sector specific data. This can be CHS placement Information in addition to LBA address & sector data.

>- ...
>I have other doubts, but first of all I want to know if there is
>anybody that really can help me.

If you really want to get into the nitty gritty then I suggest you grab the BT168.zip off of my site and study it closely.

Messy though the code is, poorly documented it may be. How ever it runs spinrite. It also handles upto 128 Gig drives. in CHS upto 8-Gig and in LBA from there up.

Done myself from the ground up. When I get time I will be cleaning up the code and makeing some real documemtation for it.

Doors - Dont look at the future in a window. just walk to the door http://walk.to/doors - Open it and go there.