Changeset 610 for trunk/kernel/syscalls/sys_stat.c
- Timestamp:
- Dec 27, 2018, 7:38:58 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_stat.c
r604 r610 1 1 /* 2 * sys_stat.c - Return statistics on a file or directory.2 * sys_stat.c - kernel function implementing the "stat" syscall. 3 3 * 4 4 * Author Alain Greiner (2016,2017,2018) … … 41 41 vseg_t * vseg; // for user space checking 42 42 struct stat k_stat; // in kernel space 43 xptr_t inode_xp; // extended pointer on target inode43 xptr_t root_inode_xp; // extended pointer on path root inode 44 44 45 45 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; … … 59 59 60 60 #if DEBUG_SYSCALLS_ERROR 61 printk("\n[ERROR] in %s / thread[%x,%x] : stat structure unmapped\n",62 __FUNCTION__ , process->pid , this->trdid );61 printk("\n[ERROR] in %s / thread[%x,%x] : stat structure %x unmapped\n", 62 __FUNCTION__ , process->pid , this->trdid, u_stat ); 63 63 vmm_display( process , false ); 64 64 #endif … … 88 88 #endif 89 89 90 // get cluster and local pointer on reference process 91 xptr_t ref_xp = process->ref_xp; 92 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 93 cxy_t ref_cxy = GET_CXY( ref_xp ); 90 // compute root inode for path 91 if( kbuf[0] == '/' ) // absolute path 92 { 93 // use extended pointer on VFS root inode 94 root_inode_xp = process->vfs_root_xp; 95 } 96 else // relative path 97 { 98 // get cluster and local pointer on reference process 99 xptr_t ref_xp = process->ref_xp; 100 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 101 cxy_t ref_cxy = GET_CXY( ref_xp ); 94 102 95 // get extended pointer on cwd inode 96 xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); 97 98 // get the cwd lock in read mode from reference process 99 remote_rwlock_rd_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 100 101 // get extended pointer on remote file descriptor 102 error = vfs_lookup( cwd_xp, 103 kbuf, 104 0, 105 &inode_xp ); 106 107 // release the cwd lock 108 remote_rwlock_rd_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 109 110 if( error ) 111 { 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; 118 return -1; 103 // use extended pointer on CWD inode 104 root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 119 105 } 120 106 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 127 // call VFS function to get stat info 128 error = vfs_stat( inode_xp, 129 &k_stat ); 107 // call the relevant VFS function 108 error = vfs_stat( root_inode_xp, 109 kbuf, 110 &k_stat ); 130 111 if( error ) 131 112 { … … 139 120 } 140 121 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 #endif146 147 122 // copy k_stat to u_stat 148 123 hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) );
Note: See TracChangeset
for help on using the changeset viewer.