Index: trunk/kernel/syscalls/sys_read.c
===================================================================
--- trunk/kernel/syscalls/sys_read.c	(revision 664)
+++ trunk/kernel/syscalls/sys_read.c	(revision 670)
@@ -2,5 +2,5 @@
  * sys_read.c - Kernel function implementing the "read" system call.
  * 
- * Author     Alain Greiner (2016,2017,2018,2019)
+ * Author     Alain Greiner (2016,2017,2018,2019,2020)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -33,4 +33,5 @@
 #include <thread.h>
 #include <printk.h>
+#include <pipe.h>
 #include <process.h>
 
@@ -73,5 +74,5 @@
     xptr_t        process_owner_xp = process->owner_xp;
  
-#if (DEBUG_SYS_READ || CONFIG_INSTRUMENTATION_SYSCALLS)
+#if DEBUG_SYS_READ || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS
 uint64_t     tm_start = hal_get_cycles();
 #endif
@@ -92,5 +93,6 @@
 
 #if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n",
+if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
+printk("\n[ERROR] in %s : thread[%x,%x] / illegal file descriptor index %d\n",
 __FUNCTION__ , process->pid, this->trdid, file_id );
 #endif
@@ -106,5 +108,6 @@
 
 #if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : thread[%x,%x] user buffer unmapped %x\n",
+if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
+printk("\n[ERROR] in %s : thread[%x,%x] / user buffer unmapped %x\n",
 __FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr );
 #endif
@@ -120,5 +123,6 @@
 
 #if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",
+if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
+printk("\n[ERROR] in %s : thread[%x,%x] / undefined fd_id %d\n",
 __FUNCTION__, process->pid, this->trdid, file_id );
 #endif
@@ -140,28 +144,28 @@
     hal_enable_irq( &save_sr );
 
+    // check file readable
+    if( (file_attr & FD_ATTR_READ_ENABLE) == 0 )
+    {
+
+#if DEBUG_SYSCALLS_ERROR
+if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
+printk("\n[ERROR] in %s : thread[%x,%x] / file %d not readable\n",
+__FUNCTION__, process->pid, this->trdid, file_id );
+#endif
+        hal_restore_irq( save_sr );
+        this->errno = EBADFD;
+        return -1;
+    }
+
     // action depend on file type:
-
-    if( file_type == INODE_TYPE_FILE )      // read from file mapper 
-    {
-        // check file readable
-        if( (file_attr & FD_ATTR_READ_ENABLE) == 0 )
-	    {
-
-#if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : thread[%x,%x] file %d not readable\n",
-__FUNCTION__, process->pid, this->trdid, file_id );
-#endif
-            hal_restore_irq( save_sr );
-		    this->errno = EBADFD;
-		    return -1;
-	    }
-
+    if( file_type == FILE_TYPE_REG )                           // read from mapper 
+    {
         // try to move count bytes from mapper
-        nbytes = vfs_user_move( true,               // from mapper to buffer
+        nbytes = vfs_user_move( true,   //  from mapper
                                 file_xp,
                                 vaddr, 
                                 count );
     }
-    else if( file_type == INODE_TYPE_DEV )  // read from TXT device
+    else if( file_type == FILE_TYPE_DEV )                      // read from TXT device
     {
         // get cluster and pointers on TXT_RX chdev 
@@ -176,6 +180,6 @@
         {
             // extended pointer on TXT owner process
-            txt_owner_xp  = hal_remote_l64( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );
-
+            txt_owner_xp  = hal_remote_l64( XPTR( chdev_cxy , 
+                                                  &chdev_ptr->ext.txt.owner_xp ) );
             // wait for TXT_RX ownership
             if ( process_owner_xp != txt_owner_xp )
@@ -197,14 +201,24 @@
 
         // try to move count bytes from TXT device
-        nbytes = devfs_user_move( true,             // from device to buffer
+        nbytes = devfs_user_move( true,    // from device 
                                   file_xp,
                                   vaddr,
                                   count );
     }
-    else    // not FILE and not DEV
-    {
-
-#if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
+    else if( (file_type == FILE_TYPE_PIPE) ||
+             (file_type == FILE_TYPE_FIFO) )                  // read from pipe 
+    {
+        // try to move count bytes from pipe
+        nbytes = pipe_user_move( true,    // from pipe 
+                                 file_xp,
+                                 vaddr,
+                                 count );
+    }   
+    else                                                      // unsupported type
+    {
+
+#if DEBUG_SYSCALLS_ERROR
+if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
+printk("\n[ERROR] in %s : thread[%x,%x] / unsupported inode type %d\n",
 __FUNCTION__, vfs_inode_type_str( file_type ) );
 #endif
@@ -219,4 +233,5 @@
 
 #if DEBUG_SYSCALLS_ERROR
+if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start )
 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read data from file %d\n",
 __FUNCTION__, process->pid, this->trdid, file_id );
