Changeset 628 for trunk/kernel/fs
- Timestamp:
- May 6, 2019, 1:28:01 PM (6 years ago)
- Location:
- trunk/kernel/fs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/fs/fatfs.c
r627 r628 442 442 443 443 ////////////////////////////////////////////////////////////////////////////////////////// 444 // This static function is called by both the fatfs_free_clusters_increment(), 445 // and the fatfs_free_cluster_decrement() functions defined below. 446 // It synchronously updates the "free_clusters" and "free_cluster_hint" variables 447 // in FS_INFO sector on the IOC device, each times these variables are modified. 448 ////////////////////////////////////////////////////////////////////////////////////////// 449 // @ fatfs_ctx_xp : extended pointer on fatfs context in FAT cluster. 450 // @ free_clusters : new free_clusters value. 451 // @ free_cluster_hint : new free_cluster_hint value. 444 // This static function synchronously updates the FAT on IOC device. 445 // It scan the FAT mapper to copy on IOC device all dirty pages in the interval 446 // defined by the <page_min> & <page_max> arguments. 447 // It can be called by a thread running in any cluster. 448 // WARNING : We don't take the lock protecting the FAT mapper, because the FAT lock 449 // (in FATFS context) must be taken by the calling function. 450 ////////////////////////////////////////////////////////////////////////////////////////// 451 // @ fatfs_ctx_xp : extended pointer on FATFS context in FAT cluster. 452 // @ page_min : first page to be checked. 453 // @ page_max : last page to be checked 452 454 // @ return 0 if success, return -1 if the FS_INFO sector cannot be updated. 453 455 ////////////////////////////////////////////////////////////////////////////////////////// 454 static error_t fatfs_free_clusters_update_ioc( xptr_t fatfs_ctx_xp, 455 uint32_t free_clusters, 456 uint32_t free_cluster_hint ) 456 static error_t fatfs_update_ioc_fat( xptr_t fatfs_ctx_xp, 457 uint32_t page_min, 458 uint32_t page_max ) 459 { 460 461 #if DEBUG_FATFS_UPDATE_IOC 462 uint32_t cycle = (uint32_t)hal_get_cycles(); 463 thread_t * this = CURRENT_THREAD; 464 if( DEBUG_FATFS_UPDATE_IOC < cycle ) 465 printk("\n[%s] thread[%x,%x] enter / page_min %d / page_max %d / cycle %d\n", 466 __FUNCTION__ , this->process->pid, this->trdid, page_min, page_max, cycle ); 467 #endif 468 469 error_t error; 470 cxy_t fat_cxy; // FAT cluster identifier 471 fatfs_ctx_t * fatfs_ctx; // local pointer on FATFS context in FAT cluster 472 xptr_t fat_mapper_xp; // extended pointer on FAT mapper 473 mapper_t * fat_mapper_ptr; // local pointer on FAT mapper 474 uint32_t page_id; // current page index in FAT mapper 475 xptr_t rt_xp; // extended pointer on FAT mapper radix tree 476 xptr_t page_xp; // extended pointer on current page in FAT mapper 477 page_t * page_ptr; // local pointer on current page 478 uint32_t flags; // current page flags 479 480 // get pointer and cluster on FATFS context in FAT cluster 481 fat_cxy = GET_CXY( fatfs_ctx_xp ); 482 fatfs_ctx = GET_PTR( fatfs_ctx_xp ); 483 484 // get FAT mapper pointers from FATFS context 485 fat_mapper_xp = hal_remote_l64( XPTR( fat_cxy , &fatfs_ctx->fat_mapper_xp ) ); 486 fat_mapper_ptr = GET_PTR( fat_mapper_xp ); 487 488 // check FAT cluster 489 assert( (fat_cxy == GET_CXY( fat_mapper_xp )) , "unconsistent FAT cluster" ); 490 491 // build extended pointer on FAT mapper radix tree 492 rt_xp = XPTR( fat_cxy , &fat_mapper_ptr->rt ); 493 494 // scan all pages in [min,max] interval 495 for( page_id = page_min ; page_id <= page_max ; page_id++ ) 496 { 497 // get extended pointer on page descriptor from FAT mapper 498 page_xp = grdxt_remote_lookup( rt_xp , page_id ); 499 500 // check only existing pages 501 if ( page_xp != XPTR_NULL ) 502 { 503 page_ptr = GET_PTR( page_xp ); 504 flags = hal_remote_l32( XPTR( fat_cxy , &page_ptr->flags ) ); 505 506 // copy only dirty pages 507 if ( flags & PG_DIRTY ) 508 { 509 510 #if (DEBUG_FATFS_UPDATE_IOC & 1) 511 if( DEBUG_FATFS_UPDATE_IOC < cycle ) 512 printk("\n[%s] thread[%x,%x] copy page %d from FAT mapper to IOC device\n", 513 __FUNCTION__, page_id ); 514 #endif 515 // move page from mapper to device 516 error = fatfs_move_page( page_xp , IOC_SYNC_WRITE ); 517 518 if ( error ) return -1; 519 520 // reset page dirty flag 521 ppm_page_undo_dirty( page_xp ); 522 } 523 } 524 } // end loop on pages 525 526 #if DEBUG_FATFS_UPDATE_IOC 527 cycle = (uint32_t)hal_get_cycles(); 528 if( DEBUG_FATFS_UPDATE_IOC < cycle ) 529 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 530 __FUNCTION__ , this->process->pid, this->trdid, cycle ); 531 #endif 532 533 return 0; 534 535 } // end fatfs_update_ioc_fat() 536 537 ////////////////////////////////////////////////////////////////////////////////////////// 538 // This static function synchronously updates the FS_INFO sector on IOC device, 539 // from values contained in the FATFS context in FAT cluster. 540 // It uses and updates the FS_INFO buffer allocated in the FAT cluster. 541 // It can be called by a thread running in any cluster. 542 ////////////////////////////////////////////////////////////////////////////////////////// 543 // @ fatfs_ctx_xp : extended pointer on FATFS context in FAT cluster. 544 // @ return 0 if success, return -1 if the FS_INFO sector cannot be updated. 545 ////////////////////////////////////////////////////////////////////////////////////////// 546 static error_t fatfs_update_ioc_fsinfo( xptr_t fatfs_ctx_xp ) 457 547 { 458 548 cxy_t fat_cxy; // FAT cluster identifier 459 549 fatfs_ctx_t * fatfs_ctx_ptr; // local pointer on fatfs context in FAT cluster 550 uint32_t free_clusters; // current vale of "free_clusters" in fatfs context 551 uint32_t free_cluster_hint; // current vale of "free_cluster_hint" in fatfs context 460 552 uint8_t * fs_info_buffer_ptr; // local pointer on FS_INFO buffer in FAT cluster 461 553 xptr_t fs_info_buffer_xp; // extended pointer on FS_INFO buffer in FAT cluster … … 466 558 fatfs_ctx_ptr = GET_PTR( fatfs_ctx_xp ); 467 559 468 // get pointers on FS_INFO buffer in FAT cluster 560 // force FATFS context update 561 hal_fence(); 562 563 // get relevant info from fatfs context in FAT cluster 564 fs_info_lba = hal_remote_l32( XPTR( fat_cxy , &fatfs_ctx_ptr->fs_info_lba ) ); 565 free_clusters = hal_remote_l32( XPTR( fat_cxy , &fatfs_ctx_ptr->free_clusters ) ); 566 free_cluster_hint = hal_remote_l32( XPTR( fat_cxy , &fatfs_ctx_ptr->free_cluster_hint ) ); 469 567 fs_info_buffer_ptr = hal_remote_lpt( XPTR( fat_cxy , &fatfs_ctx_ptr->fs_info_buffer ) ); 568 569 // build extended pointer on FS_INFO buffer in FAT cluster 470 570 fs_info_buffer_xp = XPTR( fat_cxy , fs_info_buffer_ptr ); 471 472 // get lba of FS_INFO sector on IOC device from fatfs context 473 fs_info_lba = hal_remote_l32( XPTR( fat_cxy , &fatfs_ctx_ptr->fs_info_lba ) ); 474 571 475 572 // update the FS_INFO buffer in FAT cluster 476 573 fatfs_set_remote_record( FS_FREE_CLUSTERS , fs_info_buffer_xp , free_clusters ); … … 480 577 return dev_ioc_sync_write( fs_info_buffer_xp , fs_info_lba , 1 ); 481 578 482 } // fatfs_free_clusters_update_ioc()579 } // end fatfs_update_ioc_fsinfo() 483 580 484 581 ////////////////////////////////////////////////////////////////////////////////////////// … … 488 585 // It scan all slots in the FAT mapper seen as an array of 32 bits words, looking for the 489 586 // first free slot larger than the <cluster> argument, to update "free_cluster_hint". 490 // It calls the fatfs_free_clusters_update_ioc() function to synchronously update the 491 // FS_INFO sector on the IOC device. It can be called by a thead running in any cluster. 492 // 493 // WARNING : The lock protecting exclusive access to these variables 494 // must be taken by the calling function. 587 // It synchronously updates the FS_INFO sector on the IOC device. 588 // It can be called by a thead running in any cluster. 589 // The lock protecting exclusive access to the FAT must be taken by the calling function. 495 590 ////////////////////////////////////////////////////////////////////////////////////////// 496 591 // @ fatfs_ctx_xp : extended pointer on FATFS context in FAT cluster. … … 502 597 { 503 598 error_t error; 504 cxy_t fat_cxy; // FAT cluster identifier505 fatfs_ctx_t * fat_ctx_ptr; // local pointer on fatfs context in FAT cluster506 xptr_t mapper_xp;// extended pointer on FAT mapper507 xptr_t hint_xp; // extended pointer on "free_cluster_hint" shared variable508 xptr_t numb_xp; // extended pointer on "free_clusters" shared variable509 uint32_t numb; // "free_clusters" variable current value510 uint32_t hint; // "free_cluster_hint" variable current value511 uint32_t page_id; // page index in FAT mapper512 uint32_t slot_id; // slot index in one page of FAT (1024 slots per page)513 uint32_t page_max; // max number of pages in FAT mapper514 xptr_t page_xp; // extended pointer on current page in FAT mapper515 xptr_t base_xp; // extended pointer on current page base516 xptr_t slot_xp; // extended pointer on current slot in FAT mapper599 cxy_t fat_cxy; // FAT cluster identifier 600 fatfs_ctx_t * fat_ctx_ptr; // local pointer on fatfs context in FAT cluster 601 xptr_t fat_mapper_xp; // extended pointer on FAT mapper 602 xptr_t hint_xp; // extended pointer on "free_cluster_hint" shared variable 603 xptr_t numb_xp; // extended pointer on "free_clusters" shared variable 604 uint32_t numb; // "free_clusters" variable current value 605 uint32_t hint; // "free_cluster_hint" variable current value 606 uint32_t page_id; // page index in FAT mapper 607 uint32_t slot_id; // slot index in one page of FAT (1024 slots per page) 608 uint32_t page_max; // max number of pages in FAT mapper 609 xptr_t page_xp; // extended pointer on current page in FAT mapper 610 xptr_t base_xp; // extended pointer on current page base 611 xptr_t slot_xp; // extended pointer on current slot in FAT mapper 517 612 518 613 #if DEBUG_FATFS_FREE_CLUSTERS … … 537 632 538 633 // get extended pointer on FAT mapper 539 mapper_xp = hal_remote_l64( XPTR( fat_cxy , &fat_ctx_ptr->fat_mapper_xp ) );634 fat_mapper_xp = hal_remote_l64( XPTR( fat_cxy , &fat_ctx_ptr->fat_mapper_xp ) ); 540 635 541 636 // initialise variables to scan the FAT mapper … … 549 644 { 550 645 // get current page from mapper 551 page_xp = mapper_remote_get_page( mapper_xp , page_id );646 page_xp = mapper_remote_get_page( fat_mapper_xp , page_id ); 552 647 553 648 if( page_xp == XPTR_NULL ) … … 574 669 575 670 // update FS_INFO sector on IOC device 576 error = fatfs_free_clusters_update_ioc( fatfs_ctx_xp , numb , hint ); 671 error = fatfs_update_ioc_fat( fatfs_ctx_xp, 672 page_id, 673 page_id ); 577 674 578 675 if( error ) … … 585 682 cycle = (uint32_t)hal_get_cycles(); 586 683 if( DEBUG_FATFS_FREE_CLUSTERS < (uint32_t)hal_get_cycles() ) 587 printk("\n[%s] thread[%x,%x] updated free cluster info / hint %x / number %x\n",684 printk("\n[%s] thread[%x,%x] exit / hint %x / free %x / cycle %d\n", 588 685 __FUNCTION__, this->process->pid, this->trdid, 589 hal_remote_l32(hint_xp), hal_remote_l32(numb_xp) );686 hal_remote_l32(hint_xp), hal_remote_l32(numb_xp), cycle ); 590 687 #endif 591 688 return 0; … … 612 709 // This static function increments the "free_clusters" variable, and updates the 613 710 // "free_cluster_hint" variables in the FATFS context in FAT cluster, identified 614 // by the <fat_ctx_xp> argument, when a cluster is released to FAT.711 // by the <fat_ctx_xp> argument, when a FATFS cluster is released. 615 712 // If the released cluster index is smaller than the current (hint) value, 616 713 // it set "free_cluster_hint" <= cluster. 617 // It calls the fatfs_free_clusters_update_ioc() function to synchronously update the 618 // FS_INFO sector on the IOC device. It can be called by a thead running in any cluster. 619 // 620 // WARNING : The lock protecting exclusive access to these variables 621 // must be taken by the calling function. 714 // It does NOT update the FS_INFO sector on the IOC device. 715 // It can be called by a thead running in any cluster. 716 // The lock protecting exclusive access to the FAT must be taken by the calling function. 622 717 ////////////////////////////////////////////////////////////////////////////////////////// 623 718 // @ fatfs_ctx_xp : extended pointer on FATFS context in FAT cluster. … … 665 760 666 761 // update FS_INFO sector on IOC device 667 error = fatfs_ free_clusters_update_ioc( fatfs_ctx_xp , numb , hint);762 error = fatfs_update_ioc_fsinfo( fatfs_ctx_xp ); 668 763 669 764 if( error ) … … 674 769 675 770 #if DEBUG_FATFS_FREE_CLUSTERS 676 thread_t * this = CURRENT_THREAD;771 cycle = (uint32_t)hal_get_cycles(); 677 772 if( DEBUG_FATFS_FREE_CLUSTERS < (uint32_t)hal_get_cycles() ) 678 printk("\n[%s] thread[%x,%x] updated free cluster info : hint %x / number %x\n",773 printk("\n[%s] thread[%x,%x] exit / hint %x / free %x / cycle %d\n", 679 774 __FUNCTION__, this->process->pid, this->trdid, 680 hal_remote_l32( hint_xp ), hal_remote_l32( numb_xp ) );775 hal_remote_l32( hint_xp ), hal_remote_l32( numb_xp ), cycle ); 681 776 #endif 682 777 … … 686 781 687 782 ////////////////////////////////////////////////////////////////////////////////////////// 688 // This recursive function is called by the generic function fatfs_release_all_clusters() 689 // It release all clusters allocated to a given inode in the FAT mapper. 690 // The removal is done in reverse order of the linked list (from last to first). 691 // It does NOT update the FS on the IOC device. 692 ////////////////////////////////////////////////////////////////////////////////////////// 693 // @ mapper_cxy : FAT mapper cluster identifier. 694 // @ mapper_ptr : local pointer on FAT mapper. 695 // @ fatfs_ctx : local pointer on FATFS context in FAT cluster. 696 // @ cluster : index of cluster to be released from FAT mapper. 697 // @ return 0 if success / return -1 if error (cannot access FAT) 698 ////////////////////////////////////////////////////////////////////////////////////////// 699 static error_t fatfs_recursive_release( cxy_t mapper_cxy, 700 mapper_t * mapper_ptr, 701 fatfs_ctx_t * fatfs_ctx, 702 uint32_t cluster ) 703 { 704 uint32_t next; 705 706 // build extended pointer on FAT mapper 707 xptr_t mapper_xp = XPTR( mapper_cxy , mapper_ptr ); 783 // This recursive function is called by the generic function fatfs_release_inode(). 784 // It release all FATFS clusters allocated to a given inode to the FAT mapper. 785 // It can be called by a thread running in any cluster, as it use remote pointers 786 // to access both the FAT mapper and the FATFS context in the FAT cluster, defined 787 // by the <fat_mapper_xp> and <fatfs_ctx_xp> arguments. 788 // The removal is done in reverse order of the linked list (from last cluster to first). 789 // It returns in the <dirty_page_min> and <dirty_page_max> buffers the indexes of the 790 // modified pages in the FAT mapper. 791 // It updates the FAT mapper and the free_cluster info in the FATFS context, but does NOT 792 // update the FAT and the FS_INFO on IOC device. 793 ////////////////////////////////////////////////////////////////////////////////////////// 794 // @ fat_mapper_xp : [in] extended pointer on FAT mapper. 795 // @ fatfs_ctx_xp : [in] extended pointer on FATFS context in FAT cluster. 796 // @ cluster : [in] index of cluster to be released from FAT mapper. 797 // @ dirty_page_min : [out] pointer on buffer for min dirty page index. 798 // @ dirty_page_max : [out] pointer on buffer for max dirty page index. 799 // @ return 0 if success / return -1 if error. 800 ////////////////////////////////////////////////////////////////////////////////////////// 801 static error_t fatfs_recursive_release( xptr_t fat_mapper_xp, 802 xptr_t fatfs_ctx_xp, 803 uint32_t cluster, 804 uint32_t * dirty_page_min, 805 uint32_t * dirty_page_max ) 806 { 807 uint32_t next; // next cluster index 808 uint32_t page_id; // page index in FAT mapper 809 uint32_t word_id; // word index in page 810 811 // get page index and word index from cluster 812 page_id = cluster >> 10; 813 word_id = cluster & 0x3FF; 708 814 709 815 // get next cluster index from FAT mapper 710 if ( mapper_remote_get_32( mapper_xp, 711 cluster, 816 if ( mapper_remote_get_32( fat_mapper_xp, 817 page_id, 818 word_id, 712 819 &next ) ) return -1; 713 820 … … 722 829 { 723 830 // call fatfs_recursive_release() on next cluster 724 if ( fatfs_recursive_release( mapper_cxy, 725 mapper_ptr, 726 fatfs_ctx, 727 next ) ) return -1; 831 if ( fatfs_recursive_release( fat_mapper_xp, 832 fatfs_ctx_xp, 833 next, 834 dirty_page_min, 835 dirty_page_max ) ) return -1; 728 836 } 729 837 730 // update current cluster in FAT mapper 731 if ( mapper_remote_set_32( mapper_xp, 732 cluster, 838 // update FAT mapper 839 if ( mapper_remote_set_32( fat_mapper_xp, 840 page_id, 841 word_id, 733 842 FREE_CLUSTER ) ) return -1; 734 843 735 // Update free_cluster info in FATFS context and in FS_INFO sector 736 return fatfs_free_clusters_increment( XPTR( mapper_cxy , fatfs_ctx ) , cluster ); 844 // update dirty_page_min / dirty_page_max buffers 845 if( page_id < *dirty_page_min ) *dirty_page_min = page_id; 846 if( page_id > *dirty_page_max ) *dirty_page_max = page_id; 847 848 // Update free_cluster info in FATFS context 849 return fatfs_free_clusters_increment( fatfs_ctx_xp , cluster ); 737 850 738 851 } // end fatfs_recursive_release() … … 1109 1222 fatfs_ctx->fs_info_buffer = buffer; 1110 1223 1111 remote_rwlock_init( XPTR( local_cxy , &fatfs_ctx->lock ) , LOCK_FATFS_F REE);1224 remote_rwlock_init( XPTR( local_cxy , &fatfs_ctx->lock ) , LOCK_FATFS_FAT ); 1112 1225 1113 1226 #if (DEBUG_FATFS_CTX_INIT & 0x1) … … 1760 1873 error_t error; 1761 1874 1762 char dir_name[CONFIG_VFS_MAX_NAME_LENGTH];1875 char dir_name[CONFIG_VFS_MAX_NAME_LENGTH]; 1763 1876 1764 1877 // check arguments … … 2158 2271 } // end fatfs_sync_inode() 2159 2272 2273 2274 2275 2276 2277 2160 2278 ////////////////////////////// 2161 2279 error_t fatfs_sync_fat( void ) … … 2278 2396 ioc_free_cluster_hint = fatfs_get_remote_record( FS_FREE_CLUSTER_HINT , tmp_buf_xp ); 2279 2397 2398 #if DEBUG_FATFS_SYNC_FSINFO 2399 if( DEBUG_FATFS_SYNC_FSINFO < cycle ) 2400 printk("\n[%s] thread[%x,%x] / ctx_free %x / ioc_free %x / ctx_hint %x / ioc_hint %x\n", 2401 __FUNCTION__ , this->process->pid, this->trdid, 2402 ctx_free_clusters, ioc_free_clusters, ctx_free_cluster_hint, ioc_free_cluster_hint ); 2403 #endif 2404 2280 2405 // check values 2281 2406 if( (ioc_free_clusters != ctx_free_clusters) || … … 2327 2452 fatfs_ctx_t * loc_fatfs_ctx; // local pointer on local FATFS context 2328 2453 fatfs_ctx_t * fat_fatfs_ctx; // local pointer on FATFS context in FAT cluster 2329 xptr_t mapper_xp;// extended pointer on FAT mapper2454 xptr_t fat_mapper_xp; // extended pointer on FAT mapper 2330 2455 cxy_t fat_cxy; // Fat mapper cluster identifier 2331 2456 xptr_t page_xp; // extended pointer on current page descriptor in mapper … … 2350 2475 2351 2476 // get extended pointer on FAT mapper 2352 mapper_xp = loc_fatfs_ctx->fat_mapper_xp;2477 fat_mapper_xp = loc_fatfs_ctx->fat_mapper_xp; 2353 2478 2354 2479 // get FAT cluster 2355 fat_cxy = GET_CXY( mapper_xp );2480 fat_cxy = GET_CXY( fat_mapper_xp ); 2356 2481 2357 2482 // get local pointer on FATFS context in FAT cluster … … 2394 2519 2395 2520 // get relevant page descriptor from FAT mapper 2396 page_xp = mapper_remote_get_page( mapper_xp , page_id );2521 page_xp = mapper_remote_get_page( fat_mapper_xp , page_id ); 2397 2522 2398 2523 if( page_xp == XPTR_NULL ) … … 2427 2552 hal_remote_s32( slot_xp , END_OF_CHAIN_CLUSTER_MAX ); 2428 2553 2429 // synchronously update FAT on device 2554 // we don't mark the FAT mapper page as dirty, 2555 // because we synchronously update FAT on IOC device 2430 2556 error = fatfs_move_page( page_xp , IOC_SYNC_WRITE ); 2431 2557 … … 2457 2583 vfs_ctx_t * vfs_ctx; // local pointer on VFS context (same in all clusters). 2458 2584 fatfs_ctx_t * loc_fatfs_ctx; // local pointer on local FATFS context 2459 fatfs_ctx_t * fat_fatfs_ctx; // local pointer on FATFS context in FAT cluster 2460 xptr_t mapper_xp; // extended pointer on FAT mapper 2461 cxy_t mapper_cxy; // Fat mapper cluster identifier 2462 mapper_t * mapper_ptr; // local pointer on FAT mapper 2463 xptr_t lock_xp; // extended pointer on lock protecting free clusters info. 2585 cxy_t fat_cxy; // FAT cluster identifier 2586 xptr_t fatfs_ctx_xp; // extended pointer on FATFS context in FAT cluster 2587 fatfs_ctx_t * fatfs_ctx_ptr; // local pointer on FATFS context in FAT cluster 2588 xptr_t fat_mapper_xp; // extended pointer on FAT mapper 2589 mapper_t * fat_mapper_ptr; // local pointer on FAT mapper 2590 xptr_t lock_xp; // extended pointer on lock protecting FAT. 2464 2591 xptr_t first_xp; // extended pointer on inode extension 2465 2592 uint32_t first_cluster; // first cluster index for released inode 2466 2593 vfs_inode_t * inode_ptr; // local pointer on target inode 2467 2594 cxy_t inode_cxy; // target inode cluster identifier 2595 error_t error; 2468 2596 2469 2597 // check inode pointer … … 2491 2619 #endif 2492 2620 2493 #if (DEBUG_FATFS_RELEASE_INODE & 1)2494 fatfs_display_fat( 0 , 512 );2495 #endif2496 2497 2621 // get local pointer on VFS context (same in all clusters) 2498 2622 vfs_ctx = &fs_context[FS_TYPE_FATFS]; … … 2501 2625 loc_fatfs_ctx = vfs_ctx->extend; 2502 2626 2503 // get pointers and clusteron FAT mapper2504 mapper_xp = loc_fatfs_ctx->fat_mapper_xp;2505 mapper_cxy = GET_CXY(mapper_xp );2506 mapper_ptr = GET_PTR(mapper_xp );2627 // get pointers on FAT mapper 2628 fat_mapper_xp = loc_fatfs_ctx->fat_mapper_xp; 2629 fat_cxy = GET_CXY( fat_mapper_xp ); 2630 fat_mapper_ptr = GET_PTR( fat_mapper_xp ); 2507 2631 2508 // get local pointer on FATFS context in FAT cluster 2509 fat_fatfs_ctx = hal_remote_lpt( XPTR( mapper_cxy , &vfs_ctx->extend ) ); 2632 // get pointers on FATFS context in FAT cluster 2633 fatfs_ctx_ptr = hal_remote_lpt( XPTR( fat_cxy , &vfs_ctx->extend ) ); 2634 fatfs_ctx_xp = XPTR( fat_cxy , fatfs_ctx_ptr ); 2510 2635 2511 2636 // get extended pointer on FAT lock in FAT cluster 2512 lock_xp = XPTR( mapper_cxy , &fat_fatfs_ctx->lock );2637 lock_xp = XPTR( fat_cxy , &fatfs_ctx_ptr->lock ); 2513 2638 2514 2639 // take FAT lock in write mode 2515 2640 remote_rwlock_wr_acquire( lock_xp ); 2516 2641 2642 #if (DEBUG_FATFS_RELEASE_INODE & 0x11 == 0x11) 2643 mapper_display_page( fat_mapper_xp , 0 , 4096 ); 2644 #endif 2645 2517 2646 // call the recursive function to release all clusters from FAT mapper 2518 if ( fatfs_recursive_release( mapper_cxy, 2519 mapper_ptr, 2520 fat_fatfs_ctx, 2521 first_cluster ) ) 2647 uint32_t dirty_page_min = 0xFFFFFFFF; 2648 uint32_t dirty_page_max = 0; 2649 2650 if ( fatfs_recursive_release( fat_mapper_xp, 2651 fatfs_ctx_xp, 2652 first_cluster, 2653 &dirty_page_min, 2654 &dirty_page_max ) ) 2522 2655 { 2523 2656 printk("\n[ERROR] in %s : cannot update FAT mapper\n", __FUNCTION__ ); … … 2531 2664 #endif 2532 2665 2666 #if (DEBUG_FATFS_RELEASE_INODE & 0x11 == 0x11) 2667 mapper_display_page( fat_mapper_xp , 0 , 4096 ); 2668 #endif 2669 2533 2670 // update FAT on IOC device (from FAT mapper) 2534 if ( fatfs_sync_fat() ) 2535 { 2536 printk("\n[ERROR] in %s : cannot update FAT on device\n", __FUNCTION__ ); 2671 error = fatfs_update_ioc_fat( fatfs_ctx_xp, 2672 dirty_page_min, 2673 dirty_page_max ); 2674 2675 if( error ) 2676 { 2677 printk("\n[ERROR] in %s : cannot update FAT on IOC device\n", __FUNCTION__ ); 2537 2678 remote_rwlock_wr_release( lock_xp ); 2538 2679 return -1; … … 2544 2685 #endif 2545 2686 2546 // update FS-INFO sector on IOC device (from FATFS context) 2547 if ( fatfs_sync_free_info() ) 2548 { 2549 printk("\n[ERROR] in %s: cannot update FS_INFO on device\n", __FUNCTION__ ); 2687 // update FS-INFO on IOC device (from FATFS context) 2688 error = fatfs_update_ioc_fsinfo( fatfs_ctx_xp ); 2689 2690 if( error ) 2691 { 2692 printk("\n[ERROR] in %s: cannot update FSINFO on IOC device\n", __FUNCTION__ ); 2550 2693 remote_rwlock_wr_release( lock_xp ); 2551 2694 return -1; 2552 2695 } 2696 2697 #if (DEBUG_FATFS_RELEASE_INODE & 1) 2698 if( DEBUG_FATFS_RELEASE_INODE < cycle ) 2699 printk("\n[%s] updated FS_INFO on IOC device for >%s>\n", __FUNCTION__, name ); 2700 #endif 2553 2701 2554 2702 // release FAT lock -
trunk/kernel/fs/fatfs.h
r627 r628 180 180 * functions to modify the FAT in both the FAT mapper and on IOC device. 181 181 * 182 * WARNING é : Almost all fields are constant values, but the <free_cluster_hint>, 183 * <free_clusters> and <lock> are shared variables. The <fs_info_buffer>, only 184 * allocated in cluster 0, contains a copy of the FS_INFO sector. It is used by all 185 * kernel instances to synchronously update the free clusters info on IOC device. 186 * For these four variables, all kernel instances must use the values in cluster 0, 187 * containing the FAT mapper. 182 * WARNING 2 : Most fields are constant values, but the <free_cluster_hint>, 183 * <free_clusters>, <dirty_page_min>, <dirty_page_max>, <lock>, and the <fs_info_buffer> 184 * are shared variables, that can be modified by any thread running in any cluster. 185 * The <fs_info_buffer> contains a copy of the FS_INFO sector, and is only allocated in 186 * the FAT cluster (i.e. in cluster 0). It is used by all to synchronously update the 187 * free clusters info on IOC device. 188 * => For all these variables, only the values stored in the FAT cluster must be used. 188 189 ****************************************************************************************/ 189 190 … … 201 202 202 203 /* shared variables (only the copy in FAT cluster must be used) */ 204 uint32_t dirty_page_min; /*! min dirty page index in FAT mapper */ 205 uint32_t dirty_page_max; /*! max dirty page index in FAT mapper */ 203 206 uint32_t free_cluster_hint; /*! cluster[hint+1] is the first free */ 204 207 uint32_t free_clusters; /*! free clusters number */ -
trunk/kernel/fs/vfs.c
r626 r628 815 815 assert( (inode_type == INODE_TYPE_FILE), "bad inode type" ); 816 816 817 // get mapper pointer and file offset from file descriptor 818 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 819 mapper = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) ); 820 817 821 #if DEBUG_VFS_USER_MOVE 818 822 char name[CONFIG_VFS_MAX_NAME_LENGTH]; … … 824 828 { 825 829 if( to_buffer ) 826 printk("\n[%s] thread[%x,%x] enter / %d bytes / map per(%s) -> buffer(%x)/ cycle %d\n",827 __FUNCTION__ , this->process->pid, this->trdid, size, name, buffer, cycle );830 printk("\n[%s] thread[%x,%x] enter / %d bytes / map(%s) -> buf(%x) / offset %d / cycle %d\n", 831 __FUNCTION__ , this->process->pid, this->trdid, size, name, buffer, file_offset, cycle ); 828 832 else 829 printk("\n[%s] thread[%x,%x] enter / %d bytes / buf fer(%x) -> mapper(%s)/ cycle %d\n",830 __FUNCTION__ , this->process->pid, this->trdid, size, buffer, name, cycle );833 printk("\n[%s] thread[%x,%x] enter / %d bytes / buf(%x) -> map(%s) / offset %d / cycle %d\n", 834 __FUNCTION__ , this->process->pid, this->trdid, size, buffer, name, file_offset, cycle ); 831 835 } 832 836 #endif 833 834 // get mapper pointer and file offset from file descriptor835 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) );836 mapper = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) );837 837 838 838 // move data between mapper and buffer … … 856 856 { 857 857 if( to_buffer ) 858 printk("\n[%s] thread[%x,%x] exit / %d bytes / mapper(%s) -> buffer(%x) /cycle %d\n",859 __FUNCTION__ , this->process->pid, this->trdid, size, name, buffer,cycle );858 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 859 __FUNCTION__ , this->process->pid, cycle ); 860 860 else 861 printk("\n[%s] thread[%x,%x] exit / %d bytes / buffer(%x) -> mapper(%s) /cycle %d\n",862 __FUNCTION__ , this->process->pid, this->trdid, size, buffer, name,cycle );861 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 862 __FUNCTION__ , this->process->pid, cycle ); 863 863 } 864 864 #endif … … 2538 2538 #if (DEBUG_VFS_LOOKUP & 1) 2539 2539 if( DEBUG_VFS_LOOKUP < cycle ) 2540 printk("\n[%s] thread[%x,%x] look for<%s> in <%s> / last = %d\n",2540 printk("\n[%s] thread[%x,%x] search <%s> in <%s> / last = %d\n", 2541 2541 __FUNCTION__, process->pid, this->trdid, name, pathname, last ); 2542 2542 #endif
Note: See TracChangeset
for help on using the changeset viewer.