Changeset 305 for trunk/kernel


Ignore:
Timestamp:
Jul 31, 2017, 2:46:50 PM (7 years ago)
Author:
max@…
Message:

Style, and use hal_strcpy_from_uspace.

Location:
trunk/kernel/syscalls
Files:
3 edited

Legend:

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

    r23 r305  
    11/*
    22 * sys_open.c - open a file.
    3  * 
     3 *
    44 * Author        Alain Greiner (2016,2017)
    55 *
     
    3838               uint32_t   mode )
    3939{
    40 
    41         error_t        error;
    42         xptr_t         file_xp;                          // extended pointer on vfs_file_t
    43         uint32_t       file_id;                          // file descriptor index
    44     uint32_t       length;                           // pathname length (bytes)
     40    error_t        error;
     41    xptr_t         file_xp;                          // extended pointer on vfs_file_t
     42    uint32_t       file_id;                          // file descriptor index
    4543    char           kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4644
    47         thread_t     * this     = CURRENT_THREAD;
    48         process_t    * process  = this->process;
    49 
    50         if( pathname == NULL )
    51         {
    52         printk("\n[ERROR] in %s : pathname is NULL\n", __FUNCTION__ );
    53                 this->errno = EINVAL;
    54                 return -1;
    55         }       
     45    thread_t     * this     = CURRENT_THREAD;
     46    process_t    * process  = this->process;
    5647
    5748    // check fd_array not full
    58         if( process_fd_array_full() )
    59         {
     49    if( process_fd_array_full() )
     50    {
    6051        printk("\n[ERROR] in %s : file descriptor array full for process %x\n",
    6152               __FUNCTION__ , process->pid );
    62                 this->errno = ENFILE;
     53        this->errno = ENFILE;
    6354        return -1;
    64         }
    65    
    66     // get pathname length
    67     length = hal_strlen_from_uspace( pathname );
     55    }
    6856
    69     if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
     57    // get pathname copy in kernel space
     58    error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     59
     60    if( error )
    7061    {
    7162        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
    72                 this->errno = ENFILE;
     63        this->errno = ENFILE;
    7364        return -1;
    7465    }
    75  
    76         // get pathname copy in kernel space
    77     hal_copy_from_uspace( kbuf, pathname, length );
    7866
    7967    // get cluster and local pointer on reference process
     
    8472    // get extended pointer on cwd inode
    8573    xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
    86    
     74
    8775    // get the cwd lock in read mode from reference process
    88         remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     76    remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    8977
    9078    // call the relevant VFS function
    91         error = vfs_open( cwd_xp,
     79    error = vfs_open( cwd_xp,
    9280                      kbuf,
    9381                      flags,
     
    9785
    9886    // release the cwd lock
    99         remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     87    remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    10088
    101         if( error )
    102         {
     89    if( error )
     90    {
    10391        printk("\n[ERROR] in %s : cannot create file descriptor\n", __FUNCTION__ );
    104                 this->errno = ENFILE;
    105             return -1;
    106         }
     92        this->errno = ENFILE;
     93        return -1;
     94    }
    10795
    10896    // update local fd_array
    10997    remote_spinlock_lock( XPTR( local_cxy , &process->fd_array.lock ) );
    110         process->fd_array.array[file_id] = file_xp;
     98    process->fd_array.array[file_id] = file_xp;
    11199    remote_spinlock_unlock( XPTR( local_cxy , &process->fd_array.lock ) );
    112100
    113         return file_id;
     101    return file_id;
    114102}
  • trunk/kernel/syscalls/sys_rmdir.c

    r23 r305  
    3535{
    3636    error_t     error;
    37     paddr_t     paddr;
    38     uint32_t    length;
    3937    char        kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4038       
     
    4240        process_t * process = this->process;
    4341
    44     // check pathname in user space
    45     error = vmm_v2p_translate( false , pathname , &paddr );
     42    // get pathname copy in kernel space
     43    error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    4644
    47         if( error )
    48         {
    49         printk("\n[ERROR] in %s : user buffer unmapped  for thread %x in process %x\n",
    50                __FUNCTION__ , this->trdid , process->pid );
    51                 this->errno = EINVAL;
    52                 return -1;
    53         }       
    54 
    55     // get pathname length
    56     length = hal_strlen_from_uspace( pathname );
    57 
    58     if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
     45    if( error )
    5946    {
    6047        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     
    6249        return -1;
    6350    }
    64  
    65         // get pathname copy in kernel space
    66     hal_copy_from_uspace( kbuf, pathname, length );
    6751
    6852    // get cluster and local pointer on reference process
  • trunk/kernel/syscalls/sys_unlink.c

    r23 r305  
    11/*
    22 * sys_unlink.c - file unlink
    3  * 
     3 *
    44 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
    55 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
     
    3131int sys_unlink ( char * pathname )
    3232{
    33         error_t   error;
    34     uint32_t  length;
     33    error_t   error;
    3534    char      kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    3635
    37         thread_t     * this     = CURRENT_THREAD;
    38         process_t    * process  = this->process;
     36    thread_t     * this     = CURRENT_THREAD;
     37    process_t    * process  = this->process;
    3938
    40     // get pathname length
    41     length = hal_strlen_from_uspace( pathname );
     39    // get pathname copy in kernel space
     40    error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    4241
    43     if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
     42    if( error )
    4443    {
    4544        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
    46                 this->errno = ENFILE;
     45        this->errno = ENFILE;
    4746        return -1;
    4847    }
    49  
    50         // get pathname copy in kernel space
    51     hal_copy_from_uspace( kbuf, pathname, length );
    5248
    5349    // get cluster and local pointer on reference process
     
    5753
    5854    // get the cwd lock in read mode from reference process
    59         remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     55    remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    6056
    6157    // get extended pointer on cwd inode
     
    6662
    6763    // release the cwd lock in reference process
    68         remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     64    remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    6965
    70         if( error )
    71         {
     66    if( error )
     67    {
    7268        printk("\n[ERROR] in %s : cannot unlink file/dir %s\n",
    7369               __FUNCTION__ , pathname );
    74                 this->errno = ENFILE;
    75             return -1;
    76         }
     70        this->errno = ENFILE;
     71        return -1;
     72    }
    7773
    78         return 0;
     74    return 0;
    7975
    8076} // end sys_unlink()
Note: See TracChangeset for help on using the changeset viewer.