Ignore:
Timestamp:
Oct 1, 2015, 4:20:46 PM (9 years ago)
Author:
alain
Message:

Major release: Change the task model to implement the POSIX threads API.

  • The shell "exec" and "kill" commands can be used to activate/de-activate the applications.
  • The "pause", "resume", and "context" commands can be used to stop, restart, a single thtead or to display the thread context.

This version has been tested on the following multi-threaded applications,
that have been modified to use the POSIX threads:

  • classif
  • convol
  • transpose
  • gameoflife
  • raycast
File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_fat32/fat32.c

    r707 r709  
    3838#include <vmem.h>
    3939#include <kernel_malloc.h>
     40#include <ctx_handler.h>
    4041#include <bdv_driver.h>
    4142#include <hba_driver.h>
     
    9394#if GIET_DEBUG_FAT
    9495static void _display_fat_descriptor();
    95 #endif
    96 
    97 /////////////////////////////////////////////////////////////////////////////////
    98 // This debug function displays the sequence of clusters allocated to a
    99 // file (or directory) identified by the "inode" argument.
    100 /////////////////////////////////////////////////////////////////////////////////
    101 
    102 #if GIET_DEBUG_FAT
    103 static void _display_clusters_list( fat_inode_t* inode );
    10496#endif
    10597
     
    593585
    594586
    595 #if GIET_DEBUG_FAT
     587#if 0
    596588////////////////////////////////////////////////////////
    597589static void _display_clusters_list( fat_inode_t* inode )
     
    28322824    }
    28332825
    2834     // takes the lock
     2826    // takes the FAT lock and register it in thread context
     2827    static_scheduler_t*  psched = _get_sched();
     2828    unsigned int         ltid   = _get_thread_ltid();
    28352829    _spin_lock_acquire( &_fat.fat_lock );
     2830    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
    28362831
    28372832    // get inode pointer
     
    28412836    {
    28422837        _spin_lock_release( &_fat.fat_lock );
     2838        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2839
    28432840        _printf("\n[FAT ERROR] _fat_open(): path to parent not found"
    28442841                " for file <%s>\n", pathname );
     
    28482845    {
    28492846        _spin_lock_release( &_fat.fat_lock );
     2847        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2848
    28502849        _printf("\n[FAT ERROR] _fat_open(): one name in path too long"
    28512850                " for file <%s>\n", pathname );
     
    28552854    {
    28562855        _spin_lock_release( &_fat.fat_lock );
     2856        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2857
    28572858        _printf("\n[FAT ERROR] _fat_open(): file not found"
    28582859                " for file <%s>\n", pathname );
     
    28902891        {
    28912892            _spin_lock_release( &_fat.fat_lock );
     2893            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2894
    28922895            _printf("\n[FAT ERROR] _fat_open(): cannot update parent directory"
    28932896                    " for file <%s>\n" , pathname );
     
    29012904        {
    29022905            _spin_lock_release( &_fat.fat_lock );
     2906            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2907
    29032908            _printf("\n[FAT ERROR] _fat_open(): cannot update DATA region "
    29042909                    " for parent of file <%s>\n", pathname );
     
    29122917        {
    29132918            _spin_lock_release( &_fat.fat_lock );
     2919            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2920
    29142921            _printf("\n[FAT ERROR] _fat_open(): cannot update FAT region"
    29152922                    " for file <%s>\n", pathname );
     
    29212928        {
    29222929            _spin_lock_release( &_fat.fat_lock );
     2930            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2931
    29232932            _printf("\n[FAT ERROR] _fat_open(): cannot update FS-INFO"
    29242933                    " for file <%s>\n", pathname );
     
    29522961    {
    29532962        _spin_lock_release( &_fat.fat_lock );
     2963        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2964
    29542965        _printf("\n[FAT ERROR] _fat_open(): File-Descriptors-Array full\n");
    29552966        return GIET_FAT32_TOO_MANY_OPEN_FILES;
     
    29792990        {
    29802991            _spin_lock_release( &_fat.fat_lock );
     2992            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2993
    29812994            _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n");
    29822995            return GIET_FAT32_IO_ERROR;
     
    29873000        {
    29883001            _spin_lock_release( &_fat.fat_lock );
     3002            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3003
    29893004            _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n");
    29903005            return GIET_FAT32_IO_ERROR;
     
    29943009    // releases the lock
    29953010    _spin_lock_release( &_fat.fat_lock );
     3011    _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3012
    29963013
    29973014#if GIET_DEBUG_FAT
     
    30363053    }
    30373054
    3038     // takes lock
     3055    // takes the FAT lock and register it in thread context
     3056    static_scheduler_t*  psched = _get_sched();
     3057    unsigned int         ltid   = _get_thread_ltid();
    30393058    _spin_lock_acquire( &_fat.fat_lock );
     3059    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
    30403060
    30413061    if( _fat.fd[fd_id].allocated == 0 )
    30423062    {
    30433063        _spin_lock_release( &_fat.fat_lock );
     3064        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3065
    30443066        _printf("\n[FAT ERROR] _fat_close(): file not open\n");
    30453067        return GIET_FAT32_NOT_OPEN;
     
    30673089        {
    30683090            _spin_lock_release( &_fat.fat_lock );
     3091            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3092
    30693093            _printf("\n[FAT ERROR] _fat_close(): cannot write dirty clusters "
    30703094                    "for file <%s>\n", inode->name );
     
    30843108        {
    30853109            _spin_lock_release( &_fat.fat_lock );
     3110            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3111
    30863112            _printf("\n[FAT ERROR] _fat_close(): cannot write dirty clusters "
    30873113                    "for directory <%s>\n", inode->parent->name );
     
    31113137    // release lock
    31123138    _spin_lock_release( &_fat.fat_lock );
     3139    _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    31133140
    31143141    return GIET_FAT32_OK;
     
    31613188
    31623189/////////////////////////////////////////////////////////////////////////////////
    3163 // The following function implements the "giet_fat_read()" system call.
    3164 // It transfers "count" bytes from the File_Cache associated to the file
    3165 // identified by "fd_id", to the user "buffer", from the current file offset.
     3190// The following function implements the "giet_fat_read()" system call,
     3191// but can also be used by the kernel in physical addressing mode.
     3192// It transfers <count> bytes from the File_Cache associated to the file
     3193// identified by <fd_id>, to the destination buffer defined by <vaddr>.
     3194// It uses the current file offset defined in the file descriptor.
     3195// If the <extend> 16 MSB bits are non zero, it uses physical addressing:
     3196// the physical  address is computed as extend[15:0] | vaddr[31:0]
    31663197// In case of miss in the File_Cache, it loads all involved clusters into cache.
    31673198/////////////////////////////////////////////////////////////////////////////////
     
    31753206/////////////////////////////////////////////////////////////////////////////////
    31763207int _fat_read( unsigned int fd_id,          // file descriptor index
    3177                paddr_t buffer,              // destination buffer
     3208               unsigned int vaddr,          // destination buffer vaddr
    31783209               unsigned int count,          // number of bytes to read
    3179                unsigned int phys )          // use physical_memcpy
    3180 {
    3181     // checking FAT initialized
    3182     if( _fat.initialized != FAT_INITIALIZED )
    3183     {
    3184         _printf("\n[FAT ERROR] _fat_write(): FAT not initialized\n");
    3185         return GIET_FAT32_NOT_INITIALIZED;
    3186     }
    3187 
    3188     // check fd_id overflow
    3189     if ( fd_id >= GIET_OPEN_FILES_MAX )
    3190     {
    3191         _printf("\n[FAT ERROR] _fat_read(): illegal file descriptor\n");
    3192         return GIET_FAT32_INVALID_FD;
    3193     }
    3194 
    3195     // check file is open
    3196     if ( _fat.fd[fd_id].allocated == 0 )
    3197     {
    3198         _printf("\n[FAT ERROR] _fat_read(): file not open\n");
    3199         return GIET_FAT32_NOT_OPEN;
    3200     }
    3201 
    3202     // takes lock
    3203     _spin_lock_acquire( &_fat.fat_lock );
    3204            
    3205     // get file inode pointer and offset
    3206     fat_inode_t* inode  = _fat.fd[fd_id].inode;
    3207     unsigned int seek   = _fat.fd[fd_id].seek;
    3208 
    3209     // check count & seek versus file size
    3210     if ( count + seek > inode->size && !inode->is_dir )
    3211     {
    3212         _spin_lock_release( &_fat.fat_lock );
    3213         _printf("\n[FAT ERROR] _fat_read(): file too small"
    3214                 " / seek = %x / count = %x / file_size = %x\n",
    3215                 seek , count , inode->size );
    3216         return 0;
    3217     }
    3218 
    3219     // compute first_cluster_id and first_byte_to_move
    3220     unsigned int first_cluster_id   = seek >> 12;
    3221     unsigned int first_byte_to_move = seek & 0xFFF;   
    3222 
    3223     // compute last_cluster and last_byte_to_move
    3224     unsigned int last_cluster_id   = (seek + count - 1) >> 12;   
    3225     unsigned int last_byte_to_move = (seek + count - 1) & 0xFFF;
     3210               unsigned int extend )        // physical address extension
     3211{
    32263212
    32273213#if GIET_DEBUG_FAT
     
    32313217unsigned int p       = procid & ((1<<P_WIDTH)-1);
    32323218if ( _get_proctime() > GIET_DEBUG_FAT )
    3233 _printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] enters for file <%s> "
    3234         " / bytes = %x / offset = %x\n"
    3235         "first_cluster_id = %x / first_byte_to_move = %x"
     3219_printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] enters at cycle %d\n"
     3220        "  fd = %d / vaddr = %x / bytes = %x / extend = %x\n",
     3221        x , y , p , _get_proctime(),
     3222        fd_id , vaddr , count , extend );
     3223#endif
     3224
     3225    // checking FAT initialized
     3226    if( _fat.initialized != FAT_INITIALIZED )
     3227    {
     3228        _printf("\n[FAT ERROR] _fat_read(): FAT not initialized\n");
     3229        return GIET_FAT32_NOT_INITIALIZED;
     3230    }
     3231
     3232    // check fd_id overflow
     3233    if ( fd_id >= GIET_OPEN_FILES_MAX )
     3234    {
     3235        _printf("\n[FAT ERROR] _fat_read(): illegal file descriptor\n");
     3236        return GIET_FAT32_INVALID_FD;
     3237    }
     3238
     3239    // check file is open
     3240    if ( _fat.fd[fd_id].allocated == 0 )
     3241    {
     3242        _printf("\n[FAT ERROR] _fat_read(): file not open\n");
     3243        return GIET_FAT32_NOT_OPEN;
     3244    }
     3245
     3246    // takes the FAT lock and register it in thread context
     3247    static_scheduler_t*  psched = _get_sched();
     3248    unsigned int         ltid   = _get_thread_ltid();
     3249    _spin_lock_acquire( &_fat.fat_lock );
     3250    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
     3251
     3252           
     3253    // get file inode pointer and offset
     3254    fat_inode_t* inode  = _fat.fd[fd_id].inode;
     3255    unsigned int seek   = _fat.fd[fd_id].seek;
     3256
     3257    // check count & seek versus file size
     3258    if ( count + seek > inode->size && !inode->is_dir )
     3259    {
     3260        _spin_lock_release( &_fat.fat_lock );
     3261        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3262
     3263        _printf("\n[FAT ERROR] _fat_read(): file too small"
     3264                " / seek = %x / count = %x / file_size = %x\n",
     3265                seek , count , inode->size );
     3266        return 0;
     3267    }
     3268
     3269    // compute first_cluster_id and first_byte_to_move
     3270    unsigned int first_cluster_id   = seek >> 12;
     3271    unsigned int first_byte_to_move = seek & 0xFFF;   
     3272
     3273    // compute last_cluster and last_byte_to_move
     3274    unsigned int last_cluster_id   = (seek + count - 1) >> 12;   
     3275    unsigned int last_byte_to_move = (seek + count - 1) & 0xFFF;
     3276
     3277#if GIET_DEBUG_FAT
     3278if ( _get_proctime() > GIET_DEBUG_FAT )
     3279_printf("\n[DEBUG FAT] _fat_read(): P[%d,%d,%d] search file <%s> with seek = %x\n "
     3280        " first_cluster_id = %x / first_byte_to_move = %x"
    32363281        " / last_cluster_id = %x / last_byte_to_move = %x\n",
    3237         x , y , p , inode->name , count , seek ,
     3282        x , y , p , inode->name , seek ,
    32383283        first_cluster_id , first_byte_to_move , last_cluster_id , last_byte_to_move );
    32393284#endif
     
    32523297        {
    32533298            _spin_lock_release( &_fat.fat_lock );
     3299            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3300
    32543301            _printf("\n[FAT ERROR] _fat_read(): cannot load file <%s>\n",
    32553302                    inode->name );
     
    32893336        }
    32903337
    3291         // move data
    3292         if ( !phys )
    3293         {
    3294             void* dest = (void*)(unsigned int)buffer + done;
    3295 
    3296             memcpy( dest, source, nbytes );
    3297         }
    3298         else
     3338        // move data
     3339        if ( (extend & 0xFFFF0000) == 0 )         // no physical addressing
     3340        {
     3341            char* dest = (char*)(vaddr + done);
     3342            memcpy( dest , source , nbytes );
     3343        }
     3344        else                                      // physical addressing required
    32993345        {
    33003346            unsigned int flags;
    3301             paddr_t pdest = buffer + done;
     3347            paddr_t pdest    = (((paddr_t)(extend & 0x0000FFFF))<<32) + vaddr + done;
    33023348            paddr_t psource  = _v2p_translate( (unsigned int)source, &flags );
    3303 
    3304             _physical_memcpy( pdest, psource, nbytes );
     3349            _physical_memcpy( pdest , psource , nbytes );
    33053350        }
    33063351
     
    33193364    // release lock
    33203365    _spin_lock_release( &_fat.fat_lock );
     3366    _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    33213367
    33223368    return done;
     
    33273373
    33283374/////////////////////////////////////////////////////////////////////////////////
    3329 // The following function implements the "giet_fat_write()" system call.
    3330 // It transfers "count" bytes to the fat_cache associated to the file
    3331 // identified by "fd_id", from the user "buffer", using the current file offset.
     3375// The following function implements the "giet_fat_write()" system call,
     3376// but can also be used by the kernel in physical addressing mode.
     3377// It transfers <count> bytes to the File_Cache associated to the file
     3378// identified by <fd_id>, from the source buffer defined by <vaddr>.
     3379// It uses the current file offset defined in the file descriptor.
     3380// If the <extend> 16 MSB bits are non zero, it uses physical addressing:
     3381// the physical  address is computed as extend[15:0] | vaddr[31:0]
    33323382// It increases the file size and allocate new clusters if (count + offset)
    33333383// is larger than the current file size. Then it loads and updates all
     
    33443394/////////////////////////////////////////////////////////////////////////////////
    33453395int _fat_write( unsigned int fd_id,    // file descriptor index
    3346                 void*        buffer,   // source buffer
    3347                 unsigned int count )   // number of bytes to write
     3396                unsigned int vaddr,    // source buffer vaddr
     3397                unsigned int count,    // number of bytes to write
     3398                unsigned int extend )  // physical address extension
    33483399{
    33493400    // checking FAT initialized
     
    33543405    }
    33553406
    3356     // takes lock
     3407    // takes the FAT lock and register it in thread context
     3408    static_scheduler_t*  psched = _get_sched();
     3409    unsigned int         ltid   = _get_thread_ltid();
    33573410    _spin_lock_acquire( &_fat.fat_lock );
     3411    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
     3412
    33583413           
    33593414    // check fd_id overflow
     
    33613416    {
    33623417        _spin_lock_release( &_fat.fat_lock );
     3418        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3419
    33633420        _printf("\n[FAT ERROR] _fat_write(): illegal file descriptor\n");
    33643421        return GIET_FAT32_INVALID_FD;
     
    33693426    {
    33703427        _spin_lock_release( &_fat.fat_lock );
     3428        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3429
    33713430        _printf("\n[FAT ERROR] _fat_write(): file not open\n" );
    33723431        return GIET_FAT32_NOT_OPEN;
     
    33773436    {
    33783437        _spin_lock_release( &_fat.fat_lock );
     3438        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3439
    33793440        _printf("\n[FAT ERROR] _fat_write(): file <%s> is read-only\n",
    33803441                _fat.fd[fd_id].inode->name );
     
    34293490            {
    34303491                _spin_lock_release( &_fat.fat_lock );
     3492                _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3493
    34313494                _printf("\n[FAT ERROR] _fat_write(): no free clusters"
    34323495                        " for file <%s>\n", _fat.fd[fd_id].inode->name );
     
    34393502        {
    34403503            _spin_lock_release( &_fat.fat_lock );
     3504            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3505
    34413506            _printf("\n[FAT ERROR] _fat_write(): cannot update parent directory entry"
    34423507                    " for file <%s>\n", _fat.fd[fd_id].inode->name );
     
    34833548        {
    34843549            _spin_lock_release( &_fat.fat_lock );
     3550            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3551
    34853552            _printf("\n[FAT ERROR] _fat_write(): cannot load file <%s>\n",
    34863553                    inode->name );
     
    34983565
    34993566        // compute memcpy arguments
    3500         unsigned char* source = (unsigned char*)buffer + done;
    35013567        unsigned char* dest;
    35023568        unsigned int   nbytes;
     
    35223588        }
    35233589
    3524         //move date
    3525         memcpy( dest , source , nbytes );
     3590        // move data
     3591        if ( (extend & 0xFFFF0000) == 0 )     // no physical addressing
     3592        {
     3593            char* source = (char*)(vaddr + done);
     3594            memcpy( dest , source , nbytes );
     3595        }
     3596        else                                  // physical addressing required
     3597        {
     3598            unsigned int flags;
     3599            paddr_t      psource = (((paddr_t)(extend & 0x0000FFFF))<<32) + vaddr + done;
     3600            paddr_t      pdest   = _v2p_translate( (unsigned int)dest , &flags );
     3601            _physical_memcpy( pdest , psource , nbytes );
     3602        }
     3603
    35263604        done = done + nbytes;
    35273605
     
    35393617    // release lock
    35403618    _spin_lock_release( &_fat.fat_lock );
     3619    _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    35413620
    35423621    return done;
     
    35773656    }
    35783657
    3579     // takes lock
     3658    // takes the FAT lock and register it in thread context
     3659    static_scheduler_t*  psched = _get_sched();
     3660    unsigned int         ltid   = _get_thread_ltid();
    35803661    _spin_lock_acquire( &_fat.fat_lock );
     3662    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
     3663
    35813664
    35823665    // check file open
     
    35843667    {
    35853668        _spin_lock_release( &_fat.fat_lock );
     3669        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3670
    35863671        _printf("\n[FAT ERROR] _fat_lseek(): file not open\n");
    35873672        return GIET_FAT32_NOT_OPEN;
     
    35963681    {
    35973682        _spin_lock_release( &_fat.fat_lock );
     3683        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3684
    35983685        _printf("\n[FAT ERROR] _fat_lseek(): illegal whence value\n");
    35993686        return GIET_FAT32_INVALID_ARG;
     
    36153702    // release lock
    36163703    _spin_lock_release( &_fat.fat_lock );
     3704    _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    36173705
    36183706    return new_seek;
     
    36653753    }
    36663754
    3667     // take the lock
     3755    // takes the FAT lock and register it in thread context
     3756    static_scheduler_t*  psched = _get_sched();
     3757    unsigned int         ltid   = _get_thread_ltid();
    36683758    _spin_lock_acquire( &_fat.fat_lock );
     3759    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
     3760
    36693761
    36703762    // get searched file inode
     
    36803772    {
    36813773        _spin_lock_release( &_fat.fat_lock );
     3774        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3775
    36823776        _printf("\n[FAT ERROR] _fat_remove(): file <%s> not found\n",
    36833777                pathname );
     
    36873781    {
    36883782        _spin_lock_release( &_fat.fat_lock );
     3783        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3784
    36893785        _printf("\n[FAT ERROR] _fat_remove(): name too long in <%s>\n",
    36903786                pathname );
     
    36963792    {
    36973793        _spin_lock_release( &_fat.fat_lock );
     3794        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3795
    36983796        _printf("\n[FAT ERROR] _fat_remove(): <%s> is a directory\n",
    36993797                pathname );
     
    37033801    {
    37043802        _spin_lock_release( &_fat.fat_lock );
     3803        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3804
    37053805        _printf("\n[FAT ERROR] _fat_remove(): <%s> is not a directory\n",
    37063806                pathname );
     
    37183818    {
    37193819        _spin_lock_release( &_fat.fat_lock );
     3820        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3821
    37203822        _printf("\n[FAT ERROR] _fat_remove(): file <%s> still referenced\n",
    37213823                pathname );
     
    37303832        {
    37313833            _spin_lock_release( &_fat.fat_lock );
     3834            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3835
    37323836            _printf("\n[FAT ERROR] _fat_remove(): cannot scan directory <%s>\n",
    37333837                    pathname );
     
    37373841        {
    37383842            _spin_lock_release( &_fat.fat_lock );
     3843            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3844
    37393845            _printf("\n[FAT ERROR] _fat_remove(): directory <%s> not empty\n",
    37403846                    pathname );
     
    37533859    {
    37543860        _spin_lock_release( &_fat.fat_lock );
     3861        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3862
    37553863        _printf("\n[FAT ERROR] _fat_remove(): cannot remove <%s> from FS\n",
    37563864                pathname );
     
    37603868    // release lock and return success
    37613869    _spin_lock_release( &_fat.fat_lock );
     3870    _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    37623871
    37633872#if GIET_DEBUG_FAT
     
    38213930    }
    38223931
    3823     // take the lock
     3932    // takes the FAT lock and register it in thread context
     3933    static_scheduler_t*  psched = _get_sched();
     3934    unsigned int         ltid   = _get_thread_ltid();
    38243935    _spin_lock_acquire( &_fat.fat_lock );
     3936    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
     3937
    38253938
    38263939    // get "old" and "old_parent" inode pointers
     
    38283941    {
    38293942        _spin_lock_release( &_fat.fat_lock );
     3943        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3944
    38303945        _printf("\n[FAT ERROR] _fat_rename(): <%s> not found\n", old_path );
    38313946        return GIET_FAT32_FILE_NOT_FOUND;
     
    38453960        {
    38463961            _spin_lock_release( &_fat.fat_lock );
     3962            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3963
    38473964            return GIET_FAT32_OK;
    38483965        }
     
    38593976    {
    38603977        _spin_lock_release( &_fat.fat_lock );
     3978        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3979
    38613980        _printf("\n[FAT ERROR] _fat_rename(): <%s> not found\n", new_path );
    38623981        return GIET_FAT32_FILE_NOT_FOUND;
     
    38673986    {
    38683987        _spin_lock_release( &_fat.fat_lock );
    3869         _printf("\n[FAT ERROR] _fat_rename(): can't move %s into its own subdirectory\n", old_path );
     3988        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     3989
     3990        _printf("\n[FAT ERROR] _fat_rename(): can't move %s into  own directory\n", old_path );
    38703991        return GIET_FAT32_MOVE_INTO_SUBDIR;
    38713992    }
     
    38944015            {
    38954016                _spin_lock_release( &_fat.fat_lock );
     4017                _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4018
    38964019                _printf("\n[FAT ERROR] _fat_rename(): cannot scan directory <%s>\n",
    38974020                        to_remove->name );
     
    39014024            {
    39024025                _spin_lock_release( &_fat.fat_lock );
     4026                _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4027
    39034028                _printf("\n[FAT ERROR] _fat_rename(): directory <%s> not empty\n",
    39044029                        to_remove->name );
     
    39114036            {
    39124037                _spin_lock_release( &_fat.fat_lock );
     4038                _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4039
    39134040                _printf("\n[FAT ERROR] _fat_rename(): file <%s> still referenced\n",
    39144041                        to_remove->name );
     
    39454072    {
    39464073        _spin_lock_release( &_fat.fat_lock );
     4074        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4075
    39474076        _printf("\n[FAT ERROR] _fat_rename(): cannot add <%s> into <%s>\n",
    39484077                new->name , new_parent->name );
     
    39594088    {
    39604089        _spin_lock_release( &_fat.fat_lock );
     4090        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4091
    39614092        _printf("\n[FAT ERROR] _fat_rename(): cannot update <%s> on device\n",
    39624093                    new_parent->name );
     
    39684099    {
    39694100        _spin_lock_release( &_fat.fat_lock );
     4101        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4102
    39704103        _printf("\n[FAT ERROR] _fat_rename(): cannot remove <%s> from <%s>\n",
    39714104                old->name , old_parent->name );
     
    39854118    {
    39864119        _spin_lock_release( &_fat.fat_lock );
     4120        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4121
    39874122        _printf("\n[FAT ERROR] _fat_rename(): cannot update <%s> on device\n",
    39884123                    old_parent->name );
     
    39964131        {
    39974132            _spin_lock_release( &_fat.fat_lock );
     4133            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4134
    39984135            _printf("\n[FAT ERROR] _fat_rename(): cannot remove <%s> from FS\n",
    39994136                    to_remove->name );
     
    40044141    // release lock
    40054142    _spin_lock_release( &_fat.fat_lock );
     4143    _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    40064144
    40074145    return GIET_FAT32_OK;
     
    40524190    }
    40534191
    4054     // takes the lock
     4192    // takes the FAT lock and register it in thread context
     4193    static_scheduler_t*  psched = _get_sched();
     4194    unsigned int         ltid   = _get_thread_ltid();
    40554195    _spin_lock_acquire( &_fat.fat_lock );
    4056    
     4196    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
     4197
    40574198    // get inode
    40584199    unsigned int code = _get_inode_from_path( pathname , &inode );
     
    40614202    {
    40624203        _spin_lock_release( &_fat.fat_lock );
     4204        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4205
    40634206        _printf("\n[FAT ERROR] _fat_mkdir(): path to parent not found"
    40644207                " for directory <%s>\n", pathname );
     
    40684211    {
    40694212        _spin_lock_release( &_fat.fat_lock );
     4213        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4214
    40704215        _printf("\n[FAT ERROR] _fat_mkdir(): one name in path too long"
    40714216                " for directory  <%s>\n", pathname );
     
    40754220    {
    40764221        _spin_lock_release( &_fat.fat_lock );
     4222        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4223
    40774224        _printf("\n[FAT ERROR] _fat_mkdir(): directory <%s> already exist\n",
    40784225                pathname );
     
    40984245        {
    40994246            _spin_lock_release( &_fat.fat_lock );
     4247            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4248
    41004249            _printf("\n[FAT ERROR] _fat_mkdir(): no free cluster"
    41014250                    " for directory <%s>\n" , pathname );
     
    41274276        {
    41284277            _spin_lock_release( &_fat.fat_lock );
     4278            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4279
    41294280            _printf("\n[FAT ERROR] _fat_mkdir(): cannot update parent directory"
    41304281                    " for directory <%s>\n" , pathname );
     
    41384289        {
    41394290            _spin_lock_release( &_fat.fat_lock );
     4291            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4292
    41404293            _printf("\n[FAT ERROR] _fat_mkdir(): cannot update DATA region "
    41414294                    " for parent of directory <%s>\n", pathname );
     
    41494302        {
    41504303            _spin_lock_release( &_fat.fat_lock );
     4304            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4305
    41514306            _printf("\n[FAT ERROR] _fat_mkdir(): cannot update FAT region"
    41524307                    " for directory <%s>\n", pathname );
     
    41584313        {
    41594314            _spin_lock_release( &_fat.fat_lock );
     4315            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4316
    41604317            _printf("\n[FAT ERROR] _fat_mkdir(): cannot update FS-INFO"
    41614318                    " for directory <%s>\n", pathname );
     
    41694326        {
    41704327            _spin_lock_release( &_fat.fat_lock );
     4328            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     4329
    41714330            _printf("\n[FAT ERROR] _fat_mkdir(): cannot update DATA region"
    41724331                    " for directory <%s>\n", pathname );
     
    41774336    // release lock
    41784337    _spin_lock_release( &_fat.fat_lock );
     4338    _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    41794339
    41804340    return GIET_FAT32_OK;
     
    42934453        {
    42944454            // seek back to this entry
    4295             _spin_lock_acquire( &_fat.fat_lock );
    4296             _fat.fd[fd_id].seek -= DIR_ENTRY_SIZE;
    4297             _spin_lock_release( &_fat.fat_lock );
     4455            _atomic_increment( &_fat.fd[fd_id].seek , -DIR_ENTRY_SIZE );
    42984456
    42994457            return GIET_FAT32_NO_MORE_ENTRIES;
Note: See TracChangeset for help on using the changeset viewer.