Changeset 604 for trunk/kernel/syscalls/sys_write.c
- Timestamp:
- Dec 3, 2018, 12:18:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_write.c
r594 r604 55 55 uint32_t count ) 56 56 { 57 error_t error; 58 vseg_t * vseg; // required for user space checking 59 xptr_t file_xp; // remote file extended pointer 60 uint32_t nbytes; // number of bytes actually written 61 reg_t save_sr; // required to enable IRQs during syscall 62 63 thread_t * this = CURRENT_THREAD; 64 process_t * process = this->process; 57 error_t error; 58 vseg_t * vseg; // required for user space checking 59 xptr_t file_xp; // remote file extended pointer 60 vfs_file_t * file_ptr; // remote file local pointer 61 cxy_t file_cxy; // remote file cluster identifier 62 uint32_t file_type; // file type 63 uint32_t file_offset; // current file offset 64 uint32_t file_attr; // file_attribute 65 vfs_inode_t * inode_ptr; // local pointer on associated inode 66 uint32_t nbytes; // number of bytes actually written 67 reg_t save_sr; // required to enable IRQs during syscall 68 69 thread_t * this = CURRENT_THREAD; 70 process_t * process = this->process; 65 71 66 72 #if (DEBUG_SYS_WRITE || CONFIG_INSTRUMENTATION_SYSCALLS) … … 113 119 114 120 #if DEBUG_SYSCALLS_ERROR 115 printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor index= %d\n",121 printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor = %d\n", 116 122 __FUNCTION__, process->pid, this->trdid, file_id ); 117 123 #endif … … 121 127 122 128 // get file descriptor cluster and local pointer 123 vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp ); 124 cxy_t file_cxy = GET_CXY( file_xp ); 125 126 127 // get file type 128 vfs_inode_type_t type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 129 file_ptr = GET_PTR( file_xp ); 130 file_cxy = GET_CXY( file_xp ); 131 132 // get file type, offset, aatributes, and associated inode 133 file_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 134 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 135 inode_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 136 file_attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 129 137 130 138 // enable IRQs … … 132 140 133 141 // action depend on file type 134 if( type == INODE_TYPE_FILE ) // check file writable & write tomapper142 if( file_type == INODE_TYPE_FILE ) // write to file mapper 135 143 { 136 144 // check file writable 137 uint32_t attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) ); 138 if( (attr & FD_ATTR_WRITE_ENABLE) == 0 ) 145 if( (file_attr & FD_ATTR_WRITE_ENABLE) == 0 ) 139 146 { 140 147 … … 143 150 __FUNCTION__ , process->pid, this->trdid, file_id ); 144 151 #endif 152 hal_restore_irq( save_sr ); 145 153 this->errno = EBADFD; 146 154 return -1; … … 152 160 vaddr, 153 161 count ); 154 } 155 else if( type == INODE_TYPE_DEV ) // write to TXT device 162 if ( nbytes != count ) 163 { 164 165 #if DEBUG_SYSCALLS_ERROR 166 printk("\n[ERROR] in %s : thread[%x,%x] cannot write %d bytes into file %d\n", 167 __FUNCTION__ , process->pid, this->trdid, count, file_id ); 168 #endif 169 hal_restore_irq( save_sr ); 170 this->errno = EIO; 171 return -1; 172 173 } 174 175 // update size field in inode if required 176 xptr_t size_xp = XPTR( file_cxy , &inode_ptr->size ); 177 uint32_t inode_size = hal_remote_l32( size_xp ); 178 if ( (file_offset + count) > inode_size ) 179 { 180 hal_remote_s32( size_xp , file_offset + count ); 181 } 182 } 183 else if( file_type == INODE_TYPE_DEV ) // write to TXT device 156 184 { 157 185 // move count bytes to device 158 186 nbytes = devfs_user_move( false, // from buffer to device 159 file_xp, 160 vaddr, 161 count ); 162 } 163 else // not FILE and not DEV 164 { 165 166 #if DEBUG_SYSCALLS_ERROR 167 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 168 __FUNCTION__, vfs_inode_type_str( type ) ); 169 #endif 170 this->errno = EBADFD; 171 return -1; 172 } 173 174 if( nbytes != count ) 175 { 187 file_xp, 188 vaddr, 189 count ); 190 if( nbytes != count ) 191 { 176 192 177 193 #if DEBUG_SYSCALLS_ERROR … … 179 195 __FUNCTION__ , process->pid, this->trdid, file_id ); 180 196 #endif 181 this->errno = EIO; 182 return -1; 197 hal_restore_irq( save_sr ); 198 this->errno = EIO; 199 return -1; 200 } 201 } 202 else // not FILE and not DEV 203 { 204 205 #if DEBUG_SYSCALLS_ERROR 206 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n", 207 __FUNCTION__, vfs_inode_type_str( file_type ) ); 208 #endif 209 hal_restore_irq( save_sr ); 210 this->errno = EBADFD; 211 return -1; 183 212 } 184 213
Note: See TracChangeset
for help on using the changeset viewer.