Changeset 610 for trunk/kernel/syscalls


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

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

Location:
trunk/kernel/syscalls
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/shared_include/syscalls_numbers.h

    r584 r610  
    4141    SYS_MUTEX          = 9,
    4242
    43     SYS_EXIT           = 10,
     43    SYS_RENAME         = 10,
    4444    SYS_MUNMAP         = 11,
    4545    SYS_OPEN           = 12,
     
    8585    SYS_IS_FG          = 49,
    8686
    87     SYSCALLS_NR        = 50,
     87    SYS_EXIT           = 50,
     88
     89    SYSCALLS_NR        = 51,
     90
    8891} syscalls_t;
    8992
  • trunk/kernel/syscalls/sys_chdir.c

    r566 r610  
    11/*
    2  * sys_chdir: change process current working directory
     2 * sys_chdir.c - kernel function implementing the "chdir" syscall.
    33 *
    4  * Author    Alain Greiner (2016,2017)
     4 * Author    Alain Greiner (2016,2017,2018)
    55 *
    6  * Copyright (c) 2011,2012 UPMC Sorbonne Universites
     6 * Copyright (c) UPMC Sorbonne Universites
    77 *
    88 * This file is part of ALMOS-MKH.
     
    3838{
    3939    error_t   error;
     40    vseg_t  * vseg;
     41    xptr_t    root_inode_xp;
     42
    4043    char      kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4144
    4245    thread_t  * this    = CURRENT_THREAD;
    4346    process_t * process = this->process;
     47
     48#if (DEBUG_SYS_CHDIR || CONFIG_INSTRUMENTATION_SYSCALLS)
     49uint64_t     tm_start = hal_get_cycles();
     50#endif
    4451
    4552    // check pathname length
     
    4855
    4956#if DEBUG_SYSCALLS_ERROR
    50 printk("\n[ERROR] in %s : pathname too long / thread %x in process %x\n",
    51 __FUNCTION__, this->trdid, process->pid );
     57printk("\n[ERROR] in %s : pathname too long / thread[%x,%x]\n",
     58__FUNCTION__, process->pid, this->trdid );
    5259#endif
    53         this->errno = ENFILE;
     60        this->errno = EINVAL;
    5461        return -1;
    5562    }
     63
     64    // check pathname in user space
     65    if( vmm_get_vseg( process, (intptr_t)pathname , &vseg ) )
     66        {
     67
     68#if DEBUG_SYSCALLS_ERROR
     69printk("\n[ERROR] in %s : user buffer unmapped %x for thread[%x,%x]\n",
     70__FUNCTION__ , (intptr_t)pathname , process->pid, this->trdid );
     71#endif
     72                this->errno = EINVAL;
     73        return -1;
     74        }
    5675
    5776    // copy pathname in kernel space
    5877    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    5978
    60     printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ );
    61     return -1;
     79#if DEBUG_SYS_CHDIR
     80if( DEBUG_SYS_CHDIR < tm_start )
     81printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n",
     82__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start );
     83#endif
    6284
    63     // get cluster and local pointer on reference process
    64     // xptr_t      ref_xp  = process->ref_xp;
    65     // process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
    66     // cxy_t       ref_cxy = GET_CXY( ref_xp );
     85    // compute root inode for path
     86    if( kbuf[0] == '/' )                        // absolute path
     87    {
     88        // use extended pointer on VFS root inode
     89        root_inode_xp = process->vfs_root_xp;
     90    }
     91    else                                        // relative path
     92    {
     93        // get cluster and local pointer on reference process
     94        xptr_t      ref_xp  = process->ref_xp;
     95        process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     96        cxy_t       ref_cxy = GET_CXY( ref_xp );
    6797
    68     // get extended pointer on cwd lock in reference process
    69     // xptr_t lock_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     98        // use extended pointer on CWD inode
     99        root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
     100    }
    70101
    71     // get cwd lock in read mode
    72     // remote_rwlock_rd_acquire( lock_xp );
    73 
    74     // TODO ce n'et pas au VFS de le faire [AG]
    75     // error = vfs_chdir( process->vfs_cwd_xp , kbuf );
    76 
    77     // release cwd lock
    78     // remote_rwlock_rd_release( lock_xp );
     102    // call the relevant VFS function
     103    error = vfs_chdir( root_inode_xp , kbuf );
    79104
    80105    if( error )
    81106    {
    82         printk("\n[ERROR] in %s : cannot change current directory\n", __FUNCTION__ );
     107
     108#if DEBUG_SYSCALLS_ERROR
     109printk("\n[ERROR] in %s / thread[%x,%x] : cannot change CWD\n",
     110__FUNCTION__ , process->pid , this->trdid );
     111#endif
    83112        this->errno = error;
    84113        return -1;
    85114    }
    86115
     116    hal_fence();
     117
     118#if (DEBUG_SYS_CHDIR || CONFIG_INSTRUMENTATION_SYSCALLS)
     119uint64_t     tm_end = hal_get_cycles();
     120#endif
     121
     122#if DEBUG_SYS_CHDIR
     123if( DEBUG_SYS_CHDIR < tm_end )
     124printk("\n[%s] thread[%x,%x] exit  / cycle %d\n",
     125__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end );
     126#endif
     127 
     128#if CONFIG_INSTRUMENTATION_SYSCALLS
     129hal_atomic_add( &syscalls_cumul_cost[SYS_CHDIR] , tm_end - tm_start );
     130hal_atomic_add( &syscalls_occurences[SYS_CHDIR] , 1 );
     131#endif
     132
    87133    return 0;
    88134}
  • 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;
  • trunk/kernel/syscalls/sys_mkdir.c

    r566 r610  
    11/*
    2  * sys_mkdir.c - Create a new directory in file system.
     2 * sys_mkdir.c - creates a new directory in VFS
    33 *
    4  * Author    Alain Greiner (2016,2017)
     4 * Author     Alain Greiner (2016,2017,2018)
    55 *
    6  * Copyright (c) UPMC Sorbonne Universites
     6 * Copyright (c)  UPMC Sorbonne Universites
    77 *
    8  * This file is part of ALMOS-MKH.
     8 * This file is part of ALMOS-kernel.
    99 *
    1010 * ALMOS-MKH is free software; you can redistribute it and/or modify it
     
    2222 */
    2323
     24#include <kernel_config.h>
    2425#include <hal_kernel_types.h>
    2526#include <hal_uspace.h>
     27#include <errno.h>
    2628#include <vfs.h>
    27 #include <vmm.h>
    28 #include <errno.h>
    2929#include <process.h>
    3030#include <thread.h>
    3131#include <printk.h>
    3232
    33 ///////////////////////////////////
    34 int sys_mkdir( char     * pathname,
    35                uint32_t   mode __attribute__((unused)) )
     33#include <syscalls.h>
     34
     35////////////////////////////////////
     36int sys_mkdir ( char     * pathname,
     37                uint32_t   rights __attribute__((unused)) )
    3638{
    37     error_t        error;
    38     char           kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
     39    error_t   error;
     40    xptr_t    root_inode_xp;                     // extended pointer on root inode
     41    char      kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    3942
    4043    thread_t     * this     = CURRENT_THREAD;
    4144    process_t    * process  = this->process;
    4245
    43     // check fd_array not full
    44     if( process_fd_array_full() )
     46#if (DEBUG_SYS_MKDIR || CONFIG_INSTRUMENTATION_SYSCALLS)
     47uint64_t     tm_start = hal_get_cycles();
     48#endif
     49
     50    // check pathname length
     51    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    4552    {
    46         printk("\n[ERROR] in %s : file descriptor array full for process %x\n",
    47                __FUNCTION__ , process->pid );
     53
     54#if DEBUG_SYSCALLS_ERROR
     55printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     56#endif
    4857        this->errno = ENFILE;
    4958        return -1;
    5059    }
    5160
    52     // check pathname length
    53     if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
     61    // copy pathname in kernel space
     62    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     63
     64#if DEBUG_SYS_MKDIR
     65if( DEBUG_SYS_MKDIR < tm_start )
     66printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n",
     67__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start );
     68#endif
     69 
     70    // compute root inode for path
     71    if( kbuf[0] == '/' )                        // absolute path
    5472    {
    55         printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     73        // use extended pointer on VFS root inode
     74        root_inode_xp = process->vfs_root_xp;
     75    }
     76    else                                        // relative path
     77    {
     78        // get cluster and local pointer on reference process
     79        xptr_t      ref_xp  = process->ref_xp;
     80        process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     81        cxy_t       ref_cxy = GET_CXY( ref_xp );
     82
     83        // use extended pointer on CWD inode
     84        root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
     85    }
     86
     87    // call relevant VFS function
     88    error  = vfs_mkdir( root_inode_xp , kbuf , rights );
     89
     90    if( error )
     91    {
     92
     93#if DEBUG_SYSCALLS_ERROR
     94printk("\n[ERROR] in %s : cannot create directory <%s>\n", __FUNCTION__, kbuf );
     95#endif
    5696        this->errno = ENFILE;
    5797        return -1;
    5898    }
    5999
    60     printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ );
    61     return -1;
    62    
    63     // copy pathname in kernel space
    64     hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     100#if (DEBUG_SYS_MKDIR || CONFIG_INSTRUMENTATION_SYSCALLS)
     101uint64_t     tm_end = hal_get_cycles();
     102#endif
    65103
    66     // get cluster and local pointer on reference process
    67     // xptr_t      ref_xp  = process->ref_xp;
    68     // process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
    69     // cxy_t       ref_cxy = GET_CXY( ref_xp );
    70 
    71     // get extended pointer on cwd inode
    72     // xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
    73 
    74     // get the cwd lock in read mode from reference process
    75     // remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    76 
    77     // call the relevant VFS function
    78     // error = vfs_mkdir( cwd_xp,
    79     //                   kbuf,
    80     //                   mode );
    81 
    82     // release the cwd lock
    83     // remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    84 
    85     if( error )
    86     {
    87         printk("\n[ERROR] in %s : cannot create directory %s\n",
    88                __FUNCTION__ , kbuf );
    89         this->errno = error;
    90         return -1;
    91     }
     104#if DEBUG_SYS_MKDIR
     105if( DEBUG_SYS_MKDIR < tm_end )
     106printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n",
     107__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end );
     108#endif
     109 
     110#if CONFIG_INSTRUMENTATION_SYSCALLS
     111hal_atomic_add( &syscalls_cumul_cost[SYS_MKDIR] , tm_end - tm_start );
     112hal_atomic_add( &syscalls_occurences[SYS_MKDIR] , 1 );
     113#endif
    92114
    93115    return 0;
    94 }
     116
     117} // end sys_mkdir()
  • trunk/kernel/syscalls/sys_open.c

    r604 r610  
    4040{
    4141    error_t        error;
    42     xptr_t         file_xp;                          // extended pointer on vfs_file_t
    43     uint32_t       file_id;                          // file descriptor index
     42    xptr_t         file_xp;                 // extended pointer on vfs_file_t
     43    uint32_t       file_id;                 // file descriptor index
     44    xptr_t         root_inode_xp;           // extended pointer on path root inode
     45
    4446    char           kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4547
     
    8890    cxy_t       ref_cxy = GET_CXY( ref_xp );
    8991
    90     // get the cwd lock in read mode from reference process
    91     remote_rwlock_rd_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     92    // compute root inode for path
     93    if( kbuf[0] == '/' )                        // absolute path
     94    {
     95        // use extended pointer on VFS root inode
     96        root_inode_xp = process->vfs_root_xp;
     97    }
     98    else                                        // relative path
     99    {
     100        // use extended pointer on CWD inode
     101        root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
     102    }
    92103
    93104    // call the relevant VFS function
    94     error = vfs_open( process,
     105    error = vfs_open( root_inode_xp,
    95106                      kbuf,
     107                      ref_xp,
    96108                      flags,
    97109                      mode,
    98110                      &file_xp,
    99111                      &file_id );
    100 
    101     // release the cwd lock
    102     remote_rwlock_rd_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    103112
    104113    if( error )
  • trunk/kernel/syscalls/sys_opendir.c

    r473 r610  
    22 * sys_opendir.c - open a directory.
    33 *
    4  * Author        Alain Greiner (2016,2017)
     4 * Author        Alain Greiner (2016,2017,2018)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2323
    2424#include <hal_kernel_types.h>
     25#include <hal_uspace.h>
    2526#include <thread.h>
    2627#include <process.h>
     
    3536                  DIR  ** dirp )
    3637{
    37     printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__, pathname, dirp );
    38     return -1;
    39 }  // end sys opendir()
     38    error_t       error;
     39    vseg_t      * vseg;                   // for user space checking
     40    xptr_t        root_inode_xp;          // extended pointer on path root inode
     41
     42    char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
     43       
     44        thread_t  * this    = CURRENT_THREAD;
     45        process_t * process = this->process;
     46
     47#if (DEBUG_SYS_OPENDIR || CONFIG_INSTRUMENTATION_SYSCALLS)
     48uint64_t     tm_start = hal_get_cycles();
     49#endif
     50
     51    // check DIR buffer in user space
     52    error = vmm_get_vseg( process , (intptr_t)dirp, &vseg );
     53
     54        if( error )
     55        {
     56
     57#if DEBUG_SYSCALLS_ERROR
     58printk("\n[ERROR] in %s / thread[%x,%x] : DIR buffer %x unmapped\n",
     59__FUNCTION__ , process->pid , this->trdid, dirp );
     60vmm_display( process , false );
     61#endif
     62                this->errno = EINVAL;
     63                return -1;
     64        }       
     65
     66    // check pathname length
     67    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
     68    {
     69
     70#if DEBUG_SYSCALLS_ERROR
     71printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long\n",
     72 __FUNCTION__ , process->pid , this->trdid );
     73#endif
     74        this->errno = ENFILE;
     75        return -1;
     76    }
     77
     78    // copy pathname in kernel space
     79    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     80
     81#if DEBUG_SYS_OPENDIR
     82if( DEBUG_SYS_OPENDIR < tm_start )
     83printk("\n[%s] thread[%x,%x] enter for directory <%s> / cycle %d\n",
     84__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start );
     85#endif
     86
     87    // compute root inode for path
     88    if( kbuf[0] == '/' )                        // absolute path
     89    {
     90        // use extended pointer on VFS root inode
     91        root_inode_xp = process->vfs_root_xp;
     92    }
     93    else                                        // relative path
     94    {
     95        // get cluster and local pointer on reference process
     96        xptr_t      ref_xp  = process->ref_xp;
     97        process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     98        cxy_t       ref_cxy = GET_CXY( ref_xp );
     99
     100        // use extended pointer on CWD inode
     101        root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
     102    }
     103
     104/*
     105    // call the relevant VFS function ???
     106    error = vfs_opendir( root_inode_xp,
     107                         kbuf );
     108    if( error )
     109        {
     110
     111#if DEBUG_SYSCALLS_ERROR
     112printk("\n[ERROR] in %s / thread[%x,%x] : cannot open directory <%s>\n",
     113__FUNCTION__ , process->pid , this->trdid , pathname );
     114#endif
     115                this->errno = ENFILE;
     116                return -1;
     117        }
     118   
     119    // copy to user space ???
     120*/
     121
     122    hal_fence();
     123
     124#if (DEBUG_SYS_OPENDIR || CONFIG_INSTRUMENTATION_SYSCALLS)
     125uint64_t     tm_end = hal_get_cycles();
     126#endif
     127
     128#if DEBUG_SYS_OPENDIR
     129if( DEBUG_SYS_OPENDIR < tm_end )
     130printk("\n[%s] thread[%x,%x] exit for directory <%s> / cycle %d\n",
     131__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end );
     132#endif
     133 
     134#if CONFIG_INSTRUMENTATION_SYSCALLS
     135hal_atomic_add( &syscalls_cumul_cost[SYS_OPENDIR] , tm_end - tm_start );
     136hal_atomic_add( &syscalls_occurences[SYS_OPENDIR] , 1 );
     137#endif
     138
     139        return 0;
     140
     141}  // end sys_opendir()
  • trunk/kernel/syscalls/sys_read.c

    r604 r610  
    7878#if DEBUG_SYS_READ
    7979if( DEBUG_SYS_READ < tm_start )
    80 printk("\n[DBG] %s : thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n",
     80printk("\n[%s] thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n",
    8181__FUNCTION__, process->pid, this->trdid, vaddr, count, (uint32_t)tm_start );
    8282#endif
     
    246246#if DEBUG_SYS_READ
    247247if( DEBUG_SYS_READ < tm_end )
    248 printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n",
     248printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
    249249__FUNCTION__ , process->pid, this->trdid, (uint32_t)tm_end );
    250250#endif
  • trunk/kernel/syscalls/sys_stat.c

    r604 r610  
    11/*
    2  * sys_stat.c - Return statistics on a file or directory.
     2 * sys_stat.c - kernel function implementing the "stat" syscall.
    33 *
    44 * Author    Alain Greiner  (2016,2017,2018)
     
    4141    vseg_t      * vseg;                   // for user space checking
    4242    struct stat   k_stat;                 // in kernel space
    43     xptr_t        inode_xp;               // extended pointer on target inode
     43    xptr_t        root_inode_xp;          // extended pointer on path root inode
    4444
    4545    char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
     
    5959
    6060#if DEBUG_SYSCALLS_ERROR
    61 printk("\n[ERROR] in %s / thread[%x,%x] : stat structure unmapped\n",
    62 __FUNCTION__ , process->pid , this->trdid );
     61printk("\n[ERROR] in %s / thread[%x,%x] : stat structure %x unmapped\n",
     62__FUNCTION__ , process->pid , this->trdid, u_stat );
    6363vmm_display( process , false );
    6464#endif
     
    8888#endif
    8989
    90     // get cluster and local pointer on reference process
    91     xptr_t      ref_xp  = process->ref_xp;
    92     process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
    93     cxy_t       ref_cxy = GET_CXY( ref_xp );
     90    // compute root inode for path
     91    if( kbuf[0] == '/' )                        // absolute path
     92    {
     93        // use extended pointer on VFS root inode
     94        root_inode_xp = process->vfs_root_xp;
     95    }
     96    else                                        // relative path
     97    {
     98        // get cluster and local pointer on reference process
     99        xptr_t      ref_xp  = process->ref_xp;
     100        process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     101        cxy_t       ref_cxy = GET_CXY( ref_xp );
    94102
    95     // get extended pointer on cwd inode
    96     xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
    97 
    98     // get the cwd lock in read mode from reference process
    99     remote_rwlock_rd_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    100 
    101     // get extended pointer on remote file descriptor
    102     error = vfs_lookup( cwd_xp,
    103                         kbuf,
    104                         0,
    105                         &inode_xp );
    106 
    107     // release the cwd lock
    108     remote_rwlock_rd_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    109 
    110     if( error )
    111     {
    112 
    113 #if DEBUG_SYSCALLS_ERROR
    114 printk("\n[ERROR] in %s / thread[%x,%x] : cannot found file <%s>\n",
    115 __FUNCTION__ , process->pid , this->trdid , pathname );
    116 #endif
    117         this->errno = ENFILE;
    118         return -1;
     103        // use extended pointer on CWD inode
     104        root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
    119105    }
    120106
    121 #if (DEBUG_SYS_STAT & 1)
    122 if( DEBUG_SYS_STAT < tm_start )
    123 printk("\n[%s] thread[%x,%x] got inode %x in cluster %x for <%s>\n",
    124 __FUNCTION__, process->pid, this->trdid, GET_PTR(inode_xp), GET_CXY(inode_xp), kbuf );
    125 #endif
    126 
    127     // call VFS function to get stat info
    128     error = vfs_stat( inode_xp,
    129                       &k_stat );
     107    // call the relevant VFS function
     108    error = vfs_stat( root_inode_xp,
     109                      kbuf,
     110                      &k_stat );
    130111    if( error )
    131112        {
     
    139120        }
    140121   
    141 #if (DEBUG_SYS_STAT & 1)
    142 if( DEBUG_SYS_STAT < tm_start )
    143 printk("\n[%s] thread[%x,%x] set kstat : inum %d / size %d / mode %d\n",
    144 __FUNCTION__, process->pid, this->trdid, k_stat.st_ino, k_stat.st_size, k_stat.st_mode );
    145 #endif
    146 
    147122    // copy k_stat to u_stat
    148123    hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) );
  • trunk/kernel/syscalls/sys_unlink.c

    r604 r610  
    11/*
    2  * sys_unlink.c - file unlink a file
     2 * sys_unlink.c - unlink a file or directorya from VFS
    33 *
    44 * Author     Alain Greiner (2016,2017,2018)
     
    3737{
    3838    error_t   error;
     39    xptr_t    root_inode_xp;           // extended pointer on path root inode
     40
    3941    char      kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4042
     
    6668#endif
    6769 
    68     // get cluster and local pointer on reference process
    69     xptr_t      ref_xp  = process->ref_xp;
    70     process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
    71     cxy_t       ref_cxy = GET_CXY( ref_xp );
     70    // compute root inode for path
     71    if( kbuf[0] == '/' )                        // absolute path
     72    {
     73        // use extended pointer on VFS root inode
     74        root_inode_xp = process->vfs_root_xp;
     75    }
     76    else                                        // relative path
     77    {
     78        // get cluster and local pointer on reference process
     79        xptr_t      ref_xp  = process->ref_xp;
     80        process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     81        cxy_t       ref_cxy = GET_CXY( ref_xp );
    7282
    73     // get the cwd lock in write mode from reference process
    74     remote_rwlock_wr_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     83        // use extended pointer on CWD inode
     84        root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) );
     85    }
    7586
    76     // get extended pointer on cwd inode
    77     xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
    78 
    79     // call relevant VFS function
    80     error  = vfs_unlink( cwd_xp , kbuf );
    81 
    82     // release the cwd lock in reference process
    83     remote_rwlock_wr_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     87    // call the relevant VFS function
     88    error  = vfs_unlink( root_inode_xp , kbuf );
    8489
    8590    if( error )
  • trunk/kernel/syscalls/sys_write.c

    r604 r610  
    7777tm_start = hal_get_cycles();
    7878if( DEBUG_SYS_WRITE < tm_start )
    79 printk("\n[DBG] %s : thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n",
     79printk("\n[%s] thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n",
    8080__FUNCTION__, process->pid, this->trdid, vaddr, count, (uint32_t)tm_start );
    8181#endif
     
    223223#if DEBUG_SYS_WRITE
    224224if( DEBUG_SYS_WRITE < tm_end )
    225 printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n",
     225printk("\n[%s] thread[%x,%x] exit / cycle %d\n",
    226226__FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end );
    227227#endif
  • trunk/kernel/syscalls/syscalls.h

    r594 r610  
    170170
    171171/******************************************************************************************
    172  * [10] This function implement the exit system call terminating a POSIX process.
    173  * It can be called by any thread running in any cluster.
    174  * It uses both remote accesses to access the owner process descriptor, and the
    175  * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors.
    176  * In the present implementation, this function implements actually the _exit():
    177  * - it does not flush open output streams.
    178  * - it does not close open streams.
    179  ******************************************************************************************
    180  * @ status   : terminaison status (not used in present implementation).
    181  *****************************************************************************************/
    182 int sys_exit( uint32_t status );
     172 * [10] This function causes the file named <old> to be renamed as <new>.
     173 * If new exists, it is first removed.  Both old and new must be of the same type (both
     174 * must be either directories or non-directories) and must reside on the same file system.
     175 * It guarantees that an instance of <new> will always exist, even if the system should
     176 * crash in the middle of the operation.
     177 ******************************************************************************************
     178 * @ old      : old file name.
     179 * @ new      : new file name.
     180 * @ return 0 if success / return -1 if failure.
     181 *****************************************************************************************/
     182int sys_rename( char *old,
     183                char *new );
    183184
    184185/******************************************************************************************
     
    301302
    302303/******************************************************************************************
    303  * [21] This function creates a new directory in file system.
    304  ******************************************************************************************
    305  * @ pathname   : pathname (can be relative or absolute).
    306  * @ mode       : access rights (as defined in chmod).
    307  * @ return 0 if success / returns -1 if failure.
    308  *****************************************************************************************/
    309 int sys_mkdir( char    * pathname,
    310                uint32_t  mode );
     304 * [21] This function implements the "mkdir" system call, creating a new directory in
     305 * the file system, as defined by the <pathname> argument, with the access permission
     306 * defined by the <rights> argument. All nodes but the last in the pathname must exist.
     307 * It can be called by any thread running in any cluster.
     308 ******************************************************************************************
     309 * @ pathname  : pathname defining the new directory location in file system.
     310 * @ rights    : access rights (non used yet).
     311 * @ return 0 if success / return -1 if failure.
     312 *****************************************************************************************/
     313int sys_mkdir( char     * pathname,
     314               uint32_t   rights );
    311315
    312316/******************************************************************************************
     
    653657               uint32_t * is_fg );
    654658
     659/******************************************************************************************
     660 * [50] This function implements the exit system call terminating a POSIX process.
     661 * It can be called by any thread running in any cluster.
     662 * It uses both remote accesses to access the owner process descriptor, and the
     663 * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors.
     664 * In the present implementation, this function implements actually the _exit():
     665 * - it does not flush open output streams.
     666 * - it does not close open streams.
     667 ******************************************************************************************
     668 * @ status   : terminaison status.
     669 *****************************************************************************************/
     670int sys_exit( uint32_t status );
     671
    655672#endif  // _SYSCALLS_H_
Note: See TracChangeset for help on using the changeset viewer.