[1] | 1 | /* |
---|
[611] | 2 | * sys_closedir.c - Close an open VFS directory. |
---|
[1] | 3 | * |
---|
[611] | 4 | * Author Alain Greiner (2016,2017,2018) |
---|
[1] | 5 | * |
---|
[23] | 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
[1] | 7 | * |
---|
[23] | 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
[1] | 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
[23] | 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
[1] | 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
[23] | 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
[1] | 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[611] | 24 | #include <kernel_config.h> |
---|
[457] | 25 | #include <hal_kernel_types.h> |
---|
[1] | 26 | #include <vfs.h> |
---|
[407] | 27 | #include <printk.h> |
---|
[1] | 28 | #include <thread.h> |
---|
| 29 | #include <process.h> |
---|
[611] | 30 | #include <remote_dir.h> |
---|
[407] | 31 | #include <errno.h> |
---|
| 32 | #include <syscalls.h> |
---|
| 33 | #include <shared_syscalls.h> |
---|
[1] | 34 | |
---|
[407] | 35 | /////////////////////////////// |
---|
| 36 | int sys_closedir ( DIR * dirp ) |
---|
[1] | 37 | { |
---|
[611] | 38 | xptr_t dir_xp; // extended pointer on remote_dir_t structure |
---|
| 39 | |
---|
| 40 | thread_t * this = CURRENT_THREAD; // client thread |
---|
| 41 | process_t * process = this->process; // client process |
---|
| 42 | |
---|
| 43 | #if (DEBUG_SYS_CLOSEDIR || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
| 44 | uint64_t tm_start = hal_get_cycles(); |
---|
| 45 | #endif |
---|
| 46 | |
---|
| 47 | #if DEBUG_SYS_CLOSEDIR |
---|
| 48 | if( DEBUG_SYS_CLOSEDIR < tm_start ) |
---|
| 49 | printk("\n[%s] thread[%x,%x] enter for DIR <%x> / cycle %d\n", |
---|
| 50 | __FUNCTION__, process->pid, this->trdid, dirp, (uint32_t)tm_start ); |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | // get extended pointer on kernel remote_dir_t structure from dirp |
---|
| 54 | dir_xp = remote_dir_from_ident( (intptr_t)dirp ); |
---|
| 55 | |
---|
| 56 | if( dir_xp == XPTR_NULL ) |
---|
| 57 | { |
---|
| 58 | |
---|
| 59 | #if DEBUG_SYSCALLS_ERROR |
---|
| 60 | printk("\n[ERROR] in %s / thread[%x,%x] : DIR pointer %x not registered\n", |
---|
| 61 | __FUNCTION__ , process->pid , this->trdid, dirp ); |
---|
| 62 | #endif |
---|
| 63 | this->errno = EINVAL; |
---|
| 64 | return -1; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | // delete kernel remote_dir_t structure |
---|
| 68 | remote_dir_destroy( dir_xp ); |
---|
| 69 | |
---|
| 70 | hal_fence(); |
---|
| 71 | |
---|
| 72 | #if (DEBUG_SYS_CLOSEDIR || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
| 73 | uint64_t tm_end = hal_get_cycles(); |
---|
| 74 | #endif |
---|
| 75 | |
---|
| 76 | #if DEBUG_SYS_CLOSEDIR |
---|
| 77 | if( DEBUG_SYS_CLOSEDIR < tm_end ) |
---|
| 78 | printk("\n[%s] thread[%x,%x] exit for DIR <%x> / cycle %d\n", |
---|
| 79 | __FUNCTION__, process->pid, this->trdid, dirp, (uint32_t)tm_end ); |
---|
| 80 | #endif |
---|
| 81 | |
---|
| 82 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
| 83 | hal_atomic_add( &syscalls_cumul_cost[SYS_CLOSEDIR] , tm_end - tm_start ); |
---|
| 84 | hal_atomic_add( &syscalls_occurences[SYS_CLOSEDIR] , 1 ); |
---|
| 85 | #endif |
---|
| 86 | |
---|
| 87 | return 0; |
---|
| 88 | |
---|
[23] | 89 | } // end sys_closedir() |
---|