Hello to all,
I am working on the HDD Diagnostic Module. In that i m reading and writing the data from the each and every sector of the HDD, comparing the data and checking whether the perticular sector is bad or not. I m doing the following steps :
- Locate the sectors
- Reading the data from the sector
- Saving the original data into some buffer
- Writing the new data into that sectors
- Again reading back the data from the sector
- Comparing the data
- Again putting the original data back to the sectors.
In the HDD Diagnostic code, we are dealing with different registers of IDE controller. We are reading from and writing into these registers using "inb" and "outb". Also the IDE controller allow any type of operation if and only if the drive is free. This we can check using bit called "Busy" from one of the register of the IDE Controller by polling that bit. ( "Busy" = 0 --- Drive if free, "Busy"= 1 --- Drive is busy)
Now suppose my diagnostic application has completed the first three steps like
- Locate the sectors
- Reading the data from the sector
- Saving the original data into some buffer
Now it is writing some data on to the sector. The IDE controller will make the "Busy" =1. Suppose while writing, some other application tries to poll that bit. Then in that case after completion of the write command, when the IDE controller will again make that bit "Busy" =0, the other application will get the access to that sector with the new data not with the original data.
In order to avoid the above situation we would like to put the steps (
4 to 7)
- Writing the new data into that sectors
- Again reading back the data from the sector
- Comparing the data
- Again putting the original data back to the sectors.
as an atomic operation or critical section so that we can protect perticular sector from the other application. Is there any provision in the Linux??
Another approach is to increase the priority of the thread. But i don't know much about that. Can anyonr please tell me how to set/increase thr priority of the thread??
Also i m looking for the source code of any check disk/scan disk function. Can any one please help me in that??
Thanks and Regards,
-Nutty