Index: soft/giet_vm/giet_fat32/fat32.c
===================================================================
--- soft/giet_vm/giet_fat32/fat32.c	(revision 345)
+++ soft/giet_vm/giet_fat32/fat32.c	(revision 354)
@@ -37,5 +37,4 @@
 // This function displays the content of the FAT cache
 //////////////////////////////////////////////////////////////////////////////////
-#if GIET_DEBUG_FAT
 void display_fat_cache()
 {
@@ -77,5 +76,4 @@
     _printf("**************************************************************************\n");
 } // end display_fat_cache()  
-#endif
 
 //////////////////////////////////////////////////////////////////////////////////
@@ -263,85 +261,59 @@
     char ch;
 
-#if GIET_DEBUG_FAT
-_printf("\n[FAT DEBUG] filename %s", string );
-#endif
-
     if(string[0] == '.' && string[1] == '\0')
     {
         sfn_string[0] = '.';
-
-#if GIET_DEBUG_FAT
-_printf(" converted to 8.3 SFN format : %s\n", sfn_string );
-#endif
-
-      return 1;
-   }
-
-   if(string[0] == '.' && string[1] == '.' && string[2] == '\0')
-   {
-      sfn_string[0] = '.';
-      sfn_string[1] = '.';
-
-#if GIET_DEBUG_FAT
-_printf(" converted to 8.3 SFN format : %s\n", sfn_string );
-#endif
-
-      return 1;
-   }
-
-   sfn_string[11] = '\0';
-
-   while (string[s_size] != '\0')
-   {
-      if (string[s_size] == '.')
-      {
-         dot_ext = s_size;
-         ext_len = -1;
-      }
-      ext_len++;
-      s_size++;
-   }
-
-   if (dot_ext != 0)
-   {
-      name_len = s_size - ext_len - 1;
-   }
-   else
-   {
-      name_len = s_size;
-      ext_len = 0;
-   }
-
-   if ( ext_len > 3 || ( name_len > 8))
-   {
-      return 0;
-   }
-
-   if (dot_ext != 0)
-   {
-      while (i != ext_len)
-      {
-         ch = to_upper(string[dot_ext + 1 + i]);
-         ch = illegal_short(ch);
-         sfn_string[8+i] = ch;
-         i++;
-      } 
-   }
-   i = 0;
-   sc_i = 0;
-   while (i!= name_len)
-   {
-      ch = to_upper(string[i]);
-      ch = illegal_short(ch);
-      if (ch != '.')
-         sfn_string[sc_i++] = ch;
-      i++;
-   }
-
-#if GIET_DEBUG_FAT
-_printf(" converted to 8.3 SFN format : %s\n", sfn_string );
-#endif
-
-   return 1;
+        return 1;
+    }
+    if(string[0] == '.' && string[1] == '.' && string[2] == '\0')
+    {
+        sfn_string[0] = '.';
+        sfn_string[1] = '.';
+        return 1;
+    }
+    sfn_string[11] = '\0';
+    while (string[s_size] != '\0')
+    {
+        if (string[s_size] == '.')
+        {
+            dot_ext = s_size;
+            ext_len = -1;
+        }
+        ext_len++;
+        s_size++;
+    }
+    if (dot_ext != 0)
+    {
+        name_len = s_size - ext_len - 1;
+    }
+    else
+    {
+        name_len = s_size;
+        ext_len = 0;
+    }
+    if ( ext_len > 3 || ( name_len > 8))
+    {
+        return 0;
+    }
+    if (dot_ext != 0)
+    {
+        while (i != ext_len)
+        {
+            ch = to_upper(string[dot_ext + 1 + i]);
+            ch = illegal_short(ch);
+            sfn_string[8+i] = ch;
+            i++;
+        } 
+    }
+    i = 0;
+    sc_i = 0;
+    while (i!= name_len)
+    {
+        ch = to_upper(string[i]);
+        ch = illegal_short(ch);
+        if (ch != '.') sfn_string[sc_i++] = ch;
+        i++;
+    }
+    return 1;
 }
 
@@ -850,8 +822,4 @@
 
     fat.cache_lba = lba;
-
-#if GIET_DEBUG_FAT
-display_fat_cache();
-#endif
 
     // in this loop we scan all names in directory identified by cluster: 
@@ -1045,5 +1013,4 @@
 #if GIET_DEBUG_FAT
 _printf("\n[FAT DEBUG] Boot Sector Loaded\n");
-display_fat_cache();
 #endif
 
@@ -1079,4 +1046,5 @@
     fat.fat_lba             = read_entry( BPB_RSVDSECCNT, fat.fat_cache, 1 );
     fat.data_lba            = fat.fat_lba + fat.fat_sectors;
+    fat.fat_lock.value      = 0;
     fat.initialised         = FAT_INITIALISED;
 
@@ -1106,5 +1074,5 @@
 _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 );
+        x, y, lpid, fat.number_free_cluster, fat.last_cluster_allocated );
 #endif
 
@@ -1126,6 +1094,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
-// This function checks that the kernel FAT structure has been initialised,
-// and makes the FAT initialisation if it is the first user open request. 
+// This function checks that the kernel FAT structure has been initialised.
+// It makes the FAT initialisation if it is the first open request. 
 // This function searches a file identified by the "pathname" argument.
 // It starts from root (cluster 2) to scan successively each subdirectory.
@@ -1133,5 +1101,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.
+// The same file can be open several times by differents tasks.
 ///////////////////////////////////////////////////////////////////////////////
 // Returns file descriptor index if success, returns -1 if error.
@@ -1141,12 +1109,12 @@
                unsigned int creat )
 {
-    char                 name[256];    // buffer for one name in pathname
-    unsigned int         nb_read;	   // number of characters written in name[] 
-    unsigned int         cluster;      // current cluster index when scanning FAT
-    unsigned int         dir_cluster;  // previous cluster index when scanning FAT
-    unsigned int         fd_id;        // index when scanning file descriptors array
-    unsigned int         file_size;    // number of bytes
-    unsigned int         last_name;    // directory containing file name is reached
-    unsigned int         lba;          // lba of dir_entry for this file
+    char                 name[256];        // buffer for one name in pathname
+    unsigned int         nb_read;	       // number of characters written in name[] 
+    unsigned int         cluster;          // current cluster index when scanning FAT
+    unsigned int         dir_cluster;      // previous cluster index when scanning FAT
+    unsigned int         fd_id;            // index when scanning file descriptors array
+    unsigned int         file_size = 0;    // number of bytes
+    unsigned int         last_name = 0;    // directory containing file name is reached
+    unsigned int         lba       = 0;    // lba of dir_entry for this file
     
 #if GIET_DEBUG_FAT
@@ -1169,5 +1137,5 @@
 
     // takes the FAT lock for exclusive access
-    _get_lock( &fat.lock );
+    _get_lock( &fat.fat_lock );
 
 #if GIET_DEBUG_FAT
@@ -1184,5 +1152,5 @@
 
             // release FAT lock
-            _release_lock( &fat.lock );
+            _release_lock( &fat.fat_lock );
 
             return -1;
@@ -1233,5 +1201,5 @@
 
             // release FAT lock
-            _release_lock( &fat.lock );
+            _release_lock( &fat.fat_lock );
 
             return -1;
@@ -1266,5 +1234,5 @@
 
             // release FAT lock
-            _release_lock( &fat.lock );
+            _release_lock( &fat.fat_lock );
 
             return fd_id;
@@ -1276,5 +1244,5 @@
 
             // release FAT lock
-            _release_lock( &fat.lock );
+            _release_lock( &fat.fat_lock );
 
             return -1;
@@ -1287,5 +1255,5 @@
 
         // release FAT lock
-        _release_lock( &fat.lock );
+        _release_lock( &fat.fat_lock );
 
         return -1;
@@ -1306,19 +1274,4 @@
                unsigned int offset )    // nuber of sectors to skip in file
 {
-
-#if GIET_DEBUG_FAT
-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
-
     unsigned int spc = fat.sectors_per_cluster;
 
@@ -1369,7 +1322,18 @@
 
 #if GIET_DEBUG_FAT
-_printf(" - first cluster   = %x\n"
+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"
+        " - first cluster   = %x\n"
         " - skiped clusters = %x\n",
-        cluster, clusters_to_skip );   
+        x, y, lpid, fat.fd[fd_id].name, 
+        (unsigned int)buffer, offset, count, cluster, clusters_to_skip );   
 #endif
 
