Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (5 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

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

    r11 r23  
    11/*
    2  * sys_chmod: change file mode
     2 * sys_chmod.c - Change file access rights.
    33 *
     4 * Author    Alain Greiner  (2016,2017)
     5 *
    46 * Copyright (c) 2015 UPMC Sorbonne Universites
    57 *
    6  * This file is part of ALMOS-kernel.
     8 * This file is part of ALMOS-MKH.
    79 *
    8  * ALMOS-kernel is free software; you can redistribute it and/or modify it
     10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    911 * under the terms of the GNU General Public License as published by
    1012 * the Free Software Foundation; version 2.0 of the License.
    1113 *
    12  * ALMOS-kernel is distributed in the hope that it will be useful, but
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1315 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1416 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    1618 *
    1719 * You should have received a copy of the GNU General Public License
    18  * along with ALMOS-kernel; if not, write to the Free Software Foundation,
     20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
    1921 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2022 */
    2123
    22 #include <cpu.h>
    23 #include <chdev.h>
    24 #include <driver.h>
    25 #include <rwlock.h>
     24#include <hal_types.h>
     25#include <hal_uspace.h>
    2626#include <vfs.h>
    27 #include <sys-vfs.h>
     27#include <vmm.h>
     28#include <printk.h>
    2829#include <thread.h>
    29 #include <ku_transfert.h>
    30 #include <task.h>
     30#include <process.h>
    3131
    32 int sys_chmod (char *pathname, uint_t mode)
     32//////////////////////////////////
     33int sys_chmod( char    * pathname,
     34               uint32_t  rights )
    3335{
    34         register error_t err = 0;
    35         register struct thread_s *this;
    36         register struct task_s *task;
    37         struct ku_obj ku_path;
     36    error_t     error;
     37    paddr_t     paddr;
     38    uint32_t    length;
     39    char        kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
     40       
     41        thread_t  * this    = CURRENT_THREAD;
     42        process_t * process = this->process;
    3843
    39         this = current_thread;
    40         task = current_task;
     44    // check pathname in user space
     45    error = vmm_v2p_translate( false , pathname , &paddr );
    4146
    42         if(!pathname || NOT_IN_USPACE(pathname))
     47        if( error )
    4348        {
    44                 this->info.errno = EINVAL;
     49        printk("\n[ERROR] in %s : user pathname unmapped for thread %x in process %x\n",
     50               __FUNCTION__ , this->trdid , process->pid );
     51                this->errno = EINVAL;
    4552                return -1;
    4653        }       
    47        
    48      
    49         KU_BUFF(ku_path, pathname);
    50         rwlock_wrlock(&task->cwd_lock);
    51        
    52         if((err = vfs_chmod(&ku_path, &task->vfs_cwd, mode)))
     54
     55    // get pathname length
     56    length = hal_strlen_from_uspace( pathname );
     57
     58    if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
     59    {
     60        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     61                this->errno = ENFILE;
     62        return -1;
     63    }
     64 
     65        // get pathname copy in kernel space
     66    hal_copy_from_uspace( kbuf, pathname, length );
     67
     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 );
     72
     73    // get extended pointer on cwd inode
     74    xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
     75   
     76    // get the cwd lock in read mode from reference process
     77        remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     78
     79    // call the relevant VFS function
     80        error = vfs_chmod( cwd_xp,
     81                       kbuf,
     82                       rights );
     83
     84    // release the cwd lock
     85        remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     86
     87    if( error )
    5388        {
    54                 rwlock_unlock(&task->cwd_lock);
    55                 this->info.errno = (err < 0) ? -err : err;
     89        printk("\n[ERROR] in %s : cannot remove directory %s\n",
     90               __FUNCTION__ , kbuf );
     91                this->errno = error;
    5692                return -1;
    5793        }
    5894   
    59         rwlock_unlock(&task->cwd_lock);
    6095        return 0;
    61 }
     96
     97}  // end sys_chmod()   
Note: See TracChangeset for help on using the changeset viewer.