Index: soft/giet_vm/applications/shell/main.c
===================================================================
--- soft/giet_vm/applications/shell/main.c	(revision 653)
+++ soft/giet_vm/applications/shell/main.c	(revision 654)
@@ -104,5 +104,5 @@
     size = info.size;
 
-    dst_fd = giet_fat_open( argv[2] , O_CREATE ); // TODO O_TRUNC
+    dst_fd = giet_fat_open( argv[2] , O_CREATE | O_TRUNC );
     if (dst_fd < 0)
     {
Index: soft/giet_vm/giet_fat32/fat32.c
===================================================================
--- soft/giet_vm/giet_fat32/fat32.c	(revision 653)
+++ soft/giet_vm/giet_fat32/fat32.c	(revision 654)
@@ -2800,4 +2800,5 @@
 //   -8  :  "Cannot update FS_INFO sector"
 //   -9  :  "file descriptor array full"
+//   -10 :  "cannot truncate file"
 ///////////////////////////////////////////////////////////////////////////////
 int _fat_open( char*        pathname,     // absolute path from root
@@ -2812,5 +2813,6 @@
     // get flags
     unsigned int create    = ((flags & O_CREATE) != 0);
-    unsigned int read_only = ((flags & O_RDONLY) != 0); 
+    unsigned int read_only = ((flags & O_RDONLY) != 0);
+    unsigned int truncate  = ((flags & O_TRUNC)  != 0);
 
 #if GIET_DEBUG_FAT
@@ -2925,4 +2927,7 @@
             return -8;
         }
+
+        // no need to truncate a new file
+        truncate = 0;
     }
     else // code == 0
@@ -2936,5 +2941,4 @@
         x , y , p , pathname , child );
 #endif
-
     }
 
@@ -2947,17 +2951,49 @@
 
     // set file descriptor if an empty slot has been found
-    if ( fd_id < GIET_OPEN_FILES_MAX )
-    {
-        // 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;
-
-        // increment the refcount
-        child->count = child->count + 1;
-
-        // releases the lock
+    if ( fd_id >= GIET_OPEN_FILES_MAX )
+    {
         _spin_lock_release( &_fat.fat_lock );
+        _printf("\n[FAT ERROR] in _fat_open() : File-Descriptors-Array full\n");
+        return -9;
+    }
+
+    // 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;
+
+    // increment the refcount
+    child->count = child->count + 1;
+
+    // truncate the file if requested
+    if ( truncate && !read_only && !child->is_dir )
+    {
+        // 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 ( _clusters_release( child->cluster ) )
+        {
+            _spin_lock_release( &_fat.fat_lock );
+            _printf("\n[FAT ERROR] in _fat_open() : can't truncate file\n");
+            return -10;
+        }
+
+        // update parent directory entry (size and cluster index)
+        if ( _update_dir_entry( child ) )
+        {
+            _spin_lock_release( &_fat.fat_lock );
+            _printf("\n[FAT ERROR] in _fat_open() : can't truncate file\n");
+            return -10;
+        }
+    }
+
+    // releases the lock
+    _spin_lock_release( &_fat.fat_lock );
 
 #if GIET_DEBUG_FAT
@@ -2967,12 +3003,5 @@
         x , y , p , fd_id , pathname , read_only );
 #endif
-        return fd_id;
-    }
-    else
-    {
-        _spin_lock_release( &_fat.fat_lock );
-        _printf("\n[FAT ERROR] in _fat_open() : File-Descriptors-Array full\n");
-        return -9;
-    }
+    return fd_id;
 } // end _fat_open()
 
@@ -3394,5 +3423,5 @@
         }
          
-        // update parent directory entry (size an cluster index)
+        // update parent directory entry (size and cluster index)
         if ( _update_dir_entry( inode ) )
         {
Index: soft/giet_vm/giet_fat32/fat32.h
===================================================================
--- soft/giet_vm/giet_fat32/fat32.h	(revision 653)
+++ soft/giet_vm/giet_fat32/fat32.h	(revision 654)
@@ -139,4 +139,5 @@
 
 #define O_RDONLY                0x01
+#define O_TRUNC                 0x10
 #define O_CREATE                0x20
 #endif // _FAT32_SHARED
Index: soft/giet_vm/giet_libs/stdio.h
===================================================================
--- soft/giet_vm/giet_libs/stdio.h	(revision 653)
+++ soft/giet_vm/giet_libs/stdio.h	(revision 654)
@@ -100,6 +100,7 @@
 #define SEEK_CUR            1          // argument for giet_fat_lseek
 
+#define O_RDONLY            0x01       // argument for giet_fat_open()
+#define O_TRUNC             0x10       // argument for giet_fat_open()
 #define O_CREATE            0x20       // argument for giet_fat_open()
-#define O_RDONLY            0x01       // argument for giet_fat_open()
 #endif // _FAT32_SHARED
 
