Changeset 670 for trunk/kernel/syscalls/sys_write.c
- Timestamp:
- Nov 19, 2020, 11:45:52 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_write.c
r664 r670 2 2 * sys_write.c - Kernel function implementing the "write" 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 … … 71 72 process_t * process = this->process; 72 73 73 #if (DEBUG_SYS_WRITE || CONFIG_INSTRUMENTATION_SYSCALLS)74 #if DEBUG_SYS_WRITE || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS 74 75 uint64_t tm_start = hal_get_cycles(); 75 76 #endif … … 91 92 92 93 #if DEBUG_SYSCALLS_ERROR 93 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n", 94 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 95 printk("\n[ERROR] in %s : thread[%x,%x] / illegal file descriptor index %d\n", 94 96 __FUNCTION__, process->pid, this->trdid, file_id ); 95 97 #endif … … 105 107 106 108 #if DEBUG_SYSCALLS_ERROR 107 printk("\n[ERROR] in %s : thread[%x,%x] user buffer unmapped %x\n", 109 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 110 printk("\n[ERROR] in %s : thread[%x,%x] / user buffer unmapped %x\n", 108 111 __FUNCTION__ , process->pid, this->trdid, (intptr_t)vaddr ); 109 112 #endif … … 119 122 120 123 #if DEBUG_SYSCALLS_ERROR 121 printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor = %d\n", 124 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 125 printk("\n[ERROR] in %s : thread[%x,%x] / undefined file descriptor = %d\n", 122 126 __FUNCTION__, process->pid, this->trdid, file_id ); 123 127 #endif … … 139 143 hal_enable_irq( &save_sr ); 140 144 141 // action depend on file type: 142 143 if( file_type == INODE_TYPE_FILE ) // write to a file mapper 144 { 145 // check file writable 146 if( (file_attr & FD_ATTR_WRITE_ENABLE) == 0 ) 147 { 148 149 #if DEBUG_SYSCALLS_ERROR 150 printk("\n[ERROR] in %s : thread[%x,%x] file %d not writable\n", 145 // check file writable 146 if( (file_attr & FD_ATTR_WRITE_ENABLE) == 0 ) 147 { 148 149 #if DEBUG_SYSCALLS_ERROR 150 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 151 printk("\n[ERROR] in %s : thread[%x,%x] / file %d not writable\n", 151 152 __FUNCTION__ , process->pid, this->trdid, file_id ); 152 153 #endif … … 154 155 this->errno = EBADFD; 155 156 return -1; 156 } 157 157 } 158 159 // action depend on file type: 160 if( file_type == FILE_TYPE_REG ) // write to mapper 161 { 158 162 // move count bytes to mapper 159 nbytes = vfs_user_move( false, // from bufferto mapper163 nbytes = vfs_user_move( false, // to mapper 160 164 file_xp, 161 165 vaddr, 162 166 count ); 163 167 } 164 else if( file_type == INODE_TYPE_DEV )// write to TXT device168 else if( file_type == FILE_TYPE_DEV ) // write to TXT device 165 169 { 166 170 // move count bytes to device 167 nbytes = devfs_user_move( false, // from bufferto device171 nbytes = devfs_user_move( false, // to device 168 172 file_xp, 169 173 vaddr, 170 174 count ); 171 175 } 172 else // not FILE and not DEV 173 { 174 175 #if DEBUG_SYSCALLS_ERROR 176 else if( (file_type == FILE_TYPE_PIPE) || 177 (file_type == FILE_TYPE_FIFO) ) // write to pipe 178 { 179 // move count bytes to pipe 180 nbytes = pipe_user_move( false, // to pipe 181 file_xp, 182 vaddr, 183 count ); 184 } 185 else // unsupported type 186 { 187 188 #if DEBUG_SYSCALLS_ERROR 189 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 176 190 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 177 191 __FUNCTION__, vfs_inode_type_str( file_type ) ); … … 187 201 188 202 #if DEBUG_SYSCALLS_ERROR 203 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 189 204 printk("\n[ERROR] in %s : thread[%x,‰x] cannot write data to file %d\n", 190 205 __FUNCTION__ , process->pid, this->trdid, file_id );
Note: See TracChangeset
for help on using the changeset viewer.