Ignore:
Timestamp:
Oct 10, 2020, 5:11:27 PM (4 years ago)
Author:
alain
Message:
  • Introduce the sys_socket.c file implementing all socket related syscalls.
  • Improve the non-standard sys_get_config() function.
File:
1 edited

Legend:

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

    r625 r664  
    22 * sys_close.c  close an open file
    33 *
    4  * Author    Alain Greiner (2016,2017)
     4 * Author    Alain Greiner (2016,2017,2018,2019,2020)
    55 *
    66 * Copyright (c) UPMC Sorbonne Universites
     
    2828#include <process.h>
    2929#include <thread.h>
     30#include <ksocket.h>
    3031#include <printk.h>
    3132
    3233#include <syscalls.h>
    3334
    34 //////////////////////////////////
    35 int sys_close ( uint32_t file_id )
     35///////////////////////////////
     36int sys_close ( uint32_t fdid )
    3637{
    3738    error_t            error;
     
    5152if( DEBUG_SYS_CLOSE < tm_start )
    5253printk("\n[%s] thread[%x,%x] enter / fdid %d / cycle %d\n",
    53 __FUNCTION__, process->pid, this->trdid, file_id, (uint32_t)tm_start );
     54__FUNCTION__, process->pid, this->trdid, fdid, (uint32_t)tm_start );
    5455#endif
    5556 
    56     // check file_id argument
    57         if( file_id >= CONFIG_PROCESS_FILE_MAX_NR )
     57    // check fdid argument
     58        if( fdid >= CONFIG_PROCESS_FILE_MAX_NR )
    5859        {
    5960
    6061#if DEBUG_SYSCALLS_ERROR
    6162printk("\n[ERROR] in %s : illegal file descriptor index = %d\n",
    62 __FUNCTION__ , file_id );
     63__FUNCTION__ , fdid );
    6364#endif
    6465                this->errno = EBADFD;
     
    6768
    6869    // get extended pointer on remote file descriptor
    69     file_xp = process_fd_get_xptr( process , file_id );
     70    file_xp = process_fd_get_xptr_from_local( process , fdid );
    7071
    7172    if( file_xp == XPTR_NULL )
     
    7475#if DEBUG_SYSCALLS_ERROR
    7576printk("\n[ERROR] in %s : undefined file descriptor %d\n",
    76 __FUNCTION__ , file_id );
     77__FUNCTION__ , fdid );
    7778#endif
    7879        this->errno = EBADFD;
     
    9091#if DEBUG_SYSCALLS_ERROR
    9192printk("\n[ERROR] in %s : file descriptor %d is a directory\n",
    92 __FUNCTION__ , file_id );
     93__FUNCTION__ , fdid );
    9394#endif
    9495                this->errno = EBADFD;
    9596                return -1;
    9697        }
    97 
    98     // call the relevant VFS function
    99         error = vfs_close( file_xp , file_id );
     98    else if( file_type == INODE_TYPE_SOCK )
     99    {
     100        // call the relevant socket function
     101        error = socket_close( file_xp , fdid );
     102    }
     103    else if( file_type == INODE_TYPE_FILE )
     104    {
     105        // call the relevant VFS function
     106            error = vfs_close( file_xp , fdid );
     107    }
     108    else
     109    {
     110           
     111#if DEBUG_SYSCALLS_ERROR
     112printk("\n[WARNING] in %s : type (%d) not supported  / fdid %d\n",
     113__FUNCTION__ , file_type , fdid );
     114#endif
     115        error = 0;       
     116    }
    100117
    101118        if( error )
     
    104121#if DEBUG_SYSCALLS_ERROR
    105122printk("\n[ERROR] in %s : cannot close file descriptor %d\n",
    106 __FUNCTION__ , file_id );
     123__FUNCTION__ , fdid );
    107124#endif
    108125                this->errno = error;
Note: See TracChangeset for help on using the changeset viewer.