Index: trunk/kernel/fs/vfs.c
===================================================================
--- trunk/kernel/fs/vfs.c	(revision 561)
+++ trunk/kernel/fs/vfs.c	(revision 568)
@@ -28,6 +28,4 @@
 #include <hal_atomic.h>
 #include <hal_special.h>
-#include <readlock.h>
-#include <spinlock.h>
 #include <printk.h>
 #include <list.h>
@@ -43,4 +41,5 @@
 #include <chdev.h>
 #include <process.h>
+#include <cluster.h>
 #include <vfs.h>
 #include <fatfs.h>
@@ -55,6 +54,6 @@
 
 extern vfs_ctx_t          fs_context[FS_TYPES_NR];    // allocated in kernel_init.c
-
 extern chdev_directory_t  chdev_dir;                  // allocated in kernel_init.c  
+extern char *             lock_type_str[];            // allocated in kernel_init.c
   
 //////////////////////////////////////////////////////////////////////////////////////////
@@ -79,5 +78,5 @@
     vfs_ctx->extend         = extend;
 
-    spinlock_init( &vfs_ctx->lock );
+    busylock_init( &vfs_ctx->lock , LOCK_VFS_CTX );
 
     bitmap_init( vfs_ctx->bitmap , BITMAP_SIZE(CONFIG_VFS_MAX_INODES) ); 
@@ -89,5 +88,5 @@
 {
     // get lock on inum allocator
-    spinlock_lock( &ctx->lock );
+    busylock_acquire( &ctx->lock );
 
     // get lid from local inum allocator
@@ -97,5 +96,5 @@
     {
         // release lock
-        spinlock_unlock( &ctx->lock );
+        busylock_release( &ctx->lock );
 
         // return error
@@ -108,5 +107,5 @@
 
         // release lock
-        spinlock_unlock( &ctx->lock );
+        busylock_release( &ctx->lock );
 
         // return inum
@@ -160,8 +159,15 @@
 
 #if DEBUG_VFS_INODE_CREATE
-uint32_t cycle = (uint32_t)hal_get_cycles();
+char           name[CONFIG_VFS_MAX_NAME_LENGTH];
+uint32_t       cycle      = (uint32_t)hal_get_cycles();
+cxy_t          dentry_cxy = GET_CXY( dentry_xp );
+vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp );
+thread_t *     this       = CURRENT_THREAD;
+if( dentry_xp != XPTR_NULL ) hal_remote_strcpy( XPTR( local_cxy  , name ), 
+                                                XPTR( dentry_cxy , dentry_ptr->name ) );
+else                         strcpy( name , "/" );
 if( DEBUG_VFS_INODE_CREATE < cycle )
-printk("\n[DBG] %s : thread %x enter / dentry = %x in cluster %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD, GET_PTR(dentry_xp), GET_CXY(dentry_xp), cycle );
+printk("\n[DBG] %s : thread %x in process %x enter for <%s> / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, name, cycle );
 #endif
  
@@ -232,13 +238,15 @@
     xhtab_init( &inode->children , XHTAB_DENTRY_TYPE );
 
-    // initialize inode locks 
-    remote_rwlock_init( XPTR( local_cxy , &inode->data_lock ) );
-    remote_spinlock_init( XPTR( local_cxy , &inode->main_lock ) );
+    // initialize inode lock 
+    remote_rwlock_init( XPTR( local_cxy , &inode->data_lock ), LOCK_VFS_INODE );
+
+    // initialise lock protecting inode three traversal
+    remote_busylock_init( XPTR( local_cxy , &inode->main_lock ), LOCK_VFS_MAIN );
 
 #if DEBUG_VFS_INODE_CREATE
-cycle = (uint32_t)hal_get_cycles();
+cycle      = (uint32_t)hal_get_cycles();
 if( DEBUG_VFS_INODE_CREATE < cycle )
-printk("\n[DBG] %s : thread %x exit / inode = %x in cluster %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD, inode, local_cxy, cycle );
+printk("\n[DBG] %s : thread %x in process %x exit for <%s> / inode [%x,%x] / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, name, local_cxy, inode, cycle );
 #endif
  
@@ -346,7 +354,7 @@
 
     // get size
-    remote_rwlock_rd_lock( XPTR( cxy , &ptr->data_lock ) );
-    uint32_t size = hal_remote_lw( XPTR( cxy , &ptr->size ) );
-    remote_rwlock_rd_unlock( XPTR( cxy , &ptr->data_lock ) );
+    remote_rwlock_rd_acquire( XPTR( cxy , &ptr->data_lock ) );
+    uint32_t size = hal_remote_l32( XPTR( cxy , &ptr->size ) );
+    remote_rwlock_rd_release( XPTR( cxy , &ptr->data_lock ) );
     return size;
 }
@@ -361,7 +369,7 @@
 
     // set size
-    remote_rwlock_wr_unlock( XPTR( cxy , &ptr->data_lock ) );
-    hal_remote_sw( XPTR( cxy , &ptr->size ) , size );
-    remote_rwlock_wr_unlock( XPTR( cxy , &ptr->data_lock ) );
+    remote_rwlock_wr_release( XPTR( cxy , &ptr->data_lock ) );
+    hal_remote_s32( XPTR( cxy , &ptr->size ) , size );
+    remote_rwlock_wr_release( XPTR( cxy , &ptr->data_lock ) );
 }
 
@@ -374,5 +382,5 @@
 
     // release the main lock
-    remote_spinlock_unlock( XPTR( cxy , &ptr->main_lock ) );
+    remote_busylock_release( XPTR( cxy , &ptr->main_lock ) );
 }
 
@@ -385,5 +393,5 @@
 
     // get the main lock
-    remote_spinlock_lock( XPTR( cxy , &ptr->main_lock ) );
+    remote_busylock_acquire( XPTR( cxy , &ptr->main_lock ) );
 }
 
@@ -403,5 +411,5 @@
 
     // get parent dentry
-    dentry_xp  = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
+    dentry_xp  = hal_remote_l64( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
 
     // get local copy of name
@@ -475,5 +483,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VFS_DENTRY_CREATE < cycle )
-printk("\n[DBG] %s : dentry initialised\n", __FUNCTION__ );
+printk("\n[DBG] %s : thread %x in process %x / dentry <%s> initialised / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, dentry->name, cycle );
 #endif
 
@@ -488,5 +497,6 @@
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VFS_DENTRY_CREATE < cycle )
-printk("\n[DBG] %s : dentry registerd in htab\n", __FUNCTION__ );
+printk("\n[DBG] %s : thread %x in process %x / dentry <%s> registered / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, dentry->name, cycle );
 #endif
 
@@ -544,4 +554,11 @@
     vfs_file_t  * file;
 	kmem_req_t    req;
+
+#if DEBUG_VFS_FILE_CREATE
+uint32_t cycle = (uint32_t)hal_get_cycles();
+if( DEBUG_VFS_OPEN < cycle )
+printk("\n[DBG] %s : thread %x in process %x enter for inode %x in cluster %x / cycle %d\n",
+__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, inode, local_cxy, cycle );
+#endif
 
     // allocate memory for new file descriptor
@@ -563,10 +580,10 @@
     file->mapper   = inode->mapper;
 
-    remote_rwlock_init( XPTR( local_cxy , &file->lock ) );
+    remote_rwlock_init( XPTR( local_cxy , &file->lock ), LOCK_VFS_FILE );
 
     *file_xp = XPTR( local_cxy , file );
 
-#if DEBUG_VFS_OPEN
-uint32_t cycle = (uint32_t)hal_get_cycles();
+#if DEBUG_VFS_FILE_CREATE
+cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VFS_OPEN < cycle )
 printk("\n[DBG] %s : thread %x in process %x created file %x in cluster %x / cycle %d\n",
@@ -729,5 +746,5 @@
 
     // get inode type from remote file descriptor
-    inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type   ) );
+    inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type   ) );
    
     assert( (inode_type == INODE_TYPE_FILE) ,
@@ -735,5 +752,5 @@
 
     // get mapper pointer and file offset from file descriptor
-    file_offset = hal_remote_lw( XPTR( file_cxy , &file_ptr->offset ) );
+    file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
     mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
 
@@ -784,5 +801,5 @@
 
     // get inode type from remote file descriptor
-    inode_type = hal_remote_lw( XPTR( file_cxy , &file_ptr->type   ) );
+    inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type   ) );
    
     // action depends on inode type
@@ -790,5 +807,5 @@
     {
         // get mapper pointer and file offset from file descriptor
-        file_offset = hal_remote_lw( XPTR( file_cxy , &file_ptr->offset ) );
+        file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
         mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );
 
@@ -848,9 +865,9 @@
 
     // take file descriptor lock
-    remote_rwlock_wr_lock( lock_xp );
+    remote_rwlock_wr_acquire( lock_xp );
 
     if      ( whence == SEEK_CUR )   // new = current + offset
     {
-        new = hal_remote_lw( offset_xp ) + offset;
+        new = hal_remote_l32( offset_xp ) + offset;
     }
     else if ( whence == SEEK_SET )   // new = offset
@@ -863,18 +880,18 @@
         inode_ptr = (vfs_inode_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
 
-        new = hal_remote_lw( XPTR( file_cxy , &inode_ptr->size ) ) + offset;
+        new = hal_remote_l32( XPTR( file_cxy , &inode_ptr->size ) ) + offset;
     }
     else
     {
         printk("\n[ERROR] in %s : illegal whence value\n", __FUNCTION__ );
-        remote_rwlock_wr_unlock( lock_xp );
+        remote_rwlock_wr_release( lock_xp );
         return -1;
     }
 
     // set new offset
-    hal_remote_sw( offset_xp , new );
+    hal_remote_s32( offset_xp , new );
 
     // release file descriptor lock
-    remote_rwlock_wr_unlock( lock_xp );
+    remote_rwlock_wr_release( lock_xp );
 
     // success
@@ -929,5 +946,5 @@
 
     // take the lock protecting the list of copies
-    remote_spinlock_lock( lock_xp );
+    remote_queuelock_acquire( lock_xp );
 
     XLIST_FOREACH( root_xp , iter_xp )
@@ -948,9 +965,9 @@
         xptr_t entry_xp         = XPTR( process_cxy , &process_ptr->fd_array.array[file_id] );
 
-// remote_rwlock_wr_lock( fd_array_lock_xp );
-
-        hal_remote_swd( entry_xp , XPTR_NULL );
+// remote_rwlock_wr_acquire( fd_array_lock_xp );
+
+        hal_remote_s64( entry_xp , XPTR_NULL );
         
-// remote_rwlock_wr_unlock( fd_array_lock_xp );
+// remote_rwlock_wr_release( fd_array_lock_xp );
 
         vfs_file_count_down( file_xp );
@@ -960,5 +977,5 @@
 
     // release the lock protecting the list of copies
-    remote_spinlock_unlock( lock_xp );
+    remote_queuelock_release( lock_xp );
 
 #if (DEBUG_VFS_CLOSE & 1) 
@@ -1064,5 +1081,5 @@
 
     // get inode type from remote file
-    inode_type = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->type ) );
+    inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) );
 
     if( inode_type != INODE_TYPE_DIR )
@@ -1072,5 +1089,8 @@
     }
 
-    assert( false , "not implemented\n" );
+    // TODO implement this function using process CWD lock
+
+assert( false , "not implemented\n" );
+
     return 0;
 }
@@ -1101,5 +1121,5 @@
     
     // get inode type from remote inode
-    inode_type = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->type ) );
+    inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) );
 
     
@@ -1123,5 +1143,4 @@
 //            Inode Tree functions
 //////////////////////////////////////////////////////////////////////////////////////////
-
 
 //////////////////////////////////////////////////////////////////////////
@@ -1172,5 +1191,5 @@
 
     // get inode type
-    inode_type = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->type ) );
+    inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) );
 
     // get local pointer on associated mapper
@@ -1192,5 +1211,5 @@
 
         // get xhtab lock
-        xhtab_read_lock( children_xp );
+        xhtab_lock( children_xp );
 
         // get first dentry from xhtab
@@ -1204,5 +1223,5 @@
 
             // get extended pointer on child inode
-            child_inode_xp = hal_remote_lwd( XPTR( child_dentry_cxy,
+            child_inode_xp = hal_remote_l64( XPTR( child_dentry_cxy,
                                                    &child_dentry_ptr->child_xp ) );
 
@@ -1210,5 +1229,5 @@
             child_dentry_name_xp = XPTR( child_dentry_cxy , &child_dentry_ptr->name );
 
-            // recursive call on child inode
+            // recursive call on inode display
             vfs_recursive_display( child_inode_xp,
                                    child_dentry_name_xp,
@@ -1220,5 +1239,5 @@
 
         // release xhtab lock
-        xhtab_read_unlock( children_xp );
+        xhtab_unlock( children_xp );
     }
 }  // end vfs_recursive_display()
@@ -1231,5 +1250,4 @@
     cxy_t          dentry_cxy;
     vfs_dentry_t * dentry_ptr;
-    uint32_t       save_sr;
 
     // get target inode cluster and local pointer 
@@ -1238,5 +1256,5 @@
 
     // get extended pointer on associated dentry
-    dentry_xp   = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
+    dentry_xp   = hal_remote_l64( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
 
     // check if target inode is the File System root
@@ -1265,5 +1283,5 @@
 
     // get TXT0 lock in busy waiting mode
-    remote_spinlock_lock_busy( lock_xp , &save_sr );
+    remote_busylock_acquire( lock_xp );
 
     // print header
@@ -1274,5 +1292,5 @@
 
     // release lock
-    remote_spinlock_unlock_busy( lock_xp , save_sr );
+    remote_busylock_release( lock_xp );
 
 }  // end vfs_display()
@@ -1298,7 +1316,7 @@
 
     // get inode access mode, UID, and GID
-    // TODO uint32_t  mode = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->mode ) );
-    uid_t     uid  = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->uid  ) );
-    gid_t     gid  = hal_remote_lw( XPTR( inode_cxy , &inode_ptr->gid  ) );
+    // TODO uint32_t  mode = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->mode ) );
+    uid_t     uid  = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->uid  ) );
+    gid_t     gid  = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->gid  ) );
 
     // FIXME : me must use mode
@@ -1342,5 +1360,5 @@
 
     // return child inode
-    *child_xp = (xptr_t)hal_remote_lwd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) );
+    *child_xp = (xptr_t)hal_remote_l64( XPTR( dentry_cxy , &dentry_ptr->child_xp ) );
     return true;
 
@@ -1496,5 +1514,5 @@
             parent_ptr = GET_PTR( parent_xp );
             ctx_ptr    = (vfs_ctx_t *)hal_remote_lpt( XPTR( parent_cxy,&parent_ptr->ctx ) );
-            fs_type    = hal_remote_lw( XPTR( parent_cxy , &ctx_ptr->type ) );
+            fs_type    = hal_remote_l32( XPTR( parent_cxy , &ctx_ptr->type ) );
 
             // select a cluster for missing inode
@@ -1545,5 +1563,5 @@
                 if( last && create && dir )  // new directory  => update inode type
                 {
-                     hal_remote_sw( XPTR( child_cxy, &child_ptr->type ), INODE_TYPE_DIR );
+                     hal_remote_s32( XPTR( child_cxy, &child_ptr->type ), INODE_TYPE_DIR );
 
 #if (DEBUG_VFS_LOOKUP & 1)
@@ -1555,5 +1573,5 @@
                 else if ( last && create )   // new file => update inode type
                 {
-                     hal_remote_sw( XPTR( child_cxy, &child_ptr->type ), INODE_TYPE_FILE );
+                     hal_remote_s32( XPTR( child_cxy, &child_ptr->type ), INODE_TYPE_FILE );
 
 #if (DEBUG_VFS_LOOKUP & 1)
@@ -1574,5 +1592,5 @@
             {
                 // load child mapper from device if child is a directory (prefetch)
-                if( hal_remote_lw( XPTR( child_cxy , &child_ptr->type ) ) == INODE_TYPE_DIR ) 
+                if( hal_remote_l32( XPTR( child_cxy , &child_ptr->type ) ) == INODE_TYPE_DIR ) 
                 {
                     if( child_cxy == local_cxy )
@@ -1700,5 +1718,5 @@
 
         // get extended pointer on parent dentry		
-        dentry_xp = (xptr_t)hal_remote_lwd( XPTR( inode_cxy , inode_ptr->parent_xp ) );
+        dentry_xp = (xptr_t)hal_remote_l64( XPTR( inode_cxy , inode_ptr->parent_xp ) );
 
         // get dentry cluster and local pointer
@@ -1707,5 +1725,5 @@
 
         // get dentry name length and pointer
-        length =  hal_remote_lw( XPTR( dentry_cxy , &dentry_ptr->length ) );
+        length =  hal_remote_l32( XPTR( dentry_cxy , &dentry_ptr->length ) );
         name   = (char *)hal_remote_lpt( XPTR( dentry_cxy , &dentry_ptr->name ) );
 
@@ -1727,5 +1745,5 @@
 
 		// get extended pointer on next inode
-        inode_xp = (xptr_t)hal_remote_lwd( XPTR( dentry_cxy , dentry_ptr->parent ) );
+        inode_xp = (xptr_t)hal_remote_l64( XPTR( dentry_cxy , dentry_ptr->parent ) );
     }
     while( (dentry_xp != XPTR_NULL) );
@@ -1757,7 +1775,9 @@
 #if DEBUG_VFS_ADD_CHILD
 uint32_t cycle = (uint32_t)hal_get_cycles();
+thread_t * this = CURRENT_THREAD; 
 if( DEBUG_VFS_ADD_CHILD < cycle )
-printk("\n[DBG] %s : thread %x enter for <%s> / child_cxy = %x / parent_cxy = %x / cycle %d\n",
-__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, name,
+printk("\n[DBG] %s : thread %x in process %x enter for <%s>\n"
+"      child_cxy = %x / parent_cxy = %x / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, name,
 child_cxy, parent_cxy, (uint32_t)hal_get_cycles() );
 #endif
@@ -1770,10 +1790,4 @@
                                    parent_ptr,
                                    &dentry_xp );
-
-#if (DEBUG_VFS_ADD_CHILD & 1)
-if( (DEBUG_VFS_ADD_CHILD < cycle) && (error == 0) )
-printk("\n[DBG] %s : dentry <%s> created in cluster %x\n", __FUNCTION__, name, local_cxy );
-#endif
-
     }
     else                               // parent cluster is remote
@@ -1785,10 +1799,4 @@
                                       &dentry_xp,
                                       &error );
-
-#if (DEBUG_VFS_ADD_CHILD & 1)
-if( (DEBUG_VFS_ADD_CHILD < cycle) && (error == 0) )
-printk("\n[DBG] %s : dentry <%s> created in cluster %x\n", __FUNCTION__, name, parent_cxy );
-#endif
-
     }
                                       
@@ -1799,4 +1807,10 @@
         return ENOMEM;
     }
+
+#if(DEBUG_VFS_ADD_CHILD & 1)
+if( DEBUG_VFS_ADD_CHILD < cycle )
+printk("\n[DBG] %s : thread %x in process %x / dentry <%s> created in cluster %x\n",
+__FUNCTION__, this->trdid, this->process->pid, name, parent_cxy );
+#endif
 
     // 2. create child inode TODO : define attr / mode / uid / gid
@@ -1817,11 +1831,4 @@
                                   gid,
                                   &inode_xp );
-
-#if (DEBUG_VFS_ADD_CHILD & 1)
-if( DEBUG_VFS_ADD_CHILD < cycle )
-printk("\n[DBG] %s : inode <%x> created in cluster %x\n",
-__FUNCTION__ , GET_PTR(inode_xp) , local_cxy );
-#endif
-
     }
     else                              // child cluster is remote
@@ -1838,11 +1845,4 @@
                                      &inode_xp,
                                      &error );
-
-#if (DEBUG_VFS_ADD_CHILD & 1)
-if( DEBUG_VFS_ADD_CHILD < cycle )
-printk("\n[DBG] %s : inode <%s> created in cluster %x\n",
-__FUNCTION__ , GET_PTR(inode_xp) , child_cxy );
-#endif
-
     }
                                      
@@ -1858,14 +1858,20 @@
     }
 
+#if(DEBUG_VFS_ADD_CHILD & 1)
+if( DEBUG_VFS_ADD_CHILD < cycle )
+printk("\n[DBG] %s : thread %x in process %x / inode <%s> created in cluster %x\n",
+__FUNCTION__ , this->trdid, this->process->pid, name , child_cxy );
+#endif
+
     // 3. update extended pointer on inode in dentry
     cxy_t          dentry_cxy = GET_CXY( dentry_xp );
     vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp );
-    hal_remote_swd( XPTR( dentry_cxy , &dentry_ptr->child_xp ) , inode_xp );
+    hal_remote_s64( XPTR( dentry_cxy , &dentry_ptr->child_xp ) , inode_xp );
 
 #if DEBUG_VFS_ADD_CHILD
 cycle = (uint32_t)hal_get_cycles();
 if( DEBUG_VFS_ADD_CHILD < cycle )
-printk("\n[DBG] %s : thread %x in process %x exit for <%s>\n",
-__FUNCTION__, CURRENT_THREAD, CURRENT_THREAD->process->pid, name );
+printk("\n[DBG] %s : thread %x in process %x exit for <%s> / cycle %d\n",
+__FUNCTION__, this->trdid, this->process->pid, name, (uint32_t)hal_get_cycles() );
 #endif
 
@@ -1893,5 +1899,5 @@
 
     // get cluster and pointers of associated dentry
-    dentry_xp  = hal_remote_lwd( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
+    dentry_xp  = hal_remote_l64( XPTR( inode_cxy , &inode_ptr->parent_xp ) );
     dentry_cxy = GET_CXY( dentry_xp ); 
     dentry_ptr = GET_PTR( dentry_xp );
@@ -1958,7 +1964,12 @@
     if( fs_type == FS_TYPE_FATFS )
     {
-        rwlock_wr_lock( &mapper->lock );
+        // enter mapper in write mode
+        rwlock_wr_acquire( &mapper->lock );
+
+        // move page to mapper
         error = fatfs_mapper_move_page( page , to_mapper ); 
-        rwlock_wr_unlock( &mapper->lock );
+
+        // exit mapper in write mode
+        rwlock_wr_release( &mapper->lock );
     }
     else if( fs_type == FS_TYPE_RAMFS )
