Changeset 604 for trunk/kernel/syscalls/sys_read.c
- Timestamp:
- Dec 3, 2018, 12:18:40 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_read.c
r594 r604 56 56 uint32_t count ) 57 57 { 58 error_t error; 59 vseg_t * vseg; // required for user space checking 60 xptr_t file_xp; // remote file extended pointer 61 uint32_t nbytes; // number of bytes actually read 62 reg_t save_sr; // required to enable IRQs during syscall 63 64 thread_t * this = CURRENT_THREAD; 65 process_t * process = this->process; 66 xptr_t process_owner_xp = process->owner_xp; 58 error_t error; 59 vseg_t * vseg; // required for user space checking 60 xptr_t file_xp; // remote file extended pointer 61 vfs_file_t * file_ptr; // remote file local pointer 62 cxy_t file_cxy; // remote file cluster identifier 63 uint32_t file_type; // file type 64 uint32_t file_offset; // current file offset 65 uint32_t file_attr; // file_attribute 66 vfs_inode_t * inode_ptr; // local pointer on associated inode 67 uint32_t nbytes; // number of bytes actually read 68 reg_t save_sr; // required to enable IRQs during syscall 69 70 thread_t * this = CURRENT_THREAD; 71 process_t * process = this->process; 72 xptr_t process_owner_xp = process->owner_xp; 67 73 68 74 #if (DEBUG_SYS_READ || CONFIG_INSTRUMENTATION_SYSCALLS) … … 85 91 86 92 #if DEBUG_SYSCALLS_ERROR 87 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index =%d\n",93 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n", 88 94 __FUNCTION__ , process->pid, this->trdid, file_id ); 89 95 #endif … … 107 113 } 108 114 115 // get extended pointer on remote file descriptor 116 file_xp = process_fd_get_xptr( process , file_id ); 117 118 if( file_xp == XPTR_NULL ) 119 { 120 121 #if DEBUG_SYSCALLS_ERROR 122 printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n", 123 __FUNCTION__, process->pid, this->trdid, file_id ); 124 #endif 125 this->errno = EBADFD; 126 return -1; 127 } 128 129 // get file descriptor cluster and local pointer 130 file_ptr = GET_PTR( file_xp ); 131 file_cxy = GET_CXY( file_xp ); 132 133 // get file type, offset, attributes and associated inode 134 file_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 135 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 136 inode_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 137 file_attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 138 109 139 // enable IRQs 110 140 hal_enable_irq( &save_sr ); 111 141 112 // get extended pointer on remote file descriptor113 file_xp = process_fd_get_xptr( process , file_id );114 115 if( file_xp == XPTR_NULL )116 {117 118 #if DEBUG_SYSCALLS_ERROR119 printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",120 __FUNCTION__, process->pid, this->trdid, file_id );121 #endif122 this->errno = EBADFD;123 return -1;124 }125 126 // get file descriptor cluster and local pointer127 vfs_file_t * file_ptr = GET_PTR( file_xp );128 cxy_t file_cxy = GET_CXY( file_xp );129 130 // get file type131 vfs_inode_type_t type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );132 133 142 // action depend on file type 134 if( type == INODE_TYPE_FILE ) // check file readable & read frommapper143 if( file_type == INODE_TYPE_FILE ) // read from file mapper 135 144 { 136 145 // check file readable 137 uint32_t attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 138 139 if( (attr & FD_ATTR_READ_ENABLE) == 0 ) 146 if( (file_attr & FD_ATTR_READ_ENABLE) == 0 ) 140 147 { 141 148 … … 144 151 __FUNCTION__, process->pid, this->trdid, file_id ); 145 152 #endif 153 hal_restore_irq( save_sr ); 146 154 this->errno = EBADFD; 147 155 return -1; … … 153 161 vaddr, 154 162 count ); 155 } 156 else if( type == INODE_TYPE_DEV ) // check ownership & read from device 163 if( nbytes != count ) 164 { 165 166 #if DEBUG_SYSCALLS_ERROR 167 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read %d bytes from file %d\n", 168 __FUNCTION__, process->pid, this->trdid, count, file_id ); 169 #endif 170 this->errno = EIO; 171 hal_restore_irq( save_sr ); 172 return -1; 173 } 174 } 175 else if( file_type == INODE_TYPE_DEV ) // read from TXT device 157 176 { 158 177 // get cluster and pointers on TXT_RX chdev … … 192 211 vaddr, 193 212 count ); 194 195 } 196 else // not FILE and not DEV 197 { 198 199 #if DEBUG_SYSCALLS_ERROR 200 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 201 __FUNCTION__, vfs_inode_type_str( type ) ); 202 #endif 203 this->errno = EBADFD; 204 return -1; 205 } 206 207 if( nbytes != count ) 208 { 213 if( nbytes != count ) 214 { 209 215 210 216 #if DEBUG_SYSCALLS_ERROR … … 212 218 __FUNCTION__, process->pid, this->trdid, file_id ); 213 219 #endif 214 this->errno = EIO; 215 return -1; 220 this->errno = EIO; 221 hal_restore_irq( save_sr ); 222 return -1; 223 } 224 } 225 else // not FILE and not DEV 226 { 227 228 #if DEBUG_SYSCALLS_ERROR 229 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 230 __FUNCTION__, vfs_inode_type_str( file_type ) ); 231 #endif 232 this->errno = EBADFD; 233 hal_restore_irq( save_sr ); 234 return -1; 216 235 } 217 236
Note: See TracChangeset
for help on using the changeset viewer.