Changeset 657 for trunk/kernel/fs/vfs.c
- Timestamp:
- Mar 18, 2020, 11:16:59 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/fs/vfs.c
r656 r657 3 3 * 4 4 * Author Mohamed Lamine Karaoui (2015) 5 * Alain Greiner (2016,2017,2018,2019 )5 * Alain Greiner (2016,2017,2018,2019,2020) 6 6 * 7 7 * Copyright (c) UPMC Sorbonne Universites … … 33 33 #include <xhtab.h> 34 34 #include <string.h> 35 #include <rpc.h>36 35 #include <errno.h> 37 36 #include <kmem.h> … … 59 58 ////////////////////////////////////////////////////////////////////////////////////////// 60 59 61 /////////////////////////////////////// /62 void vfs_ctx_init( vfs_fs_type_t type,63 uint32_t attr,60 /////////////////////////////////////// 61 void vfs_ctx_init( cxy_t cxy, 62 vfs_fs_type_t fs_type, 64 63 uint32_t total_clusters, 65 64 uint32_t cluster_size, … … 67 66 void * extend ) 68 67 { 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 /////////////////////////////////////////////// 88 error_t vfs_ctx_inum_alloc( xptr_t ctx_xp, 85 89 uint32_t * inum ) 86 90 { 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 87 101 // get lock on inum allocator 88 busylock_acquire( &ctx->lock);102 remote_busylock_acquire( lock_xp ); 89 103 90 104 // 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 ); 92 106 93 107 if( lid == 0xFFFFFFFF ) // no more free slot => error 94 108 { 95 109 // release lock 96 busylock_release( &ctx->lock);110 remote_busylock_release( lock_xp ); 97 111 98 112 // return error 99 return 1;113 return -1; 100 114 } 101 115 else // found => return inum 102 116 { 103 117 // set slot allocated 104 bitmap_ set( ctx->bitmap , lid );118 bitmap_remote_set( bitmap_xp , lid ); 105 119 106 120 // release lock 107 busylock_release( &ctx->lock);121 remote_busylock_release( lock_xp ); 108 122 109 123 // return inum … … 111 125 return 0; 112 126 } 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 ///////////////////////////////////////////// 130 void 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() 121 152 122 153 ////////////////////////////////////////////////////////////////////////////////////////// … … 140 171 } 141 172 142 //////////////////////////////////////////////////// 143 error_t vfs_inode_create( vfs_fs_type_t fs_type, 173 //////////////////////////////////////////////// 174 error_t vfs_inode_create( cxy_t cxy, 175 vfs_fs_type_t fs_type, 144 176 uint32_t attr, 145 177 uint32_t rights, … … 148 180 xptr_t * inode_xp ) 149 181 { 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 context155 kmem_req_t req; // request to kernel memory allocator182 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 156 188 error_t error; 157 189 … … 166 198 } 167 199 168 // allocate inum169 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 mapper178 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 187 200 // check inode descriptor contained in one page 188 201 assert( (sizeof(vfs_inode_t) <= CONFIG_PPM_PAGE_SIZE), 189 202 "inode descriptor must fit in one page" ); 190 203 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 191 225 // allocate one page for VFS inode descriptor 192 // because the embedded "children xhtab footprint193 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 ) 199 233 { 200 234 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 ); 203 237 return -1; 204 238 } 205 239 240 // initialise inode field in mapper 241 hal_remote_spt( XPTR( cxy , &mapper_ptr->inode ) , inode_ptr ); 242 206 243 // 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 221 255 // initialize chidren dentries xhtab 222 xhtab_init( &inode->children, XHTAB_DENTRY_TYPE );256 xhtab_init( XPTR( cxy , &inode_ptr->children ) , XHTAB_DENTRY_TYPE ); 223 257 224 258 // initialize parents dentries xlist 225 xlist_root_init( XPTR( local_cxy , &inode->parents ) );259 xlist_root_init( XPTR( cxy , &inode_ptr->parents ) ); 226 260 227 261 // 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 ); 229 263 230 264 // 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 ); 232 266 233 267 // return extended pointer on inode 234 *inode_xp = XPTR( local_cxy , inode);268 *inode_xp = XPTR( cxy , inode_ptr ); 235 269 236 270 #if DEBUG_VFS_INODE_CREATE … … 238 272 thread_t * this = CURRENT_THREAD; 239 273 if( DEBUG_VFS_INODE_CREATE < cycle ) 240 printk("\n[%s] thread[%x,%x] created inode (%x,%x) / c ycle %d\n",241 __FUNCTION__, this->process->pid, this->trdid, local_cxy, inode, cycle );274 printk("\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 ); 242 276 #endif 243 277 … … 246 280 } // end vfs_inode_create() 247 281 248 ///////////////////////////////////////////// 249 void vfs_inode_destroy( vfs_inode_t * inode ) 250 { 282 ////////////////////////////////////////// 283 void 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 251 289 // release memory allocated for mapper 252 mapper_destroy( inode->mapper);253 254 // release memory allocate for inode descriptor290 mapper_destroy( XPTR( inode_cxy , &inode_ptr->mapper ) ); 291 292 // release memory allocated for inode descriptor 255 293 kmem_req_t req; 256 294 req.type = KMEM_PPM; 257 req.ptr = inode ;258 kmem_ free(&req );295 req.ptr = inode_ptr; 296 kmem_remote_free( inode_cxy , &req ); 259 297 260 298 } // end vfs_inode_destroy() … … 339 377 340 378 // get inode cluster and local pointer 379 inode_ptr = GET_PTR( inode_xp ); 341 380 inode_cxy = GET_CXY( inode_xp ); 342 inode_ptr = GET_PTR( inode_xp );343 381 344 382 // build extended pointer on parents dentries root … … 367 405 } // end vfs_inode_get_name() 368 406 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 //////////////////////////////////////////////////// 408 error_t vfs_inode_load_all_pages( xptr_t inode_xp ) 409 { 375 410 uint32_t page_id; 376 411 xptr_t page_xp; 377 412 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 ) ); 382 421 383 422 #if DEBUG_VFS_INODE_LOAD_ALL 423 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 384 424 uint32_t cycle = (uint32_t)hal_get_cycles(); 385 425 thread_t * this = CURRENT_THREAD; 386 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 387 vfs_inode_get_name( XPTR( local_cxy , inode ) , name ); 426 vfs_inode_get_name( inode_xp , name ); 388 427 if( DEBUG_VFS_INODE_LOAD_ALL < cycle ) 389 428 printk("\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 ); 391 430 #endif 392 431 … … 400 439 // If the mage is missing, this function allocates the missing page, 401 440 // 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 ); 403 442 404 443 if( page_xp == XPTR_NULL ) return -1; … … 408 447 cycle = (uint32_t)hal_get_cycles(); 409 448 if( 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);449 printk("\n[%s] thread[%x,%x] exit for <%s> in cluster %x\n", 450 __FUNCTION__, this->process->pid, this->trdid, name, inode_cxy ); 412 451 #endif 413 452 … … 425 464 vfs_inode_get_name( inode_xp , name ); 426 465 466 // get inode cluster and local pointer 427 467 cxy_t inode_cxy = GET_CXY( inode_xp ); 428 468 vfs_inode_t * inode_ptr = GET_PTR( inode_xp ); … … 461 501 ////////////////////////////////////////////////////////////////////////////////////////// 462 502 463 /////////////////////////////////////////////////// 464 error_t vfs_dentry_create( vfs_fs_type_t fs_type, 503 /////////////////////////////////////////////// 504 error_t vfs_dentry_create( cxy_t cxy, 505 vfs_fs_type_t fs_type, 465 506 char * name, 466 507 xptr_t * dentry_xp ) 467 508 { 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 514 thread_t * this = CURRENT_THREAD; 515 uint32_t cycle = (uint32_t)hal_get_cycles(); 516 if( DEBUG_VFS_DENTRY_CREATE < cycle ) 517 printk("\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 471 520 472 521 // get pointer on context … … 476 525 else 477 526 { 478 ctx = NULL;527 printk("\n[ERROR] in %s undefined fs_type %d\n", __FUNCTION__, fs_type ); 479 528 return -1; 480 529 } … … 483 532 uint32_t length = strlen( name ); 484 533 485 if( length >= CONFIG_VFS_MAX_NAME_LENGTH ) return EINVAL;534 if( length >= CONFIG_VFS_MAX_NAME_LENGTH ) return -1; 486 535 487 536 // 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 ) 494 543 { 495 544 printk("\n[ERROR] in %s : cannot allocate dentry descriptor\n", … … 499 548 500 549 // 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 ) ); 505 557 506 558 // return extended pointer on dentry 507 *dentry_xp = XPTR( local_cxy , dentry);559 *dentry_xp = XPTR( cxy , dentry_ptr ); 508 560 509 561 #if DEBUG_VFS_DENTRY_CREATE 510 thread_t * this = CURRENT_THREAD;511 uint32_t cycle = (uint32_t)hal_get_cycles();512 562 if( 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);563 printk("\n[%s] thread[%x,%x] exit for <%s> / dentry (%x,%x)\n", 564 __FUNCTION__, this->process->pid, this->trdid, name, cxy, dentry_ptr ); 515 565 #endif 516 566 … … 519 569 } // end vfs_dentry_create() 520 570 521 //////////////////////////////////////////////// 522 void vfs_dentry_destroy( vfs_dentry_t * dentry ) 523 { 571 //////////////////////////////////////////// 572 void 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 524 578 // release memory allocated to dentry 525 579 kmem_req_t req; 526 580 req.type = KMEM_KCM; 527 req.ptr = dentry ;528 kmem_ free(&req );581 req.ptr = dentry_ptr; 582 kmem_remote_free( dentry_cxy , &req ); 529 583 530 584 } // end vfs_dentry_destroy() … … 536 590 537 591 ///////////////////////////////////////////// 538 error_t vfs_file_create( vfs_inode_t * inode,539 uint32_t 540 xptr_t 541 { 542 vfs_file_t * file ;592 error_t vfs_file_create( xptr_t inode_xp, 593 uint32_t attr, 594 xptr_t * file_xp ) 595 { 596 vfs_file_t * file_ptr; 543 597 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 ); 544 605 545 606 #if DEBUG_VFS_FILE_CREATE … … 547 608 uint32_t cycle = (uint32_t)hal_get_cycles(); 548 609 if( 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 );610 printk("\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 ); 551 612 #endif 552 613 … … 555 616 req.order = bits_log2( sizeof(vfs_file_t) ); 556 617 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 ) ); 560 626 561 627 // 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 ); 574 639 575 640 #if DEBUG_VFS_FILE_CREATE 576 641 cycle = (uint32_t)hal_get_cycles(); 577 642 if( 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 );643 printk("\n[%s] thread[%x,%x] created file (%x,%x) %x\n", 644 __FUNCTION__, this->process->pid, this->trdid, inode_cxy, file_ptr, cycle ); 580 645 #endif 581 646 … … 584 649 } // end vfs_file_create() 585 650 586 /////////////////////////////////////////// 587 void vfs_file_destroy( vfs_file_t * file ) 588 { 651 //////////////////////////////////////// 652 void 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 589 659 kmem_req_t req; 590 660 req.type = KMEM_KCM; 591 req.ptr = file ;592 kmem_ free(&req );661 req.ptr = file_ptr; 662 kmem_remote_free( file_cxy , &req ); 593 663 594 664 #if DEBUG_VFS_CLOSE 595 665 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 596 vfs_file_get_name( XPTR( local_cxy , file ), name );666 vfs_file_get_name( file_xp , name ); 597 667 thread_t * this = CURRENT_THREAD; 598 668 uint32_t cycle = (uint32_t)hal_get_cycles(); 599 669 if( DEBUG_VFS_CLOSE < cycle ) 600 670 printk("\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 ); 602 672 #endif 603 673 … … 738 808 739 809 // 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 ); 748 811 749 812 if( error ) return error; … … 764 827 cycle = (uint32_t)hal_get_cycles(); 765 828 if( 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 ); 829 printk("\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, 831 GET_CXY( file_xp ), GET_PTR( file_xp ), cycle ); 768 832 #endif 769 833 … … 880 944 __FUNCTION__ , this->process->pid, nbytes ); 881 945 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 ); 884 948 } 885 949 #endif … … 1035 1099 { 1036 1100 cxy_t file_cxy; // cluster containing the file descriptor. 1037 vfs_file_t * file_ptr; // local po nter on file descriptor1101 vfs_file_t * file_ptr; // local pointer on file descriptor 1038 1102 cxy_t owner_cxy; // process owner cluster 1039 1103 pid_t pid; // process identifier … … 1076 1140 1077 1141 // 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 ) ); 1088 1143 1089 1144 if( error ) … … 1128 1183 1129 1184 // 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 ); 1144 1187 1145 1188 if( error ) … … 1159 1202 1160 1203 // 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 ) ); 1171 1205 1172 1206 if( error ) … … 1222 1256 //////// 4) release memory allocated to file descriptor in remote cluster 1223 1257 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 ); 1232 1259 1233 1260 #if DEBUG_VFS_CLOSE … … 1320 1347 1321 1348 // 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 ); 1337 1353 if( error ) 1338 1354 { … … 1361 1377 inode_cxy = cluster_random_select(); 1362 1378 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 ); 1384 1387 if( error ) 1385 1388 { 1386 1389 remote_rwlock_wr_release( lock_xp ); 1387 1390 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 ); 1391 1393 return -1; 1392 1394 } … … 1434 1436 remote_rwlock_wr_release( lock_xp ); 1435 1437 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 ); 1439 1440 return -1; 1440 1441 } … … 1445 1446 // 8. update parent directory mapper 1446 1447 // 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 ); 1460 1450 if( error ) 1461 1451 { … … 1589 1579 { 1590 1580 // 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 ); 1606 1585 if( error ) 1607 1586 { … … 1643 1622 // and synchronize the parent directory on IOC device 1644 1623 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 ); 1656 1626 if( error ) 1657 1627 { … … 1703 1673 vfs_fs_type_t fs_type; // File system type 1704 1674 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 1706 1677 1707 1678 thread_t * this = CURRENT_THREAD; … … 1731 1702 VFS_LOOKUP_PARENT, 1732 1703 &parent_xp, 1733 name );1704 child_name ); 1734 1705 if( error ) 1735 1706 { 1736 1707 remote_rwlock_wr_release( lock_xp ); 1737 1708 printk("\n[ERROR] in %s : cannot get parent inode for <%s> in <%s>\n", 1738 __FUNCTION__, name, path );1709 __FUNCTION__, child_name, path ); 1739 1710 return -1; 1740 1711 } 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 ); 1743 1715 parent_cxy = GET_CXY( parent_xp ); 1744 1716 parent_ptr = GET_PTR( parent_xp ); 1745 1717 1746 1718 #if( DEBUG_VFS_UNLINK & 1 ) 1747 char parent_name[CONFIG_VFS_MAX_NAME_LENGTH];1748 vfs_inode_get_name( parent_xp , parent_name );1749 1719 if( DEBUG_VFS_UNLINK < cycle ) 1750 1720 printk("\n[%s] thread[%x,%x] : parent inode <%s> is (%x,%x)\n", … … 1756 1726 1757 1727 // 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 ); 1759 1729 1760 // when dentry not found in Inode Tree, try to get it from inode tree1730 // when dentry not found in Inode Tree, try to get it from mapper 1761 1731 1762 1732 if( dentry_xp == XPTR_NULL ) // miss target dentry in Inode Tree … … 1765 1735 #if( DEBUG_VFS_UNLINK & 1 ) 1766 1736 if( 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 );1737 printk("\n[%s] thread[%x,%x] : inode <%s> not found => scan parent mapper <%s>\n", 1738 __FUNCTION__, process->pid, this->trdid, child_name , parent_name ); 1769 1739 #endif 1770 1740 // get parent inode FS type … … 1779 1749 fs_type, 1780 1750 parent_xp, 1781 name,1751 child_name, 1782 1752 &dentry_xp, 1783 1753 &inode_xp ); 1784 1754 if( error ) 1785 1755 { 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 ); 1790 1758 return -1; 1791 1759 } … … 1797 1765 // scan parent mapper to find the missing dentry, and complete 1798 1766 // 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 ) 1800 1770 { 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 ); 1818 1773 return -1; 1819 1774 } … … 1822 1777 if( DEBUG_VFS_UNLINK < cycle ) 1823 1778 printk("\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 ); 1825 1780 #endif 1826 1781 … … 1856 1811 if( DEBUG_VFS_UNLINK < cycle ) 1857 1812 printk("\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, 1814 vfs_inode_type_str(inode_type), inode_links ); 1859 1815 #endif 1860 1816 … … 1898 1854 // 2. update parent directory mapper 1899 1855 // 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 ); 1913 1858 if( error ) 1914 1859 { … … 2172 2117 2173 2118 ////////////////////////////////////////////////////////////////////////// 2174 // This staticfunction is called by the vfs_display() function.2119 // This recursive function is called by the vfs_display() function. 2175 2120 // that is supposed to take the TXT0 lock. 2176 2121 ////////////////////////////////////////////////////////////////////////// … … 2184 2129 uint32_t inode_size; 2185 2130 uint32_t inode_attr; 2186 uint32_t inode_dirty;2187 2131 void * inode_extd; 2188 2132 … … 2234 2178 2235 2179 // compute dirty 2236 inode_dirty = ((inode_attr & INODE_ATTR_DIRTY) != 0);2180 // inode_dirty = ((inode_attr & INODE_ATTR_DIRTY) != 0); unused [AG] dec 2019 2237 2181 2238 2182 // 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", 2240 2184 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 ); 2242 2186 2243 2187 // scan directory entries when current inode is a directory … … 2328 2272 2329 2273 // print header 2330 nolock_printk("\n***** file systemstate\n\n");2274 nolock_printk("\n***** current VFS state\n\n"); 2331 2275 2332 2276 // call recursive function … … 2484 2428 vfs_inode_t * parent_ptr; // local pointer on parent inode 2485 2429 xptr_t dentry_xp; // extended pointer on dentry 2430 vfs_dentry_t * dentry_ptr; // local pointer on dentry 2486 2431 xptr_t child_xp; // extended pointer on child inode 2487 2432 cxy_t child_cxy; // cluster for child inode … … 2532 2477 last = false; 2533 2478 child_xp = XPTR_NULL; 2479 child_cxy = 0; 2480 child_ptr = NULL; 2534 2481 2535 2482 // loop on nodes in pathname … … 2570 2517 &child_xp ); 2571 2518 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 2577 2520 { 2578 2521 // when a inode is not found in the Inode Tree: … … 2606 2549 #endif 2607 2550 // 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 ) ); 2609 2552 fs_type = hal_remote_l32( XPTR( parent_cxy , &ctx_ptr->type ) ); 2610 2553 … … 2626 2569 } 2627 2570 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 ); 2630 2574 2631 2575 #if (DEBUG_VFS_LOOKUP & 1) … … 2636 2580 // scan parent mapper to find the missing dentry, and complete 2637 2581 // 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 : 2656 2586 { 2657 2587 if ( last && create ) // add a brand new dentry in parent directory 2658 2588 { 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 ); 2662 2591 if ( error ) 2663 2592 { 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 ); 2666 2595 vfs_remove_child_from_parent( dentry_xp ); 2667 2596 return -1; … … 2674 2603 vfs_inode_display( child_xp ); 2675 2604 #endif 2676 2677 2678 2605 } 2679 2606 else // not last or not create => error … … 2704 2631 if( type == INODE_TYPE_DIR ) 2705 2632 { 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 2716 2635 if ( error ) 2717 2636 { … … 2731 2650 } 2732 2651 } 2733 else // child directly found in inode tree2652 else // child found in Inode Tree 2734 2653 { 2654 // get child inode local pointer and cluster 2655 child_ptr = GET_PTR( child_xp ); 2656 child_cxy = GET_CXY( child_xp ); 2735 2657 2736 2658 #if (DEBUG_VFS_LOOKUP & 1) … … 2759 2681 // } 2760 2682 2761 // take lock on child inode and release lock on parent2762 // vfs_inode_lock( child_xp );2763 // vfs_inode_unlock( parent_xp );2764 2765 2683 // exit when last 2766 2684 if ( last ) // last inode in path => return relevant info … … 2792 2710 } 2793 2711 } 2794 else // not the last inode in path => update loop variables2712 else // not the last node in path => update loop variables 2795 2713 { 2796 2714 parent_xp = child_xp; 2797 2715 current = next; 2798 2716 } 2799 } 2717 } // end while loop on nodes in pathname 2718 2719 #if ( DEBUG_VFS_LOOKUP & 1 ) 2720 if( DEBUG_VFS_LOOKUP < cycle ) 2721 vfs_display( root_xp ); 2722 #endif 2800 2723 2801 2724 return 0; 2802 2725 2803 2726 } // 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_INIT2816 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 #endif2826 2827 // get parent inode cluster and local pointer2828 cxy_t parent_cxy = GET_CXY( parent_xp );2829 vfs_inode_t * parent_ptr = GET_PTR( parent_xp );2830 2831 // get dentry local pointer2832 vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp );2833 2834 // get child inode cluster and local pointer2835 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 #endif2857 2858 // 2. update the child inode descriptor size and extend2859 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, and2866 // update the dentry extension if required2867 if( local_cxy == parent_cxy )2868 {2869 error = vfs_fs_add_dentry( parent_ptr,2870 dentry_ptr );2871 }2872 else2873 {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_INIT2887 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 #endif2892 2893 return 0;2894 2895 } // end vfs_new_dentry_init()2896 2727 2897 2728 /////////////////////////////////////////////////// … … 2906 2737 xptr_t dentry_xp; // extended pointer on dentry (used for . and ..) 2907 2738 vfs_dentry_t * dentry_ptr; // local pointer on dentry (used for . and ..) 2908 2909 // xptr_t parents_root_xp; // extended pointer on inode "parents" field2910 // xptr_t parents_entry_xp; // extended pointer on dentry "parents" field2911 2739 xptr_t children_xhtab_xp; // extended pointer on inode "children" field 2912 2740 xptr_t children_entry_xp; // extended pointer on dentry "children" field … … 2924 2752 #endif 2925 2753 2926 // get newdirectory cluster and local pointer2754 // get child directory cluster and local pointer 2927 2755 child_cxy = GET_CXY( child_xp ); 2928 2756 child_ptr = GET_PTR( child_xp ); … … 2933 2761 2934 2762 //////////////////////////// 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 ); 2949 2767 if( error ) 2950 2768 { … … 2967 2785 children_xhtab_xp = XPTR( child_cxy , &child_ptr->children ); 2968 2786 children_entry_xp = XPTR( child_cxy , &dentry_ptr->children ); 2787 2969 2788 error = xhtab_insert( children_xhtab_xp , "." , children_entry_xp ); 2789 2970 2790 if( error ) 2971 2791 { … … 2974 2794 return -1; 2975 2795 } 2976 2977 2796 2978 // don't register <.> dentry in child_inode xlist of parents2979 // 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 2984 2797 // update "parent" and "child_xp" fields in <.> dentry 2985 2798 hal_remote_s64( XPTR( child_cxy , &dentry_ptr->child_xp ) , child_xp ); … … 2997 2810 if( child_xp != parent_xp ) 2998 2811 { 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 ); 3011 2814 if( error ) 3012 2815 { … … 3026 2829 3027 2830 ///////////////////////////// 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 ); 3042 2835 if( error ) 3043 2836 { … … 3085 2878 if( child_xp != parent_xp ) 3086 2879 { 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 ); 3099 2882 if( error ) 3100 2883 { … … 3259 3042 3260 3043 3261 ////////////////////////////////////////////////////////////// //////3044 ////////////////////////////////////////////////////////////// 3262 3045 error_t vfs_add_child_in_parent( cxy_t child_cxy, 3263 3046 vfs_fs_type_t fs_type, … … 3296 3079 3297 3080 // 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 ); 3313 3085 if( error ) 3314 3086 { … … 3334 3106 uint32_t gid = 0; 3335 3107 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 ); 3357 3115 if( error ) 3358 3116 { … … 3360 3118 __FUNCTION__ , child_cxy ); 3361 3119 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 ); 3364 3121 return -1; 3365 3122 } … … 3374 3131 #endif 3375 3132 3376 3377 3133 // 3. register new_dentry in new_inode xlist of parents 3378 3134 parents_root_xp = XPTR( child_cxy , &new_inode_ptr->parents ); … … 3457 3213 3458 3214 // 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 ); 3468 3216 3469 3217 // 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 ); 3481 3219 3482 3220 } // end vfs_remove_child_from_parent() … … 3489 3227 ////////////////////////////////////////////////////////////////////////////////////////// 3490 3228 3491 ////////////////////////////////////////////// 3492 error_t vfs_fs_ move_page( xptr_t page_xp,3493 cmd_type_t cmd_type)3229 /////////////////////////////////////////////////// 3230 error_t vfs_fs_add_dentry( xptr_t inode_xp, 3231 vfs_dentry_t * dentry_ptr ) 3494 3232 { 3495 3233 error_t error = 0; 3496 3234 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" ); 3235 assert( (inode_xp != XPTR_NULL) , "inode_xp argument is NULL" ); 3236 assert( (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 3244 assert( (mapper != NULL) , "mapper pointer is NULL") 3506 3245 3507 3246 // 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 ) ); 3509 3248 3510 3249 // call relevant FS function 3511 3250 if( fs_type == FS_TYPE_FATFS ) 3512 3251 { 3513 error = fatfs_ move_page( page_xp , cmd_type);3252 error = fatfs_add_dentry( inode_xp , dentry_ptr ); 3514 3253 } 3515 3254 else if( fs_type == FS_TYPE_RAMFS ) 3516 3255 { 3517 assert( false , "should not be called for RAMFS\n" );3256 error = 0; // does nothing for RAMFS 3518 3257 } 3519 3258 else if( fs_type == FS_TYPE_DEVFS ) 3520 3259 { 3521 assert( false , "should not be called for DEVFS\n" );3260 error = 0; // does nothing for DEVFS 3522 3261 } 3523 3262 else … … 3528 3267 return error; 3529 3268 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 ////////////////////////////////////////////////////// 3272 error_t vfs_fs_remove_dentry( xptr_t inode_xp, 3273 vfs_dentry_t * dentry_ptr ) 3535 3274 { 3536 3275 error_t error = 0; 3537 3276 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" ); 3277 assert( (inode_xp != XPTR_NULL) , "inode_xp argument is NULL" ); 3278 assert( (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 3286 assert( (mapper != NULL) , "mapper pointer is NULL") 3544 3287 3545 3288 // 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 ) ); 3547 3290 3548 3291 // call relevant FS function 3549 3292 if( fs_type == FS_TYPE_FATFS ) 3550 3293 { 3551 error = fatfs_add_dentry( inode , dentry ); 3294 error = fatfs_remove_dentry( inode_xp , dentry_ptr ); 3295 3552 3296 } 3553 3297 else if( fs_type == FS_TYPE_RAMFS ) … … 3566 3310 return error; 3567 3311 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 /////////////////////////////////////////////////////////////// 3315 error_t vfs_fs_new_dentry_from_mapper( xptr_t inode_xp, 3316 vfs_dentry_t * dentry_ptr ) 3573 3317 { 3574 3318 error_t error = 0; 3575 3319 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" ); 3320 assert( (inode_xp != XPTR_NULL) , "inode_xp argument is NULL" ); 3321 assert( (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 3329 assert( (mapper != NULL) , "mapper pointer is NULL") 3582 3330 3583 3331 // 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 ) ); 3585 3333 3586 3334 // call relevant FS function 3587 3335 if( fs_type == FS_TYPE_FATFS ) 3588 3336 { 3589 error = fatfs_ remove_dentry( inode , dentry );3337 error = fatfs_new_dentry_from_mapper( inode_xp , dentry_ptr ); 3590 3338 } 3591 3339 else if( fs_type == FS_TYPE_RAMFS ) 3592 3340 { 3593 error = 0; // does nothing for RAMFS3341 assert( false , "should not be called for RAMFS" ); 3594 3342 } 3595 3343 else if( fs_type == FS_TYPE_DEVFS ) 3596 3344 { 3597 error = 0; // does nothing for DEVFS3345 assert( false , "should not be called for DEVFS" ); 3598 3346 } 3599 3347 else … … 3604 3352 return error; 3605 3353 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 /////////////////////////////////////////////////////////////// 3357 error_t vfs_fs_new_dentry_to_mapper( xptr_t inode_xp, 3358 vfs_dentry_t * dentry_ptr ) 3612 3359 { 3613 3360 error_t error = 0; 3614 3361 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; 3362 assert( (inode_xp != XPTR_NULL) , "inode_xp argument is NULL" ); 3363 assert( (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 3371 assert( (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 ) ); 3621 3375 3622 3376 // call relevant FS function 3623 3377 if( fs_type == FS_TYPE_FATFS ) 3624 3378 { 3625 error = fatfs_new_dentry ( parent , name , child_xp);3379 error = fatfs_new_dentry_to_mapper( inode_xp , dentry_ptr ); 3626 3380 } 3627 3381 else if( fs_type == FS_TYPE_RAMFS ) … … 3640 3394 return error; 3641 3395 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 ////////////////////////////////////////////////////// 3399 error_t vfs_fs_update_dentry( xptr_t inode_xp, 3400 vfs_dentry_t * dentry_ptr ) 3648 3401 { 3649 3402 error_t error = 0; 3650 3403 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; 3404 assert( (inode_xp != XPTR_NULL) , "inode_xp argument is NULL" ); 3405 assert( (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 3413 assert( (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 ) ); 3657 3417 3658 3418 // call relevant FS function 3659 3419 if( fs_type == FS_TYPE_FATFS ) 3660 3420 { 3661 error = fatfs_update_dentry( inode , dentry , size);3421 error = fatfs_update_dentry( inode_xp , dentry_ptr ); 3662 3422 } 3663 3423 else if( fs_type == FS_TYPE_RAMFS ) … … 3739 3499 } // end vfs_fs_get_user_dir() 3740 3500 3741 ///////////////////////////////////////////// ///3742 error_t vfs_fs_sync_inode( vfs_inode_t * inode)3501 ///////////////////////////////////////////// 3502 error_t vfs_fs_sync_inode( xptr_t inode_xp ) 3743 3503 { 3744 3504 error_t error = 0; 3745 3505 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; 3506 assert( (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 3514 assert( (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 ) ); 3751 3518 3752 3519 // call relevant FS function 3753 3520 if( fs_type == FS_TYPE_FATFS ) 3754 3521 { 3755 error = fatfs_sync_inode( inode );3522 error = fatfs_sync_inode( inode_xp ); 3756 3523 } 3757 3524 else if( fs_type == FS_TYPE_RAMFS ) … … 3799 3566 } // end vfs_fs_sync_fat() 3800 3567 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 function3807 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 else3820 {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 function3835 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 else3848 {3849 assert( false , "undefined file system type" );3850 }3851 3852 return error;3853 3854 } // end vfs_fs_cluster_alloc()3855 3856 3568 //////////////////////////////////////////////// 3857 3569 error_t vfs_fs_release_inode( xptr_t inode_xp ) … … 3859 3571 error_t error = 0; 3860 3572 3861 assert( (inode_xp != XPTR_NULL) , "inode pointeris NULL")3573 assert( (inode_xp != XPTR_NULL) , "inode_xp argument is NULL") 3862 3574 3863 3575 vfs_inode_t * inode_ptr = GET_PTR( inode_xp ); 3864 3576 cxy_t inode_cxy = GET_CXY( inode_xp ); 3865 3577 3866 // get local pointer on pagemapper3578 // get local pointer on mapper 3867 3579 mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) ); 3868 3580 … … 3870 3582 3871 3583 // 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 ) ); 3873 3585 3874 3586 // call relevant FS function … … 3894 3606 } // end vfs_fs_release_inode() 3895 3607 3896 3608 ////////////////////////////////////////////////// 3609 error_t vfs_fs_move_page( xptr_t page_xp, 3610 ioc_cmd_type_t cmd_type ) 3611 { 3612 error_t error = 0; 3613 3614 assert( (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 3622 assert( (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.