Atomic section query

Nov 15, 2006 2 Replies

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 :


  1. Locate the sectors
  2. Reading the data from the sector
  3. Saving the original data into some buffer
  4. Writing the new data into that sectors
  5. Again reading back the data from the sector
  6. Comparing the data
  7. 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


  1. Locate the sectors
  2. Reading the data from the sector
  3. 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)


  1. Writing the new data into that sectors



  1. Again reading back the data from the sector
  2. Comparing the data
  3. 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



DID YOU GET THE KERNEL BOOK?

The disk system cannot be disabled for long enough to satisfy your requirement - it would cripple the virtual memory system out of usable condition.

What you're attempting to do, can be done ONLY in a stand-alone system without the kernel assisting in any way.

Tauno Voipio tauno voipio (at) iki fi

We all already know that you don't want to do anything that has anything to do with Linux. So why are you asking here ?

-Michael

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required