Changeset 664 for trunk/kernel/syscalls/sys_close.c
- Timestamp:
- Oct 10, 2020, 5:11:27 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_close.c
r625 r664 2 2 * sys_close.c close an open file 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018,2019,2020) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 28 28 #include <process.h> 29 29 #include <thread.h> 30 #include <ksocket.h> 30 31 #include <printk.h> 31 32 32 33 #include <syscalls.h> 33 34 34 /////////////////////////////// ///35 int sys_close ( uint32_t f ile_id )35 /////////////////////////////// 36 int sys_close ( uint32_t fdid ) 36 37 { 37 38 error_t error; … … 51 52 if( DEBUG_SYS_CLOSE < tm_start ) 52 53 printk("\n[%s] thread[%x,%x] enter / fdid %d / cycle %d\n", 53 __FUNCTION__, process->pid, this->trdid, f ile_id, (uint32_t)tm_start );54 __FUNCTION__, process->pid, this->trdid, fdid, (uint32_t)tm_start ); 54 55 #endif 55 56 56 // check f ile_id argument57 if( f ile_id >= CONFIG_PROCESS_FILE_MAX_NR )57 // check fdid argument 58 if( fdid >= CONFIG_PROCESS_FILE_MAX_NR ) 58 59 { 59 60 60 61 #if DEBUG_SYSCALLS_ERROR 61 62 printk("\n[ERROR] in %s : illegal file descriptor index = %d\n", 62 __FUNCTION__ , f ile_id );63 __FUNCTION__ , fdid ); 63 64 #endif 64 65 this->errno = EBADFD; … … 67 68 68 69 // get extended pointer on remote file descriptor 69 file_xp = process_fd_get_xptr ( process , file_id );70 file_xp = process_fd_get_xptr_from_local( process , fdid ); 70 71 71 72 if( file_xp == XPTR_NULL ) … … 74 75 #if DEBUG_SYSCALLS_ERROR 75 76 printk("\n[ERROR] in %s : undefined file descriptor %d\n", 76 __FUNCTION__ , f ile_id );77 __FUNCTION__ , fdid ); 77 78 #endif 78 79 this->errno = EBADFD; … … 90 91 #if DEBUG_SYSCALLS_ERROR 91 92 printk("\n[ERROR] in %s : file descriptor %d is a directory\n", 92 __FUNCTION__ , f ile_id );93 __FUNCTION__ , fdid ); 93 94 #endif 94 95 this->errno = EBADFD; 95 96 return -1; 96 97 } 97 98 // call the relevant VFS function 99 error = vfs_close( file_xp , file_id ); 98 else if( file_type == INODE_TYPE_SOCK ) 99 { 100 // call the relevant socket function 101 error = socket_close( file_xp , fdid ); 102 } 103 else if( file_type == INODE_TYPE_FILE ) 104 { 105 // call the relevant VFS function 106 error = vfs_close( file_xp , fdid ); 107 } 108 else 109 { 110 111 #if DEBUG_SYSCALLS_ERROR 112 printk("\n[WARNING] in %s : type (%d) not supported / fdid %d\n", 113 __FUNCTION__ , file_type , fdid ); 114 #endif 115 error = 0; 116 } 100 117 101 118 if( error ) … … 104 121 #if DEBUG_SYSCALLS_ERROR 105 122 printk("\n[ERROR] in %s : cannot close file descriptor %d\n", 106 __FUNCTION__ , f ile_id );123 __FUNCTION__ , fdid ); 107 124 #endif 108 125 this->errno = error;
Note: See TracChangeset
for help on using the changeset viewer.