Changeset 23 for trunk/kernel/syscalls/sys_chmod.c
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_chmod.c
r11 r23 1 1 /* 2 * sys_chmod : change file mode2 * sys_chmod.c - Change file access rights. 3 3 * 4 * Author Alain Greiner (2016,2017) 5 * 4 6 * Copyright (c) 2015 UPMC Sorbonne Universites 5 7 * 6 * This file is part of ALMOS- kernel.8 * This file is part of ALMOS-MKH. 7 9 * 8 * ALMOS- kernelis free software; you can redistribute it and/or modify it10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 9 11 * under the terms of the GNU General Public License as published by 10 12 * the Free Software Foundation; version 2.0 of the License. 11 13 * 12 * ALMOS- kernelis distributed in the hope that it will be useful, but14 * ALMOS-MKH is distributed in the hope that it will be useful, but 13 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 16 18 * 17 19 * You should have received a copy of the GNU General Public License 18 * along with ALMOS- kernel; if not, write to the Free Software Foundation,20 * along with ALMOS-MKH; if not, write to the Free Software Foundation, 19 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 22 */ 21 23 22 #include <cpu.h> 23 #include <chdev.h> 24 #include <driver.h> 25 #include <rwlock.h> 24 #include <hal_types.h> 25 #include <hal_uspace.h> 26 26 #include <vfs.h> 27 #include <sys-vfs.h> 27 #include <vmm.h> 28 #include <printk.h> 28 29 #include <thread.h> 29 #include <ku_transfert.h> 30 #include <task.h> 30 #include <process.h> 31 31 32 int sys_chmod (char *pathname, uint_t mode) 32 ////////////////////////////////// 33 int sys_chmod( char * pathname, 34 uint32_t rights ) 33 35 { 34 register error_t err = 0; 35 register struct thread_s *this; 36 register struct task_s *task; 37 struct ku_obj ku_path; 36 error_t error; 37 paddr_t paddr; 38 uint32_t length; 39 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 40 41 thread_t * this = CURRENT_THREAD; 42 process_t * process = this->process; 38 43 39 this = current_thread; 40 task = current_task;44 // check pathname in user space 45 error = vmm_v2p_translate( false , pathname , &paddr ); 41 46 42 if( !pathname || NOT_IN_USPACE(pathname))47 if( error ) 43 48 { 44 this->info.errno = EINVAL; 49 printk("\n[ERROR] in %s : user pathname unmapped for thread %x in process %x\n", 50 __FUNCTION__ , this->trdid , process->pid ); 51 this->errno = EINVAL; 45 52 return -1; 46 53 } 47 48 49 KU_BUFF(ku_path, pathname); 50 rwlock_wrlock(&task->cwd_lock); 51 52 if((err = vfs_chmod(&ku_path, &task->vfs_cwd, mode))) 54 55 // get pathname length 56 length = hal_strlen_from_uspace( pathname ); 57 58 if( length >= CONFIG_VFS_MAX_PATH_LENGTH ) 59 { 60 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 61 this->errno = ENFILE; 62 return -1; 63 } 64 65 // get pathname copy in kernel space 66 hal_copy_from_uspace( kbuf, pathname, length ); 67 68 // get cluster and local pointer on reference process 69 xptr_t ref_xp = process->ref_xp; 70 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 71 cxy_t ref_cxy = GET_CXY( ref_xp ); 72 73 // get extended pointer on cwd inode 74 xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); 75 76 // get the cwd lock in read mode from reference process 77 remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 78 79 // call the relevant VFS function 80 error = vfs_chmod( cwd_xp, 81 kbuf, 82 rights ); 83 84 // release the cwd lock 85 remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 86 87 if( error ) 53 88 { 54 rwlock_unlock(&task->cwd_lock); 55 this->info.errno = (err < 0) ? -err : err; 89 printk("\n[ERROR] in %s : cannot remove directory %s\n", 90 __FUNCTION__ , kbuf ); 91 this->errno = error; 56 92 return -1; 57 93 } 58 94 59 rwlock_unlock(&task->cwd_lock);60 95 return 0; 61 } 96 97 } // end sys_chmod()
Note: See TracChangeset
for help on using the changeset viewer.