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_unlink.c

    r1 r23  
    11/*
    2  * kern/sys_unlink.c - file unlink
     2 * sys_unlink.c - file unlink
    33 *
    44 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
     
    2121 */
    2222
     23#include <hal_types.h>
     24#include <hal_uspace.h>
    2325#include <vfs.h>
    24 #include <sys-vfs.h>
    25 #include <task.h>
     26#include <process.h>
    2627#include <thread.h>
     28#include <printk.h>
    2729
    28 int sys_unlink (char *pathname)
     30//////////////////////////////////
     31int sys_unlink ( char * pathname )
    2932{
    30         error_t err = 0;
    31         struct ku_obj ku_path;
     33        error_t   error;
     34    uint32_t  length;
     35    char      kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    3236
    33         KU_BUFF(ku_path, pathname);
    34         if((err = vfs_unlink(&current_task->vfs_cwd, &ku_path)))
     37        thread_t     * this     = CURRENT_THREAD;
     38        process_t    * process  = this->process;
     39
     40    // get pathname length
     41    length = hal_strlen_from_uspace( pathname );
     42
     43    if( length >= CONFIG_VFS_MAX_PATH_LENGTH )
     44    {
     45        printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     46                this->errno = ENFILE;
     47        return -1;
     48    }
     49 
     50        // get pathname copy in kernel space
     51    hal_copy_from_uspace( kbuf, pathname, length );
     52
     53    // get cluster and local pointer on reference process
     54    xptr_t      ref_xp  = process->ref_xp;
     55    process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     56    cxy_t       ref_cxy = GET_CXY( ref_xp );
     57
     58    // get the cwd lock in read mode from reference process
     59        remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     60
     61    // get extended pointer on cwd inode
     62    xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
     63
     64    // call relevant VFS function
     65    error  = vfs_unlink( cwd_xp , kbuf );
     66
     67    // release the cwd lock in reference process
     68        remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
     69
     70        if( error )
    3571        {
    36                 current_thread->info.errno = (err < 0) ? -err : err;
    37                 return -1;
     72        printk("\n[ERROR] in %s : cannot unlink file/dir %s\n",
     73               __FUNCTION__ , pathname );
     74                this->errno = ENFILE;
     75            return -1;
    3876        }
    39  
     77
    4078        return 0;
    41 }
     79
     80} // end sys_unlink()
Note: See TracChangeset for help on using the changeset viewer.