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

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

File:
1 edited

Legend:

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

    r513 r606  
    11/*
    2  * mapper.h - Map memory, file or device in process virtual address space.
     2 * mapper.h - Kernel cache for FS files or directories definition.
    33 *
    44 * Authors   Mohamed Lamine Karaoui (2015)
     
    7272        struct vfs_inode_s * inode;           /*! owner inode                                     */
    7373    uint32_t             type;        /*! file system type                                */
    74         grdxt_t              radix;           /*! pages cache implemented as a radix tree         */
    75         rwlock_t             lock;        /*! several readers / only one writer               */
     74        grdxt_t              rt;              /*! embedded pages cache descriptor (radix tree)    */
     75        remote_rwlock_t      lock;        /*! several readers / only one writer               */
    7676        uint32_t                 refcount;    /*! several vsegs can refer the same file           */
    7777        xlist_entry_t        vsegs_root;  /*! root of list of vsegs refering this mapper      */
     
    109109
    110110/*******************************************************************************************
    111  * This function releases all physical pages allocated for the mapper.
    112  * It synchronizes all dirty pages (i.e. update the file on disk) if required.
    113  * The mapper descriptor and the radix tree themselves are released.
     111 * This function releases all physical memory allocated for a mapper.
     112 * Both the mapper descriptor and the radix tree are released.
     113 * It does NOT synchronize dirty pages. Use the vfs_sync_inode() function if required.
    114114 * It must be executed by a thread running in the cluster containing the mapper.
    115115 *******************************************************************************************
    116116 * @ mapper      : target mapper.
    117  * @ return 0 if success / return EIO if a dirty page cannot be updated on device.
    118  ******************************************************************************************/
    119 error_t mapper_destroy( mapper_t * mapper );
    120 
    121 /*******************************************************************************************
    122  * This function move data between a mapper and a - possibly distributed - user buffer.
    123  * It must be called by a thread running in the cluster containing the mapper.
    124  * It is called by the vfs_user_move() function to implement sys_read() and sys_write().
     117 ******************************************************************************************/
     118void mapper_destroy( mapper_t * mapper );
     119
     120/*******************************************************************************************
     121 * This function load from device a missing page identified by the <page_id> argument
     122 * into the mapper identified by the <mapper> local pointer.
     123 * It allocates a physical page from the local cluster, initialise by accessing device,
     124 * and register the page in the mapper radix tree.
     125 * It must be executed by a thread running in the cluster containing the mapper.
     126 * WARNING : the calling function mapper_remote_get_page() is supposed to take and release
     127 * the lock protecting the mapper in WRITE_MODE.
     128 *******************************************************************************************
     129 * @ mapper      : [in]  target mapper.
     130 * @ page_id : [in]  missing page index in file.
     131 * @ page_xp : [out] buffer for extended pointer on missing page descriptor.
     132 * @ return 0 if success / return -1 if a dirty page cannot be updated on device.
     133 ******************************************************************************************/
     134error_t mapper_handle_miss( mapper_t * mapper,
     135                            uint32_t   page_id,
     136                            xptr_t   * page_xp );
     137
     138/*******************************************************************************************
     139 * This function move data between a local mapper, and a distributed user buffer.
     140 * It must be called by a thread running in cluster containing the mapper.
     141 * It is called by the vfs_user_move() to implement sys_read() and sys_write() syscalls.
    125142 * If required, the data transfer is split in "fragments", where one fragment contains
    126143 * contiguous bytes in the same mapper page.
    127144 * It uses "hal_uspace" accesses to move a fragment to/from the user buffer.
    128145 * In case of write, the dirty bit is set for all pages written in the mapper.
    129  * The offset in the file descriptor is not modified by this function.
     146 * The mapper being an extendable cache, it is automatically extended when required
     147 * for both read and write accesses.
     148 * The "offset" field in the file descriptor, and the "size" field in inode descriptor
     149 * are not modified by this function.
    130150 *******************************************************************************************
    131151 * @ mapper       : local pointer on mapper.
     
    134154 * @ u_buf        : user space pointer on user buffer.
    135155 * @ size         : number of bytes to move.
    136  * returns O if success / returns EINVAL if error.
     156 * returns O if success / returns -1 if error.
    137157 ******************************************************************************************/
    138158error_t mapper_move_user( mapper_t * mapper,
     
    142162                          uint32_t   size );
    143163
    144 /*******************************************************************************************
    145  * This function move data between a mapper and a remote kernel buffer.
    146  * It must be called by a thread running in the cluster containing the mapper.
     164/********************************************************************************************
     165 * This function move data between a remote mapper and a remote kernel buffer.
     166 * It can be called by a thread running any cluster.
    147167 * If required, the data transfer is split in "fragments", where one fragment contains
    148168 * contiguous bytes in the same mapper page.
    149169 * It uses a "remote_memcpy" to move a fragment to/from the kernel buffer.
    150170 * In case of write, the dirty bit is set for all pages written in the mapper.
    151  * The offset in the file descriptor is not modified by this function.
    152  *******************************************************************************************
    153  * @ mapper       : local pointer on mapper.
     171 *******************************************************************************************
     172 * @ mapper_xp    : extended pointer on mapper.
    154173 * @ to_buffer    : mapper -> buffer if true / buffer -> mapper if false.
    155174 * @ file_offset  : first byte to move in file.
    156175 * @ buffer_xp    : extended pointer on kernel buffer.
    157176 * @ size         : number of bytes to move.
    158  * returns O if success / returns EINVAL if error.
    159  ******************************************************************************************/
    160 error_t mapper_move_kernel( mapper_t * mapper,
     177 * returns O if success / returns -1 if error.
     178 ******************************************************************************************/
     179error_t mapper_move_kernel( xptr_t     mapper_xp,
    161180                            bool_t     to_buffer,
    162181                            uint32_t   file_offset,
     
    164183                            uint32_t   size );
    165184
    166 
    167 /*******************************************************************************************
    168  * This function removes a physical page from the mapper, update the FS if the page
    169  * is dirty, and releases the page to PPM. It is called by the mapper_destroy() function.
    170  * It must be executed by a thread running in the cluster containing the mapper.
    171  * It takes both the page lock and the mapper lock in WRITE_MODE to release the page.
     185/*******************************************************************************************
     186 * This function removes a physical page from the mapper, and releases
     187 * the page to the local PPM. It is called by the mapper_destroy() function.
     188 * It must be executed by a thread running in the cluster containing the mapper.
     189 * It takes the mapper lock in WRITE_MODE to update the mapper.
    172190 *******************************************************************************************
    173191 * @ mapper     : local pointer on the mapper.
    174192 * @ page       : pointer on page to remove.
    175  * @ return 0 if success / return EIO if a dirty page cannot be copied to FS.
    176  ******************************************************************************************/
    177 error_t mapper_release_page( mapper_t      * mapper,
    178                              struct page_s * page );
    179 
    180 /*******************************************************************************************
    181  * This function searches a physical page descriptor from its index in mapper.
    182  * It must be executed by a thread running in the cluster containing the mapper.
     193 ******************************************************************************************/
     194void mapper_release_page( mapper_t      * mapper,
     195                          struct page_s * page );
     196
     197/*******************************************************************************************
     198 * This function returns an extended pointer on a mapper page, identified by <page_id>,
     199 * index in the file. The - possibly remote - mapper is identified by the <mapper_xp>
     200 * argument.  It can be executed by a thread running in any cluster, as it uses remote
     201 * access primitives to scan the mapper.
     202 * In case of miss, this function takes the mapper lock in WRITE_MODE, and call the
     203 * mapper_handle_miss() to load the missing page from device to mapper, using an RPC
     204 * when the mapper is remote.
     205 *******************************************************************************************
     206 * @ mapper_xp  : extended pointer on the mapper.
     207 * @ page_id    : page index in file
     208 * @ returns extended pointer on page base if success / return XPTR_NULL if error.
     209 ******************************************************************************************/
     210xptr_t mapper_remote_get_page( xptr_t    mapper_xp,
     211                               uint32_t  page_id );
     212
     213/*******************************************************************************************
     214 * This function allows to read a single word in a mapper seen as and array of uint32_t.
     215 * It has bee designed to support remote access tho the FAT mapper of the FATFS.
     216 * It can be called by any thread running in any cluster.
    183217 * In case of miss, it takes the mapper lock in WRITE_MODE, load the missing
    184  * page from device to the mapper, and release the mapper lock.
    185  *******************************************************************************************
    186  * @ mapper     : local pointer on the mapper.
    187  * @ index      : page index in file
    188  * @ returns pointer on page descriptor if success / return NULL if error.
    189  ******************************************************************************************/
    190 struct page_s * mapper_get_page( mapper_t * mapper,
    191                                  uint32_t   index );
    192 
    193  
     218 * page from device to mapper, and release the mapper lock.
     219 *******************************************************************************************
     220 * @ mapper_xp  : [in]  extended pointer on the mapper.
     221 * @ index          : [in]  32 bits word index in file.
     222 * @ p_value    : [out] local pointer on destination buffer.
     223 * @ returns 0 if success / return -1 if error.
     224 ******************************************************************************************/
     225error_t mapper_remote_get_32( xptr_t     mapper_xp,
     226                              uint32_t   word_id,
     227                              uint32_t * p_value );
     228
     229/*******************************************************************************************
     230 * This function allows to write a single word to a mapper seen as and array of uint32_t.
     231 * It has bee designed to support remote access tho the FAT mapper of the FATFS.
     232 * It can be called by any thread running in any cluster.
     233 * In case of miss, it takes the mapper lock in WRITE_MODE, load the missing
     234 * page from device to mapper, and release the mapper lock.
     235 *******************************************************************************************
     236 * @ mapper_xp  : [in]  extended pointer on the mapper.
     237 * @ index          : [in]  32 bits word index in file.
     238 * @ p_value    : [in]  value to be written.
     239 * @ returns 0 if success / return -1 if error.
     240 ******************************************************************************************/
     241error_t mapper_remote_set_32( xptr_t     mapper_xp,
     242                              uint32_t   word_id,
     243                              uint32_t   value );
    194244
    195245#endif /* _MAPPER_H_ */
Note: See TracChangeset for help on using the changeset viewer.