Ignore:
Timestamp:
Dec 27, 2018, 7:38:58 PM (5 years ago)
Author:
alain
Message:

Fix several bugs in VFS to support the following
ksh commandis : cp, mv, rm, mkdir, cd, pwd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/htab.c

    r563 r610  
    3434///////////////////////////////////////////////////////////////////////////////////////////
    3535//    Item type specific (static) functions (two functions for each item type).
    36 // Example below if for <vhs_inode_t>, where the identifier is the inum field.
    37 ///////////////////////////////////////////////////////////////////////////////////////////
    38 
    39 ///////////////////////////////////////////////////////////////////////////////////////////
    40 // These static functions compute the hash index from the key.
     36// Example below if for <bloup_t> type, where the identifier is an uint32_t field.
     37///////////////////////////////////////////////////////////////////////////////////////////
     38
     39typedef struct bloup_s
     40{
     41    uint32_t       key;
     42    list_entry_t   list;
     43}
     44bloup_t;
     45
     46///////////////////////////////////////////////////////////////////////////////////////////
     47// This static function computes the hash index from the key.
    4148///////////////////////////////////////////////////////////////////////////////////////////
    4249// @ key      : local pointer on key.
    4350// @ return the index value, from 0 to (HASHTAB_SIZE - 1)
    4451///////////////////////////////////////////////////////////////////////////////////////////
    45 static uint32_t htab_inode_index( void * key )
    46 {
    47         uint32_t * inum = key;
    48         return (((*inum) >> 16) ^ ((*inum) & 0xFFFF)) % HASHTAB_SIZE;
     52static uint32_t htab_bloup_index( void * key )
     53{
     54        return (*(uint32_t *)key) % HASHTAB_SIZE;
    4955}
    5056
    5157///////////////////////////////////////////////////////////////////////////////////////
    52 // These static functions are used by htab_lookup(), htab_insert(), and htab_remove().
     58// This static function is used by htab_lookup(), htab_insert(), and htab_remove().
    5359// They scan one sub-list identified by  <index> to find an item  identified by <key>.
    5460// The sub-list is not modified, but the lock must have been taken by the caller.
     
    5965// @ return pointer on item if found / return NULL if not found.
    6066///////////////////////////////////////////////////////////////////////////////////////
    61 static void * htab_inode_scan( htab_t  * htab,
     67static void * htab_bloup_scan( htab_t  * htab,
    6268                               uint32_t  index,
    6369                               void    * key )
    6470{
    6571    list_entry_t * list_entry;   // pointer on list_entry_t (iterator)
    66     vfs_inode_t  * inode;        // pointer on item
     72    bloup_t      * bloup;        // pointer on item
    6773   
    6874        LIST_FOREACH( &htab->roots[index] , list_entry )
    6975        {
    70         inode = (vfs_inode_t *)LIST_ELEMENT( list_entry , vfs_inode_t , list );
    71         if( inode->inum == *(uint32_t *)key ) return inode;
     76        bloup = (bloup_t *)LIST_ELEMENT( list_entry , bloup_t , list );
     77        if( bloup->key == *(uint32_t *)key ) return bloup;
    7278    }
    7379
     
    9197    htab->items = 0;
    9298
    93     if( type == HTAB_INODE_TYPE )
    94     {
    95         htab->scan    = &htab_inode_scan;
    96         htab->index   = &htab_inode_index;
     99    if( type == HTAB_BLOUP_TYPE )
     100    {
     101        htab->scan    = &htab_bloup_scan;
     102        htab->index   = &htab_bloup_index;
    97103    }
    98104    else
Note: See TracChangeset for help on using the changeset viewer.