Ignore:
Timestamp:
Dec 6, 2019, 12:07:51 PM (5 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.