Ignore:
Timestamp:
Aug 29, 2017, 12:03:37 PM (7 years ago)
Author:
alain
Message:

This version executed successfully the user "init" process on a mono-processor TSAR architecture.

File:
1 edited

Legend:

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

    r401 r406  
    249249error_t fatfs_get_cluster( mapper_t * mapper,
    250250                           uint32_t   first_cluster_id,
    251                            uint32_t   page_index,
     251                           uint32_t   searched_page_index,
    252252                           uint32_t * searched_cluster_id )
    253253{
    254254    page_t   * current_page_desc;      // pointer on current page descriptor
    255255    uint32_t * current_page_buffer;    // pointer on current page (array of uint32_t)
    256     uint32_t   current_page_index;     // index of current page in mapper
     256    uint32_t   current_page_index;     // index of current page in FAT
    257257    uint32_t   current_page_offset;    // offset of slot in current page
    258258    uint32_t   page_count_in_file;     // index of page in file (index in linked list)
    259     uint32_t   current_cluster_id;     // content of current FAT slot
    260 
    261     assert( (page_index > 0) , __FUNCTION__ , "no FAT access required for first page\n");
    262 
    263     fatfs_dmsg("\n[INFO] %s : enters / mapper = %x / first_cluster_id = %d / page_index = %d\n",
    264                __FUNCTION__ , first_cluster_id , page_index );
    265 
    266 #if (CONFIG_FATFS_DEBUG > 1)
    267     xptr_t     base_xp = ppm_page2base( XPTR( local_cxy , mapper_get_page ( mapper , 0 ) ) );
    268     uint32_t * buf     = (uint32_t *)GET_PTR( base_xp );
    269     uint32_t   line , word;
    270     printk("\n***  FAT mapper content for first 256 entries ***\n");
    271     for( line = 0 ; line < 16 ; line++ )
    272     {
    273         printk("%X : ", line );
    274         for( word = 0 ; word < 16 ; word++ ) printk("%X ", buf[(line<<4) + word] );
    275         printk("\n");
    276     }
    277 #endif
    278 
    279     // compute number of FAT slots per page
     259    uint32_t   next_cluster_id;        // content of current FAT slot
     260
     261    assert( (searched_page_index > 0) , __FUNCTION__ ,
     262    "no FAT access required for first page\n");
     263
     264    fatfs_dmsg("\n[DMSG] %s : enter / first_cluster_id = %d / searched_page_index = %d\n",
     265    __FUNCTION__ , first_cluster_id , searched_page_index );
     266
     267    // get number of FAT slots per page
    280268    uint32_t slots_per_page = CONFIG_PPM_PAGE_SIZE >> 2;
    281269
     
    284272    current_page_offset = first_cluster_id % slots_per_page;
    285273    page_count_in_file  = 0;
     274    next_cluster_id     = 0xFFFFFFFF;
    286275
    287276    // scan FAT (i.e. traverse FAT linked list)
    288     while( page_count_in_file <= page_index )
    289     {
    290 
    291         fatfs_dmsg("\n[INFO] %s : page_index = %d / page_offset = %d / count = %d\n",
    292                __FUNCTION__ , current_page_index , current_page_offset , page_count_in_file );
    293 
     277    while( page_count_in_file < searched_page_index )
     278    {
    294279        // get pointer on current page descriptor
    295280        current_page_desc = mapper_get_page( mapper , current_page_index );
     
    302287
    303288        // get FAT slot content
    304         current_cluster_id = current_page_buffer[current_page_offset];
     289        next_cluster_id = current_page_buffer[current_page_offset];
     290
     291        fatfs_dmsg("\n[DMSG] %s : traverse FAT / current_page_index = %d\n"
     292                   "       current_page_offset = %d / next_cluster_id = %d\n",
     293        __FUNCTION__ , current_page_index , current_page_offset , next_cluster_id );
    305294
    306295        // update loop variables
    307         current_page_index  = current_cluster_id / slots_per_page;
    308         current_page_offset = current_cluster_id % slots_per_page;
     296        current_page_index  = next_cluster_id / slots_per_page;
     297        current_page_offset = next_cluster_id % slots_per_page;
    309298        page_count_in_file++;
    310299    }
    311    
    312     fatfs_dmsg("\n[INFO] %s : exit / cluster_id = %d\n",
    313                __FUNCTION__ , current_cluster_id );
    314 
    315     *searched_cluster_id = current_cluster_id;
     300
     301    if( next_cluster_id == 0xFFFFFFFF ) return EIO;
     302   
     303    fatfs_dmsg("\n[DMSG] %s : exit / cluster_id = %d\n", __FUNCTION__ , next_cluster_id );
     304
     305    *searched_cluster_id = next_cluster_id;
    316306    return 0;
    317307
     
    343333    uint8_t     * buffer;
    344334
    345     fatfs_dmsg("\n[INFO] %s : enter for fatfs_ctx = %x\n",
     335    fatfs_dmsg("\n[DMSG] %s : enter for fatfs_ctx = %x\n",
    346336               __FUNCTION__ , fatfs_ctx );
    347337
     
    357347                   "cannot allocate memory for 512 bytes buffer\n" );
    358348     
    359     fatfs_dmsg("\n[INFO] %s : allocated 512 bytes buffer\n", __FUNCTION__ );
     349    fatfs_dmsg("\n[DMSG] %s : allocated 512 bytes buffer\n", __FUNCTION__ );
    360350
    361351    // load the boot record from device
     
    363353    error = dev_ioc_sync_read( buffer , 0 , 1 );
    364354
    365     fatfs_dmsg("\n[INFO] %s : buffer loaded\n", __FUNCTION__ );
    366 
    367     assert( (error == 0) , __FUNCTION__ ,
    368                    "cannot access boot record\n" );
    369 
    370 #if (CONFIG_FATFS_DEBUG > 1)
     355    fatfs_dmsg("\n[DMSG] %s : buffer loaded\n", __FUNCTION__ );
     356
     357    assert( (error == 0) , __FUNCTION__ , "cannot access boot record\n" );
     358
     359#if (CONFIG_FATFS_DEBUG & 0x1)
     360if( hal_time_stamp() > CONFIG_FATFS_DEBUG )
     361{
    371362    uint32_t   line;
    372363    uint32_t   byte = 0;
    373     printk("\n***** FAT boot record\n" );
     364    printk("\n***** %s : FAT boot record\n", __FUNCTION__ );
    374365    for ( line = 0 ; line < 32 ; line++ )
    375366    {
     
    383374         byte += 16;
    384375    }
     376}
    385377#endif
    386378
     
    423415    kmem_free( &req );
    424416
    425     fatfs_dmsg("\n[INFO] %s : boot record read & released\n",
     417    fatfs_dmsg("\n[DMSG] %s : boot record read & released\n",
    426418               __FUNCTION__ );
    427419
     
    445437    fatfs_ctx->fat_mapper_xp         = XPTR( local_cxy , fat_mapper );
    446438
    447     fatfs_dmsg("\n[INFO] %s : exit for fatfs_ctx = %x\n",
     439    fatfs_dmsg("\n[DMSG] %s : exit for fatfs_ctx = %x\n",
    448440               __FUNCTION__ , fatfs_ctx );
    449441
     
    472464    fatfs_ctx_t * fatfs_ctx;   // pointer on local FATFS context
    473465
    474     // get pointer on source mapper and page index from page descriptor
     466    // get pointer on mapper and page index from page descriptor
    475467    mapper = page->mapper;
    476468    index  = page->index;
    477469
    478     // get VFS inode pointer from mapper
     470    // get inode pointer from mapper
    479471    inode = mapper->inode;
    480472
    481     fatfs_dmsg("\n[INFO] %s : core[%x,%d] enter for inode %x / page_id = %d / mapper = %x\n",
    482     __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , inode , index , mapper );
    483 
    484     // get page to move base address
     473    fatfs_dmsg("\n[DMSG] %s : core[%x,%d] enter for page %d / inode %x / mapper %x\n",
     474    __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , index , inode , mapper );
     475
     476    // get page base address
    485477    xptr_t base_xp = ppm_page2base( XPTR( local_cxy , page ) );
    486478    buffer = (uint8_t *)GET_PTR( base_xp );
     
    496488        lba = fatfs_ctx->fat_begin_lba + (count * index);
    497489 
    498         fatfs_dmsg("\n[INFO] %s : core[%x,%d] access FAT on device / lba = %d\n",
     490        fatfs_dmsg("\n[DMSG] %s : core[%x,%d] access FAT on device / lba = %d\n",
    499491        __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , lba );
    500492
     
    519511        else                        // FAT mapper access required
    520512        {
     513            fatfs_dmsg("\n[DMSG] %s : core[%x,%d] must access FAT\n",
     514            __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid );
     515
    521516            // get cluster and local pointer on FAT mapper
    522517            xptr_t     fat_mapper_xp  = fatfs_ctx->fat_mapper_xp;
     
    545540        }
    546541
     542        fatfs_dmsg("\n[DMSG] %s : core[%x,%d] access device for inode %x / cluster_id %d\n",
     543        __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , inode , searched_cluster_id );
     544
    547545        // get lba from cluster_id
    548546        lba = fatfs_lba_from_cluster( fatfs_ctx , searched_cluster_id );
    549 
    550         fatfs_dmsg("\n[INFO] %s : core[%x,%d] access device for inode %x / cluster_id = %d\n",
    551         __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , inode , first_cluster_id );
    552547
    553548        // access device
     
    558553    }
    559554
    560     fatfs_dmsg("\n[INFO] %s : core[%x,%d] exit for inode %x / page_id = %d / mapper = %x\n",
    561     __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , inode , index , mapper );
     555    fatfs_dmsg("\n[DMSG] %s : core[%x,%d] exit for page %d / inode %x / mapper %x\n",
     556    __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , index , inode , mapper );
     557
     558#if (CONFIG_FATFS_DEBUG & 0x1)
     559if( hal_time_stamp() > CONFIG_FATFS_DEBUG )
     560{
     561    uint32_t * tab = (uint32_t *)buffer;
     562    uint32_t line , word;
     563    printk("\n***** %s : First 64 words of loaded page\n", __FUNCTION__ );
     564    for( line = 0 ; line < 8 ; line++ )
     565    {
     566        printk("%X : ", line );
     567        for( word = 0 ; word < 8 ; word++ ) printk("%X ", tab[(line<<3) + word] );
     568        printk("\n");
     569    }
     570}
     571#endif
    562572
    563573    return 0;
     
    574584    // - scan the directory entries in each 4 Kbytes page
    575585
    576     fatfs_dmsg("\n[INFO] %s : enter for child <%s> in parent inode %l\n",
     586    fatfs_dmsg("\n[DMSG] %s : enter for child <%s> in parent inode %l\n",
    577587               __FUNCTION__ , name , XPTR( local_cxy , parent_inode ) );
    578588
     
    612622        base = (uint8_t *)GET_PTR( base_xp );
    613623
    614 #if (CONFIG_FATFS_DEBUG > 1)
     624#if (CONFIG_FATFS_DEBUG & 0x1)
     625if( hal_time_stamp() > CONFIG_FATFS_DEBUG )
     626{
    615627    uint32_t * buf = (uint32_t *)base;
    616628    uint32_t line , word;
    617     printk("\n***** first 16 dir entries for parent inode %x\n", parent_inode );
     629    printk("\n***** %s : First 16 dentries for parent inode %x\n",
     630    __FUNCTION__ , parent_inode );
    618631    for( line = 0 ; line < 16 ; line++ )
    619632    {
     
    622635        printk("\n");
    623636    }
     637}
    624638#endif
    625 
    626 
    627639        // scan this page until end of directory, end of page, or name found
    628640        while( (offset < 4096) && (found == 0) )
     
    693705    if ( found == -1 )  // found end of directory => failure
    694706    {
    695         fatfs_dmsg("\n[INFO] %s : exit / child <%s> not found in parent inode %l\n",
     707        fatfs_dmsg("\n[DMSG] %s : exit / child <%s> not found in parent inode %l\n",
    696708                   __FUNCTION__ , name , XPTR( local_cxy , parent_inode ) );
    697709
     
    711723        hal_remote_sw( XPTR( child_cxy , &child_ptr->extend ) , cluster );
    712724
    713         fatfs_dmsg("\n[INFO] %s : exit / child <%s> found in parent inode %l\n",
     725        fatfs_dmsg("\n[DMSG] %s : exit / child <%s> found in parent inode %l\n",
    714726                   __FUNCTION__ , name , XPTR( local_cxy , parent_inode ) );
    715727
Note: See TracChangeset for help on using the changeset viewer.