When a hard disk is manufactured, there are areas on the platter that have bad sectors. Considering that on a 2 TB hard disk there are 4 billion sectors, then a few bad sectors is only a tiny proportion of the total number of sectors on the drive. During the test phases of a hard disk, the platters are scanned at the factory and the bad sectors are mapped out – these are generally called ‘Primary Defects’. The primary defects are stored in tables in the firmware zone, or in some cases the ROM of a hard disk. When you buy a brand new hard disk, you will most likely be completely unaware of these bad sectors and the numbers because they are ‘mapped out’ using ‘translator‘ algorithms.
Modern hard disks use Logical Block Addressing or LBA, this describes the sector numbering system on the hard disk, and goes in sequence
0,1,2,3,4,5,…..n-1,n (where n is the last sector on the drive.
Spare sector pools
All modern hard disk drives have a spare sector pool. This is used when bad sectors develop during the normal life of the hard disk and any newly found bad sectors are ‘replaced’ with good ones from the spare sector pool. This process is invisible to the user and they will probably never know that anything has changed.
How Bad Sector Mapping Works:
There are at least two methods of bad sector re-mapping (or translation) these are P-List and G-List.
- P-list are defects found during manufacture and are also know as Primary Defects
- G-List are defects that develop in normal use of the drive and are known as Grown Defects
There are other defect lists found in modern drives but the principles are similar. For example, you may find a T-List or a Track defect list, or an S-List or System area defect list.
Lets get into how these defect lists actually work, so let’s say we have a small hard disk with 100 sectors and a 10 sector spares pool.
When bad sectors are found at the factory, shift-points are entered into the P-List, if we take the following LBA sequence 0,1,2,3,4,5,6,7,8,9,10 …99, 100 Lets say that Sectors 3, 6 and 9 are found to be bad. When the first bad sector is found, the first part of the re-mapping process will look like this
What happens here is the bad sector at position 3 is recorded in the P-List. The new map now looks like this;
0,1,2,P,3,4,5,6,7,8,9,10 .. You can see now that 3 is where 4 was.
The next bad sector at LBA 6 is now found
0,1,2,P,3,4,5,B,7 and is again mapped out giving 0,1,2,P,3,4,5,P,6,7
When the whole sequence is complete, our final map looks like this.
Because these sectors are mapped out, the user will never be aware that they exist. If you want to look at sector 6, the drive will translate that to physical sector 8. It takes the 6 and adds the shift points to it, +1 for the bad sector at LBA3 and +1 for the bad sector at LBA 6. When the testing gets to the end of the drive, in order that it is of the correct size of 100 sectors, it allocates the sectors from the spare sector pool completely concealing the fact that there are bad sectors on the media. To all intents and purposes the drive looks just like the original as 1,2,3,4,5,6,7,8,9,10. However, our spare pool has reduced in size and there are now 7 sectors remaining in the spares pool.
After using the drive for a while some bad sectors develop the drive takes care of these using a grown defect list.
The grown defect list or G-List is a table containing the location of bad sector defects found during normal operation of the hard disk drive. When a bad sector occurs during normal use of the drive, something a similar process to P-List generation occurs – resulting with the bad sectors being mapped out. The process for G-List mapping out is slightly different. Lets say our hard disk develops a bad sector at the current LBA 6. What happens in this case is first the bad sector is mapped out. Giving; 0,1,2,3,4,5,G,7,8,9,10 .. A sector from the spare pool is allocated in the bad sectors place. We used 3 of these sectors in factory testing, so the next available bad sector is 104 this now becomes mapped to LBA 6 so our sequence would look like this; 0,1,2,3,4,5,104,7,8,9,10
Again, this process is completely invisible to the user and will still look like the original sequence of 0,1,2,3,4,5,6,7,8,9,10
You might ask, ‘why don’t the new defects get added to the P-List?‘ the answer is that if you add a grown defect to the P-List it has the effect of shifting the data up the drive for each sector from the point where the new bad sector is found. If you look again at the methodology behind the P-List it will help you understand this.
Where a G-List entry can help to revive hard disk, if there was data stored in the original sector attempts then usually it is lost. This may appear to the user as a file that not longer opens, or a a program that doesn’t run anymore or some other errant behaviour. This will not become apparent until the next time the file is attempted to be opened. It may also be that it is such a long time since it was opened that a backup plan means there are no backups of the working version. So bear this in mind when developing you backup plan.
Defect Mapping in a live system
When a hard disk is powered up, the p-list and g-list are usually loaded into RAM on the controller card. As requests for data come through, the location where the data is required from is passed to the translator, which makes the calculations necessary so as to determine which sectors to actually read in order to get to the actual data requested. In our example above, if we wanted the data from LBA 6 the translator would first run through the p-list and add 2 sectors to the count for the two bad sectors found at the factory, it then checks this value in the G-list and finds it has been re-allocated to sector 104. It then reads sector 104 and presents you with the data.
All the magic that goes unnoticed by normal people 🙂