Index: soft/giet_vm/giet_fat32/fat32.c
===================================================================
--- soft/giet_vm/giet_fat32/fat32.c	(revision 474)
+++ soft/giet_vm/giet_fat32/fat32.c	(revision 503)
@@ -36,5 +36,5 @@
 // This function displays the content of the FAT cache
 //////////////////////////////////////////////////////////////////////////////////
-void display_fat_cache()
+void _display_fat_cache()
 {
     unsigned int line;
@@ -78,5 +78,5 @@
     _puts("***************************************************************************\n");
 
-} // end display_fat_cache()  
+} // end _display_fat_cache()  
 
 //////////////////////////////////////////////////////////////////////////////////
@@ -191,13 +191,6 @@
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
 
-_puts("\n[FAT DEBUG] _get_next_cluster() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] enters for cluster ");
-_putx( cluster );
-_puts("\n");
+_printf("\n[FAT DEBUG] _get_next_cluster() : P[%d,%d,%d] enters for cluster %x\n",
+      x , y , p , cluster );
 #endif
 
@@ -214,7 +207,5 @@
                        1 ) )              // one sector
         {
-            _puts("[FAT_ERROR] in get_next cluster_id() : cannot read block ");
-            _putx( lba );
-            _puts("\n");
+            _printf("[FAT_ERROR] in get_next cluster_id() : cannot read block %x", lba );
             return 1;
         }
@@ -222,5 +213,5 @@
     
 #if (GIET_DEBUG_FAT > 1)
-display_fat_cache();
+_display_fat_cache();
 #endif
 
@@ -232,13 +223,5 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _get_next_cluster() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] next cluster = ");
-_putx( next );
-_puts("\n");
+_printf("\n[FAT DEBUG] _get_next_cluster() : P[%d,%d,%d] next cluster = %x\n", next );
 #endif
 
@@ -512,7 +495,5 @@
                     1 ) )            // one sector
     {
-        _puts("[FAT ERROR] in update_entry() cannot read sector ");
-        _putx( lba );
-        _puts("\n");
+        _printf("\n[FAT ERROR] in update_entry() cannot read sector %x\n", lba );
         return 1;
     }
@@ -543,5 +524,5 @@
             else if (ord == NO_MORE_ENTRY )            // end of directory : return
             {
-                _puts("[FAT ERROR] in update_entry() : reaches end of directory\n");
+                _printf("\n[FAT ERROR] in update_entry() : reaches end of directory\n");
                 return 1;
             }
@@ -569,5 +550,5 @@
             else if (ord == NO_MORE_ENTRY )			   // end of directory : return
             {
-                _puts("[FAT ERROR] in update_entry() reaches end of directory\n");
+                _printf("\n[FAT ERROR] in update_entry() reaches end of directory\n");
                 return 1;
             }
@@ -634,5 +615,5 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _update_fs_info() : enters\n");
+_printf("\n[FAT DEBUG] _update_fs_info() : enters\n");
 #endif
 
@@ -650,7 +631,5 @@
                         1 ) )              // one sector
         {
-            _puts("[FAT_ERROR] in _update_fat() cannot read block ");
-            _putx( lba );
-            _puts("\n");
+            _printf("\n[FAT_ERROR] in _update_fat() cannot read block %x\n", lba );
             return 1;
         }
@@ -677,9 +656,5 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _update_fat() : cluster = ");
-_putx( cluster );
-_puts(" / value = ");
-_putx( value );
-_puts("\n");
+_printf("\n[FAT DEBUG] _update_fat() : cluster = %x / value = %x\n", cluster, value );
 #endif
 
@@ -696,5 +671,5 @@
                         1 ) )              // one sector
         {
-            _puts("[FAT_ERROR] in _update_fat() cannot read block %x\n");
+            _printf("\n[FAT_ERROR] in _update_fat() cannot read block %x\n", lba );
             return 1;
         }
@@ -717,7 +692,7 @@
                                  unsigned int count )
 {
-    unsigned int next_cluster = fat.fd[fd_id].first_cluster;    // Get the first cluster of file
-    unsigned int cluster_to_allocate = count;                   // Number of cluster to allocate
-    unsigned int last_cluster_file;                             // Last cluster of the file (EOC)
+    unsigned int next_cluster = fat.fd[fd_id].first_cluster;    // get first cluster
+    unsigned int cluster_to_allocate = count;                   // clusters to allocate
+    unsigned int last_cluster_file;                             // Last cluster (EOC)
     unsigned int free_cluster = fat.last_cluster_allocated + 1; // First free cluster
 
@@ -725,5 +700,5 @@
     if ( _get_next_cluster( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER)
     {
-        _puts("\n[FAT ERROR] in _fat_allocate() : first free cluster not free\n");
+        _printf("\n[FAT ERROR] in _fat_allocate() : first free cluster not free\n");
         return -1;
     }
@@ -731,19 +706,19 @@
     if ( count > fat.number_free_cluster )
     {
-        _puts("\n[FAT ERROR] in _fat_allocate() : Not enough free cluster(s)\n");
+        _printf("\n[FAT ERROR] in _fat_allocate() : Not enough free cluster(s)\n");
         return -1;
     }
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _fat_allocate() for fd = ");
-_putd( fd_id );
-_puts("\n");
+_printf("\n[FAT DEBUG] _fat_allocate() for fd = %d\n" fd_id );
 #endif
 
     // Get the last cluster allocated for the file (seek END_OF_CHAIN_CLUSTER).
-    do{
+    do 
+    {
         last_cluster_file = next_cluster;
         next_cluster      = _get_next_cluster( IOC_KERNEL_MODE, next_cluster );
-    }while ( next_cluster < END_OF_CHAIN_CLUSTER );
+    }
+    while ( next_cluster < END_OF_CHAIN_CLUSTER );
 
     // Loop on the number of clusters to be allocated
@@ -752,11 +727,6 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] cluster to update = ");
-_putx( last_cluster_file );
-_puts(" / free cluster = ");
-_putx( free_cluster );
-_puts(" / clusters required = ");
-_putx( cluster_to_allocate );
-_puts("\n");
+_printf("\n[FAT DEBUG] cluster to update = %x / free cluster = %x / nb_clusters %d\n",
+        last_cluster_file , free_cluster , cluster_to_allocate );
 #endif
 
@@ -765,5 +735,5 @@
         if ( _update_fat( last_cluster_file, free_cluster ) )
         {
-            _puts("\n[FAT ERROR] in _fat_allocate() : update fat failed\n");
+            _printf("\n[FAT ERROR] in _fat_allocate() : update fat failed\n");
             return -1;
         }
@@ -780,5 +750,5 @@
             if ( _update_fat( last_cluster_file, END_OF_CHAIN_CLUSTER ) )
             {
-                _puts("\n[FAT ERROR] in _fat_allocate() : update fat failed\n");
+                _printf("\n[FAT ERROR] in _fat_allocate() : update fat failed\n");
                 return -1;
             }
@@ -790,5 +760,5 @@
         if ( _get_next_cluster( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER)
         {
-            _puts("\n[FAT ERROR] in _fat_allocate() : free_cluster not free\n");
+            _printf("\n[FAT ERROR] in _fat_allocate() : free_cluster not free\n");
             return -1;
         }
@@ -802,5 +772,5 @@
     if ( _update_fs_info() )
     {
-        _puts("\n[FAT ERROR] in _fat_allocate() : update fs_info failed\n");
+        _printf("\n[FAT ERROR] in _fat_allocate() : update fs_info failed\n");
         return -1;
     }
@@ -847,15 +817,6 @@
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
 
-_puts("\n[FAT DEBUG] _scan_directory() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] enters for ");
-_puts( file_name );
-_puts(" / is_sfn = ");
-_putd( is_sfn );
-_puts("\n"); 
+_printf("\n[FAT DEBUG] _scan_directory() : P[%d,%d,%d] enters for %s\n",
+      x, y, p, file_name );
 #endif
 
@@ -872,7 +833,5 @@
                    1 ) )            // one sector
     {
-        _puts("[FAT ERROR] in _scan_directory() : cannot read sector ");
-        _putx( lba );
-        _puts("\n");
+        _printf("[\nFAT ERROR] in _scan_directory() : cannot read sector %x\n", lba );
         return -1;
     }
@@ -881,5 +840,5 @@
 
 #if ( GIET_DEBUG_FAT > 1 )
-display_fat_cache();
+_display_fat_cache();
 #endif
 
@@ -912,7 +871,5 @@
                            1 ) )            // one sector
             {
-                _puts("[FAT ERROR] in _scan_directory() : cannot read sector ");
-                _putx( lba );
-                _puts("\n");
+                _printf("\n[FAT ERROR] in _scan_directory() : cannot read sector %x\n", lba);
                 return -1;
             }
@@ -1008,15 +965,6 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _scan_directory() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] found ");
-_puts( file_name );
-_puts(" / cluster = ");
-_putx( searched_cluster );
-_puts("\n"); 
+_printf("\n[FAT DEBUG] _scan_directory() : P[%d,%d,%d] found %s"
+        " : cluster = %x\n", x, y, p, file_name, searched_cluster );
 #endif
 
@@ -1035,5 +983,5 @@
                         unsigned int    dir_cluster )
 {
-    _puts("\n[FAT ERROR] _fat_create() not implemented\n");
+    _printf("\n[FAT ERROR] _fat_create() not implemented\n");
     return 0;
 }  //end _fat_create()
@@ -1049,5 +997,5 @@
 // This should be done only once.
 //////////////////////////////////////////////////////////////////////////
-// Return 0 if success, Return -1 if failure 
+// Return 0 if success, exit if failure 
 //////////////////////////////////////////////////////////////////////////
 int _fat_init( unsigned int mode )   // mode for IOC driver
@@ -1061,14 +1009,10 @@
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
 
-_puts("\n[FAT DEBUG] _fat_init() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] enters _fat_init()");
-if ( mode == IOC_BOOT_MODE   ) _puts(" in BOOT_MODE\n");
-if ( mode == IOC_KERNEL_MODE ) _puts(" in KERNEL_MODE\n");
-if ( mode == IOC_USER_MODE   ) _puts(" in USER_MODE\n");
+if ( mode == IOC_BOOT_MODE ) 
+_printf("\n[FAT DEBUG] _fat_init() : P[%d,%d,%d] enters in BOOT_MODE\n",x,y,p);
+if ( mode == IOC_KERNEL_MODE )
+_printf("\n[FAT DEBUG] _fat_init() : P[%d,%d,%d] enters in KERNEL_MODE\n",x,y,p);
+if ( mode == IOC_USER_MODE )
+_printf("\n[FAT DEBUG] _fat_init() : P[%d,%d,%d] enters in USER_MODE\n",x,y,p);
 #endif
 
@@ -1076,6 +1020,6 @@
     if ( fat.initialised == FAT_INITIALISED )
     {
-        _puts("\n[FAT WARNING] Strange initialisation  of a FAT already initialised...\n");
-        return 0;
+        _printf("\n[FAT WARNING] Strange, FAT already initialised...\n");
+        _exit();
     }
 
@@ -1087,11 +1031,12 @@
                     1 ) )                // one sector
     {
-        _puts("\n[FAT ERROR] in _fat_init() cannot load VBR\n");
-        return -1;
+        _printf("\n[FAT ERROR] in _fat_init() cannot load VBR\n");
+        _exit();
     }
     fat.cache_lba = 0;
 
-#if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _fat_init() : Boot Sector Loaded\n");
+#if GIET_DEBUG_FAT > 1
+_printf("\n[FAT DEBUG] _fat_init() : Boot Sector Loaded\n");
+_display_fat_cache();
 #endif
 
@@ -1099,21 +1044,21 @@
     if( _read_entry( BPB_BYTSPERSEC, fat.fat_cache, 1 ) != 512 )
     {
-        _puts("\n[FAT ERROR] The sector size must be 512 bytes\n");
-        return -1;  
+        _printf("\n[FAT ERROR] The sector size must be 512 bytes\n");
+        _exit();
     }
     if( _read_entry( BPB_NUMFATS, fat.fat_cache, 1 ) != 1 )
     {
-        _puts("\n[FAT ERROR] The number of FAT copies in FAT region must be 1\n");
-        return -1;  
+        _printf("\n[FAT ERROR] The number of FAT copies in FAT region must be 1\n");
+        _exit();
     }
     if( (_read_entry( BPB_FAT32_FATSZ32, fat.fat_cache, 1 ) & 0xF) != 0 )
     {
-        _puts("\n[FAT ERROR] The FAT region in FAT32 must be multiple of 32 sectors\n");
-        return -1;  
+        _printf("\n[FAT ERROR] The FAT region in FAT32 must be multiple of 32 sectors\n");
+        _exit();
     }
     if( _read_entry( BPB_FAT32_ROOTCLUS, fat.fat_cache, 1 ) != 2 )
     {
-        _puts("\n[FAT ERROR] The first cluster index must be 2\n");
-        return -1;  
+        _printf("\n[FAT ERROR] The first cluster index must be 2\n");
+        _exit();
     }
     // FS Info always in sector 1
@@ -1136,7 +1081,5 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _fat_init() : FS_INFO Sector = ");
-_putx( fat.fs_info_lba );
-_puts("\n");
+_printf("\n[FAT DEBUG] _fat_init() : FS_INFO Sector = %x\n", fat.fs_info_lba );
 #endif
 
@@ -1148,6 +1091,6 @@
                     1 ) )               // one sector
     { 
-        _puts("\n[FAT ERROR] in _fat_init() cannot load FS_INFO Sector\n"); 
-        return -1;
+        _printf("\n[FAT ERROR] in _fat_init() cannot load FS_INFO Sector\n"); 
+        _exit();
     }
     fat.cache_lba = fat.fs_info_lba;
@@ -1159,11 +1102,5 @@
 #if GIET_DEBUG_FAT
 _fat_print();
-_puts("\n[FAT DEBUG] P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] exit _fat_init()\n");
+_printf("\n[FAT DEBUG] P[%d,%d,%d] exit _fat_init()\n" );
 #endif
 
@@ -1174,14 +1111,22 @@
 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("\nFAT region first lba             "); _putx( fat.fat_lba );
-    _puts("\nData region first lba            "); _putx( fat.data_lba );
-    _puts("\nNumber of sectors for one FAT    "); _putx( fat.fat_sectors );
-    _puts("\nNumber of free clusters          "); _putx( fat.number_free_cluster );
-    _puts("\nLast allocated cluster           "); _putx( fat.last_cluster_allocated );
-    _puts("\n#################################################################\n");
+    _printf("\n########################## FAT32 ################################"  
+            "\nFAT initialised                  %x"
+            "\nSector Size  (bytes)             %x"
+            "\nSectors per cluster              %x"
+            "\nFAT region first lba             %x"
+            "\nData region first lba            %x"
+            "\nNumber of sectors for one FAT    %x"
+            "\nNumber of free clusters          %x"
+            "\nLast allocated cluster           %x" 
+            "\n#################################################################\n",
+            fat.initialised,
+            fat.sector_size,
+            fat.sectors_per_cluster,
+            fat.fat_lba,
+            fat.data_lba,
+            fat.fat_sectors,
+            fat.number_free_cluster,
+            fat.last_cluster_allocated );
 }
 
@@ -1216,13 +1161,6 @@
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
 
-_puts("\n[FAT DEBUG] P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] enters _fat_open() for path ");
-_puts( pathname );
-_puts("\n");
+_printf("\n[FAT DEBUG] P[%d,%d,%d] enters _fat_open() for path %s\n",
+        x, y, p, pathname );
 #endif
 
@@ -1230,5 +1168,5 @@
     if ( creat )
     {
-        _puts("[FAT ERROR] in _fat_open() : create not supported yet\n");
+        _printf("\n[FAT ERROR] in _fat_open() : create not supported yet\n");
         return -1;
     }
@@ -1237,5 +1175,5 @@
     if( fat.initialised != FAT_INITIALISED )
     {
-        _puts("[FAT ERROR] in _fat_open() : FAT not initialised\n");
+        _printf("\n[FAT ERROR] in _fat_open() : FAT not initialised\n");
         return -1;
     }
@@ -1244,11 +1182,6 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _fat_open() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] takes the FAT lock\n");
+_printf("\n[FAT DEBUG] _fat_open() : P[%d,%d,%d] takes the FAT lock\n",
+        x, y, p );
 #endif
  
@@ -1266,13 +1199,6 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _fat_open() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] search dir/file ");
-_puts( name );
-_puts("\n");
+_printf("\n[FAT DEBUG] _fat_open() : P[%d,%d,%d] search file/dir %s\n",
+        x, y, p, name );
 #endif
 
@@ -1293,7 +1219,5 @@
         else if ( cluster == END_OF_CHAIN_CLUSTER )
         {
-            _puts("\n[FAT ERROR] in _fat_open() cannot found ");
-            _puts( name );
-            _puts("\n");
+            _printf("\n[FAT ERROR] in _fat_open() cannot found %s\n", name );
             _spin_lock_release( &fat.fat_lock );
             return -1;
@@ -1302,15 +1226,6 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _fat_open() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] cluster index for file ");
-_puts( pathname );
-_puts(" = ");
-_putx( cluster );
-_puts("\n");
+_printf("\n[FAT DEBUG] _fat_open() : P[%d,%d,%d] cluster for %s = %x\n",
+       x, y, p, pathname, cluster );
 #endif
 
@@ -1337,15 +1252,6 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _fat_open() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] exit : fd = ");
-_putd( fd_id );
-_puts(" for file ");
-_puts( pathname );
-_puts("\n");
+_printf("\n[FAT DEBUG] _fat_open() : P[%d,%d,%d] exit : fd = %d for file %s\n",
+        x, y, p, fd_id, pathname );
 #endif
 
@@ -1357,7 +1263,6 @@
         else
         {
-            _puts("\n[FAT ERROR] in _fat_open() for file ");
-            _puts( pathname );
-            _puts(" : fd array full\n");
+            _printf("\n[FAT ERROR] in _fat_open() for file %s : fd array full\n", 
+                    pathname );
             _spin_lock_release( &fat.fat_lock );
             return -1;
@@ -1366,7 +1271,6 @@
     else
     {
-        _puts("\n[FAT ERROR] in _fat_open() for file ");
-        _puts( pathname );
-        _puts(" : bad cluster\n");
+        _printf("\n[FAT ERROR] in _fat_open() for file %s : bad cluster\n",
+                pathname );
         _spin_lock_release( &fat.fat_lock );
         return -1;
@@ -1399,15 +1303,15 @@
     if ( fd_id >= GIET_OPEN_FILES_MAX )
     { 
-        _puts("\n[FAT ERROR] in _fat_read() : illegal file descriptor index\n");
+        _printf("\n[FAT ERROR] in _fat_read() : illegal file descriptor index\n");
         return -1;
     }
     if ( fat.fd[fd_id].used != 1 )
     {
-        _puts("\n[FAT ERROR] in _fat_read() : file not open\n");
+        _printf("\n[FAT ERROR] in _fat_read() : file not open\n");
         return -1;
     }
     if ( ((unsigned int)buffer & 0x1FF) != 0 )
     {
-        _puts("\n[FAT ERROR] in _fat_read() : memory buffer not sector aligned\n");
+        _printf("\n[FAT ERROR] in _fat_read() : memory buffer not sector aligned\n");
         return -1;
     }
@@ -1420,5 +1324,5 @@
     if ( offset >= file_sectors )
     {
-        _puts("\n[FAT ERROR] offset larger than number of sectors\n");
+        _printf("\n[FAT ERROR] offset larger than number of sectors\n");
         return -1;
     }
@@ -1440,23 +1344,17 @@
 unsigned int y       = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
-_puts("\n[FAT DEBUG] _fat_read() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] enters for file ");
-_puts( fat.fd[fd_id].name ); 
-_puts("\n - buffer vbase    = ");
-_putx( (unsigned int)buffer );
-_puts("\n - skipped sectors = ");
-_putx( offset );
-_puts("\n - read sectors    = ");
-_putx( count );
-_puts("\n - first cluster   = ");
-_putx( cluster );
-_puts("\n - skiped clusters = ");
-_putx( clusters_to_skip );   
-_puts("\n");
+_printf("\n[FAT DEBUG] _fat_read() : P[%d,%d,%d] enters for file %s\n"
+        " - buffer vbase     = %x\n"
+        " - skipped sectors  = %x\n"
+        " - read sectors     = %x\n"
+        " - first cluster    = %x\n"
+        " - skipped clusters = %x\n",
+        x, y, p, 
+        fat.fd[fd_id].name,
+        (unsigned int)buffer,
+        offset,
+        count,
+        cluster,
+        clusters_to_skip );
 #endif
 
@@ -1487,20 +1385,14 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _fat_read() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] makes an IOC read");
-_puts("\n - cluster = ");
-_putx( cluster );
-_puts("\n - buf     = ");
-_putx( (unsigned int)dst );
-_puts("\n - lba     = ");
-_putx( lba );
-_puts("\n - sectors = ");
-_putd( iter_sectors );
-_puts("\n");
+_printf("\n[FAT DEBUG] _fat_read() : P[%d,%d,%d] makes an IOC read\n"
+        " - cluster = %x\n"
+        " - buffer  = %x\n"
+        " - lba     = %x\n"
+        " - sectors = %x\n",
+        x, y, p,
+        cluster,
+        (unsigned int)dst,
+        lba,
+        iter_sectors );
 #endif
 
@@ -1511,7 +1403,5 @@
                        iter_sectors ) )   // number of sectors
         {
-            _puts("\n[FAT ERROR] in _fat_read() cannot load block ");
-            _putx( lba );
-            _puts("\n");
+            _printf("\n[FAT ERROR] in _fat_read() cannot load block %x", lba );
             return -1;
         }
@@ -1582,22 +1472,18 @@
 unsigned int y       = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1);
 unsigned int p       = procid & ((1<<P_WIDTH)-1);
-_puts("\n[FAT DEBUG] _fat_write() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] enters for file ");
-_puts( fat.fd[fd_id].name ); 
-_puts("\n - buffer vbase    = ");
-_putx( (unsigned int)buffer );
-_puts("\n - skipped sectors = ");
-_putx( offset );
-_puts("\n - write sectors   = ");
-_putx( count );
-_puts("\n - file sectors    = ");
-_putx( file_sectors );
-_puts("\n - need_allocate   = ");
-_putd( allocate );   
+
+_printf("\n[FAT DEBUG] _fat_write() : P[%d,%d,%d] enters 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, p,
+        fat.fd[fd_id].name
+        (unsigned int)buffer,
+        offset,
+        count,
+        file_sectors,
+        allocate );
 #endif
 
@@ -1605,15 +1491,15 @@
     if ( fd_id >= GIET_OPEN_FILES_MAX )
     { 
-        _puts("\n[FAT ERROR] in _fat_write() : illegal file descriptor index\n");
+        _printf("\n[FAT ERROR] in _fat_write() : illegal file descriptor index\n");
         return -1;
     }
     if ( fat.fd[fd_id].used != 1 )
     {
-        _puts("\n[FAT ERROR] in _fat_write() : file not open\n");
+        _printf("\n[FAT ERROR] in _fat_write() : file not open\n");
         return -1;
     }
     if ( ((unsigned int)buffer & 0x1FF) != 0 )
     {
-        _puts("\n[FAT ERROR] in _fat_write() : memory buffer not sector aligned\n");
+        _printf("\n[FAT ERROR] in _fat_write() : memory buffer not sector aligned\n");
         return -1;
     }
@@ -1623,5 +1509,5 @@
         if ( _fat_allocate( fd_id, (required_cluster - current_cluster) ) < 0 )
         {
-            _puts("\n[FAT ERROR] in _fat_write() : fat_allocate failed\n");
+            _printf("\n[FAT ERROR] in _fat_write() : fat_allocate failed\n");
             return -1;
         }
@@ -1636,9 +1522,6 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n - first cluster   = ");
-_putx( cluster );
-_puts("\n - skiped clusters = ");
-_putx( clusters_to_skip );   
-_puts("\n");
+_printf("\n[FAT DEBUG] _fat_write() : P[%d,%d,%d] get cluster %x\n",
+        x, y, p, cluster );
 #endif
 
@@ -1669,20 +1552,14 @@
 
 #if GIET_DEBUG_FAT
-_puts("\n[FAT DEBUG] _fat_write() : P[");
-_putd( x );
-_puts(",");
-_putd( y );
-_puts(",");
-_putd( p );
-_puts("] makes an IOC write");
-_puts("\n - cluster = ");
-_putx( cluster );
-_puts("\n - buf     = ");
-_putx( (unsigned int)src );
-_puts("\n - lba     = ");
-_putx( lba );
-_puts("\n - sectors = ");
-_putd( iter_sectors );
-_puts("\n");
+_printf("\n[FAT DEBUG] _fat_write() : P[%d,%d,%d] makes an IOC write"
+        " - cluster  = %x\n"
+        " - buffer   = %x\n"
+        " - lba      = %x\n"
+        " - sectors  = %x\n",
+        x, y, p, 
+        cluster,
+        (unsigned int) src,
+        lba,
+        iter_sectors );
 #endif
 
@@ -1693,7 +1570,5 @@
                         iter_sectors ) )   // number of sectors
         {
-            _puts("\n[FAT ERROR] in _fat_write() cannot write block ");
-            _putx( lba );
-            _puts("\n");
+            _printf("\n[FAT ERROR] in _fat_write() cannot write block %x\n", lba );
             return -1;
         }
@@ -1719,5 +1594,5 @@
     if ( update_entry(fd_id, DIR_FILE_SIZE, fat.fd[fd_id].file_size) )
     {
-            _puts("\n[FAT ERROR] in _fat_write() update entry failed\n");
+            _printf("\n[FAT ERROR] in _fat_write() update entry failed\n");
             return -1;
     }
@@ -1749,5 +1624,5 @@
     else
     {
-        _puts("\n[FAT ERROR] in _fat_fstat() : illegal file descriptor index\n");
+        _printf("\n[FAT ERROR] in _fat_fstat() : illegal file descriptor index\n");
         return -1;
     } 
@@ -1768,5 +1643,5 @@
     else
     {
-        _puts("\n[FAT ERROR] in _fat_close() : illegal file descriptor index\n");
+        _printf("\n[FAT ERROR] in _fat_close() : illegal file descriptor index\n");
         return -1;
     } 
@@ -1828,5 +1703,5 @@
                      unsigned int whence )
 {
-    _puts("[GIET ERROR] _fat_user_lseek() not implemented\n");
+    _printf("\n[GIET ERROR] _fat_user_lseek() not implemented\n");
     _exit();
     return 0;
