Changeset 657 for trunk/kernel/fs/vfs.c


Ignore:
Timestamp:
Mar 18, 2020, 11:16:59 PM (4 years ago)
Author:
alain
Message:

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/fs/vfs.c

    r656 r657  
    33 *
    44 * Author  Mohamed Lamine Karaoui (2015)
    5  *         Alain Greiner (2016,2017,2018,2019)
     5 *         Alain Greiner (2016,2017,2018,2019,2020)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    3333#include <xhtab.h>
    3434#include <string.h>
    35 #include <rpc.h>
    3635#include <errno.h>
    3736#include <kmem.h>
     
    5958//////////////////////////////////////////////////////////////////////////////////////////
    6059
    61 ////////////////////////////////////////
    62 void vfs_ctx_init( vfs_fs_type_t   type,
    63                    uint32_t        attr,
     60///////////////////////////////////////
     61void vfs_ctx_init( cxy_t           cxy,
     62                   vfs_fs_type_t   fs_type,
    6463                       uint32_t        total_clusters,
    6564                       uint32_t        cluster_size,
     
    6766                   void          * extend )
    6867{
    69     vfs_ctx_t * vfs_ctx = &fs_context[type];
    70 
    71     vfs_ctx->type           = type;
    72     vfs_ctx->attr           = attr;
    73     vfs_ctx->total_clusters = total_clusters;
    74     vfs_ctx->cluster_size   = cluster_size;
    75     vfs_ctx->vfs_root_xp    = vfs_root_xp;
    76     vfs_ctx->extend         = extend;
    77 
    78     busylock_init( &vfs_ctx->lock , LOCK_VFS_CTX );
    79 
    80     bitmap_init( vfs_ctx->bitmap , BITMAP_SIZE(CONFIG_VFS_MAX_INODES) );
    81 }
    82 
    83 ////////////////////////////////////////////
    84 error_t vfs_ctx_inum_alloc( vfs_ctx_t * ctx,
     68    // get pointer on relevant VFS context (same in all clusters)
     69    vfs_ctx_t * vfs_ctx_ptr = &fs_context[fs_type];
     70
     71    // initialise VFS context fields
     72    hal_remote_s32( XPTR( cxy , &vfs_ctx_ptr->type           ) , fs_type );
     73    hal_remote_s32( XPTR( cxy , &vfs_ctx_ptr->total_clusters ) , total_clusters );
     74    hal_remote_s32( XPTR( cxy , &vfs_ctx_ptr->cluster_size   ) , cluster_size );
     75    hal_remote_s64( XPTR( cxy , &vfs_ctx_ptr->vfs_root_xp    ) , vfs_root_xp );
     76    hal_remote_spt( XPTR( cxy , &vfs_ctx_ptr->extend         ) , extend );
     77
     78    // initialize VFS context lock
     79    remote_busylock_init( XPTR( cxy , &vfs_ctx_ptr->lock ) , LOCK_VFS_CTX );
     80
     81    // initialize inum allocator
     82    bitmap_remote_init( XPTR( cxy , &vfs_ctx_ptr->bitmap ),
     83                        BITMAP_SIZE(CONFIG_VFS_MAX_INODES) );
     84
     85} // end vfs_ctx_init()
     86
     87///////////////////////////////////////////////
     88error_t vfs_ctx_inum_alloc( xptr_t      ctx_xp,
    8589                            uint32_t  * inum )
    8690{
     91    // get context cluster and local pointer
     92    cxy_t       ctx_cxy = GET_CXY( ctx_xp );
     93    vfs_ctx_t * ctx_ptr = GET_PTR( ctx_xp );
     94
     95    // build extended pointer on lock protecting the inum allocator
     96    xptr_t lock_xp = XPTR( ctx_cxy , &ctx_ptr->lock );
     97
     98    // build extended pointer on inum bitmap
     99    xptr_t bitmap_xp = XPTR( ctx_cxy , &ctx_ptr->bitmap );
     100
    87101    // get lock on inum allocator
    88     busylock_acquire( &ctx->lock );
     102    remote_busylock_acquire( lock_xp );
    89103
    90104    // get lid from local inum allocator
    91     uint32_t lid = bitmap_ffc( ctx->bitmap , CONFIG_VFS_MAX_INODES );
     105    uint32_t lid = bitmap_remote_ffc( bitmap_xp , CONFIG_VFS_MAX_INODES );
    92106
    93107    if( lid == 0xFFFFFFFF )   // no more free slot => error
    94108    {
    95109        // release lock
    96         busylock_release( &ctx->lock );
     110        remote_busylock_release( lock_xp );
    97111
    98112        // return error
    99         return 1;
     113        return -1;
    100114    }
    101115    else              // found => return inum
    102116    {
    103117        // set slot allocated
    104         bitmap_set( ctx->bitmap , lid );
     118        bitmap_remote_set( bitmap_xp , lid );
    105119
    106120        // release lock
    107         busylock_release( &ctx->lock );
     121        remote_busylock_release( lock_xp );
    108122
    109123        // return inum
     
    111125        return 0;
    112126    }
    113 }
    114 
    115 ////////////////////////////////////////////
    116 void vfs_ctx_inum_release( vfs_ctx_t * ctx,
    117                            uint32_t    inum )
    118 {
    119     bitmap_clear( ctx->bitmap , inum & 0xFFFF );
    120 }
     127}  // end vfs_ctx_inum_alloc()
     128
     129/////////////////////////////////////////////
     130void vfs_ctx_inum_release( xptr_t     ctx_xp,
     131                           uint32_t   inum )
     132{
     133    // get context cluster and local pointer
     134    cxy_t       ctx_cxy = GET_CXY( ctx_xp );
     135    vfs_ctx_t * ctx_ptr = GET_PTR( ctx_xp );
     136
     137    // build extended pointer on inum bitmap
     138    xptr_t bitmap_xp = XPTR( ctx_cxy , &ctx_ptr->bitmap );
     139
     140    // build extended pointer on lock
     141    xptr_t lock_xp = XPTR( ctx_cxy , &ctx_ptr->lock );
     142
     143    // get lock
     144    remote_busylock_acquire( lock_xp );
     145
     146    bitmap_remote_clear( bitmap_xp , inum & 0xFFFF );
     147
     148    // release lock
     149    remote_busylock_release( lock_xp );
     150
     151}  // end vfs_ctx_inum_release()
    121152
    122153//////////////////////////////////////////////////////////////////////////////////////////
     
    140171}
    141172
    142 ////////////////////////////////////////////////////
    143 error_t vfs_inode_create( vfs_fs_type_t     fs_type,
     173////////////////////////////////////////////////
     174error_t vfs_inode_create( cxy_t             cxy,
     175                          vfs_fs_type_t     fs_type,
    144176                          uint32_t          attr,
    145177                          uint32_t          rights,
     
    148180                          xptr_t          * inode_xp )
    149181{
    150     mapper_t         * mapper;     // associated mapper( to be allocated)
    151     vfs_inode_t      * inode;      // inode descriptor (to be allocated)
    152    
    153     uint32_t           inum;       // inode identifier (to be allocated)
    154     vfs_ctx_t        * ctx;        // file system context
    155         kmem_req_t         req;        // request to kernel memory allocator
     182    xptr_t             mapper_xp;    // extended pointer on associated mapper
     183    mapper_t         * mapper_ptr;   // local pointer on associated mapper
     184    vfs_inode_t      * inode_ptr;    // local pointer on allocated inode
     185    uint32_t           inum;         // inode identifier (to be allocated)
     186    vfs_ctx_t        * ctx;          // file system context
     187        kmem_req_t         req;          // request to kernel memory allocator
    156188    error_t            error;
    157189
     
    166198    }
    167199
    168     // allocate inum
    169     error = vfs_ctx_inum_alloc( ctx , &inum );
    170 
    171     if( error )
    172     {
    173         printk("\n[ERROR] in %s : cannot allocate inum\n", __FUNCTION__ );
    174         return -1;
    175     }
    176 
    177     // allocate memory for mapper
    178     mapper = mapper_create( fs_type );
    179 
    180     if( mapper == NULL )
    181     {
    182         printk("\n[ERROR] in %s : cannot allocate mapper\n", __FUNCTION__ );
    183         vfs_ctx_inum_release( ctx , inum );
    184         return ENOMEM;
    185     }
    186 
    187200// check inode descriptor contained in one page
    188201assert( (sizeof(vfs_inode_t) <= CONFIG_PPM_PAGE_SIZE),
    189202"inode descriptor must fit in one page" );
    190203
     204    // allocate inum
     205    error = vfs_ctx_inum_alloc( XPTR( cxy , ctx ) , &inum );
     206
     207    if( error )
     208    {
     209        printk("\n[ERROR] in %s : cannot allocate inum\n", __FUNCTION__ );
     210        return -1;
     211    }
     212
     213    // allocate memory for mapper in cluster cxy
     214    mapper_xp = mapper_create( cxy , fs_type );
     215
     216    if( mapper_xp == XPTR_NULL )
     217    {
     218        printk("\n[ERROR] in %s : cannot allocate mapper\n", __FUNCTION__ );
     219        vfs_ctx_inum_release( XPTR( cxy , ctx ) , inum );
     220        return -1;
     221    }
     222
     223    mapper_ptr = GET_PTR( mapper_xp );
     224
    191225    // allocate one page for VFS inode descriptor
    192     // because the embedded "children xhtab footprint
    193         req.type  = KMEM_PPM;
    194         req.order = 0;
    195     req.flags = AF_KERNEL | AF_ZERO;
    196         inode     = kmem_alloc( &req );
    197 
    198     if( inode == NULL )
     226    // because the embedded "children" xhtab footprint
     227        req.type   = KMEM_PPM;
     228        req.order  = 0;
     229    req.flags  = AF_KERNEL | AF_ZERO;
     230        inode_ptr  = kmem_remote_alloc( cxy , &req );
     231
     232    if( inode_ptr == NULL )
    199233    {
    200234        printk("\n[ERROR] in %s : cannot allocate inode descriptor\n", __FUNCTION__ );
    201         vfs_ctx_inum_release( ctx , inum );
    202         mapper_destroy( mapper );
     235        vfs_ctx_inum_release( XPTR( cxy , ctx ) , inum );
     236        mapper_destroy( mapper_xp );
    203237        return -1;
    204238    }
    205239
     240    // initialise inode field in mapper
     241    hal_remote_spt( XPTR( cxy , &mapper_ptr->inode ) , inode_ptr );
     242 
    206243    // initialize inode descriptor
    207     inode->type       = INODE_TYPE_FILE;     // default value
    208     inode->inum       = inum;
    209     inode->attr       = attr;
    210     inode->rights     = rights;
    211     inode->uid        = uid;
    212     inode->gid        = gid;
    213     inode->ctx        = ctx;
    214     inode->mapper     = mapper;
    215     inode->extend     = NULL;
    216     inode->links      = 0;
    217 
    218     // initialise inode field in mapper
    219     mapper->inode     = inode;
    220  
     244    hal_remote_s32( XPTR( cxy , &inode_ptr->type   ) , INODE_TYPE_FILE );  // default value
     245    hal_remote_s32( XPTR( cxy , &inode_ptr->inum   ) , inum ); 
     246    hal_remote_s32( XPTR( cxy , &inode_ptr->attr   ) , attr ); 
     247    hal_remote_s32( XPTR( cxy , &inode_ptr->rights ) , rights ); 
     248    hal_remote_s32( XPTR( cxy , &inode_ptr->links  ) , 0 );
     249    hal_remote_s32( XPTR( cxy , &inode_ptr->uid    ) , uid ); 
     250    hal_remote_s32( XPTR( cxy , &inode_ptr->gid    ) , gid ); 
     251    hal_remote_spt( XPTR( cxy , &inode_ptr->ctx    ) , ctx ); 
     252    hal_remote_spt( XPTR( cxy , &inode_ptr->mapper ) , mapper_ptr ); 
     253    hal_remote_spt( XPTR( cxy , &inode_ptr->extend ) , NULL ); 
     254
    221255    // initialize chidren dentries xhtab
    222     xhtab_init( &inode->children , XHTAB_DENTRY_TYPE );
     256    xhtab_init( XPTR( cxy , &inode_ptr->children ) , XHTAB_DENTRY_TYPE );
    223257
    224258    // initialize parents dentries xlist
    225     xlist_root_init( XPTR( local_cxy , &inode->parents ) );
     259    xlist_root_init( XPTR( cxy , &inode_ptr->parents ) );
    226260 
    227261    // initialize lock protecting size
    228     remote_rwlock_init( XPTR( local_cxy , &inode->size_lock ), LOCK_VFS_SIZE );
     262    remote_rwlock_init( XPTR( cxy , &inode_ptr->size_lock ), LOCK_VFS_SIZE );
    229263
    230264    // initialise lock protecting inode tree traversal
    231     remote_rwlock_init( XPTR( local_cxy , &inode->main_lock ), LOCK_VFS_MAIN );
     265    remote_rwlock_init( XPTR( cxy , &inode_ptr->main_lock ), LOCK_VFS_MAIN );
    232266
    233267    // return extended pointer on inode
    234     *inode_xp = XPTR( local_cxy , inode );
     268    *inode_xp = XPTR( cxy , inode_ptr );
    235269
    236270#if DEBUG_VFS_INODE_CREATE
     
    238272thread_t *     this       = CURRENT_THREAD;
    239273if( DEBUG_VFS_INODE_CREATE < cycle )
    240 printk("\n[%s] thread[%x,%x] created inode (%x,%x) / cycle %d\n",
    241 __FUNCTION__, this->process->pid, this->trdid, local_cxy, inode, cycle );
     274printk("\n[%s] thread[%x,%x] created inode (%x,%x) / ctx %x / fs_type %d / cycle %d\n",
     275__FUNCTION__, this->process->pid, this->trdid, cxy, inode_ptr, ctx, ctx->type, cycle );
    242276#endif
    243277 
     
    246280}  // end vfs_inode_create() 
    247281
    248 /////////////////////////////////////////////
    249 void vfs_inode_destroy( vfs_inode_t * inode )
    250 {
     282//////////////////////////////////////////
     283void vfs_inode_destroy( xptr_t  inode_xp )
     284{
     285    // get cluster and local pointer
     286    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     287    cxy_t         inode_cxy = GET_CXY( inode_xp );
     288
    251289    // release memory allocated for mapper
    252     mapper_destroy( inode->mapper );
    253 
    254     // release memory allocate for inode descriptor
     290    mapper_destroy( XPTR( inode_cxy , &inode_ptr->mapper ) );
     291
     292    // release memory allocated for inode descriptor
    255293        kmem_req_t req;
    256294        req.type  = KMEM_PPM;
    257         req.ptr   = inode;
    258         kmem_free( &req );
     295        req.ptr   = inode_ptr;
     296        kmem_remote_free( inode_cxy , &req );
    259297
    260298}  // end vfs_inode_destroy()
     
    339377   
    340378    // get inode cluster and local pointer
     379    inode_ptr = GET_PTR( inode_xp );
    341380    inode_cxy = GET_CXY( inode_xp );
    342     inode_ptr = GET_PTR( inode_xp );
    343381
    344382    // build extended pointer on parents dentries root
     
    367405}  // end vfs_inode_get_name()
    368406
    369 ///////////////////////////////////////////////////////
    370 error_t vfs_inode_load_all_pages( vfs_inode_t * inode )
    371 {
    372 
    373 assert( (inode != NULL) , "inode pointer is NULL" );
    374 
     407////////////////////////////////////////////////////
     408error_t vfs_inode_load_all_pages( xptr_t  inode_xp )
     409{
    375410    uint32_t   page_id;
    376411    xptr_t     page_xp;
    377412
    378     mapper_t * mapper = inode->mapper;
    379     uint32_t   size   = inode->size;
    380 
    381 assert( (mapper != NULL) , "mapper pointer is NULL" );
     413
     414    // get inode cluster and local pointer
     415    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     416    cxy_t         inode_cxy = GET_CXY( inode_xp );
     417
     418    // get pointer on mapper and size
     419    mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     420    uint32_t   size   = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->size ) );
    382421
    383422#if DEBUG_VFS_INODE_LOAD_ALL
     423char       name[CONFIG_VFS_MAX_NAME_LENGTH];
    384424uint32_t   cycle = (uint32_t)hal_get_cycles();
    385425thread_t * this  = CURRENT_THREAD;
    386 char       name[CONFIG_VFS_MAX_NAME_LENGTH];
    387 vfs_inode_get_name( XPTR( local_cxy , inode ) , name );
     426vfs_inode_get_name( inode_xp , name );
    388427if( DEBUG_VFS_INODE_LOAD_ALL < cycle )
    389428printk("\n[%s] thread[%x,%x] enter for <%s> in cluster %x / cycle %d\n",
    390 __FUNCTION__, this->process->pid, this->trdid, name, local_cxy, cycle );
     429__FUNCTION__, this->process->pid, this->trdid, name, inode_cxy, cycle );
    391430#endif
    392431
     
    400439        // If the mage is missing, this function allocates the missing page,
    401440        // and load the page from IOC device into mapper
    402         page_xp = mapper_remote_get_page( XPTR( local_cxy , mapper ), page_id );
     441        page_xp = mapper_get_page( XPTR( inode_cxy , mapper ), page_id );
    403442
    404443        if( page_xp == XPTR_NULL ) return -1;
     
    408447cycle = (uint32_t)hal_get_cycles();
    409448if( DEBUG_VFS_INODE_LOAD_ALL < cycle )
    410 printk("\n[%s] thread[%x,%x] exit for <%x> in cluster %x / cycle %d\n",
    411 __FUNCTION__, this->process->pid, this->trdid, name, local_cxy, cycle );
     449printk("\n[%s] thread[%x,%x] exit for <%s> in cluster %x\n",
     450__FUNCTION__, this->process->pid, this->trdid, name, inode_cxy );
    412451#endif
    413452
     
    425464    vfs_inode_get_name( inode_xp , name );
    426465
     466    // get inode cluster and local pointer
    427467    cxy_t         inode_cxy = GET_CXY( inode_xp );
    428468    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     
    461501//////////////////////////////////////////////////////////////////////////////////////////
    462502
    463 ///////////////////////////////////////////////////
    464 error_t vfs_dentry_create( vfs_fs_type_t   fs_type,
     503///////////////////////////////////////////////
     504error_t vfs_dentry_create( cxy_t           cxy,
     505                           vfs_fs_type_t   fs_type,
    465506                           char          * name,
    466507                           xptr_t        * dentry_xp )
    467508{
    468     vfs_ctx_t      * ctx;        // context descriptor
    469     vfs_dentry_t   * dentry;     // dentry descriptor (to be allocated)
    470         kmem_req_t       req;        // request to kernel memory allocator
     509        kmem_req_t       req;            // request to kernel memory allocator
     510    vfs_ctx_t      * ctx = NULL;     // context descriptor
     511    vfs_dentry_t   * dentry_ptr;     // dentry descriptor (to be allocated)
     512
     513#if DEBUG_VFS_DENTRY_CREATE
     514thread_t * this  = CURRENT_THREAD;
     515uint32_t   cycle = (uint32_t)hal_get_cycles();
     516if( DEBUG_VFS_DENTRY_CREATE < cycle )
     517printk("\n[%s] thread[%x,%x] enters for <%s> /  fs_type %x / cycle %d\n",
     518__FUNCTION__, this->process->pid, this->trdid, name, fs_type, cycle );
     519#endif
    471520
    472521    // get pointer on context
     
    476525    else
    477526    {
    478         ctx = NULL;
     527        printk("\n[ERROR] in %s undefined fs_type %d\n", __FUNCTION__, fs_type );
    479528        return -1;
    480529    }
     
    483532    uint32_t length = strlen( name );
    484533
    485     if( length >= CONFIG_VFS_MAX_NAME_LENGTH ) return EINVAL;
     534    if( length >= CONFIG_VFS_MAX_NAME_LENGTH ) return -1;
    486535
    487536    // allocate memory for dentry descriptor
    488         req.type  = KMEM_KCM;
    489         req.order = bits_log2( sizeof(vfs_dentry_t) );
    490     req.flags = AF_KERNEL | AF_ZERO;
    491         dentry    = kmem_alloc( &req );
    492 
    493     if( dentry == NULL )
     537        req.type   = KMEM_KCM;
     538        req.order  = bits_log2( sizeof(vfs_dentry_t) );
     539    req.flags  = AF_KERNEL | AF_ZERO;
     540        dentry_ptr = kmem_remote_alloc( cxy , &req );
     541
     542    if( dentry_ptr == NULL )
    494543    {
    495544        printk("\n[ERROR] in %s : cannot allocate dentry descriptor\n",
     
    499548
    500549    // initialize dentry descriptor
    501     dentry->ctx     = ctx;
    502     dentry->length  = length;
    503     dentry->extend  = NULL;
    504     strcpy( dentry->name , name );
     550    hal_remote_spt( XPTR( cxy , &dentry_ptr->ctx    ) , ctx );
     551    hal_remote_s32( XPTR( cxy , &dentry_ptr->length ) , length );
     552    hal_remote_spt( XPTR( cxy , &dentry_ptr->extend ) , NULL );
     553
     554    // register name
     555    hal_remote_strcpy( XPTR( cxy, dentry_ptr->name ),
     556                       XPTR( local_cxy, name ) );
    505557
    506558    // return extended pointer on dentry
    507     *dentry_xp = XPTR( local_cxy , dentry );
     559    *dentry_xp = XPTR( cxy , dentry_ptr );
    508560
    509561#if DEBUG_VFS_DENTRY_CREATE
    510 thread_t * this  = CURRENT_THREAD;
    511 uint32_t   cycle = (uint32_t)hal_get_cycles();
    512562if( DEBUG_VFS_DENTRY_CREATE < cycle )
    513 printk("\n[%s] thread[%x,%x] created dentry <%s> : (%x,%x) / cycle %d\n",
    514 __FUNCTION__, this->process->pid, this->trdid, name, local_cxy, dentry, cycle );
     563printk("\n[%s] thread[%x,%x] exit for <%s> / dentry (%x,%x)\n",
     564__FUNCTION__, this->process->pid, this->trdid, name, cxy, dentry_ptr );
    515565#endif
    516566
     
    519569}  // end vfs_dentry_create()
    520570
    521 ////////////////////////////////////////////////
    522 void vfs_dentry_destroy( vfs_dentry_t * dentry )
    523 {
     571////////////////////////////////////////////
     572void vfs_dentry_destroy( xptr_t  dentry_xp )
     573{
     574    // get cluster and local pointer
     575    vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp );
     576    cxy_t          dentry_cxy = GET_CXY( dentry_xp );
     577 
    524578    // release memory allocated to dentry
    525579        kmem_req_t req;
    526580        req.type  = KMEM_KCM;
    527         req.ptr   = dentry;
    528         kmem_free( &req );
     581        req.ptr   = dentry_ptr;
     582        kmem_remote_free( dentry_cxy , &req );
    529583
    530584}  // end vfs_dentry_destroy()
     
    536590
    537591/////////////////////////////////////////////
    538 error_t vfs_file_create( vfs_inode_t * inode,
    539                          uint32_t      attr,
    540                          xptr_t      * file_xp )
    541 {
    542     vfs_file_t  * file;
     592error_t vfs_file_create( xptr_t     inode_xp,
     593                         uint32_t   attr,
     594                         xptr_t   * file_xp )
     595{
     596    vfs_file_t  * file_ptr;
    543597        kmem_req_t    req;
     598    uint32_t      type;
     599    mapper_t    * mapper;
     600    vfs_ctx_t   * ctx;
     601
     602    // get inode cluster and local pointer
     603    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     604    cxy_t         inode_cxy = GET_CXY( inode_xp );
    544605
    545606#if DEBUG_VFS_FILE_CREATE
     
    547608uint32_t cycle = (uint32_t)hal_get_cycles();
    548609if( DEBUG_VFS_OPEN < cycle )
    549 printk("\n[%s] thread[%x,%x] enter for inode %x in cluster %x / cycle %d\n",
    550 __FUNCTION__, this->process->pid, this->trdid, inode, local_cxy, cycle );
     610printk("\n[%s] thread[%x,%x] enter for inode (%x,%x) / cycle %d\n",
     611__FUNCTION__, this->process->pid, this->trdid, inode_cxy, inode_ptr, cycle );
    551612#endif
    552613
     
    555616        req.order = bits_log2( sizeof(vfs_file_t) );
    556617    req.flags = AF_KERNEL | AF_ZERO;
    557         file      = kmem_alloc( &req );
    558 
    559     if( file == NULL ) return ENOMEM;
     618        file_ptr  = kmem_remote_alloc( inode_cxy , &req );
     619
     620    if( file_ptr == NULL ) return -1;
     621
     622    // get type, ctx and mapper from inode descriptor
     623    type   = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) );
     624    ctx    = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->ctx ) );
     625    mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
    560626
    561627    // initializes new file descriptor
    562     file->gc       = 0;
    563     file->type     = inode->type;
    564     file->attr     = attr;
    565     file->offset   = 0;
    566     file->refcount = 1;
    567     file->inode    = inode;
    568     file->ctx      = inode->ctx;
    569     file->mapper   = inode->mapper;
    570 
    571     remote_rwlock_init( XPTR( local_cxy , &file->lock ), LOCK_VFS_FILE );
    572 
    573     *file_xp = XPTR( local_cxy , file );
     628    hal_remote_s32( XPTR( inode_cxy , &file_ptr->type     ) , type );
     629    hal_remote_s32( XPTR( inode_cxy , &file_ptr->attr     ) , attr );
     630    hal_remote_s32( XPTR( inode_cxy , &file_ptr->offset   ) , 0 );
     631    hal_remote_s32( XPTR( inode_cxy , &file_ptr->refcount ) , 1 );
     632    hal_remote_spt( XPTR( inode_cxy , &file_ptr->inode    ) , inode_ptr );
     633    hal_remote_spt( XPTR( inode_cxy , &file_ptr->ctx      ) , ctx );
     634    hal_remote_spt( XPTR( inode_cxy , &file_ptr->mapper   ) , mapper );
     635
     636    remote_rwlock_init( XPTR( inode_cxy , &file_ptr->lock ), LOCK_VFS_FILE );
     637
     638    *file_xp = XPTR( inode_cxy , file_ptr );
    574639
    575640#if DEBUG_VFS_FILE_CREATE
    576641cycle = (uint32_t)hal_get_cycles();
    577642if( DEBUG_VFS_OPEN < cycle )
    578 printk("\n[%s] thread[%x,%x] created file %x in cluster %x / cycle %d\n",
    579 __FUNCTION__, this->process->pid, this->trdid, file, local_cxy, cycle );
     643printk("\n[%s] thread[%x,%x] created file (%x,%x) %x\n",
     644__FUNCTION__, this->process->pid, this->trdid, inode_cxy, file_ptr, cycle );
    580645#endif
    581646
     
    584649}  // end vfs_file_create()
    585650
    586 ///////////////////////////////////////////
    587 void vfs_file_destroy( vfs_file_t *  file )
    588 {
     651////////////////////////////////////////
     652void vfs_file_destroy( xptr_t  file_xp )
     653{
     654    // get file cluster and local pointer
     655    vfs_file_t * file_ptr = GET_PTR( file_xp );
     656    cxy_t        file_cxy = GET_CXY( file_xp );
     657
     658    // release file descriptor
    589659        kmem_req_t req;
    590660        req.type  = KMEM_KCM;
    591         req.ptr   = file;
    592         kmem_free( &req );
     661        req.ptr   = file_ptr;
     662        kmem_remote_free( file_cxy , &req );
    593663
    594664#if DEBUG_VFS_CLOSE
    595665char name[CONFIG_VFS_MAX_NAME_LENGTH];
    596 vfs_file_get_name( XPTR( local_cxy , file ) , name );
     666vfs_file_get_name( file_xp , name );
    597667thread_t * this = CURRENT_THREAD;
    598668uint32_t cycle = (uint32_t)hal_get_cycles();
    599669if( DEBUG_VFS_CLOSE < cycle )
    600670printk("\n[%s] thread[%x,%x] deleted file <%s> in cluster %x / cycle %d\n",
    601 __FUNCTION__, this->process->pid, this->trdid, name, local_cxy, cycle );
     671__FUNCTION__, this->process->pid, this->trdid, name, file_cxy, cycle );
    602672#endif
    603673
     
    738808
    739809    // create a new file descriptor in cluster containing inode
    740     if( inode_cxy == local_cxy )      // target cluster is local
    741     {
    742         error = vfs_file_create( inode_ptr , file_attr , &file_xp );
    743     }
    744     else                              // target cluster is remote
    745     {
    746         rpc_vfs_file_create_client( inode_cxy , inode_ptr , file_attr , &file_xp , &error );
    747     }
     810    error = vfs_file_create( inode_xp , file_attr , &file_xp );
    748811
    749812    if( error )  return error;
     
    764827cycle = (uint32_t)hal_get_cycles();
    765828if( DEBUG_VFS_OPEN < cycle )
    766 printk("\n[%s] thread[%x,%x] exit for <%s> / fdid %d / cxy %x / cycle %d\n",
    767 __FUNCTION__, process->pid, this->trdid, path, file_id, GET_CXY( file_xp ), cycle );
     829printk("\n[%s] thread[%x,%x] exit for <%s> / fdid %d / file(%x,%x) / cycle %d\n",
     830__FUNCTION__, process->pid, this->trdid, path, file_id,
     831GET_CXY( file_xp ), GET_PTR( file_xp ), cycle );
    768832#endif
    769833
     
    880944    __FUNCTION__ , this->process->pid, nbytes );
    881945    else           
    882     printk("\n[%s] thread[%x,%x] exit / %d bytes moved from buffer to mapper / size %d\n",
    883     __FUNCTION__ , this->process->pid, nbytes, hal_remote_l32(XPTR(file_cxy,&inode->size)) );
     946    printk("\n[%s] thread[%x,%x] exit / %d bytes moved from buffer to mapper\n",
     947    __FUNCTION__ , this->process->pid, nbytes );
    884948}
    885949#endif
     
    10351099{
    10361100    cxy_t         file_cxy;         // cluster containing the file descriptor.
    1037     vfs_file_t  * file_ptr;         // local ponter on file descriptor
     1101    vfs_file_t  * file_ptr;         // local pointer on file descriptor
    10381102    cxy_t         owner_cxy;        // process owner cluster
    10391103    pid_t         pid;              // process identifier
     
    10761140
    10771141    // copy all dirty pages from mapper to device
    1078     if( file_cxy == local_cxy )
    1079     {
    1080         error = mapper_sync( mapper_ptr );
    1081     }
    1082     else
    1083     {
    1084         rpc_mapper_sync_client( file_cxy,
    1085                                 mapper_ptr,
    1086                                 &error );
    1087     }
     1142    error = mapper_sync( XPTR( file_cxy , mapper_ptr ) );
    10881143
    10891144    if( error )
     
    11281183 
    11291184        // update dentry size in parent directory mapper
    1130         if( parent_cxy == local_cxy )
    1131         {
    1132             error = vfs_fs_update_dentry( parent_inode_ptr,
    1133                                           parent_dentry_ptr,
    1134                                           size );
    1135         }
    1136         else
    1137         {
    1138             rpc_vfs_fs_update_dentry_client( parent_cxy,
    1139                                              parent_inode_ptr,
    1140                                              parent_dentry_ptr,
    1141                                              size,
    1142                                              &error );
    1143         }
     1185        error = vfs_fs_update_dentry( XPTR( parent_cxy , parent_inode_ptr ),
     1186                                      parent_dentry_ptr );
    11441187
    11451188        if( error )
     
    11591202
    11601203        // copy all dirty pages from parent mapper to device
    1161         if( parent_cxy == local_cxy )
    1162         {
    1163             error = mapper_sync( parent_mapper_ptr );
    1164         }
    1165         else
    1166         {
    1167             rpc_mapper_sync_client( parent_cxy,
    1168                                     parent_mapper_ptr,
    1169                                     &error );
    1170         }
     1204        error = mapper_sync( XPTR( parent_cxy , parent_mapper_ptr ) );
    11711205
    11721206        if( error )
     
    12221256    //////// 4) release memory allocated to file descriptor in remote cluster
    12231257
    1224     if( file_cxy == local_cxy )             // file cluster is local
    1225     {
    1226         vfs_file_destroy( file_ptr );
    1227     }
    1228     else                                    // file cluster is local
    1229     {
    1230         rpc_vfs_file_destroy_client( file_cxy , file_ptr );
    1231     }
     1258    vfs_file_destroy( file_xp );
    12321259
    12331260#if DEBUG_VFS_CLOSE
     
    13201347
    13211348    // 2. create one new dentry in parent cluster
    1322     if( parent_cxy == local_cxy ) 
    1323     {
    1324         error = vfs_dentry_create( parent_fs_type,
    1325                                    last_name,
    1326                                    &dentry_xp );
    1327     }
    1328     else
    1329     {
    1330         rpc_vfs_dentry_create_client( parent_cxy,
    1331                                       parent_fs_type,
    1332                                       last_name,
    1333                                       &dentry_xp,
    1334                                       &error );
    1335     }
    1336 
     1349    error = vfs_dentry_create( parent_cxy,
     1350                               parent_fs_type,
     1351                               last_name,
     1352                               &dentry_xp );
    13371353    if( error )
    13381354    {
     
    13611377    inode_cxy = cluster_random_select();
    13621378   
    1363     if( inode_cxy == local_cxy )      // target cluster is local
    1364     {
    1365         error = vfs_inode_create( parent_fs_type,
    1366                                   attr,
    1367                                   rights,
    1368                                   uid,
    1369                                   gid,
    1370                                   &inode_xp );
    1371     }
    1372     else                              // target cluster is remote
    1373     {
    1374         rpc_vfs_inode_create_client( inode_cxy,
    1375                                      parent_fs_type,
    1376                                      attr,
    1377                                      rights,
    1378                                      uid,
    1379                                      gid,
    1380                                      &inode_xp,
    1381                                      &error );
    1382     }
    1383                                      
     1379    // create inode
     1380    error = vfs_inode_create( inode_cxy,
     1381                              parent_fs_type,
     1382                              attr,
     1383                              rights,
     1384                              uid,
     1385                              gid,
     1386                              &inode_xp );
    13841387    if( error )
    13851388    {
    13861389        remote_rwlock_wr_release( lock_xp );
    13871390        printk("\n[ERROR] in %s : cannot create new inode in cluster %x for <%s>\n",
    1388                __FUNCTION__ , inode_cxy , path );
    1389         if( parent_cxy == local_cxy ) vfs_dentry_destroy( dentry_ptr );
    1390         else rpc_vfs_dentry_destroy_client( parent_cxy , dentry_ptr );
     1391         __FUNCTION__ , inode_cxy , path );
     1392        vfs_dentry_destroy( dentry_xp );
    13911393        return -1;
    13921394    }
     
    14341436        remote_rwlock_wr_release( lock_xp );
    14351437        printk("\n[ERROR] in %s : cannot create new inode in cluster %x for <%s>\n",
    1436                __FUNCTION__ , inode_cxy , path );
    1437         if( parent_cxy == local_cxy ) vfs_dentry_destroy( dentry_ptr );
    1438         else rpc_vfs_dentry_destroy_client( parent_cxy , dentry_ptr );
     1438        __FUNCTION__ , inode_cxy , path );
     1439        vfs_dentry_destroy( dentry_xp );
    14391440        return -1;
    14401441    }
     
    14451446    // 8. update parent directory mapper
    14461447    //    and synchronize the parent directory on IOC device
    1447     if (parent_cxy == local_cxy)
    1448     {
    1449         error = vfs_fs_add_dentry( parent_ptr,
    1450                                    dentry_ptr );
    1451     }
    1452     else
    1453     {
    1454         rpc_vfs_fs_add_dentry_client( parent_cxy,
    1455                                       parent_ptr,
    1456                                       dentry_ptr,
    1457                                       &error );
    1458     }
    1459 
     1448    error = vfs_fs_add_dentry( parent_xp,
     1449                               dentry_ptr );
    14601450    if( error )
    14611451    {
     
    15891579    {
    15901580        // 1. create one new dentry
    1591         if( new_parent_cxy == local_cxy ) 
    1592         {
    1593             error = vfs_dentry_create( inode_fs_type,
    1594                                        new_name,
    1595                                        &dentry_xp );
    1596         }
    1597         else
    1598         {
    1599             rpc_vfs_dentry_create_client( new_parent_cxy,
    1600                                           inode_fs_type,
    1601                                           new_name,
    1602                                           &dentry_xp,
    1603                                           &error );
    1604         }
    1605 
     1581        error = vfs_dentry_create( new_parent_cxy,
     1582                                   inode_fs_type,
     1583                                   new_name,
     1584                                   &dentry_xp );
    16061585        if( error )
    16071586        {
     
    16431622        //    and synchronize the parent directory on IOC device
    16441623        if (new_parent_cxy == local_cxy)
    1645         {
    1646             error = vfs_fs_add_dentry( new_parent_ptr,
    1647                                        dentry_ptr );
    1648         }
    1649         else
    1650         {
    1651             rpc_vfs_fs_add_dentry_client( new_parent_cxy,
    1652                                           new_parent_ptr,
    1653                                           dentry_ptr,
    1654                                           &error );
    1655         }
     1624        error = vfs_fs_add_dentry( new_parent_xp,
     1625                                   dentry_ptr );
    16561626        if( error )
    16571627        {
     
    17031673    vfs_fs_type_t     fs_type;            // File system type
    17041674
    1705     char              name[CONFIG_VFS_MAX_NAME_LENGTH];  // name of link to remove
     1675    char              child_name[CONFIG_VFS_MAX_NAME_LENGTH];   // name of link to remove
     1676    char              parent_name[CONFIG_VFS_MAX_NAME_LENGTH];  // name of parent directory
    17061677
    17071678    thread_t  * this    = CURRENT_THREAD;
     
    17311702                        VFS_LOOKUP_PARENT,
    17321703                        &parent_xp,
    1733                         name );
     1704                        child_name );
    17341705    if( error )
    17351706    {
    17361707        remote_rwlock_wr_release( lock_xp );
    17371708        printk("\n[ERROR] in %s : cannot get parent inode for <%s> in <%s>\n",
    1738         __FUNCTION__, name, path );
     1709        __FUNCTION__, child_name, path );
    17391710        return -1;
    17401711    }
    1741 
    1742     // get parent inode cluster and local pointer
     1712   
     1713    // get parent inode name, cluster and local pointer
     1714    vfs_inode_get_name( parent_xp , parent_name );
    17431715    parent_cxy = GET_CXY( parent_xp );
    17441716    parent_ptr = GET_PTR( parent_xp );
    17451717 
    17461718#if( DEBUG_VFS_UNLINK & 1 )
    1747 char parent_name[CONFIG_VFS_MAX_NAME_LENGTH];
    1748 vfs_inode_get_name( parent_xp , parent_name );
    17491719if( DEBUG_VFS_UNLINK < cycle )
    17501720printk("\n[%s] thread[%x,%x] : parent inode <%s> is (%x,%x)\n",
     
    17561726
    17571727    // try to get extended pointer on dentry from Inode Tree
    1758     dentry_xp = xhtab_lookup( children_xp , name );
     1728    dentry_xp = xhtab_lookup( children_xp , child_name );
    17591729   
    1760     // when dentry not found in Inode Tree, try to get it from inode tree
     1730    // when dentry not found in Inode Tree, try to get it from mapper
    17611731
    17621732    if( dentry_xp == XPTR_NULL )           // miss target dentry in Inode Tree
     
    17651735#if( DEBUG_VFS_UNLINK & 1 )
    17661736if( DEBUG_VFS_UNLINK < cycle )
    1767 printk("\n[%s] thread[%x,%x] : inode <%s> not found => scan parent mapper\n",
    1768 __FUNCTION__, process->pid, this->trdid, name );
     1737printk("\n[%s] thread[%x,%x] : inode <%s> not found => scan parent mapper <%s>\n",
     1738__FUNCTION__, process->pid, this->trdid, child_name , parent_name );
    17691739#endif
    17701740        // get parent inode FS type
     
    17791749                                         fs_type,
    17801750                                         parent_xp,
    1781                                          name,
     1751                                         child_name,
    17821752                                         &dentry_xp,
    17831753                                         &inode_xp );
    17841754        if( error )
    17851755        {
    1786             printk("\n[ERROR] in %s : cannot create inode <%s> in path <%s>\n",
    1787             __FUNCTION__ , name, path );
    1788 
    1789             vfs_remove_child_from_parent( dentry_xp );
     1756            printk("\n[ERROR] in %s : cannot create inode <%s> in Inode Tree\n",
     1757            __FUNCTION__ , child_name );
    17901758            return -1;
    17911759        }
     
    17971765        // scan parent mapper to find the missing dentry, and complete
    17981766        // initialisation of new dentry and new inode descriptors In Inode Tree
    1799         if( parent_cxy == local_cxy )
     1767        error = vfs_fs_new_dentry_from_mapper( parent_xp,
     1768                                               dentry_ptr );
     1769        if ( error )
    18001770        {
    1801             error = vfs_fs_new_dentry( parent_ptr,
    1802                                        name,
    1803                                        inode_xp );
    1804         }
    1805         else
    1806         {
    1807             rpc_vfs_fs_new_dentry_client( parent_cxy,
    1808                                           parent_ptr,
    1809                                           name,
    1810                                           inode_xp,
    1811                                           &error );
    1812         }
    1813 
    1814         if ( error )   // dentry not found in parent mapper
    1815         {
    1816             printk("\n[ERROR] in %s : cannot get dentry <%s> in path <%s>\n",
    1817             __FUNCTION__ , name, path );
     1771            printk("\n[ERROR] in %s : cannot get entry <%s> in parent <%s> mapper\n",
     1772            __FUNCTION__ , child_name, parent_name );
    18181773            return -1;
    18191774        }
     
    18221777if( DEBUG_VFS_UNLINK < cycle )
    18231778printk("\n[%s] thread[%x,%x] : created missing inode & dentry <%s> in cluster %x\n",
    1824 __FUNCTION__, process->pid, this->trdid, name, inode_cxy );
     1779__FUNCTION__, process->pid, this->trdid, child_name, inode_cxy );
    18251780#endif
    18261781
     
    18561811if( DEBUG_VFS_UNLINK < cycle )
    18571812printk("\n[%s] thread[%x,%x] : unlink inode <%s> / type %s / %d links\n",
    1858 __FUNCTION__, process->pid, this->trdid, name, vfs_inode_type_str(inode_type), inode_links );
     1813__FUNCTION__, process->pid, this->trdid, child_name,
     1814vfs_inode_type_str(inode_type), inode_links );
    18591815#endif
    18601816
     
    18981854        // 2. update parent directory mapper
    18991855        //    and synchronize the parent directory on IOC device
    1900         if (parent_cxy == local_cxy)
    1901         {
    1902             error = vfs_fs_remove_dentry( parent_ptr,
    1903                                           dentry_ptr );
    1904         }
    1905         else           
    1906         {
    1907             rpc_vfs_fs_remove_dentry_client( parent_cxy,
    1908                                              parent_ptr,
    1909                                              dentry_ptr,
    1910                                              &error );
    1911         }
    1912 
     1856        error = vfs_fs_remove_dentry( parent_xp,
     1857                                      dentry_ptr );
    19131858        if( error )
    19141859        {
     
    21722117
    21732118//////////////////////////////////////////////////////////////////////////
    2174 // This static function is called by the vfs_display() function.
     2119// This recursive function is called by the vfs_display() function.
    21752120// that is supposed to take the TXT0 lock.
    21762121//////////////////////////////////////////////////////////////////////////
     
    21842129    uint32_t           inode_size;
    21852130    uint32_t           inode_attr;
    2186     uint32_t           inode_dirty;
    21872131    void             * inode_extd;
    21882132
     
    22342178
    22352179    // compute dirty
    2236     inode_dirty = ((inode_attr & INODE_ATTR_DIRTY) != 0);
     2180    // inode_dirty = ((inode_attr & INODE_ATTR_DIRTY) != 0); unused [AG] dec 2019
    22372181
    22382182    // display inode
    2239     nolock_printk("%s<%s> : %s / extd %x / %d bytes / dirty %d / cxy %x / inode %x / mapper %x\n",
     2183    nolock_printk("%s<%s> : %s / extd %x / %d bytes / cxy %x / inode %x / mapper %x\n",
    22402184    indent_str[indent], name, vfs_inode_type_str( inode_type ), (uint32_t)inode_extd,
    2241     inode_size, inode_dirty, inode_cxy, inode_ptr, mapper_ptr );
     2185    inode_size, inode_cxy, inode_ptr, mapper_ptr );
    22422186
    22432187    // scan directory entries when current inode is a directory
     
    23282272
    23292273    // print header
    2330     nolock_printk("\n***** file system state\n\n");
     2274    nolock_printk("\n***** current VFS state\n\n");
    23312275
    23322276    // call recursive function
     
    24842428    vfs_inode_t      * parent_ptr;   // local pointer on parent inode 
    24852429    xptr_t             dentry_xp;    // extended pointer on dentry       
     2430    vfs_dentry_t     * dentry_ptr;   // local pointer on dentry
    24862431    xptr_t             child_xp;     // extended pointer on child inode
    24872432    cxy_t              child_cxy;    // cluster for child inode
     
    25322477    last      = false;
    25332478    child_xp  = XPTR_NULL;
     2479    child_cxy = 0;
     2480    child_ptr = NULL;
    25342481
    25352482    // loop on nodes in pathname
     
    25702517                               &child_xp );
    25712518
    2572         // get child inode local pointer and cluster
    2573         child_ptr  = GET_PTR( child_xp );
    2574         child_cxy  = GET_CXY( child_xp );
    2575 
    2576         if( found == false )                              // not found in Inode Tree
     2519        if( found == false )                          // child not found in Inode Tree
    25772520        {
    25782521            // when a inode is not found in the Inode Tree:
     
    26062549#endif
    26072550                // get parent inode FS type
    2608                 ctx_ptr    = hal_remote_lpt( XPTR( parent_cxy,&parent_ptr->ctx ) );
     2551                ctx_ptr    = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->ctx ) );
    26092552                fs_type    = hal_remote_l32( XPTR( parent_cxy , &ctx_ptr->type ) );
    26102553
     
    26262569                }
    26272570
    2628                 // get child inode local pointer
    2629                 child_ptr = GET_PTR( child_xp );
     2571                // get child inode and dentry local pointers
     2572                child_ptr  = GET_PTR( child_xp );
     2573                dentry_ptr = GET_PTR( dentry_xp );
    26302574
    26312575#if (DEBUG_VFS_LOOKUP & 1)
     
    26362580                // scan parent mapper to find the missing dentry, and complete
    26372581                // the initialisation of dentry and child inode descriptors
    2638                 if( parent_cxy == local_cxy )
    2639                 {
    2640                     error = vfs_fs_new_dentry( parent_ptr,
    2641                                                name,
    2642                                                child_xp );
    2643                 }
    2644                 else
    2645                 {
    2646                     rpc_vfs_fs_new_dentry_client( parent_cxy,
    2647                                                   parent_ptr,
    2648                                                   name,
    2649                                                   child_xp,
    2650                                                   &error );
    2651                 }
    2652 
    2653                 // when the missing dentry is not in the parent mapper,
    2654                 // a new dentry must be registered in parent directory mapper
    2655                 if ( error )
     2582                error = vfs_fs_new_dentry_from_mapper( parent_xp,
     2583                                                       dentry_ptr );
     2584
     2585                if ( error )  // an error can be fatal or non-fatal :
    26562586                {
    26572587                    if ( last && create )  // add a brand new dentry in parent directory
    26582588                    {
    2659                         error = vfs_new_dentry_init( parent_xp,               
    2660                                                      dentry_xp,
    2661                                                      child_xp );
     2589                        error = vfs_fs_new_dentry_to_mapper( parent_xp,               
     2590                                                             dentry_ptr );
    26622591                        if ( error )
    26632592                        {
    2664                             printk("\n[ERROR] in %s : cannot init inode <%s> in path <%s>\n",
    2665                             __FUNCTION__, name, pathname );
     2593                            printk("\n[ERROR] in %s : cannot add dentry <%s> in parent dir\n",
     2594                            __FUNCTION__, name );
    26662595                            vfs_remove_child_from_parent( dentry_xp );
    26672596                            return -1;
     
    26742603vfs_inode_display( child_xp );
    26752604#endif
    2676 
    2677 
    26782605                    }
    26792606                    else                   // not last or not create => error
     
    27042631                    if( type == INODE_TYPE_DIR )
    27052632                    {
    2706                         if( child_cxy == local_cxy )
    2707                         {
    2708                             error = vfs_inode_load_all_pages( child_ptr );
    2709                         }
    2710                         else
    2711                         {
    2712                             rpc_vfs_inode_load_all_pages_client( child_cxy,
    2713                                                                  child_ptr,
    2714                                                                  &error );
    2715                         }
     2633                        error = vfs_inode_load_all_pages( child_xp );
     2634
    27162635                        if ( error )
    27172636                        {
     
    27312650            }
    27322651        }
    2733         else                                    // child directly found in inode tree
     2652        else                                    // child found in Inode Tree
    27342653        {
     2654            // get child inode local pointer and cluster
     2655            child_ptr  = GET_PTR( child_xp );
     2656            child_cxy  = GET_CXY( child_xp );
    27352657       
    27362658#if (DEBUG_VFS_LOOKUP & 1)
     
    27592681        // }
    27602682
    2761         // take lock on child inode and release lock on parent
    2762         // vfs_inode_lock( child_xp );
    2763         // vfs_inode_unlock( parent_xp );
    2764 
    27652683        // exit when last
    27662684        if ( last )           // last inode in path  => return relevant info
     
    27922710            }
    27932711        }
    2794         else                     // not the last inode in path => update loop variables
     2712        else                     // not the last node in path => update loop variables
    27952713        {
    27962714            parent_xp = child_xp;
    27972715            current   = next;
    27982716        }
    2799     }
     2717    }  // end while loop on nodes in pathname
     2718
     2719#if ( DEBUG_VFS_LOOKUP & 1 )
     2720if( DEBUG_VFS_LOOKUP < cycle )
     2721vfs_display( root_xp );
     2722#endif
    28002723
    28012724    return 0;
    28022725
    28032726}  // end vfs_lookup()
    2804 
    2805 ////////////////////////////////////////////////
    2806 error_t vfs_new_dentry_init( xptr_t   parent_xp,
    2807                              xptr_t   dentry_xp,
    2808                              xptr_t   child_xp )
    2809 {
    2810     error_t     error;
    2811     uint32_t    cluster_id;
    2812     uint32_t    child_type;
    2813     uint32_t    child_size;
    2814 
    2815 #if DEBUG_VFS_NEW_DENTRY_INIT
    2816 char parent_name[CONFIG_VFS_MAX_NAME_LENGTH];
    2817 char child_name[CONFIG_VFS_MAX_NAME_LENGTH];
    2818 vfs_inode_get_name( parent_xp , parent_name );
    2819 vfs_inode_get_name( child_xp  , child_name );
    2820 uint32_t   cycle = (uint32_t)hal_get_cycles();
    2821 thread_t * this  = CURRENT_THREAD;
    2822 if( DEBUG_VFS_NEW_DENTRY_INIT < cycle )
    2823 printk("\n[%s] thread[%x,%x] enter / parent <%s> / child <%s> / cycle %d\n",
    2824 __FUNCTION__ , this->process->pid, this->trdid, parent_name, child_name, cycle );
    2825 #endif
    2826 
    2827     // get parent inode cluster and local pointer
    2828     cxy_t          parent_cxy = GET_CXY( parent_xp );
    2829     vfs_inode_t  * parent_ptr = GET_PTR( parent_xp );
    2830 
    2831     // get dentry local pointer
    2832     vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp );
    2833 
    2834     // get child inode cluster and local pointer
    2835     cxy_t          child_cxy  = GET_CXY( child_xp );
    2836     vfs_inode_t  * child_ptr  = GET_PTR( child_xp );
    2837 
    2838     // 1. allocate one free cluster_id in file system to child inode,
    2839     // and update the File Allocation Table in both the FAT mapper and IOC device.
    2840     // It depends on the child inode FS type.
    2841     vfs_ctx_t * ctx = hal_remote_lpt( XPTR( child_cxy , &child_ptr->ctx ) );
    2842 
    2843     error = vfs_fs_cluster_alloc( ctx->type,
    2844                                   &cluster_id );
    2845     if ( error )
    2846     {
    2847         printk("\n[ERROR] in %s : cannot find a free VFS cluster_id\n",
    2848         __FUNCTION__ );
    2849         return -1;
    2850     }
    2851 
    2852 #if( DEBUG_VFS_NEW_DENTRY_INIT & 1)
    2853 if( DEBUG_VFS_NEW_DENTRY_INIT < cycle )
    2854 printk("\n[%s] thread[%x,%x] allocated FS cluster_id %x to <%s>\n",
    2855 __FUNCTION__ , this->process->pid, this->trdid, cluster_id, child_name );
    2856 #endif
    2857 
    2858     // 2. update the child inode descriptor size and extend
    2859     child_type = hal_remote_l32( XPTR( child_cxy , &child_ptr->type ) );
    2860     child_size = 0;
    2861    
    2862     hal_remote_s32( XPTR( child_cxy , &child_ptr->size )   , child_size );
    2863     hal_remote_spt( XPTR( child_cxy , &child_ptr->extend ) , (void*)(intptr_t)cluster_id );
    2864 
    2865     // 3. update the parent inode mapper, and
    2866     // update the dentry extension if required
    2867     if( local_cxy == parent_cxy )
    2868     {
    2869         error = vfs_fs_add_dentry( parent_ptr,
    2870                                    dentry_ptr );
    2871     }
    2872     else
    2873     {
    2874         rpc_vfs_fs_add_dentry_client( parent_cxy,
    2875                                       parent_ptr,
    2876                                       dentry_ptr,
    2877                                       &error );
    2878     }
    2879     if ( error )
    2880     {
    2881         printk("\n[ERROR] in %s : cannot register child in parent directory\n",
    2882         __FUNCTION__ );
    2883         return -1;
    2884     }
    2885 
    2886 #if DEBUG_VFS_NEW_DENTRY_INIT
    2887 cycle = (uint32_t)hal_get_cycles();
    2888 if( DEBUG_VFS_NEW_DENTRY_INIT < cycle )
    2889 printk("\n[%s] thread[%x,%x] exit / parent <%s> / child <%s> / cycle %d\n",
    2890 __FUNCTION__ , this->process->pid, this->trdid, parent_name, child_name, cycle );
    2891 #endif
    2892 
    2893     return 0;
    2894 
    2895 }  // end vfs_new_dentry_init()
    28962727
    28972728///////////////////////////////////////////////////
     
    29062737    xptr_t          dentry_xp;         // extended pointer on dentry (used for . and ..)
    29072738    vfs_dentry_t  * dentry_ptr;        // local pointer on dentry (used for . and ..)
    2908 
    2909     // xptr_t          parents_root_xp;   // extended pointer on inode "parents" field
    2910     // xptr_t          parents_entry_xp;  // extended pointer on dentry "parents" field
    29112739    xptr_t          children_xhtab_xp; // extended pointer on inode "children" field
    29122740    xptr_t          children_entry_xp; // extended pointer on dentry "children" field
     
    29242752#endif
    29252753
    2926     // get new directory cluster and local pointer
     2754    // get child directory cluster and local pointer
    29272755    child_cxy  = GET_CXY( child_xp );
    29282756    child_ptr  = GET_PTR( child_xp );
     
    29332761
    29342762    //////////////////////////// create <.> dentry //////////////////////
    2935     if( child_cxy == local_cxy )     
    2936     {
    2937         error = vfs_dentry_create( fs_type,
    2938                                    ".",
    2939                                    &dentry_xp );
    2940     }
    2941     else
    2942     {
    2943         rpc_vfs_dentry_create_client( child_cxy,
    2944                                       fs_type,
    2945                                       ".",
    2946                                       &dentry_xp,
    2947                                       &error );
    2948     }
     2763    error = vfs_dentry_create( child_cxy,
     2764                               fs_type,
     2765                               ".",
     2766                               &dentry_xp );
    29492767    if( error )
    29502768    {
     
    29672785    children_xhtab_xp = XPTR( child_cxy , &child_ptr->children );
    29682786    children_entry_xp = XPTR( child_cxy , &dentry_ptr->children );
     2787
    29692788    error = xhtab_insert( children_xhtab_xp , "." , children_entry_xp );
     2789
    29702790    if( error )
    29712791    {
     
    29742794        return -1;
    29752795    }
    2976 
    29772796   
    2978     // don't register <.> dentry in child_inode xlist of parents
    2979     // parents_root_xp  = XPTR( child_cxy , &child_ptr->parents );
    2980     // parents_entry_xp = XPTR( child_cxy , &dentry_ptr->parents );
    2981     // xlist_add_first( parents_root_xp , parents_entry_xp );
    2982     // hal_remote_atomic_add( XPTR( child_cxy , &child_ptr->links ) , 1 );
    2983 
    29842797    // update "parent" and "child_xp" fields in <.> dentry
    29852798    hal_remote_s64( XPTR( child_cxy , &dentry_ptr->child_xp ) , child_xp );
     
    29972810    if( child_xp != parent_xp )
    29982811    {
    2999         if( child_cxy == local_cxy )
    3000         {
    3001             error = vfs_fs_add_dentry( child_ptr,
    3002                                        dentry_ptr );
    3003         }
    3004         else
    3005         {
    3006             rpc_vfs_fs_add_dentry_client( child_cxy,
    3007                                           child_ptr,
    3008                                           dentry_ptr,
    3009                                           &error );
    3010         }
     2812        error = vfs_fs_add_dentry( child_xp,
     2813                                   dentry_ptr );
    30112814        if( error )
    30122815        {
     
    30262829
    30272830    ///////////////////////////// create <..> dentry ///////////////////////
    3028     if( child_cxy == local_cxy )     
    3029     {
    3030         error = vfs_dentry_create( fs_type,
    3031                                    "..",
    3032                                    &dentry_xp );
    3033     }
    3034     else
    3035     {
    3036         rpc_vfs_dentry_create_client( child_cxy,
    3037                                       fs_type,
    3038                                       "..",
    3039                                       &dentry_xp,
    3040                                       &error );
    3041     }
     2831    error = vfs_dentry_create( child_cxy,
     2832                               fs_type,
     2833                               "..",
     2834                               &dentry_xp );
    30422835    if( error )
    30432836    {
     
    30852878    if( child_xp != parent_xp )
    30862879    {
    3087         if( child_cxy == local_cxy )
    3088         {
    3089             error = vfs_fs_add_dentry( child_ptr,
    3090                                        dentry_ptr );
    3091         }
    3092         else
    3093         {
    3094             rpc_vfs_fs_add_dentry_client( child_cxy,
    3095                                           child_ptr,
    3096                                           dentry_ptr,
    3097                                           &error );
    3098         }
     2880        error = vfs_fs_add_dentry( child_xp,
     2881                                   dentry_ptr );
    30992882        if( error )
    31002883        {
     
    32593042
    32603043     
    3261 ////////////////////////////////////////////////////////////////////
     3044//////////////////////////////////////////////////////////////
    32623045error_t vfs_add_child_in_parent( cxy_t              child_cxy,
    32633046                                 vfs_fs_type_t      fs_type,
     
    32963079
    32973080    // 1. create dentry in parent cluster
    3298     if( parent_cxy == local_cxy )           // parent cluster is local
    3299     {
    3300         error = vfs_dentry_create( fs_type,
    3301                                    name,
    3302                                    &new_dentry_xp );
    3303     }
    3304     else                                    // parent cluster is remote
    3305     {
    3306         rpc_vfs_dentry_create_client( parent_cxy,
    3307                                       fs_type,
    3308                                       name,
    3309                                       &new_dentry_xp,
    3310                                       &error );
    3311     }
    3312                                      
     3081    error = vfs_dentry_create( parent_cxy,
     3082                               fs_type,
     3083                               name,
     3084                               &new_dentry_xp );
    33133085    if( error )
    33143086    {
     
    33343106    uint32_t gid  = 0;
    33353107   
    3336     if( child_cxy == local_cxy )      // child cluster is local
    3337     {
    3338         error = vfs_inode_create( fs_type,
    3339                                   attr,
    3340                                   mode,
    3341                                   uid,
    3342                                   gid,
    3343                                   &new_inode_xp );
    3344     }
    3345     else                              // child cluster is remote
    3346     {
    3347         rpc_vfs_inode_create_client( child_cxy,
    3348                                      fs_type,
    3349                                      attr,
    3350                                      mode,
    3351                                      uid,
    3352                                      gid,
    3353                                      &new_inode_xp,
    3354                                      &error );
    3355     }
    3356                                      
     3108    error = vfs_inode_create( child_cxy,
     3109                              fs_type,
     3110                              attr,
     3111                              mode,
     3112                              uid,
     3113                              gid,
     3114                              &new_inode_xp );
    33573115    if( error )
    33583116    {
     
    33603118               __FUNCTION__ , child_cxy );
    33613119 
    3362         if( parent_cxy == local_cxy ) vfs_dentry_destroy( new_dentry_ptr );
    3363         else rpc_vfs_dentry_destroy_client( parent_cxy , new_dentry_ptr );
     3120        vfs_dentry_destroy( new_dentry_xp );
    33643121        return -1;
    33653122    }
     
    33743131#endif
    33753132
    3376 
    33773133    // 3. register new_dentry in new_inode xlist of parents
    33783134    parents_root_xp  = XPTR( child_cxy , &new_inode_ptr->parents );
     
    34573213
    34583214    // delete dentry descriptor
    3459     if( parent_cxy == local_cxy )
    3460     {
    3461          vfs_dentry_destroy( dentry_ptr );
    3462     }
    3463     else
    3464     {
    3465          rpc_vfs_dentry_destroy_client( parent_cxy,
    3466                                         dentry_ptr );
    3467     }
     3215    vfs_dentry_destroy( dentry_xp );
    34683216
    34693217    // delete child_inode descriptor if last link
    3470     if( links == 1 )
    3471     {
    3472         if( child_cxy == local_cxy )
    3473         {
    3474             vfs_inode_destroy( child_inode_ptr );
    3475         }
    3476         else
    3477         {
    3478             rpc_vfs_inode_destroy_client( child_cxy , child_inode_ptr );
    3479         }
    3480     }
     3218    if( links == 1 )  vfs_inode_destroy( child_inode_xp );
    34813219
    34823220}  // end vfs_remove_child_from_parent()
     
    34893227//////////////////////////////////////////////////////////////////////////////////////////
    34903228
    3491 //////////////////////////////////////////////
    3492 error_t vfs_fs_move_page( xptr_t      page_xp,
    3493                           cmd_type_t  cmd_type )
     3229///////////////////////////////////////////////////
     3230error_t vfs_fs_add_dentry( xptr_t         inode_xp,
     3231                           vfs_dentry_t * dentry_ptr )
    34943232{
    34953233    error_t error = 0;
    34963234
    3497 assert( (page_xp != XPTR_NULL) , "page pointer is NULL" );
    3498 
    3499     page_t * page_ptr = GET_PTR( page_xp );
    3500     cxy_t    page_cxy = GET_CXY( page_xp );
    3501 
    3502     // get local pointer on page mapper
    3503     mapper_t * mapper = hal_remote_lpt( XPTR( page_cxy , &page_ptr->mapper ) );
    3504 
    3505 assert( (mapper != NULL) , "no mapper for page" );
     3235assert( (inode_xp   != XPTR_NULL) , "inode_xp argument is NULL" );
     3236assert( (dentry_ptr != NULL     ) , "dentry_ptr argument is NULL" );
     3237
     3238    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     3239    cxy_t         inode_cxy = GET_CXY( inode_xp );
     3240
     3241    // get inode mapper
     3242    mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     3243
     3244assert( (mapper != NULL) , "mapper pointer is NULL")       
    35063245
    35073246    // get FS type
    3508     vfs_fs_type_t fs_type = hal_remote_l32( XPTR( page_cxy , &mapper->type ) );
     3247    vfs_fs_type_t fs_type = hal_remote_l32( XPTR( inode_cxy , &mapper->fs_type ) );
    35093248
    35103249    // call relevant FS function
    35113250    if( fs_type == FS_TYPE_FATFS )
    35123251    {
    3513         error = fatfs_move_page( page_xp , cmd_type );
     3252        error = fatfs_add_dentry( inode_xp , dentry_ptr );
    35143253    }
    35153254    else if( fs_type == FS_TYPE_RAMFS )
    35163255    {
    3517         assert( false , "should not be called for RAMFS\n" );
     3256        error = 0;     // does nothing for RAMFS
    35183257    }
    35193258    else if( fs_type == FS_TYPE_DEVFS )
    35203259    {
    3521         assert( false , "should not be called for DEVFS\n" );
     3260        error = 0;     // does nothing for DEVFS
    35223261    }
    35233262    else
     
    35283267    return error;
    35293268
    3530 }  // end vfs_fs_move_page()
    3531 
    3532 ////////////////////////////////////////////////
    3533 error_t vfs_fs_add_dentry( vfs_inode_t  * inode,
    3534                            vfs_dentry_t * dentry )
     3269}  // end vfs_fs_add_dentry()
     3270
     3271//////////////////////////////////////////////////////
     3272error_t vfs_fs_remove_dentry( xptr_t         inode_xp,
     3273                              vfs_dentry_t * dentry_ptr )
    35353274{
    35363275    error_t error = 0;
    35373276
    3538 assert( (inode  != NULL) , "inode  pointer is NULL" );
    3539 assert( (dentry != NULL) , "dentry pointer is NULL" );
    3540 
    3541     mapper_t * mapper = inode->mapper;
    3542 
    3543 assert( (mapper != NULL) , "mapper pointer is NULL" );
     3277assert( (inode_xp   != XPTR_NULL) , "inode_xp argument is NULL" );
     3278assert( (dentry_ptr != NULL     ) , "dentry_ptr argument is NULL" );
     3279
     3280    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     3281    cxy_t         inode_cxy = GET_CXY( inode_xp );
     3282
     3283    // get inode mapper
     3284    mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     3285
     3286assert( (mapper != NULL) , "mapper pointer is NULL")       
    35443287
    35453288    // get FS type
    3546     vfs_fs_type_t fs_type = mapper->type;
     3289    vfs_fs_type_t fs_type = hal_remote_l32( XPTR( inode_cxy , &mapper->fs_type ) );
    35473290
    35483291    // call relevant FS function
    35493292    if( fs_type == FS_TYPE_FATFS )
    35503293    {
    3551         error = fatfs_add_dentry( inode , dentry );
     3294        error = fatfs_remove_dentry( inode_xp , dentry_ptr );
     3295
    35523296    }
    35533297    else if( fs_type == FS_TYPE_RAMFS )
     
    35663310    return error;
    35673311
    3568 }  // end vfs_fs_add_dentry()
    3569 
    3570 ///////////////////////////////////////////////////
    3571 error_t vfs_fs_remove_dentry( vfs_inode_t  * inode,
    3572                               vfs_dentry_t * dentry )
     3312}  // end vfs_fs_remove_dentry()
     3313
     3314///////////////////////////////////////////////////////////////
     3315error_t vfs_fs_new_dentry_from_mapper( xptr_t         inode_xp,
     3316                                       vfs_dentry_t * dentry_ptr )
    35733317{
    35743318    error_t error = 0;
    35753319
    3576 assert( (inode  != NULL) , "inode  pointer is NULL" );
    3577 assert( (dentry != NULL) , "dentry pointer is NULL" );
    3578 
    3579     mapper_t * mapper = inode->mapper;
    3580 
    3581 assert( (mapper != NULL) , "mapper pointer is NULL" );
     3320assert( (inode_xp   != XPTR_NULL) , "inode_xp argument is NULL" );
     3321assert( (dentry_ptr != NULL     ) , "dentry_ptr argument is NULL" );
     3322
     3323    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     3324    cxy_t         inode_cxy = GET_CXY( inode_xp );
     3325
     3326    // get inode mapper
     3327    mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     3328
     3329assert( (mapper != NULL) , "mapper pointer is NULL")       
    35823330
    35833331    // get FS type
    3584     vfs_fs_type_t fs_type = mapper->type;
     3332    vfs_fs_type_t fs_type = hal_remote_l32( XPTR( inode_cxy , &mapper->fs_type ) );
    35853333
    35863334    // call relevant FS function
    35873335    if( fs_type == FS_TYPE_FATFS )
    35883336    {
    3589         error = fatfs_remove_dentry( inode , dentry );
     3337        error = fatfs_new_dentry_from_mapper( inode_xp , dentry_ptr );
    35903338    }
    35913339    else if( fs_type == FS_TYPE_RAMFS )
    35923340    {
    3593         error = 0;     // does nothing for RAMFS
     3341        assert( false , "should not be called for RAMFS" );
    35943342    }
    35953343    else if( fs_type == FS_TYPE_DEVFS )
    35963344    {
    3597         error = 0;     // does nothing for DEVFS
     3345        assert( false , "should not be called for DEVFS" );
    35983346    }
    35993347    else
     
    36043352    return error;
    36053353
    3606 }  // end vfs_fs_remove_dentry()
    3607 
    3608 ////////////////////////////////////////////////
    3609 error_t vfs_fs_new_dentry( vfs_inode_t * parent,
    3610                            char        * name,
    3611                            xptr_t        child_xp )
     3354} // end vfs_fs_new_dentry_from_mapper()
     3355
     3356///////////////////////////////////////////////////////////////
     3357error_t vfs_fs_new_dentry_to_mapper( xptr_t         inode_xp,
     3358                                     vfs_dentry_t * dentry_ptr )
    36123359{
    36133360    error_t error = 0;
    36143361
    3615 // check arguments
    3616 assert( (parent != NULL) , "parent pointer is NULL");
    3617 assert( (child_xp != XPTR_NULL) , "child pointer is NULL");
    3618 
    3619     // get parent inode FS type
    3620     vfs_fs_type_t fs_type = parent->ctx->type;
     3362assert( (inode_xp   != XPTR_NULL) , "inode_xp argument is NULL" );
     3363assert( (dentry_ptr != NULL     ) , "dentry_ptr argument is NULL" );
     3364
     3365    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     3366    cxy_t         inode_cxy = GET_CXY( inode_xp );
     3367
     3368    // get inode mapper
     3369    mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     3370
     3371assert( (mapper != NULL) , "mapper pointer is NULL")       
     3372
     3373    // get FS type
     3374    vfs_fs_type_t fs_type = hal_remote_l32( XPTR( inode_cxy , &mapper->fs_type ) );
    36213375
    36223376    // call relevant FS function
    36233377    if( fs_type == FS_TYPE_FATFS )
    36243378    {
    3625         error = fatfs_new_dentry( parent , name , child_xp );
     3379        error = fatfs_new_dentry_to_mapper( inode_xp , dentry_ptr );
    36263380    }
    36273381    else if( fs_type == FS_TYPE_RAMFS )
     
    36403394    return error;
    36413395
    3642 } // end vfs_fs_new_dentry()
    3643 
    3644 ///////////////////////////////////////////////////
    3645 error_t vfs_fs_update_dentry( vfs_inode_t  * inode,
    3646                               vfs_dentry_t * dentry,
    3647                               uint32_t       size )
     3396} // end vfs_fs_new_dentry_to_mapper()
     3397
     3398//////////////////////////////////////////////////////
     3399error_t vfs_fs_update_dentry( xptr_t         inode_xp,
     3400                              vfs_dentry_t * dentry_ptr )
    36483401{
    36493402    error_t error = 0;
    36503403
    3651 // check arguments
    3652 assert( (inode  != NULL) , "inode  pointer is NULL");
    3653 assert( (dentry != NULL) , "dentry pointer is NULL");
    3654 
    3655     // get parent inode FS type
    3656     vfs_fs_type_t fs_type = inode->ctx->type;
     3404assert( (inode_xp   != XPTR_NULL) , "inode_xp argument is NULL" );
     3405assert( (dentry_ptr != NULL     ) , "dentry_ptr argument is NULL" );
     3406
     3407    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     3408    cxy_t         inode_cxy = GET_CXY( inode_xp );
     3409
     3410    // get inode mapper
     3411    mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     3412
     3413assert( (mapper != NULL) , "mapper pointer is NULL")       
     3414
     3415    // get FS type
     3416    vfs_fs_type_t fs_type = hal_remote_l32( XPTR( inode_cxy , &mapper->fs_type ) );
    36573417
    36583418    // call relevant FS function
    36593419    if( fs_type == FS_TYPE_FATFS )
    36603420    {
    3661         error = fatfs_update_dentry( inode , dentry , size );
     3421        error = fatfs_update_dentry( inode_xp , dentry_ptr );
    36623422    }
    36633423    else if( fs_type == FS_TYPE_RAMFS )
     
    37393499}  // end vfs_fs_get_user_dir()
    37403500 
    3741 ////////////////////////////////////////////////
    3742 error_t vfs_fs_sync_inode( vfs_inode_t * inode )
     3501/////////////////////////////////////////////
     3502error_t vfs_fs_sync_inode( xptr_t  inode_xp )
    37433503{
    37443504    error_t error = 0;
    37453505
    3746 // check arguments
    3747 assert( (inode != NULL) , "inode pointer is NULL");
    3748 
    3749     // get inode FS type
    3750     vfs_fs_type_t fs_type = inode->ctx->type;
     3506assert( (inode_xp != XPTR_NULL) , "inode_xp argument is NULL");
     3507
     3508    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
     3509    cxy_t         inode_cxy = GET_CXY( inode_xp );
     3510
     3511    // get inode mapper
     3512    mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
     3513
     3514assert( (mapper != NULL) , "mapper pointer is NULL")       
     3515
     3516    // get FS type
     3517    vfs_fs_type_t fs_type = hal_remote_l32( XPTR( inode_cxy , &mapper->fs_type ) );
    37513518
    37523519    // call relevant FS function
    37533520    if( fs_type == FS_TYPE_FATFS )
    37543521    {
    3755         error = fatfs_sync_inode( inode );
     3522        error = fatfs_sync_inode( inode_xp );
    37563523    }
    37573524    else if( fs_type == FS_TYPE_RAMFS )
     
    37993566}  // end vfs_fs_sync_fat()
    38003567
    3801 //////////////////////////////////////////////////////
    3802 error_t vfs_fs_sync_free_info( vfs_fs_type_t fs_type )
    3803 {
    3804     error_t error = 0;
    3805 
    3806     // call relevant FS function
    3807     if( fs_type == FS_TYPE_FATFS )
    3808     {
    3809         error = fatfs_sync_free_info();
    3810     }
    3811     else if( fs_type == FS_TYPE_RAMFS )
    3812     {
    3813         assert( false , "should not be called for RAMFS" );
    3814     }
    3815     else if( fs_type == FS_TYPE_DEVFS )
    3816     {
    3817         assert( false , "should not be called for DEVFS" );
    3818     }
    3819     else
    3820     {
    3821         assert( false , "undefined file system type" );
    3822     }
    3823 
    3824     return error;
    3825 
    3826 }  // end vfs_fs_sync_fat()
    3827 
    3828 /////////////////////////////////////////////////
    3829 error_t vfs_fs_cluster_alloc( uint32_t   fs_type,
    3830                               uint32_t * cluster )
    3831 {
    3832     error_t error = 0;
    3833 
    3834     // call relevant FS function
    3835     if( fs_type == FS_TYPE_FATFS )
    3836     {
    3837         error = fatfs_cluster_alloc( cluster );
    3838     }
    3839     else if( fs_type == FS_TYPE_RAMFS )
    3840     {
    3841         assert( false , "should not be called for RAMFS" );
    3842     }
    3843     else if( fs_type == FS_TYPE_DEVFS )
    3844     {
    3845         assert( false , "should not be called for DEVFS" );
    3846     }
    3847     else
    3848     {
    3849         assert( false , "undefined file system type" );
    3850     }
    3851 
    3852     return error;
    3853 
    3854 } // end vfs_fs_cluster_alloc()
    3855 
    38563568////////////////////////////////////////////////
    38573569error_t vfs_fs_release_inode( xptr_t  inode_xp )
     
    38593571    error_t error = 0;
    38603572
    3861 assert( (inode_xp  != XPTR_NULL) , "inode pointer is NULL")       
     3573assert( (inode_xp  != XPTR_NULL) , "inode_xp argument is NULL")       
    38623574
    38633575    vfs_inode_t * inode_ptr = GET_PTR( inode_xp );
    38643576    cxy_t         inode_cxy = GET_CXY( inode_xp );
    38653577
    3866     // get local pointer on page mapper
     3578    // get local pointer on mapper
    38673579    mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) );
    38683580
     
    38703582
    38713583    // get FS type from mapper
    3872     vfs_fs_type_t fs_type = hal_remote_l32( XPTR( inode_cxy , &mapper->type ) );
     3584    vfs_fs_type_t fs_type = hal_remote_l32( XPTR( inode_cxy , &mapper->fs_type ) );
    38733585
    38743586    // call relevant FS function
     
    38943606}  // end vfs_fs_release_inode()
    38953607
    3896 
     3608//////////////////////////////////////////////////
     3609error_t vfs_fs_move_page( xptr_t          page_xp,
     3610                          ioc_cmd_type_t  cmd_type )
     3611{
     3612    error_t error = 0;
     3613
     3614assert( (page_xp != XPTR_NULL) , "page pointer is NULL" );
     3615
     3616    page_t * page_ptr = GET_PTR( page_xp );
     3617    cxy_t    page_cxy = GET_CXY( page_xp );
     3618
     3619    // get local pointer on  mapper
     3620    mapper_t * mapper = hal_remote_lpt( XPTR( page_cxy , &page_ptr->mapper ) );
     3621
     3622assert( (mapper != NULL) , "no mapper for page" );
     3623
     3624    // get FS type
     3625    vfs_fs_type_t fs_type = hal_remote_l32( XPTR( page_cxy , &mapper->fs_type ) );
     3626
     3627    // call relevant FS function
     3628    if( fs_type == FS_TYPE_FATFS )
     3629    {
     3630        error = fatfs_move_page( page_xp , cmd_type );
     3631    }
     3632    else if( fs_type == FS_TYPE_RAMFS )
     3633    {
     3634        assert( false , "should not be called for RAMFS\n" );
     3635    }
     3636    else if( fs_type == FS_TYPE_DEVFS )
     3637    {
     3638        assert( false , "should not be called for DEVFS\n" );
     3639    }
     3640    else
     3641    {
     3642        assert( false , "undefined file system type" );
     3643    }
     3644
     3645    return error;
     3646
     3647}  // end vfs_fs_move_page()
     3648
     3649
Note: See TracChangeset for help on using the changeset viewer.