Index: /soft/giet_vm/giet_fat32/fat32.c
===================================================================
--- /soft/giet_vm/giet_fat32/fat32.c	(revision 806)
+++ /soft/giet_vm/giet_fat32/fat32.c	(revision 807)
@@ -576,6 +576,5 @@
     fat_cache_desc_t*  pdesc;
     unsigned int*      buffer;
-    if ( _get_fat_cache_buffer( cluster_id,
-                                &pdesc ) ) return 1;
+    if ( _get_fat_cache_buffer( cluster_id, &pdesc ) ) return 1;
 
     // get value from FAT slot
@@ -600,6 +599,5 @@
     fat_cache_desc_t*  pdesc;
     unsigned int*      buffer; 
-    if ( _get_fat_cache_buffer( cluster_id,
-                                &pdesc ) )  return 1;           
+    if ( _get_fat_cache_buffer( cluster_id, &pdesc ) ) return 1;           
 
     // set value into FAT slot
@@ -792,8 +790,4 @@
             if ( pdesc != NULL )
             { 
-                // check dirty
-                if ( pdesc->dirty )
-                    _printf("\n[FAT ERROR] _release_cache_memory(): dirty cluster\n");
-
                 _free( pdesc->buffer );
                 _free( pdesc );
@@ -848,9 +842,5 @@
     {
         // get next cluster
-        if ( _get_fat_entry( current , &next ) )
-        {
-            _printf("\n[FAT ERROR] in _one_cluster_allocate() scanning FAT\n");
-            return 1;
-        }
+        if ( _get_fat_entry( current , &next ) ) return 1;
         
         // increment number of allocated clusters
@@ -875,9 +865,5 @@
 
     // update allocated FAT slot
-    if ( _set_fat_entry( new , END_OF_CHAIN_CLUSTER_MAX ) ) 
-    {
-        _printf("\n[FAT ERROR] in _one_cluster_allocate() accessing FAT\n");
-        return 1;
-    }
+    if ( _set_fat_entry( new , END_OF_CHAIN_CLUSTER_MAX ) ) return 1;
 
     // update FAT descriptor global variables
@@ -892,9 +878,5 @@
     else                             // not the last : update previous last cluster in FAT
     {
-        if ( _set_fat_entry( last , new ) ) 
-        {
-            _printf("\n[FAT ERROR] in _one_cluster_allocate() accessing FAT\n");
-            return 1;
-        }
+        if ( _set_fat_entry( last , new ) ) return 1;
     }
 
@@ -936,26 +918,18 @@
         // get next cluster
         unsigned int next;
-        if ( _get_fat_entry( cluster , &next ) ) 
-        {
-            _printf("\n[FAT ERROR] in _cluster_release() scanning Fat-Cache"
-                    " for cluster %x\n", cluster );
-            return 1;
-        }
+        if ( _get_fat_entry( cluster , &next ) ) return 1;
 
         // call _cluster_release() on next cluster
         if ( _cluster_release( next ) ) return 1;
+
+        // release cluster
+        if ( _set_fat_entry( cluster , FREE_CLUSTER ) ) return 1;
+
+        // Update free_cluster _hint and free_clusters_number in FAT descriptor
+        _fat.free_clusters_number++;
+        if ( cluster < _fat.free_cluster_hint ) _fat.free_cluster_hint = cluster;
     }       
 
-    // In both cases (terminal or not) release cluster
-    if ( _set_fat_entry( cluster , FREE_CLUSTER ) )
-    {
-        _printf("\n[FAT ERROR] in _cluster_release() updating Fat-Cache"
-                " for cluster %x\n", cluster );
-        return 1;
-    }
-
-    // Update free_cluster _hint and free_clusters_number in FAT descriptor
-    _fat.free_clusters_number++;
-    if ( cluster < _fat.free_cluster_hint ) _fat.free_cluster_hint = cluster;
+    // do nothing if terminal case : cluster == END_OF_CHAIN
 
     return 0;
@@ -2425,6 +2399,6 @@
 
 ////////////////////////////////////////////////////////////////////
-int _fat_open( char*        pathname,     // absolute path from root
-               unsigned int flags )       // O_CREAT and O_RDONLY
+int _fat_open( char*        pathname,      // absolute path from root
+               unsigned int flags )        // O_CREAT / O_RDONLY / O_TRUNC
 {
     unsigned int         fd_id;            // index in File-Descriptor-Array
@@ -2438,4 +2412,5 @@
     unsigned int read_only = ((flags & O_RDONLY) != 0);
     unsigned int truncate  = ((flags & O_TRUNC)  != 0);
+    unsigned int append    = ((flags & O_APPEND) != 0);
 
 #if GIET_DEBUG_FAT
@@ -2604,5 +2579,5 @@
     }
 
-    // set file descriptor if an empty slot has been found
+    // check if an empty slot has been found
     if ( fd_id >= GIET_OPEN_FILES_MAX )
     {
@@ -2614,43 +2589,43 @@
     }
 
+    // truncate the file if requested
+    if ( truncate && !read_only && !child->is_dir && child->size != 0 )
+    {
+        // release File-Cache (keep root node)
+        _release_cache_memory( child->cache, child->levels );
+
+        // release clusters allocated to file/dir in DATA region
+        if ( _all_clusters_release( child ) )
+        {
+            _spin_lock_release( &_fat.fat_lock );
+            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 
+
+            _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n");
+            return GIET_FAT32_IO_ERROR;
+        }
+
+        // update parent directory entry (size and cluster index)
+        if ( _update_dir_entry( child ) )
+        {
+            _spin_lock_release( &_fat.fat_lock );
+            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 
+
+            _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n");
+            return GIET_FAT32_IO_ERROR;
+        }
+
+        // update inode
+        child->size   = 0;
+        child->levels = 1;
+    }
+
     // update file descriptor
     _fat.fd[fd_id].allocated  = 1;
-    _fat.fd[fd_id].seek       = 0;
     _fat.fd[fd_id].read_only  = read_only;
     _fat.fd[fd_id].inode      = child;
+    _fat.fd[fd_id].seek       = ( append ) ? child->size : 0;
 
     // increment the refcount
     child->count = child->count + 1;
-
-    // truncate the file if requested
-    if ( truncate && !read_only && !child->is_dir && child->size != 0 )
-    {
-        // empty file
-        child->size   = 0;
-        child->levels = _get_levels_from_size( child->size );
-
-        // release File-Cache (keep root node)
-        _release_cache_memory( child->cache, child->levels );
-
-        // release clusters allocated to file/dir in DATA region
-        if ( _all_clusters_release( child ) )
-        {
-            _spin_lock_release( &_fat.fat_lock );
-            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 
-
-            _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n");
-            return GIET_FAT32_IO_ERROR;
-        }
-
-        // update parent directory entry (size and cluster index)
-        if ( _update_dir_entry( child ) )
-        {
-            _spin_lock_release( &_fat.fat_lock );
-            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 
-
-            _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n");
-            return GIET_FAT32_IO_ERROR;
-        }
-    }
 
 #if GIET_DEBUG_FAT
@@ -4120,5 +4095,5 @@
     {
         _printf("\n[FAT ERROR] in _get_fat_cache_buffer() : "
-                "cluster_id %d too large", cluster_id );
+                "cluster_id %d too large\n", cluster_id );
         return GIET_FAT32_IO_ERROR;
     }
Index: /soft/giet_vm/giet_fat32/fat32_shared.h
===================================================================
--- /soft/giet_vm/giet_fat32/fat32_shared.h	(revision 806)
+++ /soft/giet_vm/giet_fat32/fat32_shared.h	(revision 807)
@@ -39,4 +39,5 @@
 #define O_TRUNC                 0x10
 #define O_CREAT                 0x20
+#define O_APPEND                0x40
 
 /********************************************************************************
