Atomic section query



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)

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.

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

.



Relevant Pages

  • fs/udf: vm pages "overlap" while reading large dir
    ... More on the problem with reading big directories on UDF. ... to more vnode types than before. ... bread is done on as much data as possible, ... physical sector number adjusted to DEV_BSIZE sectors is ...
    (freebsd-hackers)
  • fs/udf: vm pages "overlap" while reading large dir [patch]
    ... More on the problem with reading big directories on UDF. ... to more vnode types than before. ... bread is done on as much data as possible, ... physical sector number adjusted to DEV_BSIZE sectors is ...
    (freebsd-hackers)
  • Re: CETK test case failure
    ... no matching symbolic information found. ... will not read past the sector ... Reading CDROM media starting 1 sector per read, ... Buffer miscompare at sector 0 ...
    (microsoft.public.windowsce.embedded)
  • Sector reading and writing
    ... We have problem in reading and writing to the sector ... The direct function Calls are used to deal with sector ... this image file we are restoring back the contents of the disk or drive. ...
    (microsoft.public.windowsxp.device_driver.dev)
  • Sector reading and writing
    ... I have problem in reading and writing to the sector ... The direct function Calls are used to deal with sector ... this image file I am restoring back the contents of the disk or drive. ...
    (microsoft.public.vc.language)