Changeset 774 for soft/giet_vm
- Timestamp:
- Feb 4, 2016, 5:02:03 PM (9 years ago)
- Location:
- soft/giet_vm/giet_kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_kernel/sys_handler.c
r760 r774 243 243 &_sys_fat_mmap, /* 0x2D */ 244 244 &_sys_fat_munmap, /* 0x2E */ 245 &_sys_ ukn,/* 0x2F */245 &_sys_fat_dump, /* 0x2F */ 246 246 247 247 #if NB_NIC_CHANNELS … … 535 535 #if GIET_DEBUG_MMAP 536 536 if ( _get_proctime() > GIET_DEBUG_MMAP ) 537 _printf("\n[DEBUG MMAP] _sys_fat_mmap() : P[%d,%d,%d] map cluster %d\n"537 _printf("\n[DEBUG MMAP] _sys_fat_mmap() : P[%d,%d,%d] map cluster_id = %d\n" 538 538 " user_vaddr = %x / cache_paddr = %l\n", 539 539 x_id , y_id , p_id , cid , user_vaddr , cache_paddr ); … … 591 591 return 0; 592 592 } // end _sys_fat_munmap() 593 594 595 596 597 /////////////////////////////////////////////////////////////////////////////////// 598 // This service function is called by the _sys_fat_dump() kernel function. 599 // It displays on the calling thread terminal the content of a 512 bytes buffer 600 // defined by the <buf> pointer. 601 // The <string> , <cluster_id> and <block_id> arguments are only used 602 // to build a meaningful title: <string> is an identifier, <cluster_id> is 603 // the cluster index (in file or FAT), <block_id> is the block index (in cluster). 604 /////////////////////////////////////////////////////////////////////////////////// 605 static void _dump_block( unsigned char* buf, 606 char* string, 607 unsigned int cluster_id, 608 unsigned int block_id ) 609 { 610 unsigned int line; 611 unsigned int word; 612 613 _user_printf("\n--- %s / cluster_id = %d / block_id = %d ---\n", 614 string , cluster_id , block_id ); 615 616 for ( line = 0 ; line < 16 ; line++ ) 617 { 618 // display line index 619 _user_printf("%x : ", line ); 620 621 // display 8*4 bytes hexa per line 622 for ( word=0 ; word<8 ; word++ ) 623 { 624 unsigned int byte = (line<<5) + (word<<2); 625 unsigned int hexa = (buf[byte ]<<24) | 626 (buf[byte+1]<<16) | 627 (buf[byte+2]<< 8) | 628 (buf[byte+3] ); 629 _user_printf(" %X |", hexa ); 630 } 631 _user_printf("\n"); 632 } 633 } // end _dump_block() 634 635 636 /////////////////////////////////////////////////////////////////////////////////// 637 // This function implements the giet_fat_dump() system call. 638 // It analyse the <type>, <pathname> and <sector_id> arguments to select 639 // a 512 bytes sector, and display the sector content on the calling thread TTY. 640 // The <type> argument can take the following values : 641 // - DUMP_BS : boot sector 642 // - DUMP_FS : fs_info sector 643 // - DUMP_FAT : fat sector, identified by <sector_id> 644 // - DUMP_FILE : file sector, identified by <pathname> and <sector_id> 645 // - DUMP_DIR : directory sector, identified by <pathname> and <sector_id> 646 // The <sector_id> argument defines the sector index in the file or in the FAT. 647 // For a file or a directory, or for the FAT itself, it uses the kernel File-Caches 648 // or Fat-Cache, and the Inode-Tree. 649 // For the boot sector, or fs_info sector, it access directly the block device, 650 // that is loaded in the FAT descriptor block-buffer. 651 /////////////////////////////////////////////////////////////////////////////////// 652 // Returns 0 in case of success. 653 // Returns 1 in case of error. 654 /////////////////////////////////////////////////////////////////////////////////// 655 int _sys_fat_dump( unsigned int type, 656 char* pathname, 657 unsigned int sector_id ) 658 { 659 unsigned char* buf; // pointer on 512 bytes buffer 660 unsigned int cluster_id = sector_id >> 3; // cluster index in cache 661 unsigned int block_id = sector_id & 0x7; // cluster index in cache 662 unsigned int fd_id; // file/dir descriptor index 663 664 if( type == DUMP_BS ) // dump the boot sector 665 { 666 // access block_device 667 buf = _fat.block_buffer; 668 if ( _fat_ioc_access( 1, // descheduling mode 669 1, // read 670 0, // boot sector lba 671 (unsigned int)buf, 672 1 ) ) // one block 673 { 674 _printf("\n[FAT ERROR] _sys_fat_dump(): cannot access device for BS\n"); 675 return 1; 676 } 677 _fat.block_buffer_lba = 0; 678 679 // dump boot sector 680 _dump_block( buf, "boot sector" , 0 , 0 ); 681 } 682 else if ( type == DUMP_FS ) // dump the fs_info sector 683 { 684 // access block_device 685 buf = _fat.block_buffer; 686 if ( _fat_ioc_access( 1, // descheduling mode 687 1, // read 688 _fat.fs_info_lba, // fs_info sector lba 689 (unsigned int)buf, 690 1 ) ) // one block 691 { 692 _printf("\n[FAT ERROR] _sys_fat_dump(): cannot access device for FS\n"); 693 return 1; 694 } 695 _fat.block_buffer_lba = _fat.fs_info_lba; 696 697 // dump fs-info sector 698 _dump_block( buf, "fs_info sector" , 0 , 0 ); 699 } 700 else if ( type == DUMP_FAT ) // dump a fat sector 701 { 702 // get pointer on the relevant buffer descriptor in Fat-Cache 703 fat_cache_desc_t* pdesc; 704 if ( _get_fat_cache_buffer( cluster_id, &pdesc ) ) 705 { 706 _printf("\n[FAT ERROR] _sys_fat_dump(): cannot access Fat-Cache\n"); 707 return 1; 708 } 709 buf = pdesc->buffer + (block_id<<9); 710 711 // dump fat sector 712 _dump_block( buf, "fat" , cluster_id , block_id ); 713 } 714 else if ( type == DUMP_FILE ) // dump a file sector 715 { 716 // open file 717 fd_id = _fat_open( pathname , O_RDONLY ); 718 if ( fd_id < 0 ) 719 { 720 _printf("\n[FAT ERROR] _sys_fat_dump(): cannot open file <%s>\n", pathname ); 721 return 1; 722 } 723 fat_inode_t* inode = _fat.fd[fd_id].inode; 724 725 // get pointer on the relevant buffer descriptor in File-Cache 726 fat_cache_desc_t* pdesc; 727 if ( _get_file_cache_buffer( inode, cluster_id, 0, &pdesc ) ) 728 { 729 _printf("\n[FAT ERROR] _sys_fat_dump(): cannot access file <%s>\n", pathname ); 730 return 1; 731 } 732 buf = pdesc->buffer + (block_id<<9); 733 734 // dump file sector 735 _dump_block( buf, pathname , cluster_id , block_id ); 736 737 // close file 738 _fat_close( fd_id ); 739 } 740 else if ( type == DUMP_DIR ) // dump a directory sector 741 { 742 // open directory 743 fd_id = _fat_opendir( pathname ); 744 if ( fd_id < 0 ) 745 { 746 _printf("\n[FAT ERROR] _sys_fat_dump(): cannot open <%s>\n", pathname ); 747 return 1; 748 } 749 fat_inode_t* inode = _fat.fd[fd_id].inode; 750 751 // get pointer on the relevant buffer descriptor in File-Cache 752 fat_cache_desc_t* pdesc; 753 if ( _get_file_cache_buffer( inode, cluster_id, 0, &pdesc ) ) 754 { 755 _printf("\n[FAT ERROR] _sys_fat_dump(): cannot access <%s>\n", pathname ); 756 return 1; 757 } 758 buf = pdesc->buffer + (block_id<<9); 759 760 // dump directory sector 761 _dump_block( buf, pathname , cluster_id , block_id ); 762 763 // close directory 764 _fat_closedir( fd_id ); 765 } 766 767 return 0; 768 } // end sys_fat_dump 593 769 594 770 -
soft/giet_vm/giet_kernel/sys_handler.h
r760 r774 136 136 unsigned int count ); // number of pages 137 137 138 extern int _sys_fat_dump( unsigned int type, // BS/FS/FAT/FILE/DIR 139 char* pathname, // file/dir pathname 140 unsigned int block_id ); // block index in file/dir/fat 141 138 142 139 143 //////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.