Changeset 50 for trunk/kernel/vfs/fatfs.c
- Timestamp:
- Jun 26, 2017, 3:15:11 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/vfs/fatfs.c
r23 r50 36 36 #include <fatfs.h> 37 37 38 38 39 ////////////////////////////////////////////////////////////////////////////////////////// 39 40 // Extern variables 40 41 ////////////////////////////////////////////////////////////////////////////////////////// 41 42 42 extern vfs_ctx_t fs_context[FS_TYPES_NR]; // allocated in vfs.c file43 44 extern remote_barrier_t global_barrier; // allocated danskernel_init.c43 extern vfs_ctx_t fs_context[FS_TYPES_NR]; // allocated in vfs.c file 44 45 extern remote_barrier_t global_barrier; // allocated in kernel_init.c 45 46 46 47 ////////////////////////////////////////////////////////////////////////////////////////// … … 297 298 xptr_t root_inode_xp ) 298 299 { 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 303 314 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 305 334 306 335 // check sector size from boot record 307 336 uint32_t sector_size = get_record_from_buffer( BPB_BYTSPERSEC , buffer , 1 ); 337 308 338 assert( (sector_size == 512) , __FUNCTION__ , "sector size must be 512 bytes" ); 309 339 310 340 // check cluster size from boot record 311 341 uint32_t nb_sectors = get_record_from_buffer( BPB_SECPERCLUS , buffer , 1 ); 342 312 343 assert( (nb_sectors == 8) , __FUNCTION__ , "cluster size must be 8 sectors" ); 313 344 314 345 // check number of FAT copies from boot record 315 346 uint32_t nb_fats = get_record_from_buffer( BPB_NUMFATS , buffer , 1 ); 347 316 348 assert( (nb_fats == 1) , __FUNCTION__ , "number of FAT copies must be 1" ); 317 349 318 350 // get & check number of sectors in FAT from boot record 319 351 uint32_t fat_sectors = get_record_from_buffer( BPB_FAT32_FATSZ32 , buffer , 1 ); 352 320 353 assert( ((fat_sectors & 0xF) == 0) , __FUNCTION__ , "FAT not multiple of 16 sectors"); 321 354 322 355 // get and check root cluster from boot record 323 356 uint32_t root_cluster = get_record_from_buffer( BPB_FAT32_ROOTCLUS , buffer , 1 ); 357 324 358 assert( (root_cluster == 2) , __FUNCTION__ , "Root cluster index must be 2"); 325 359 326 360 // get FAT lba from boot record 327 361 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 329 368 // allocate a mapper for the FAT itself 330 369 mapper_t * fat_mapper = mapper_create(); 370 331 371 assert( (fat_mapper != NULL) , __FUNCTION__ , "no memory for FAT mapper" ); 332 372 … … 342 382 fatfs_ctx->fat_mapper_xp = XPTR( local_cxy , fat_mapper ); 343 383 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 344 398 // initialize the VFS context 345 399 vfs_ctx->type = FS_TYPE_FATFS;
Note: See TracChangeset
for help on using the changeset viewer.