Changeset 594 for trunk/kernel/syscalls/sys_stat.c
- Timestamp:
- Nov 10, 2018, 2:33:26 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_stat.c
r566 r594 39 39 { 40 40 error_t error; 41 vseg_t * vseg; // for user space checking 42 struct stat k_stat; // kernel space 43 xptr_t file_xp; 41 vseg_t * vseg; // for user space checking 42 struct stat k_stat; // in kernel space 43 xptr_t inode_xp; // extended pointer on target inode 44 44 45 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 45 46 46 47 thread_t * this = CURRENT_THREAD; 47 48 process_t * process = this->process; 49 50 #if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS) 51 uint64_t tm_start = hal_get_cycles(); 52 #endif 48 53 49 54 // check stat structure in user space … … 54 59 55 60 #if DEBUG_SYSCALLS_ERROR 56 printk("\n[ERROR] in %s : stat structure unmapped %x / thread %x / process %x\n",57 __FUNCTION__ , (intptr_t)u_stat , this->trdid , process->pid );61 printk("\n[ERROR] in %s / thread[%x,%x] : stat structure unmapped\n", 62 __FUNCTION__ , process->pid , this->trdid ); 58 63 vmm_display( process , false ); 59 64 #endif … … 65 70 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 66 71 { 67 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 72 73 #if DEBUG_SYSCALLS_ERROR 74 printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long\n", 75 __FUNCTION__ , process->pid , this->trdid ); 76 #endif 68 77 this->errno = ENFILE; 69 78 return -1; … … 72 81 // copy pathname in kernel space 73 82 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 83 84 #if DEBUG_SYS_STAT 85 if( DEBUG_SYS_STAT < tm_start ) 86 printk("\n[%s] thread[%x,%x] enter for file <%s> / cycle %d\n", 87 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start ); 88 #endif 74 89 75 90 // get cluster and local pointer on reference process … … 86 101 // get extended pointer on remote file descriptor 87 102 error = vfs_lookup( cwd_xp, 88 pathname,103 kbuf, 89 104 0, 90 & file_xp );105 &inode_xp ); 91 106 92 107 // release the cwd lock … … 95 110 if( error ) 96 111 { 97 printk("\n[ERROR] in %s : cannot found file <%s> for thread %x in process %x\n", 98 __FUNCTION__ , pathname , this->trdid , process->pid ); 99 this->errno = error; 112 113 #if DEBUG_SYSCALLS_ERROR 114 printk("\n[ERROR] in %s / thread[%x,%x] : cannot found file <%s>\n", 115 __FUNCTION__ , process->pid , this->trdid , pathname ); 116 #endif 117 this->errno = ENFILE; 100 118 return -1; 101 119 } 102 120 121 #if (DEBUG_SYS_STAT & 1) 122 if( DEBUG_SYS_STAT < tm_start ) 123 printk("\n[%s] thread[%x,%x] got inode %x in cluster %x for <%s>\n", 124 __FUNCTION__, process->pid, this->trdid, GET_PTR(inode_xp), GET_CXY(inode_xp), kbuf ); 125 #endif 126 103 127 // call VFS function to get stat info 104 error = vfs_stat( file_xp,128 error = vfs_stat( inode_xp, 105 129 &k_stat ); 106 130 if( error ) 107 131 { 108 printk("\n[ERROR] in %s : cannot get stats for file %s\n", 109 __FUNCTION__ , pathname ); 110 this->errno = error; 132 133 #if DEBUG_SYSCALLS_ERROR 134 printk("\n[ERROR] in %s / thread[%x,%x] : cannot get stats for inode <%s>\n", 135 __FUNCTION__ , process->pid , this->trdid , pathname ); 136 #endif 137 this->errno = ENFILE; 111 138 return -1; 112 139 } 113 140 141 #if (DEBUG_SYS_STAT & 1) 142 if( DEBUG_SYS_STAT < tm_start ) 143 printk("\n[%s] thread[%x,%x] set kstat : inum %d / size %d / mode %d\n", 144 __FUNCTION__, process->pid, this->trdid, k_stat.st_ino, k_stat.st_size, k_stat.st_mode ); 145 #endif 146 114 147 // copy k_stat to u_stat 115 148 hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) ); … … 117 150 hal_fence(); 118 151 152 #if (DEBUG_SYS_STAT || CONFIG_INSTRUMENTATION_SYSCALLS) 153 uint64_t tm_end = hal_get_cycles(); 154 #endif 155 156 #if DEBUG_SYS_STAT 157 if( DEBUG_SYS_STAT < tm_end ) 158 printk("\n[%s] thread[%x,%x] exit for file <%s> / cycle %d\n", 159 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end ); 160 #endif 161 162 #if CONFIG_INSTRUMENTATION_SYSCALLS 163 hal_atomic_add( &syscalls_cumul_cost[SYS_STAT] , tm_end - tm_start ); 164 hal_atomic_add( &syscalls_occurences[SYS_STAT] , 1 ); 165 #endif 166 119 167 return 0; 120 168
Note: See TracChangeset
for help on using the changeset viewer.