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

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

rename hal_wbflush->hal_fence

File size: 2.4 KB
RevLine 
[1]1/*
[23]2 * sys_stat.c - Return statistics on a file or directory.
[1]3 *
[23]4 * Author    Alain Greiner  (2016,2017)
[1]5 *
[23]6 * Copyright (c) UPMC Sorbonne Universites
[1]7 *
[23]8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
[1]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 *
[23]14 * ALMOS-MKH is distributed in the hope that it will be useful, but
[1]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
[23]20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
[1]21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
[23]24#include <hal_types.h>
25#include <hal_uspace.h>
26#include <hal_special.h>
[1]27#include <errno.h>
28#include <thread.h>
[23]29#include <printk.h>
[1]30#include <vfs.h>
[23]31#include <vmm.h>
32#include <process.h>
[1]33
[23]34//////////////////////////////////////////
35int sys_stat( uint32_t            file_id,
36              struct vfs_stat_s * stat )
[1]37{
[23]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;
[1]45
[23]46    // check stat structure in user space
47    error = vmm_v2p_translate( false , stat , &paddr );
[1]48
[23]49        if( error )
[1]50        {
[23]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;
[1]54                return -1;
[23]55        }       
[1]56
[23]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 )
[1]72        {
[23]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;
[1]76                return -1;
77        }
[23]78   
79    // copy stat to user space
80    hal_copy_to_uspace( stat , &k_stat , sizeof(struct vfs_stat_s) );
[1]81
[124]82    hal_fence();
[23]83
[1]84        return 0;
[23]85
86}  // end sys_stat()
87
Note: See TracBrowser for help on using the repository browser.