| [1] | 1 | /* | 
|---|
|  | 2 | * sys_chmod: change file mode | 
|---|
|  | 3 | * | 
|---|
|  | 4 | * Copyright (c) 2015 UPMC Sorbonne Universites | 
|---|
|  | 5 | * | 
|---|
|  | 6 | * This file is part of ALMOS-kernel. | 
|---|
|  | 7 | * | 
|---|
|  | 8 | * ALMOS-kernel is free software; you can redistribute it and/or modify it | 
|---|
|  | 9 | * under the terms of the GNU General Public License as published by | 
|---|
|  | 10 | * the Free Software Foundation; version 2.0 of the License. | 
|---|
|  | 11 | * | 
|---|
|  | 12 | * ALMOS-kernel is distributed in the hope that it will be useful, but | 
|---|
|  | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
|  | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
|  | 15 | * General Public License for more details. | 
|---|
|  | 16 | * | 
|---|
|  | 17 | * 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, | 
|---|
|  | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 
|---|
|  | 20 | */ | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include <cpu.h> | 
|---|
|  | 23 | #include <device.h> | 
|---|
|  | 24 | #include <driver.h> | 
|---|
|  | 25 | #include <rwlock.h> | 
|---|
|  | 26 | #include <vfs.h> | 
|---|
|  | 27 | #include <sys-vfs.h> | 
|---|
|  | 28 | #include <thread.h> | 
|---|
|  | 29 | #include <ku_transfert.h> | 
|---|
|  | 30 | #include <task.h> | 
|---|
|  | 31 |  | 
|---|
|  | 32 | int sys_chmod (char *pathname, uint_t mode) | 
|---|
|  | 33 | { | 
|---|
|  | 34 | register error_t err = 0; | 
|---|
|  | 35 | register struct thread_s *this; | 
|---|
|  | 36 | register struct task_s *task; | 
|---|
|  | 37 | struct ku_obj ku_path; | 
|---|
|  | 38 |  | 
|---|
|  | 39 | this = current_thread; | 
|---|
|  | 40 | task = current_task; | 
|---|
|  | 41 |  | 
|---|
|  | 42 | if(!pathname || NOT_IN_USPACE(pathname)) | 
|---|
|  | 43 | { | 
|---|
|  | 44 | this->info.errno = EINVAL; | 
|---|
|  | 45 | return -1; | 
|---|
|  | 46 | } | 
|---|
|  | 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))) | 
|---|
|  | 53 | { | 
|---|
|  | 54 | rwlock_unlock(&task->cwd_lock); | 
|---|
|  | 55 | this->info.errno = (err < 0) ? -err : err; | 
|---|
|  | 56 | return -1; | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
|  | 59 | rwlock_unlock(&task->cwd_lock); | 
|---|
|  | 60 | return 0; | 
|---|
|  | 61 | } | 
|---|