Ignore:
Timestamp:
Jun 26, 2017, 3:15:11 PM (7 years ago)
Author:
alain
Message:

bloup

File:
1 edited

Legend:

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

    r23 r50  
    3636#include <fatfs.h>
    3737
     38
    3839//////////////////////////////////////////////////////////////////////////////////////////
    3940//          Extern  variables         
    4041//////////////////////////////////////////////////////////////////////////////////////////
    4142
    42 extern vfs_ctx_t        fs_context[FS_TYPES_NR];   // allocated in vfs.c file
    43 
    44 extern remote_barrier_t global_barrier;            // allocated dans kernel_init.c
     43extern vfs_ctx_t          fs_context[FS_TYPES_NR];   // allocated in vfs.c file
     44
     45extern remote_barrier_t   global_barrier;            // allocated in kernel_init.c
    4546 
    4647//////////////////////////////////////////////////////////////////////////////////////////
     
    297298                        xptr_t        root_inode_xp )
    298299{
    299     error_t  error;
    300     uint8_t  buffer[512];    // buffer for boot record
    301 
    302     // make a synchronous access to IOC device to read the boot record from device
     300    error_t     error;
     301    uint8_t   * buffer;
     302    kmem_req_t  req;
     303
     304    // allocate a 512 bytes buffer to store the boot record
     305        req.type    = KMEM_512_BYTES;
     306    req.flags   = AF_KERNEL | AF_ZERO;
     307        buffer      = (uint8_t *)kmem_alloc( &req );
     308     
     309    fatfs_dmsg("\n[INFO] %s : enters with buffer = %x\n",
     310               __FUNCTION__ , (intptr_t)buffer );
     311
     312    // load the boot record from device
     313    // using a synchronous access to IOC device 
    303314    error = dev_ioc_sync_read( buffer , 0 , 1 );
    304     assert( (error == 0) , __FUNCTION__ , "cannot access FAT boot record" );
     315
     316    assert( (error == 0) , __FUNCTION__ , "cannot access boot record" );
     317
     318#if CONFIG_FAT_DEBUG
     319    uint32_t   line;
     320    uint32_t   byte = 0;
     321    printk("\n*** boot record at cycle %d ***\n", hal_time_stamp() );
     322    for ( line = 0 ; line < 32 ; line++ )
     323    {
     324        printk(" %X | %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x |\n",
     325               byte,
     326               buffer[byte+ 0],buffer[byte+ 1],buffer[byte+ 2],buffer[byte+ 3],
     327               buffer[byte+ 4],buffer[byte+ 5],buffer[byte+ 6],buffer[byte+ 7],
     328               buffer[byte+ 8],buffer[byte+ 9],buffer[byte+10],buffer[byte+11],
     329               buffer[byte+12],buffer[byte+13],buffer[byte+14],buffer[byte+15] );
     330
     331         byte += 16;
     332    }
     333#endif
    305334
    306335    // check sector size from boot record
    307336    uint32_t sector_size = get_record_from_buffer( BPB_BYTSPERSEC , buffer , 1 );
     337
    308338    assert( (sector_size == 512) , __FUNCTION__ , "sector size must be 512 bytes" );
    309339
    310340    // check cluster size from boot record
    311341    uint32_t nb_sectors = get_record_from_buffer( BPB_SECPERCLUS , buffer , 1 );
     342
    312343    assert( (nb_sectors == 8) , __FUNCTION__ , "cluster size must be 8 sectors" );
    313344
    314345    // check number of FAT copies from boot record
    315346    uint32_t nb_fats = get_record_from_buffer( BPB_NUMFATS , buffer , 1 );
     347
    316348    assert( (nb_fats == 1) , __FUNCTION__ , "number of FAT copies must be 1" );
    317349
    318350    // get & check number of sectors in FAT from boot record
    319351    uint32_t fat_sectors = get_record_from_buffer( BPB_FAT32_FATSZ32 , buffer , 1 );
     352
    320353    assert( ((fat_sectors & 0xF) == 0) , __FUNCTION__ , "FAT not multiple of 16 sectors");
    321354
    322355    // get and check root cluster from boot record
    323356    uint32_t root_cluster = get_record_from_buffer( BPB_FAT32_ROOTCLUS , buffer , 1 );
     357
    324358    assert( (root_cluster == 2) , __FUNCTION__ , "Root cluster index must be  2");
    325359
    326360    // get FAT lba from boot record
    327361    uint32_t fat_lba = get_record_from_buffer( BPB_RSVDSECCNT , buffer , 1 );
    328    
     362
     363    // release the 512 bytes buffer
     364    req.type = KMEM_512_BYTES;
     365    req.ptr  = buffer;
     366    kmem_free( &req );
     367
    329368    // allocate a mapper for the FAT itself
    330369    mapper_t * fat_mapper = mapper_create();
     370
    331371    assert( (fat_mapper != NULL) , __FUNCTION__ , "no memory for FAT mapper" );
    332372
     
    342382    fatfs_ctx->fat_mapper_xp         = XPTR( local_cxy , fat_mapper );
    343383
     384    fatfs_dmsg("\n*** FAT context ***\n"
     385               "- fat_sectors     = %d\n"
     386               "- sector size     = %d\n"
     387               "- cluster size    = %d\n"
     388               "- fat_first_lba   = %d\n"
     389               "- data_first_lba  = %d\n"
     390               "- mapper          = %l\n",
     391               fatfs_ctx->fat_sectors_count,
     392               fatfs_ctx->bytes_per_sector,
     393               fatfs_ctx->bytes_per_cluster,
     394               fatfs_ctx->fat_begin_lba,
     395               fatfs_ctx->cluster_begin_lba,
     396               fatfs_ctx->fat_mapper_xp );
     397
    344398    // initialize the VFS context
    345399    vfs_ctx->type    = FS_TYPE_FATFS;
Note: See TracChangeset for help on using the changeset viewer.