Ignore:
Timestamp:
Jul 27, 2017, 12:23:29 AM (7 years ago)
Author:
alain
Message:

1) Introduce independant command fields for the various devices in the thread descriptor.
2) Introduce a new dev_pic_enable_ipi() function in the generic PIC device
3) Fix two bugs identified by Maxime in the scheduler initialisation, and in the sched_select().
4) fix several bugs in the TSAR hal_kentry.S.
5) Introduce a third kgiet segment (besides kdata and kcode) in the TSAR bootloader.

File:
1 edited

Legend:

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

    r265 r279  
    217217} // end get_name_from_long()
    218218
    219 //////////////////////////////////////////////////////////////////////////////////////////
    220 // This function returns the FATFS cluster index of a page identified by its page
    221 // index in the file, using the FAT mapper. It scans the FAT mapper, starting from the
    222 // FATFS cluster index allocated to the first page of the file, until it reaches the
    223 // searched page. The FAT mapper is automatically updated in case of miss.
    224 // This function can be called by any thread running in any cluster, as it uses the
    225 // RPC_FATFS_GET_CLUSTER to access the remote FAT mapper if required.
    226 // We use a RPC to scan the FAT because the RPC_FIFO will avoid contention
    227 // in the cluster containing the FAT mapper, and the RPC latency is not critical
    228 // compared to the device access latency.
    229 //////////////////////////////////////////////////////////////////////////////////////////
    230 // @ ctx               : pointer on local FATFS context.
    231 // @ first_cluster : first cluster allocated to a file in FATFS.
    232 // @ page_index    : index of searched page in file (one page occupies one cluster).
    233 // @ cluster_index : [out] pointer on buffer for FATFS cluster index.
    234 // @ return 0 if success / return EIO if a FAT cluster miss cannot be solved.
    235 //////////////////////////////////////////////////////////////////////////////////////////
    236 static error_t fatfs_cluster_from_index( fatfs_ctx_t * ctx,
    237                                          uint32_t      first_cluster,
    238                                          uint32_t      page_index,
    239                                          uint32_t    * cluster_index )
    240 {
    241     uint32_t searched_cluster;   // searched FATFS cluster index
    242     error_t  error;
    243 
    244     // get extended pointer on FAT mapper
    245     xptr_t fat_mapper_xp = ctx->fat_mapper_xp;
    246 
    247     // get cluster cxy and local pointer on FAT mapper
    248     cxy_t      fat_mapper_cxy = GET_CXY( fat_mapper_xp );
    249     mapper_t * fat_mapper_ptr = (mapper_t *)GET_PTR( fat_mapper_xp );
    250 
    251     if( fat_mapper_cxy == local_cxy )    // FAT mapper is local
    252     {
    253         error = fatfs_get_cluster( fat_mapper_ptr,
    254                                    first_cluster,
    255                                    page_index,
    256                                    &searched_cluster );
    257     }
    258     else                                 // FAT mapper is remote
    259     {
    260         rpc_fatfs_get_cluster_client( fat_mapper_cxy,
    261                                       fat_mapper_ptr,
    262                                       first_cluster,
    263                                       page_index,
    264                                       &searched_cluster,
    265                                       &error );
    266     }
    267    
    268     if( error )
    269     {
    270         printk("\n[ERROR] in %s : cannot access FAT\n", __FUNCTION__ );
    271         return error;
    272     }
    273 
    274     // return success
    275     *cluster_index = searched_cluster;
    276     return 0;
    277 
    278 }  // end fatfs_cluster_from_index()
    279219
    280220//////////////////////////////////////////////////////////////////////////////////////////
     
    400340    uint8_t     * buffer;
    401341
    402     fatfs_dmsg("\n[INFO] %s : enters for fatfs_ctx = %x\n",
     342    fatfs_dmsg("\n[INFO] %s : enter for fatfs_ctx = %x\n",
    403343               __FUNCTION__ , fatfs_ctx );
    404344
     
    414354                   "cannot allocate memory for 512 bytes buffer\n" );
    415355     
     356    fatfs_dmsg("\n[INFO] %s : allocated 512 bytes buffer\n", __FUNCTION__ );
     357
    416358    // load the boot record from device
    417359    // using a synchronous access to IOC device 
    418360    error = dev_ioc_sync_read( buffer , 0 , 1 );
     361
     362    fatfs_dmsg("\n[INFO] %s : buffer loaded\n", __FUNCTION__ );
    419363
    420364    assert( (error == 0) , __FUNCTION__ ,
     
    441385    uint32_t sector_size = fatfs_get_record( BPB_BYTSPERSEC , buffer , 1 );
    442386
    443     nolock_assert( (sector_size == 512) , __FUNCTION__ ,
    444                    "sector size must be 512 bytes\n" );
     387    assert( (sector_size == 512) , __FUNCTION__ ,
     388            "sector size must be 512 bytes\n" );
    445389
    446390    // check cluster size from boot record
    447391    uint32_t nb_sectors = fatfs_get_record( BPB_SECPERCLUS , buffer , 1 );
    448392
    449     nolock_assert( (nb_sectors == 8) , __FUNCTION__ ,
    450                    "cluster size must be 8 sectors\n" );
     393    assert( (nb_sectors == 8) , __FUNCTION__ ,
     394            "cluster size must be 8 sectors\n" );
    451395
    452396    // check number of FAT copies from boot record
    453397    uint32_t nb_fats = fatfs_get_record( BPB_NUMFATS , buffer , 1 );
    454398
    455     nolock_assert( (nb_fats == 1) , __FUNCTION__ ,
    456                    "number of FAT copies must be 1\n" );
     399    assert( (nb_fats == 1) , __FUNCTION__ ,
     400            "number of FAT copies must be 1\n" );
    457401
    458402    // get & check number of sectors in FAT from boot record
    459403    uint32_t fat_sectors = fatfs_get_record( BPB_FAT32_FATSZ32 , buffer , 1 );
    460404
    461     nolock_assert( ((fat_sectors & 0xF) == 0) , __FUNCTION__ ,
    462                    "FAT not multiple of 16 sectors\n");
     405    assert( ((fat_sectors & 0xF) == 0) , __FUNCTION__ ,
     406            "FAT not multiple of 16 sectors\n");
    463407
    464408    // get and check root cluster from boot record
    465409    uint32_t root_cluster = fatfs_get_record( BPB_FAT32_ROOTCLUS , buffer , 1 );
    466410
    467     nolock_assert( (root_cluster == 2) , __FUNCTION__ ,
    468                    "root cluster index must be  2\n");
     411    assert( (root_cluster == 2) , __FUNCTION__ ,
     412            "root cluster index must be  2\n");
    469413
    470414    // get FAT lba from boot record
     
    475419    req.ptr  = buffer;
    476420    kmem_free( &req );
     421
     422    fatfs_dmsg("\n[INFO] %s : boot record read & released\n",
     423               __FUNCTION__ );
    477424
    478425    // allocate a mapper for the FAT itself
     
    494441    fatfs_ctx->last_allocated_index  = 0;    // TODO ???
    495442    fatfs_ctx->fat_mapper_xp         = XPTR( local_cxy , fat_mapper );
     443
     444    fatfs_dmsg("\n[INFO] %s : exit for fatfs_ctx = %x\n",
     445               __FUNCTION__ , fatfs_ctx );
    496446
    497447}  // end fatfs_ctx_init()
Note: See TracChangeset for help on using the changeset viewer.