Changeset 406 for trunk/kernel/vfs/fatfs.c
- Timestamp:
- Aug 29, 2017, 12:03:37 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/vfs/fatfs.c
r401 r406 249 249 error_t fatfs_get_cluster( mapper_t * mapper, 250 250 uint32_t first_cluster_id, 251 uint32_t page_index,251 uint32_t searched_page_index, 252 252 uint32_t * searched_cluster_id ) 253 253 { 254 254 page_t * current_page_desc; // pointer on current page descriptor 255 255 uint32_t * current_page_buffer; // pointer on current page (array of uint32_t) 256 uint32_t current_page_index; // index of current page in mapper256 uint32_t current_page_index; // index of current page in FAT 257 257 uint32_t current_page_offset; // offset of slot in current page 258 258 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 280 268 uint32_t slots_per_page = CONFIG_PPM_PAGE_SIZE >> 2; 281 269 … … 284 272 current_page_offset = first_cluster_id % slots_per_page; 285 273 page_count_in_file = 0; 274 next_cluster_id = 0xFFFFFFFF; 286 275 287 276 // 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 { 294 279 // get pointer on current page descriptor 295 280 current_page_desc = mapper_get_page( mapper , current_page_index ); … … 302 287 303 288 // 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 ); 305 294 306 295 // 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; 309 298 page_count_in_file++; 310 299 } 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; 316 306 return 0; 317 307 … … 343 333 uint8_t * buffer; 344 334 345 fatfs_dmsg("\n[ INFO] %s : enter for fatfs_ctx = %x\n",335 fatfs_dmsg("\n[DMSG] %s : enter for fatfs_ctx = %x\n", 346 336 __FUNCTION__ , fatfs_ctx ); 347 337 … … 357 347 "cannot allocate memory for 512 bytes buffer\n" ); 358 348 359 fatfs_dmsg("\n[ INFO] %s : allocated 512 bytes buffer\n", __FUNCTION__ );349 fatfs_dmsg("\n[DMSG] %s : allocated 512 bytes buffer\n", __FUNCTION__ ); 360 350 361 351 // load the boot record from device … … 363 353 error = dev_ioc_sync_read( buffer , 0 , 1 ); 364 354 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) 360 if( hal_time_stamp() > CONFIG_FATFS_DEBUG ) 361 { 371 362 uint32_t line; 372 363 uint32_t byte = 0; 373 printk("\n***** FAT boot record\n");364 printk("\n***** %s : FAT boot record\n", __FUNCTION__ ); 374 365 for ( line = 0 ; line < 32 ; line++ ) 375 366 { … … 383 374 byte += 16; 384 375 } 376 } 385 377 #endif 386 378 … … 423 415 kmem_free( &req ); 424 416 425 fatfs_dmsg("\n[ INFO] %s : boot record read & released\n",417 fatfs_dmsg("\n[DMSG] %s : boot record read & released\n", 426 418 __FUNCTION__ ); 427 419 … … 445 437 fatfs_ctx->fat_mapper_xp = XPTR( local_cxy , fat_mapper ); 446 438 447 fatfs_dmsg("\n[ INFO] %s : exit for fatfs_ctx = %x\n",439 fatfs_dmsg("\n[DMSG] %s : exit for fatfs_ctx = %x\n", 448 440 __FUNCTION__ , fatfs_ctx ); 449 441 … … 472 464 fatfs_ctx_t * fatfs_ctx; // pointer on local FATFS context 473 465 474 // get pointer on sourcemapper and page index from page descriptor466 // get pointer on mapper and page index from page descriptor 475 467 mapper = page->mapper; 476 468 index = page->index; 477 469 478 // get VFSinode pointer from mapper470 // get inode pointer from mapper 479 471 inode = mapper->inode; 480 472 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 , in ode , index, mapper );483 484 // get page to movebase address473 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 485 477 xptr_t base_xp = ppm_page2base( XPTR( local_cxy , page ) ); 486 478 buffer = (uint8_t *)GET_PTR( base_xp ); … … 496 488 lba = fatfs_ctx->fat_begin_lba + (count * index); 497 489 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", 499 491 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid , lba ); 500 492 … … 519 511 else // FAT mapper access required 520 512 { 513 fatfs_dmsg("\n[DMSG] %s : core[%x,%d] must access FAT\n", 514 __FUNCTION__ , local_cxy , CURRENT_THREAD->core->lid ); 515 521 516 // get cluster and local pointer on FAT mapper 522 517 xptr_t fat_mapper_xp = fatfs_ctx->fat_mapper_xp; … … 545 540 } 546 541 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 547 545 // get lba from cluster_id 548 546 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 );552 547 553 548 // access device … … 558 553 } 559 554 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) 559 if( 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 562 572 563 573 return 0; … … 574 584 // - scan the directory entries in each 4 Kbytes page 575 585 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", 577 587 __FUNCTION__ , name , XPTR( local_cxy , parent_inode ) ); 578 588 … … 612 622 base = (uint8_t *)GET_PTR( base_xp ); 613 623 614 #if (CONFIG_FATFS_DEBUG > 1) 624 #if (CONFIG_FATFS_DEBUG & 0x1) 625 if( hal_time_stamp() > CONFIG_FATFS_DEBUG ) 626 { 615 627 uint32_t * buf = (uint32_t *)base; 616 628 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 ); 618 631 for( line = 0 ; line < 16 ; line++ ) 619 632 { … … 622 635 printk("\n"); 623 636 } 637 } 624 638 #endif 625 626 627 639 // scan this page until end of directory, end of page, or name found 628 640 while( (offset < 4096) && (found == 0) ) … … 693 705 if ( found == -1 ) // found end of directory => failure 694 706 { 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", 696 708 __FUNCTION__ , name , XPTR( local_cxy , parent_inode ) ); 697 709 … … 711 723 hal_remote_sw( XPTR( child_cxy , &child_ptr->extend ) , cluster ); 712 724 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", 714 726 __FUNCTION__ , name , XPTR( local_cxy , parent_inode ) ); 715 727
Note: See TracChangeset
for help on using the changeset viewer.