Changeset 625 for trunk/kernel/fs
- Timestamp:
- Apr 10, 2019, 10:09:39 AM (6 years ago)
- Location:
- trunk/kernel/fs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/fs/fatfs.c
r623 r625 2 2 * fatfs.c - FATFS file system API implementation. 3 3 * 4 * Author Alain Greiner (2016,2017,2018 )4 * Author Alain Greiner (2016,2017,2018,2019) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 374 374 375 375 ////////////////////////////////////////////////////////////////////////////////////////// 376 // This static function - atomically - decrements "free_clusters", and updates 377 // the "free_cluster_hint" shared variables in the FATFS context in the FAT cluster. 378 // It scan the FAT to find the first free slot larger than the <cluster> argument, 379 // and set "free_cluster_hint" <= (free - 1). 376 // This static function decrements the "free_clusters" variable, and updates the 377 // "free_cluster_hint" variable in the FATFS context, identified by the <fat_ctx_cxy> 378 // and <fat_ctx_ptr> arguments (cluster containing the FAT mapper). 379 // It scan all slots in the FAT mapper seen as an array of 32 bits words, looking for the 380 // first free slot larger than the <cluster> argument, to update "free_cluster_hint". 380 381 // 381 382 // WARNING : The free_lock protecting exclusive access to these variables 382 383 // must be taken by the calling function. 383 384 ////////////////////////////////////////////////////////////////////////////////////////// 384 // @ cluster : recently allocated cluster index in FAT. 385 ////////////////////////////////////////////////////////////////////////////////////////// 386 static error_t fatfs_free_clusters_decrement( uint32_t cluster ) 387 { 388 fatfs_ctx_t * loc_ctx; // local pointer on local FATFS context 389 fatfs_ctx_t * fat_ctx; // local pointer on FATFS in cluster containing FAT mapper 390 cxy_t mapper_cxy; // cluster identifier for cluster containing FAT mapper 385 // @ fat_ctx_cxy : FAT mapper cluster identifier. 386 // @ fat_ctx_ptr : local pointer on FATFS context. 387 // @ cluster : recently allocated cluster index in FAT. 388 ////////////////////////////////////////////////////////////////////////////////////////// 389 static error_t fatfs_free_clusters_decrement( cxy_t fat_ctx_cxy, 390 fatfs_ctx_t * fat_ctx_ptr, 391 uint32_t cluster ) 392 { 391 393 xptr_t mapper_xp; // extended pointer on FAT mapper 392 394 xptr_t hint_xp; // extended pointer on "free_cluster_hint" shared variable … … 397 399 uint32_t page_max; // max number of pages in FAT mapper 398 400 xptr_t page_xp; // extended pointer on current page in FAT mapper 401 xptr_t base_xp; // extended pointer on current page base 399 402 xptr_t slot_xp; // extended pointer on current slot in FAT mapper 400 403 … … 407 410 #endif 408 411 409 // get local pointer on local FATFS context410 loc_ctx = fs_context[FS_TYPE_FATFS].extend;411 412 // get cluster containing FAT mapper413 mapper_xp = loc_ctx->fat_mapper_xp;414 mapper_cxy = GET_CXY( mapper_xp );415 416 // get local pointer on FATFS context in FAT cluster417 fat_ctx = hal_remote_lpt( XPTR( mapper_cxy , &fs_context[FS_TYPE_FATFS].extend ) );418 419 412 // build extended pointers on free_clusters, and free_cluster_hint 420 hint_xp = XPTR( mapper_cxy , &fat_ctx->free_cluster_hint );421 numb_xp = XPTR( mapper_cxy , &fat_ctx->free_clusters );413 hint_xp = XPTR( fat_ctx_cxy , &fat_ctx_ptr->free_cluster_hint ); 414 numb_xp = XPTR( fat_ctx_cxy , &fat_ctx_ptr->free_clusters ); 422 415 423 416 // update "free_clusters" … … 425 418 hal_remote_s32( numb_xp , numb - 1 ); 426 419 427 // scan FAT mapper to find the first free slot > cluster 428 // and update "free_cluster_hint" as (free - 1) 420 // get extended pointer on FAT mapper 421 mapper_xp = hal_remote_l64( XPTR( fat_ctx_cxy , &fat_ctx_ptr->fat_mapper_xp ) ); 422 423 // initialise variables to scan the FAT mapper 424 // and find the first free slot > cluster 429 425 page_id = (cluster + 1) >> 10; 430 426 slot_id = (cluster + 1) & 0x3FF; 431 page_max = (loc_ctx->fat_sectors_count >> 3);427 page_max = hal_remote_l32( XPTR( fat_ctx_cxy, &fat_ctx_ptr->fat_sectors_count ) ) >> 3; 432 428 433 429 // scan FAT mapper / loop on pages … … 443 439 } 444 440 441 // get extended pointer on page 442 base_xp = ppm_page2base( page_xp ); 443 445 444 // scan FAT mapper / loop on slots 446 445 while ( slot_id < 1024 ) 447 446 { 448 447 // get extended pointer on current slot 449 slot_xp = ppm_page2base( page_xp )+ (slot_id << 2);450 451 // test FATslot value448 slot_xp = base_xp + (slot_id << 2); 449 450 // test slot value 452 451 if ( hal_remote_l32( slot_xp ) == FREE_CLUSTER ) 453 452 { 454 // update "free_cluster_hint" <= (free - 1)453 // update "free_cluster_hint" 455 454 hal_remote_s32( hint_xp , (page_id << 10) + slot_id - 1 ); 456 455 … … 465 464 } 466 465 467 // incrementslot_id468 slot_id ++;466 // update slot_id 467 slot_id = 0; 469 468 470 469 } // end loop on slots 471 470 472 // update loopvariables471 // update (page_id,slot_id) variables 473 472 page_id++; 474 473 slot_id = 0; … … 483 482 484 483 ////////////////////////////////////////////////////////////////////////////////////////// 485 // This static function atomically increments <free_clusters>, and updates 486 // the <free_cluster_hint> shared variables in the FATFS context in the FAT cluster. 487 // If the released cluster index is smaller than the current (hint + 1) value, 488 // it set "free_cluster_hint" <= cluster - 1. 484 // This static function increments the "free_clusters" variable, and updates the 485 // "free_cluster_hint" variables in the FATFS context, identified by the <fat_ctx_cxy> 486 // and <fat_ctx_ptr> argument (cluster containing the FAT mapper). 487 // If the released cluster index is smaller than the current (hint) value, 488 // it set "free_cluster_hint" <= cluster. 489 489 // 490 490 // WARNING : The free_lock protecting exclusive access to these variables 491 491 // must be taken by the calling function. 492 492 ////////////////////////////////////////////////////////////////////////////////////////// 493 // @ fat_ctx_cxy : FAT mapper cluster identifier. 494 // @ fat_ctx_ptr : local pointer on FATFS context. 493 495 // @ cluster : recently released cluster index in FAT. 494 496 ////////////////////////////////////////////////////////////////////////////////////////// 495 static void fatfs_free_clusters_increment( uint32_t cluster ) 496 { 497 fatfs_ctx_t * loc_ctx; // local pointer on local FATFS context 498 fatfs_ctx_t * fat_ctx; // local pointer on FATFS in cluster containing FAT mapper 499 cxy_t fat_cxy; // cluster identifier for cluster containing FAT mapper 497 static void fatfs_free_clusters_increment( cxy_t fat_ctx_cxy, 498 fatfs_ctx_t * fat_ctx_ptr, 499 uint32_t cluster ) 500 { 500 501 xptr_t hint_xp; // extended pointer on "free_cluster_hint" shared variable 501 502 xptr_t numb_xp; // extended pointer on "free_clusters" shared variable … … 503 504 uint32_t numb; // "free_clusters" variable current value 504 505 505 // get local pointer on local FATFS context 506 loc_ctx = fs_context[FS_TYPE_FATFS].extend; 507 508 // get cluster containing FAT mapper 509 fat_cxy = GET_CXY( loc_ctx->fat_mapper_xp ); 510 511 // get local pointer on FATFS context in FAT cluster 512 fat_ctx = hal_remote_lpt( XPTR( fat_cxy , &fs_context[FS_TYPE_FATFS].extend ) ); 513 514 // build extended pointers free_lock, free_clusters, and free_cluster_hint 515 hint_xp = XPTR( fat_cxy , &fat_ctx->free_cluster_hint ); 516 numb_xp = XPTR( fat_cxy , &fat_ctx->free_clusters ); 506 // build extended pointers on free_clusters, and free_cluster_hint 507 hint_xp = XPTR( fat_ctx_cxy , &fat_ctx_ptr->free_cluster_hint ); 508 numb_xp = XPTR( fat_ctx_cxy , &fat_ctx_ptr->free_clusters ); 517 509 518 510 // get current value of free_cluster_hint and free_clusters … … 521 513 522 514 // update free_cluster_hint if required 523 if ( cluster < (hint + 1)) hal_remote_s32( hint_xp , (cluster - 1) );515 if ( (cluster - 1) < hint ) hal_remote_s32( hint_xp , (cluster - 1) ); 524 516 525 517 // update free_clusters … … 542 534 // It does NOT update the FS on the IOC device. 543 535 ////////////////////////////////////////////////////////////////////////////////////////// 544 // @ fat_mapper_xp : extended pointer on FAT mapper. 545 // @ cluster : cluster index in FAT. 536 // @ mapper_cxy : FAT mapper cluster identifier. 537 // @ mapper_ptr : local pointer on FAT mapper. 538 // @ fatfs_ctx : local pointer on FATFS context in FAT cluster. 539 // @ cluster : index of cluster to be released from FAT mapper. 546 540 // @ return 0 if success / return -1 if error (cannot access FAT) 547 541 ////////////////////////////////////////////////////////////////////////////////////////// 548 static error_t fatfs_recursive_release( xptr_t fat_mapper_xp, 549 uint32_t cluster ) 542 static error_t fatfs_recursive_release( cxy_t mapper_cxy, 543 mapper_t * mapper_ptr, 544 fatfs_ctx_t * fatfs_ctx, 545 uint32_t cluster ) 550 546 { 551 547 uint32_t next; 552 548 553 // get next cluster from FAT mapper 554 if ( mapper_remote_get_32( fat_mapper_xp , cluster , &next ) ) return -1; 549 // build extended pointer on FAT mapper 550 xptr_t mapper_xp = XPTR( mapper_cxy , mapper_ptr ); 551 552 // get next cluster index from FAT mapper 553 if ( mapper_remote_get_32( mapper_xp, 554 cluster, 555 &next ) ) return -1; 555 556 556 557 #if (DEBUG_FATFS_RELEASE_INODE & 1) … … 564 565 { 565 566 // call fatfs_recursive_release() on next cluster 566 if ( fatfs_recursive_release( fat_mapper_xp , next ) ) return -1; 567 if ( fatfs_recursive_release( mapper_cxy, 568 mapper_ptr, 569 fatfs_ctx, 570 next ) ) return -1; 567 571 } 568 572 569 573 // update current cluster in FAT mapper 570 if ( mapper_remote_set_32( fat_mapper_xp, cluster , FREE_CLUSTER ) ) return -1; 574 if ( mapper_remote_set_32( mapper_xp, 575 cluster, 576 FREE_CLUSTER ) ) return -1; 571 577 572 578 // Update free_cluster_hint and free_clusters in FAT context 573 fatfs_free_clusters_increment( cluster ); 579 fatfs_free_clusters_increment( mapper_cxy, 580 fatfs_ctx, 581 cluster ); 574 582 575 583 return 0; … … 582 590 ////////////////////////////////////////////////////////////////////////////////////////// 583 591 584 ////////////////////////////// 585 void fatfs_ctx_display( void ) 586 { 587 // get pointer on local FATFS context 588 vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS]; 589 fatfs_ctx_t * fatfs_ctx = (fatfs_ctx_t *)vfs_ctx->extend; 590 592 /////////////////////////////////////////// 593 void fatfs_ctx_display( fatfs_ctx_t * ctx ) 594 { 591 595 printk("\n*** FAT context ***\n" 592 596 "- fat_sectors = %d\n" … … 599 603 "- free_cluster_hint = %d\n" 600 604 "- fat_mapper_xp = %l\n", 601 fatfs_ctx->fat_sectors_count,602 fatfs_ctx->bytes_per_sector,603 fatfs_ctx->sectors_per_cluster * fatfs_ctx->bytes_per_sector,604 fatfs_ctx->fat_begin_lba,605 fatfs_ctx->cluster_begin_lba,606 fatfs_ctx->root_dir_cluster,607 fatfs_ctx->free_clusters,608 fatfs_ctx->free_cluster_hint,609 fatfs_ctx->fat_mapper_xp );610 611 } // end fatfs_ctx_display()605 ctx->fat_sectors_count, 606 ctx->bytes_per_sector, 607 ctx->sectors_per_cluster * ctx->bytes_per_sector, 608 ctx->fat_begin_lba, 609 ctx->cluster_begin_lba, 610 ctx->root_dir_cluster, 611 ctx->free_clusters, 612 ctx->free_cluster_hint, 613 ctx->fat_mapper_xp ); 614 615 } // end ctx_display() 612 616 613 617 ////////////////////////////////////////// … … 659 663 uint32_t * buffer; // pointer on current page (array of uint32_t) 660 664 uint32_t current_page_index; // index of current page in FAT 661 uint32_t current_ page_offset; // offsetof slot in current page665 uint32_t current_slot_index; // index of slot in current page 662 666 uint32_t page_count_in_file; // index of page in file (index in linked list) 663 667 uint32_t next_cluster_id; // content of current FAT slot … … 670 674 thread_t * this = CURRENT_THREAD; 671 675 if( DEBUG_FATFS_GET_CLUSTER < cycle ) 672 printk("\n[%s] thread[%x,%x] enter / first_cluster_id %d / searched_index / cycle %d\n",676 printk("\n[%s] thread[%x,%x] enter / first_cluster_id %d / searched_index %d / cycle %d\n", 673 677 __FUNCTION__, this->process->pid, this->trdid, first_cluster_id, searched_page_index, cycle ); 674 678 #endif … … 678 682 679 683 // get extended pointer and cluster on FAT mapper 680 xptr_t mapper_xp = ctx->fat_mapper_xp;681 cxy_t mapper_cxy = GET_CXY(mapper_xp );684 xptr_t fat_mapper_xp = ctx->fat_mapper_xp; 685 cxy_t fat_mapper_cxy = GET_CXY( fat_mapper_xp ); 682 686 683 687 // initialize loop variable (1024 slots per page) 684 688 current_page_index = first_cluster_id >> 10; 685 current_ page_offset= first_cluster_id & 0x3FF;689 current_slot_index = first_cluster_id & 0x3FF; 686 690 page_count_in_file = 0; 687 691 next_cluster_id = 0xFFFFFFFF; 688 692 689 // scan FAT (i.e. traverse FAT linked list)693 // scan FAT mapper (i.e. traverse FAT linked list) 690 694 while( page_count_in_file < searched_page_index ) 691 695 { 692 // get pointer on current page descriptor 693 current_page_xp = mapper_remote_get_page( mapper_xp , current_page_index );696 // get pointer on current page descriptor in FAT mapper 697 current_page_xp = mapper_remote_get_page( fat_mapper_xp , current_page_index ); 694 698 695 699 if( current_page_xp == XPTR_NULL ) 696 700 { 697 // TODO701 printk("\n[ERROR] in %s : cannot get next page from FAT mapper\n", __FUNCTION__); 698 702 return -1; 699 703 } … … 704 708 705 709 // get FAT slot content 706 next_cluster_id = hal_remote_l32( XPTR( mapper_cxy , &buffer[current_page_offset] ) ); 710 next_cluster_id = hal_remote_l32( XPTR( fat_mapper_cxy, 711 &buffer[current_slot_index] ) ); 707 712 708 713 #if (DEBUG_FATFS_GET_CLUSTER & 1) 709 714 if( DEBUG_FATFS_GET_CLUSTER < cycle ) 710 715 printk("\n[%s] traverse FAT / current_page_index = %d\n" 711 "current_ page_offset= %d / next_cluster_id = %d\n",712 __FUNCTION__, current_page_index, current_ page_offset, next_cluster_id );716 "current_slot_index = %d / next_cluster_id = %d\n", 717 __FUNCTION__, current_page_index, current_slot_index , next_cluster_id ); 713 718 #endif 714 719 715 720 // update loop variables 716 current_page_index 717 current_ page_offset= next_cluster_id & 0x3FF;721 current_page_index = next_cluster_id >> 10; 722 current_slot_index = next_cluster_id & 0x3FF; 718 723 page_count_in_file++; 719 724 } 720 725 721 if( next_cluster_id == 0xFFFFFFFF ) return -1; 726 if( next_cluster_id == 0xFFFFFFFF ) 727 { 728 printk("\n[ERROR] in %s : searched_cluster_id not found in FAT\n", __FUNCTION__ ); 729 return -1; 730 } 722 731 723 732 #if DEBUG_FATFS_GET_CLUSTER … … 759 768 760 769 #if DEBUG_FATFS_CTX_INIT 761 uint32_t cycle = (uint32_t)hal_get_cycles(); 770 uint32_t cycle = (uint32_t)hal_get_cycles(); 771 thread_t * this = CURRENT_THREAD; 762 772 if( DEBUG_FATFS_CTX_INIT < cycle ) 763 773 printk("\n[%s] thread[%x,%x] enter for fatfs_ctx = %x / cycle %d\n", … … 766 776 767 777 // check argument 768 assert( (fatfs_ctx != NULL) , "pointer on FATFS context is NULL \n" );778 assert( (fatfs_ctx != NULL) , "pointer on FATFS context is NULL" ); 769 779 770 780 // check only cluster 0 does FATFS init 771 assert( (local_cxy == 0) , "only cluster 0 can initialize FATFS \n");781 assert( (local_cxy == 0) , "only cluster 0 can initialize FATFS"); 772 782 773 783 // allocate a 512 bytes buffer to store the boot record … … 882 892 // WARNING : the inode field MUST be NULL for the FAT mapper 883 893 fat_mapper->inode = NULL; 894 884 895 885 896 // initialize the FATFS context … … 895 906 896 907 remote_queuelock_init( XPTR( local_cxy , &fatfs_ctx->free_lock ) , LOCK_FATFS_FREE ); 908 909 #if (DEBUG_FATFS_CTX_INIT & 0x1) 910 if( DEBUG_FATFS_CTX_INIT < cycle ) 911 fatfs_ctx_display( fatfs_ctx ); 912 #endif 897 913 898 914 #if DEBUG_FATFS_CTX_INIT … … 1525 1541 xptr_t child_inode_xp ) 1526 1542 { 1527 uint8_t * entry; // pointer on FAT32 directory entry (array of 32 bytes) 1528 uint32_t index; // index of FAT32 directory entry in mapper 1529 mapper_t * mapper; // pointer on directory mapper 1530 uint32_t cluster; // directory entry cluster 1531 uint32_t size; // directory entry size 1532 bool_t is_dir; // directory entry type (file/dir) 1533 error_t error; 1543 uint8_t * entry; // pointer on FAT32 directory entry (array of 32 bytes) 1544 uint32_t index; // index of FAT32 directory entry in mapper 1545 mapper_t * mapper; // pointer on directory mapper 1546 uint32_t cluster; // directory entry cluster 1547 uint32_t size; // directory entry size 1548 bool_t is_dir; // directory entry type (file/dir) 1549 xptr_t root_xp; // extended pointer on root of parent dentries 1550 xptr_t iter_xp; // iterator for this list 1551 cxy_t child_inode_cxy; // child inode cluster 1552 vfs_inode_t * child_inode_ptr; // child inode local pointer 1553 xptr_t dentry_xp; // extended pointer on searched dentry descriptor 1554 cxy_t dentry_cxy; // cluster identifier of dentry (must be local_cxy) 1555 vfs_dentry_t * dentry_ptr; // local pointer 1556 error_t error; 1557 1558 char dir_name[CONFIG_VFS_MAX_NAME_LENGTH]; 1534 1559 1535 1560 // check arguments … … 1539 1564 1540 1565 #if DEBUG_FATFS_GET_DENTRY 1541 char parent_name[CONFIG_VFS_MAX_NAME_LENGTH];1542 1566 uint32_t cycle = (uint32_t)hal_get_cycles(); 1543 1567 thread_t * this = CURRENT_THREAD; 1544 vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , parent_name );1568 vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , dir_name ); 1545 1569 if( DEBUG_FATFS_GET_DENTRY < cycle ) 1546 1570 printk("\n[%s] thread[%x,%x] enter for child <%s> in parent <%s> / cycle %d\n", 1547 __FUNCTION__, this->process->pid, this->trdid, name , parent_name , cycle );1548 #endif 1549 1550 // get pointer and index of searched directory entry in mapper1571 __FUNCTION__, this->process->pid, this->trdid, name , dir_name , cycle ); 1572 #endif 1573 1574 // get local pointer on parent mapper 1551 1575 mapper = parent_inode->mapper; 1576 1577 // get pointer and index in mapper for searched directory entry 1552 1578 error = fatfs_scan_directory( mapper, name , &entry , &index ); 1553 1579 1554 // update child inode and dentry descriptors if sucess 1555 if( error == 0 ) 1580 if( error ) 1556 1581 { 1582 vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , dir_name ); 1583 printk("\n[ERROR] in %s : cannot find <%s> in parent mapper <%s>\n", 1584 __FUNCTION__, name , dir_name ); 1585 return -1; 1586 } 1587 1588 // get relevant infos from FAT32 directory entry 1589 cluster = (fatfs_get_record( DIR_FST_CLUS_HI , entry , 1 ) << 16) | 1590 (fatfs_get_record( DIR_FST_CLUS_LO , entry , 1 ) ) ; 1591 is_dir = (fatfs_get_record( DIR_ATTR , entry , 1 ) & ATTR_DIRECTORY); 1592 size = fatfs_get_record( DIR_FILE_SIZE , entry , 1 ); 1593 1594 // get child inode cluster and local pointer 1595 child_inode_cxy = GET_CXY( child_inode_xp ); 1596 child_inode_ptr = GET_PTR( child_inode_xp ); 1597 1598 // build extended pointer on root of list of parent dentries 1599 root_xp = XPTR( child_inode_cxy , &child_inode_ptr->parents ); 1600 1601 // check child inode has at least one parent 1602 assert( (xlist_is_empty( root_xp ) == false ), "child inode must have one parent\n"); 1603 1604 // scan list of parent dentries to search the parent_inode 1605 bool_t found = false; 1606 XLIST_FOREACH( root_xp , iter_xp ) 1607 { 1608 // get pointers on dentry 1609 dentry_xp = XLIST_ELEMENT( iter_xp , vfs_dentry_t , parents ); 1610 dentry_cxy = GET_CXY( dentry_xp ); 1611 dentry_ptr = GET_PTR( dentry_xp ); 1612 1613 // get local pointer on current parent directory inode 1614 vfs_inode_t * current = hal_remote_lpt( XPTR( dentry_cxy , &dentry_ptr->parent ) ); 1615 1616 // check if current parent is the searched parent 1617 if( XPTR( dentry_cxy , current ) == XPTR( local_cxy , parent_inode ) ) 1618 { 1619 found = true; 1620 break; 1621 } 1622 } 1623 1624 if( found == false ) 1625 { 1626 vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , dir_name ); 1627 printk("\n[ERROR] in %s : cannot find <%s> directory in list of parents for <%s>\n", 1628 __FUNCTION__, dir_name, name ); 1629 return -1; 1630 } 1631 1632 // update the child inode "type", "size", and "extend" fields 1633 vfs_inode_type_t type = (is_dir) ? INODE_TYPE_DIR : INODE_TYPE_FILE; 1634 1635 hal_remote_s32( XPTR( child_inode_cxy , &child_inode_ptr->type ) , type ); 1636 hal_remote_s32( XPTR( child_inode_cxy , &child_inode_ptr->size ) , size ); 1637 hal_remote_s32( XPTR( child_inode_cxy , &child_inode_ptr->extend ) , cluster ); 1638 1639 // update the dentry "extend" field 1640 dentry_ptr->extend = (void *)(intptr_t)index; 1557 1641 1558 1642 #if DEBUG_FATFS_GET_DENTRY 1559 1643 cycle = (uint32_t)hal_get_cycles(); 1560 1644 if( DEBUG_FATFS_GET_DENTRY < cycle ) 1561 printk("\n[%s] thread[%x,%x] exit / intialised child <%s> in %s / cycle %d\n", 1562 __FUNCTION__, this->process->pid, this->trdid, name, parent_name, cycle ); 1563 #endif 1564 // get relevant infos from FAT32 directory entry 1565 cluster = (fatfs_get_record( DIR_FST_CLUS_HI , entry , 1 ) << 16) | 1566 (fatfs_get_record( DIR_FST_CLUS_LO , entry , 1 ) ) ; 1567 is_dir = (fatfs_get_record( DIR_ATTR , entry , 1 ) & ATTR_DIRECTORY); 1568 size = fatfs_get_record( DIR_FILE_SIZE , entry , 1 ); 1569 1570 // get child inode cluster and local pointer 1571 cxy_t inode_cxy = GET_CXY( child_inode_xp ); 1572 vfs_inode_t * inode_ptr = GET_PTR( child_inode_xp ); 1573 1574 // build extended pointer on root of list of prent dentries 1575 xptr_t parents_root_xp = XPTR( inode_cxy , &inode_ptr->parents ); 1576 1577 // check child inode has at least one parent 1578 assert( (xlist_is_empty( parents_root_xp ) == false ), "child inode must have one parent\n"); 1579 1580 // get dentry pointers and cluster 1581 xptr_t dentry_xp = XLIST_FIRST( parents_root_xp , vfs_dentry_t , parents ); 1582 vfs_dentry_t * dentry_ptr = GET_PTR( dentry_xp ); 1583 cxy_t dentry_cxy = GET_CXY( dentry_xp ); 1584 1585 // check dentry descriptor in same cluster as parent inode 1586 assert( (dentry_cxy == local_cxy) , "illegal dentry cluster\n" ); 1587 1588 // update the child inode "type", "size", and "extend" fields 1589 vfs_inode_type_t type = (is_dir) ? INODE_TYPE_DIR : INODE_TYPE_FILE; 1590 1591 hal_remote_s32( XPTR( inode_cxy , &inode_ptr->type ) , type ); 1592 hal_remote_s32( XPTR( inode_cxy , &inode_ptr->size ) , size ); 1593 hal_remote_s32( XPTR( inode_cxy , &inode_ptr->extend ) , cluster ); 1594 1595 // update the dentry "extend" field 1596 dentry_ptr->extend = (void *)(intptr_t)index; 1597 1598 return 0; 1599 } 1600 else 1601 { 1602 return -1; 1603 } 1645 printk("\n[%s] thread[%x,%x] exit / intialised inode & dentry for <%s> in <%s> / cycle %d\n", 1646 __FUNCTION__, this->process->pid, this->trdid, name, dir_name, cycle ); 1647 #endif 1648 1649 return 0; 1604 1650 1605 1651 } // end fatfs_new_dentry() … … 1615 1661 error_t error; 1616 1662 1663 char dir_name[CONFIG_VFS_MAX_NAME_LENGTH]; 1664 1617 1665 // check arguments 1618 1666 assert( (inode != NULL) , "inode is NULL\n" ); … … 1621 1669 1622 1670 #if DEBUG_FATFS_UPDATE_DENTRY 1623 char dir_name[CONFIG_VFS_MAX_NAME_LENGTH];1624 1671 uint32_t cycle = (uint32_t)hal_get_cycles(); 1625 1672 thread_t * this = CURRENT_THREAD; 1626 1673 vfs_inode_get_name( XPTR( local_cxy , inode ) , dir_name ); 1627 1674 if( DEBUG_FATFS_UPDATE_DENTRY < cycle ) 1628 printk("\n[%s] thread[%x,%x] enter for entry <%s> in dir <%s>/ cycle %d\n",1629 __FUNCTION__, this->process->pid, this->trdid, d entry->name , dir_name, cycle );1630 #endif 1631 1632 // get pointer and index of searched directory entry in mapper1675 printk("\n[%s] thread[%x,%x] enter for <%s/%s> / size %d / cycle %d\n", 1676 __FUNCTION__, this->process->pid, this->trdid, dir_name, dentry->name, size, cycle ); 1677 #endif 1678 1679 // get local pointer on mapper 1633 1680 mapper = inode->mapper; 1681 1682 // get pointer and index in mapper for searched directory entry 1634 1683 error = fatfs_scan_directory( mapper, dentry->name , &entry , &index ); 1635 1684 1636 // update size in mapper if found 1637 if( error == 0 ) 1685 if( error ) 1638 1686 { 1687 vfs_inode_get_name( XPTR( local_cxy , inode ) , dir_name ); 1688 printk("\n[ERROR] in %s : cannot find <%s> in parent mapper <%s>\n", 1689 __FUNCTION__, dentry->name, dir_name ); 1690 return -1; 1691 } 1692 1693 // set size in FAT32 directory entry 1694 fatfs_set_record( DIR_FILE_SIZE , entry , 1 , size ); 1695 1696 // get local pointer on modified page base 1697 void * base = (void *)((intptr_t)entry & (~CONFIG_PPM_PAGE_MASK)); 1698 1699 // get extended pointer on modified page descriptor 1700 xptr_t page_xp = ppm_base2page( XPTR( local_cxy , base ) ); 1701 1702 // synchronously update the modified page on device 1703 error = fatfs_move_page( page_xp , IOC_SYNC_WRITE ); 1704 1705 if( error ) 1706 { 1707 vfs_inode_get_name( XPTR( local_cxy , inode ) , dir_name ); 1708 printk("\n[ERROR] in %s : cannot update parent directory <%s> on device\n", 1709 __FUNCTION__, dir_name ); 1710 return -1; 1711 } 1639 1712 1640 1713 #if DEBUG_FATFS_UPDATE_DENTRY 1641 1714 cycle = (uint32_t)hal_get_cycles(); 1642 1715 if( DEBUG_FATFS_UPDATE_DENTRY < cycle ) 1643 printk("\n[%s] thread[%x,%x] exit / found entry <%s> in <%s> / cycle %d\n", 1644 __FUNCTION__, this->process->pid, this->trdid, dentry->name, dir_name, cycle ); 1645 #endif 1646 // set size in FAT32 directory entry 1647 fatfs_set_record( DIR_FILE_SIZE , entry , 1 , size ); 1648 1649 // get local pointer on modified page base 1650 void * base = (void *)((intptr_t)entry & (~CONFIG_PPM_PAGE_MASK)); 1651 1652 // get extended pointer on modified page descriptor 1653 xptr_t page_xp = ppm_base2page( XPTR( local_cxy , base ) ); 1654 1655 // mark page as dirty 1656 ppm_page_do_dirty( page_xp ); 1657 1658 return 0; 1659 } 1660 else 1661 { 1662 return -1; 1663 } 1716 printk("\n[%s] thread[%x,%x] exit / updated size for <%s/%s> / cycle %d\n", 1717 __FUNCTION__, this->process->pid, this->trdid, dir_name, dentry->name, cycle ); 1718 #endif 1719 1720 return 0; 1664 1721 1665 1722 } // end fatfs_update_dentry() … … 2044 2101 error_t fatfs_cluster_alloc( uint32_t * searched_cluster ) 2045 2102 { 2046 uint32_t page_id; // page index in mapper2103 uint32_t page_id; // page index in FAT mapper 2047 2104 uint32_t slot_id; // slot index in page (1024 slots per page) 2048 uint32_t hint;// first free cluster index in FAT2105 uint32_t cluster; // first free cluster index in FAT 2049 2106 uint32_t free_clusters; // total number of free clusters 2050 2107 vfs_ctx_t * vfs_ctx; // local pointer on VFS context (same in all clusters) … … 2080 2137 fat_fatfs_ctx = hal_remote_lpt( XPTR( mapper_cxy , &vfs_ctx->extend ) ); 2081 2138 2082 // build relevant extended pointers in on free clusters info in FATcluster2139 // build relevant extended pointers on free clusters info in mapper cluster 2083 2140 lock_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->free_lock ); 2084 2141 hint_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->free_cluster_hint ); … … 2089 2146 2090 2147 // get hint and free_clusters values from FATFS context 2091 hint = hal_remote_l32( hint_xp );2148 cluster = hal_remote_l32( hint_xp ) + 1; 2092 2149 free_clusters = hal_remote_l32( numb_xp ); 2093 2150 2094 // get page index & slot index for the first free cluster2095 page_id = (hint + 1) >> 10;2096 slot_id = (hint + 1) & 0x3FF;2097 2098 // get relevant page from mapper2099 page_xp = mapper_remote_get_page( mapper_xp , page_id );2100 2101 if( page_xp == XPTR_NULL )2102 {2103 printk("\n[ERROR] in %s : cannot acces FAT mapper\n", __FUNCTION__ );2104 return -1;2105 }2106 2107 // build extended pointer on free cluster slot2108 slot_xp = ppm_page2base( page_xp ) + (slot_id<<2);2109 2110 2151 #if (DEBUG_FATFS_CLUSTER_ALLOC & 1) 2111 2152 if( DEBUG_FATFS_CLUSTER_ALLOC < cycle ) 2112 printk("\n[%s] thread[%x,%x] get free info /hint %x / free_clusters %x\n",2113 __FUNCTION__, this->process->pid, this->trdid, hint, free_clusters );2153 printk("\n[%s] thread[%x,%x] get free info : hint %x / free_clusters %x\n", 2154 __FUNCTION__, this->process->pid, this->trdid, (cluster - 1), free_clusters ); 2114 2155 #endif 2115 2156 … … 2127 2168 } 2128 2169 2129 // check "hint" 2170 2171 2172 // get page index & slot index for selected cluster 2173 page_id = cluster >> 10; 2174 slot_id = cluster & 0x3FF; 2175 2176 // get relevant page descriptor from mapper 2177 page_xp = mapper_remote_get_page( mapper_xp , page_id ); 2178 2179 if( page_xp == XPTR_NULL ) 2180 { 2181 printk("\n[ERROR] in %s : cannot acces FAT mapper\n", __FUNCTION__ ); 2182 return -1; 2183 } 2184 2185 // build extended pointer on selected cluster slot in FAT mapper 2186 slot_xp = ppm_page2base( page_xp ) + (slot_id << 2); 2187 2188 // check selected cluster actually free 2130 2189 if( hal_remote_l32( slot_xp ) != FREE_CLUSTER ) 2131 2190 { 2132 printk("\n[ERROR] in %s : illegal hint cluster\n", __FUNCTION__);2191 printk("\n[ERROR] in %s : selected cluster %x not free\n", __FUNCTION__, cluster ); 2133 2192 remote_queuelock_acquire( lock_xp ); 2134 2193 return -1; 2135 2194 } 2136 2195 2137 // update allocated cluster in FAT mapper 2138 hal_remote_s32( slot_xp , END_OF_CHAIN_CLUSTER_MAX ); 2139 2140 // update free cluster info 2141 fatfs_free_clusters_decrement( hint + 1 ); 2196 // update free cluster info in FATFS context 2197 fatfs_free_clusters_decrement( mapper_cxy , fat_fatfs_ctx , cluster ); 2142 2198 2143 2199 // release free clusters busylock 2144 2200 remote_queuelock_release( lock_xp ); 2201 2202 // update FAT mapper 2203 hal_remote_s32( slot_xp , END_OF_CHAIN_CLUSTER_MAX ); 2204 2205 // synchronously update FAT on device 2206 fatfs_move_page( page_xp , IOC_SYNC_WRITE ); 2145 2207 2146 2208 #if DEBUG_FATFS_CLUSTER_ALLOC 2147 2209 cycle = (uint32_t)hal_get_cycles(); 2148 2210 if( DEBUG_FATFS_CLUSTER_ALLOC < cycle ) 2149 printk("\n[%s] thread[%x,%x] exit / cluster %x/ cycle %d\n",2150 __FUNCTION__, this->process->pid, this->trdid, hint + 1, cycle );2151 #endif 2152 2153 *searched_cluster = hint + 1;2211 printk("\n[%s] thread[%x,%x] exit / updated cluster %x in FAT / cycle %d\n", 2212 __FUNCTION__, this->process->pid, this->trdid, cluster, cycle ); 2213 #endif 2214 2215 *searched_cluster = cluster; 2154 2216 return 0; 2155 2217 … … 2164 2226 xptr_t mapper_xp; // extended pointer on FAT mapper 2165 2227 cxy_t mapper_cxy; // Fat mapper cluster identifier 2228 mapper_t * mapper_ptr; // local pointer on FAT mapper 2166 2229 xptr_t lock_xp; // extended pointer on lock protecting free clusters info. 2167 2230 xptr_t first_xp; // extended pointer on inode extension … … 2204 2267 loc_fatfs_ctx = vfs_ctx->extend; 2205 2268 2206 // get extended pointerand cluster on FAT mapper2269 // get pointers and cluster on FAT mapper 2207 2270 mapper_xp = loc_fatfs_ctx->fat_mapper_xp; 2208 2271 mapper_cxy = GET_CXY( mapper_xp ); 2272 mapper_ptr = GET_PTR( mapper_xp ); 2209 2273 2210 2274 // get local pointer on FATFS context in FAT cluster … … 2218 2282 2219 2283 // call the recursive function to release all clusters from FAT mapper 2220 if ( fatfs_recursive_release( mapper_xp , first_cluster ) ) 2284 if ( fatfs_recursive_release( mapper_cxy, 2285 mapper_ptr, 2286 fat_fatfs_ctx, 2287 first_cluster ) ) 2221 2288 { 2222 2289 printk("\n[ERROR] in %s : cannot update FAT mapper\n", __FUNCTION__ ); … … 2300 2367 { 2301 2368 // get lba from FATFS context and page_id 2302 uint32_t lba 2369 uint32_t lba = fatfs_ctx->fat_begin_lba + (page_id << 3); 2303 2370 2304 2371 // access device … … 2311 2378 if( error ) return EIO; 2312 2379 2313 #if (DEBUG_FATFS_MOVE_PAGE & 0x1)2314 if( DEBUG_FATFS_MOVE_PAGE < cycle )2315 mapper_display_page( XPTR(page_cxy , mapper_ptr) , page_id );2316 #endif2317 2318 2380 #if DEBUG_FATFS_MOVE_PAGE 2319 cycle = (uint32_t)hal_get_cycles();2320 2381 if( DEBUG_FATFS_MOVE_PAGE < cycle ) 2321 2382 { … … 2357 2418 page_id, 2358 2419 &searched_cluster ); 2359 if( error ) return EIO; 2420 if( error ) 2421 { 2422 printk("\n[ERROR] in %s : cannot access FAT mapper\n", __FUNCTION__ ); 2423 return -1; 2424 } 2360 2425 } 2361 2426 2362 2427 // get lba from searched_cluster 2363 2428 uint32_t lba = fatfs_lba_from_cluster( fatfs_ctx , searched_cluster ); 2429 2430 #if DEBUG_FATFS_MOVE_PAGE 2431 if( DEBUG_FATFS_MOVE_PAGE < cycle ) 2432 { 2433 if ( (cmd_type == IOC_READ) || (cmd_type == IOC_SYNC_READ) ) 2434 printk("\n[%s] thread[%x,%x] load page %d of <%s> / cluster_id %x / cycle %d\n", 2435 __FUNCTION__, this->process->pid, this->trdid, page_id, name, searched_cluster, cycle ); 2436 else 2437 printk("\n[%s] thread[%x,%x] sync page %d of <%s> / cluster_id %x / cycle %d\n", 2438 __FUNCTION__, this->process->pid, this->trdid, page_id, name, searched_cluster, cycle ); 2439 } 2440 #endif 2364 2441 2365 2442 // access device … … 2370 2447 else error = -1; 2371 2448 2372 if( error ) return EIO; 2373 2374 #if (DEBUG_FATFS_MOVE_PAGE & 0x1) 2375 if( DEBUG_FATFS_MOVE_PAGE < cycle ) 2376 mapper_display_page( XPTR(page_cxy , mapper_ptr) , page_id ); 2377 #endif 2378 2379 #if DEBUG_FATFS_MOVE_PAGE 2380 cycle = (uint32_t)hal_get_cycles(); 2381 if(DEBUG_FATFS_MOVE_PAGE < cycle) 2382 { 2383 if ( (cmd_type == IOC_READ) || (cmd_type == IOC_SYNC_READ) ) 2384 printk("\n[%s] thread[%x,%x] load page %d of <%s> inode / cycle %d\n", 2385 __FUNCTION__, this->process->pid, this->trdid, page_id, name, cycle ); 2386 else 2387 printk("\n[%s] thread[%x,%x] sync page %d of <%s> inode / cycle %d\n", 2388 __FUNCTION__, this->process->pid, this->trdid, page_id, name, cycle ); 2389 } 2390 #endif 2391 2449 if( error ) 2450 { 2451 printk("\n[ERROR] in %s : cannot access device\n", __FUNCTION__ ); 2452 return -1; 2453 } 2392 2454 } 2393 2455 -
trunk/kernel/fs/fatfs.h
r623 r625 35 35 // The FATFS File System implements a FAT32 read/write file system. 36 36 // 37 // The FATFS extensions to the generic VFS are the following:37 // The FATFS specific extensions to the generic VFS are the following: 38 38 // 39 39 // 1) The vfs_ctx_t "extend" field is a void* pointing on the fatfs_ctx_t structure. … … 190 190 uint32_t root_dir_cluster; /*! cluster index for root directory */ 191 191 xptr_t fat_mapper_xp; /*! extended pointer on FAT mapper */ 192 uint32_t free_cluster_hint; /*! start point to search free cluster*/192 uint32_t free_cluster_hint; /*! cluster[hint+1] is the first free */ 193 193 uint32_t free_clusters; /*! free clusters number */ 194 194 remote_queuelock_t free_lock; /*! exclusive access to hint & number */ … … 224 224 225 225 /***************************************************************************************** 226 * This function display the content of the FATFS context. 227 ****************************************************************************************/ 228 void fatfs_ctx_display( void ); 226 * This function display the content of the local FATFS context. 227 ***************************************************************************************** 228 * @ ctx : local pointer on the context. 229 ****************************************************************************************/ 230 void fatfs_ctx_display( fatfs_ctx_t * ctx ); 229 231 230 232 /***************************************************************************************** … … 312 314 ***************************************************************************************** 313 315 * It initializes a new inode/dentry couple in Inode Tree, attached to the directory 314 * identified by the <parent_inode> argument. The newdirectory entry is identified315 * by the <name> argument. The child inode descriptor identified by the <child_inode_xp>316 * argument, and the dentry descriptor must have been previously allocated.316 * identified by the <parent_inode> argument. The directory entry is identified 317 * by the <name> argument. The child inode descriptor, identified by the <child_inode_xp> 318 * argument, and the associated dentry descriptor must have been previously allocated. 317 319 * It scan the parent mapper to find the <name> argument. 318 * It set the "type", "size", and "extend" fields in inode descriptor.319 * It set the " extend" field in dentry descriptor.320 * It set the "type", "size", and "extend" fields in the child inode descriptor. 321 * It set the " extend" field in the dentry descriptor. 320 322 * It must be called by a thread running in the cluster containing the parent inode. 321 323 ***************************************************************************************** … … 333 335 ***************************************************************************************** 334 336 * It update the size of a directory entry identified by the <dentry> argument in 335 * the mapper of a directory identified by the <inode> argument, as defined by the <size>336 * argument.337 * the mapper of a directory identified by the <inode> argument, as defined by the 338 * <size> argument. 337 339 * It scan the mapper to find the entry identified by the dentry "name" field. 338 340 * It set the "size" field in the in the directory mapper AND marks the page as DIRTY. … … 427 429 * in <searched_cluster> the FATFS cluster index of a free cluster. 428 430 * It can be called by a thread running in any cluster, as it uses remote access 429 * primitives when the FAT mapper is remote. It takes the "free_lock" stored in the 430 * FATFS context located in the same cluster as the FAT mapper itself, to get exclusive 431 * access to the FAT. It uses (and updates) the <free_cluster_hint> and <free_clusters> 432 * shared variables in this FATFS context. 433 * It updates the FAT mapper, and synchronously updates the FAT region on IOC device. 434 * The FAT mapper being a cache, this function updates the FAT mapper from informations 435 * stored on IOC device in case of miss. 431 * primitives when the FAT mapper is remote. It takes the queuelock stored in the FATFS 432 * context (located in the same cluster as the FAT mapper itself), to get exclusive 433 * access to the FAT. It uses the <free_cluster_hint> and <free_clusters> variables 434 * stored in this FATFS context. 435 * - it updates the <free_cluster_hint> and <free_clusters> variables in FATFS context. 436 * - it updates the FAT mapper (handling miss from IOC device if required). 437 * - it synchronously updates the FAT region on IOC device. 438 * - it returns the allocated cluster index. 436 439 ***************************************************************************************** 437 440 * @ searched_cluster : [out] found FATFS cluster index. … … 461 464 * This function moves a page from/to the mapper to/from the FATFS file system on device. 462 465 * The page must have been previously allocated and registered in the mapper. 463 * The page - and the mapper - can be located in another cluster than the calling thread.464 466 * The pointer on the mapper and the page index in file are found in the page descriptor. 465 467 * It is used for both a regular file/directory mapper, and the FAT mapper. -
trunk/kernel/fs/vfs.c
r623 r625 175 175 else 176 176 { 177 ctx = NULL;178 assert( false , "illegal file system type = %d\n" , fs_type );177 printk("\n[ERROR] in %s : illegal FS type\n", __FUNCTION__ ); 178 return -1; 179 179 } 180 180 … … 185 185 { 186 186 printk("\n[ERROR] in %s : cannot allocate inum\n", __FUNCTION__ ); 187 return ENOMEM;187 return -1; 188 188 } 189 189 … … 378 378 { 379 379 380 assert( (inode != NULL) , "inode pointer is NULL \n" );380 assert( (inode != NULL) , "inode pointer is NULL" ); 381 381 382 382 uint32_t page_id; … … 386 386 uint32_t size = inode->size; 387 387 388 assert( (mapper != NULL) , "mapper pointer is NULL \n" );388 assert( (mapper != NULL) , "mapper pointer is NULL" ); 389 389 390 390 #if DEBUG_VFS_INODE_LOAD_ALL … … 560 560 void vfs_file_destroy( vfs_file_t * file ) 561 561 { 562 563 // check refcount564 // assert( (file->refcount == 0) , "refcount non zero\n" );565 566 562 kmem_req_t req; 567 563 req.ptr = file; … … 766 762 767 763 // check argument 768 assert( (file_xp != XPTR_NULL), "file_xp == XPTR_NULL \n" );764 assert( (file_xp != XPTR_NULL), "file_xp == XPTR_NULL" ); 769 765 770 766 // get cluster and local pointer on remote file descriptor … … 776 772 777 773 // check inode type 778 assert( (inode_type == INODE_TYPE_FILE), " inode type is not INODE_TYPE_FILE" );774 assert( (inode_type == INODE_TYPE_FILE), "bad inode type" ); 779 775 780 776 // get mapper pointer and file offset from file descriptor 781 777 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 782 mapper = (mapper_t *)hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );778 mapper = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) ); 783 779 784 780 // move data between mapper and buffer … … 788 784 buffer, 789 785 size ); 786 if( error ) 787 { 788 printk("\n[ERROR] in %s : cannot move data", __FUNCTION__ ); 789 return -1; 790 } 790 791 791 792 // update file offset in file descriptor 792 793 hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->offset ) , size ); 793 794 794 if( error ) 795 { 796 return -1; 797 } 795 #if DEBUG_VFS_USER_MOVE 796 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 797 uint32_t cycle = (uint32_t)hal_get_cycles(); 798 thread_t * this = CURRENT_THREAD; 799 vfs_inode_t * inode = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 800 vfs_inode_get_name( XPTR( file_cxy , inode ) , name ); 801 if( cycle > DEBUG_VFS_USER_MOVE ) 802 { 803 if( to_buffer ) 804 printk("\n[%s] thread[%x,%x] moves %d bytes from <%s> mapper to buffer (%x) / cycle %d\n", 805 __FUNCTION__ , this->process->pid, this->trdid, size, name, buffer ); 806 else 807 printk("\n[%s] thread[%x,%x] moves %d bytes from buffer (%x) to <%s> mapper / cycle %d\n", 808 __FUNCTION__ , this->process->pid, this->trdid, size, buffer, name ); 809 } 810 #endif 798 811 799 812 return size; … … 816 829 817 830 // check argument 818 assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL \n" );831 assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL" ); 819 832 820 833 // get cluster and local pointer on remote file descriptor … … 825 838 inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 826 839 827 // action depends on inode type 828 if( inode_type == INODE_TYPE_FILE ) 829 { 830 // get mapper pointers and file offset from file descriptor 831 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 832 mapper_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) ); 833 mapper_xp = XPTR( file_cxy , mapper_ptr ); 834 835 // move data between mapper and buffer 836 error = mapper_move_kernel( mapper_xp, 837 to_buffer, 838 file_offset, 839 buffer_xp, 840 size ); 841 if( error ) return -1; 842 } 843 else 844 { 845 printk("\n[ERROR] in %s : inode is not a file", __FUNCTION__ ); 840 // check inode type 841 assert( (inode_type == INODE_TYPE_FILE), "bad file type" ); 842 843 // get mapper pointers and file offset from file descriptor 844 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 845 mapper_ptr = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) ); 846 mapper_xp = XPTR( file_cxy , mapper_ptr ); 847 848 // move data between mapper and buffer 849 error = mapper_move_kernel( mapper_xp, 850 to_buffer, 851 file_offset, 852 buffer_xp, 853 size ); 854 if( error ) 855 { 856 printk("\n[ERROR] in %s : cannot move data", __FUNCTION__ ); 846 857 return -1; 847 858 } 859 860 #if DEBUG_VFS_KERNEL_MOVE 861 char name[CONFIG_VFS_MAX_NAME_LENGTH]; 862 uint32_t cycle = (uint32_t)hal_get_cycles(); 863 thread_t * this = CURRENT_THREAD; 864 cxy_t buffer_cxy = GET_CXY( buffer_xp ); 865 void * buffer_ptr = GET_PTR( buffer_xp ); 866 vfs_inode_t * inode = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 867 vfs_inode_get_name( XPTR( file_cxy , inode ) , name ); 868 if( cycle > DEBUG_VFS_KERNEL_MOVE ) 869 { 870 if( to_buffer ) 871 printk("\n[%s] thread[%x,%x] moves %d bytes from <%s> mapper to buffer(%x,%x) / cycle %d\n", 872 __FUNCTION__ , this->process->pid, this->trdid, size, name, buffer_cxy, buffer_ptr ); 873 else 874 printk("\n[%s] thread[%x,%x] moves %d bytes from buffer(%x,%x) to <%s> mapper / cycle %d\n", 875 __FUNCTION__ , this->process->pid, this->trdid, size, buffer_cxy, buffer_ptr, name ); 876 } 877 #endif 848 878 849 879 return 0; … … 866 896 867 897 // check argument 868 assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL \n" );898 assert( (file_xp != XPTR_NULL) , "file_xp == XPTR_NULL" ); 869 899 870 900 // get cluster and local pointer on remote file descriptor … … 946 976 947 977 // check argument 948 assert( (file_xp != XPTR_NULL) , "file_xp is XPTR_NULL \n" );978 assert( (file_xp != XPTR_NULL) , "file_xp is XPTR_NULL" ); 949 979 950 980 thread_t * this = CURRENT_THREAD; … … 997 1027 #endif 998 1028 999 //////// 2) update file size in all parent directory mapper(s) and ondevice1029 //////// 2) update file size in all parent directory mapper(s) and update device 1000 1030 1001 1031 // get pointers on remote inode … … 1052 1082 vfs_inode_get_name( XPTR( parent_cxy , parent_inode_ptr ) , parent_name ); 1053 1083 if( DEBUG_VFS_CLOSE < cycle ) 1054 printk("\n[%s] thread[%x,%x] updated size of <%s> in parent <%s>\n",1055 __FUNCTION__, process->pid, this->trdid, name, parent_name );1084 printk("\n[%s] thread[%x,%x] updated <%s> in <%s> / size = %d bytes\n", 1085 __FUNCTION__, process->pid, this->trdid, name, parent_name, size ); 1056 1086 #endif 1057 1087 … … 1114 1144 #if DEBUG_VFS_CLOSE 1115 1145 if( DEBUG_VFS_CLOSE < cycle ) 1116 printk("\n[%s] thread[%x,%x] reset all fd-array copies for <% x>\n",1146 printk("\n[%s] thread[%x,%x] reset all fd-array copies for <%s>\n", 1117 1147 __FUNCTION__, process->pid, this->trdid, name ); 1118 1148 #endif … … 1132 1162 cycle = (uint32_t)hal_get_cycles(); 1133 1163 if( DEBUG_VFS_CLOSE < cycle ) 1134 printk("\n[%s] thread[%x,%x] exit / <%s> closed/ cycle %d\n",1135 __FUNCTION__, process->pid, this->trdid, name, cycle );1164 printk("\n[%s] thread[%x,%x] exit / closed <%s> in process %x / cycle %d\n", 1165 __FUNCTION__, process->pid, this->trdid, name, process->pid, cycle ); 1136 1166 #endif 1137 1167 … … 2029 2059 vfs_inode_type_t inode_type; // target inode type 2030 2060 2031 // set lookup working mode 2032 assert( (rights == 0), __FUNCTION__, 2033 "access rights non implemented yet\n" ); 2061 // check lookup working mode 2062 assert( (rights == 0), "access rights non implemented yet" ); 2034 2063 2035 2064 // get extended pointer on target inode … … 2051 2080 // TODO implement this function 2052 2081 2053 assert( false , "not implemented \n" );2082 assert( false , "not implemented" ); 2054 2083 2055 2084 return 0; … … 2061 2090 uint32_t rights ) 2062 2091 { 2063 assert( false , "not implemented cwd_xp: %x, path <%s>, rights %x\n", 2064 cwd_xp, path, rights ); 2092 assert( false , "not implemented %l %x %x", cwd_xp, path, rights ); 2065 2093 return 0; 2066 2094 } … … 2084 2112 vfs_inode_type_t inode_type; 2085 2113 uint32_t inode_size; 2086 uint32_t inode_inum;2087 2114 uint32_t inode_attr; 2088 2115 uint32_t inode_dirty; 2116 void * inode_extd; 2117 2089 2118 xptr_t children_xp; // extended pointer on children xhtab 2090 2119 … … 2115 2144 " " }; // level 15 2116 2145 2117 assert( (inode_xp != XPTR_NULL) , "inode_xp cannot be NULL \n" );2118 assert( (name_xp != XPTR_NULL) , "name_xp cannot be NULL \n" );2119 assert( (indent < 16) , "depth cannot be larger than 15 \n" );2146 assert( (inode_xp != XPTR_NULL) , "inode_xp cannot be NULL" ); 2147 assert( (name_xp != XPTR_NULL) , "name_xp cannot be NULL" ); 2148 assert( (indent < 16) , "depth cannot be larger than 15" ); 2120 2149 2121 2150 // get current inode cluster and local pointer … … 2126 2155 inode_type = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->type ) ); 2127 2156 inode_size = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->size ) ); 2128 inode_inum = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->inum ) );2129 2157 inode_attr = hal_remote_l32( XPTR( inode_cxy , &inode_ptr->attr ) ); 2158 inode_extd = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->extend ) ); 2130 2159 mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) ); 2131 2160 … … 2137 2166 2138 2167 // display inode 2139 nolock_printk("%s<%s> : %s / inum%d / %d bytes / dirty %d / cxy %x / inode %x / mapper %x\n",2140 indent_str[indent], name, vfs_inode_type_str( inode_type ),2141 inode_inum,inode_size, inode_dirty, inode_cxy, inode_ptr, mapper_ptr );2168 nolock_printk("%s<%s> : %s / extd %d / %d bytes / dirty %d / cxy %x / inode %x / mapper %x\n", 2169 indent_str[indent], name, vfs_inode_type_str( inode_type ), (uint32_t)inode_extd, 2170 inode_size, inode_dirty, inode_cxy, inode_ptr, mapper_ptr ); 2142 2171 2143 2172 // scan directory entries when current inode is a directory … … 2405 2434 // check pathname / root_xp consistency 2406 2435 assert( ((pathname[0] != '/') || (root_xp == process->vfs_root_xp)), 2407 "root inode must be VFS root for path <%s> \n", pathname );2436 "root inode must be VFS root for path <%s>", pathname ); 2408 2437 2409 2438 #if DEBUG_VFS_LOOKUP … … 2550 2579 if ( error ) // child not found in parent mapper 2551 2580 { 2552 if ( last && create ) // add a brand new dentry in parent 2581 if ( last && create ) // add a brand new dentry in parent directory 2553 2582 { 2554 2583 error = vfs_new_dentry_init( parent_xp, … … 2705 2734 uint32_t child_size; 2706 2735 2707 #if DEBUG_VFS_NEW_ CHILD_INIT2736 #if DEBUG_VFS_NEW_DENTRY_INIT 2708 2737 char parent_name[CONFIG_VFS_MAX_NAME_LENGTH]; 2709 2738 char child_name[CONFIG_VFS_MAX_NAME_LENGTH]; … … 2712 2741 uint32_t cycle = (uint32_t)hal_get_cycles(); 2713 2742 thread_t * this = CURRENT_THREAD; 2714 if( DEBUG_VFS_NEW_ CHILD_INIT < cycle )2743 if( DEBUG_VFS_NEW_DENTRY_INIT < cycle ) 2715 2744 printk("\n[%s] thread[%x,%x] enter / parent <%s> / child <%s> / cycle %d\n", 2716 2745 __FUNCTION__ , this->process->pid, this->trdid, parent_name, child_name, cycle ); … … 2741 2770 } 2742 2771 2743 #if( DEBUG_VFS_NEW_ CHILD_INIT & 1)2744 if( DEBUG_VFS_NEW_ CHILD_INIT < cycle )2745 printk("\n[%s] thread[%x,%x] allocated one FAT clusterto <%s>\n",2746 __FUNCTION__ , this->process->pid, this->trdid, c hild_name );2772 #if( DEBUG_VFS_NEW_DENTRY_INIT & 1) 2773 if( DEBUG_VFS_NEW_DENTRY_INIT < cycle ) 2774 printk("\n[%s] thread[%x,%x] allocated FAT cluster %x to <%s>\n", 2775 __FUNCTION__ , this->process->pid, this->trdid, cluster, child_name ); 2747 2776 #endif 2748 2777 … … 2775 2804 } 2776 2805 2777 #if DEBUG_VFS_NEW_ CHILD_INIT2806 #if DEBUG_VFS_NEW_DENTRY_INIT 2778 2807 cycle = (uint32_t)hal_get_cycles(); 2779 if( DEBUG_VFS_NEW_ CHILD_INIT < cycle )2808 if( DEBUG_VFS_NEW_DENTRY_INIT < cycle ) 2780 2809 printk("\n[%s] thread[%x,%x] exit / parent <%s> / child <%s> / cycle %d\n", 2781 2810 __FUNCTION__ , this->process->pid, this->trdid, parent_name, child_name, cycle ); … … 3085 3114 3086 3115 // check buffer overflow 3087 assert( (index >= 0) , "kernel buffer too small \n" );3116 assert( (index >= 0) , "kernel buffer too small" ); 3088 3117 3089 3118 } … … 3111 3140 3112 3141 // check buffer overflow 3113 assert( (index >= 0) , "kernel buffer too small \n" );3142 assert( (index >= 0) , "kernel buffer too small" ); 3114 3143 3115 3144 // update pathname … … 3379 3408 error_t error = 0; 3380 3409 3381 assert( (page_xp != XPTR_NULL) , "page pointer is NULL \n" );3410 assert( (page_xp != XPTR_NULL) , "page pointer is NULL" ); 3382 3411 3383 3412 page_t * page_ptr = GET_PTR( page_xp ); … … 3387 3416 mapper_t * mapper = hal_remote_lpt( XPTR( page_cxy , &page_ptr->mapper ) ); 3388 3417 3389 assert( (mapper != NULL) , "no mapper for page \n" );3418 assert( (mapper != NULL) , "no mapper for page" ); 3390 3419 3391 3420 // get FS type … … 3407 3436 else 3408 3437 { 3409 assert( false , "undefined file system type \n" );3438 assert( false , "undefined file system type" ); 3410 3439 } 3411 3440 … … 3420 3449 error_t error = 0; 3421 3450 3422 assert( (inode != NULL) , "inode pointer is NULL \n" );3423 assert( (dentry != NULL) , "dentry pointer is NULL \n" );3451 assert( (inode != NULL) , "inode pointer is NULL" ); 3452 assert( (dentry != NULL) , "dentry pointer is NULL" ); 3424 3453 3425 3454 mapper_t * mapper = inode->mapper; 3426 3455 3427 assert( (mapper != NULL) , "mapper pointer is NULL \n" );3456 assert( (mapper != NULL) , "mapper pointer is NULL" ); 3428 3457 3429 3458 // get FS type … … 3445 3474 else 3446 3475 { 3447 assert( false , "undefined file system type \n" );3476 assert( false , "undefined file system type" ); 3448 3477 } 3449 3478 … … 3458 3487 error_t error = 0; 3459 3488 3460 assert( (inode != NULL) , "inode pointer is NULL \n" );3461 assert( (dentry != NULL) , "dentry pointer is NULL \n" );3489 assert( (inode != NULL) , "inode pointer is NULL" ); 3490 assert( (dentry != NULL) , "dentry pointer is NULL" ); 3462 3491 3463 3492 mapper_t * mapper = inode->mapper; 3464 3493 3465 assert( (mapper != NULL) , "mapper pointer is NULL \n" );3494 assert( (mapper != NULL) , "mapper pointer is NULL" ); 3466 3495 3467 3496 // get FS type … … 3483 3512 else 3484 3513 { 3485 assert( false , "undefined file system type \n" );3514 assert( false , "undefined file system type" ); 3486 3515 } 3487 3516 … … 3498 3527 3499 3528 // check arguments 3500 assert( (parent != NULL) , "parent pointer is NULL \n");3501 assert( (child_xp != XPTR_NULL) , "child pointer is NULL \n");3529 assert( (parent != NULL) , "parent pointer is NULL"); 3530 assert( (child_xp != XPTR_NULL) , "child pointer is NULL"); 3502 3531 3503 3532 // get parent inode FS type … … 3511 3540 else if( fs_type == FS_TYPE_RAMFS ) 3512 3541 { 3513 assert( false , "should not be called for RAMFS \n" );3542 assert( false , "should not be called for RAMFS" ); 3514 3543 } 3515 3544 else if( fs_type == FS_TYPE_DEVFS ) 3516 3545 { 3517 assert( false , "should not be called for DEVFS \n" );3546 assert( false , "should not be called for DEVFS" ); 3518 3547 } 3519 3548 else 3520 3549 { 3521 assert( false , "undefined file system type \n" );3550 assert( false , "undefined file system type" ); 3522 3551 } 3523 3552 … … 3534 3563 3535 3564 // check arguments 3536 assert( (inode != NULL) , "inode pointer is NULL \n");3537 assert( (dentry != NULL) , "dentry pointer is NULL \n");3565 assert( (inode != NULL) , "inode pointer is NULL"); 3566 assert( (dentry != NULL) , "dentry pointer is NULL"); 3538 3567 3539 3568 // get parent inode FS type … … 3547 3576 else if( fs_type == FS_TYPE_RAMFS ) 3548 3577 { 3549 assert( false , "should not be called for RAMFS \n" );3578 assert( false , "should not be called for RAMFS" ); 3550 3579 } 3551 3580 else if( fs_type == FS_TYPE_DEVFS ) 3552 3581 { 3553 assert( false , "should not be called for DEVFS \n" );3582 assert( false , "should not be called for DEVFS" ); 3554 3583 } 3555 3584 else 3556 3585 { 3557 assert( false , "undefined file system type \n" );3586 assert( false , "undefined file system type" ); 3558 3587 } 3559 3588 … … 3574 3603 3575 3604 // check arguments 3576 assert( (inode != NULL) , "parent pointer is NULL \n");3577 assert( (array != NULL) , "child pointer is NULL \n");3605 assert( (inode != NULL) , "parent pointer is NULL"); 3606 assert( (array != NULL) , "child pointer is NULL"); 3578 3607 assert( (detailed == false) , "detailed argument not supported\n"); 3579 3608 … … 3602 3631 else if( fs_type == FS_TYPE_RAMFS ) 3603 3632 { 3604 assert( false , "should not be called for RAMFS \n" );3633 assert( false , "should not be called for RAMFS" ); 3605 3634 } 3606 3635 else if( fs_type == FS_TYPE_DEVFS ) … … 3616 3645 else 3617 3646 { 3618 assert( false , "undefined file system type \n" );3647 assert( false , "undefined file system type" ); 3619 3648 } 3620 3649 … … 3629 3658 3630 3659 // check arguments 3631 assert( (inode != NULL) , "inode pointer is NULL \n");3660 assert( (inode != NULL) , "inode pointer is NULL"); 3632 3661 3633 3662 // get inode FS type … … 3641 3670 else if( fs_type == FS_TYPE_RAMFS ) 3642 3671 { 3643 assert( false , "should not be called for RAMFS \n" );3672 assert( false , "should not be called for RAMFS" ); 3644 3673 } 3645 3674 else if( fs_type == FS_TYPE_DEVFS ) 3646 3675 { 3647 assert( false , "should not be called for DEVFS \n" );3676 assert( false , "should not be called for DEVFS" ); 3648 3677 } 3649 3678 else 3650 3679 { 3651 assert( false , "undefined file system type \n" );3680 assert( false , "undefined file system type" ); 3652 3681 } 3653 3682 … … 3668 3697 else if( fs_type == FS_TYPE_RAMFS ) 3669 3698 { 3670 assert( false , "should not be called for RAMFS \n" );3699 assert( false , "should not be called for RAMFS" ); 3671 3700 } 3672 3701 else if( fs_type == FS_TYPE_DEVFS ) 3673 3702 { 3674 assert( false , "should not be called for DEVFS \n" );3703 assert( false , "should not be called for DEVFS" ); 3675 3704 } 3676 3705 else 3677 3706 { 3678 assert( false , "undefined file system type \n" );3707 assert( false , "undefined file system type" ); 3679 3708 } 3680 3709 … … 3695 3724 else if( fs_type == FS_TYPE_RAMFS ) 3696 3725 { 3697 assert( false , "should not be called for RAMFS \n" );3726 assert( false , "should not be called for RAMFS" ); 3698 3727 } 3699 3728 else if( fs_type == FS_TYPE_DEVFS ) 3700 3729 { 3701 assert( false , "should not be called for DEVFS \n" );3730 assert( false , "should not be called for DEVFS" ); 3702 3731 } 3703 3732 else 3704 3733 { 3705 assert( false , "undefined file system type \n" );3734 assert( false , "undefined file system type" ); 3706 3735 } 3707 3736 … … 3723 3752 else if( fs_type == FS_TYPE_RAMFS ) 3724 3753 { 3725 assert( false , "should not be called for RAMFS \n" );3754 assert( false , "should not be called for RAMFS" ); 3726 3755 } 3727 3756 else if( fs_type == FS_TYPE_DEVFS ) 3728 3757 { 3729 assert( false , "should not be called for DEVFS \n" );3758 assert( false , "should not be called for DEVFS" ); 3730 3759 } 3731 3760 else 3732 3761 { 3733 assert( false , "undefined file system type \n" );3762 assert( false , "undefined file system type" ); 3734 3763 } 3735 3764 … … 3743 3772 error_t error = 0; 3744 3773 3745 assert( (inode_xp != XPTR_NULL) , "inode pointer is NULL \n")3774 assert( (inode_xp != XPTR_NULL) , "inode pointer is NULL") 3746 3775 3747 3776 vfs_inode_t * inode_ptr = GET_PTR( inode_xp ); … … 3751 3780 mapper_t * mapper = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) ); 3752 3781 3753 assert( (mapper != NULL) , "mapper pointer is NULL \n")3782 assert( (mapper != NULL) , "mapper pointer is NULL") 3754 3783 3755 3784 // get FS type from mapper … … 3763 3792 else if( fs_type == FS_TYPE_RAMFS ) 3764 3793 { 3765 assert( false , "should not be called for RAMFS \n" );3794 assert( false , "should not be called for RAMFS" ); 3766 3795 } 3767 3796 else if( fs_type == FS_TYPE_DEVFS ) 3768 3797 { 3769 assert( false , "should not be called for DEVFS \n" );3798 assert( false , "should not be called for DEVFS" ); 3770 3799 } 3771 3800 else 3772 3801 { 3773 assert( false , "undefined file system type \n" );3802 assert( false , "undefined file system type" ); 3774 3803 } 3775 3804 -
trunk/kernel/fs/vfs.h
r623 r625 593 593 * This function is called by the vfs_lookup() function when a new dentry/inode must 594 594 * be created from scratch and introduced in both the Inode Tree and the IOC device. 595 * The dentry and inode descriptors have been created by the caller :595 * The dentry and inode descriptors have been created by the caller. 596 596 * - It allocates one cluster from the relevant FS, and updates the File Allocation 597 597 * Table (both the FAT mapper, and the IOC device). … … 966 966 * the <inode> argument, to find a directory entry identified by the <dentry> argument, 967 967 * and update the size for this directory entry in mapper, as defined by <size>. 968 * The searched "name" is defined in the <dentry> argument, that must be in the same969 * cluster as the parent inode.It is called by the vfs_close() function.968 * The parent directory on device is synchronously updated. 969 * It is called by the vfs_close() function. 970 970 * 971 971 * Depending on the file system type, it calls the relevant, FS specific function.
Note: See TracChangeset
for help on using the changeset viewer.