Changeset 530 for soft/giet_vm
- Timestamp:
- Mar 27, 2015, 12:10:20 PM (10 years ago)
- Location:
- soft/giet_vm/giet_fat32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r503 r530 5 5 // Copyright (c) UPMC-LIP6 6 6 ////////////////////////////////////////////////////////////////////////////////// 7 // The fat 32.h and fat32.c files define a library of access functions7 // The fat.h and fat_common.c files define a library of access functions 8 8 // to a FAT32 disk on a block device. It is intended to be used 9 9 // by the GIET_VM nano-kernel for both the boot code and the kernel code. 10 // This code uses functions defined in the utils.c and drivers.c files.11 10 ////////////////////////////////////////////////////////////////////////////////// 12 11 // Implementation notes: … … 15 14 // 2. the "cluster" variable is actually a cluster index. A cluster contains 16 15 // typically 8 sectors (4K bytes) and the cluster index is a 32 bits word. 17 // 2. This FAT32 library uses a FAT cache whose storage capacity is one 18 // sector (512 bytes, or 128 cluster indexes in FAT) 19 // 3. This FAT32 library can be used in 3 modes: BOOT/BOOT/KERNEL/USER 20 // defining different behaviours for the IOC driver. 16 // 3. This FAT32 library uses a FAT cache whose storage capacity is one 17 // sector (512 bytes = 128 cluster indexes in FAT) 21 18 ////////////////////////////////////////////////////////////////////////////////// 22 19 23 20 #include <giet_config.h> 21 #include <hard_config.h> 24 22 #include <fat32.h> 23 #include <utils.h> 24 #include <vmem.h> 25 #include <bdv_driver.h> 26 #include <hba_driver.h> 27 #include <sdc_driver.h> 28 #include <rdk_driver.h> 29 #include <mmc_driver.h> 25 30 #include <tty0.h> 26 #include <ioc_driver.h>27 #include <utils.h>28 31 29 32 ////////////////////////////////////////////////////////////////////////////////// … … 31 34 ////////////////////////////////////////////////////////////////////////////////// 32 35 33 extern fat32_fs_t fat __attribute__((aligned(512))); 36 extern fat32_fs_t _fat; 37 38 extern unsigned int _ptabs_vaddr[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE]; 39 40 ////////////////////////////////////////////////////////////////////////////// 41 // This function computes the memory buffer physical address, and calls 42 // the proper IOC driver depending on the subtype (BDV / HBA / SDC /RDK). 43 // The use_irq argument allows to activate the descheduling mode, if it 44 // supported by the IOC driver subtype 45 ////////////////////////////////////////////////////////////////////////////// 46 // Return 0 in case of success, return -1 in case of error 47 ////////////////////////////////////////////////////////////////////////////// 48 static 49 int _fat_ioc_access( unsigned int use_irq, 50 unsigned int to_mem, 51 unsigned int lba, 52 unsigned int buf_vaddr, 53 unsigned int count ) 54 { 55 // compute memory buffer physical address 56 unsigned int flags; // for _v2p_translate 57 unsigned long long buf_paddr; // buffer physical address 58 59 if ( ((_get_mmu_mode() & 0x4) == 0 ) || USE_IOC_RDK ) // identity 60 { 61 buf_paddr = (unsigned long long)buf_vaddr; 62 } 63 else // V2P translation required 64 { 65 buf_paddr = _v2p_translate( buf_vaddr , &flags ); 66 } 67 68 #if (GIET_DEBUG_FAT > 1) 69 unsigned int procid = _get_procid(); 70 unsigned int x = procid >> (Y_WIDTH + P_WIDTH); 71 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 72 unsigned int p = procid & ((1<<P_WIDTH)-1); 73 _printf("\n[DEBUG FAT] P[%d,%d,%d] enters _fat_ioc_access() at cycle %d\n" 74 " to_mem = %d / vaddr = %x / paddr = %l / sectors = %d / lba = %x\n", 75 x, y , p, _get_proctime(), to_mem, buf_vaddr, buf_paddr, count, lba ); 76 #endif 77 78 // cache coherence for both L1 & L2 caches 79 if ( to_mem ) // memory write 80 { 81 // L1 cache (only if L1 cache coherence not guaranteed by hardware) 82 if ( GIET_NO_HARD_CC ) _dcache_buf_invalidate( buf_vaddr, count<<9 ); 83 84 // L2 cache (only if we use an IO-Bridge component in architecture)) 85 if ( USE_IOB ) _mmc_inval( buf_paddr, count<<9 ); 86 } 87 else // memory read 88 { 89 // L1 cache : nothing to do for L1 write-through 90 91 // L2 cache (only if we use an IO-Bridge component in architecture)) 92 if ( USE_IOB ) _mmc_sync( buf_paddr, count<<9 ); 93 } 94 95 // call the proper descheduling physical device driver 96 97 #if ( USE_IOC_BDV ) 98 return( _bdv_access( use_irq , to_mem , lba , buf_paddr , count ) ); 99 #elif ( USE_IOC_HBA ) 100 return( _hba_access( use_irq , to_mem , lba , buf_paddr , count ) ); 101 #elif ( USE_IOC_SPI ) 102 return( _sdc_access( use_irq , to_mem , lba , buf_paddr , count ) ); 103 #elif ( USE_IOC_RDK ) 104 return( _rdk_access( use_irq , to_mem , lba , buf_paddr , count ) ); 105 #else 106 _printf("\n[FAT ERROR] in _fat_ioc_access() : no IOC driver\n"); 107 _exit(); 108 #endif 109 110 } // end _fat_ioc_access() 111 34 112 35 113 ////////////////////////////////////////////////////////////////////////////////// 36 114 // This function displays the content of the FAT cache 37 115 ////////////////////////////////////////////////////////////////////////////////// 116 #if (GIET_DEBUG_FAT > 1) 117 static 38 118 void _display_fat_cache() 39 119 { … … 45 125 46 126 _puts("\n*********************** fat_cache_lba = "); 47 _putx( fat.cache_lba );127 _putx( _fat.cache_lba ); 48 128 _puts(" *****************************\n"); 49 129 … … 58 138 { 59 139 unsigned int byte = (line<<5) + (word<<2); 60 unsigned int hexa = ( fat.fat_cache[byte ]<<24) |61 ( fat.fat_cache[byte+1]<<16) |62 ( fat.fat_cache[byte+2]<< 8) |63 ( fat.fat_cache[byte+3]);140 unsigned int hexa = (_fat.fat_cache[byte ]<<24) | 141 (_fat.fat_cache[byte+1]<<16) | 142 (_fat.fat_cache[byte+2]<< 8) | 143 (_fat.fat_cache[byte+3]); 64 144 _putx( hexa ); 65 145 _puts(" | "); 66 146 67 147 // prepare display ascii 68 temp[word] = fat.fat_cache[byte] |69 ( fat.fat_cache[byte+1]<<8) |70 ( fat.fat_cache[byte+2]<<16) |71 ( fat.fat_cache[byte+3]<<24) ;148 temp[word] = _fat.fat_cache[byte] | 149 (_fat.fat_cache[byte+1]<<8) | 150 (_fat.fat_cache[byte+2]<<16) | 151 (_fat.fat_cache[byte+3]<<24) ; 72 152 } 73 153 … … 79 159 80 160 } // end _display_fat_cache() 161 #endif 162 163 ////////////////////////////////////////////////////////////////////////////////// 164 // This function displays the FAT descriptor. 165 ////////////////////////////////////////////////////////////////////////////////// 166 #if GIET_DEBUG_FAT 167 static 168 void _fat_print() 169 { 170 _printf("\n########################## FAT32 ################################" 171 "\nFAT initialised %x" 172 "\nSector Size (bytes) %x" 173 "\nSectors per cluster %x" 174 "\nFAT region first lba %x" 175 "\nData region first lba %x" 176 "\nNumber of sectors for one FAT %x" 177 "\nNumber of free clusters %x" 178 "\nLast allocated cluster %x" 179 "\n#################################################################\n", 180 _fat.initialised, 181 _fat.sector_size, 182 _fat.sectors_per_cluster, 183 _fat.fat_lba, 184 _fat.data_lba, 185 _fat.fat_sectors, 186 _fat.number_free_cluster, 187 _fat.last_cluster_allocated ); 188 } // end _fat_print() 189 #endif 81 190 82 191 ////////////////////////////////////////////////////////////////////////////////// … … 84 193 // by an (offset,length) mnemonic defined in fat32.h file. 85 194 ////////////////////////////////////////////////////////////////////////////////// 86 static inline int get_length( int offset, 87 int length ) 195 static inline 196 int get_length( int offset, 197 int length ) 88 198 { 89 199 return length; … … 94 204 // The modified field in buffer is defined by the offset and size arguments. 95 205 ////////////////////////////////////////////////////////////////////////////// 96 static void _write_entry( unsigned int offset, 97 unsigned int size, 98 char* buffer, 99 unsigned int value ) 206 static 207 void _write_entry( unsigned int offset, 208 unsigned int size, 209 char* buffer, 210 unsigned int value ) 100 211 { 101 212 unsigned int turn = 0; … … 116 227 // The analysed field in buffer is defined by the offset and size arguments. 117 228 ////////////////////////////////////////////////////////////////////////////// 118 static unsigned int _read_entry( unsigned int offset, 119 unsigned int size, 120 char* buffer, 121 unsigned int little_indian ) 229 static 230 unsigned int _read_entry( unsigned int offset, 231 unsigned int size, 232 char* buffer, 233 unsigned int little_indian ) 122 234 { 123 235 unsigned int turn; … … 156 268 // The DATA region indexing starts a cluster 2. 157 269 ////////////////////////////////////////////////////////////////////////////////// 158 static inline unsigned int lba_to_cluster( unsigned int lba ) 159 { 160 if (lba < fat.data_lba ) return 0; 161 162 return ( (lba - fat.data_lba) / fat.sectors_per_cluster) + 2; 270 static inline 271 unsigned int lba_to_cluster( unsigned int lba ) 272 { 273 if (lba < _fat.data_lba ) return 0; 274 275 return ( (lba - _fat.data_lba) / _fat.sectors_per_cluster) + 2; 163 276 } 164 277 … … 167 280 // from the cluster index. The cluster index must be larger than 2. 168 281 ////////////////////////////////////////////////////////////////////////////////// 169 static inline unsigned int cluster_to_lba( unsigned int cluster ) 282 static inline 283 unsigned int cluster_to_lba( unsigned int cluster ) 170 284 { 171 285 if ( cluster < 2 ) return 0; 172 286 173 return ( fat.sectors_per_cluster * (cluster - 2)) +fat.data_lba;287 return (_fat.sectors_per_cluster * (cluster - 2)) + _fat.data_lba; 174 288 } 175 289 … … 179 293 // remark: a sector of FAT contains 128 cluster indexes. 180 294 ///////////////////////////////////////////////////////////////////////////////// 181 static unsigned int _get_next_cluster( unsigned int mode, 182 unsigned int cluster ) 295 static 296 unsigned int _get_next_cluster( unsigned int use_irq, 297 unsigned int cluster ) 183 298 { 184 299 // compute lba of the sector containing the cluster index 185 unsigned int lba = fat.fat_lba + (cluster / 128); 186 187 #if GIET_DEBUG_FAT 300 unsigned int lba = _fat.fat_lba + (cluster / 128); 301 302 if ( lba != _fat.cache_lba ) // miss in fat_cache 303 { 304 // access fat 305 if( _fat_ioc_access( use_irq, 306 1, // read 307 lba, 308 (unsigned int)_fat.fat_cache, 309 1 ) ) // one sector 310 { 311 _printf("[FAT_ERROR] in get_next_cluster_id() : cannot read block %x", 312 lba ); 313 return 1; 314 } 315 _fat.cache_lba = lba; 316 } 317 318 unsigned int next = _read_entry( ((cluster % 128) * 4), 319 4, 320 _fat.fat_cache, 321 1 ); 322 #if (GIET_DEBUG_FAT > 1) 188 323 unsigned int procid = _get_procid(); 189 324 unsigned int x = procid >> (Y_WIDTH + P_WIDTH); 190 325 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 191 326 unsigned int p = procid & ((1<<P_WIDTH)-1); 192 193 _printf("\n[FAT DEBUG] _get_next_cluster() : P[%d,%d,%d] enters for cluster %x\n", 194 x , y , p , cluster ); 195 #endif 196 197 if ( lba != fat.cache_lba ) // miss in fat_cache 198 { 199 // we cannot access fat in user mode 200 if( mode == IOC_USER_MODE ) mode = IOC_KERNEL_MODE; 201 202 // access fat 203 if( _ioc_read( 0, // channel 204 mode, // mode for IOC driver 205 lba, // sector index 206 fat.fat_cache, // fat cache 207 1 ) ) // one sector 208 { 209 _printf("[FAT_ERROR] in get_next cluster_id() : cannot read block %x", lba ); 210 return 1; 211 } 212 fat.cache_lba = lba; 213 214 #if (GIET_DEBUG_FAT > 1) 327 _printf("\n[DEBUG FAT] P[%d,%d,%d] in _get_next_cluster() : next = %x\n", 328 x , y , p , next ); 215 329 _display_fat_cache(); 216 #endif217 218 }219 unsigned int next = _read_entry( ((cluster % 128) * 4),220 4,221 fat.fat_cache,222 1 );223 224 #if GIET_DEBUG_FAT225 _printf("\n[FAT DEBUG] _get_next_cluster() : P[%d,%d,%d] next cluster = %x\n", next );226 330 #endif 227 331 … … 241 345 // Return the '_' character if c is illegal 242 346 //////////////////////////////////////////////////////////////// 243 static unsigned char illegal_short(unsigned char c) 347 static 348 unsigned char illegal_short(unsigned char c) 244 349 { 245 350 const unsigned char illegal_char [] =";+=[]â,\"*\\<>/?:|\0"; … … 265 370 // Return 0 if not legal SFN 266 371 ///////////////////////////////////////////////////////////////////////////////// 267 static int is_short( char* string, 268 char* sfn_string) 372 static 373 int is_short( char* string, 374 char* sfn_string) 269 375 { 270 376 int s_size = 0; … … 340 446 // Return 1 if name found, Return 0 if NUL character found, 341 447 /////////////////////////////////////////////////////////////////////// 342 static int get_name_from_path( char* pathname, 343 char* name, 344 unsigned int* nb_read ) 448 static 449 int get_name_from_path( char* pathname, 450 char* name, 451 unsigned int* nb_read ) 345 452 { 346 453 if ( pathname[*nb_read] == 0 ) return 0; … … 452 559 } // end get_name_from_long() 453 560 454 /////////////////////////////////////////////////////////////////////////////////// ///561 /////////////////////////////////////////////////////////////////////////////////// 455 562 // This function update a DIR_ENTRY, write a new value into a specific field 456 563 // (ex : DIR_FILE_SIZE, when we want update the file size after a fat_write) 457 564 // Return 0 in case of success, > 0 if failure. 458 /////////////////////////////////////////////////////////////////////////////////// ///565 /////////////////////////////////////////////////////////////////////////////////// 459 566 // TODO : make this function less complex 460 ////////////////////////////////////////////////////////////////////////////////////// 461 static inline unsigned int update_entry( unsigned int fd_id, 462 unsigned int field, 463 unsigned int size, 464 unsigned int value ) 567 /////////////////////////////////////////////////////////////////////////////////// 568 static inline 569 unsigned int _update_entry( unsigned int use_irq, 570 unsigned int fd_id, 571 unsigned int field, 572 unsigned int size, 573 unsigned int value ) 465 574 { 466 575 char dir_entry[32]; // buffer to store a full directory_entry … … 468 577 char file_name[256]; // buffer to store the name (not pathname) of the file 469 578 470 char sfn_string[12] = {[0 ... 10] = ' ', '\0'}; // buffer for aShort File Name471 unsigned int lba = fat.fd[fd_id].lba_dir_entry;// Lba of file dir_entry579 char sfn_string[12] = {[0 ... 10] = ' ', '\0'}; // buffer Short File Name 580 unsigned int lba = _fat.fd[fd_id].lba_dir_entry; // Lba of file dir_entry 472 581 unsigned int is_sfn; 473 unsigned int attr = 0; // directoryentry attribute474 unsigned int ord = 0; // directoryentry sequence475 unsigned int found = 0; 476 unsigned int offset = 0; 582 unsigned int attr = 0; // dir entry attribute 583 unsigned int ord = 0; // dir entry sequence 584 unsigned int found = 0; // name found 585 unsigned int offset = 0; // offset in fat_cache 477 586 unsigned int i = 0; 478 587 unsigned int nb_read = 0; … … 482 591 483 592 // Get the name of the file. 484 while ( get_name_from_path( fat.fd[fd_id].name, file_name, &nb_read ) )593 while ( get_name_from_path( _fat.fd[fd_id].name, file_name, &nb_read ) ) 485 594 { 486 595 } … … 489 598 is_sfn = is_short( file_name, sfn_string ); 490 599 491 if ( _ioc_read( 0, // channel 492 IOC_KERNEL_MODE, // mode for IOC driver 493 lba, // sector index 494 fat.fat_cache, // buffer address 495 1 ) ) // one sector 496 { 497 _printf("\n[FAT ERROR] in update_entry() cannot read sector %x\n", lba ); 600 // access FAT 601 if ( _fat_ioc_access( use_irq, 602 1, // read 603 lba, 604 (unsigned int)_fat.fat_cache, 605 1 ) ) // one sector 606 { 607 _printf("\n[FAT ERROR] in _update_entry() cannot read sector %x\n", 608 lba ); 498 609 return 1; 499 610 } 500 fat.cache_lba = lba;611 _fat.cache_lba = lba; 501 612 502 613 // - the offset increment is an integer number of directory entry (32 bytes) … … 504 615 while ( !found ) 505 616 { 506 attr = _read_entry( DIR_ATTR, fat.fat_cache + offset, 0 );507 ord = _read_entry( LDIR_ORD, fat.fat_cache + offset, 0 );617 attr = _read_entry( DIR_ATTR, _fat.fat_cache + offset, 0 ); 618 ord = _read_entry( LDIR_ORD, _fat.fat_cache + offset, 0 ); 508 619 509 620 if ( is_sfn == 1 ) // searched name is short … … 520 631 (ord != NO_MORE_ENTRY ) ) // SFN entry : checked 521 632 { 522 memcpy( dir_entry, fat.fat_cache + offset, DIR_ENTRY_SIZE );633 memcpy( dir_entry, _fat.fat_cache + offset, DIR_ENTRY_SIZE ); 523 634 } 524 635 else if (ord == NO_MORE_ENTRY ) // end of directory : return 525 636 { 526 _printf("\n[FAT ERROR] in update_entry() : reaches end of directory\n");637 _printf("\n[FAT ERROR] in _update_entry() : reaches end\n"); 527 638 return 1; 528 639 } … … 539 650 (ord != NO_MORE_ENTRY) ) // LFN entry : checked 540 651 { 541 memcpy( dir_entry, fat.fat_cache + offset, DIR_ENTRY_SIZE );652 memcpy( dir_entry, _fat.fat_cache + offset, DIR_ENTRY_SIZE ); 542 653 } 543 654 else if ( (attr != ATTR_LONG_NAME_MASK) && … … 550 661 else if (ord == NO_MORE_ENTRY ) // end of directory : return 551 662 { 552 _printf("\n[FAT ERROR] in update_entry() reaches end of directory\n");663 _printf("\n[FAT ERROR] in _update_entry() reaches end\n"); 553 664 return 1; 554 665 } … … 568 679 if ( _strncmp( (char*)sfn_string, (char*)name_entry, 13 ) == 0 ) 569 680 { 570 _write_entry(offset + field, size, fat.fat_cache, value);681 _write_entry(offset + field, size, _fat.fat_cache, value); 571 682 found = 1; 572 683 } … … 581 692 582 693 unsigned shift = ((ord & 0xf) - 1) * 13; 583 if ( _strncmp( (char*)(file_name + shift), (char*)name_entry, 13 ) == 0 ) 694 if ( _strncmp( (char*)(file_name + shift), 695 (char*)name_entry, 13 ) == 0 ) 584 696 { 585 697 if ( (ord & 0xf) == 1 ) 586 698 { 587 699 offset = offset + DIR_ENTRY_SIZE; 588 _write_entry(offset + field, size, fat.fat_cache, value);700 _write_entry(offset + field, size, _fat.fat_cache, value); 589 701 found = 1; 590 702 } … … 599 711 } 600 712 601 return _ioc_write( 0, // channel 602 IOC_KERNEL_MODE, // mode 603 lba, // sector index 604 fat.fat_cache, // source buffer 605 1 ); // one sector 606 } 607 ////////////////////////////////////////////////////////////////////////////////// 608 // This function update FS_INFO: 713 // write block to FAT 714 if ( _fat_ioc_access( use_irq, 715 0, // write 716 lba, 717 (unsigned int)_fat.fat_cache, 718 1 ) ) // one sector 719 { 720 _printf("\n[FAT ERROR] in _update_entry() cannot write sector %x\n", 721 lba ); 722 return 1; 723 } 724 725 return 0; 726 } // end _update_entry() 727 728 729 ////////////////////////////////////////////////////////////////////////////////// 730 // This function update the FS_INFO block: 609 731 // last cluster allocated and number of free cluster. 610 732 // Return 0 in case of success, > 0 if failure. 611 733 ////////////////////////////////////////////////////////////////////////////////// 612 static inline unsigned int _update_fs_info( ) 613 { 614 unsigned int lba = fat.fs_info_lba; 615 616 #if GIET_DEBUG_FAT 617 _printf("\n[FAT DEBUG] _update_fs_info() : enters\n"); 618 #endif 619 620 if ( lba == fat.cache_lba ) // hit cache 621 { 622 _write_entry( FS_FREE_CLUSTER , fat.fat_cache, fat.number_free_cluster ); 623 _write_entry( FS_FREE_CLUSTER_HINT, fat.fat_cache, fat.last_cluster_allocated ); 624 } 625 else // miss cache 626 { 627 if ( _ioc_read( 0, // channel 628 IOC_KERNEL_MODE, // mode for IOC driver 629 lba, // sector index 630 fat.fat_cache, // source buffer 631 1 ) ) // one sector 632 { 633 _printf("\n[FAT_ERROR] in _update_fat() cannot read block %x\n", lba ); 734 static inline 735 unsigned int _update_fs_info( unsigned int use_irq ) 736 { 737 unsigned int lba = _fat.fs_info_lba; 738 739 #if GIET_DEBUG_FAT 740 _printf("\n[DEBUG FAT] _update_fs_info()\n"); 741 #endif 742 743 // update FAT cache in case of miss 744 if ( lba != _fat.cache_lba ) 745 { 746 if ( _fat_ioc_access( use_irq, 747 1, // read 748 lba, 749 (unsigned int)_fat.fat_cache, 750 1 ) ) // one sector 751 { 752 _printf("\n[FAT_ERROR] in _update_fs_info() cannot read block\n"); 634 753 return 1; 635 754 } 636 fat.cache_lba = lba; 637 _write_entry( FS_FREE_CLUSTER , fat.fat_cache, fat.number_free_cluster ); 638 _write_entry( FS_FREE_CLUSTER_HINT, fat.fat_cache, fat.last_cluster_allocated ); 639 } 640 return _ioc_write( 0, // channel 641 IOC_KERNEL_MODE, // mode 642 lba, // sector index 643 fat.fat_cache, // source buffer 644 1 ); // one sector 645 } 755 _fat.cache_lba = lba; 756 } 757 758 _write_entry( FS_FREE_CLUSTER , _fat.fat_cache, _fat.number_free_cluster ); 759 _write_entry( FS_FREE_CLUSTER_HINT, _fat.fat_cache, _fat.last_cluster_allocated ); 760 761 // write bloc to FAT 762 if ( _fat_ioc_access( use_irq, 763 0, // write 764 lba, 765 (unsigned int)_fat.fat_cache, 766 1 ) ) // one sector 767 { 768 _printf("\n[FAT_ERROR] in _update_fs_info() cannot write block\n"); 769 return 1; 770 } 771 772 return 0; 773 } // end _update_fs_info() 646 774 647 775 ////////////////////////////////////////////////////////////////////////////////// … … 650 778 // Return 0 in case of success, > 0 if failure. 651 779 ////////////////////////////////////////////////////////////////////////////////// 652 static inline unsigned int _update_fat( unsigned int cluster, 653 unsigned int value ) 654 { 655 unsigned int lba = fat.fat_lba + (cluster / 128); 656 657 #if GIET_DEBUG_FAT 658 _printf("\n[FAT DEBUG] _update_fat() : cluster = %x / value = %x\n", cluster, value ); 659 #endif 660 661 if ( lba == fat.cache_lba ) // hit cache 662 { 663 _write_entry( ((cluster % 128) << 2), 4, fat.fat_cache, value ); 664 } 665 else // miss cache 666 { 667 if ( _ioc_read( 0, // channel 668 IOC_KERNEL_MODE, // mode for IOC driver 669 lba, // sector index 670 fat.fat_cache, // source buffer 671 1 ) ) // one sector 672 { 673 _printf("\n[FAT_ERROR] in _update_fat() cannot read block %x\n", lba ); 780 static inline 781 unsigned int _update_fat( unsigned int use_irq, 782 unsigned int cluster, 783 unsigned int value ) 784 { 785 unsigned int lba = _fat.fat_lba + (cluster / 128); 786 787 #if GIET_DEBUG_FAT 788 _printf("\n[DEBUG FAT] _update_fat() : cluster = %x / value = %x\n", 789 cluster, value ); 790 #endif 791 792 // update FAT cache in case of miss 793 if ( lba != _fat.cache_lba ) 794 { 795 if ( _fat_ioc_access( use_irq, 796 1, // read 797 lba, 798 (unsigned int)_fat.fat_cache, 799 1 ) ) // one sector 800 { 801 _printf("\n[FAT_ERROR] in _update_fat() cannot read block %x\n", 802 lba ); 674 803 return 1; 675 804 } 676 fat.cache_lba = lba; 677 _write_entry( ((cluster % 128) << 2), 4, fat.fat_cache, value ); 678 } 679 return _ioc_write( 0, // channel 680 IOC_KERNEL_MODE, // mode 681 lba, // sector indexs 682 fat.fat_cache, // source buffer 683 1 ); // one sector 805 _fat.cache_lba = lba; 806 } 807 808 _write_entry( ((cluster % 128) << 2), 4, _fat.fat_cache, value ); 809 810 // write bloc to FAT 811 if ( _fat_ioc_access( use_irq, 812 0, // write 813 lba, 814 (unsigned int)_fat.fat_cache, 815 1 ) ) // one sector 816 { 817 _printf("\n[FAT_ERROR] in _update_fat() cannot write block %x\n", 818 lba ); 819 return 1; 820 } 821 822 return 0; 684 823 } // end update_fat() 685 824 … … 689 828 // return 0 if success, -1 if failure 690 829 ////////////////////////////////////////////////////////////////////////////////// 691 static inline int _fat_allocate( unsigned int fd_id, 692 unsigned int count ) 693 { 694 unsigned int next_cluster = fat.fd[fd_id].first_cluster; // get first cluster 695 unsigned int cluster_to_allocate = count; // clusters to allocate 696 unsigned int last_cluster_file; // Last cluster (EOC) 697 unsigned int free_cluster = fat.last_cluster_allocated + 1; // First free cluster 830 static inline 831 int _fat_allocate( unsigned int use_irq, 832 unsigned int fd_id, 833 unsigned int count ) 834 { 835 unsigned int next_cluster = _fat.fd[fd_id].first_cluster; // first cluster 836 unsigned int cluster_to_allocate = count; // to allocate 837 unsigned int last_cluster_file; // Last cluster 838 unsigned int free_cluster = _fat.last_cluster_allocated + 1; // First free 698 839 699 840 // Check if free_cluster is really free (must be true) 700 if ( _get_next_cluster( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER)841 if ( _get_next_cluster( use_irq , free_cluster ) != FREE_CLUSTER) 701 842 { 702 843 _printf("\n[FAT ERROR] in _fat_allocate() : first free cluster not free\n"); … … 704 845 } 705 846 // Check if FAT contains enough cluster free for this allocation 706 if ( count > fat.number_free_cluster )847 if ( count > _fat.number_free_cluster ) 707 848 { 708 849 _printf("\n[FAT ERROR] in _fat_allocate() : Not enough free cluster(s)\n"); … … 711 852 712 853 #if GIET_DEBUG_FAT 713 _printf("\n[ FAT DEBUG] _fat_allocate() for fd = %d\n"fd_id );854 _printf("\n[DEBUG FAT] _fat_allocate() for fd = %d\n", fd_id ); 714 855 #endif 715 856 … … 718 859 { 719 860 last_cluster_file = next_cluster; 720 next_cluster = _get_next_cluster( IOC_KERNEL_MODE, next_cluster );861 next_cluster = _get_next_cluster( use_irq , next_cluster ); 721 862 } 722 863 while ( next_cluster < END_OF_CHAIN_CLUSTER ); … … 727 868 728 869 #if GIET_DEBUG_FAT 729 _printf("\n[ FAT DEBUG] cluster to update = %x / free cluster = %x / nb_clusters%d\n",870 _printf("\n[DEBUG FAT] cluster to update = %x / free cluster = %x / count = %d\n", 730 871 last_cluster_file , free_cluster , cluster_to_allocate ); 731 872 #endif … … 733 874 // update, in the FAT, the value of last cluster allocated by the index 734 875 // of free cluster. 735 if ( _update_fat( last_cluster_file, free_cluster ) )876 if ( _update_fat( use_irq , last_cluster_file , free_cluster ) ) 736 877 { 737 878 _printf("\n[FAT ERROR] in _fat_allocate() : update fat failed\n"); … … 748 889 // update, in the FAT, the value of the last cluster allocated by 749 890 // END_OF_CHAIN_CLUSTER 750 if ( _update_fat( last_cluster_file, END_OF_CHAIN_CLUSTER ) )891 if ( _update_fat( use_irq , last_cluster_file , END_OF_CHAIN_CLUSTER ) ) 751 892 { 752 893 _printf("\n[FAT ERROR] in _fat_allocate() : update fat failed\n"); … … 758 899 759 900 // Check if free_cluster is really free (must be true) 760 if ( _get_next_cluster( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER)901 if ( _get_next_cluster( use_irq , free_cluster ) != FREE_CLUSTER) 761 902 { 762 903 _printf("\n[FAT ERROR] in _fat_allocate() : free_cluster not free\n"); … … 767 908 // Update field number_free_cluster and last_cluster_allocated 768 909 // of structure fat for next fat_allocate 769 fat.last_cluster_allocated = last_cluster_file;770 fat.number_free_cluster =fat.number_free_cluster - count;771 772 if ( _update_fs_info( ) )910 _fat.last_cluster_allocated = last_cluster_file; 911 _fat.number_free_cluster = _fat.number_free_cluster - count; 912 913 if ( _update_fs_info( use_irq ) ) 773 914 { 774 915 _printf("\n[FAT ERROR] in _fat_allocate() : update fs_info failed\n"); … … 779 920 } // end _fat_allocate() 780 921 781 ////////////////////////////////////////////////////////////////////////////////// //////922 ////////////////////////////////////////////////////////////////////////////////// 782 923 // This function read the blocks defined by the cluster index argument, in a data 783 924 // region containing a directory to search the name of a file/firectory. … … 790 931 // The cluster index is always stored in a SFN or LFN entry. 791 932 // Return cluster index if name found / Return -1 if not found. 792 //////////////////////////////////////////////////////////////////////////////////////// 793 static int _scan_directory( unsigned int mode, // mode for IOC driver 794 unsigned int cluster, // cluster containing dir_entry 795 char* file_name, // searched file/directory name 796 unsigned int* file_size, // file size 797 unsigned int* lba_dir_entry ) // lba of dir_entry 933 ////////////////////////////////////////////////////////////////////////////////// 934 static 935 int _scan_directory( unsigned int use_irq, // use descheduling mode 936 unsigned int cluster, // cluster of dir_entry 937 char* file_name, // searched file/dir name 938 unsigned int* file_size, // file size 939 unsigned int* lba_dir_entry ) // lba of dir_entry 798 940 { 799 941 char dir_entry[32]; // buffer to store a full directory_entry 800 942 char name_entry[14]; // buffer to store a 13 characters (partial) name 801 943 802 char sfn_string[12] = {[0 ... 10] = ' ', '\0'}; // buffer for Short File Name803 unsigned int is_sfn = is_short(file_name, sfn_string); // iffile_name is short804 unsigned int offset = 0; 805 unsigned int block_id = fat.sectors_per_cluster; // sector index initialisation806 unsigned int lba = cluster_to_lba(cluster); // lba of cluster containing dir807 unsigned int attr = 0; // directoryentry attribute808 unsigned int ord = 0; // directoryentry sequence809 unsigned int found = 0; 810 unsigned int long_name_found = 0; // a matching XTN has beenfound811 unsigned int searched_cluster; 944 char sfn_string[12] = {[0 ... 10] = ' ', '\0'}; // buffer Short File Name 945 unsigned int is_sfn = is_short(file_name, sfn_string); // file_name is short 946 unsigned int offset = 0; // byte offset in block 947 unsigned int block_id = _fat.sectors_per_cluster; // sector index 948 unsigned int lba = cluster_to_lba(cluster); // lba of cluster 949 unsigned int attr = 0; // dir entry attribute 950 unsigned int ord = 0; // dir entry sequence 951 unsigned int found = 0; // searched name found 952 unsigned int long_name_found = 0; // matching XTN found 953 unsigned int searched_cluster; // searched cluster index 812 954 813 955 #if GIET_DEBUG_FAT … … 817 959 unsigned int p = procid & ((1<<P_WIDTH)-1); 818 960 819 _printf("\n[ FAT DEBUG] _scan_directory() : P[%d,%d,%d] entersfor %s\n",961 _printf("\n[DEBUG FAT] P[%d,%d,%d] enters _scan_directory() for %s\n", 820 962 x, y, p, file_name ); 821 963 #endif … … 827 969 // load first sector from DATA region into FAT cache 828 970 // other sectors will be loaded inside loop as required 829 if( _ioc_read( 0, // channel 830 mode, // mode for IOC driver 831 lba, // sector index 832 fat.fat_cache, // buffer address 833 1 ) ) // one sector 834 { 835 _printf("[\nFAT ERROR] in _scan_directory() : cannot read sector %x\n", lba ); 971 if( _fat_ioc_access( use_irq, 972 1, // read 973 lba, 974 (unsigned int)_fat.fat_cache, 975 1 ) ) // one sector 976 { 977 _printf("[\nFAT ERROR] in _scan_directory() : cannot read sector %x\n", 978 lba ); 836 979 return -1; 837 980 } 838 839 fat.cache_lba = lba; 981 _fat.cache_lba = lba; 840 982 841 983 #if ( GIET_DEBUG_FAT > 1 ) … … 858 1000 else // get next cluster 859 1001 { 860 cluster = _get_next_cluster( mode, cluster );1002 cluster = _get_next_cluster( use_irq , cluster ); 861 1003 862 1004 if ( cluster >= END_OF_CHAIN_CLUSTER ) return END_OF_CHAIN_CLUSTER; 863 1005 864 1006 lba = cluster_to_lba(cluster); 865 block_id = fat.sectors_per_cluster; 866 } 867 if( _ioc_read( 0, // channel 868 mode, // mode for IOC driver 869 lba, // sector index 870 fat.fat_cache, // buffer address 871 1 ) ) // one sector 872 { 873 _printf("\n[FAT ERROR] in _scan_directory() : cannot read sector %x\n", lba); 1007 block_id = _fat.sectors_per_cluster; 1008 } 1009 if( _fat_ioc_access( use_irq, 1010 1, // read 1011 lba, 1012 (unsigned int)_fat.fat_cache, 1013 1 ) ) // one sector 1014 { 1015 _printf("\n[FAT ERROR] in _scan_directory() : cannot read sector %x\n", 1016 lba); 874 1017 return -1; 875 1018 } 876 fat.cache_lba = lba;1019 _fat.cache_lba = lba; 877 1020 block_id--; 878 1021 offset = offset % 512; … … 882 1025 // if it a possible candidate for the searched name 883 1026 884 attr = _read_entry( DIR_ATTR, fat.fat_cache + offset, 0);885 ord = _read_entry( LDIR_ORD, fat.fat_cache + offset, 0);1027 attr = _read_entry( DIR_ATTR, _fat.fat_cache + offset, 0); 1028 ord = _read_entry( LDIR_ORD, _fat.fat_cache + offset, 0); 886 1029 887 1030 if ( is_sfn == 1 ) // searched name is short … … 897 1040 (ord != NO_MORE_ENTRY ) ) // SFN entry : to be checked 898 1041 { 899 memcpy( dir_entry, fat.fat_cache + offset, DIR_ENTRY_SIZE );1042 memcpy( dir_entry, _fat.fat_cache + offset, DIR_ENTRY_SIZE ); 900 1043 901 1044 get_name_from_short( dir_entry, name_entry ); … … 922 1065 (ord != NO_MORE_ENTRY) ) // EXT entry : to be checked 923 1066 { 924 memcpy( dir_entry, fat.fat_cache + offset, DIR_ENTRY_SIZE );1067 memcpy( dir_entry, _fat.fat_cache + offset, DIR_ENTRY_SIZE ); 925 1068 926 1069 get_name_from_long( dir_entry, name_entry ); … … 943 1086 if ( long_name_found ) // LFN entry 944 1087 { 945 memcpy( dir_entry, fat.fat_cache + offset, DIR_ENTRY_SIZE );1088 memcpy( dir_entry, _fat.fat_cache + offset, DIR_ENTRY_SIZE ); 946 1089 found = 1; 947 1090 } … … 965 1108 966 1109 #if GIET_DEBUG_FAT 967 _printf("\n[ FAT DEBUG] _scan_directory() : P[%d,%d,%d] found %s"1110 _printf("\n[DEBUG FAT] _scan_directory() : P[%d,%d,%d] found %s" 968 1111 " : cluster = %x\n", x, y, p, file_name, searched_cluster ); 969 1112 #endif … … 999 1142 // Return 0 if success, exit if failure 1000 1143 ////////////////////////////////////////////////////////////////////////// 1001 int _fat_init( unsigned int mode ) // mode for IOC driver 1002 { 1003 unsigned int n; 1144 int _fat_init( unsigned int use_irq ) 1145 { 1004 1146 1005 1147 #if GIET_DEBUG_FAT … … 1008 1150 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 1009 1151 unsigned int p = procid & ((1<<P_WIDTH)-1); 1010 1011 if ( mode == IOC_BOOT_MODE ) 1012 _printf("\n[FAT DEBUG] _fat_init() : P[%d,%d,%d] enters in BOOT_MODE\n",x,y,p); 1013 if ( mode == IOC_KERNEL_MODE ) 1014 _printf("\n[FAT DEBUG] _fat_init() : P[%d,%d,%d] enters in KERNEL_MODE\n",x,y,p); 1015 if ( mode == IOC_USER_MODE ) 1016 _printf("\n[FAT DEBUG] _fat_init() : P[%d,%d,%d] enters in USER_MODE\n",x,y,p); 1152 _printf("\n[DEBUG FAT] P[%d,%d,%d] enters _fat_init\n",x,y,p); 1017 1153 #endif 1018 1154 1019 1155 // FAT initialisation should be done only once 1020 if ( fat.initialised == FAT_INITIALISED )1021 { 1022 _printf("\n[FAT WARNING] Strange, FAT already initialised...\n");1156 if ( _fat.initialised == FAT_INITIALISED ) 1157 { 1158 _printf("\n[FAT ERROR] Strange, FAT already initialised...\n"); 1023 1159 _exit(); 1024 1160 } 1025 1161 1026 1162 // load Boot Record (VBR) into fat cache 1027 if ( _ ioc_read( 0, // channel1028 mode, // mode for IOC driver1029 0, // sector index1030 fat.fat_cache, // buffer address1031 1 ) ) // one sector1163 if ( _fat_ioc_access( use_irq, 1164 1, // read 1165 0, // sector index 1166 (unsigned int)_fat.fat_cache, 1167 1 ) ) // one sector 1032 1168 { 1033 1169 _printf("\n[FAT ERROR] in _fat_init() cannot load VBR\n"); 1034 1170 _exit(); 1035 1171 } 1036 fat.cache_lba = 0;1172 _fat.cache_lba = 0; 1037 1173 1038 1174 #if GIET_DEBUG_FAT > 1 1039 _printf("\n[ FAT DEBUG] _fat_init() : Boot Sector Loaded\n");1175 _printf("\n[DEBUG FAT] _fat_init() : Boot Sector Loaded\n"); 1040 1176 _display_fat_cache(); 1041 1177 #endif 1042 1178 1043 1179 // checking various FAT32 assuptions from boot sector 1044 if( _read_entry( BPB_BYTSPERSEC, fat.fat_cache, 1 ) != 512 )1180 if( _read_entry( BPB_BYTSPERSEC, _fat.fat_cache, 1 ) != 512 ) 1045 1181 { 1046 1182 _printf("\n[FAT ERROR] The sector size must be 512 bytes\n"); 1047 1183 _exit(); 1048 1184 } 1049 if( _read_entry( BPB_NUMFATS, fat.fat_cache, 1 ) != 1 )1185 if( _read_entry( BPB_NUMFATS, _fat.fat_cache, 1 ) != 1 ) 1050 1186 { 1051 1187 _printf("\n[FAT ERROR] The number of FAT copies in FAT region must be 1\n"); 1052 1188 _exit(); 1053 1189 } 1054 if( (_read_entry( BPB_FAT32_FATSZ32, fat.fat_cache, 1 ) & 0xF) != 0 )1055 { 1056 _printf("\n[FAT ERROR] The FAT region in FAT32must be multiple of 32 sectors\n");1190 if( (_read_entry( BPB_FAT32_FATSZ32, _fat.fat_cache, 1 ) & 0xF) != 0 ) 1191 { 1192 _printf("\n[FAT ERROR] The FAT region must be multiple of 32 sectors\n"); 1057 1193 _exit(); 1058 1194 } 1059 if( _read_entry( BPB_FAT32_ROOTCLUS, fat.fat_cache, 1 ) != 2 )1195 if( _read_entry( BPB_FAT32_ROOTCLUS, _fat.fat_cache, 1 ) != 2 ) 1060 1196 { 1061 1197 _printf("\n[FAT ERROR] The first cluster index must be 2\n"); … … 1063 1199 } 1064 1200 // FS Info always in sector 1 1065 fat.fs_info_lba = _read_entry( BPB_FAT32_FSINFO,fat.fat_cache, 1 );1201 _fat.fs_info_lba = _read_entry( BPB_FAT32_FSINFO, _fat.fat_cache, 1 ); 1066 1202 1067 1203 // initialise fat descriptor from VBR 1068 fat.sectors_per_cluster = _read_entry( BPB_SECPERCLUS,fat.fat_cache, 1 );1069 fat.sector_size = _read_entry( BPB_BYTSPERSEC,fat.fat_cache, 1 );1070 fat.cluster_size =fat.sectors_per_cluster * 512;1071 fat.fat_sectors = _read_entry( BPB_FAT32_FATSZ32,fat.fat_cache, 1 );1072 fat.fat_lba = _read_entry( BPB_RSVDSECCNT,fat.fat_cache, 1 );1073 fat.data_lba = fat.fat_lba +fat.fat_sectors;1074 fat.initialised = FAT_INITIALISED;1204 _fat.sectors_per_cluster = _read_entry( BPB_SECPERCLUS, _fat.fat_cache, 1 ); 1205 _fat.sector_size = _read_entry( BPB_BYTSPERSEC, _fat.fat_cache, 1 ); 1206 _fat.cluster_size = _fat.sectors_per_cluster * 512; 1207 _fat.fat_sectors = _read_entry( BPB_FAT32_FATSZ32, _fat.fat_cache, 1 ); 1208 _fat.fat_lba = _read_entry( BPB_RSVDSECCNT, _fat.fat_cache, 1 ); 1209 _fat.data_lba = _fat.fat_lba + _fat.fat_sectors; 1210 _fat.initialised = FAT_INITIALISED; 1075 1211 1076 1212 // initalise the lock protecting the FAT 1077 _spin_lock_init( & fat.fat_lock );1213 _spin_lock_init( &_fat.fat_lock ); 1078 1214 1079 1215 // initialise file descriptor array 1080 for( n = 0 ; n < GIET_OPEN_FILES_MAX ; n++ ) fat.fd[n].used = 0; 1081 1082 #if GIET_DEBUG_FAT 1083 _printf("\n[FAT DEBUG] _fat_init() : FS_INFO Sector = %x\n", fat.fs_info_lba ); 1216 unsigned int n; 1217 for( n = 0 ; n < GIET_OPEN_FILES_MAX ; n++ ) _fat.fd[n].used = 0; 1218 1219 #if GIET_DEBUG_FAT 1220 _printf("\n[DEBUG FAT] _fat_init() : FS_INFO Sector = %x\n", _fat.fs_info_lba ); 1084 1221 #endif 1085 1222 1086 1223 // load FS_INFO into fat cache 1087 if ( _ ioc_read( 0, // channel1088 mode, // mode for IOC driver1089 fat.fs_info_lba, // sector index1090 fat.fat_cache, // buffer address1091 1 ) ) // one sector1224 if ( _fat_ioc_access( use_irq, 1225 1, // read 1226 _fat.fs_info_lba, 1227 (unsigned int)_fat.fat_cache, 1228 1 ) ) // one sector 1092 1229 { 1093 1230 _printf("\n[FAT ERROR] in _fat_init() cannot load FS_INFO Sector\n"); 1094 1231 _exit(); 1095 1232 } 1096 fat.cache_lba = fat.fs_info_lba; 1097 1098 fat.number_free_cluster = _read_entry( FS_FREE_CLUSTER , fat.fat_cache, 1); 1099 fat.last_cluster_allocated = _read_entry( FS_FREE_CLUSTER_HINT, fat.fat_cache, 1); 1100 1233 _fat.cache_lba = _fat.fs_info_lba; 1234 1235 _fat.number_free_cluster = _read_entry( FS_FREE_CLUSTER , _fat.fat_cache, 1); 1236 _fat.last_cluster_allocated = _read_entry( FS_FREE_CLUSTER_HINT, _fat.fat_cache, 1); 1101 1237 1102 1238 #if GIET_DEBUG_FAT 1103 1239 _fat_print(); 1104 _printf("\n[ FAT DEBUG] P[%d,%d,%d] exit _fat_init()\n");1240 _printf("\n[DEBUG FAT] P[%d,%d,%d] exit _fat_init()\n", x,y,p ); 1105 1241 #endif 1106 1242 1107 1243 return 0; 1108 1244 } // end _fat_init() 1109 1110 /////////////////1111 void _fat_print()1112 {1113 _printf("\n########################## FAT32 ################################"1114 "\nFAT initialised %x"1115 "\nSector Size (bytes) %x"1116 "\nSectors per cluster %x"1117 "\nFAT region first lba %x"1118 "\nData region first lba %x"1119 "\nNumber of sectors for one FAT %x"1120 "\nNumber of free clusters %x"1121 "\nLast allocated cluster %x"1122 "\n#################################################################\n",1123 fat.initialised,1124 fat.sector_size,1125 fat.sectors_per_cluster,1126 fat.fat_lba,1127 fat.data_lba,1128 fat.fat_sectors,1129 fat.number_free_cluster,1130 fat.last_cluster_allocated );1131 }1132 1245 1133 1246 /////////////////////////////////////////////////////////////////////////////// … … 1142 1255 // Returns file descriptor index if success, returns -1 if error. 1143 1256 /////////////////////////////////////////////////////////////////////////////// 1144 int _fat_open( unsigned mode,1257 int _fat_open( unsigned int use_irq, // use descheduling mode if possible 1145 1258 char* pathname, 1146 1259 unsigned int creat ) … … 1160 1273 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 1161 1274 unsigned int p = procid & ((1<<P_WIDTH)-1); 1162 1163 _printf("\n[FAT DEBUG] P[%d,%d,%d] enters _fat_open() for path %s\n", 1275 _printf("\n[DEBUG FAT] P[%d,%d,%d] enters _fat_open() for path %s\n", 1164 1276 x, y, p, pathname ); 1165 1277 #endif … … 1173 1285 1174 1286 // checking FAT initialised 1175 if( fat.initialised != FAT_INITIALISED )1287 if( _fat.initialised != FAT_INITIALISED ) 1176 1288 { 1177 1289 _printf("\n[FAT ERROR] in _fat_open() : FAT not initialised\n"); … … 1179 1291 } 1180 1292 // takes the FAT lock for exclusive access 1181 _spin_lock_acquire( & fat.fat_lock );1182 1183 #if GIET_DEBUG_FAT 1184 _printf("\n[ FAT DEBUG] _fat_open() : P[%d,%d,%d] takes the FAT lock\n",1293 _spin_lock_acquire( &_fat.fat_lock ); 1294 1295 #if GIET_DEBUG_FAT 1296 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] takes the FAT lock\n", 1185 1297 x, y, p ); 1186 1298 #endif … … 1199 1311 1200 1312 #if GIET_DEBUG_FAT 1201 _printf("\n[ FAT DEBUG] _fat_open() : P[%d,%d,%d] search file/dir %s\n",1313 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] search file/dir %s\n", 1202 1314 x, y, p, name ); 1203 1315 #endif … … 1211 1323 1212 1324 // scan current directory 1213 cluster = _scan_directory( mode, cluster, name, &file_size, &lba );1325 cluster = _scan_directory( use_irq , cluster , name , &file_size , &lba ); 1214 1326 1215 1327 if( cluster == END_OF_CHAIN_CLUSTER && last_name && creat ) … … 1220 1332 { 1221 1333 _printf("\n[FAT ERROR] in _fat_open() cannot found %s\n", name ); 1222 _spin_lock_release( & fat.fat_lock );1334 _spin_lock_release( &_fat.fat_lock ); 1223 1335 return -1; 1224 1336 } … … 1226 1338 1227 1339 #if GIET_DEBUG_FAT 1228 _printf("\n[ FAT DEBUG] _fat_open() : P[%d,%d,%d]cluster for %s = %x\n",1340 _printf("\n[DEBUG FAT] P[%d,%d,%d] in _fat_open() : cluster for %s = %x\n", 1229 1341 x, y, p, pathname, cluster ); 1230 1342 #endif 1231 1343 1232 1344 // check the next value for cluster index found 1233 unsigned next = _get_next_cluster( mode, cluster );1345 unsigned next = _get_next_cluster( use_irq , cluster ); 1234 1346 1235 1347 if ( (next != BAD_CLUSTER) && (next != FREE_CLUSTER) ) … … 1237 1349 // Search an empty slot scanning open file descriptors array 1238 1350 fd_id = 0; 1239 while ( fat.fd[fd_id].used != 0 && fd_id < GIET_OPEN_FILES_MAX )1351 while ( _fat.fd[fd_id].used != 0 && fd_id < GIET_OPEN_FILES_MAX ) 1240 1352 { 1241 1353 fd_id++; … … 1245 1357 if ( fd_id < GIET_OPEN_FILES_MAX ) 1246 1358 { 1247 fat.fd[fd_id].used = 1;1248 fat.fd[fd_id].first_cluster = cluster;1249 fat.fd[fd_id].file_size = file_size;1250 fat.fd[fd_id].lba_dir_entry = lba;1251 _strcpy( fat.fd[fd_id].name, pathname );1252 1253 #if GIET_DEBUG_FAT 1254 _printf("\n[ FAT DEBUG] _fat_open() : P[%d,%d,%d] exit : fd = %d for file %s\n",1359 _fat.fd[fd_id].used = 1; 1360 _fat.fd[fd_id].first_cluster = cluster; 1361 _fat.fd[fd_id].file_size = file_size; 1362 _fat.fd[fd_id].lba_dir_entry = lba; 1363 _strcpy( _fat.fd[fd_id].name, pathname ); 1364 1365 #if GIET_DEBUG_FAT 1366 _printf("\n[DEBUG FAT] _fat_open() : P[%d,%d,%d] exit : fd = %d for file %s\n", 1255 1367 x, y, p, fd_id, pathname ); 1256 1368 #endif 1257 1369 1258 1370 // release FAT lock 1259 _spin_lock_release( & fat.fat_lock );1371 _spin_lock_release( &_fat.fat_lock ); 1260 1372 1261 1373 return fd_id; … … 1265 1377 _printf("\n[FAT ERROR] in _fat_open() for file %s : fd array full\n", 1266 1378 pathname ); 1267 _spin_lock_release( & fat.fat_lock );1379 _spin_lock_release( &_fat.fat_lock ); 1268 1380 return -1; 1269 1381 } … … 1273 1385 _printf("\n[FAT ERROR] in _fat_open() for file %s : bad cluster\n", 1274 1386 pathname ); 1275 _spin_lock_release( & fat.fat_lock );1387 _spin_lock_release( &_fat.fat_lock ); 1276 1388 return -1; 1277 1389 } … … 1285 1397 // Returns number of sectors transfered if success, < 0 if error. 1286 1398 /////////////////////////////////////////////////////////////////////////////// 1287 int _fat_read( unsigned int mode, // mode for IOC driver1399 int _fat_read( unsigned int use_irq, // use descheduling mode if possible 1288 1400 unsigned int fd_id, // file descriptor 1289 1401 void* buffer, // target buffer base address … … 1291 1403 unsigned int offset ) // nuber of sectors to skip in file 1292 1404 { 1293 unsigned int spc = fat.sectors_per_cluster;1405 unsigned int spc = _fat.sectors_per_cluster; 1294 1406 1295 1407 unsigned int file_size; // number of bytes in file … … 1306 1418 return -1; 1307 1419 } 1308 if ( fat.fd[fd_id].used != 1 )1420 if ( _fat.fd[fd_id].used != 1 ) 1309 1421 { 1310 1422 _printf("\n[FAT ERROR] in _fat_read() : file not open\n"); … … 1318 1430 1319 1431 // compute file size as a number of sectors 1320 file_size = fat.fd[fd_id].file_size;1432 file_size = _fat.fd[fd_id].file_size; 1321 1433 if ( file_size & 0x1FF ) file_sectors = (file_size >> 9) + 1; 1322 1434 else file_sectors = (file_size >> 9); … … 1337 1449 1338 1450 // get first cluster index 1339 cluster = fat.fd[fd_id].first_cluster;1451 cluster = _fat.fd[fd_id].first_cluster; 1340 1452 1341 1453 #if GIET_DEBUG_FAT … … 1344 1456 unsigned int y = (procid >> P_WIDTH) & ((1<<Y_WIDTH)-1); 1345 1457 unsigned int p = procid & ((1<<P_WIDTH)-1); 1346 _printf("\n[ FAT DEBUG] _fat_read() : P[%d,%d,%d] enters for file %s\n"1458 _printf("\n[DEBUG FAT] _fat_read() : P[%d,%d,%d] enters for file %s\n" 1347 1459 " - buffer vbase = %x\n" 1348 1460 " - skipped sectors = %x\n" … … 1350 1462 " - first cluster = %x\n" 1351 1463 " - skipped clusters = %x\n", 1352 x, y, p, 1353 fat.fd[fd_id].name, 1354 (unsigned int)buffer, 1355 offset, 1356 count, 1357 cluster, 1358 clusters_to_skip ); 1464 x, y, p, _fat.fd[fd_id].name, (unsigned int)buffer, 1465 offset, count, cluster, clusters_to_skip ); 1359 1466 #endif 1360 1467 1361 1468 // compute index of first cluster to be loaded 1362 // as we may need to scan the FAT, we use the kernel mode1363 1469 while ( clusters_to_skip ) 1364 1470 { 1365 cluster = _get_next_cluster( IOC_KERNEL_MODE, cluster );1471 cluster = _get_next_cluster( use_irq , cluster ); 1366 1472 clusters_to_skip--; 1367 1473 } … … 1371 1477 unsigned int lba; // first sector index on device 1372 1478 unsigned int iter_sectors; // number of sectors to load in iteration 1373 char*dst; // pointer on target buffer1479 unsigned int dst; // pointer on target buffer 1374 1480 1375 1481 // initialize these variables for the first iteration 1376 1482 todo_sectors = total_sectors; 1377 dst = ( char*)buffer;1483 dst = (unsigned int)buffer; 1378 1484 lba = cluster_to_lba(cluster) + sectors_to_skip; 1379 1485 if( total_sectors < (spc - sectors_to_skip) ) iter_sectors = total_sectors; … … 1385 1491 1386 1492 #if GIET_DEBUG_FAT 1387 _printf("\n[FAT DEBUG] _fat_read() : P[%d,%d,%d] makes an IOC read\n" 1388 " - cluster = %x\n" 1389 " - buffer = %x\n" 1390 " - lba = %x\n" 1391 " - sectors = %x\n", 1392 x, y, p, 1393 cluster, 1394 (unsigned int)dst, 1395 lba, 1396 iter_sectors ); 1397 #endif 1398 1399 if( _ioc_read( 0, // channel 1400 mode, // mode for IOC driver 1401 lba, // first sector index 1402 dst, // buffer address 1403 iter_sectors ) ) // number of sectors 1493 _printf("\n[DEBUG FAT] _fat_read() : P[%d,%d,%d] makes an IOC read\n" 1494 " cluster = %x / buffer = %x / lba = %x / sectors = %d\n", 1495 x, y, p, cluster, dst, lba, iter_sectors ); 1496 #endif 1497 1498 if( _fat_ioc_access( use_irq, 1499 1, // read 1500 lba, 1501 dst, // buffer address 1502 iter_sectors ) ) // number of sectors 1404 1503 { 1405 1504 _printf("\n[FAT ERROR] in _fat_read() cannot load block %x", lba ); … … 1408 1507 1409 1508 // update variables for next iteration 1410 cluster = _get_next_cluster( mode, cluster );1509 cluster = _get_next_cluster( use_irq , cluster ); 1411 1510 todo_sectors = todo_sectors - iter_sectors; 1412 1511 dst = dst + (iter_sectors << 9); … … 1426 1525 // Allocate new clusters if the offset+count larger than current file size, 1427 1526 // but the offset should be smaller than the current file size... 1428 // - fat : pointer on FAT1429 // - mode : mode for the IOC driver1430 // - fd_id : open file descriptor index1431 // - buffer : base address of the memory buffer (must be sector aligned)1432 // - offset : number of sectors to skip in file1433 // - count : number of sectors to be written.1434 1527 /////////////////////////////////////////////////////////////////////////////// 1435 1528 // Returns number of sectors written if success, < 0 if error. 1436 1529 /////////////////////////////////////////////////////////////////////////////// 1437 int _fat_write( unsigned int mode, // mode for IOC driver1530 int _fat_write( unsigned int use_irq, // use descheduling mode if possible 1438 1531 unsigned int fd_id, // file descriptor 1439 1532 void* buffer, // target buffer base address … … 1442 1535 { 1443 1536 1444 unsigned int spc = fat.sectors_per_cluster;1537 unsigned int spc = _fat.sectors_per_cluster; 1445 1538 1446 1539 unsigned int file_size; // number of bytes in file … … 1454 1547 1455 1548 // compute file size as a number of sectors 1456 file_size = fat.fd[fd_id].file_size;1549 file_size = _fat.fd[fd_id].file_size; 1457 1550 if ( file_size & 0x1FF ) file_sectors = (file_size >> 9) + 1; 1458 1551 else file_sectors = (file_size >> 9); … … 1473 1566 unsigned int p = procid & ((1<<P_WIDTH)-1); 1474 1567 1475 _printf("\n[ FAT DEBUG] _fat_write() : P[%d,%d,%d] enters for file %s\n"1568 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] enters for file %s\n" 1476 1569 " - buffer vbase = %x\n" 1477 1570 " - skipped sectors = %x\n" … … 1479 1572 " - file sectors = %x\n" 1480 1573 " - need_allocate = %d\n", 1481 x, y, p, 1482 fat.fd[fd_id].name 1483 (unsigned int)buffer, 1484 offset, 1485 count, 1486 file_sectors, 1487 allocate ); 1574 x, y, p, _fat.fd[fd_id].name, (unsigned int)buffer, 1575 offset, count, file_sectors, allocate ); 1488 1576 #endif 1489 1577 … … 1494 1582 return -1; 1495 1583 } 1496 if ( fat.fd[fd_id].used != 1 )1584 if ( _fat.fd[fd_id].used != 1 ) 1497 1585 { 1498 1586 _printf("\n[FAT ERROR] in _fat_write() : file not open\n"); … … 1507 1595 if ( allocate ) 1508 1596 { 1509 if ( _fat_allocate( fd_id, (required_cluster - current_cluster) ) < 0)1597 if ( _fat_allocate( use_irq , fd_id, (required_cluster-current_cluster) ) ) 1510 1598 { 1511 1599 _printf("\n[FAT ERROR] in _fat_write() : fat_allocate failed\n"); … … 1519 1607 1520 1608 // get first cluster index 1521 cluster = fat.fd[fd_id].first_cluster;1522 1523 #if GIET_DEBUG_FAT 1524 _printf("\n[ FAT DEBUG] _fat_write() : P[%d,%d,%d] get cluster %x\n",1609 cluster = _fat.fd[fd_id].first_cluster; 1610 1611 #if GIET_DEBUG_FAT 1612 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] get cluster %x\n", 1525 1613 x, y, p, cluster ); 1526 1614 #endif 1527 1615 1528 1616 // compute index of first cluster to be loaded 1529 // as we may need to scan the FAT, we use the kernel mode1530 1617 while ( clusters_to_skip ) 1531 1618 { 1532 cluster = _get_next_cluster( IOC_KERNEL_MODE, cluster );1619 cluster = _get_next_cluster( use_irq , cluster ); 1533 1620 clusters_to_skip--; 1534 1621 } … … 1538 1625 unsigned int lba; // first sector index on device 1539 1626 unsigned int iter_sectors; // number of sectors to load in iteration 1540 char*src; // pointer on target buffer1627 unsigned int src; // pointer on target buffer 1541 1628 1542 1629 // initialize these variables for the first iteration 1543 1630 todo_sectors = count; 1544 src = ( char*)buffer;1631 src = (unsigned int)buffer; 1545 1632 lba = cluster_to_lba(cluster) + sectors_to_skip; 1546 1633 if( count < (spc - sectors_to_skip) ) iter_sectors = count; … … 1552 1639 1553 1640 #if GIET_DEBUG_FAT 1554 _printf("\n[FAT DEBUG] _fat_write() : P[%d,%d,%d] makes an IOC write" 1555 " - cluster = %x\n" 1556 " - buffer = %x\n" 1557 " - lba = %x\n" 1558 " - sectors = %x\n", 1559 x, y, p, 1560 cluster, 1561 (unsigned int) src, 1562 lba, 1563 iter_sectors ); 1564 #endif 1565 1566 if( _ioc_write( 0, // channel 1567 mode, // mode for IOC driver 1568 lba, // first sector index 1569 src, // source buffer address 1570 iter_sectors ) ) // number of sectors 1641 _printf("\n[DEBUG FAT] _fat_write() : P[%d,%d,%d] makes an IOC write" 1642 " cluster = %x / buffer = %x / lba = %x / sectors = %d\n", 1643 x, y, p, cluster, src, lba, iter_sectors ); 1644 #endif 1645 1646 if( _fat_ioc_access( use_irq, 1647 0, // write 1648 lba, 1649 src, // source buffer address 1650 iter_sectors ) ) // number of sectors 1571 1651 { 1572 1652 _printf("\n[FAT ERROR] in _fat_write() cannot write block %x\n", lba ); … … 1575 1655 1576 1656 // update variables for next iteration 1577 cluster = _get_next_cluster( mode, cluster );1657 cluster = _get_next_cluster( use_irq , cluster ); 1578 1658 todo_sectors = todo_sectors - iter_sectors; 1579 1659 src = src + (iter_sectors << 9); … … 1587 1667 if ( ( offset + count ) > file_sectors ) 1588 1668 { 1589 fat.fd[fd_id].file_size = (count + offset) << 9;1669 _fat.fd[fd_id].file_size = (count + offset) << 9; 1590 1670 } 1591 1671 1592 1672 // Update entry of directory with the new value 1593 1673 // of file size (Field : DIR_FILE_SIZE) 1594 if ( update_entry(fd_id, DIR_FILE_SIZE, fat.fd[fd_id].file_size) )1595 { 1596 1597 1674 if ( _update_entry( use_irq, fd_id , DIR_FILE_SIZE , _fat.fd[fd_id].file_size ) ) 1675 { 1676 _printf("\n[FAT ERROR] in _fat_write() update entry failed\n"); 1677 return -1; 1598 1678 } 1599 1679 … … 1615 1695 if( (fd_id < GIET_OPEN_FILES_MAX) ) 1616 1696 { 1617 file_size = fat.fd[fd_id].file_size;1697 file_size = _fat.fd[fd_id].file_size; 1618 1698 1619 1699 if ( file_size & 0x1FF ) file_sectors = (file_size >> 9) + 1; … … 1638 1718 if( (fd_id < GIET_OPEN_FILES_MAX) ) 1639 1719 { 1640 fat.fd[fd_id].used = 0;1720 _fat.fd[fd_id].used = 0; 1641 1721 return 0; 1642 1722 } … … 1648 1728 } // end fat_close() 1649 1729 1650 ///////////////////////////////////////////////////////////////////////////////// ////1730 ///////////////////////////////////////////////////////////////////////////////// 1651 1731 // The following function implement the user_level system call. 1652 1732 // The flags argument is not used, as file access modes are not implemented yet. 1653 ///////////////////////////////////////////////////////////////////////////////// ////1733 ///////////////////////////////////////////////////////////////////////////////// 1654 1734 // Return the file descriptor index if success / return -1 if failure 1655 ///////////////////////////////////////////////////////////////////////////////// ////1735 ///////////////////////////////////////////////////////////////////////////////// 1656 1736 int _fat_user_open( char* pathname, // absolute pathname from root 1657 1737 unsigned int flags ) // unused: TODO 1658 1738 { 1659 return _fat_open( IOC_KERNEL_MODE, // we use KERNEL_MODE, because1660 pathname, // we need to write into FAT cache1661 0 ); 1739 return _fat_open( 1, // use descheduling mode if possible 1740 pathname, 1741 0 ); // no creation if not found 1662 1742 } 1663 1743 1664 ///////////////////////////////////////////////////////////////////////////////// ////1744 ///////////////////////////////////////////////////////////////////////////////// 1665 1745 // The following function implement the user_level system call. 1666 // This function should be modified to respect the UNIX specification 1667 ///////////////////////////////////////////////////////////////////////////////// ////1746 // This function should be modified to respect the UNIX specification. 1747 ///////////////////////////////////////////////////////////////////////////////// 1668 1748 // Return number of sectors actually transfered if success / return -1 if failure 1669 ///////////////////////////////////////////////////////////////////////////////// ////1749 ///////////////////////////////////////////////////////////////////////////////// 1670 1750 int _fat_user_read( unsigned int fd, // file descriptor index 1671 1751 void* buffer, // destination buffer … … 1673 1753 unsigned int offset ) // number of sectors to skip 1674 1754 { 1675 return _fat_read( IOC_USER_MODE,1755 return _fat_read( 1, // use descheduling mode if possible 1676 1756 fd, 1677 1757 buffer, … … 1680 1760 } 1681 1761 1682 ///////////////////////////////////////////////////////////////////////////////// ////1762 ///////////////////////////////////////////////////////////////////////////////// 1683 1763 // The following function implement the user_level system call. 1684 1764 // This function should be modified to respect the UNIX specification. 1685 ///////////////////////////////////////////////////////////////////////////////// ////1765 ///////////////////////////////////////////////////////////////////////////////// 1686 1766 // Return number of sectors actually transfered if success / return -1 if failure 1687 ///////////////////////////////////////////////////////////////////////////////// ////1767 ///////////////////////////////////////////////////////////////////////////////// 1688 1768 int _fat_user_write( unsigned int fd, // file descriptor 1689 1769 void* buffer, // source buffer … … 1691 1771 unsigned int offset ) // number of sectors to skip on file 1692 1772 { 1693 return _fat_write( IOC_USER_MODE,1773 return _fat_write( 1, // use descheduling mode if possible 1694 1774 fd, 1695 1775 buffer, … … 1698 1778 } 1699 1779 1700 ///////////////////////////////////////////////////////////////////////////////// ////1780 ///////////////////////////////////////////////////////////////////////////////// 1701 1781 int _fat_user_lseek( unsigned int fd_id, 1702 1782 unsigned int offset, -
soft/giet_vm/giet_fat32/fat32.h
r503 r530 1 //////////////////////////////////////////////////////////////////////////// 1 //////////////////////////////////////////////////////////////////////////////// 2 2 // File : fat32.h 3 3 // Date : 01/09/2013 4 4 // Author : Marco Jankovic / Alain Greiner 5 5 // Copyright (c) UPMC-LIP6 6 //////////////////////////////////////////////////////////////////////////// 6 //////////////////////////////////////////////////////////////////////////////// 7 7 8 8 #ifndef _FAT32_H … … 12 12 #include "kernel_locks.h" 13 13 14 /*************** Partition Boot Sector Format ********************************** ********/14 /*************** Partition Boot Sector Format **********************************/ 15 15 // offset | length 16 16 #define BS_JMPBOOT 0 , 3 … … 56 56 #define FOURTH_PARTITION_BEGIN_LBA 502 , 4 57 57 #define FOURTH_PARTITION_SIZE 506 , 4 58 /******************************************************************************* ********/58 /*******************************************************************************/ 59 59 60 60 #define MBR_SIGNATURE_POSITION 510 , 2 61 61 #define MBR_SIGNATURE_VALUE 0xAA55 62 62 63 /************** FAT_FS_INFO SECTOR ******************************************** ********/63 /************** FAT_FS_INFO SECTOR ********************************************/ 64 64 #define FS_SIGNATURE_VALUE_1 0x52526141 65 65 #define FS_SIGNATURE_VALUE_2 0x72724161 … … 70 70 #define FS_FREE_CLUSTER 488 , 4 71 71 #define FS_FREE_CLUSTER_HINT 492 , 4 72 /******************************************************************************* ********/72 /*******************************************************************************/ 73 73 74 74 #define DIR_ENTRY_SIZE 32 75 75 76 /******* Directory Entry Structure (32 bytes) ********************************** ********/76 /******* Directory Entry Structure (32 bytes) **********************************/ 77 77 // offset | length 78 78 #define DIR_NAME 0 , 11 // dir_entry name … … 85 85 #define DIR_FST_CLUS_LO 26 , 2 // cluster index 16 LSB bit 86 86 #define DIR_FILE_SIZE 28 , 4 // file size (up to 4 giga bytes) 87 /******************************************************************************* ********/88 89 /******* LFN Directory Entry Structure (32 bytes) ***************************** ********/87 /*******************************************************************************/ 88 89 /******* LFN Directory Entry Structure (32 bytes) *****************************/ 90 90 // offset | length 91 91 #define LDIR_ORD 0 , 1 // Sequence number (from 0x01 to 0x0f) … … 97 97 #define LDIR_RSVD 26 , 2 // artifact of previous fat (must be 0) 98 98 #define LDIR_NAME_3 28 , 4 99 /******************************************************************************* ********/100 101 /*********************** DIR_ATTR values (attributes) ************************ ********/99 /*******************************************************************************/ 100 101 /*********************** DIR_ATTR values (attributes) ************************/ 102 102 #define ATTR_READ_ONLY 0x01 103 103 #define ATTR_HIDDEN 0x02 … … 107 107 #define ATTR_ARCHIVE 0x20 108 108 #define ATTR_LONG_NAME_MASK 0x0f // READ_ONLY|HIDDEN|SYSTEM|VOLUME_ID 109 /******************************************************************************* ********/110 111 /********************* DIR_ORD special values ********************************** ********/109 /*******************************************************************************/ 110 111 /********************* DIR_ORD special values **********************************/ 112 112 #define FREE_ENTRY 0xE5 // this entry is free in the directory 113 113 #define NO_MORE_ENTRY 0x00 // no more entry in the directory 114 /******************************************************************************* ********/115 116 /******************** CLuster Index Special Values ***************************** ********/114 /*******************************************************************************/ 115 116 /******************** CLuster Index Special Values *****************************/ 117 117 #define FREE_CLUSTER 0x00000000 118 118 #define RESERVED_CLUSTER 0x00000001 119 119 #define BAD_CLUSTER 0x0FFFFFF7 120 120 #define END_OF_CHAIN_CLUSTER 0x0ffffff8 121 /******************************************************************************* ********/121 /*******************************************************************************/ 122 122 123 123 #define FAT_INITIALISED 0xBABEF00D 124 124 125 /************ This struct defines a file descriptor **************************** ********/125 /************ This struct defines a file descriptor ****************************/ 126 126 typedef struct file_descriptor_s 127 127 { … … 132 132 char name[244]; // pathname 133 133 } file_desc_t; 134 /******************************************************************************* ********/135 136 /************ This struct describes a FAT32 disk ******************************* ***/134 /*******************************************************************************/ 135 136 /************ This struct describes a FAT32 disk *******************************/ 137 137 typedef struct fat32_fs_s 138 138 { 139 char fat_cache[512]; // FAT cache: 1 sector = 128 cluster indexes139 char fat_cache[512]; // FAT cache: 1 sector 140 140 spin_lock_t fat_lock; // lock protecting exclusive access 141 141 file_desc_t fd[GIET_OPEN_FILES_MAX]; // file descriptors array 142 unsigned int initialised; // contains0xBABEF00D when FAT initialised142 unsigned int initialised; // 0xBABEF00D when FAT initialised 143 143 unsigned int sector_size; // number of bytes (power of 2) 144 144 unsigned int sectors_per_cluster; // power of 2 (must be greater than 4) 145 unsigned int cluster_size; // sector_size * sector_per_cluster (bytes)146 unsigned int fat_sectors; // number of sectors occupied by oneFAT copy145 unsigned int cluster_size; // sector_size * sector_per_cluster 146 unsigned int fat_sectors; // number of sectors for 1 FAT copy 147 147 unsigned int fat_lba; // lba of first FAT sector 148 148 unsigned int data_lba; // lba of first data sector … … 152 152 unsigned int fs_info_lba; // lba of fs_info 153 153 } fat32_fs_t; 154 /***************************************************************************************/ 155 156 /*********************** Export Functions *********************************************/ 157 158 extern void _fat_print(); 159 160 // functions used for low level access to fat 161 // (move sectors between block device and system buffers) 162 163 extern int _fat_init( unsigned int mode ); // mode for IOC driver 164 165 extern int _fat_open( unsigned int mode, // mode for IOC driver 166 char* pathname, // file pathname from root 167 unsigned int create ); // create new file if non zero 168 169 extern int _fat_read( unsigned int mode, // mode for IOC driver 170 unsigned int fd_id, // file descriptor index 171 void* buffer, // destination buffer 172 unsigned int count, // number of sectors to read 173 unsigned int offset ); // offset sector in file 174 175 extern int _fat_write( unsigned int mode, // mode for IOC driver 176 unsigned int fd_id, // file descriptor index 177 void* buffer, // source buffer 178 unsigned int count, // number of sectors to write 179 unsigned int offset ); // offset sector in file 180 181 extern int _fat_fstat( unsigned int fd_id ); // file descriptor index 182 183 extern int _fat_close( unsigned int fd_id ); // file descriptor index 184 185 186 // functions used by user system calls 187 // (should move bytes between system buffers and user buffers) 188 189 extern int _fat_user_open( char* pathname, // file pathname from root 190 unsigned int flags ); // unused 154 /*******************************************************************************/ 155 156 /*********************** Extern Functions *************************************/ 157 158 extern int _fat_init( unsigned int use_irq ); // use IRQ if possible 159 160 extern int _fat_open( unsigned int use_irq, // use IRQ if possible 161 char* pathname, // file pathname from root 162 unsigned int create ); // create new file if non zero 163 164 extern int _fat_read( unsigned int use_irq, // use IRQ if possible 165 unsigned int fd_id, // file descriptor index 166 void* buffer, // destination buffer 167 unsigned int count, // number of sectors to read 168 unsigned int offset ); // offset sector in file 169 170 extern int _fat_write( unsigned int use_irq, // use IRQ if possible 171 unsigned int fd_id, // file descriptor index 172 void* buffer, // source buffer 173 unsigned int count, // number of sectors to write 174 unsigned int offset ); // offset sector in file 175 176 extern int _fat_fstat( unsigned int fd_id ); // file descriptor index 177 178 extern int _fat_close( unsigned int fd_id ); // file descriptor index 179 180 181 extern int _fat_user_open( char* pathname, // file pathname from root 182 unsigned int flags ); // unused 191 183 192 184 extern int _fat_user_read( unsigned int fd_id, // file descriptor index 193 185 void* buffer, // destination buffer 194 186 unsigned int count, // number of sectors to read 195 unsigned int offset ); // number ofsectors to skip in file187 unsigned int offset ); // sectors to skip in file 196 188 197 189 extern int _fat_user_write( unsigned int fd_id, // file descriptor index 198 190 void* buffer, // source buffer 199 191 unsigned int count, // number of sectors to write 200 unsigned int offset ); // number ofsectors to skip in file192 unsigned int offset ); // sectors to skip in file 201 193 202 194 extern int _fat_user_lseek( unsigned int fd_id, … … 204 196 unsigned int whence ); 205 197 206 /******************************************************************************* ********/198 /*******************************************************************************/ 207 199 208 200
Note: See TracChangeset
for help on using the changeset viewer.