Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (7 years ago)
Author:
alain
Message:

First implementation of fork/exec.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_stat.c

    r124 r407  
    3232#include <process.h>
    3333
    34 //////////////////////////////////////////
    35 int sys_stat( uint32_t            file_id,
    36               struct vfs_stat_s * stat )
     34/////////////////////////////////////
     35int sys_stat( char        * pathname,
     36              struct stat * u_stat )
    3737{
    38     error_t           error;
    39     paddr_t           paddr;
    40     struct vfs_stat_s k_stat;
    41     xptr_t            file_xp;
     38    error_t       error;
     39    paddr_t       paddr;
     40    struct stat   k_stat;       // kernel space
     41    xptr_t        file_xp;
     42    char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4243       
    4344        thread_t  * this    = CURRENT_THREAD;
     
    4546
    4647    // check stat structure in user space
    47     error = vmm_v2p_translate( false , stat , &paddr );
     48    error = vmm_v2p_translate( false , u_stat , &paddr );
    4849
    4950        if( error )
     
    5556        }       
    5657
    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 )
     58    // check pathname length
     59    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    6160    {
    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;
     61        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     62        this->errno = ENFILE;
    6563        return -1;
    6664    }
    6765
    68     // call the relevant VFS function
     66    // copy pathname in kernel space
     67    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     68
     69    // get cluster and local pointer on reference process
     70    xptr_t      ref_xp  = process->ref_xp;
     71    process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     72    cxy_t       ref_cxy = GET_CXY( ref_xp );
     73
     74    // get extended pointer on cwd inode
     75    xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
     76
     77    // get the cwd lock in read mode from reference process
     78    remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     79
     80    // get extended pointer on remote file descriptor
     81    error = vfs_lookup( cwd_xp,
     82                        pathname,
     83                        0,
     84                        &file_xp );
     85
     86    // release the cwd lock
     87    remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     88
     89    if( error )
     90    {
     91        printk("\n[ERROR] in %s : cannot found file <%s> for thread %x in process %x\n",
     92               __FUNCTION__ , pathname , this->trdid , process->pid );
     93        this->errno = error;
     94        return -1;
     95    }
     96
     97    // call VFS function to get stat info
    6998    error = vfs_stat( file_xp,
    7099                      &k_stat );
    71100    if( error )
    72101        {
    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 );
     102        printk("\n[ERROR] in %s : cannot get stats for file %s\n",
     103               __FUNCTION__ , pathname );
    75104                this->errno = error;
    76105                return -1;
    77106        }
    78107   
    79     // copy stat to user space
    80     hal_copy_to_uspace( stat , &k_stat , sizeof(struct vfs_stat_s) );
     108    // copy k_stat to u_stat
     109    hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) );
    81110
    82111    hal_fence();
Note: See TracChangeset for help on using the changeset viewer.