Changeset 787 for soft


Ignore:
Timestamp:
Feb 10, 2016, 1:23:36 AM (8 years ago)
Author:
alain
Message:

Bug fix in mkdir.

Location:
soft/giet_vm/giet_fat32
Files:
2 edited

Legend:

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

    r783 r787  
    1 /////////////////////////////////////////////////////////////////////////////////
     1//////////////////////////////////////////////////////////////////////////////////
    22// Date     : 01/06/2015
    33// Authors  : Alain Greiner
     
    148148static unsigned int _update_dir_entry( fat_inode_t*  inode );
    149149
    150 static unsigned int _add_dir_entry( fat_inode_t* child,
    151                                     fat_inode_t* parent );
     150static unsigned int _add_dir_entry( fat_inode_t* child );
    152151
    153152static unsigned int _remove_dir_entry( fat_inode_t*  inode );
    154153
    155 static void _add_special_directories( fat_inode_t* child,
    156                                       fat_inode_t* parent );
     154static void _add_special_directories( fat_inode_t* child );
    157155
    158156static unsigned int _one_cluster_allocate( fat_inode_t*   inode,
     
    620618                                  unsigned int  cluster )
    621619{
    622 
    623 #if GIET_DEBUG_FAT
    624 if ( _get_proctime() > GIET_DEBUG_FAT )
    625 _printf("\n[DEBUG FAT] _allocate_one_buffer(): in cache <%s> for cluster_id %d\n",
    626         inode->name, cluster_id );
    627 #endif
    628 
    629620    // add cache levels if needed
    630621    while ( _get_levels_from_size( (cluster_id + 1) * 4096 ) > inode->levels )
     
    633624#if GIET_DEBUG_FAT
    634625if ( _get_proctime() > GIET_DEBUG_FAT )
    635 _printf("\n[DEBUG FAT] _allocate_one_buffer(): adding a cache level\n" );
     626_printf("\n[DEBUG FAT] _allocate_one_buffer(): adding a cache level for %s\n",
     627        inode->name );
    636628#endif
    637629
     
    834826                                           unsigned int*  cluster )
    835827{
     828
     829#if GIET_DEBUG_FAT
     830if ( _get_proctime() > GIET_DEBUG_FAT )
     831_printf("\n[DEBUG FAT] _one_cluster_allocate(): enter for <%s>\n", inode->name );
     832#endif
     833
    836834    // Check free cluster available
    837835    if ( _fat.free_clusters_number == 0 )
     
    887885    _fat.free_cluster_hint = new;
    888886
    889     if ( nb_current_clusters == 0 )  // first cluster : inode and directory entry
    890     {
    891         // update inode
     887    // update cluster chaining
     888    if ( nb_current_clusters == 0 )  // first cluster : update cluster field in inode
     889    {
    892890        inode->cluster = new;
    893 
    894         // update directory entry
    895         _update_dir_entry( inode );
    896     }
    897     else                             // update previous last cluster in FAT
     891    }
     892    else                             // not the last : update previous last cluster in FAT
    898893    {
    899894        if ( _set_fat_entry( last , new ) )
     
    922917#if GIET_DEBUG_FAT
    923918if ( _get_proctime() > GIET_DEBUG_FAT )
    924 _printf("\n[DEBUG FAT] _one_cluster_allocate(): for <%s>\n"
    925         " nb_clusters = %d / last_cluster = %x / new_cluster = %x\n",
    926         inode->name , nb_current_clusters , last , new );
     919_printf("\n[DEBUG FAT] _one_cluster_allocate(): for <%s> cluster = %x\n",
     920        inode->name , new );
    927921#endif
    928922
     
    933927}  // end _one_cluster_allocate()
    934928
     929////////////////////////////////////////////////////////////
     930// recursive function called by _all_clusters_release()
    935931////////////////////////////////////////////////////////////
    936932static unsigned int _cluster_release( unsigned int cluster )
     
    10081004
    10091005///////////////////////////////////////////////////////////
    1010 static void _add_special_directories( fat_inode_t*  child,
    1011                                       fat_inode_t*  parent )
    1012 {
    1013     // get first File-Cache buffer for child
     1006static void _add_special_directories( fat_inode_t*  child )
     1007{
     1008    // get File-Cache buffer for child and cluster_id = 0
    10141009    fat_cache_desc_t*   pdesc  = (fat_cache_desc_t*)child->cache->children[0];
    10151010    unsigned char*      entry;
     
    10171012    unsigned int i;
    10181013    unsigned int cluster;
    1019     unsigned int size;
    10201014
    10211015    // set "." entry (32 bytes)
     1016    entry   = pdesc->buffer;
    10221017    cluster = child->cluster;
    1023     size    = child->size;
    1024     entry   = pdesc->buffer;
    10251018   
    10261019    for ( i = 0 ; i < 32 ; i++ )
     
    10331026        else if (i == 26)     entry[i] = cluster>>0;    // cluster.B0
    10341027        else if (i == 27)     entry[i] = cluster>>8;    // cluster.B1
    1035         else if (i == 28)     entry[i] = size>>0;       // size.B0
    1036         else if (i == 29)     entry[i] = size>>8;       // size.B1
    1037         else if (i == 30)     entry[i] = size>>16;      // size.B2
    1038         else if (i == 31)     entry[i] = size>>24;      // size.B3
    10391028        else                  entry[i] = 0x00;
    10401029    }
    10411030
    10421031    // set ".." entry (32 bytes)
    1043     cluster = parent->cluster;
    1044     size    = parent->size;
    10451032    entry   = pdesc->buffer + 32;
     1033    cluster = child->parent->cluster;
     1034
     1035    // handling special case when parent is root directory
     1036    if ( cluster == 2 ) cluster = 0;
    10461037
    10471038    for ( i = 0 ; i < 32 ; i++ )
     
    10541045        else if (i == 26)     entry[i] = cluster>>0;    // cluster.B0
    10551046        else if (i == 27)     entry[i] = cluster>>8;    // cluster.B1
    1056         else if (i == 28)     entry[i] = size>>0;       // size.B0
    1057         else if (i == 29)     entry[i] = size>>8;       // size.B1
    1058         else if (i == 30)     entry[i] = size>>16;      // size.B2
    1059         else if (i == 31)     entry[i] = size>>24;      // size.B3
    10601047        else                  entry[i] = 0x00;
    10611048    }
     
    13041291
    13051292
    1306 ///////////////////////////////////////////////////////////
    1307 static unsigned int _add_dir_entry( fat_inode_t*   child,
    1308                                     fat_inode_t*   parent )
     1293//////////////////////////////////////////////////////////
     1294static unsigned int _add_dir_entry( fat_inode_t*   child )
    13091295{
    13101296    // get child attributes
     
    13121298    unsigned int      size    = child->size;
    13131299    unsigned int      cluster = child->cluster;
     1300    fat_inode_t*      parent  = child->parent;
     1301
     1302    if ( parent == NULL ) return 1;
    13141303
    13151304    // compute number of required 32 bytes entries to store
     
    13201309    unsigned char   checksum;
    13211310    if ( _get_sfn_name( child->name,
    1322                              &length,
    1323                              &nb_lfn,
    1324                              sfn,
    1325                              &checksum ) )  return 1;
     1311                        &length,
     1312                        &nb_lfn,
     1313                        sfn,
     1314                        &checksum ) )  return 1;
    13261315
    13271316#if GIET_DEBUG_FAT
     
    13791368#endif
    13801369
    1381     // enter FSM :
     1370    // enter FSM to modify parent directory:
    13821371    // The new child requires to write 3, 4, or 5 directory entries.
    13831372    // To actually register the new child, we use a 5 steps FSM
     
    15361525            case 1:   // write NOMORE entry 
    15371526            {
     1527                entry [0] = 0x00;
    15381528                step--;
    1539                 entry [0] = 0x00;
    15401529                break;
    15411530            }
     
    15531542
    15541543    return 0;       
    1555 } // end _add_dir_entry
     1544} // end _add_dir_entry()
    15561545
    15571546
     
    25312520
    25322521        // add an entry in the parent directory Cache_file
    2533         if ( _add_dir_entry( child , parent ) )
     2522        // and update the dentry field in child inode
     2523        if ( _add_dir_entry( child ) )
    25342524        {
    25352525            _spin_lock_release( &_fat.fat_lock );
     
    36323622                               old->size,
    36333623                               0,              // count
    3634                                0,              // dentry
     3624                               0,              // dentry set by _add_dir_entry()
    36353625                               0 );            // no cache_allocate
    36363626 
     
    36393629    new->cache  = old->cache;
    36403630
     3631    // add "new" to "new_parent" directory in Inode-Tree
     3632    _add_inode_in_tree( new , new_parent );
     3633   
    36413634    // add "new" to "new_parent" directory File-Cache
    3642     if ( _add_dir_entry( new , new_parent ) )
     3635    // and update the dentry field in new inode
     3636    if ( _add_dir_entry( new ) )
    36433637    {
    36443638        _spin_lock_release( &_fat.fat_lock );
     
    36503644    }
    36513645
    3652     // add "new" to "new_parent" directory in Inode-Tree
    3653     _add_inode_in_tree( new , new_parent );
    3654    
    36553646    // updates "new_parent" directory on device
    36563647    if ( _update_device_from_cache( new_parent->levels,
     
    37963787        // allocate a new inode and an empty Cache-File
    37973788        child = _allocate_one_inode( name,
    3798                                      1,           // it's a directory
    3799                                      0xFFFFFFFF,  // cluster index not defined yet
    3800                                      0,           // size = 0 for a directory
    3801                                      0,           // count
    3802                                      0,           // dentry set by _add_dir_entry()
    3803                                      1 );         // cache_allocate
     3789                                     1,                         // it's a directory
     3790                                     END_OF_CHAIN_CLUSTER_MAX,  // cluster set later
     3791                                     0,                         // size = 0 for directory
     3792                                     0,                         // count
     3793                                     0,                         // dentry set later
     3794                                     1 );                       // cache_allocate
    38043795
    38053796        // introduce inode in Inode-Tree
    38063797        _add_inode_in_tree( child , parent );
    38073798 
    3808         // allocate cluster from FAT
     3799        // allocate one cluster from FAT for child
    38093800        unsigned int cluster;
    3810         if ( _one_cluster_allocate( inode , &cluster ) )
     3801        if ( _one_cluster_allocate( child , &cluster ) )
    38113802        {
    38123803            _spin_lock_release( &_fat.fat_lock );
     
    38213812        child->cluster = cluster;
    38223813
    3823         // allocate and initialise one 4 Kbytes buffer and associated descriptor
    3824         _allocate_one_buffer( child,
    3825                               0,            // cluster_id,
    3826                               cluster );
    3827 
    3828         _add_special_directories( child,
    3829                                   parent );
    3830 
    3831         // add an entry in the parent directory Cache_file
    3832         if ( _add_dir_entry( child , parent ) )
    3833         {
     3814        // add new entry in parent directory File-Cache
     3815        // and update dentry field in child inode
     3816        if ( _add_dir_entry( child ) )
     3817        {
    38343818            _spin_lock_release( &_fat.fat_lock );
    38353819            _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     
    38393823            return GIET_FAT32_IO_ERROR;
    38403824        }
     3825
     3826        // add "." and ".." directories in child directory
     3827        _add_special_directories( child );
    38413828
    38423829        // update DATA region on block device for parent directory
  • soft/giet_vm/giet_fat32/fat32.h

    r783 r787  
    170170    unsigned int         size;                   // number of bytes
    171171    unsigned int         count;                  // reference count / 0 if dir
    172     unsigned short       dentry;                 // directory entry index in parent
     172    unsigned short       dentry;                 // NORMAL dir_entry index in parent
    173173    unsigned char        levels;                 // number of levels in file_cache
    174174    unsigned char        is_dir;                 // directory if non zero
Note: See TracChangeset for help on using the changeset viewer.