Changeset 303 for trunk/kernel/syscalls


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

Style, and use hal_strcpy_from_uspace.

File:
1 edited

Legend:

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

    r23 r303  
    11/*
    22 * sys_mkdir.c - Create a new directory
    3  * 
     3 *
    44 * Author    Alain Greiner (2016,2017)
    55 *
     
    3535               uint32_t   mode )
    3636{
    37         error_t        error;
    38     paddr_t        paddr;
    39     uint32_t       length;
     37    error_t        error;
    4038    char           kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4139
    42         thread_t     * this     = CURRENT_THREAD;
    43         process_t    * process  = this->process;
     40    thread_t     * this     = CURRENT_THREAD;
     41    process_t    * process  = this->process;
    4442
    45     // check pathname in user space
    46     error = vmm_v2p_translate( false , pathname , &paddr );
    47 
    48         if( error )
    49         {
    50         printk("\n[ERROR] in %s : user buffer unmapped  for thread %x in process %x\n",
    51                __FUNCTION__ , this->trdid , process->pid );
    52                 this->errno = EINVAL;
    53                 return -1;
    54         }       
    55      
    5643    // check fd_array not full
    57         if( process_fd_array_full() )
    58         {
     44    if( process_fd_array_full() )
     45    {
    5946        printk("\n[ERROR] in %s : file descriptor array full for process %x\n",
    6047               __FUNCTION__ , process->pid );
    61                 this->errno = ENFILE;
     48        this->errno = ENFILE;
    6249        return -1;
    63         }
    64    
    65     // get pathname length
    66     length = hal_strlen_from_uspace( pathname );
     50    }
    6751
    68     if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
     52    // get pathname copy in kernel space
     53    error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     54
     55    if( error )
    6956    {
    7057        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
    71                 this->errno = ENFILE;
     58        this->errno = ENFILE;
    7259        return -1;
    7360    }
    74  
    75         // get pathname copy in kernel space
    76     hal_copy_from_uspace( kbuf, pathname, length );
    7761
    7862    // get cluster and local pointer on reference process
     
    8367    // get extended pointer on cwd inode
    8468    xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
    85    
     69
    8670    // get the cwd lock in read mode from reference process
    87         remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     71    remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    8872
    8973    // call the relevant VFS function
    90         error = vfs_mkdir( cwd_xp,
     74    error = vfs_mkdir( cwd_xp,
    9175                       kbuf,
    9276                       mode );
    9377
    9478    // release the cwd lock
    95         remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     79    remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    9680
    9781    if( error )
    98         {
     82    {
    9983        printk("\n[ERROR] in %s : cannot create directory %s\n",
    10084               __FUNCTION__ , kbuf );
    101                 this->errno = error;
    102                 return -1;
    103         }
    104    
    105         return 0;
     85        this->errno = error;
     86        return -1;
     87    }
     88
     89    return 0;
    10690}
Note: See TracChangeset for help on using the changeset viewer.