How to develop critical section - Embedded

This is a discussion on How to develop critical section - Embedded ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: How to develop critical section

  1. How to develop critical section

    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


  2. Re: How to develop critical section

    > 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'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

  3. Re: How to develop critical section

    > 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??


    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



  4. Re: How to develop critical section

    Sebastian wrote:
    >>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??

    >
    >
    > 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



    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

+ Reply to Thread