Index: /soft/giet_vm/giet_fat32/fat32.c
===================================================================
--- /soft/giet_vm/giet_fat32/fat32.c	(revision 357)
+++ /soft/giet_vm/giet_fat32/fat32.c	(revision 358)
@@ -790,5 +790,5 @@
 
 #if GIET_DEBUG_FAT
-_printf("\n[FAT DEBUG] enter _scan_directory() searching dir/file %s", file_name );
+_printf("\n[FAT DEBUG] enter _scan_directory() for dir/file %s\n", file_name );
 #endif
 
@@ -822,4 +822,8 @@
 
     fat.cache_lba = lba;
+
+#if ( GIET_DEBUG_FAT > 1 )
+display_fat_cache();
+#endif
 
     // in this loop we scan all names in directory identified by cluster: 
@@ -1071,8 +1075,9 @@
     fat.last_cluster_allocated = read_entry( FS_FREE_CLUSTER_HINT, fat.fat_cache, 1);
 
-#if GIET_DEBUG_FAT
-_printf("\n[FAT DEBUG] Processor[%d,%d,%d] exit _fat_init() / "
-        "free clusters = %x / last allocated cluster = %x\n",
-        x, y, lpid, fat.number_free_cluster, fat.last_cluster_allocated );
+
+#if GIET_DEBUG_FAT
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] initialises FAT descriptor\n", x, y, lpid );
+_fat_print();
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] exit _fat_init()\n", x, y, lpid );
 #endif
 
@@ -1083,12 +1088,14 @@
 void _fat_print()
 {
-    _printf("\n########################## FAT32 ###########################");  
-    _printf("\nFAT initialised                %x", fat.initialised );
-    _printf("\nSector Size  (bytes)           %x", fat.sector_size );
-    _printf("\nSectors per cluster            %x", fat.sectors_per_cluster );
-    _printf("\nFAT region first lba           %x", fat.fat_lba );
-    _printf("\nData region first lba          %x", fat.data_lba );
-    _printf("\nNumber of sectors for one FAT  %x", fat.fat_sectors );
-    _printf("\n############################################################\n");
+    _printf("\n########################## FAT32 ################################");  
+    _printf("\nFAT initialised                  %x", fat.initialised );
+    _printf("\nSector Size  (bytes)             %x", fat.sector_size );
+    _printf("\nSectors per cluster              %x", fat.sectors_per_cluster );
+    _printf("\nFAT region first lba             %x", fat.fat_lba );
+    _printf("\nData region first lba            %x", fat.data_lba );
+    _printf("\nNumber of sectors for one FAT    %x", fat.fat_sectors );
+    _printf("\nNumber of free clusters          %x", fat.number_free_cluster );
+    _printf("\nLast last allocated cluster      %x", fat.last_cluster_allocated );
+    _printf("\n#################################################################\n");
 }
 
@@ -1150,17 +1157,7 @@
         {
             _printf("[FAT ERROR] in _fat_open() : Cannot initialize FAT descriptor\n");
-
-            // release FAT lock
             _release_lock( &fat.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();
-#endif
-
     }
  
@@ -1283,9 +1280,4 @@
     unsigned int sectors_to_skip;   // number of sectors to skip in first iteration
 
-    // compute file size as a number of sectors 
-    file_size    = fat.fd[fd_id].file_size;
-    if ( file_size & 0x1FF ) file_sectors = (file_size >> 9) + 1;
-    else                     file_sectors = (file_size >> 9); 
-
     // arguments checking
     if ( fd_id >= GIET_OPEN_FILES_MAX )
@@ -1304,4 +1296,10 @@
         return -1;
     }
+
+    // compute file size as a number of sectors 
+    file_size    = fat.fd[fd_id].file_size;
+    if ( file_size & 0x1FF ) file_sectors = (file_size >> 9) + 1;
+    else                     file_sectors = (file_size >> 9); 
+
     if ( offset >= file_sectors )
     {
@@ -1359,12 +1357,12 @@
     else                                          iter_sectors = spc - sectors_to_skip; 
 
-    // loop on the clusters
+    // loop on the clusters: one IOC access per cluster
     while ( todo_sectors > 0 )
     {
 
 #if GIET_DEBUG_FAT
-_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 );
+_printf("\n[FAT DEBUG] Processor[%d,%d,%d] makes an IOC read "
+        " for cluster %x : buf = %x / lba = %x / sectors = %d\n",
+        x, y, lpid, cluster, (unsigned int)dst, lba, iter_sectors );
 #endif
 
