Index: trunk/kernel/syscalls/sys_read.c
===================================================================
--- trunk/kernel/syscalls/sys_read.c	(revision 594)
+++ trunk/kernel/syscalls/sys_read.c	(revision 604)
@@ -56,13 +56,19 @@
               uint32_t   count )
 {
-    error_t      error;
-    vseg_t     * vseg;        // required for user space checking
-	xptr_t       file_xp;     // remote file extended pointer
-    uint32_t     nbytes;      // number of bytes actually read
-    reg_t        save_sr;     // required to enable IRQs during syscall
-
-	thread_t  *  this             = CURRENT_THREAD;
-	process_t *  process          = this->process;
-    xptr_t       process_owner_xp = process->owner_xp;
+    error_t       error;
+    vseg_t      * vseg;            // required for user space checking
+	xptr_t        file_xp;         // remote file extended pointer
+    vfs_file_t  * file_ptr;        // remote file local pointer
+    cxy_t         file_cxy;        // remote file cluster identifier
+    uint32_t      file_type;       // file type
+    uint32_t      file_offset;     // current file offset
+    uint32_t      file_attr;       // file_attribute
+    vfs_inode_t * inode_ptr;       // local pointer on associated inode
+    uint32_t      nbytes;          // number of bytes actually read
+    reg_t         save_sr;         // required to enable IRQs during syscall
+
+	thread_t    * this             = CURRENT_THREAD;
+	process_t   * process          = this->process;
+    xptr_t        process_owner_xp = process->owner_xp;
  
 #if (DEBUG_SYS_READ || CONFIG_INSTRUMENTATION_SYSCALLS)
@@ -85,5 +91,5 @@
 
 #if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index = %d\n",
+printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n",
 __FUNCTION__ , process->pid, this->trdid, file_id );
 #endif
@@ -107,35 +113,36 @@
     }
 
+    // get extended pointer on remote file descriptor
+    file_xp = process_fd_get_xptr( process , file_id );
+
+    if( file_xp == XPTR_NULL )
+    {
+
+#if DEBUG_SYSCALLS_ERROR
+printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",
+__FUNCTION__, process->pid, this->trdid, file_id );
+#endif
+        this->errno = EBADFD;
+        return -1;
+    }
+
+    // get file descriptor cluster and local pointer
+    file_ptr = GET_PTR( file_xp );
+    file_cxy = GET_CXY( file_xp );
+
+    // get file type, offset, attributes and associated inode
+    file_type   = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
+    file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
+    inode_ptr   = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
+    file_attr   = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) );
+
     // enable IRQs
     hal_enable_irq( &save_sr );
 
-    // get extended pointer on remote file descriptor
-    file_xp = process_fd_get_xptr( process , file_id );
-
-    if( file_xp == XPTR_NULL )
-    {
-
-#if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",
-__FUNCTION__, process->pid, this->trdid, file_id );
-#endif
-        this->errno = EBADFD;
-        return -1;
-    }
-
-    // get file descriptor cluster and local pointer
-    vfs_file_t * file_ptr = GET_PTR( file_xp );
-    cxy_t        file_cxy = GET_CXY( file_xp );
-
-    // get file type
-    vfs_inode_type_t type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
-
     // action depend on file type
-    if( type == INODE_TYPE_FILE )      // check file readable & read from mapper 
+    if( file_type == INODE_TYPE_FILE )      // read from file mapper 
     {
         // check file readable
-        uint32_t attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) );
-
-        if( (attr & FD_ATTR_READ_ENABLE) == 0 )
+        if( (file_attr & FD_ATTR_READ_ENABLE) == 0 )
 	    {
 
@@ -144,4 +151,5 @@
 __FUNCTION__, process->pid, this->trdid, file_id );
 #endif
+            hal_restore_irq( save_sr );
 		    this->errno = EBADFD;
 		    return -1;
@@ -153,6 +161,17 @@
                                 vaddr, 
                                 count );
-    }
-    else if( type == INODE_TYPE_DEV )  // check ownership & read from device
+        if( nbytes != count )
+        {
+
+#if DEBUG_SYSCALLS_ERROR
+printk("\n[ERROR] in %s : thread[%x,‰x] cannot read %d bytes from file %d\n",
+__FUNCTION__, process->pid, this->trdid, count, file_id );
+#endif
+            this->errno = EIO;
+            hal_restore_irq( save_sr );
+            return -1;
+        }
+    }
+    else if( file_type == INODE_TYPE_DEV )  // read from TXT device
     {
         // get cluster and pointers on TXT_RX chdev 
@@ -192,19 +211,6 @@
                                   vaddr,
                                   count );
-
-    }
-    else    // not FILE and not DEV
-    {
-
-#if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
-__FUNCTION__, vfs_inode_type_str( type ) );
-#endif
-		this->errno = EBADFD;
-		return -1;
-    }
-
-    if( nbytes != count )
-    {
+        if( nbytes != count )
+        {
 
 #if DEBUG_SYSCALLS_ERROR
@@ -212,6 +218,19 @@
 __FUNCTION__, process->pid, this->trdid, file_id );
 #endif
-        this->errno = EIO;
-        return -1;
+            this->errno = EIO;
+            hal_restore_irq( save_sr );
+            return -1;
+        }
+    }
+    else    // not FILE and not DEV
+    {
+
+#if DEBUG_SYSCALLS_ERROR
+printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
+__FUNCTION__, vfs_inode_type_str( file_type ) );
+#endif
+		this->errno = EBADFD;
+        hal_restore_irq( save_sr );
+		return -1;
     }
 
