Changeset 23 for trunk/kernel/syscalls/sys_stat.c
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_stat.c
r1 r23 1 1 /* 2 * kern/sys_stat.c - stats a file or directory2 * sys_stat.c - Return statistics on a file or directory. 3 3 * 4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless 5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites 4 * Author Alain Greiner (2016,2017) 6 5 * 7 * This file is part of ALMOS-kernel.6 * Copyright (c) UPMC Sorbonne Universites 8 7 * 9 * ALMOS-kernel is free software; you can redistribute it and/or modify it 8 * This file is part of ALMOS-MKH. 9 * 10 * ALMOS-MKH is free software; you can redistribute it and/or modify it 10 11 * under the terms of the GNU General Public License as published by 11 12 * the Free Software Foundation; version 2.0 of the License. 12 13 * 13 * 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 14 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU … … 17 18 * 18 19 * You should have received a copy of the GNU General Public License 19 * 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, 20 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 21 22 */ 22 23 24 #include <hal_types.h> 25 #include <hal_uspace.h> 26 #include <hal_special.h> 23 27 #include <errno.h> 24 28 #include <thread.h> 29 #include <printk.h> 25 30 #include <vfs.h> 26 #include <sys-vfs.h> 27 #include <task.h> 28 #include <spinlock.h> 29 #include <cpu-trace.h> 31 #include <vmm.h> 32 #include <process.h> 30 33 34 ////////////////////////////////////////// 35 int sys_stat( uint32_t file_id, 36 struct vfs_stat_s * stat ) 37 { 38 error_t error; 39 paddr_t paddr; 40 struct vfs_stat_s k_stat; 41 xptr_t file_xp; 42 43 thread_t * this = CURRENT_THREAD; 44 process_t * process = this->process; 31 45 32 int sys_stat(char *pathname, struct vfs_stat_s *buff, int fd) 33 { 34 CPU_HW_TRACE(sys_stat); 35 struct thread_s *this; 36 register error_t err = 0; 37 struct vfs_file_s *file; 38 struct ku_obj ku_path; 39 struct task_s *task; 46 // check stat structure in user space 47 error = vmm_v2p_translate( false , stat , &paddr ); 40 48 41 file = NULL; 42 this = current_thread; 43 task = current_task; 49 if( error ) 50 { 51 printk("\n[ERROR] in %s : stat structure unmapped for thread %x in process %x\n", 52 __FUNCTION__ , this->trdid , process->pid ); 53 this->errno = EINVAL; 54 return -1; 55 } 44 56 45 if((buff == NULL) || ((pathname == NULL) && (fd == -1))) 57 // get extended pointer on remote file descriptor 58 file_xp = process_fd_get_xptr( process , file_id ); 59 60 if( file_xp == XPTR_NULL ) 61 { 62 printk("\n[ERROR] in %s : undefined file descriptor for thread %x in process %x\n", 63 __FUNCTION__ , this->trdid , process->pid ); 64 this->errno = EBADFD; 65 return -1; 66 } 67 68 // call the relevant VFS function 69 error = vfs_stat( file_xp, 70 &k_stat ); 71 if( error ) 46 72 { 47 this->info.errno = EINVAL; 48 CPU_HW_TRACE(sys_stat); 73 printk("\n[ERROR] in %s : cannot access file %d for thread %x in process %x\n", 74 __FUNCTION__ , file_id , this->trdid , process->pid ); 75 this->errno = error; 49 76 return -1; 50 77 } 78 79 // copy stat to user space 80 hal_copy_to_uspace( stat , &k_stat , sizeof(struct vfs_stat_s) ); 51 81 52 if(NOT_IN_USPACE((uint_t)buff)) 53 { 54 this->info.errno = EPERM; 55 CPU_HW_TRACE(sys_stat); 56 return -1; 57 } 82 hal_wbflush(); 58 83 59 if(pathname == NULL)60 {61 if((fd >= CONFIG_TASK_FILE_MAX_NR) || (task_fd_lookup(task, fd, &file)))62 {63 CPU_HW_TRACE(sys_stat);64 return EBADFD;65 }66 67 err = vfs_stat(&task->vfs_cwd, NULL, buff, file);68 }69 else70 {71 KU_BUFF(ku_path, pathname);72 rwlock_rdlock(&task->cwd_lock);73 err = vfs_stat(&task->vfs_cwd, &ku_path, buff, NULL);74 rwlock_unlock(&task->cwd_lock);75 }76 77 this->info.errno = err;78 CPU_HW_TRACE(sys_stat);79 84 return 0; 80 } 85 86 } // end sys_stat() 87
Note: See TracChangeset
for help on using the changeset viewer.