Changeset 656 for trunk/kernel/syscalls


Ignore:
Timestamp:
Dec 6, 2019, 12:07:51 PM (4 years ago)
Author:
alain
Message:

Fix several bugs in the FATFS and in the VFS,
related to the creation of big files requiring
more than 4 Kbytes (one cluster) on device.

Location:
trunk/kernel/syscalls
Files:
3 edited

Legend:

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

    r640 r656  
    300300            xptr_t        mapper_xp;
    301301            mapper_t    * mapper_ptr;
     302            xptr_t        page_xp;
    302303
    303304            char          kbuf[CONFIG_VFS_MAX_PATH_LENGTH];
     
    315316 __FUNCTION__ );
    316317#endif
    317                 this->errno = ENFILE;
    318                 return -1;
    319             }
    320 
     318                this->errno = EINVAL;
     319                return -1;
     320            }
     321
     322            // check nbytes
     323            if( nbytes >= 4096 )
     324            {
     325
     326#if DEBUG_SYSCALLS_ERROR
     327printk("\n[ERROR] in %s for MAPPER : nbytes cannot be larger than 4096\n",
     328 __FUNCTION__ );
     329#endif
     330                this->errno = EINVAL;
     331                return -1;
     332            }
     333           
    321334            // copy pathname in kernel space
    322335            hal_strcpy_from_uspace( XPTR( local_cxy , kbuf ),
     
    366379            mapper_xp  = XPTR( inode_cxy , mapper_ptr );
    367380
    368             // display mapper
    369             error = mapper_display_page( mapper_xp , page_id , nbytes );
    370 
    371             if( error )
     381            // get extended pointer on target page
     382            page_xp = mapper_remote_get_page( mapper_xp , page_id );
     383
     384            if( page_xp == XPTR_NULL )
    372385                {
    373386
    374387#if DEBUG_SYSCALLS_ERROR
    375 printk("\n[ERROR] in %s for MAPPER : cannot display page %d\n",
     388printk("\n[ERROR] in %s for MAPPER : cannot get page %d\n",
    376389__FUNCTION__ , page_id );
    377390#endif
     
    379392                        return -1;
    380393                }
     394
     395            // display mapper
     396            mapper_display_page( mapper_xp , page_xp , nbytes );
     397
    381398
    382399            break;
     
    463480                uint32_t page = (uint32_t)arg0;
    464481
    465                 fatfs_display_fat( page , entries );
     482                fatfs_display_fat( page , 0 , entries );
    466483            }
    467484
  • trunk/kernel/syscalls/sys_read.c

    r635 r656  
    6363    cxy_t         file_cxy;        // remote file cluster identifier
    6464    uint32_t      file_type;       // file type
    65     uint32_t      file_attr;       // file_attribute
     65    uint32_t      file_offset;     // file offset
     66    uint32_t      file_attr;       // file attributes
     67    vfs_inode_t * inode_ptr;       // local pointer on file inode
    6668    uint32_t      nbytes;          // number of bytes actually read
    6769    reg_t         save_sr;         // required to enable IRQs during syscall
     
    129131    file_cxy = GET_CXY( file_xp );
    130132
    131     // get file type and attributes
    132     file_type   = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) );
    133     file_attr   = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr ) );
     133    // get inode, file type, offset and attributes
     134    inode_ptr   = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode  ) );
     135    file_type   = hal_remote_l32( XPTR( file_cxy , &file_ptr->type   ) );
     136    file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );
     137    file_attr   = hal_remote_l32( XPTR( file_cxy , &file_ptr->attr   ) );
    134138
    135139    // enable IRQs
    136140    hal_enable_irq( &save_sr );
    137141
    138     // action depend on file type
     142    // action depend on file type:
     143
    139144    if( file_type == INODE_TYPE_FILE )      // read from file mapper
    140145    {
     
    152157            }
    153158
    154         // move count bytes from mapper
     159        // try to move count bytes from mapper
    155160        nbytes = vfs_user_move( true,               // from mapper to buffer
    156161                                file_xp,
    157162                                vaddr,
    158163                                count );
    159         if( nbytes != count )
    160         {
    161 
    162 #if DEBUG_SYSCALLS_ERROR
    163 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read %d bytes from file %d\n",
    164 __FUNCTION__, process->pid, this->trdid, count, file_id );
    165 #endif
    166             this->errno = EIO;
    167             hal_restore_irq( save_sr );
    168             return -1;
    169         }
    170164    }
    171165    else if( file_type == INODE_TYPE_DEV )  // read from TXT device
     
    184178            txt_owner_xp  = hal_remote_l64( XPTR( chdev_cxy , &chdev_ptr->ext.txt.owner_xp ) );
    185179
    186             // check TXT_RX ownership
     180            // wait for TXT_RX ownership
    187181            if ( process_owner_xp != txt_owner_xp )
    188182            {
     
    202196        }
    203197
    204         // move count bytes from device
     198        // try to move count bytes from TXT device
    205199        nbytes = devfs_user_move( true,             // from device to buffer
    206200                                  file_xp,
    207201                                  vaddr,
    208202                                  count );
    209         if( nbytes != count )
    210         {
    211 
    212 #if DEBUG_SYSCALLS_ERROR
    213 printk("\n[ERROR] in %s : thread[%x,‰x] cannot read data from file %d\n",
    214 __FUNCTION__, process->pid, this->trdid, file_id );
    215 #endif
    216             this->errno = EIO;
    217             hal_restore_irq( save_sr );
    218             return -1;
    219         }
    220203    }
    221204    else    // not FILE and not DEV
     
    229212        hal_restore_irq( save_sr );
    230213                return -1;
     214    }
     215
     216    // check error
     217    if( nbytes == 0xFFFFFFFF )
     218    {
     219
     220#if DEBUG_SYSCALLS_ERROR
     221printk("\n[ERROR] in %s : thread[%x,‰x] cannot read data from file %d\n",
     222__FUNCTION__, process->pid, this->trdid, file_id );
     223#endif
     224        this->errno = EIO;
     225        hal_restore_irq( save_sr );
     226        return -1;
    231227    }
    232228
  • trunk/kernel/syscalls/sys_write.c

    r635 r656  
    6262    cxy_t         file_cxy;        // remote file cluster identifier
    6363    uint32_t      file_type;       // file type
    64     uint32_t      file_offset;     // current file offset
    65     uint32_t      file_attr;       // file_attribute
     64    uint32_t      file_offset;     // file offset
     65    uint32_t      file_attr;       // file attributes
    6666    vfs_inode_t * inode_ptr;       // local pointer on associated inode
    6767    uint32_t      nbytes;          // number of bytes actually written
     
    138138    hal_enable_irq( &save_sr );
    139139
    140     // action depend on file type
     140    // action depend on file type:
     141
    141142    if( file_type == INODE_TYPE_FILE )  // write to a file mapper
    142143    {
     
    159160                                vaddr,
    160161                                count );
    161         if ( nbytes != count )
    162         {
    163 
    164 #if DEBUG_SYSCALLS_ERROR
    165 printk("\n[ERROR] in %s : thread[%x,%x] cannot write %d bytes into file %d\n",
    166 __FUNCTION__ , process->pid, this->trdid, count, file_id );
    167 #endif
    168             hal_restore_irq( save_sr );
    169             this->errno = EIO;
    170             return -1;
    171 
    172         }
    173 
    174         // update file size in inode descriptor
    175         // only if (file_offset + count) > current_size
    176         // note: the parent directory entry in mapper will
    177         // be updated by the close syscall     
    178         xptr_t inode_xp = XPTR( file_cxy , inode_ptr );
    179         vfs_inode_update_size( inode_xp , file_offset + count );
    180162    }
    181163    else if( file_type == INODE_TYPE_DEV )  // write to TXT device
     
    186168                                  vaddr,
    187169                                  count );
    188         if( nbytes != count )
    189         {
     170    }
     171    else  // not FILE and not DEV
     172    {
     173
     174#if DEBUG_SYSCALLS_ERROR
     175printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
     176__FUNCTION__, vfs_inode_type_str( file_type ) );
     177#endif
     178        hal_restore_irq( save_sr );
     179                this->errno = EBADFD;
     180                return -1;
     181    }
     182
     183    // chek error
     184    if( nbytes == 0xFFFFFFFF )
     185    {
    190186
    191187#if DEBUG_SYSCALLS_ERROR
     
    193189__FUNCTION__ , process->pid, this->trdid, file_id );
    194190#endif
    195             hal_restore_irq( save_sr );
    196             this->errno = EIO;
    197             return -1;
    198         }
    199     }
    200     else  // not FILE and not DEV
    201     {
    202 
    203 #if DEBUG_SYSCALLS_ERROR
    204 printk("\n[ERROR] in %s : thread[%x,%x] / illegal inode type %\n",
    205 __FUNCTION__, vfs_inode_type_str( file_type ) );
    206 #endif
    207191        hal_restore_irq( save_sr );
    208                 this->errno = EBADFD;
    209                 return -1;
     192        this->errno = EIO;
     193        return -1;
    210194    }
    211195
Note: See TracChangeset for help on using the changeset viewer.