Changeset 304 for trunk/kernel


Ignore:
Timestamp:
Jul 31, 2017, 2:42:36 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_mkfifo.c

    r23 r304  
    11/*
    22 * sys_mkfifo.c - creates a named FIFO file.
    3  * 
     3 *
    44 * Author    Alain Greiner (2016,2017)
    55 *
     
    3434{
    3535    error_t        error;
    36     uint32_t       length;                           // pathname length (bytes)
    3736    char           kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    3837
    3938    thread_t  * this    = CURRENT_THREAD;
    40         process_t * process = this->process;
    41 
    42         if( pathname == NULL )
    43         {
    44         printk("\n[ERROR] in %s : pathname is NULL\n", __FUNCTION__ );
    45                 this->errno = EINVAL;
    46                 return -1;
    47         }       
     39    process_t * process = this->process;
    4840
    4941    // check fd_array not full
    50         if( process_fd_array_full() )
    51         {
     42    if( process_fd_array_full() )
     43    {
    5244        printk("\n[ERROR] in %s : file descriptor array full for process %x\n",
    5345               __FUNCTION__ , process->pid );
    54                 this->errno = ENFILE;
     46        this->errno = ENFILE;
    5547        return -1;
    56         }
    57    
    58     // get pathname length
    59     length = hal_strlen_from_uspace( pathname );
     48    }
    6049
    61     if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
     50    // get pathname copy in kernel space
     51    error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
     52
     53    if( error )
    6254    {
    6355        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
    64                 this->errno = ENFILE;
     56        this->errno = ENFILE;
    6557        return -1;
    6658    }
    67  
    68         // get pathname copy in kernel space
    69     hal_copy_from_uspace( kbuf, pathname, length );
    7059
    7160    // get cluster and local pointer on reference process
     
    7665    // get extended pointer on cwd inode
    7766    xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
    78    
     67
    7968    // get the cwd lock in read mode from reference process
    80         remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     69    remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    8170
    8271    // call the relevant VFS function
    83         error = vfs_mkfifo( cwd_xp,
     72    error = vfs_mkfifo( cwd_xp,
    8473                        kbuf,
    8574                        mode );
    8675
    8776    // release the cwd lock
    88         remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     77    remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    8978
    9079    if( error )
    91         {
     80    {
    9281        printk("\n[ERROR] in %s : cannot create named FIFO %s\n",
    9382               __FUNCTION__ , kbuf );
    94                 this->errno = error;
    95                 return -1;
    96         }
    97    
    98         return 0;
     83        this->errno = error;
     84        return -1;
     85    }
     86
     87    return 0;
    9988
    10089} // end sys_mkfifo()
Note: See TracChangeset for help on using the changeset viewer.