1 | /* |
---|
2 | * sys_closedir.c - Close an open VFS directory. |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016,2017,2018,2019,20120) |
---|
5 | * |
---|
6 | * Copyright (c) UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
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 | * |
---|
14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
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 |
---|
20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | #include <kernel_config.h> |
---|
25 | #include <hal_kernel_types.h> |
---|
26 | #include <vfs.h> |
---|
27 | #include <printk.h> |
---|
28 | #include <thread.h> |
---|
29 | #include <process.h> |
---|
30 | #include <user_dir.h> |
---|
31 | #include <errno.h> |
---|
32 | #include <syscalls.h> |
---|
33 | #include <shared_syscalls.h> |
---|
34 | |
---|
35 | /////////////////////////////// |
---|
36 | int sys_closedir ( DIR * dirp ) |
---|
37 | { |
---|
38 | xptr_t dir_xp; // extended pointer on user_dir_t structure |
---|
39 | user_dir_t * dir_ptr; // local pointer on user_dir_t structure |
---|
40 | cxy_t dir_cxy; // cluster identifier (inode cluster) |
---|
41 | |
---|
42 | thread_t * this = CURRENT_THREAD; // client thread |
---|
43 | process_t * process = this->process; // client process |
---|
44 | |
---|
45 | #if DEBUG_SYS_CLOSEDIR || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS |
---|
46 | uint64_t tm_start = hal_get_cycles(); |
---|
47 | #endif |
---|
48 | |
---|
49 | #if DEBUG_SYS_CLOSEDIR |
---|
50 | if( DEBUG_SYS_CLOSEDIR < tm_start ) |
---|
51 | printk("\n[%s] thread[%x,%x] enter for DIR <%x> / cycle %d\n", |
---|
52 | __FUNCTION__, process->pid, this->trdid, dirp, (uint32_t)tm_start ); |
---|
53 | #endif |
---|
54 | |
---|
55 | // get extended pointer on kernel user_dir_t structure from dirp |
---|
56 | dir_xp = user_dir_from_ident( (intptr_t)dirp ); |
---|
57 | |
---|
58 | if( dir_xp == XPTR_NULL ) |
---|
59 | { |
---|
60 | |
---|
61 | #if DEBUG_SYSCALLS_ERROR |
---|
62 | if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) |
---|
63 | printk("\n[ERROR] in %s : thread[%x,%x] / DIR pointer %x not registered\n", |
---|
64 | __FUNCTION__ , process->pid , this->trdid, dirp ); |
---|
65 | #endif |
---|
66 | this->errno = EINVAL; |
---|
67 | return -1; |
---|
68 | } |
---|
69 | |
---|
70 | // get cluster and local pointer for user_dir_t structure |
---|
71 | dir_ptr = GET_PTR( dir_xp ); |
---|
72 | dir_cxy = GET_CXY( dir_xp ); |
---|
73 | |
---|
74 | // delete both user_dir_t structure and dirent array |
---|
75 | if( dir_cxy == local_cxy ) |
---|
76 | { |
---|
77 | user_dir_destroy( dir_ptr, |
---|
78 | process->ref_xp ); |
---|
79 | } |
---|
80 | else |
---|
81 | { |
---|
82 | rpc_user_dir_destroy_client( dir_cxy, |
---|
83 | dir_ptr, |
---|
84 | process->ref_xp ); |
---|
85 | } |
---|
86 | |
---|
87 | hal_fence(); |
---|
88 | |
---|
89 | #if (DEBUG_SYS_CLOSEDIR || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
90 | uint64_t tm_end = hal_get_cycles(); |
---|
91 | #endif |
---|
92 | |
---|
93 | #if DEBUG_SYS_CLOSEDIR |
---|
94 | if( DEBUG_SYS_CLOSEDIR < tm_end ) |
---|
95 | printk("\n[%s] thread[%x,%x] exit for DIR <%x> / cycle %d\n", |
---|
96 | __FUNCTION__, process->pid, this->trdid, dirp, (uint32_t)tm_end ); |
---|
97 | #endif |
---|
98 | |
---|
99 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
100 | hal_atomic_add( &syscalls_cumul_cost[SYS_CLOSEDIR] , tm_end - tm_start ); |
---|
101 | hal_atomic_add( &syscalls_occurences[SYS_CLOSEDIR] , 1 ); |
---|
102 | #endif |
---|
103 | |
---|
104 | return 0; |
---|
105 | |
---|
106 | } // end sys_closedir() |
---|