Changeset 670 for trunk/kernel/syscalls/sys_close.c
- Timestamp:
- Nov 19, 2020, 11:45:52 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_close.c
r664 r670 1 1 /* 2 * sys_close.c close an open file2 * sys_close.c kernel function implementing the <close> syscall 3 3 * 4 * Author Alain Greiner (2016,2017,2018,2019,2020)4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 40 40 cxy_t file_cxy; 41 41 vfs_file_t * file_ptr; 42 vfs_ inode_type_t file_type;42 vfs_file_type_t file_type; 43 43 44 44 thread_t * this = CURRENT_THREAD; 45 45 process_t * process = this->process; 46 46 47 #if (DEBUG_SYS_CLOSE || CONFIG_INSTRUMENTATION_SYSCALLS)47 #if DEBUG_SYS_CLOSE || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS 48 48 uint64_t tm_start = hal_get_cycles(); 49 49 #endif 50 50 51 51 #if DEBUG_SYS_CLOSE 52 if( DEBUG_SYS_CLOSE < tm_start )52 if( DEBUG_SYS_CLOSE < (uint32_t)tm_start ) 53 53 printk("\n[%s] thread[%x,%x] enter / fdid %d / cycle %d\n", 54 54 __FUNCTION__, process->pid, this->trdid, fdid, (uint32_t)tm_start ); … … 60 60 61 61 #if DEBUG_SYSCALLS_ERROR 62 printk("\n[ERROR] in %s : illegal file descriptor index = %d\n", 63 __FUNCTION__ , fdid ); 62 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 63 printk("\n[ERROR] in %s : thread[%x,%x] / illegal file descriptor index = %d\n", 64 __FUNCTION__ , process->pid , this->trdid , fdid ); 64 65 #endif 65 66 this->errno = EBADFD; … … 74 75 75 76 #if DEBUG_SYSCALLS_ERROR 76 printk("\n[ERROR] in %s : undefined file descriptor %d\n", 77 __FUNCTION__ , fdid ); 77 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 78 printk("\n[ERROR] in %s : thread[%x,%x] / undefined file descriptor %d\n", 79 __FUNCTION__ , process->pid , this->trdid , fdid ); 78 80 #endif 79 81 this->errno = EBADFD; … … 86 88 file_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 87 89 88 if( file_type == INODE_TYPE_DIR )90 if( file_type == FILE_TYPE_DIR ) 89 91 { 90 92 91 93 #if DEBUG_SYSCALLS_ERROR 92 printk("\n[ERROR] in %s : file descriptor %d is a directory\n", 93 __FUNCTION__ , fdid ); 94 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 95 printk("\n[ERROR] in %s : thread[%x,%x] / file descriptor %d is a directory\n", 96 __FUNCTION__ , process->pid , this->trdid , fdid ); 94 97 #endif 95 98 this->errno = EBADFD; 96 99 return -1; 97 100 } 98 else if( file_type == INODE_TYPE_SOCK )101 else if( file_type == FILE_TYPE_SOCK ) 99 102 { 100 103 // call the relevant socket function 101 104 error = socket_close( file_xp , fdid ); 102 105 } 103 else if( file_type == INODE_TYPE_FILE ) 106 else if( (file_type == FILE_TYPE_REG) || 107 (file_type == FILE_TYPE_FIFO) ) 104 108 { 105 109 // call the relevant VFS function … … 110 114 111 115 #if DEBUG_SYSCALLS_ERROR 112 printk("\n[WARNING] in %s : type (%d) not supported / fdid %d\n", 113 __FUNCTION__ , file_type , fdid ); 116 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 117 printk("\n[WARNING] in %s : thread[%x,%x] / file_type (%s) unsupported / fdid %d\n", 118 __FUNCTION__ , process->pid , this->trdid , vfs_inode_type_str(file_type) , fdid ); 114 119 #endif 115 120 error = 0; … … 120 125 121 126 #if DEBUG_SYSCALLS_ERROR 122 printk("\n[ERROR] in %s : cannot close file descriptor %d\n", 123 __FUNCTION__ , fdid ); 127 if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) 128 printk("\n[ERROR] in %s : thread[%x,%x] cannot close file descriptor %d\n", 129 __FUNCTION__ , process->pid , this->trdid , fdid ); 124 130 #endif 125 131 this->errno = error;
Note: See TracChangeset
for help on using the changeset viewer.