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.

File:
1 edited

Legend:

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

    r638 r656  
    3232
    3333
    34 /**************************************************************************************
     34/******************************************************************************************
    3535 * The FATFS File System implements a FAT32 read/write file system.
    3636 *
     
    4343 *    on the FAT mapper.
    4444 * 2) The vfs_inode_t "extend" contains, for each inode,
    45  *    the first FAT cluster index (after cast to intptr).
     45 *    the first FAT32 cluster_id (after cast to intptr).
    4646 * 3) The vfs_dentry_t "extend" field contains, for each dentry, the entry index
    47  *    in the FATFS directory (32 bytes per FATFS entry).
    48  *************************************************************************************/
     47 *    in the FATFS directory (32 bytes per FATFS directory entry).
     48 *
     49 * In the FAT32 File System, the File Allocation Table is is actually an array
     50 * of uint32_t slots. Each slot in this array contains the index (called cluster_id)
     51 * of another slot in this array, to form one linked list for each file stored on
     52 * device in the FAT32 File System. This index in the FAT array is also the index of
     53 * the FATFS cluster on the device. One FATFS cluster is supposed to contain one PPM page.
     54 * For a given file, the entry point in the FAT is the cluster_id of the FATFS cluster
     55 * containing the first page of the file, but it can be any cluster_id already allocated
     56 * to the file.
     57 *****************************************************************************************/
    4958 
    5059///////////////////////////////////////////////////////////////////////////////////////////
     
    213222
    214223/*****************************************************************************************
    215  * This function access the FAT (File Allocation Table), stored in the FAT mapper, and
    216  * returns in <searched_cluster> the FATFS cluster index for a given page of a given
    217  * inode identified by the <first_cluster> and <page_id> arguments.
    218  * It can be called by a thread running in any cluster, as it uses remote access
    219  * primitives when the FAT mapper is remote.
    220  * The FAT is actually an array of uint32_t slots. Each slot in this array contains the
    221  * index of another slot in this array, to form one linked list for each file stored on
    222  * device in the FATFS file system. This index in the FAT array is also the index of the
    223  * FATFS cluster on the device. One FATFS cluster is supposed to contain one PPM page.
    224  * For a given file, the entry point in the FAT is simply the index of the FATFS cluster
    225  * containing the first page of the file. The FAT mapper being a cache, this function
    226  * updates the FAT mapper from informations stored on IOC device in case of miss.
    227  *****************************************************************************************
    228  * @ first_cluster       : [in]  index of first FATFS cluster allocated to the file.
    229  * @ page_id             : [in]  index of searched page in file.
    230  * @ searched_cluster    : [out] found FATFS cluster index.
    231  * @ return 0 if success / return -1 if a FAT mapper miss cannot be solved.
    232  ****************************************************************************************/
    233 error_t fatfs_get_cluster( uint32_t   first_cluster,
    234                            uint32_t   page_id,
    235                            uint32_t * searched_cluster );
    236 
    237 /*****************************************************************************************
    238  * This function display the content of the FATFS context copy in cluster identified
    239  * by the <cxy> argument.
     224 * This debug function display the content of the FATFS context copy in cluster
     225 * identified by the <cxy> argument.
    240226 * This function can be called by a thread running in any cluster.
    241227 *****************************************************************************************
     
    245231
    246232/*****************************************************************************************
    247  * This function access the FAT mapper to display one page of the File Allocation Table.
    248  * It loads the requested page fom IOC device to FAT mapper if required.
     233 * This debug function access the FAT mapper to display the current FAT state,
     234 * as defined by the <page_id>, <min_slot>, and <nb_slots> arguments.
     235 * It loads the missing pages from IOC to mapper if required.
    249236 * This function can be called by a thread running in any cluster.
    250237 *****************************************************************************************
    251  * @ page_id     : page index in FAT mapper (one page is 4 Kbytes).
    252  * @ nb_entries  : number of entries (one entry is 4 bytes).
     238 * @ page_id   : page index in FAT mapper (one page is 4 Kbytes = 1024 slots).
     239 * @ min_slot  : first slot in page
     240 * @ nb_slots  : number of slots (one slot is 4 bytes).
    253241 ****************************************************************************************/
    254242void fatfs_display_fat( uint32_t  page_id,
    255                         uint32_t  nb_entries );
     243                        uint32_t  min_slot,
     244                        uint32_t  nb_slots );
    256245
    257246
     
    330319 *****************************************************************************************
    331320 * It scan a parent directory mapper, identified by the <parent_inode> argument to find
    332  * a directory entry identified by the <name> argument.  In case of success, it
    333  * initializes the inode/dentry couple, identified by the  <child_inode_xp> argument
    334  * in the Inode Tree. The child inode descriptor, and the associated dentry descriptor
    335  * must have been previously allocated by the caller.
     321 * a directory entry identified by the <name> argument.  In case of success, it completes
     322 * initialization the inode/dentry couple, identified by the  <child_inode_xp> argument.
     323 * The child inode descriptor, and the associated dentry descriptor must have been
     324 * previously allocated by the caller.
    336325 * - It set the "type", "size", and "extend" fields in the child inode descriptor.
    337326 * - It set the " extend" field in the dentry descriptor.
     
    421410 * TODO : the current implementation check ALL pages in the FAT region, even if most
    422411 * pages are empty, and not copied in mapper. It is sub-optimal.
    423  * - A first solution is to maintain in the FAT context two "dirty_min" and "dirty_max"
    424  *  variables defining the smallest/largest dirty page index in FAT mapper...
     412 * A solution is to maintain in the FAT context two "dirty_min" and "dirty_max"
     413 * variables defining the smallest/largest dirty page index in FAT mapper...
    425414 *****************************************************************************************
    426415 * @ return 0 if success / return -1 if failure during IOC device access.
     
    448437 * in <searched_cluster> the FATFS cluster index of a free cluster.
    449438 * It can be called by a thread running in any cluster, as it uses remote access
    450  * primitives when the FAT mapper is remote. It takes the queuelock stored in the FATFS
     439 * primitives when the FAT mapper is remote. It takes the rwlock stored in the FATFS
    451440 * context located in the same cluster as the FAT mapper itself, to get exclusive
    452441 * access to the FAT. It uses and updates the <free_cluster_hint> and <free_clusters>
     
    457446 * - it returns the allocated cluster index.
    458447 *****************************************************************************************
    459  * @ searched_cluster    : [out] found FATFS cluster index.
     448 * @ searched_cluster_id  : [out] allocated FATFS cluster index.
    460449 * @ return 0 if success / return -1 if no more free clusters on IOC device.
    461450 ****************************************************************************************/
    462 error_t fatfs_cluster_alloc( uint32_t * searched_cluster );
     451error_t fatfs_cluster_alloc( uint32_t * searched_cluster_id );
    463452
    464453/*****************************************************************************************
    465454 * This function implements the generic vfs_fs_release_inode() function for the FATFS.
    466   *****************************************************************************************
     455 *****************************************************************************************
     456 * This function is used to remove a given file or directory from FATFS the file system.
    467457 * It releases all clusters allocated to a file/directory identified by the <inode_xp>
    468458 * argument. All released clusters are marked FREE_CLUSTER in the FAT mapper.
     
    470460 * the clusters in reverse order of the linked list (from last to first).
    471461 * When the FAT mapper has been updated, it calls the fatfs_sync_fat() function to
    472  * synchronously update all dirty pages in the FAT mapper to the IOC device.
     462 * synchronously update all modified pages in the FAT mapper to the IOC device.
    473463 * Finally the FS-INFO sector on the IOC device is updated.
    474464 *****************************************************************************************
     
    485475 * The pointer on the mapper and the page index in file are found in the page descriptor.
    486476 * It is used for both a regular file/directory mapper, and the FAT mapper.
    487  * - For the FAT mapper, it updates the FAT region on IOC device.
    488  * - For a regular file, it access the FAT mapper to get the cluster index on IOC device.
     477 * - For the FAT mapper, it read/write the FAT region on IOC device.
     478 * - For a regular file, it scan the FAT mapper to get the cluster_id on IOC device,
     479 *   and read/write this cluster.
    489480 * It can be called by any thread running in any cluster.
    490481 *
    491482 * WARNING : For the FAT mapper, the inode field in the mapper MUST be NULL, as this
    492  * is used to indicate that the corresponding mapper is the FAT mapper.
     483 *           is used to indicate that the corresponding mapper is the FAT mapper.
     484 *
     485 * TODO : In this first implementation, the entry point in the FAT to get the cluster_id
     486 *        is always the cluster_id of the first page, registered in the inode extension.
     487 *        This can introduce a quadratic cost when trying of acessing all pages of a
     488 *        big file. An optimisation would be to introduce in the inode extension two
     489 *        new fields <other_page_id> & <other_cluster_id>, defining a second entry point
     490 *        in the FAT.
    493491 *****************************************************************************************
    494492 * @ page_xp   : extended pointer on page descriptor.
Note: See TracChangeset for help on using the changeset viewer.