Changeset 610 for trunk/kernel/syscalls/sys_chdir.c
- Timestamp:
- Dec 27, 2018, 7:38:58 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_chdir.c
r566 r610 1 1 /* 2 * sys_chdir : change process current working directory2 * sys_chdir.c - kernel function implementing the "chdir" syscall. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 * Copyright (c) 2011,2012UPMC Sorbonne Universites6 * Copyright (c) UPMC Sorbonne Universites 7 7 * 8 8 * This file is part of ALMOS-MKH. … … 38 38 { 39 39 error_t error; 40 vseg_t * vseg; 41 xptr_t root_inode_xp; 42 40 43 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 41 44 42 45 thread_t * this = CURRENT_THREAD; 43 46 process_t * process = this->process; 47 48 #if (DEBUG_SYS_CHDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 49 uint64_t tm_start = hal_get_cycles(); 50 #endif 44 51 45 52 // check pathname length … … 48 55 49 56 #if DEBUG_SYSCALLS_ERROR 50 printk("\n[ERROR] in %s : pathname too long / thread %x in process %x\n",51 __FUNCTION__, this->trdid, process->pid );57 printk("\n[ERROR] in %s : pathname too long / thread[%x,%x]\n", 58 __FUNCTION__, process->pid, this->trdid ); 52 59 #endif 53 this->errno = E NFILE;60 this->errno = EINVAL; 54 61 return -1; 55 62 } 63 64 // check pathname in user space 65 if( vmm_get_vseg( process, (intptr_t)pathname , &vseg ) ) 66 { 67 68 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : user buffer unmapped %x for thread[%x,%x]\n", 70 __FUNCTION__ , (intptr_t)pathname , process->pid, this->trdid ); 71 #endif 72 this->errno = EINVAL; 73 return -1; 74 } 56 75 57 76 // copy pathname in kernel space 58 77 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 59 78 60 printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ ); 61 return -1; 79 #if DEBUG_SYS_CHDIR 80 if( DEBUG_SYS_CHDIR < tm_start ) 81 printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n", 82 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start ); 83 #endif 62 84 63 // get cluster and local pointer on reference process 64 // xptr_t ref_xp = process->ref_xp; 65 // process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 66 // cxy_t ref_cxy = GET_CXY( ref_xp ); 85 // compute root inode for path 86 if( kbuf[0] == '/' ) // absolute path 87 { 88 // use extended pointer on VFS root inode 89 root_inode_xp = process->vfs_root_xp; 90 } 91 else // relative path 92 { 93 // get cluster and local pointer on reference process 94 xptr_t ref_xp = process->ref_xp; 95 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 96 cxy_t ref_cxy = GET_CXY( ref_xp ); 67 97 68 // get extended pointer on cwd lock in reference process 69 // xptr_t lock_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 98 // use extended pointer on CWD inode 99 root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 100 } 70 101 71 // get cwd lock in read mode 72 // remote_rwlock_rd_acquire( lock_xp ); 73 74 // TODO ce n'et pas au VFS de le faire [AG] 75 // error = vfs_chdir( process->vfs_cwd_xp , kbuf ); 76 77 // release cwd lock 78 // remote_rwlock_rd_release( lock_xp ); 102 // call the relevant VFS function 103 error = vfs_chdir( root_inode_xp , kbuf ); 79 104 80 105 if( error ) 81 106 { 82 printk("\n[ERROR] in %s : cannot change current directory\n", __FUNCTION__ ); 107 108 #if DEBUG_SYSCALLS_ERROR 109 printk("\n[ERROR] in %s / thread[%x,%x] : cannot change CWD\n", 110 __FUNCTION__ , process->pid , this->trdid ); 111 #endif 83 112 this->errno = error; 84 113 return -1; 85 114 } 86 115 116 hal_fence(); 117 118 #if (DEBUG_SYS_CHDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 119 uint64_t tm_end = hal_get_cycles(); 120 #endif 121 122 #if DEBUG_SYS_CHDIR 123 if( DEBUG_SYS_CHDIR < tm_end ) 124 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 125 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 126 #endif 127 128 #if CONFIG_INSTRUMENTATION_SYSCALLS 129 hal_atomic_add( &syscalls_cumul_cost[SYS_CHDIR] , tm_end - tm_start ); 130 hal_atomic_add( &syscalls_occurences[SYS_CHDIR] , 1 ); 131 #endif 132 87 133 return 0; 88 134 }
Note: See TracChangeset
for help on using the changeset viewer.