Changeset 670 for trunk/kernel/syscalls/sys_read.c
- Timestamp:
- Nov 19, 2020, 11:45:52 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_read.c
r664 r670 2 2 * sys_read.c - Kernel function implementing the "read" system call. 3 3 * 4 * Author Alain Greiner (2016,2017,2018,2019 )4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 33 33 #include <thread.h> 34 34 #include <printk.h> 35 #include <pipe.h> 35 36 #include <process.h> 36 37 … … 73 74 xptr_t process_owner_xp = process->owner_xp; 74 75 75 #if (DEBUG_SYS_READ || CONFIG_INSTRUMENTATION_SYSCALLS)76 #if DEBUG_SYS_READ || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS 76 77 uint64_t tm_start = hal_get_cycles(); 77 78 #endif … … 92 93 93 94 #if DEBUG_SYSCALLS_ERROR 94 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n", 95 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 96 printk("\n[ERROR] in %s : thread[%x,%x] / illegal file descriptor index %d\n", 95 97 __FUNCTION__ , process->pid, this->trdid, file_id ); 96 98 #endif … … 106 108 107 109 #if DEBUG_SYSCALLS_ERROR 108 printk("\n[ERROR] in %s : thread[%x,%x] user buffer unmapped %x\n", 110 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 111 printk("\n[ERROR] in %s : thread[%x,%x] / user buffer unmapped %x\n", 109 112 __FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr ); 110 113 #endif … … 120 123 121 124 #if DEBUG_SYSCALLS_ERROR 122 printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n", 125 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 126 printk("\n[ERROR] in %s : thread[%x,%x] / undefined fd_id %d\n", 123 127 __FUNCTION__, process->pid, this->trdid, file_id ); 124 128 #endif … … 140 144 hal_enable_irq( &save_sr ); 141 145 146 // check file readable 147 if( (file_attr & FD_ATTR_READ_ENABLE) == 0 ) 148 { 149 150 #if DEBUG_SYSCALLS_ERROR 151 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 152 printk("\n[ERROR] in %s : thread[%x,%x] / file %d not readable\n", 153 __FUNCTION__, process->pid, this->trdid, file_id ); 154 #endif 155 hal_restore_irq( save_sr ); 156 this->errno = EBADFD; 157 return -1; 158 } 159 142 160 // action depend on file type: 143 144 if( file_type == INODE_TYPE_FILE ) // read from file mapper 145 { 146 // check file readable 147 if( (file_attr & FD_ATTR_READ_ENABLE) == 0 ) 148 { 149 150 #if DEBUG_SYSCALLS_ERROR 151 printk("\n[ERROR] in %s : thread[%x,%x] file %d not readable\n", 152 __FUNCTION__, process->pid, this->trdid, file_id ); 153 #endif 154 hal_restore_irq( save_sr ); 155 this->errno = EBADFD; 156 return -1; 157 } 158 161 if( file_type == FILE_TYPE_REG ) // read from mapper 162 { 159 163 // try to move count bytes from mapper 160 nbytes = vfs_user_move( true, // from mapper to buffer164 nbytes = vfs_user_move( true, // from mapper 161 165 file_xp, 162 166 vaddr, 163 167 count ); 164 168 } 165 else if( file_type == INODE_TYPE_DEV )// read from TXT device169 else if( file_type == FILE_TYPE_DEV ) // read from TXT device 166 170 { 167 171 // get cluster and pointers on TXT_RX chdev … … 176 180 { 177 181 // extended pointer on TXT owner process 178 txt_owner_xp = hal_remote_l64( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );179 182 txt_owner_xp = hal_remote_l64( XPTR( chdev_cxy , 183 &chdev_ptr->ext.txt.owner_xp ) ); 180 184 // wait for TXT_RX ownership 181 185 if ( process_owner_xp != txt_owner_xp ) … … 197 201 198 202 // try to move count bytes from TXT device 199 nbytes = devfs_user_move( true, // from device to buffer203 nbytes = devfs_user_move( true, // from device 200 204 file_xp, 201 205 vaddr, 202 206 count ); 203 207 } 204 else // not FILE and not DEV 205 { 206 207 #if DEBUG_SYSCALLS_ERROR 208 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 208 else if( (file_type == FILE_TYPE_PIPE) || 209 (file_type == FILE_TYPE_FIFO) ) // read from pipe 210 { 211 // try to move count bytes from pipe 212 nbytes = pipe_user_move( true, // from pipe 213 file_xp, 214 vaddr, 215 count ); 216 } 217 else // unsupported type 218 { 219 220 #if DEBUG_SYSCALLS_ERROR 221 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 222 printk("\n[ERROR] in %s : thread[%x,%x] / unsupported inode type %d\n", 209 223 __FUNCTION__, vfs_inode_type_str( file_type ) ); 210 224 #endif … … 219 233 220 234 #if DEBUG_SYSCALLS_ERROR 235 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 221 236 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read data from file %d\n", 222 237 __FUNCTION__, process->pid, this->trdid, file_id );
Note: See TracChangeset
for help on using the changeset viewer.