Changeset 604 for trunk/kernel/syscalls


Ignore:
Timestamp:
Dec 3, 2018, 12:18:40 PM (6 years ago)
Author:
alain
Message:

Improve the FAT32 file system to support cat, rm, cp commands.

Location:
trunk/kernel/syscalls
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/shared_include/shared_pthread.h

    r581 r604  
    9898/*******************************************************************************************
    9999 * These typedef and enum define the shared informations related to POSIX barriers.
     100 * The following struct is NOT used in the current implementation or the POSIX barrier
     101 * that is based on a - non scalable - single shared variable.
     102 * It can be used by another implementation, based on a distributed quadtree implemented
     103 * in user space, and relying on a busy waiting policy.
    100104 ******************************************************************************************/
    101105
  • trunk/kernel/syscalls/sys_open.c

    r599 r604  
    117117
    118118#if DEBUG_SYS_OPEN
    119 if( DEBUG_SYS_OPEN < tm_start )
     119if( DEBUG_SYS_OPEN < tm_end )
    120120printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n",
    121121__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end );
  • trunk/kernel/syscalls/sys_read.c

    r594 r604  
    5656              uint32_t   count )
    5757{
    58     error_t      error;
    59     vseg_t     * vseg;        // required for user space checking
    60         xptr_t       file_xp;     // remote file extended pointer
    61     uint32_t     nbytes;      // number of bytes actually read
    62     reg_t        save_sr;     // required to enable IRQs during syscall
    63 
    64         thread_t  *  this             = CURRENT_THREAD;
    65         process_t *  process          = this->process;
    66     xptr_t       process_owner_xp = process->owner_xp;
     58    error_t       error;
     59    vseg_t      * vseg;            // required for user space checking
     60        xptr_t        file_xp;         // remote file extended pointer
     61    vfs_file_t  * file_ptr;        // remote file local pointer
     62    cxy_t         file_cxy;        // remote file cluster identifier
     63    uint32_t      file_type;       // file type
     64    uint32_t      file_offset;     // current file offset
     65    uint32_t      file_attr;       // file_attribute
     66    vfs_inode_t * inode_ptr;       // local pointer on associated inode
     67    uint32_t      nbytes;          // number of bytes actually read
     68    reg_t         save_sr;         // required to enable IRQs during syscall
     69
     70        thread_t    * this             = CURRENT_THREAD;
     71        process_t   * process          = this->process;
     72    xptr_t        process_owner_xp = process->owner_xp;
    6773 
    6874#if (DEBUG_SYS_READ || CONFIG_INSTRUMENTATION_SYSCALLS)
     
    8591
    8692#if DEBUG_SYSCALLS_ERROR
    87 printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index = %d\n",
     93printk("\n[ERROR] in %s : thread[%x,%x] illegal file descriptor index %d\n",
    8894__FUNCTION__ , process->pid, this->trdid, file_id );
    8995#endif
     
    107113    }
    108114
     115    // get extended pointer on remote file descriptor
     116    file_xp = process_fd_get_xptr( process , file_id );
     117
     118    if( file_xp == XPTR_NULL )
     119    {
     120
     121#if DEBUG_SYSCALLS_ERROR
     122printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",
     123__FUNCTION__, process->pid, this->trdid, file_id );
     124#endif
     125        this->errno = EBADFD;
     126        return -1;
     127    }
     128
     129    // get file descriptor cluster and local pointer
     130    file_ptr = GET_PTR( file_xp );
     131    file_cxy = GET_CXY( file_xp );
     132
     133    // get file type, offset, attributes and associated inode
     134    file_type   = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
     135    file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
     136    inode_ptr   = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
     137    file_attr   = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) );
     138
    109139    // enable IRQs
    110140    hal_enable_irq( &save_sr );
    111141
    112     // get extended pointer on remote file descriptor
    113     file_xp = process_fd_get_xptr( process , file_id );
    114 
    115     if( file_xp == XPTR_NULL )
    116     {
    117 
    118 #if DEBUG_SYSCALLS_ERROR
    119 printk("\n[ERROR] in %s : thread[%x,%x] undefined fd_id %d\n",
    120 __FUNCTION__, process->pid, this->trdid, file_id );
    121 #endif
    122         this->errno = EBADFD;
    123         return -1;
    124     }
    125 
    126     // get file descriptor cluster and local pointer
    127     vfs_file_t * file_ptr = GET_PTR( file_xp );
    128     cxy_t        file_cxy = GET_CXY( file_xp );
    129 
    130     // get file type
    131     vfs_inode_type_t type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
    132 
    133142    // action depend on file type
    134     if( type == INODE_TYPE_FILE )      // check file readable & read from mapper
     143    if( file_type == INODE_TYPE_FILE )      // read from file mapper
    135144    {
    136145        // check file readable
    137         uint32_t attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) );
    138 
    139         if( (attr & FD_ATTR_READ_ENABLE) == 0 )
     146        if( (file_attr & FD_ATTR_READ_ENABLE) == 0 )
    140147            {
    141148
     
    144151__FUNCTION__, process->pid, this->trdid, file_id );
    145152#endif
     153            hal_restore_irq( save_sr );
    146154                    this->errno = EBADFD;
    147155                    return -1;
     
    153161                                vaddr,
    154162                                count );
    155     }
    156     else if( type == INODE_TYPE_DEV )  // check ownership & read from device
     163        if( nbytes != count )
     164        {
     165
     166#if DEBUG_SYSCALLS_ERROR
     167printk("\n[ERROR] in %s : thread[%x,‰x] cannot read %d bytes from file %d\n",
     168__FUNCTION__, process->pid, this->trdid, count, file_id );
     169#endif
     170            this->errno = EIO;
     171            hal_restore_irq( save_sr );
     172            return -1;
     173        }
     174    }
     175    else if( file_type == INODE_TYPE_DEV )  // read from TXT device
    157176    {
    158177        // get cluster and pointers on TXT_RX chdev
     
    192211                                  vaddr,
    193212                                  count );
    194 
    195     }
    196     else    // not FILE and not DEV
    197     {
    198 
    199 #if DEBUG_SYSCALLS_ERROR
    200 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
    201 __FUNCTION__, vfs_inode_type_str( type ) );
    202 #endif
    203                 this->errno = EBADFD;
    204                 return -1;
    205     }
    206 
    207     if( nbytes != count )
    208     {
     213        if( nbytes != count )
     214        {
    209215
    210216#if DEBUG_SYSCALLS_ERROR
     
    212218__FUNCTION__, process->pid, this->trdid, file_id );
    213219#endif
    214         this->errno = EIO;
    215         return -1;
     220            this->errno = EIO;
     221            hal_restore_irq( save_sr );
     222            return -1;
     223        }
     224    }
     225    else    // not FILE and not DEV
     226    {
     227
     228#if DEBUG_SYSCALLS_ERROR
     229printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
     230__FUNCTION__, vfs_inode_type_str( file_type ) );
     231#endif
     232                this->errno = EBADFD;
     233        hal_restore_irq( save_sr );
     234                return -1;
    216235    }
    217236
  • trunk/kernel/syscalls/sys_rmdir.c

    r566 r604  
    3636int sys_rmdir( char * pathname )
    3737{
    38     error_t     error;
     38    // error_t     error;
    3939    char        kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
    4040       
     
    4545    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    4646    {
    47         printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     47
     48#if DEBUG_SYSCALLS_ERROR
     49printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     50#endif
    4851        this->errno = ENFILE;
    4952        return -1;
     
    5962
    6063    // get extended pointer on cwd inode
    61     xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
     64    // xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) );
    6265   
    6366    // get the cwd lock in write mode from reference process
     
    6568
    6669    // call the relevant VFS function
    67         error = vfs_rmdir( cwd_xp,
    68                        kbuf );
     70        printk("\n[ERROR] in %s : non implemented yet\n", __FUNCTION__ );
    6971
    7072    // release the cwd lock
    7173        remote_rwlock_wr_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );
    7274
    73     if( error )
    74         {
    75         printk("\n[ERROR] in %s : cannot remove directory %s\n",
    76                __FUNCTION__ , kbuf );
    77                 this->errno = error;
    78                 return -1;
    79         }
    80    
    8175        return 0;
    8276
  • trunk/kernel/syscalls/sys_stat.c

    r594 r604  
    156156#if DEBUG_SYS_STAT
    157157if( DEBUG_SYS_STAT < tm_end )
    158 printk("\n[%s] thread[%x,%x] exit for file <%s> / cycle %d\n",
    159 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end );
     158printk("\n[%s] thread[%x,%x] exit for file <%s> / size %d / mode %d / cycle %d\n",
     159__FUNCTION__, process->pid, this->trdid, kbuf,
     160k_stat.st_size, k_stat.st_mode, (uint32_t)tm_end );
    160161#endif
    161162 
  • trunk/kernel/syscalls/sys_unlink.c

    r566 r604  
    11/*
    2  * sys_unlink.c - file unlink
     2 * sys_unlink.c - file unlink a file
    33 *
    4  * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
    5  * Copyright (c) 2011,2012 UPMC Sorbonne Universites
     4 * Author     Alain Greiner (2016,2017,2018)
     5 *
     6 * Copyright (c)  UPMC Sorbonne Universites
    67 *
    78 * This file is part of ALMOS-kernel.
    89 *
    9  * 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
    1011 * under the terms of the GNU General Public License as published by
    1112 * the Free Software Foundation; version 2.0 of the License.
    1213 *
    13  * 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
    1415 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1516 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    1718 *
    1819 * You should have received a copy of the GNU General Public License
    19  * 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,
    2021 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2122 */
    2223
     24#include <kernel_config.h>
    2325#include <hal_kernel_types.h>
    2426#include <hal_uspace.h>
     27#include <errno.h>
    2528#include <vfs.h>
    2629#include <process.h>
     
    3942    process_t    * process  = this->process;
    4043
     44#if (DEBUG_SYS_UNLINK || CONFIG_INSTRUMENTATION_SYSCALLS)
     45uint64_t     tm_start = hal_get_cycles();
     46#endif
     47
    4148    // check pathname length
    4249    if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH )
    4350    {
    44         printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     51
     52#if DEBUG_SYSCALLS_ERROR
     53printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ );
     54#endif
    4555        this->errno = ENFILE;
    4656        return -1;
     
    5060    hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH );
    5161
     62#if DEBUG_SYS_UNLINK
     63if( DEBUG_SYS_UNLINK < tm_start )
     64printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n",
     65__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start );
     66#endif
     67 
    5268    // get cluster and local pointer on reference process
    5369    xptr_t      ref_xp  = process->ref_xp;
     
    6985    if( error )
    7086    {
    71         printk("\n[ERROR] in %s : cannot unlink file/dir %s\n",
    72                __FUNCTION__ , pathname );
     87
     88#if DEBUG_SYSCALLS_ERROR
     89printk("\n[ERROR] in %s : cannot unlink file/dir %s\n", __FUNCTION__, kbuf );
     90#endif
    7391        this->errno = ENFILE;
    7492        return -1;
    7593    }
    7694
     95#if (DEBUG_SYS_UNLINK || CONFIG_INSTRUMENTATION_SYSCALLS)
     96uint64_t     tm_end = hal_get_cycles();
     97#endif
     98
     99#if DEBUG_SYS_UNLINK
     100if( DEBUG_SYS_UNLINK < tm_end )
     101printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n",
     102__FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end );
     103#endif
     104 
     105#if CONFIG_INSTRUMENTATION_SYSCALLS
     106hal_atomic_add( &syscalls_cumul_cost[SYS_UNLINK] , tm_end - tm_start );
     107hal_atomic_add( &syscalls_occurences[SYS_UNLINK] , 1 );
     108#endif
     109
    77110    return 0;
    78111
  • trunk/kernel/syscalls/sys_write.c

    r594 r604  
    5555               uint32_t   count )
    5656{
    57     error_t      error;
    58     vseg_t     * vseg;            // required for user space checking
    59         xptr_t       file_xp;         // remote file extended pointer
    60     uint32_t     nbytes;          // number of bytes actually written
    61     reg_t        save_sr;         // required to enable IRQs during syscall
    62 
    63         thread_t   * this = CURRENT_THREAD;
    64         process_t  * process = this->process;
     57    error_t       error;
     58    vseg_t      * vseg;            // required for user space checking
     59        xptr_t        file_xp;         // remote file extended pointer
     60    vfs_file_t  * file_ptr;        // remote file local pointer
     61    cxy_t         file_cxy;        // remote file cluster identifier
     62    uint32_t      file_type;       // file type
     63    uint32_t      file_offset;     // current file offset
     64    uint32_t      file_attr;       // file_attribute
     65    vfs_inode_t * inode_ptr;       // local pointer on associated inode
     66    uint32_t      nbytes;          // number of bytes actually written
     67    reg_t         save_sr;         // required to enable IRQs during syscall
     68
     69        thread_t    * this = CURRENT_THREAD;
     70        process_t   * process = this->process;
    6571
    6672#if (DEBUG_SYS_WRITE || CONFIG_INSTRUMENTATION_SYSCALLS)
     
    113119
    114120#if DEBUG_SYSCALLS_ERROR
    115 printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor index = %d\n",
     121printk("\n[ERROR] in %s : thread[%x,%x] undefined file descriptor = %d\n",
    116122__FUNCTION__, process->pid, this->trdid, file_id );
    117123#endif
     
    121127
    122128    // get file descriptor cluster and local pointer
    123     vfs_file_t * file_ptr = (vfs_file_t *)GET_PTR( file_xp );
    124     cxy_t        file_cxy = GET_CXY( file_xp );
    125 
    126  
    127     // get file type
    128     vfs_inode_type_t type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
     129    file_ptr = GET_PTR( file_xp );
     130    file_cxy = GET_CXY( file_xp );
     131
     132    // get file type, offset, aatributes, and associated inode
     133    file_type   = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
     134    file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
     135    inode_ptr   = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );
     136    file_attr   = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) );
    129137
    130138    // enable IRQs
     
    132140
    133141   // action depend on file type
    134     if( type == INODE_TYPE_FILE )  // check file writable & write to mapper
     142    if( file_type == INODE_TYPE_FILE )  // write to file mapper
    135143    {
    136144        // check file writable
    137         uint32_t attr = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) );
    138         if( (attr & FD_ATTR_WRITE_ENABLE) == 0 )
     145        if( (file_attr & FD_ATTR_WRITE_ENABLE) == 0 )
    139146            {
    140147
     
    143150__FUNCTION__ , process->pid, this->trdid, file_id );
    144151#endif
     152            hal_restore_irq( save_sr );
    145153                    this->errno = EBADFD;
    146154                    return -1;
     
    152160                                vaddr,
    153161                                count );
    154     }
    155     else if( type == INODE_TYPE_DEV )  // write to TXT device
     162        if ( nbytes != count )
     163        {
     164
     165#if DEBUG_SYSCALLS_ERROR
     166printk("\n[ERROR] in %s : thread[%x,%x] cannot write %d bytes into file %d\n",
     167__FUNCTION__ , process->pid, this->trdid, count, file_id );
     168#endif
     169            hal_restore_irq( save_sr );
     170            this->errno = EIO;
     171            return -1;
     172
     173        }
     174
     175        // update size field in inode if required
     176        xptr_t   size_xp    = XPTR( file_cxy , &inode_ptr->size );
     177        uint32_t inode_size = hal_remote_l32( size_xp );
     178        if ( (file_offset + count) > inode_size )
     179        {
     180            hal_remote_s32( size_xp , file_offset + count );
     181        }
     182    }
     183    else if( file_type == INODE_TYPE_DEV )  // write to TXT device
    156184    {
    157185        // move count bytes to device
    158186        nbytes = devfs_user_move( false,             // from buffer to device
    159                                  file_xp,
    160                                  vaddr,
    161                                  count );
    162     }
    163     else  // not FILE and not DEV
    164     {
    165 
    166 #if DEBUG_SYSCALLS_ERROR
    167 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
    168 __FUNCTION__, vfs_inode_type_str( type ) );
    169 #endif
    170                 this->errno = EBADFD;
    171                 return -1;
    172     }
    173 
    174     if( nbytes != count )
    175     {
     187                                  file_xp,
     188                                  vaddr,
     189                                  count );
     190        if( nbytes != count )
     191        {
    176192
    177193#if DEBUG_SYSCALLS_ERROR
     
    179195__FUNCTION__ , process->pid, this->trdid, file_id );
    180196#endif
    181         this->errno = EIO;
    182         return -1;
     197            hal_restore_irq( save_sr );
     198            this->errno = EIO;
     199            return -1;
     200        }
     201    }
     202    else  // not FILE and not DEV
     203    {
     204
     205#if DEBUG_SYSCALLS_ERROR
     206printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
     207__FUNCTION__, vfs_inode_type_str( file_type ) );
     208#endif
     209        hal_restore_irq( save_sr );
     210                this->errno = EBADFD;
     211                return -1;
    183212    }
    184213
Note: See TracChangeset for help on using the changeset viewer.