Index: trunk/kernel/syscalls/sys_stat.c
===================================================================
--- trunk/kernel/syscalls/sys_stat.c	(revision 566)
+++ trunk/kernel/syscalls/sys_stat.c	(revision 594)
@@ -39,11 +39,16 @@
 {
     error_t       error;
-    vseg_t      * vseg;         // for user space checking
-    struct stat   k_stat;       // kernel space 
-    xptr_t        file_xp;
+    vseg_t      * vseg;                   // for user space checking
+    struct stat   k_stat;                 // in kernel space 
+    xptr_t        inode_xp;               // extended pointer on target inode
+
     char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
 	
 	thread_t  * this    = CURRENT_THREAD;
 	process_t * process = this->process;
+
+#if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS)
+uint64_t     tm_start = hal_get_cycles();
+#endif
 
     // check stat structure in user space
@@ -54,6 +59,6 @@
 
 #if DEBUG_SYSCALLS_ERROR
-printk("\n[ERROR] in %s : stat structure unmapped %x / thread %x / process %x\n",
-__FUNCTION__ , (intptr_t)u_stat , this->trdid , process->pid );
+printk("\n[ERROR] in %s / thread[%x,%x] : stat structure unmapped\n",
+__FUNCTION__ , process->pid , this->trdid );
 vmm_display( process , false );
 #endif
@@ -65,5 +70,9 @@
     if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
     {
-        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
+
+#if DEBUG_SYSCALLS_ERROR
+printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long\n",
+ __FUNCTION__ , process->pid , this->trdid );
+#endif
         this->errno = ENFILE;
         return -1;
@@ -72,4 +81,10 @@
     // copy pathname in kernel space
     hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
+
+#if DEBUG_SYS_STAT
+if( DEBUG_SYS_STAT < tm_start )
+printk("\n[%s] thread[%x,%x] enter for file <%s> / cycle %d\n",
+__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start );
+#endif
 
     // get cluster and local pointer on reference process
@@ -86,7 +101,7 @@
     // get extended pointer on remote file descriptor
     error = vfs_lookup( cwd_xp,
-                        pathname,
+                        kbuf,
                         0,
-                        &file_xp );
+                        &inode_xp );
 
     // release the cwd lock
@@ -95,21 +110,39 @@
     if( error )
     {
-        printk("\n[ERROR] in %s : cannot found file <%s> for thread %x in process %x\n",
-               __FUNCTION__ , pathname , this->trdid , process->pid );
-        this->errno = error;
+
+#if DEBUG_SYSCALLS_ERROR
+printk("\n[ERROR] in %s / thread[%x,%x] : cannot found file <%s>\n",
+__FUNCTION__ , process->pid , this->trdid , pathname );
+#endif
+        this->errno = ENFILE;
         return -1;
     }
 
+#if (DEBUG_SYS_STAT & 1)
+if( DEBUG_SYS_STAT < tm_start )
+printk("\n[%s] thread[%x,%x] got inode %x in cluster %x for <%s>\n",
+__FUNCTION__, process->pid, this->trdid, GET_PTR(inode_xp), GET_CXY(inode_xp), kbuf );
+#endif
+
     // call VFS function to get stat info
-    error = vfs_stat( file_xp,
+    error = vfs_stat( inode_xp,
                       &k_stat );
     if( error )
 	{
-        printk("\n[ERROR] in %s : cannot get stats for file %s\n",
-               __FUNCTION__ , pathname );
-		this->errno = error;
+
+#if DEBUG_SYSCALLS_ERROR
+printk("\n[ERROR] in %s / thread[%x,%x] : cannot get stats for inode <%s>\n",
+__FUNCTION__ , process->pid , this->trdid , pathname );
+#endif
+		this->errno = ENFILE;
 		return -1;
 	}
    
+#if (DEBUG_SYS_STAT & 1)
+if( DEBUG_SYS_STAT < tm_start )
+printk("\n[%s] thread[%x,%x] set kstat : inum %d / size %d / mode %d\n",
+__FUNCTION__, process->pid, this->trdid, k_stat.st_ino, k_stat.st_size, k_stat.st_mode );
+#endif
+
     // copy k_stat to u_stat 
     hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) );
@@ -117,4 +150,19 @@
     hal_fence();
 
+#if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS)
+uint64_t     tm_end = hal_get_cycles();
+#endif
+
+#if DEBUG_SYS_STAT
+if( DEBUG_SYS_STAT < tm_end )
+printk("\n[%s] thread[%x,%x] exit for file <%s> / cycle %d\n",
+__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end );
+#endif
+ 
+#if CONFIG_INSTRUMENTATION_SYSCALLS
+hal_atomic_add( &syscalls_cumul_cost[SYS_STAT] , tm_end - tm_start );
+hal_atomic_add( &syscalls_occurences[SYS_STAT] , 1 );
+#endif
+
 	return 0;
 
