Ignore:
Timestamp:
Apr 29, 2019, 7:25:09 PM (5 years ago)
Author:
alain
Message:

This version has been tested on the sort multithreaded application
for TSAR_IOB architectures ranging from 1 to 8 clusters.
It fixes three bigs bugs:
1) the dev_ioc device API has been modified: the dev_ioc_sync_read()
and dev_ioc_sync_write() function use now extended pointers on the
kernel buffer to access a mapper stored in any cluster.
2) the hal_uspace API has been modified: the hal_copy_to_uspace()
and hal_copy_from_uspace() functions use now a (cxy,ptr) couple
to identify the target buffer (equivalent to an extended pointer.
3) an implementation bug has been fixed in the assembly code contained
in the hal_copy_to_uspace() and hal_copy_from_uspace() functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/fs/fatfs.h

    r625 r626  
    173173/*****************************************************************************************
    174174 * This structure defines a FATFS specific context (extension to VFS context).
    175  * This extension is replicated in all clusters.
    176  *
    177  * WARNING : Almost all fields are constant values, but the <free_cluster_hint> and
    178  * <free_clusters> are shared variables. All kernel instances use the variables
    179  * in cluster 0, using the <free_lock> remote busy_lock for exclusive access.
     175 * This fatfs context is replicated in all clusters.
     176 *
     177 * WARNING : Almost all fields are constant values, but the <free_cluster_hint>,
     178 * <free_clusters> and <free_lock> are shared variables. Moreover, the <fs_info_buffer>,
     179 * only allocated in cluster 0, contains a copy of the FS_INFO sector. It is used by all
     180 * kernel instances to synchronously update the free clusters info on IOC device.
     181 * For these four variables, all kernel instances must use the values in cluster 0,
     182 * and take the <free_lock> stored in this cluster for exclusive access to FAT.
    180183 ****************************************************************************************/
    181184
    182185typedef struct fatfs_ctx_s
    183186{
     187    /* read-only constants replicated in all clusters                                   */
    184188    uint32_t            fat_sectors_count;     /*! number of sectors in FAT region      */
    185189    uint32_t            bytes_per_sector;      /*! number of bytes per sector           */
     
    190194    uint32_t            root_dir_cluster;      /*! cluster index for  root directory    */
    191195    xptr_t              fat_mapper_xp;         /*! extended pointer on FAT mapper       */
     196
     197    /* shared variables (only the copy in FAT cluster must be used)                     */
    192198    uint32_t            free_cluster_hint;     /*! cluster[hint+1] is the first free    */
    193199    uint32_t            free_clusters;         /*! free clusters number                 */
    194     remote_queuelock_t  free_lock;             /*! exclusive access to hint & number    */
     200    remote_queuelock_t  free_lock;             /*! exclusive access to FAT              */
     201    uint8_t           * fs_info_buffer;        /*! local pointer on FS_INFO buffer      */
    195202}
    196203fatfs_ctx_t;
     
    224231
    225232/*****************************************************************************************
    226  * This function display the content of the local FATFS context.
    227  *****************************************************************************************
    228  * @ ctx  : local pointer on the context.
    229  ****************************************************************************************/
    230 void fatfs_ctx_display( fatfs_ctx_t * ctx );
    231 
    232 /*****************************************************************************************
    233  * This function displays the content of a part of the File Allocation Table.
    234  * It loads the requested page fom device to mapper if required.
    235  *****************************************************************************************
    236  * @ page_id   : page index in FAT mapper (one page is 4 Kbytes).
    237  * @ nentries  : number of entries (one entry is 4 bytes).
     233 * This function display the content of the FATFS context copy in cluster identified
     234 * by the <cxy> argument.
     235 * This function can be called by a thread running in any cluster.
     236 *****************************************************************************************
     237 * @ cxy       :  target cluster identifier.
     238 ****************************************************************************************/
     239void fatfs_display_ctx( cxy_t cxy );
     240
     241/*****************************************************************************************
     242 * This function access the FAT mapper to display one page of the File Allocation Table.
     243 * It loads the requested page fom IOC device to FAT mapper if required.
     244 * This function can be called by a thread running in any cluster.
     245 *****************************************************************************************
     246 * @ page_id     : page index in FAT mapper (one page is 4 Kbytes).
     247 * @ nb_entries  : number of entries (one entry is 4 bytes).
    238248 ****************************************************************************************/
    239249void fatfs_display_fat( uint32_t  page_id,
    240                         uint32_t  nentries );
     250                        uint32_t  nb_entries );
    241251
    242252
     
    254264
    255265/*****************************************************************************************
    256  * This function access the boot device, and initialises the local FATFS context
    257  * from informations contained in the boot record.
     266 * This function access the boot device, and initialises the local FATFS context,
     267 * from informations contained in the boot record. This initialisation includes the
     268 * creation of the FAT mapper in cluster 0.
    258269 *****************************************************************************************
    259270 * @ vfs_ctx   : local pointer on VFS context for FATFS.
     
    271282 * This function implements the generic vfs_fs_add_dentry() function for the FATFS.
    272283 *****************************************************************************************
    273  * This function updates a directory identified by the <inode> argument
     284 * This function updates a directory mapper identified by the <inode> argument
    274285 * to add a new directory entry identified by the <dentry> argument.
    275  * All modified pages in directory mapper are synchronously updated on IOC device.
    276  * It must be called by a thread running in the cluster containing the inode.
     286 * All modified pages in the directory mapper are synchronously updated on IOC device.
     287 * It must be called by a thread running in the cluster containing the directory inode.
    277288 *
    278289 * Implementation note : this function works in two steps:
     
    313324 * This function implements the generic vfs_fs_new_dentry() function for the FATFS.
    314325 *****************************************************************************************
    315  * It initializes a new inode/dentry couple in Inode Tree, attached to the directory
    316  * identified by the <parent_inode> argument. The directory entry is identified
    317  * by the <name> argument. The child inode descriptor, identified by the <child_inode_xp>
    318  * argument, and the associated dentry descriptor must have been previously allocated.
    319  * It scan the parent mapper to find the <name> argument.
    320  * It set the "type", "size", and "extend" fields in the child inode descriptor.
    321  * It set the " extend" field in the dentry descriptor.
     326 * It scan a parent directory mapper, identified by the <parent_inode> argument to find
     327 * a directory entry identified by the <name> argument.  In case of success, it
     328 * initializes the inode/dentry couple, identified by the  <child_inode_xp> argument
     329 * in the Inode Tree. The child inode descriptor, and the associated dentry descriptor
     330 * must have been previously allocated by the caller.
     331 * - It set the "type", "size", and "extend" fields in the child inode descriptor.
     332 * - It set the " extend" field in the dentry descriptor.
    322333 * It must be called by a thread running in the cluster containing the parent inode.
    323334 *****************************************************************************************
     
    325336 * @ name            : child name.
    326337 * @ child_inode_xp  : extended pointer on remote child inode (file or directory).
    327  * @ return 0 if success / return ENOENT if child not found.
     338 * @ return 0 if success / return -1 if child not found.
    328339 ****************************************************************************************/
    329340error_t fatfs_new_dentry( struct vfs_inode_s * parent_inode,
     
    392403 *****************************************************************************************
    393404 * @ inode   : local pointer on inode.
    394  * @ return 0 if success / return EIO if failure during device access.
     405 * @ return 0 if success / return -1 if failure during IOC device access.
    395406 ****************************************************************************************/
    396407error_t fatfs_sync_inode( struct vfs_inode_s * inode );
     
    399410 * This function implements the generic vfs_fs_sync_fat() function for the FATFS.
    400411 *****************************************************************************************
    401  * It updates the FATFS on the IOC device for the FAT itself.
     412 * It updates the FAT on the IOC device for the FAT itself.
    402413 * It scan all clusters registered in the FAT mapper, and copies from mapper to device
    403414 * each page marked as dirty.
     
    408419 *  variables defining the smallest/largest dirty page index in FAT mapper...
    409420 *****************************************************************************************
    410  * @ return 0 if success / return EIO if failure during device access.
     421 * @ return 0 if success / return -1 if failure during IOC device access.
    411422 ****************************************************************************************/
    412423error_t fatfs_sync_fat( void );
     
    415426 * This function implements the generic vfs_fs_sync_fsinfo() function for the FATFS.
    416427 *****************************************************************************************
    417  * It updates the FS_INFO sector on the IOC device.
    418  * It copies the <free_cluster_hint> and <free_clusters> variables from
    419  * the FATFS context in cluster 0 to the FS_INFO sector on device.
    420  *****************************************************************************************
    421  * @ return 0 if success / return EIO if failure during device access.
     428 * It checks the current values of the "free_clusters" and "free_cluster_hint" variables
     429 * in the FS_INFO sector on IOC, versus the values stored in the fatfs context.
     430 * As these values are synchronously updated on IOC device at each modification,
     431 * it does nothing if the values are equal. It updates the FS_INFO sector on IOC device,
     432 * and displays a warning message on TXT0 if they are not equal.
     433 * This function can be called by any thread running in any cluster.
     434 *****************************************************************************************
     435 * @ return 0 if success / return -1 if failure during IOC device access.
    422436 ****************************************************************************************/
    423437error_t fatfs_sync_free_info( void );
     
    430444 * It can be called by a thread running in any cluster, as it uses remote access
    431445 * primitives when the FAT mapper is remote. It takes the queuelock stored in the FATFS
    432  * context (located in the same cluster as the FAT mapper itself), to get exclusive
    433  * access to the FAT. It uses the <free_cluster_hint> and <free_clusters> variables
    434  * stored in this FATFS context.
     446 * context located in the same cluster as the FAT mapper itself, to get exclusive
     447 * access to the FAT. It uses and updates the <free_cluster_hint> and <free_clusters>
     448 * variables stored in this FATFS context.
    435449 * - it updates the <free_cluster_hint> and <free_clusters> variables in FATFS context.
    436450 * - it updates the FAT mapper (handling miss from IOC device if required).
     
    445459/*****************************************************************************************
    446460 * This function implements the generic vfs_fs_release_inode() function for the FATFS.
    447  *****************************************************************************************
     461  *****************************************************************************************
    448462 * It releases all clusters allocated to a file/directory identified by the <inode_xp>
    449463 * argument. All released clusters are marked FREE_CLUSTER in the FAT mapper.
     
    466480 * The pointer on the mapper and the page index in file are found in the page descriptor.
    467481 * It is used for both a regular file/directory mapper, and the FAT mapper.
    468  * For the FAT mapper, it access the FATFS to get the location on IOC device.
    469  * For a regular file, it access the FAT mapper to get the cluster index on IOC device.
     482 * - For the FAT mapper, it updates the FAT region on IOC device.
     483 * - For a regular file, it access the FAT mapper to get the cluster index on IOC device.
    470484 * It can be called by any thread running in any cluster.
    471485 *
Note: See TracChangeset for help on using the changeset viewer.