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/xlist.h

    r603 r610  
    55 * xlist.h - Double Circular Linked lists, using extended pointers.
    66 *
    7  * Author : Alain Greiner (2016)
     7 * Author : Alain Greiner (2016,2017,2018)
    88 *
    99 * Copyright (c) UPMC Sorbonne Universites
     
    3131#include <hal_kernel_types.h>
    3232#include <hal_remote.h>
     33#include <printk.h>
    3334
    3435/**** global variables ***/
     
    190191 * double linked list. Four extended pointers must be modified.
    191192 * The lock protecting the list should have been previously taken.
    192  * @ root   : extended pointer on the root xlist_entry_t
    193  * @ entry  : extended pointer on the xlist_entry_t to be inserted
    194  **************************************************************************/
    195 static inline void xlist_add_first( xptr_t root,
    196                                     xptr_t entry )
     193 * @ root_xp   : extended pointer on the root xlist_entry_t
     194 * @ entry_xp  : extended pointer on the xlist_entry_t to be inserted
     195 **************************************************************************/
     196static inline void xlist_add_first( xptr_t root_xp,
     197                                    xptr_t entry_xp )
    197198{
    198199    // get the extended pointer on the first element in list
    199     xptr_t first = (xptr_t)hal_remote_l64( root );
    200 
    201     // update root.next <= entry
    202     hal_remote_s64( root , (uint64_t)entry );
    203 
    204     // update entry.next <= first
    205     hal_remote_s64( entry , (uint64_t)first );
    206 
    207     // entry.pred <= root
    208     hal_remote_s64( entry + sizeof(xptr_t) , (uint64_t)root );
     200    xptr_t first_xp = hal_remote_l64( root_xp );
     201
     202    // update root_xp->next <= entry_xp
     203    hal_remote_s64( root_xp , entry_xp );
     204
     205    // update entry_xp->next <= first_xp
     206    hal_remote_s64( entry_xp , first_xp );
     207
     208    // update entry_xp->pred <= root_xp
     209    hal_remote_s64( entry_xp + sizeof(xptr_t) , root_xp );
    209210   
    210     // first.pred <= new
    211     hal_remote_s64( first + sizeof(xptr_t) , (uint64_t)entry );
     211    // update first_xp->pred <= entry_xp
     212    hal_remote_s64( first_xp + sizeof(xptr_t) , entry_xp );
    212213}
    213214
     
    216217 * double linked list.  Four extended pointers must be modified.
    217218 * The lock protecting the list should have been previously taken.
    218  * @ root   : extended pointer on the root xlist_entry_t
    219  * @ entry  : extended pointer on the xlist_entry_t to be inserted
    220  **************************************************************************/
    221 static inline void xlist_add_last( xptr_t root,
    222                                    xptr_t entry )
     219 * @ root_xp   : extended pointer on the root xlist_entry_t
     220 * @ entry_xp  : extended pointer on the xlist_entry_t to be inserted
     221 **************************************************************************/
     222static inline void xlist_add_last( xptr_t root_xp,
     223                                   xptr_t entry_xp )
    223224{
    224225    // get the extended pointer on the last element in list
    225     xptr_t last = (xptr_t)hal_remote_l64( root + sizeof(xptr_t) );
    226 
    227     // update root.pred <= entry
    228     hal_remote_s64( root + sizeof(xptr_t) , (uint64_t)entry );
    229 
    230     // update entry.pred <= last
    231     hal_remote_s64( entry + sizeof(xptr_t) , (uint64_t)last );
    232 
    233     // entry.next <= root
    234     hal_remote_s64( entry , (uint64_t)root );
     226    xptr_t last_xp = hal_remote_l64( root_xp + sizeof(xptr_t) );
     227
     228    // update root_xp->pred <= entry_xp
     229    hal_remote_s64( root_xp + sizeof(xptr_t) , entry_xp );
     230
     231    // update entry_xp->pred <= last_xp
     232    hal_remote_s64( entry_xp + sizeof(xptr_t) , last_xp );
     233
     234    // update entry_xp->next <= root_xp
     235    hal_remote_s64( entry_xp , root_xp );
    235236   
    236     // last.next <= entry
    237     hal_remote_s64( last , (uint64_t)entry );
     237    // update last_xp->next <= entry_xp
     238    hal_remote_s64( last_xp , entry_xp );
    238239}
    239240
     
    241242/***************************************************************************
    242243 * This function returns true if the list is empty.
    243  * @ root  : extended pointer on the root xlist_entry_t
    244  **************************************************************************/
    245 static inline bool_t xlist_is_empty( xptr_t root )
     244 * @ root_xp  : extended pointer on the root xlist_entry_t.
     245 **************************************************************************/
     246static inline bool_t xlist_is_empty( xptr_t root_xp )
    246247{
    247248    // get the extended pointer root.next value
    248     xptr_t next = (xptr_t)hal_remote_l64( root );
    249 
    250     return ( root == next );
     249    xptr_t next = (xptr_t)hal_remote_l64( root_xp );
     250
     251    return ( root_xp == next );
    251252}
    252253
     
    279280 * Four extended pointers must be modified.
    280281 * The memory allocated to the removed entry is not released.
    281  * @old      : extended pointer on the xlist_entry_t to be removed.
    282  * @new      : extended pointer on the xlist_entry_t to be inserted.
     282 * @ old      : extended pointer on the xlist_entry_t to be removed.
     283 * @ new      : extended pointer on the xlist_entry_t to be inserted.
    283284 **************************************************************************/
    284285static inline void xlist_replace( xptr_t old,
     
    307308}
    308309
     310/***************************************************************************
     311 * This debug function displays all entries of an xlist.
     312 * @ root_xp : extended pointer on the root xlist_entry_t.
     313 * @ string  : list identifier displayed in header.
     314 * @ max     : max number of éléments to display.
     315 **************************************************************************/
     316static inline void xlist_display( xptr_t  root_xp,
     317                                  char  * string,
     318                                  uint32_t max )
     319{
     320    cxy_t           root_cxy;
     321    xlist_entry_t * root_ptr;
     322
     323    xptr_t          iter_xp;
     324    cxy_t           iter_cxy;
     325    xlist_entry_t * iter_ptr;
     326
     327    xptr_t          next_xp;
     328    cxy_t           next_cxy;
     329    xlist_entry_t * next_ptr;
     330
     331    xptr_t          pred_xp;
     332    cxy_t           pred_cxy;
     333    xlist_entry_t * pred_ptr;
     334
     335    uint32_t        index;
     336
     337    root_cxy = GET_CXY( root_xp );
     338    root_ptr = GET_PTR( root_xp );
     339
     340    next_xp  = hal_remote_l64( XPTR( root_cxy , &root_ptr->next ) );
     341    next_cxy = GET_CXY( next_xp );
     342    next_ptr = GET_PTR( next_xp );
     343
     344    pred_xp  = hal_remote_l64( XPTR( root_cxy , &root_ptr->pred ) );
     345    pred_cxy = GET_CXY( pred_xp );
     346    pred_ptr = GET_PTR( pred_xp );
     347
     348    printk("\n***** root (%x,%x) / next (%x,%x) / pred (%x,%x) / %s *****\n",
     349    root_cxy, root_ptr, next_cxy, next_ptr, pred_cxy, pred_ptr, string );
     350
     351    if( xlist_is_empty( root_xp ) == false )
     352    {
     353        for( iter_xp = hal_remote_l64( XPTR( root_cxy , &root_ptr->next) ) , index = 0 ;
     354             (iter_xp != root_xp) && (index < max) ;
     355             iter_xp = next_xp , index++ )
     356        {
     357            iter_cxy = GET_CXY( iter_xp );
     358            iter_ptr = GET_PTR( iter_xp );
     359
     360            next_xp  = hal_remote_l64( XPTR( iter_cxy , &iter_ptr->next ) );
     361            next_cxy = GET_CXY( next_xp );
     362            next_ptr = GET_PTR( next_xp );
     363
     364            pred_xp  = hal_remote_l64( XPTR( iter_cxy , &iter_ptr->pred ) );
     365            pred_cxy = GET_CXY( pred_xp );
     366            pred_ptr = GET_PTR( pred_xp );
     367
     368            printk(" - %d : iter (%x,%x) / next (%x,%x) / pred (%x,%x)\n",
     369            index, iter_cxy, iter_ptr, next_cxy, next_ptr, pred_cxy, pred_ptr );
     370        }
     371    }
     372}  // end xlist_display()
     373
    309374#endif  /* _XLIST_H_ */
Note: See TracChangeset for help on using the changeset viewer.