Ignore:
Timestamp:
Dec 3, 2018, 12:17:35 PM (6 years ago)
Author:
alain
Message:

Improve the FAT32 file system to support cat, rm, cp commands.

File:
1 edited

Legend:

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

    r492 r603  
    2424#include <hal_kernel_types.h>
    2525#include <hal_special.h>
     26#include <hal_remote.h>
    2627#include <errno.h>
    2728#include <printk.h>
    28 #include <vseg.h>
    2929#include <kmem.h>
    3030#include <grdxt.h>
     
    5353
    5454        return 0;
    55 }
     55
     56}  // end grdxt_init()
    5657
    5758//////////////////////////////////
     
    7071        uint32_t   ix1;
    7172        uint32_t   ix2;
     73
     74// check rt
     75assert( (rt != NULL) , "pointer on radix tree is NULL\n" );
    7276
    7377        req.type = KMEM_GENERIC;
     
    107111}  // end grdxt_destroy()
    108112
    109 ///////////////////////////////
    110 void grdxt_print( grdxt_t * rt,
    111                   char    * name )
    112 {
    113         uint32_t        ix1; 
    114         uint32_t        ix2;
    115         uint32_t        ix3;
    116 
    117     uint32_t        w1 = rt->ix1_width;
    118     uint32_t        w2 = rt->ix2_width;
    119     uint32_t        w3 = rt->ix3_width;
    120 
    121     void         ** ptr1 = rt->root;
    122     void         ** ptr2;
    123     void         ** ptr3;
    124 
    125     intptr_t        key;
    126     intptr_t        value;
    127 
    128         printk("\n***** Generic Radix tree %s : n1 = %d / n2 = %d / n3 = %d\n\n",
    129            name, 1<<w1 , 1<<w2 , 1<<w3 );
     113////////////////////////////////////
     114void grdxt_display( xptr_t    rt_xp,
     115                    char    * name )
     116{
     117        uint32_t       ix1; 
     118        uint32_t       ix2;
     119        uint32_t       ix3;
     120
     121// check rt_xp
     122assert( (rt_xp != XPTR_NULL) , "pointer on radix tree is NULL\n" );
     123
     124    // get cluster and local pointer on remote rt descriptor
     125    grdxt_t      * rt_ptr = GET_PTR( rt_xp );
     126    cxy_t          rt_cxy = GET_CXY( rt_xp );
     127
     128    // get widths
     129    uint32_t       w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) );
     130    uint32_t       w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) );
     131    uint32_t       w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) );
     132
     133    void ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
     134
     135        printk("\n***** Generic Radix Tree for <%s> : %d / %d / %d\n",
     136    name, 1<<w1 , 1<<w2 , 1<<w3 );
    130137
    131138        for( ix1=0 ; ix1 < (uint32_t)(1<<w1) ; ix1++ )
    132139        {
    133         ptr2 = ptr1[ix1];
     140            void ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
    134141        if( ptr2 == NULL )  continue;
    135142   
    136143        for( ix2=0 ; ix2 < (uint32_t)(1<<w2) ; ix2++ )
    137144        {
    138             ptr3 = ptr2[ix2];
     145                void ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
    139146            if( ptr3 == NULL ) continue;
    140147
    141148            for( ix3=0 ; ix3 < (uint32_t)(1<<w3) ; ix3++ )
    142149            {
    143                 value = (intptr_t)ptr3[ix3];
    144                 if( value == 0 )  continue;
    145 
    146                 key = (ix1<<(w2+w3)) + (ix2<<w3) + ix3;
    147                 printk(" - key = %x / value = %x\n", key , value );
     150                void * value = hal_remote_lpt( XPTR( rt_cxy , &ptr3[ix3] ) );
     151                if( value == NULL )  continue;
     152
     153                uint32_t key = (ix1<<(w2+w3)) + (ix2<<w3) + ix3;
     154                printk(" - key = %x / value = %x\n", key , (intptr_t)value );
    148155            }
    149156        }
    150157        }
    151 } // end grdxt_print()
     158
     159} // end grdxt_display()
    152160
    153161////////////////////////////////////
     
    162170    uint32_t        w3 = rt->ix3_width;
    163171
    164     // Check key
    165     if( (key >> (w1 + w2 + w3)) != 0 )
    166     {
    167         assert( false ,
    168         "key value %x exceed (%d + %d + %d) bits", key , w1 , w2 , w3 );
    169     }
     172// Check key value
     173assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    170174
    171175    // compute indexes
     
    179183
    180184    // If required, we must allocate memory for the selected level 2 array,
    181     // and atomically update the level 1 array.
     185    // and update the level 1 array.
    182186        if( ptr1[ix1] == NULL )
    183187        {
     
    198202
    199203    // If required, we must allocate memory for the selected level 3 array,
    200     // and atomically update the level 2 array.
     204    // and update the level 2 array.
    201205        if( ptr2[ix2] == NULL )
    202206        {
     
    224228
    225229        return 0;
    226 }
     230
     231}  // end grdxt_insert()
    227232
    228233///////////////////////////////////
     
    234239    uint32_t        w3 = rt->ix3_width;
    235240
    236     // Check key
    237     if( (key >> (w1 + w2 + w3)) != 0 )
    238     {
    239         assert( false ,
    240         "key value %x exceed (%d + %d + %d) bits", key , w1 , w2 , w3 );
    241     }
     241// Check key value
     242assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    242243
    243244    // compute indexes
     
    266267
    267268        return value;
    268 }
     269
     270}  // end grdxt_remove()
    269271
    270272///////////////////////////////////
     
    276278    uint32_t        w3 = rt->ix3_width;
    277279
    278     // Check key
    279     if( (key >> (w1 + w2 + w3)) != 0 )
    280     {
    281         assert( false ,
    282         "key value %x exceed (%d + %d + %d) bits", key , w1 , w2 , w3 );
    283     }
     280// Check key value
     281assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
    284282
    285283    void         ** ptr1 = rt->root;
     
    304302
    305303        return value;
    306 }
     304
     305}  // end grdxt_lookup()
     306
     307////////////////////////////////////////////
     308xptr_t grdxt_remote_lookup( xptr_t    rt_xp,
     309                            uint32_t  key )
     310{
     311    // get cluster and local pointer on remote rt descriptor
     312    grdxt_t       * rt_ptr = GET_PTR( rt_xp );
     313    cxy_t           rt_cxy = GET_CXY( rt_xp );
     314
     315    // get widths
     316    uint32_t        w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) );
     317    uint32_t        w2 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix2_width ) );
     318    uint32_t        w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) );
     319
     320// Check key value
     321assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
     322
     323    // compute indexes
     324    uint32_t        ix1 = key >> (w2 + w3);              // index in level 1 array
     325        uint32_t        ix2 = (key >> w3) & ((1 << w2) -1);  // index in level 2 array
     326        uint32_t        ix3 = key & ((1 << w3) - 1);         // index in level 3 array
     327
     328    // get ptr1
     329    void         ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
     330
     331    // get ptr2
     332        void         ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
     333        if( ptr2 == NULL ) return XPTR_NULL;
     334
     335    // get ptr3
     336        void         ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
     337        if( ptr3 == NULL ) return XPTR_NULL;
     338
     339    // get value
     340        xptr_t      value = XPTR( rt_cxy , ptr3[ix3] );
     341
     342        return value;
     343
     344}  // end grdxt_remote_lookup()
    307345
    308346//////////////////////////////////////
     
    319357    uint32_t        w3 = rt->ix3_width;
    320358
    321     // Check start_key
    322     if( (start_key >> (w1 + w2 + w3)) != 0 )
    323     {
    324         assert( false ,
    325         "start_key value %x exceed (%d + %d + %d) bits", start_key , w1 , w2 , w3 );
    326     }
     359// Check key value
     360assert( ((start_key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", start_key );
    327361
    328362    // compute max indexes
     
    363397
    364398    return NULL;
    365 }
     399
     400}  // end grdxt_get_first()
Note: See TracChangeset for help on using the changeset viewer.