How to develop critical section

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hello to all,

I m working on the system which is smilar to the PC.
I wanted to read and write each and every sector of the HDD and that
also by writing C program on the Linux OS from the user mode. I can
read and write the sector from the user mode.
But while doing so i just wanted to lock that perticular sector using
some critical section.Say suppose i m accessing some sector for
writing, then i wanted that no other application can use that sector
otherwise my system will get crashed. I know there is one concept
called "spinlock" in the linux, but i think that can be used only from
the Kernal Mode.

Actually i wanted that my code should work like a scan disk or check
disk utility. Please let me know how these utilities r working
internally, how they take care of system crash and all??

Thanks and Regards,
Nutty


Re: How to develop critical section
Quoted text here. Click to load it

I'm quite sure that the standard Linux does not have that functionality.
I suppose that can be done if you modify the appropriate driver (e.g.
the IDE driver) and provide it with an additional API that can be
accessed by your program and sets/resets the lock. Of course that will
result in greatly slowing down anything that requests to access a locked
sector.

Afterthought: if the locked sector is in the swap partition, this maybe
can result in a deadlock, if the locking program is swapped out and
never can get swapped in due to the locking.

-Michael

Re: How to develop critical section
Quoted text here. Click to load it

Think about DOS Scandisk or fsck, these are quite easy to understand:

DOS Scandisk doesn't lock anything, it is the only running program => no
other program which could access the hard disk is able to run (single
tasking). If you want to kill a file system, program a TSR which interferes
with Scandisk.

fsck: It won't work on mounted file systems (a.k.a. file systems in use), so
there is no special handling for that necessary. If you want to kill a file
system, run fsck on it when it's mounted and in use or access it directly
(again, with dd) while it is checked.

System crash handlings are through the file system, not through any IDE
drivers. If an ext2 volume gets corrupted, an fsck is forced; ext3 keeps a
journal and doesn't get confused that easy. DOS FAT simply gets errors.
You'll notice when you try to access a corrupt file/directory.

Anyway, if you want to program really inside the system, you are quite wrong
here. Take a look at some OS developing sites/groups, they might be able to
answer easier.

Regards,
Sebastian



Re: How to develop critical section
Quoted text here. Click to load it


The OP should really learn the kernel basics before continuing
with this kind of tasks. It's not fair that he's attempting to
make us to do his work. No pain - no gain.

--

Tauno Voipio
tauno voipio (at) iki fi

Site Timeline