Changeset 656 for trunk/kernel/syscalls
- Timestamp:
- Dec 6, 2019, 12:07:51 PM (5 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_display.c
r640 r656 300 300 xptr_t mapper_xp; 301 301 mapper_t * mapper_ptr; 302 xptr_t page_xp; 302 303 303 304 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; … … 315 316 __FUNCTION__ ); 316 317 #endif 317 this->errno = ENFILE; 318 return -1; 319 } 320 318 this->errno = EINVAL; 319 return -1; 320 } 321 322 // check nbytes 323 if( nbytes >= 4096 ) 324 { 325 326 #if DEBUG_SYSCALLS_ERROR 327 printk("\n[ERROR] in %s for MAPPER : nbytes cannot be larger than 4096\n", 328 __FUNCTION__ ); 329 #endif 330 this->errno = EINVAL; 331 return -1; 332 } 333 321 334 // copy pathname in kernel space 322 335 hal_strcpy_from_uspace( XPTR( local_cxy , kbuf ), … … 366 379 mapper_xp = XPTR( inode_cxy , mapper_ptr ); 367 380 368 // display mapper369 error = mapper_display_page( mapper_xp , page_id , nbytes);370 371 if( error)381 // get extended pointer on target page 382 page_xp = mapper_remote_get_page( mapper_xp , page_id ); 383 384 if( page_xp == XPTR_NULL ) 372 385 { 373 386 374 387 #if DEBUG_SYSCALLS_ERROR 375 printk("\n[ERROR] in %s for MAPPER : cannot displaypage %d\n",388 printk("\n[ERROR] in %s for MAPPER : cannot get page %d\n", 376 389 __FUNCTION__ , page_id ); 377 390 #endif … … 379 392 return -1; 380 393 } 394 395 // display mapper 396 mapper_display_page( mapper_xp , page_xp , nbytes ); 397 381 398 382 399 break; … … 463 480 uint32_t page = (uint32_t)arg0; 464 481 465 fatfs_display_fat( page , entries );482 fatfs_display_fat( page , 0 , entries ); 466 483 } 467 484 -
trunk/kernel/syscalls/sys_read.c
r635 r656 63 63 cxy_t file_cxy; // remote file cluster identifier 64 64 uint32_t file_type; // file type 65 uint32_t file_attr; // file_attribute 65 uint32_t file_offset; // file offset 66 uint32_t file_attr; // file attributes 67 vfs_inode_t * inode_ptr; // local pointer on file inode 66 68 uint32_t nbytes; // number of bytes actually read 67 69 reg_t save_sr; // required to enable IRQs during syscall … … 129 131 file_cxy = GET_CXY( file_xp ); 130 132 131 // get file type and attributes 132 file_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 133 file_attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 133 // get inode, file type, offset and attributes 134 inode_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 135 file_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 136 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 137 file_attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 134 138 135 139 // enable IRQs 136 140 hal_enable_irq( &save_sr ); 137 141 138 // action depend on file type 142 // action depend on file type: 143 139 144 if( file_type == INODE_TYPE_FILE ) // read from file mapper 140 145 { … … 152 157 } 153 158 154 // move count bytes from mapper159 // try to move count bytes from mapper 155 160 nbytes = vfs_user_move( true, // from mapper to buffer 156 161 file_xp, 157 162 vaddr, 158 163 count ); 159 if( nbytes != count )160 {161 162 #if DEBUG_SYSCALLS_ERROR163 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read %d bytes from file %d\n",164 __FUNCTION__, process->pid, this->trdid, count, file_id );165 #endif166 this->errno = EIO;167 hal_restore_irq( save_sr );168 return -1;169 }170 164 } 171 165 else if( file_type == INODE_TYPE_DEV ) // read from TXT device … … 184 178 txt_owner_xp = hal_remote_l64( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) ); 185 179 186 // checkTXT_RX ownership180 // wait for TXT_RX ownership 187 181 if ( process_owner_xp != txt_owner_xp ) 188 182 { … … 202 196 } 203 197 204 // move count bytes fromdevice198 // try to move count bytes from TXT device 205 199 nbytes = devfs_user_move( true, // from device to buffer 206 200 file_xp, 207 201 vaddr, 208 202 count ); 209 if( nbytes != count )210 {211 212 #if DEBUG_SYSCALLS_ERROR213 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read data from file %d\n",214 __FUNCTION__, process->pid, this->trdid, file_id );215 #endif216 this->errno = EIO;217 hal_restore_irq( save_sr );218 return -1;219 }220 203 } 221 204 else // not FILE and not DEV … … 229 212 hal_restore_irq( save_sr ); 230 213 return -1; 214 } 215 216 // check error 217 if( nbytes == 0xFFFFFFFF ) 218 { 219 220 #if DEBUG_SYSCALLS_ERROR 221 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read data from file %d\n", 222 __FUNCTION__, process->pid, this->trdid, file_id ); 223 #endif 224 this->errno = EIO; 225 hal_restore_irq( save_sr ); 226 return -1; 231 227 } 232 228 -
trunk/kernel/syscalls/sys_write.c
r635 r656 62 62 cxy_t file_cxy; // remote file cluster identifier 63 63 uint32_t file_type; // file type 64 uint32_t file_offset; // currentfile offset65 uint32_t file_attr; // file _attribute64 uint32_t file_offset; // file offset 65 uint32_t file_attr; // file attributes 66 66 vfs_inode_t * inode_ptr; // local pointer on associated inode 67 67 uint32_t nbytes; // number of bytes actually written … … 138 138 hal_enable_irq( &save_sr ); 139 139 140 // action depend on file type 140 // action depend on file type: 141 141 142 if( file_type == INODE_TYPE_FILE ) // write to a file mapper 142 143 { … … 159 160 vaddr, 160 161 count ); 161 if ( nbytes != count )162 {163 164 #if DEBUG_SYSCALLS_ERROR165 printk("\n[ERROR] in %s : thread[%x,%x] cannot write %d bytes into file %d\n",166 __FUNCTION__ , process->pid, this->trdid, count, file_id );167 #endif168 hal_restore_irq( save_sr );169 this->errno = EIO;170 return -1;171 172 }173 174 // update file size in inode descriptor175 // only if (file_offset + count) > current_size176 // note: the parent directory entry in mapper will177 // be updated by the close syscall178 xptr_t inode_xp = XPTR( file_cxy , inode_ptr );179 vfs_inode_update_size( inode_xp , file_offset + count );180 162 } 181 163 else if( file_type == INODE_TYPE_DEV ) // write to TXT device … … 186 168 vaddr, 187 169 count ); 188 if( nbytes != count ) 189 { 170 } 171 else // not FILE and not DEV 172 { 173 174 #if DEBUG_SYSCALLS_ERROR 175 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 176 __FUNCTION__, vfs_inode_type_str( file_type ) ); 177 #endif 178 hal_restore_irq( save_sr ); 179 this->errno = EBADFD; 180 return -1; 181 } 182 183 // chek error 184 if( nbytes == 0xFFFFFFFF ) 185 { 190 186 191 187 #if DEBUG_SYSCALLS_ERROR … … 193 189 __FUNCTION__ , process->pid, this->trdid, file_id ); 194 190 #endif 195 hal_restore_irq( save_sr );196 this->errno = EIO;197 return -1;198 }199 }200 else // not FILE and not DEV201 {202 203 #if DEBUG_SYSCALLS_ERROR204 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",205 __FUNCTION__, vfs_inode_type_str( file_type ) );206 #endif207 191 hal_restore_irq( save_sr ); 208 this->errno = EBADFD;209 192 this->errno = EIO; 193 return -1; 210 194 } 211 195
Note: See TracChangeset
for help on using the changeset viewer.