source: trunk/kernel/syscalls/sys_stat.c @ 324

Last change on this file since 324 was 124, checked in by max@…, 7 years ago

rename hal_wbflush->hal_fence

File size: 2.4 KB
Line 
1/*
2 * sys_stat.c - Return statistics on a file or directory.
3 *
4 * Author    Alain Greiner  (2016,2017)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include <hal_types.h>
25#include <hal_uspace.h>
26#include <hal_special.h>
27#include <errno.h>
28#include <thread.h>
29#include <printk.h>
30#include <vfs.h>
31#include <vmm.h>
32#include <process.h>
33
34//////////////////////////////////////////
35int 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;
45
46    // check stat structure in user space
47    error = vmm_v2p_translate( false , stat , &paddr );
48
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        }       
56
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 )
72        {
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;
76                return -1;
77        }
78   
79    // copy stat to user space
80    hal_copy_to_uspace( stat , &k_stat , sizeof(struct vfs_stat_s) );
81
82    hal_fence();
83
84        return 0;
85
86}  // end sys_stat()
87
Note: See TracBrowser for help on using the repository browser.