Ignore:
Timestamp:
Dec 27, 2018, 7:38:58 PM (3 years ago)
Author:
alain
Message:

Fix several bugs in VFS to support the following
ksh commandis : cp, mv, rm, mkdir, cd, pwd

File:
1 edited

Legend:

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

    r566 r610  
    11/*
    2  * sys_getcwd.c - get process current work directory
     2 * sys_getcwd.c - kernel function implementing the "getcwd" syscall.
    33 *
    44 * Author    Alain Greiner (2016,2017,2018)
     
    3535#include <syscalls.h>
    3636
    37 /* TODO: user page(s) need to be locked  [AG] */
    38 
    39 ////////////////////////////////
    40 int sys_getcwd ( char     * buf,
     37///////////////////////////////////
     38int sys_getcwd ( char     * buffer,
    4139                 uint32_t   nbytes )
    4240{
    43         error_t    error;
    44     vseg_t   * vseg;
    45     char       kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    46  
     41        error_t       error;
     42    vseg_t      * vseg;
     43    char        * first;                   // first character valid in buffer
     44
     45    char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
     46
    4747        thread_t  * this    = CURRENT_THREAD;
    4848    process_t * process = this->process;
     49
     50#if (DEBUG_SYS_GETCWD || CONFIG_INSTRUMENTATION_SYSCALLS)
     51uint64_t     tm_start = hal_get_cycles();
     52#endif
    4953
    5054    // check buffer size
     
    5357
    5458#if DEBUG_SYSCALLS_ERROR
    55 printk("\n[ERROR] in %s : buffer too small / thread %x / process %x\n",
    56 __FUNCTION__ , this->trdid , process->pid );
     59printk("\n[ERROR] in %s : buffer too small for thread %x,%x]\n",
     60__FUNCTION__ , process->pid, this->trdid );
    5761#endif
    5862                this->errno = EINVAL;
     
    6165
    6266    // check buffer in user space
    63     error = vmm_get_vseg( process, (intptr_t)buf , &vseg );
     67    error = vmm_get_vseg( process, (intptr_t)buffer , &vseg );
    6468
    6569        if( error )
     
    6771
    6872#if DEBUG_SYSCALLS_ERROR
    69 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n",
    70 __FUNCTION__ , (intptr_t)buf , this->trdid , process->pid );
     73printk("\n[ERROR] in %s : user buffer unmapped %x for thread[%x,%x]\n",
     74__FUNCTION__ , (intptr_t)buffer , process->pid, this->trdid );
    7175#endif
    7276                this->errno = EINVAL;
     
    7478        }
    7579
    76     // get reference process cluster and local pointer
     80#if DEBUG_SYS_GETCWD
     81if( DEBUG_SYS_GETCWD < tm_start )
     82printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
     83__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_start );
     84#endif
     85
     86    // get extended pointer on CWD inode from the reference process
    7787    xptr_t      ref_xp  = process->ref_xp;
     88    process_t * ref_ptr = GET_PTR( ref_xp );
    7889    cxy_t       ref_cxy = GET_CXY( ref_xp );
    79     process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
    80 
    81     // get CWD lock in read mode
    82         remote_rwlock_rd_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     90    xptr_t      cwd_xp  = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
    8391
    8492    // call relevant VFS function
    85         error = vfs_get_path( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ,
    86                           kbuf , CONFIG_VFS_MAX_PATH_LENGTH );
    87 
    88     // release CWD lock in read mode
    89         remote_rwlock_rd_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     93        error = vfs_get_path( cwd_xp,
     94                          kbuf,
     95                          &first,
     96                          CONFIG_VFS_MAX_PATH_LENGTH );
    9097
    9198    // copy kernel buffer to user space
    92     hal_copy_to_uspace( buf , kbuf , CONFIG_VFS_MAX_PATH_LENGTH );
     99    hal_strcpy_to_uspace( buffer , first , CONFIG_VFS_MAX_PATH_LENGTH );
    93100
    94101    hal_fence();
     102
     103#if (DEBUG_SYS_GETCWD || CONFIG_INSTRUMENTATION_SYSCALLS)
     104uint64_t     tm_end = hal_get_cycles();
     105#endif
     106
     107#if DEBUG_SYS_GETCWD
     108if( DEBUG_SYS_GETCWD < tm_end )
     109printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
     110__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end );
     111#endif
     112 
     113#if CONFIG_INSTRUMENTATION_SYSCALLS
     114hal_atomic_add( &syscalls_cumul_cost[SYS_GETCWD] , tm_end - tm_start );
     115hal_atomic_add( &syscalls_occurences[SYS_GETCWD] , 1 );
     116#endif
    95117
    96118        return 0;
Note: See TracChangeset for help on using the changeset viewer.