Changeset 656 for trunk/kernel/libk


Ignore:
Timestamp:
Dec 6, 2019, 12:07:51 PM (5 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.

Location:
trunk/kernel/libk
Files:
4 edited

Legend:

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

    r635 r656  
    315315                else                   
    316316                {
    317                     *found_key = (ix1 << (w2+w3)) | (ix2 << w1) | ix3;
     317                    *found_key = (ix1 << (w2+w3)) | (ix2 << w3) | ix3;
    318318                    return ptr3[ix3];
    319319                }
     
    343343    grdxt_t * rt_ptr = GET_PTR( rt_xp );
    344344
     345#if DEBUG_GRDXT_INSERT
     346uint32_t cycle = (uint32_t)hal_get_cycles();
     347if(DEBUG_GRDXT_INSERT < cycle)
     348printk("\n[%s] enter / rt_xp (%x,%x) / key %x / value %x\n",
     349__FUNCTION__, rt_cxy, rt_ptr, key, (intptr_t)value );
     350#endif
     351
    345352    // get widths
    346353    uint32_t        w1 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix1_width ) );
     
    348355    uint32_t        w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) );
    349356
     357#if DEBUG_GRDXT_INSERT
     358if(DEBUG_GRDXT_INSERT < cycle)
     359printk("\n[%s] get widths : w1 %d / w2 %d / w3 %d\n",
     360__FUNCTION__, w1, w2, w3 );
     361#endif
     362
    350363// Check key value
    351364assert( ((key >> (w1 + w2 + w3)) == 0 ), "illegal key value %x\n", key );
     
    356369        uint32_t        ix3 = key & ((1 << w3) - 1);         // index in level 3 array
    357370
     371#if DEBUG_GRDXT_INSERT
     372if(DEBUG_GRDXT_INSERT < cycle)
     373printk("\n[%s] compute indexes : ix1 %d / ix2 %d / ix3 %d\n",
     374__FUNCTION__, ix1, ix2, ix3 );
     375#endif
     376
    358377    // get ptr1
    359378    void ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
     
    361380    if( ptr1 == NULL ) return -1;
    362381
     382#if DEBUG_GRDXT_INSERT
     383if(DEBUG_GRDXT_INSERT < cycle)
     384printk("\n[%s] compute ptr1 = %x\n",
     385__FUNCTION__, (intptr_t)ptr1 );
     386#endif
     387
    363388    // get ptr2
    364389    void ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
     390
     391#if DEBUG_GRDXT_INSERT
     392if(DEBUG_GRDXT_INSERT < cycle)
     393printk("\n[%s] get current ptr2 = %x\n",
     394__FUNCTION__, (intptr_t)ptr2 );
     395#endif
    365396
    366397    // allocate memory for the missing level_2 array if required
     
    374405
    375406        if( ptr2 == NULL ) return -1;
    376 
     407       
    377408        // update level_1 entry
    378409        hal_remote_spt( XPTR( rt_cxy , &ptr1[ix1] ) , ptr2 );
     410
     411#if DEBUG_GRDXT_INSERT
     412if(DEBUG_GRDXT_INSERT < cycle)
     413printk("\n[%s] update ptr1[%d] : &ptr1[%d] = %x / ptr2 = %x\n",
     414__FUNCTION__, ix1, ix1, &ptr1[ix1], ptr2 );
     415#endif
     416
    379417    }
    380418
    381419    // get ptr3
    382420    void ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
     421
     422#if DEBUG_GRDXT_INSERT
     423if(DEBUG_GRDXT_INSERT < cycle)
     424printk("\n[%s] get current ptr3 = %x\n",
     425__FUNCTION__, (intptr_t)ptr3 );
     426#endif
    383427
    384428    // allocate memory for the missing level_3 array if required
     
    395439        // update level_2 entry
    396440        hal_remote_spt( XPTR( rt_cxy , &ptr2[ix2] ) , ptr3 );
     441
     442#if DEBUG_GRDXT_INSERT
     443if(DEBUG_GRDXT_INSERT < cycle)
     444printk("\n[%s] update  ptr2[%d] : &ptr2[%d] %x / ptr3 %x\n",
     445__FUNCTION__, ix2, ix2, &ptr2[ix2], ptr3 );
     446#endif
     447
    397448    }
    398449
    399450    // register value in level_3 array
    400451    hal_remote_spt( XPTR( rt_cxy , &ptr3[ix3] ) , value );
     452
     453#if DEBUG_GRDXT_INSERT
     454if(DEBUG_GRDXT_INSERT < cycle)
     455printk("\n[%s] update  ptr3[%d] : &ptr3[%d] %x / value %x\n",
     456__FUNCTION__, ix3, ix3, &ptr3[ix3], value );
     457#endif
    401458
    402459    hal_fence();
     
    498555        uint32_t       ix3;
    499556
     557    void        ** ptr1;
     558    void        ** ptr2;
     559    void        ** ptr3;
     560
    500561// check rt_xp
    501562assert( (rt_xp != XPTR_NULL) , "pointer on radix tree is NULL\n" );
     
    510571    uint32_t       w3 = hal_remote_l32( XPTR( rt_cxy , &rt_ptr->ix3_width ) );
    511572
    512     void ** ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
     573    ptr1 = hal_remote_lpt( XPTR( rt_cxy , &rt_ptr->root ) );
    513574
    514575        printk("\n***** Generic Radix Tree for <%s>\n", name );
     
    516577        for( ix1=0 ; ix1 < (uint32_t)(1<<w1) ; ix1++ )
    517578        {
    518             void ** ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
     579            ptr2 = hal_remote_lpt( XPTR( rt_cxy , &ptr1[ix1] ) );
    519580        if( ptr2 == NULL )  continue;
    520581   
    521582        for( ix2=0 ; ix2 < (uint32_t)(1<<w2) ; ix2++ )
    522583        {
    523                 void ** ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
     584                ptr3 = hal_remote_lpt( XPTR( rt_cxy , &ptr2[ix2] ) );
    524585            if( ptr3 == NULL ) continue;
    525586
     
    530591
    531592                uint32_t key = (ix1<<(w2+w3)) + (ix2<<w3) + ix3;
    532                 printk(" - key = %x / value = %x\n", key , (intptr_t)value );
     593                printk(" - key = %x / value = %x / ptr1 = %x / ptr2 = %x / ptr3 = %x\n",
     594                key, (intptr_t)value, (intptr_t)ptr1, (intptr_t)ptr2, (intptr_t)ptr3 );
    533595            }
    534596        }
  • trunk/kernel/libk/grdxt.h

    r635 r656  
    6161/*******************************************************************************************
    6262 * This function initialises the radix-tree descriptor,
     63 * and allocates memory for the first level array of pointers.
    6364 * It must be called by a local thread.
    64  * and allocates memory for the first level array of pointers.
    6565 *******************************************************************************************
    6666 * @ rt        : pointer on the radix-tree descriptor.
     
    7777/*******************************************************************************************
    7878 * This function releases all memory allocated to the radix-tree infrastructure.
     79 * A warning message is printed on the kernel TXT0 if the radix tree is not empty.
    7980 * It must be called by a local thread.
    80  * A warning message is printed on the kernel TXT0 if the radix tree is not empty.
    8181 *******************************************************************************************
    8282 * @ rt      : pointer on the radix-tree descriptor.
     
    8686/*******************************************************************************************
    8787 * This function insert a new item in the radix-tree.
     88 * It dynamically allocates memory for new second and third level arrays if required.
    8889 * It must be called by a local thread.
    89  * It dynamically allocates memory for new second and third level arrays if required.
    9090 *******************************************************************************************
    9191 * @ rt      : pointer on the radix-tree descriptor.
     
    100100/*******************************************************************************************
    101101 * This function removes an item identified by its key from the radix tree,
     102 * and returns a pointer on the removed item. No memory is released.
    102103 * It must be called by a local thread.
    103  * and returns a pointer on the removed item. No memory is released.
    104104 *******************************************************************************************
    105105 * @ rt      : pointer on the radix-tree descriptor.
     
    124124/*******************************************************************************************
    125125 * This function scan all radix-tree entries in increasing key order, starting from
     126 * the value defined by the <start_key> argument, and return a pointer on the first valid
     127 * registered item, and the found item key value.
    126128 * It must be called by a local thread.
    127  * the value defined by the <key> argument, and return a pointer on the first valid
    128  * registered item, and the found item key value.
    129129 *******************************************************************************************
    130130 * @ rt         : pointer on the radix-tree descriptor.
    131131 * @ start_key  : key starting value for the scan.
    132132 * @ found_key  : [out] buffer for found key value.
    133  * @ return pointer on first valid item if found / return NULL if not found.
     133 * @ return pointer on first valid item if found / return NULL if no item found.
    134134 ******************************************************************************************/
    135135void * grdxt_get_first( grdxt_t  * rt,
  • trunk/kernel/libk/list.h

    r651 r656  
    11/*
    2  * list.h - Double circular linked list
     2 * list.h - Local double circular linked list, using local pointers.
    33 *
    44 * Authors Ghassan Almaless  (2008,2009,2010,2011,2012)
     
    9191
    9292/***************************************************************************
    93  * This macro returns t pointer on the first element of a list.
     93 * This macro returns a pointer on the first element of a list.
    9494 ***************************************************************************
    9595 * @ root     : pointer on the list root
     
    171171                                   list_entry_t * entry )
    172172{
    173     list_entry_t * next = root->next; 
    174 
    175         entry->next = next;
     173    list_entry_t * first = root->next; 
     174
     175        entry->next = first;
    176176        entry->pred = root;
    177177 
    178         root->next = entry;
    179         next->pred = entry;
     178        root->next  = entry;
     179        first->pred = entry;
    180180}
    181181
     
    190190                                  list_entry_t * entry )
    191191{
    192     list_entry_t * pred = root->pred;
     192    list_entry_t * last = root->pred;
    193193
    194194        entry->next = root;
    195         entry->pred = pred;
     195        entry->pred = last;
    196196 
    197197        root->pred = entry;
    198         pred->next = entry;
     198        last->next = entry;
    199199}
    200200
     
    366366                                          list_entry_t * entry )
    367367{
    368     list_entry_t * next = hal_remote_lpt( XPTR( cxy , &root->next ) );
     368    list_entry_t * first = hal_remote_lpt( XPTR( cxy , &root->next ) );
    369369       
    370         hal_remote_spt( XPTR( cxy , &entry->next ) , next );
     370        hal_remote_spt( XPTR( cxy , &entry->next ) , first );
    371371        hal_remote_spt( XPTR( cxy , &entry->pred ) , root );
    372372 
    373         hal_remote_spt( XPTR( cxy , &root->next ) , entry );
    374         hal_remote_spt( XPTR( cxy , &next->pred ) , entry );
     373        hal_remote_spt( XPTR( cxy , &root->next )  , entry );
     374        hal_remote_spt( XPTR( cxy , &first->pred ) , entry );
    375375}
    376376
     
    387387                                         list_entry_t * entry )
    388388{
    389     list_entry_t * pred = hal_remote_lpt( XPTR( cxy , &root->pred ) );
     389    list_entry_t * last = hal_remote_lpt( XPTR( cxy , &root->pred ) );
    390390       
    391391        hal_remote_spt( XPTR( cxy , &entry->next ) , root );
    392         hal_remote_spt( XPTR( cxy , &entry->pred ) , pred );
     392        hal_remote_spt( XPTR( cxy , &entry->pred ) , last );
    393393 
    394394        hal_remote_spt( XPTR( cxy , &root->pred ) , entry );
    395         hal_remote_spt( XPTR( cxy , &pred->next ) , entry );
     395        hal_remote_spt( XPTR( cxy , &last->next ) , entry );
    396396}
    397397
     
    401401 ***************************************************************************
    402402 * @ cxy     : remote list cluster identifier
    403  * @ entry   : pointer on the entry to be removed.
     403 * @ entry   : local pointer on the remote entry to be removed.
    404404 **************************************************************************/
    405405static inline void list_remote_unlink( cxy_t          cxy,
  • trunk/kernel/libk/xlist.h

    r636 r656  
    11/*
    2  * xlist.h - Double Circular Linked lists, using extended pointers.
     2 * xlist.h - Trans-cluster double circular linked list, using extended pointers.
    33 *
    44 * Author : Alain Greiner (2016,2017,2018,2019)
Note: See TracChangeset for help on using the changeset viewer.