Changeset 265 for trunk/kernel/mm


Ignore:
Timestamp:
Jul 21, 2017, 7:36:08 AM (4 years ago)
Author:
alain
Message:

Fix several bugs in VFS.

Location:
trunk/kernel/mm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/mm/mapper.c

    r246 r265  
    169169        if ( page == NULL )   // missing page => create it and load it from file system
    170170        {
    171             mapper_dmsg("\n[INFO] %s : missing page => load from FS\n", __FUNCTION__ );
     171            mapper_dmsg("\n[INFO] %s : missing page => load from device\n", __FUNCTION__ );
    172172
    173173            // allocate one page from PPM
     
    298298}  // end mapper_release_page()
    299299
    300 /////////////////////////////////////////
    301 error_t mapper_move( mapper_t  *  mapper,
    302                      bool_t       to_buffer,
    303                      uint32_t     file_offset,
    304                      void      *  buffer,
    305                      uint32_t     size )
     300////////////////////////////////////////////////
     301error_t mapper_move_buffer( mapper_t  *  mapper,
     302                            bool_t       to_buffer,
     303                            bool_t       is_user,
     304                            uint32_t     file_offset,
     305                            void      *  buffer,
     306                            uint32_t     size )
    306307{
    307308    uint32_t   page_offset;    // first byte to move to/from a mapper page
     
    313314    uint8_t  * buf_ptr;        // current buffer  address
    314315 
    315     mapper_dmsg("\n[INFO] %s : enter / to_buf = %d / buffer = %x\n",
     316    mapper_dmsg("\n[INFO] %s : enters / to_buf = %d / buffer = %x\n",
    316317                __FUNCTION__ , to_buffer , buffer );
    317318
     
    339340        else                       page_count = CONFIG_PPM_PAGE_SIZE;
    340341
     342        mapper_dmsg("\n[INFO] %s : index = %d / offset = %d / count = %d\n",
     343                    __FUNCTION__ , index , page_offset , page_count );
     344
    341345        // get page descriptor
    342346        page = mapper_get_page( mapper , index );
     
    350354        buf_ptr = (uint8_t *)buffer + done;
    351355
     356        mapper_dmsg("\n[INFO] %s : index = %d / buf_ptr = %x / map_ptr = %x\n",
     357                    __FUNCTION__ , index , buf_ptr , map_ptr );
     358
    352359        // move fragment
    353360        if( to_buffer )
    354361        {
    355             hal_copy_to_uspace( buf_ptr , map_ptr , page_count );
    356         }
    357         else
     362            if( is_user ) hal_copy_to_uspace( buf_ptr , map_ptr , page_count );
     363            else          memcpy( buf_ptr , map_ptr , page_count );
     364        }
     365        else                 
    358366        {
    359367            page_do_dirty( page );
    360             hal_copy_from_uspace( map_ptr , buf_ptr , page_count );
     368            if( is_user ) hal_copy_from_uspace( map_ptr , buf_ptr , page_count );
     369            else          memcpy( map_ptr , buf_ptr , page_count );
    361370        }
    362371
     
    369378    return 0;
    370379
    371 }  // end mapper_move()
    372 
     380}  // end mapper_move_buffer()
     381
  • trunk/kernel/mm/mapper.h

    r246 r265  
    5151 * - The mapper_get_page() function that return a page descriptor pointer from a page
    5252 *   index in file is in charge of handling the miss on the mapper cache.
    53  * - The vfs_mapper_move_page() function is used to handle miss on one specific page,
     53 * - The vfs_mapper_move_page() function access the file system to handle a mapper miss,
    5454 *   or update a dirty page on device.
    55  * - The vfs_mapper_load_all() functions is used to load all pages of a given directory
    56  *   into the mapper.
    57  * - the mapper_move() function is used to move data to or from an user buffer.
     55 * - The vfs_mapper_load_all() functions is used to load all pages of a given file
     56 *   or directory into the mapper.
     57 * - the mapper_move_user() function is used to move data to or from an user buffer.
    5858 *   This user space buffer can be physically distributed in several clusters.
    5959 * - In the present implementation the cache size for a given file increases on demand,
     
    117117
    118118/*******************************************************************************************
    119  * This function move data between a kernel mapper and an user buffer.
     119 * This function move data between a mapper and an user or kernel buffer.
    120120 * It must be called by a thread running in the cluster containing the mapper.
    121  * It split the data in fragments : one fragment is a set of contiguous bytes
    122  * stored in the same mapper page. 
    123  * It uses "hal_uspace" accesses to move fragments to/from the user buffer.
     121 * - A kernel buffer must be entirely contained in the same cluster as the mapper.
     122 * - An user buffer can be physically distributed in several clusters.
     123 * In both cases, the data transfer is split in "fragments": one fragment contains
     124 * contiguous bytes in the same mapper page.
     125 * - It uses "hal_uspace" accesses to move a fragment to/from the user buffer.
     126 * - It uses a simple memcpy" access to move a fragment to/from a kernel buffer.
    124127 * In case of write, the dirty bit is set for all pages written in the mapper.
    125128 * The offset in the file descriptor is not modified by this function.
    126129 *******************************************************************************************
    127  * @ mapper       : local pointer on local mapper.
    128  * @ to_buffer    : move data from mapper to buffer if true.
     130 * @ mapper       : local pointer on mapper.
     131 * @ to_buffer    : mapper -> buffer if true / buffer -> mapper if false.
     132 * @ is_user      : user space buffer if true / kernel local buffer if false.
    129133 * @ file_offset  : first byte to move in file.
    130  * @ buffer       : buffer address in user space.
     134 * @ buffer       : pointer on buffer (local kernel buffer or user spaceaddress in user space.
    131135 * @ size         : number of bytes to move.
    132136 * returns O if success / returns EINVAL if error.
    133137 ******************************************************************************************/
    134 error_t mapper_move( mapper_t * mapper,
    135                      bool_t     to_buffer,
    136                      uint32_t   file_offset,
    137                      void     * buffer,
    138                      uint32_t   size );
     138error_t mapper_move_buffer( mapper_t * mapper,
     139                            bool_t     to_buffer,
     140                            bool_t     is_user,
     141                            uint32_t   file_offset,
     142                            void     * buffer,
     143                            uint32_t   size );
    139144
    140145/*******************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.