Changeset 797 for soft


Ignore:
Timestamp:
Mar 2, 2016, 2:26:49 PM (9 years ago)
Author:
alain
Message:

Fix a bug in _all_clusters_allocate()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_fat32/fat32.c

    r787 r797  
    686686
    687687
    688 ///////////////////////////////////////////////////////////////////
     688///////////////////////////////////////////////////////////////
    689689static unsigned int _get_free_cluster( unsigned int*  cluster ) 
    690690{
     
    932932static unsigned int _cluster_release( unsigned int cluster )
    933933{
    934     if ( cluster >= END_OF_CHAIN_CLUSTER_MIN )  // terminal case : nothing to do
    935     {
    936         return 0;       
    937     }
    938     else                 // non terminal case : recursive call, then release cluster
     934    if ( cluster < END_OF_CHAIN_CLUSTER_MIN )  // non terminal case
    939935    {
    940936        // get next cluster
     
    942938        if ( _get_fat_entry( cluster , &next ) )
    943939        {
    944             _printf("\n[FAT ERROR] in _cluster_release() accessing Fat-Cache"
     940            _printf("\n[FAT ERROR] in _cluster_release() scanning Fat-Cache"
    945941                    " for cluster %x\n", cluster );
    946942            return 1;
    947943        }
    948944
    949         // call _cluster_release() on next
     945        // call _cluster_release() on next cluster
    950946        if ( _cluster_release( next ) ) return 1;
    951        
    952         // release current cluster
    953         if ( _set_fat_entry( cluster , FREE_CLUSTER ) )
    954         {
    955             _printf("\n[FAT ERROR] in _cluster_release() updating Fat-Cache"
    956                     " for cluster %x\n", cluster );
    957             return 1;
    958         }
    959 
    960         // update free_cluster _hint and free_clusters_number in FAT descriptor
    961         _fat.free_clusters_number++;
    962         if ( cluster < _fat.free_cluster_hint ) _fat.free_cluster_hint = cluster;
    963 
    964         return 0;
    965     }
     947    }       
     948
     949    // In both cases (terminal or not) release cluster
     950    if ( _set_fat_entry( cluster , FREE_CLUSTER ) )
     951    {
     952        _printf("\n[FAT ERROR] in _cluster_release() updating Fat-Cache"
     953                " for cluster %x\n", cluster );
     954        return 1;
     955    }
     956
     957    // Update free_cluster _hint and free_clusters_number in FAT descriptor
     958    _fat.free_clusters_number++;
     959    if ( cluster < _fat.free_cluster_hint ) _fat.free_cluster_hint = cluster;
     960
     961    return 0;
     962
    966963}  // end _cluster_release()
    967964
     
    969966static unsigned int _all_clusters_release( fat_inode_t* inode )
    970967{
    971     // release recursively all clusters in FAT chaining,
    972     // starting from last cluster in chain, ending by first.
     968    // release recursively all clusters in FAT chaining reverse order
     969    // starting from last cluster in chain, ending by first.
     970 
    973971    if ( _cluster_release( inode->cluster ) )
    974972    {
     
    989987    if ( _update_fs_info() )
    990988    {
    991         _printf("\n[FAT ERROR] in _all_clusters_release() updating FS_INFO sector on device\n");
     989        _printf("\n[FAT ERROR] in _all_clusters_release() updating FS_INFO sector\n");
    992990        return 1;
    993991    }
     992
     993    // update cluster field in inode
     994    inode->cluster = END_OF_CHAIN_CLUSTER_MIN;
    994995
    995996#if GIET_DEBUG_FAT
     
    26262627    {
    26272628        // empty file
    2628         child->size = 0;
     2629        child->size   = 0;
    26292630        child->levels = _get_levels_from_size( child->size );
    26302631
Note: See TracChangeset for help on using the changeset viewer.