Changeset 301 for trunk


Ignore:
Timestamp:
Jul 31, 2017, 2:30:23 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_chdir.c

    r23 r301  
    11/*
    22 * sys_chdir: change process current working directory
    3  * 
     3 *
    44 * Author    Alain Greiner (2016,2017)
    55 *
     
    3535int sys_chdir ( char * pathname )
    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;
     40    thread_t  * this    = CURRENT_THREAD;
    4341    process_t * process = this->process;
    4442
    45     // check pathname in user space
    46     error = vmm_v2p_translate( false , pathname , &paddr );
     43    // get pathname copy in kernel space
     44    error = hal_strcpy_from_uspace( kbuf, pathname, CONFIG_VFS_MAX_PATH_LENGTH );
    4745
    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      
    56     // get pathname length
    57     length = hal_strlen_from_uspace( pathname );
    58 
    59     if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
     46    if( error )
    6047    {
    6148        printk("\n[ERROR] in %s : pathname too long for thread %x in process %x\n",
    6249               __FUNCTION__ , this->trdid , process->pid );
    63                 this->errno = ENFILE;
     50        this->errno = ENFILE;
    6451        return -1;
    6552    }
    66  
    67         // get pathname copy in kernel space
    68     hal_copy_from_uspace( kbuf, pathname, length );
    6953
    7054    // get cluster and local pointer on reference process
     
    7559    // get extended pointer on cwd lock in reference process
    7660    xptr_t lock_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    77        
    78     // get cwd lock in read mode 
    79         remote_rwlock_rd_lock( lock_xp );
     61
     62    // get cwd lock in read mode
     63    remote_rwlock_rd_lock( lock_xp );
    8064
    8165    // call relevant VFS function
    82         error = vfs_chdir( process->vfs_cwd_xp , kbuf );
     66    error = vfs_chdir( process->vfs_cwd_xp , kbuf );
    8367
    84     // release cwd lock 
    85         remote_rwlock_rd_unlock( lock_xp );
     68    // release cwd lock
     69    remote_rwlock_rd_unlock( lock_xp );
    8670
    87         if( error )
    88         {
     71    if( error )
     72    {
    8973        printk("\n[ERROR] in %s : cannot change current directory\n", __FUNCTION__ );
    90                 this->errno = error;
    91                 return -1;
    92         }
    93    
    94         return 0;
     74        this->errno = error;
     75        return -1;
     76    }
     77
     78    return 0;
    9579}
Note: See TracChangeset for help on using the changeset viewer.