Changeset 407 for trunk/kernel/syscalls/sys_stat.c
- Timestamp:
- Nov 7, 2017, 3:08:12 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_stat.c
r124 r407 32 32 #include <process.h> 33 33 34 ///////////////////////////////////// /////35 int sys_stat( uint32_t file_id,36 struct vfs_stat_s *stat )34 ///////////////////////////////////// 35 int sys_stat( char * pathname, 36 struct stat * u_stat ) 37 37 { 38 error_t error; 39 paddr_t paddr; 40 struct vfs_stat_s k_stat; 41 xptr_t file_xp; 38 error_t error; 39 paddr_t paddr; 40 struct stat k_stat; // kernel space 41 xptr_t file_xp; 42 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 42 43 43 44 thread_t * this = CURRENT_THREAD; … … 45 46 46 47 // check stat structure in user space 47 error = vmm_v2p_translate( false , stat , &paddr );48 error = vmm_v2p_translate( false , u_stat , &paddr ); 48 49 49 50 if( error ) … … 55 56 } 56 57 57 // get extended pointer on remote file descriptor 58 file_xp = process_fd_get_xptr( process , file_id ); 59 60 if( file_xp == XPTR_NULL ) 58 // check pathname length 59 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 61 60 { 62 printk("\n[ERROR] in %s : undefined file descriptor for thread %x in process %x\n", 63 __FUNCTION__ , this->trdid , process->pid ); 64 this->errno = EBADFD; 61 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 62 this->errno = ENFILE; 65 63 return -1; 66 64 } 67 65 68 // call the relevant VFS function 66 // copy pathname in kernel space 67 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 68 69 // get cluster and local pointer on reference process 70 xptr_t ref_xp = process->ref_xp; 71 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 72 cxy_t ref_cxy = GET_CXY( ref_xp ); 73 74 // get extended pointer on cwd inode 75 xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); 76 77 // get the cwd lock in read mode from reference process 78 remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 79 80 // get extended pointer on remote file descriptor 81 error = vfs_lookup( cwd_xp, 82 pathname, 83 0, 84 &file_xp ); 85 86 // release the cwd lock 87 remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 88 89 if( error ) 90 { 91 printk("\n[ERROR] in %s : cannot found file <%s> for thread %x in process %x\n", 92 __FUNCTION__ , pathname , this->trdid , process->pid ); 93 this->errno = error; 94 return -1; 95 } 96 97 // call VFS function to get stat info 69 98 error = vfs_stat( file_xp, 70 99 &k_stat ); 71 100 if( error ) 72 101 { 73 printk("\n[ERROR] in %s : cannot access file %d for thread %x in process %x\n",74 __FUNCTION__ , file_id , this->trdid , process->pid);102 printk("\n[ERROR] in %s : cannot get stats for file %s\n", 103 __FUNCTION__ , pathname ); 75 104 this->errno = error; 76 105 return -1; 77 106 } 78 107 79 // copy stat to user space80 hal_copy_to_uspace( stat , &k_stat , sizeof(struct vfs_stat_s) );108 // copy k_stat to u_stat 109 hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) ); 81 110 82 111 hal_fence();
Note: See TracChangeset
for help on using the changeset viewer.