Ignore:
Timestamp:
Dec 6, 2019, 12:07:51 PM (4 years ago)
Author:
alain
Message:

Fix several bugs in the FATFS and in the VFS,
related to the creation of big files requiring
more than 4 Kbytes (one cluster) on device.

File:
1 edited

Legend:

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

    r647 r656  
    850850
    851851}  // end fatfs_recursive_release()
     852
     853
     854//////////////////////////////////////////////////////////////////////////////////////////
     855// This static function access the FAT (File Allocation Table), stored in the FAT mapper,
     856// and returns in <searched_cluster_id> the FATFS cluster_id for a given page of a given
     857// inode, identified by the <searched_page_id> argument, that is the page index in file
     858// (i.e. the page index in file mapper). The entry point in the FAT is defined by the
     859// <first_cluster_id> argument, that is the cluster_id of an already allocated cluster.
     860// It can be the cluster_id of the first page of the file (always registered in the
     861// fatfs_inode extension), or any page of the file whose <first_page_id> argument
     862// is smaller than the searched <first_page_id> argument.
     863// This function can be called by a thread running in any cluster, as it uses remote
     864// access primitives when the FAT mapper is remote.
     865// The FAT mapper being a WRITE-THROUGH cache, this function updates the FAT mapper
     866// from informations stored on IOC device in case of miss when scanning the FAT mapper.
     867// The searched inode mapper being a WRITE-BACK cache, this function allocates a new
     868// cluster_id when the searched page exist in the inode mapper, and there is no FATFS
     869// cluster allocated yet for this page. It updates the FAT, but it does NOT copy the
     870// mapper page content to the File System.
     871//////////////////////////////////////////////////////////////////////////////////////////
     872// @ first_page_id       : [in]  index in file mapper for an existing page.
     873// @ first_cluster_id    : [in]  cluster_id for this existing page.
     874// @ searched_page_id    : [in]  index in file mapper for the searched page.
     875// @ searched_cluster_id : [out] cluster_id for the searched page.
     876// @ return 0 if success / return -1 if a FAT mapper miss cannot be solved,
     877//                         or if a missing cluster_id cannot be allocated.
     878//////////////////////////////////////////////////////////////////////////////////////////
     879static error_t fatfs_get_cluster( uint32_t   first_page_id,
     880                                  uint32_t   first_cluster_id,
     881                                  uint32_t   searched_page_id,
     882                                  uint32_t * searched_cluster_id )
     883{
     884    uint32_t   current_page_id;        // index of page in file mapper
     885    uint32_t   current_cluster_id;     // index of cluster in FATFS
     886    xptr_t     lock_xp;                // extended pointer on FAT lock
     887
     888assert( (searched_page_id > first_page_id) ,
     889"searched_page_id must be larger than first_page_id\n");
     890
     891#if DEBUG_FATFS_GET_CLUSTER
     892uint32_t   cycle = (uint32_t)hal_get_cycles();
     893thread_t * this  = CURRENT_THREAD;
     894if( DEBUG_FATFS_GET_CLUSTER < cycle )
     895printk("\n[%s] thread[%x,%x] enter / first_cluster_id %x / searched_page_id %d / cycle %d\n",
     896__FUNCTION__, this->process->pid, this->trdid, first_cluster_id, searched_page_id, cycle );
     897#endif
     898
     899    // get local pointer on VFS context (same in all clusters)
     900    vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS];
     901
     902    // get local pointer on local FATFS context
     903    fatfs_ctx_t * loc_fatfs_ctx = vfs_ctx->extend;
     904
     905    // get extended pointer and cluster on FAT mapper
     906    xptr_t fat_mapper_xp  = loc_fatfs_ctx->fat_mapper_xp;
     907    cxy_t  fat_cxy        = GET_CXY( fat_mapper_xp );
     908
     909    // get local pointer on FATFS context in FAT cluster
     910    fatfs_ctx_t * fat_fatfs_ctx = hal_remote_lpt( XPTR( fat_cxy , &vfs_ctx->extend ) );
     911
     912    // build extended pointer on FAT lock in FAT cluster
     913    lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->lock );
     914
     915    // take FAT lock in read mode
     916    remote_rwlock_rd_acquire( lock_xp );
     917
     918    // initialize loop variables
     919    current_page_id    = first_page_id;
     920    current_cluster_id = first_cluster_id;
     921
     922    // scan FAT mapper (i.e. traverse FAT linked list)
     923    // starting from first_page_id until searched_page_id
     924    // each iteration in this loop can change both
     925    // the FAT page index and the slot index in FAT
     926    while( current_page_id < searched_page_id )
     927    {
     928        // FAT mapper page and slot indexes (1024 slots per FAT page)
     929        uint32_t fat_page_index   = current_cluster_id >> 10;
     930        uint32_t fat_slot_index   = current_cluster_id & 0x3FF;
     931
     932        // get pointer on current page descriptor in FAT mapper
     933        xptr_t current_page_xp = mapper_remote_get_page( fat_mapper_xp , fat_page_index );
     934
     935        if( current_page_xp == XPTR_NULL )
     936        {
     937            printk("\n[ERROR] in %s : cannot get page %d from FAT mapper\n",
     938            __FUNCTION__ , fat_page_index );
     939            remote_rwlock_rd_release( lock_xp );
     940            return -1;
     941        }
     942
     943        // get pointer on buffer containing the FAT mapper page
     944        xptr_t base_xp = ppm_page2base( current_page_xp );
     945        uint32_t * buffer = (uint32_t *)GET_PTR( base_xp );
     946
     947        // get next_cluster_id from FAT slot 
     948        uint32_t next_cluster_id = hal_remote_l32( XPTR( fat_cxy, &buffer[fat_slot_index] ) );
     949
     950        // allocate a new FAT cluster when there is no cluster
     951        // allocated on device for the current page
     952        if( next_cluster_id >= END_OF_CHAIN_CLUSTER_MIN )
     953        {
     954            // release the FAT lock in read mode,
     955            remote_rwlock_rd_release( lock_xp );
     956
     957            // allocate a new cluster_id (and update both FAT mapper and FAT on device).
     958            error_t error = fatfs_cluster_alloc( &next_cluster_id );
     959
     960            if( error )
     961            {
     962                printk("\n[ERROR] in %s : cannot allocate cluster on FAT32 for page %d\n",
     963                __FUNCTION__ , current_page_id );
     964                remote_rwlock_wr_release( lock_xp );
     965                return -1;
     966            }
     967
     968#if (DEBUG_FATFS_GET_CLUSTER & 1)
     969if( DEBUG_FATFS_GET_CLUSTER < cycle )
     970printk("\n[%s] allocated a new cluster_id %d in FATFS\n",
     971__FUNCTION__, next_cluster_id );
     972#endif
     973            // take the FAT lock in read mode,
     974            remote_rwlock_rd_acquire( lock_xp );
     975        }
     976
     977#if (DEBUG_FATFS_GET_CLUSTER & 1)
     978if( DEBUG_FATFS_GET_CLUSTER < cycle )
     979printk("\n[%s] traverse FAT / fat_page_index %d / fat_slot_index %d / next_cluster_id %x\n",
     980__FUNCTION__, fat_page_index, fat_slot_index , next_cluster_id );
     981#endif
     982
     983        // update loop variables
     984        current_cluster_id = next_cluster_id;
     985        current_page_id++;
     986    }
     987   
     988    // release FAT lock
     989    remote_rwlock_rd_release( lock_xp );
     990
     991#if DEBUG_FATFS_GET_CLUSTER
     992if( DEBUG_FATFS_GET_CLUSTER < cycle )
     993printk("\n[%s] thread[%x,%x] exit / searched_cluster_id = %d\n",
     994__FUNCTION__, this->process->pid, this->trdid, current_cluster_id );
     995#endif
     996
     997    *searched_cluster_id = current_cluster_id;
     998    return 0;
     999
     1000}  // end fatfs_get_cluster()
     1001
     1002
     1003
    8521004
    8531005
     
    9041056//////////////////////////////////////////
    9051057void fatfs_display_fat( uint32_t  page_id,
    906                         uint32_t  nentries )
     1058                        uint32_t  min_slot,
     1059                        uint32_t  nb_slots )
    9071060{
    9081061    uint32_t line;
    909     uint32_t maxline;
    9101062
    9111063    // compute number of lines to display
    912     maxline = nentries >> 3;
    913     if( nentries & 0x7 ) maxline++;
     1064    uint32_t min_line = min_slot >> 3;
     1065    uint32_t max_line = (min_slot + nb_slots - 1) >> 3;
    9141066
    9151067    // get pointer on local FATFS context
     
    9171069    fatfs_ctx_t * loc_fatfs_ctx = (fatfs_ctx_t *)vfs_ctx->extend;
    9181070
    919     // get extended pointer on FAT mapper
    920     xptr_t fat_mapper_xp  = loc_fatfs_ctx->fat_mapper_xp;
    921 
    922     // get FAT cluster identifier
    923     cxy_t  fat_cxy = GET_CXY( fat_mapper_xp );
     1071    // get pointers on FAT mapper (in FAT cluster)
     1072    xptr_t     mapper_xp  = loc_fatfs_ctx->fat_mapper_xp;
     1073    cxy_t      mapper_cxy = GET_CXY( mapper_xp );
    9241074
    9251075    // get pointer on FATFS context in FAT cluster
    926     fatfs_ctx_t * fat_fatfs_ctx = hal_remote_lpt( XPTR( fat_cxy , &vfs_ctx->extend ) );
     1076    fatfs_ctx_t * fat_fatfs_ctx = hal_remote_lpt( XPTR( mapper_cxy , &vfs_ctx->extend ) );
    9271077 
    9281078    // get current value of hint and free_clusters
    929     uint32_t hint = hal_remote_l32( XPTR( fat_cxy , &fat_fatfs_ctx->free_cluster_hint ) );
    930     uint32_t free = hal_remote_l32( XPTR( fat_cxy , &fat_fatfs_ctx->free_clusters ) );
    931  
    932     // get extended pointer on requested page in FAT mapper
    933     xptr_t     page_xp  = mapper_remote_get_page( fat_mapper_xp , page_id );
    934 
    935     // get extended pointer on requested page base
     1079    uint32_t hint = hal_remote_l32( XPTR( mapper_cxy , &fat_fatfs_ctx->free_cluster_hint ) );
     1080    uint32_t free = hal_remote_l32( XPTR( mapper_cxy , &fat_fatfs_ctx->free_clusters ) );
     1081
     1082    // get extended pointer on requested page descriptor in FAT mapper
     1083    xptr_t page_xp = mapper_remote_get_page( mapper_xp , page_id );
     1084
     1085    // get pointers on requested page base
    9361086    xptr_t     base_xp  = ppm_page2base( page_xp );
    9371087    void     * base     = GET_PTR( base_xp );
    9381088
    9391089    printk("\n***** FAT mapper / cxy %x / page_id %d / base %x / free_clusters %x / hint %x\n",
    940     fat_cxy, page_id, base, free, hint );
    941 
    942     for( line = 0 ; line < maxline ; line++ )
    943     {
    944         printk("%x : %X | %X | %X | %X | %X | %X | %X | %X\n", (line<<3),
     1090    mapper_cxy, page_id, base, free, hint );
     1091
     1092    for( line = min_line ; line <= max_line ; line++ )
     1093    {
     1094        printk("%d : %X | %X | %X | %X | %X | %X | %X | %X\n", (line<<3),
    9451095        hal_remote_l32( base_xp + ((line<<5)      ) ),
    9461096        hal_remote_l32( base_xp + ((line<<5) + 4  ) ),
     
    9541104
    9551105}  // end fatfs_display_fat()
    956 
    957 ///////////////////////////////////////////////////////
    958 error_t fatfs_get_cluster( uint32_t   first_cluster_id,
    959                            uint32_t   searched_page_index,
    960                            uint32_t * searched_cluster_id )
    961 {
    962     xptr_t     current_page_xp;        // pointer on current page descriptor
    963     uint32_t * buffer;                 // pointer on current page (array of uint32_t)
    964     uint32_t   current_page_index;     // index of current page in FAT
    965     uint32_t   current_slot_index;     // index of slot in current page
    966     uint32_t   page_count_in_file;     // index of page in file (index in linked list)
    967     uint32_t   next_cluster_id;        // content of current FAT slot
    968     xptr_t     lock_xp;                // extended pointer on FAT lock
    969 
    970 assert( (searched_page_index > 0) ,
    971 "no FAT access required for first page\n");
    972 
    973 #if DEBUG_FATFS_GET_CLUSTER
    974 uint32_t   cycle = (uint32_t)hal_get_cycles();
    975 thread_t * this  = CURRENT_THREAD;
    976 if( DEBUG_FATFS_GET_CLUSTER < cycle )
    977 printk("\n[%s] thread[%x,%x] enter / first_cluster_id %d / searched_index %d / cycle %d\n",
    978 __FUNCTION__, this->process->pid, this->trdid, first_cluster_id, searched_page_index, cycle );
    979 #endif
    980 
    981     // get local pointer on VFS context (same in all clusters)
    982     vfs_ctx_t * vfs_ctx = &fs_context[FS_TYPE_FATFS];
    983 
    984     // get local pointer on local FATFS context
    985     fatfs_ctx_t * loc_fatfs_ctx = vfs_ctx->extend;
    986 
    987     // get extended pointer and cluster on FAT mapper
    988     xptr_t fat_mapper_xp  = loc_fatfs_ctx->fat_mapper_xp;
    989     cxy_t  fat_cxy        = GET_CXY( fat_mapper_xp );
    990 
    991     // get local pointer on FATFS context in FAT cluster
    992     fatfs_ctx_t * fat_fatfs_ctx = hal_remote_lpt( XPTR( fat_cxy , &vfs_ctx->extend ) );
    993 
    994     // build extended pointer on FAT lock in FAT cluster
    995     lock_xp = XPTR( fat_cxy , &fat_fatfs_ctx->lock );
    996 
    997     // take FAT lock in read mode
    998     remote_rwlock_rd_acquire( lock_xp );
    999 
    1000     // initialize loop variable (1024 slots per page)
    1001     current_page_index  = first_cluster_id >> 10;
    1002     current_slot_index  = first_cluster_id & 0x3FF;
    1003     page_count_in_file  = 0;
    1004     next_cluster_id     = 0xFFFFFFFF;
    1005 
    1006     // scan FAT mapper (i.e. traverse FAT linked list)
    1007     while( page_count_in_file < searched_page_index )
    1008     {
    1009         // get pointer on current page descriptor in FAT mapper
    1010         current_page_xp = mapper_remote_get_page( fat_mapper_xp , current_page_index );
    1011 
    1012         if( current_page_xp == XPTR_NULL )
    1013         {
    1014             printk("\n[ERROR] in %s : cannot get next page from FAT mapper\n", __FUNCTION__);
    1015             remote_rwlock_rd_release( lock_xp );
    1016             return -1;
    1017         }
    1018 
    1019         // get pointer on buffer for current page
    1020         xptr_t base_xp = ppm_page2base( current_page_xp );
    1021         buffer = (uint32_t *)GET_PTR( base_xp );
    1022 
    1023         // get FAT slot content
    1024         next_cluster_id = hal_remote_l32( XPTR( fat_cxy, &buffer[current_slot_index] ) );
    1025 
    1026 #if (DEBUG_FATFS_GET_CLUSTER & 1)
    1027 if( DEBUG_FATFS_GET_CLUSTER < cycle )
    1028 printk("\n[%s] traverse FAT / current_page_index = %d\n"
    1029 "current_slot_index = %d / next_cluster_id = %d\n",
    1030 __FUNCTION__, current_page_index, current_slot_index , next_cluster_id );
    1031 #endif
    1032         // update loop variables
    1033         current_page_index = next_cluster_id >> 10;
    1034         current_slot_index = next_cluster_id & 0x3FF;
    1035         page_count_in_file++;
    1036     }
    1037 
    1038     if( next_cluster_id == 0xFFFFFFFF )
    1039     {
    1040         printk("\n[ERROR] in %s : searched_cluster_id not found in FAT\n", __FUNCTION__ );
    1041         remote_rwlock_rd_release( lock_xp );
    1042         return -1;
    1043     }
    1044    
    1045     // release FAT lock
    1046     remote_rwlock_rd_release( lock_xp );
    1047 
    1048 #if DEBUG_FATFS_GET_CLUSTER
    1049 cycle = (uint32_t)hal_get_cycles();
    1050 if( DEBUG_FATFS_GET_CLUSTER < cycle )
    1051 printk("\n[%s] thread[%x,%x] exit / searched_cluster_id = %d / cycle %d\n",
    1052 __FUNCTION__, this->process->pid, this->trdid, next_cluster_id / cycle );
    1053 #endif
    1054 
    1055     *searched_cluster_id = next_cluster_id;
    1056     return 0;
    1057 
    1058 }  // end fatfs_get_cluster()
    10591106
    10601107
     
    16911738// by the <mapper> argument, to find the directory entry identified by the <name> argument,
    16921739// and return a pointer on the directory entry, described as and array of 32 bytes, and the
    1693 // incex of this entry in the FAT32 mapper, seen as an array of 32 bytes entries.
     1740// index of this entry in the FAT32 mapper, seen as an array of 32 bytes entries.
    16941741// It is called by the fatfs_new_dentry() and fatfs_update_dentry() functions.
    16951742// It must be called by a thread running in the cluster containing the mapper.
     
    17011748// @ return 0 if found / return 1 if not found / return -1 if mapper access error.
    17021749//////////////////////////////////////////////////////////////////////////////////////////////
    1703 error_t fatfs_scan_directory( mapper_t *  mapper,
    1704                               char     *  name,
    1705                               uint8_t  ** entry,
    1706                               uint32_t *  index )
     1750static error_t fatfs_scan_directory( mapper_t *  mapper,
     1751                                     char     *  name,
     1752                                     uint8_t  ** entry,
     1753                                     uint32_t *  index )
    17071754{
    17081755    // Two embedded loops to scan the directory mapper:
     
    17251772#endif
    17261773
    1727     char       cname[CONFIG_VFS_MAX_NAME_LENGTH];  // name extracted from each directory entry
     1774    char       cname[CONFIG_VFS_MAX_NAME_LENGTH];  // name extracted from directory entry
    17281775
    17291776    char       lfn1[16];         // buffer for one partial cname
     
    17611808#if (DEBUG_FATFS_SCAN_DIRECTORY & 0x1)
    17621809if( DEBUG_FATFS_SCAN_DIRECTORY < cycle )
    1763 mapper_display_page( mapper_xp , page_id , 256 );
     1810mapper_display_page( mapper_xp , page_xp , 256 );
    17641811#endif
    17651812        // scan this page until end of directory, end of page, or name found
     
    18831930    error_t        error;
    18841931
    1885     char           dir_name[CONFIG_VFS_MAX_NAME_LENGTH];
     1932    char           parent_name[CONFIG_VFS_MAX_NAME_LENGTH];
    18861933
    18871934// check arguments
     
    19001947assert( (xlist_is_empty( root_xp ) == false ), "child inode must have one parent\n");
    19011948
    1902 #if DEBUG_FATFS_GET_DENTRY
     1949#if DEBUG_FATFS_NEW_DENTRY
    19031950uint32_t   cycle = (uint32_t)hal_get_cycles();
    19041951thread_t * this  = CURRENT_THREAD;
    1905 vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , dir_name );
    1906 if( DEBUG_FATFS_GET_DENTRY < cycle )
     1952vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , parent_name );
     1953if( DEBUG_FATFS_NEW_DENTRY < cycle )
    19071954printk("\n[%s]  thread[%x,%x] enter for child <%s> in parent <%s> / cycle %d\n",
    1908 __FUNCTION__, this->process->pid, this->trdid, name , dir_name , cycle );
     1955__FUNCTION__, this->process->pid, this->trdid, name , parent_name , cycle );
    19091956#endif
    19101957
     
    19161963
    19171964    // return non fatal error if not found
    1918     if( error ) return -1;
     1965    if( error )
     1966    {
     1967        vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , parent_name );
     1968        printk("\n[ERROR] in %s : cannot find <%s> entry in <%s> directory mapper\n",
     1969        __FUNCTION__, name , parent_name, name );
     1970        return -1;
     1971    }
     1972 
    19191973
    19201974    // get relevant infos from FAT32 directory entry
     
    19462000    if( found == false )
    19472001    {
    1948         vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , dir_name );
     2002        vfs_inode_get_name( XPTR( local_cxy , parent_inode ) , parent_name );
    19492003        printk("\n[ERROR] in %s : cannot find <%s> directory in list of parents for <%s>\n",
    1950         __FUNCTION__, dir_name, name );
     2004        __FUNCTION__, parent_name, name );
    19512005        return -1;
    19522006    }
     
    19622016    dentry_ptr->extend = (void *)(intptr_t)index;
    19632017
    1964 #if DEBUG_FATFS_GET_DENTRY
     2018#if DEBUG_FATFS_NEW_DENTRY
    19652019cycle = (uint32_t)hal_get_cycles();
    1966 if( DEBUG_FATFS_GET_DENTRY < cycle )
    1967 printk("\n[%s]  thread[%x,%x] exit / intialised inode & dentry for <%s> in <%s> / cycle %d\n",
    1968 __FUNCTION__, this->process->pid, this->trdid, name, dir_name, cycle );
     2020if( DEBUG_FATFS_NEW_DENTRY < cycle )
     2021printk("\n[%s]  thread[%x,%x] exit for <%s> in <%s> / cluster_id %x / size %d  / cycle %d\n",
     2022__FUNCTION__, this->process->pid, this->trdid, name, parent_name, cluster, size,  cycle );
     2023#endif
     2024
     2025
     2026#if (DEBUG_FATFS_NEW_DENTRY & 1)
     2027if( DEBUG_FATFS_NEW_DENTRY < cycle )
     2028{
     2029    fatfs_display_fat( 0 , 0 , 64 );
     2030    fatfs_display_fat( cluster >> 10 ,  (cluster & 0x3FF) , 32 );
     2031}
    19692032#endif
    19702033
     
    19882051assert( (inode  != NULL) , "inode is NULL\n" );
    19892052assert( (dentry != NULL) , "dentry is NULL\n" );
    1990 assert( (size   != 0   ) , "size is 0\n" );
    19912053
    19922054#if DEBUG_FATFS_UPDATE_DENTRY
     
    20132075    }
    20142076
    2015     // set size in FAT32 directory entry
    2016     fatfs_set_record( DIR_FILE_SIZE , entry , size );
    2017 
    2018     // get local pointer on modified page base
    2019     void * base = (void *)((intptr_t)entry & (~CONFIG_PPM_PAGE_MASK));
    2020 
    2021     // get extended pointer on modified page descriptor
    2022     xptr_t page_xp = ppm_base2page( XPTR( local_cxy , base ) );
    2023 
    2024     // synchronously update the modified page on device
    2025     error = fatfs_move_page( page_xp , IOC_SYNC_WRITE );
    2026 
    2027     if( error )
    2028     {
    2029         vfs_inode_get_name( XPTR( local_cxy , inode ) , dir_name );
    2030         printk("\n[ERROR] in %s : cannot update parent directory <%s> on device\n",
    2031         __FUNCTION__, dir_name );
    2032         return -1;
     2077    // get current size value
     2078    uint32_t current_size = fatfs_get_record( DIR_FILE_SIZE , entry );
     2079
     2080    // update dentry in mapper & device only if required
     2081    if( size != current_size )
     2082    {
     2083        // set size field in FAT32 directory entry
     2084        fatfs_set_record( DIR_FILE_SIZE , entry , size );
     2085
     2086        // get pointer on modified page base
     2087        void * base = (void *)((intptr_t)entry & (~CONFIG_PPM_PAGE_MASK));
     2088
     2089        // get extended pointer on modified page descriptor
     2090        xptr_t page_xp = ppm_base2page( XPTR( local_cxy , base ) );
     2091
     2092        // synchronously update the modified page on device
     2093        error = fatfs_move_page( page_xp , IOC_SYNC_WRITE );
     2094
     2095        if( error )
     2096        {
     2097            vfs_inode_get_name( XPTR( local_cxy , inode ) , dir_name );
     2098            printk("\n[ERROR] in %s : cannot update parent directory <%s> on device\n",
     2099            __FUNCTION__, dir_name );
     2100            return -1;
     2101        }
    20332102    }
    20342103
     
    25862655    return 0;
    25872656
    2588 }  // end fat_cluster_alloc()
     2657}  // end fatfs_cluster_alloc()
    25892658
    25902659//////////////////////////////////////////////
     
    27372806#endif
    27382807
    2739     // get page cluster an local pointer
     2808    // get page cluster and local pointer
    27402809    cxy_t    page_cxy = GET_CXY( page_xp );
    27412810    page_t * page_ptr = GET_PTR( page_xp );
     
    27542823    inode_ptr  = hal_remote_lpt( XPTR( page_cxy , &mapper_ptr->inode ) );
    27552824
     2825    //////////////////////////////  FAT mapper  /////////////////////////////////////////
     2826    if( inode_ptr == NULL )
     2827    {
     2828
    27562829#if DEBUG_FATFS_MOVE_PAGE
    27572830if( DEBUG_FATFS_MOVE_PAGE < cycle )
    2758 printk("\n[%s] thread[%x,%x] enters : %s / cxy %x / mapper %x / inode %x / page %x\n",
    2759 __FUNCTION__, this->process->pid, this->trdid,
    2760 dev_ioc_cmd_str( cmd_type ), page_cxy, mapper_ptr, inode_ptr, GET_PTR(buffer_xp) );
    2761 #endif
    2762 
    2763     //////////////////////////////  FAT mapper
    2764     if( inode_ptr == NULL )
    2765     {
     2831printk("\n[%s] thread[%x,%x] enters for %s /  page %d in FAT mapper / cycle %d\n",
     2832__FUNCTION__, this->process->pid, this->trdid, dev_ioc_cmd_str(cmd_type), page_id, cycle );
     2833#endif
    27662834        // get lba from FATFS context and page_id
    27672835        uint32_t      lba = fatfs_ctx->fat_begin_lba + (page_id << 3);
     
    27782846#if DEBUG_FATFS_MOVE_PAGE
    27792847if( DEBUG_FATFS_MOVE_PAGE < cycle )
    2780 {
    2781     if ( (cmd_type == IOC_READ) || (cmd_type == IOC_SYNC_READ) )
    2782         printk("\n[%s] thread[%x,%x] load FAT mapper page %d from IOC / cycle %d\n",
    2783         __FUNCTION__, this->process->pid, this->trdid, page_id, cycle );
    2784     else
    2785         printk("\n[%s] thread[%x,%x] sync FAT mapper page %d to IOC / cycle %d\n",
    2786         __FUNCTION__, this->process->pid, this->trdid, page_id, cycle );
    2787 }
    2788 #endif
    2789 
    2790     }
    2791     /////////////////////////  inode mapper
     2848printk("\n[%s] thread[%x,%x] exit / page %d in FAT mapper\n",
     2849__FUNCTION__, this->process->pid, this->trdid, page_id, cycle );
     2850#endif
     2851
     2852    }
     2853    /////////////////////////  inode mapper  ////////////////////////////////////////////
    27922854    else                       
    27932855    {
     
    27952857#if DEBUG_FATFS_MOVE_PAGE
    27962858vfs_inode_get_name( XPTR( page_cxy , inode_ptr ) , name );
    2797 #endif
    2798 
    2799         uint32_t  searched_cluster;
    2800         uint32_t  first_cluster;
    2801 
    2802         // get first_cluster from inode extension
    2803         void * extend = hal_remote_lpt( XPTR( page_cxy , &inode_ptr->extend ) );
    2804         first_cluster = (uint32_t)(intptr_t)extend;
    2805 
    2806         // compute searched_cluster
     2859if( DEBUG_FATFS_MOVE_PAGE < cycle )
     2860printk("\n[%s] thread[%x,%x] enters for %s / page %d in <%s> mapper/ cycle %d\n",
     2861__FUNCTION__, this->process->pid, this->trdid,
     2862dev_ioc_cmd_str( cmd_type ), page_id, name, cycle );
     2863#endif
     2864
     2865        uint32_t  searched_cluster_id;
     2866        uint32_t  first_cluster_id;
     2867
     2868        // get first_cluster_id from inode extension
     2869        void * extend    = hal_remote_lpt( XPTR( page_cxy , &inode_ptr->extend ) );
     2870        first_cluster_id = (uint32_t)(intptr_t)extend;
     2871
     2872        // compute searched_cluster_id
    28072873        if( page_id == 0 )            // no need to access FAT mapper
    28082874        {
    28092875            // searched cluster is first cluster
    2810             searched_cluster = first_cluster;
     2876            searched_cluster_id = first_cluster_id;
    28112877        }
    28122878        else                        // FAT mapper access required
    28132879        {
    2814             // access FAT mapper to get searched cluster
    2815             error = fatfs_get_cluster( first_cluster,
     2880            // scan FAT mapper to get searched_cluster_id
     2881            error = fatfs_get_cluster( 0,                    // first page in mapper
     2882                                       first_cluster_id,
    28162883                                       page_id,
    2817                                        &searched_cluster );
     2884                                       &searched_cluster_id );
    28182885            if( error )
    28192886            {
    2820                 printk("\n[ERROR] in %s : cannot access FAT mapper\n", __FUNCTION__ );
     2887                printk("\n[ERROR] in %s : cannot get cluster_id\n", __FUNCTION__ );
    28212888                return -1;
    28222889            }
     
    28242891
    28252892        // get lba for searched_cluster
    2826         uint32_t lba = fatfs_lba_from_cluster( fatfs_ctx , searched_cluster );
    2827 
    2828         // access IOC device
     2893        uint32_t lba = fatfs_lba_from_cluster( fatfs_ctx , searched_cluster_id );
     2894
     2895        // access IOC device to move 8 blocks
    28292896        error = dev_ioc_move_data( cmd_type , buffer_xp , lba , 8 );
    28302897
     
    28372904#if DEBUG_FATFS_MOVE_PAGE
    28382905if( DEBUG_FATFS_MOVE_PAGE < cycle )
    2839 {
    2840     if ( (cmd_type == IOC_READ) || (cmd_type == IOC_SYNC_READ) )
    2841     printk("\n[%s] thread[%x,%x] load page %d of <%s> / cluster_id %x / cycle %d\n",
    2842     __FUNCTION__, this->process->pid, this->trdid, page_id, name, searched_cluster, cycle );
    2843     else
    2844     printk("\n[%s] thread[%x,%x] sync page %d of <%s> / cluster_id %x / cycle %d\n",
    2845     __FUNCTION__, this->process->pid, this->trdid, page_id, name, searched_cluster, cycle );
    2846 }
     2906vfs_inode_get_name( XPTR( page_cxy, inode_ptr ) , name );
     2907printk("\n[%s] thread[%x,%x] exit / page %d in <%s> mapper / cluster_id %x\n",
     2908__FUNCTION__, this->process->pid, this->trdid, page_id, name, searched_cluster_id );
    28472909#endif
    28482910
Note: See TracChangeset for help on using the changeset viewer.