- Timestamp:
- Jul 31, 2017, 2:30:23 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_chdir.c
r23 r301 1 1 /* 2 2 * sys_chdir: change process current working directory 3 * 3 * 4 4 * Author Alain Greiner (2016,2017) 5 5 * … … 35 35 int sys_chdir ( char * pathname ) 36 36 { 37 error_t error; 38 paddr_t paddr; 39 uint32_t length; 37 error_t error; 40 38 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 41 39 42 40 thread_t * this = CURRENT_THREAD; 43 41 process_t * process = this->process; 44 42 45 // check pathname in userspace46 error = vmm_v2p_translate( false , pathname , &paddr);43 // get pathname copy in kernel space 44 error = hal_strcpy_from_uspace( kbuf, pathname, CONFIG_VFS_MAX_PATH_LENGTH ); 47 45 48 if( error ) 49 { 50 printk("\n[ERROR] in %s : user buffer unmapped for thread %x in process %x\n", 51 __FUNCTION__ , this->trdid , process->pid ); 52 this->errno = EINVAL; 53 return -1; 54 } 55 56 // get pathname length 57 length = hal_strlen_from_uspace( pathname ); 58 59 if( length >= CONFIG_VFS_MAX_PATH_LENGTH ) 46 if( error ) 60 47 { 61 48 printk("\n[ERROR] in %s : pathname too long for thread %x in process %x\n", 62 49 __FUNCTION__ , this->trdid , process->pid ); 63 50 this->errno = ENFILE; 64 51 return -1; 65 52 } 66 67 // get pathname copy in kernel space68 hal_copy_from_uspace( kbuf, pathname, length );69 53 70 54 // get cluster and local pointer on reference process … … 75 59 // get extended pointer on cwd lock in reference process 76 60 xptr_t lock_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 77 78 // get cwd lock in read mode 79 61 62 // get cwd lock in read mode 63 remote_rwlock_rd_lock( lock_xp ); 80 64 81 65 // call relevant VFS function 82 66 error = vfs_chdir( process->vfs_cwd_xp , kbuf ); 83 67 84 // release cwd lock 85 68 // release cwd lock 69 remote_rwlock_rd_unlock( lock_xp ); 86 70 87 88 71 if( error ) 72 { 89 73 printk("\n[ERROR] in %s : cannot change current directory\n", __FUNCTION__ ); 90 91 92 93 94 74 this->errno = error; 75 return -1; 76 } 77 78 return 0; 95 79 }
Note: See TracChangeset
for help on using the changeset viewer.