Index: soft/giet_vm/giet_fat32/fat32.c
===================================================================
--- soft/giet_vm/giet_fat32/fat32.c	(revision 291)
+++ soft/giet_vm/giet_fat32/fat32.c	(revision 295)
@@ -17,6 +17,6 @@
 // 2. This FAT32 library uses a FAT cache whose storage capacity is one
 //    sector (512 bytes, or 128 cluster indexes in FAT)
-// 3. This FAT32 library can be used in three modes: BOOT/KERNEL/USER
-//    defining three different behaviours for the IOC driver.
+// 3. This FAT32 library can be used in four modes: BOOT_PA/BOOT_VA/KERNEL/USER
+//    defining different behaviours for the IOC driver.
 //////////////////////////////////////////////////////////////////////////////////
 
@@ -46,14 +46,11 @@
     temp[8] = 0;
 
-    _tty_get_lock( 0 );
-    _puts("\n*********************** fat_cache_lba = ");
-    _putx( fat.cache_lba );
-    _puts(" **************************\n");
+    _printf("\n*********************** fat_cache_lba = %x *****************************\n",
+            fat.cache_lba );
 
     for ( line=0 ; line<16 ; line++ )
     {
         // display address 
-        _putx( (fat.cache_lba<<9) + (line<<5) );
-        _puts(" : ");
+        _printf( "%x : ", (fat.cache_lba<<9) + (line<<5) );
 
         // display data hexa
@@ -65,6 +62,5 @@
                                  (fat.fat_cache[byte+2]<< 8) |
                                  (fat.fat_cache[byte+3]);
-            _putx( hexa );
-            _puts(" | ");
+            _printf("%x | ", hexa );
 
             // prepare display ascii
@@ -76,9 +72,8 @@
         
         // display data ascii 
-        _puts( (char*)temp );
-        _puts("\n");
-    }
-    _puts("***************************************************************************\n");
-    _tty_release_lock( 0 );
+        _printf( (char*)temp );
+        _printf("\n");
+    }
+    _printf("**************************************************************************\n");
 } // end display_fat_cache()  
 #endif
@@ -202,14 +197,12 @@
         
         // access fat
-        if( _ioc_read( mode,              // mode for IOC driver
+        if( _ioc_read( 0,                 // channel
+                       mode,              // mode for IOC driver
                        lba,               // sector index 
                        fat.fat_cache,     // fat cache
                        1 ) )              // one sector
         {
-            _tty_get_lock( 0 );
-            _puts("[FAT_ERROR] in get_next cluster_id() cannot read block ");
-            _putd( lba );
-            _puts("\n");
-            _tty_release_lock( 0 );
+            _printf("[FAT_ERROR] in get_next cluster_id() "
+                    "cannot read block %x\n", lba );
             return 1;
         }
@@ -271,8 +264,5 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] filename ");
-_puts( string );
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] filename %s", string );
 #endif
 
@@ -282,9 +272,5 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts(" converted to 8.3 SFN format : ");
-_puts( sfn_string );
-_puts("\n");
-_tty_release_lock( 0 );
+_printf(" converted to 8.3 SFN format : %s\n", sfn_string );
 #endif
 
@@ -298,9 +284,5 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts(" converted to 8.3 SFN format : ");
-_puts( string );
-_puts("\n");
-_tty_release_lock( 0 );
+_printf(" converted to 8.3 SFN format : %s\n", sfn_string );
 #endif
 
@@ -358,9 +340,5 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts(" converted to 8.3 SFN format : ");
-_puts( sfn_string );
-_puts("\n");
-_tty_release_lock( 0 );
+_printf(" converted to 8.3 SFN format : %s\n", sfn_string );
 #endif
 
@@ -524,14 +502,11 @@
     is_sfn = is_short( file_name, sfn );
 
-    if ( _ioc_read( IOC_KERNEL_MODE, // mode for IOC driver
+    if ( _ioc_read( 0,               // channel
+                    IOC_KERNEL_MODE, // mode for IOC driver
                     lba,             // sector index 
                     fat.fat_cache,   // buffer address
                     1 ) )            // one sector
     {
-        _tty_get_lock( 0 );
-        _puts("[FAT ERROR] in update_entry() cannot read sector ");
-        _putd( lba );
-        _puts("\n");
-        _tty_release_lock( 0 );
+        _printf("[FAT ERROR] in update_entry() cannot read sector %x\n", lba );
         return 1;
     }
@@ -562,8 +537,5 @@
             else if (ord == NO_MORE_ENTRY )            // end of directory : return
             {
-                _tty_get_lock( 0 );
-                _puts("[FAT ERROR] in update_entry() end of directory reaches ");
-                _puts("\n");
-                _tty_release_lock( 0 );
+                _printf("[FAT ERROR] in update_entry() : reaches end of directory\n");
                 return 1;
             }
@@ -591,8 +563,5 @@
             else if (ord == NO_MORE_ENTRY )			   // end of directory : return
             {
-                _tty_get_lock( 0 );
-                _puts("[FAT ERROR] in update_entry() end of directory reaches ");
-                _puts("\n");
-                _tty_release_lock( 0 );
+                _printf("[FAT ERROR] in update_entry() reaches end of directory\n");
                 return 1;
             }
@@ -643,12 +612,13 @@
     }
 
-    return _ioc_write( IOC_KERNEL_MODE,
-                       lba,  
-                       fat.fat_cache,
-                       1     );
-}
-//////////////////////////////////////////////////////////////////////////////////
-// This function update FS_INFO, for new last cluster allocated and number of free
-// cluster. 
+    return _ioc_write( 0,                // channel
+                       IOC_KERNEL_MODE,  // mode
+                       lba,              // sector index
+                       fat.fat_cache,    // source buffer
+                       1 );              // one sector
+}
+//////////////////////////////////////////////////////////////////////////////////
+// This function update FS_INFO:
+// last cluster allocated and number of free cluster. 
 // Return 0 in case of success, > 0 if failure.
 //////////////////////////////////////////////////////////////////////////////////
@@ -658,7 +628,5 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Enter in update_fs_info()\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] Enter update_fs_info()\n");
 #endif
 
@@ -670,14 +638,11 @@
     else                                   // miss cache
     {
-        if ( _ioc_read( IOC_KERNEL_MODE,   // mode for IOC driver
+        if ( _ioc_read( 0,                 // channel
+                        IOC_KERNEL_MODE,   // mode for IOC driver
                         lba,               // sector index 
-                        fat.fat_cache,     // fat cache
+                        fat.fat_cache,     // source buffer
                         1 ) )              // one sector
         {
-            _tty_get_lock( 0 );
-            _puts("[FAT_ERROR] in update_fat() cannot read block ");
-            _putd( lba );
-            _puts("\n");
-            _tty_release_lock( 0 );
+            _printf("[FAT_ERROR] in update_fat() cannot read block %x\n", lba );
             return 1;
         }
@@ -686,8 +651,9 @@
         write_entry( FS_FREE_CLUSTER_HINT, fat.fat_cache, fat.last_cluster_allocated );
     }
-    return _ioc_write( IOC_KERNEL_MODE,       
-                       lba,           
-                       fat.fat_cache,           
-                       1 ); 
+    return _ioc_write( 0,                // channel
+                       IOC_KERNEL_MODE,  // mode    
+                       lba,              // sector index
+                       fat.fat_cache,    // source buffer
+                       1 );              // one sector
 }
 
@@ -703,13 +669,6 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Enter in update_fat() :\n");
-_puts("    - Cluster to update = ");
-_putd( cluster );
-_puts("\n");
-_puts("    - Value to write = ");
-_putd( value );
-_puts("\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] Enter update_fat() : cluster = %x / value = %x\n",
+        cluster, value );
 #endif
 
@@ -720,14 +679,11 @@
     else                                   // miss cache
     {
-        if ( _ioc_read( IOC_KERNEL_MODE,   // mode for IOC driver
+        if ( _ioc_read( 0,                 // channel
+                        IOC_KERNEL_MODE,   // mode for IOC driver
                         lba,               // sector index 
-                        fat.fat_cache,     // fat cache
+                        fat.fat_cache,     // source buffer
                         1 ) )              // one sector
         {
-            _tty_get_lock( 0 );
-            _puts("[FAT_ERROR] in update_fat() cannot read block ");
-            _putd( lba );
-            _puts("\n");
-            _tty_release_lock( 0 );
+            _printf("[FAT_ERROR] in update_fat() cannot read block %x\n");
             return 1;
         }
@@ -735,8 +691,9 @@
         write_entry( ((cluster % 128) << 2), 4, fat.fat_cache, value );
     }
-    return _ioc_write( IOC_KERNEL_MODE,       
-                       lba,           
-                       fat.fat_cache,           
-                       1 ); 
+    return _ioc_write( 0,                // channel
+                       IOC_KERNEL_MODE,  // mode      
+                       lba,              // sector indexs
+                       fat.fat_cache,    // source buffer 
+                       1 );              // one sector
 }
 
@@ -759,7 +716,5 @@
     if ( get_next_cluster_id( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER)
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_allocate() : first free_cluster isnt free\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_allocate() : first free_cluster not free\n");
         return -1;
     }
@@ -767,19 +722,10 @@
     if ( count > fat.number_free_cluster )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_allocate() : Not enough free cluster(s) for this allocation\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_allocate() : Not enough free cluster(s)\n");
         return -1;
     }
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Enter in _fat_allocate() :\n");
-_puts("    - Need to allocate ");
-_putd( count );
-_puts(" cluster(s) for file ");
-_putd( fd_id );
-_puts("\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] Enter in _fat_allocate() for file %d\n", fd_id );
 #endif
 
@@ -795,15 +741,6 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Cluster to update is : ");
-_putd( last_cluster_file );
-_puts("\n");
-_puts("[FAT DEBUG] Free cluster is : ");
-_putd( free_cluster );
-_puts("\n");
-_puts("[FAT DEBUG] Number of cluster need to be allocated : ");
-_putd( cluster_to_allocate );
-_puts("\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] cluster to update = %x / free cluster = %x / clusters required = %d\n",
+        last_cluster_file, free_cluster, cluster_to_allocate );
 #endif
 
@@ -812,9 +749,5 @@
         if ( update_fat( last_cluster_file, free_cluster ) )
         {
-            _tty_get_lock( 0 );
-            _puts("\n[FAT ERROR] in _fat_allocate() : update fat for file ");
-            _putd( fd_id );
-            _puts(" failed\n");
-            _tty_release_lock( 0 );
+            _printf("\n[FAT ERROR] in _fat_allocate() : update fat failed\n");
             return -1;
         }
@@ -831,9 +764,5 @@
             if ( update_fat( last_cluster_file, END_OF_CHAIN_CLUSTER ) )
             {
-                _tty_get_lock( 0 );
-                _puts("\n[FAT ERROR] in _fat_allocate() : update fat for file ");
-                _putd( fd_id );
-                _puts(" failed\n");
-                _tty_release_lock( 0 );
+                _printf("\n[FAT ERROR] in _fat_allocate() : update fat failed\n");
                 return -1;
             }
@@ -845,7 +774,5 @@
         if ( get_next_cluster_id( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER)
         {
-            _tty_get_lock( 0 );
-            _puts("\n[FAT ERROR] in _fat_allocate() : free_cluster isnt free\n");
-            _tty_release_lock( 0 );
+            _printf("\n[FAT ERROR] in _fat_allocate() : free_cluster not free\n");
             return -1;
         }
@@ -859,9 +786,5 @@
     if ( update_fs_info() )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_allocate() : update fs_info for file ");
-        _putd( fd_id );
-        _puts(" failed\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_allocate() : update fs_info failed\n");
         return -1;
     }
@@ -895,9 +818,5 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] enter _scan_directory() searching dir/file : ");
-_puts( file_name );
-_puts("\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] enter _scan_directory() searching dir/file %s", filename );
 #endif
 
@@ -920,14 +839,11 @@
     // load first cluster sector from DATA region into FAT cache
     // other sectors will be loaded inside loop as required
-    if( _ioc_read( mode,            // mode for IOC driver
+    if( _ioc_read( 0,               // channel
+                   mode,            // mode for IOC driver
                    lba,             // sector index 
                    fat.fat_cache,   // buffer address
                    1 ) )            // one sector
     {
-        _tty_get_lock( 0 );
-        _puts("[FAT ERROR] in scan directory() cannot read sector ");
-        _putd( lba );
-        _puts("\n");
-        _tty_release_lock( 0 );
+        _printf("[FAT ERROR] in scan directory() cannot read sector %x\n", lba );
         return -1;
     }
@@ -935,7 +851,7 @@
     fat.cache_lba = lba;
 
-    #if GIET_DEBUG_FAT
-    display_fat_cache();
-    #endif
+#if GIET_DEBUG_FAT
+display_fat_cache();
+#endif
 
     // in this loop we scan all names in directory identified by cluster: 
@@ -961,14 +877,11 @@
                 block_id = fat.sectors_per_cluster;
             }
-            if( _ioc_read( mode,            // mode for IOC driver
+            if( _ioc_read( 0,               // channel
+                           mode,            // mode for IOC driver
                            lba,             // sector index 
                            fat.fat_cache,   // buffer address
                            1 ) )            // one sector
             {
-                _tty_get_lock( 0 );
-                _puts("[FAT ERROR] in scan directory() cannot read sector ");
-                _putd( lba );
-                _puts("\n");
-                _tty_release_lock( 0 );
+                _printf("[FAT ERROR] in scan directory() cannot read sector %x\n", lba );
                 return -1;
             }
@@ -1072,9 +985,4 @@
             *lba_dir_entry = lba;
 
-#if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] FILE FOUND\n");
-_tty_release_lock( 0 );
-#endif
             return read_cluster( dir_entry );
         }
@@ -1094,7 +1002,5 @@
                        unsigned int    dir_cluster )
 {
-    _tty_get_lock( 0 );
-    _puts("\n[FAT ERROR] _fat_create() not implemented\n");
-    _tty_release_lock( 0 );
+    _printf("\n[FAT ERROR] _fat_create() not implemented\n");
     return 0;
 }  //end _fat_create()
@@ -1115,37 +1021,39 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Enter _fat_init() / fat_cache_base = ");
-_putx( (unsigned int)fat.fat_cache );
-_puts("\n");
-_tty_release_lock( 0 );
+unsigned int procid  = _get_procid();
+unsigned int cid     = procid / NB_PROCS_MAX;
+unsigned int lpid    = procid % NB_PROCS_MAX;
+unsigned int x       = cid >> Y_WIDTH;
+unsigned int y       = cid & ((1<<Y_WIDTH) - 1);
+
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] enters _fat_init()\n",
+        x, y, lpid );
 #endif
 
     // load Master Boot Record (sector 0) into fat cache
-    if ( _ioc_read( mode,             // mode for IOC driver
+    if ( _ioc_read( 0,                // channel
+                    mode,             // mode for IOC driver
                     0,                // sector index 
                     fat.fat_cache,    // buffer address
                     1 ) )             // one sector
     { 
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_init() cannot load Boot Sector\n"); 
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_init() cannot load Boot Sector\n"); 
         return -1;
     }
     fat.cache_lba = 0;
     
+#if GIET_DEBUG_FAT
+display_fat_cache();
+#endif
+
     // checking Boot sector integrity
     if( MBR_SIGNATURE_VALUE != read_entry( MBR_SIGNATURE_POSITION, fat.fat_cache, 1))
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] Boot sector not recognized or corrupt \n"); 
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] Boot sector not recognized or corrupt \n"); 
         return -1;  
     }
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Boot Sector Loaded\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] Boot Sector Loaded\n");
 #endif
 
@@ -1155,14 +1063,11 @@
 
     // load Partition Boot Record (first partition sector) into fat cache
-    if ( _ioc_read( mode,                // mode for IOC driver
+    if ( _ioc_read( 0,                   // channel
+                    mode,                // mode for IOC driver
                     fat.partition_lba,   // sector index
                     fat.fat_cache,       // buffer address
                     1 ) )                // one sector
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_init() cannot load block ");
-        _putd( fat.partition_lba );
-        _puts("\n"); 
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_init() cannot load block %x\n", fat.partition_lba );
         return -1;
     }
@@ -1170,7 +1075,5 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Partition First Sector Loaded\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] Partition First Sector Loaded\n");
 #endif
 
@@ -1179,36 +1082,25 @@
     if( read_entry( BPB_BYTSPERSEC, fat.fat_cache, 1 ) != 512 )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] The sector size must be 512 bytes\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] The sector size must be 512 bytes\n");
         return -1;  
     }
     if( read_entry( BPB_RSVDSECCNT, fat.fat_cache, 1 ) != 32 ) 
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] The RSVD region in FAT32 must be 32 sectors\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] The RSVD region in FAT32 must be 32 sectors\n");
         return -1;  
     }
     if( read_entry( BPB_NUMFATS, fat.fat_cache, 1 ) != 1 )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] The number of FAT copies in FAT region must be 1\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] The number of FAT copies in FAT region must be 1\n");
         return -1;  
     }
     if( (read_entry( BPB_FAT32_FATSZ32, fat.fat_cache, 1 ) & 0xF) != 0 )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] The FAT region in FAT32 must be multiple of 32 sectors\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] The FAT region in FAT32 must be multiple of 32 sectors\n");
         return -1;  
     }
-
     if( read_entry( BPB_FAT32_ROOTCLUS, fat.fat_cache, 1 ) != 2 )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] The first cluster index must be 2\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] The first cluster index must be 2\n");
         return -1;  
     }
@@ -1227,20 +1119,15 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] FS_INFO Sector = ");
-_putd(fat.fs_info_lba);
-_puts("\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] FS_INFO Sector = %x\n", fat.fs_info_lba );
 #endif
 
     // load FS_INFO into fat cache
-    if ( _ioc_read( mode,               // mode for IOC driver
+    if ( _ioc_read( 0,                  // channel
+                    mode,               // mode for IOC driver
                     fat.fs_info_lba,    // sector index 
                     fat.fat_cache,      // buffer address
                     1 ) )               // one sector
     { 
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_init() cannot load FS_INFO Sector\n"); 
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_init() cannot load FS_INFO Sector\n"); 
         return -1;
     }
@@ -1251,20 +1138,7 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Number of Free Clusters = ");
-_putd(fat.number_free_cluster);
-_puts("\n");
-_puts("\n[FAT DEBUG] Last known cluster allocated = ");
-_putd(fat.last_cluster_allocated);
-_puts("\n");
-_puts("\n[FAT DEBUG] FS_INFO Sector Loaded\n");
-_tty_release_lock( 0 );
-#endif
-
-
-#if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Exit _fat_init()\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] exit _fat_init() / "
+        "free clusters = %x / last allocated cluster = %x\n",
+        fat.number_free_cluster, fat.last_cluster_allocated );
 #endif
 
@@ -1275,13 +1149,13 @@
 void _fat_print()
 {
-    _puts("\n################################ FAT32 ###############################");  
-    _puts("\nFAT initialised                "); _putx( fat.initialised );
-    _puts("\nSector Size  (bytes)           "); _putx( fat.sector_size );
-    _puts("\nSectors per cluster            "); _putx( fat.sectors_per_cluster );
-    _puts("\nPartition size (sectors)       "); _putx( fat.partition_sectors );
-    _puts("\nPartition first lba            "); _putx( fat.partition_lba ); 
-    _puts("\nData region first lba          "); _putx( fat.data_lba );
-    _puts("\nNumber of sectors for one FAT  "); _putx( fat.fat_sectors );
-    _puts("\n######################################################################\n");
+    _printf("\n########################## FAT32 ###########################");  
+    _printf("\nFAT initialised                %d", fat.initialised );
+    _printf("\nSector Size  (bytes)           %x", fat.sector_size );
+    _printf("\nSectors per cluster            %x", fat.sectors_per_cluster );
+    _printf("\nPartition size (sectors)       %x", fat.partition_sectors );
+    _printf("\nPartition first lba            %x", fat.partition_lba ); 
+    _printf("\nData region first lba          %x", fat.data_lba );
+    _printf("\nNumber of sectors for one FAT  %x", fat.fat_sectors );
+    _printf("\n############################################################\n");
 }
 
@@ -1294,4 +1168,5 @@
 // a new file is created and introduced in the directory.
 // Finally, it sets a new open file in the file descriptors array.
+// The same file can be open several times by differents taks.
 ///////////////////////////////////////////////////////////////////////////////
 // Returns file descriptor index if success, returns -1 if error.
@@ -1311,28 +1186,48 @@
     
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] enter _fat_open() for file ");
-_puts( pathname );
-_puts("\n");
-_tty_release_lock( 0 );
-#endif
-
-    // check FAT initialised
+unsigned int procid  = _get_procid();
+unsigned int cid     = procid / NB_PROCS_MAX;
+unsigned int lpid    = procid % NB_PROCS_MAX;
+unsigned int x       = cid >> Y_WIDTH;
+unsigned int y       = cid & ((1<<Y_WIDTH) - 1);
+
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] enters _fat_open() for file %s\n",
+        x, y, lpid, pathname );
+#endif
+
+    // checking arguments
+    if ( creat )
+    {
+        _printf("[FAT ERROR] in _fat_open() : create not supported yet\n");
+        return -1;
+    }
+
+    // takes the FAT lock for exclusive access
+    _get_lock( &fat.lock );
+
+#if GIET_DEBUG_FAT
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] takes the FAT lock\n",
+        x, y, lpid );
+#endif
+
+    // FAT initialisation if required
     if( fat.initialised != FAT_INITIALISED )
     {
         if ( _fat_init( mode ) )
         {
-            _puts("[FAT ERROR] Cannot initialize FAT descriptor from Boot Sector\n");
-            _exit();
-        }
-
-#if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] FAT initialisation completed at cycle ");
-_putd(_get_proctime());
-_puts("\n");
+            _printf("[FAT ERROR] in _fat_open() : Cannot initialize FAT descriptor\n");
+
+            // release FAT lock
+            _release_lock( &fat.lock );
+
+            return -1;
+        }
+
+#if GIET_DEBUG_FAT
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] initialises FAT descriptor\n",
+        x, y, lpid );
 _fat_print();
-_tty_release_lock( 0 );
-#endif
+#endif
+
     }
  
@@ -1350,9 +1245,6 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] _fat_open : search dir/file : ");
-_puts( name );
-_puts("\n");
-_tty_release_lock( 0 );
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] search dir/file : %s\n",
+        x, y, lpid, name );
 #endif
 
@@ -1373,22 +1265,12 @@
         else if ( cluster == END_OF_CHAIN_CLUSTER )
         {
-            _tty_get_lock( 0 );
-            _puts("\n[FAT ERROR] in _fat_open() for file ");
-            _puts( pathname );
-            _puts(" : cannot found name ");
-            _puts( name );
-            _puts("\n");
-            _tty_release_lock( 0 );
+            _printf("\n[FAT ERROR] in _fat_open() cannot found %s\n", name );
+
+            // release FAT lock
+            _release_lock( &fat.lock );
+
             return -1;
         }
     }
-
-#if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] File ");
-_puts( pathname );
-_puts(" found\n");
-_tty_release_lock( 0 );
-#endif
 
     // check the next value for cluster index found
@@ -1414,12 +1296,10 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] file  ");
-_puts( pathname );
-_puts(" open with fd_id = ");
-_putd( fd_id );
-_puts("\n");
-_tty_release_lock( 0 );
-#endif
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] open file %s with fd = %d\n",
+        x, y, lpid, pathname, fd_id );
+#endif
+
+            // release FAT lock
+            _release_lock( &fat.lock );
 
             return fd_id;
@@ -1427,9 +1307,10 @@
         else
         {
-            _tty_get_lock( 0 );
-            _puts("\n[FAT ERROR] in _fat_open() for file ");
-            _puts( pathname );
-            _puts(" : file descriptor array full\n ");
-            _tty_release_lock( 0 );
+            _printf("\n[FAT ERROR] in _fat_open() for file %s : fd array full\n",
+                    pathname );
+
+            // release FAT lock
+            _release_lock( &fat.lock );
+
             return -1;
         }
@@ -1437,9 +1318,10 @@
     else
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_open() for file ");
-        _puts( pathname );
-        _puts(" : file found, but bad cluster\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_open() for file %s : bad cluster\n",
+                pathname );
+
+        // release FAT lock
+        _release_lock( &fat.lock );
+
         return -1;
     }
@@ -1461,14 +1343,15 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Enter _fat_read() for file ");
-_puts( fat.fd[fd_id].name );
-_puts("\n - buffer base     = ");
-_putx( (unsigned int)buffer );
-_puts("\n - skipped sectors = ");
-_putd( offset );
-_puts("\n - read sectors    = "); 
-_putd( count );
-_tty_release_lock( 0 );
+unsigned int procid  = _get_procid();
+unsigned int cid     = procid / NB_PROCS_MAX;
+unsigned int lpid    = procid % NB_PROCS_MAX;
+unsigned int x       = cid >> Y_WIDTH;
+unsigned int y       = cid & ((1<<Y_WIDTH) - 1);
+
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] enters _fat_read() for file %s\n",
+        " - buffer vbase    = %x\n"
+        " - skipped sectors = %x\n"
+        " - read sectors    = %x\n", 
+        x, y, lpid, fat.fd[fd_id].name, (unsigned int)buffer, offset, count );
 #endif
 
@@ -1490,32 +1373,20 @@
     if ( fd_id >= GIET_OPEN_FILES_MAX )
     { 
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_read() : illegal file descriptor index\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_read() : illegal file descriptor index\n");
         return -1;
     }
     if ( fat.fd[fd_id].used != 1 )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_read() : file not open\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_read() : file not open\n");
         return -1;
     }
     if ( ((unsigned int)buffer & 0x1FF) != 0 )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_read() : memory buffer not sector aligned\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_read() : memory buffer not sector aligned\n");
         return -1;
     }
     if ( offset >= file_sectors )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] offset larger than number of sectors in file\n");
-        _puts(" - offset       = ");
-        _putd( offset );
-        _puts(" - file_sectors = ");
-        _putd( file_sectors );
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] offset larger than number of sectors\n");
         return -1;
     }
@@ -1533,11 +1404,7 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n - first cluster   = ");
-_putd( cluster );   
-_puts("\n - skiped clusters = ");
-_putd( clusters_to_skip );   
-_puts("\n");
-_tty_release_lock( 0 );
+_printf(" - first cluster   = %x\n"
+        " - skiped clusters = %x\n",
+        cluster, clusters_to_skip );   
 #endif
 
@@ -1568,25 +1435,16 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] _fat_read() IOC request : buf = ");
-_putx( (unsigned int)dst );
-_puts(" / lba = ");
-_putd( lba );
-_puts(" / sectors = "); 
-_putd( iter_sectors );
-_puts("\n");  
-_tty_release_lock( 0 );
-#endif
-
-        if( _ioc_read( mode,              // mode for IOC driver
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] makes an IOC read :"
+        " buf = %x / lba = %x / sectors = %d\n",
+        x, y, lpid, (unsigned int)dst, lba, iter_sectors );
+#endif
+
+        if( _ioc_read( 0,                 // channel
+                       mode,              // mode for IOC driver
                        lba,               // first sector index 
                        dst,               // buffer address
                        iter_sectors ) )   // number of sectors
         {
-            _tty_get_lock( 0 );
-            _puts("\n[FAT ERROR] in _fat_read() cannot load block ");
-            _putd( lba );
-            _puts("\n"); 
-            _tty_release_lock( 0 );
+            _printf("\n[FAT ERROR] in _fat_read() cannot load block %x\n", lba );
             return -1;
         }
@@ -1653,18 +1511,18 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] Enter _fat_write() for file ");
-_puts( fat.fd[fd_id].name );
-_puts("\n - buffer base     = ");
-_putx( (unsigned int)buffer );
-_puts("\n - skipped sectors = ");
-_putd( offset );
-_puts("\n - write sectors    = "); 
-_putd( count );
-_puts("\n - file size (sectors)  = "); 
-_putd( file_sectors );
-_puts("\n - need allocate = "); 
- allocate ? _puts( "True" ) : _puts( "False");
-_tty_release_lock( 0 );
+unsigned int procid  = _get_procid();
+unsigned int cid     = procid / NB_PROCS_MAX;
+unsigned int lpid    = procid % NB_PROCS_MAX;
+unsigned int x       = cid >> Y_WIDTH;
+unsigned int y       = cid & ((1<<Y_WIDTH) - 1);
+
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] enters _fat_write() for file %s\n",
+        " - buffer vbase    = %x\n"
+        " - skipped sectors = %x\n"
+        " - write sectors   = %x\n" 
+        " - file sectors    = %x\n" 
+        " - need allocate   = %d\n", 
+        x, y, lpid, fat.fd[fd_id].name, (unsigned int)buffer, 
+        offset, count, file_sectors, allocate );
 #endif
 
@@ -1672,21 +1530,15 @@
     if ( fd_id >= GIET_OPEN_FILES_MAX )
     { 
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_write() : illegal file descriptor index\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_write() : illegal file descriptor index\n");
         return -1;
     }
     if ( fat.fd[fd_id].used != 1 )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_write() : file not open\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_write() : file not open\n");
         return -1;
     }
     if ( ((unsigned int)buffer & 0x1FF) != 0 )
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_write() : memory buffer not sector aligned\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_write() : memory buffer not sector aligned\n");
         return -1;
     }
@@ -1696,9 +1548,5 @@
         if ( _fat_allocate( fd_id, (required_cluster - current_cluster) ) < 0 )
         {
-            _tty_get_lock( 0 );
-            _puts("\n[FAT ERROR] in _fat_write() : fat_allocate for file ");
-            _putd( fd_id );
-            _puts(" failed\n");
-            _tty_release_lock( 0 );
+            _printf("\n[FAT ERROR] in _fat_write() : fat_allocate failed\n");
             return -1;
         }
@@ -1713,11 +1561,7 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n - first cluster   = ");
-_putd( cluster );   
-_puts("\n - skiped clusters = ");
-_putd( clusters_to_skip );   
-_puts("\n");
-_tty_release_lock( 0 );
+_printf(" - first cluster   = %x\n"
+        " - skiped clusters = %x\n",
+        cluster, clusters_to_skip );   
 #endif
 
@@ -1748,25 +1592,16 @@
 
 #if GIET_DEBUG_FAT
-_tty_get_lock( 0 );
-_puts("\n[FAT DEBUG] _fat_write() IOC request : buf = ");
-_putx( (unsigned int)src );
-_puts(" / lba = ");
-_putd( lba );
-_puts(" / sectors = "); 
-_putd( iter_sectors );
-_puts("\n");  
-_tty_release_lock( 0 );
-#endif
-
-        if( _ioc_write( mode,              // mode for IOC driver
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] makes an IOC write : "
+        "buf = %x / lba = %x / sectors = %x\n",
+        x, y, lpid, (unsigned int)src, lba, iter_sectors );
+#endif
+
+        if( _ioc_write( 0,                 // channel
+                        mode,              // mode for IOC driver
                         lba,               // first sector index 
-                        src,               // buffer address
+                        src,               // source buffer address
                         iter_sectors ) )   // number of sectors
         {
-            _tty_get_lock( 0 );
-            _puts("\n[FAT ERROR] in _fat_write() cannot write block ");
-            _putd( lba );
-            _puts("\n"); 
-            _tty_release_lock( 0 );
+            _printf("\n[FAT ERROR] in _fat_write() cannot write block %x\n", lba );
             return -1;
         }
@@ -1792,9 +1627,5 @@
     if ( update_entry(fd_id, DIR_FILE_SIZE, fat.fd[fd_id].file_size) )
     {
-            _tty_get_lock( 0 );
-            _puts("\n[FAT ERROR] in _fat_write() update entry for file ");
-            _putd( fd_id );
-            _puts(" failed\n"); 
-            _tty_release_lock( 0 );
+            _printf("\n[FAT ERROR] in _fat_write() update entry failed\n");
             return -1;
     }
@@ -1826,7 +1657,5 @@
     else
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_fstat() : illegal file descriptor index\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_fstat() : illegal file descriptor index\n");
         return -1;
     } 
@@ -1847,7 +1676,5 @@
     else
     {
-        _tty_get_lock( 0 );
-        _puts("\n[FAT ERROR] in _fat_close() : illegal file descriptor index\n");
-        _tty_release_lock( 0 );
+        _printf("\n[FAT ERROR] in _fat_close() : illegal file descriptor index\n");
         return -1;
     } 
@@ -1863,7 +1690,7 @@
                     unsigned int flags )     // unused: TODO
 {
-    return _fat_open( IOC_KERNEL_MODE,       // we KERNEL_MODE, because
+    return _fat_open( IOC_KERNEL_MODE,       // we use KERNEL_MODE, because
                       pathname,              // we need to write into FAT cache
-                      0 );       
+                      0 );                   // no creation if not found
 }
 
@@ -1909,7 +1736,5 @@
                      unsigned int whence )
 {
-    _tty_get_lock( 0 );
-    _puts("[GIET ERROR] _fat_user_lseek function not implemented\n");
-    _tty_release_lock( 0 );
+    _printf("[GIET ERROR] _fat_user_lseek() not implemented\n");
     _exit();
     return 0;
