Changeset 295 for soft/giet_vm/giet_fat32
- Timestamp:
- Mar 26, 2014, 6:44:44 PM (11 years ago)
- Location:
- soft/giet_vm/giet_fat32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r291 r295 17 17 // 2. This FAT32 library uses a FAT cache whose storage capacity is one 18 18 // sector (512 bytes, or 128 cluster indexes in FAT) 19 // 3. This FAT32 library can be used in three modes: BOOT/KERNEL/USER20 // defining threedifferent behaviours for the IOC driver.19 // 3. This FAT32 library can be used in four modes: BOOT_PA/BOOT_VA/KERNEL/USER 20 // defining different behaviours for the IOC driver. 21 21 ////////////////////////////////////////////////////////////////////////////////// 22 22 … … 46 46 temp[8] = 0; 47 47 48 _tty_get_lock( 0 ); 49 _puts("\n*********************** fat_cache_lba = "); 50 _putx( fat.cache_lba ); 51 _puts(" **************************\n"); 48 _printf("\n*********************** fat_cache_lba = %x *****************************\n", 49 fat.cache_lba ); 52 50 53 51 for ( line=0 ; line<16 ; line++ ) 54 52 { 55 53 // display address 56 _putx( (fat.cache_lba<<9) + (line<<5) ); 57 _puts(" : "); 54 _printf( "%x : ", (fat.cache_lba<<9) + (line<<5) ); 58 55 59 56 // display data hexa … … 65 62 (fat.fat_cache[byte+2]<< 8) | 66 63 (fat.fat_cache[byte+3]); 67 _putx( hexa ); 68 _puts(" | "); 64 _printf("%x | ", hexa ); 69 65 70 66 // prepare display ascii … … 76 72 77 73 // display data ascii 78 _puts( (char*)temp ); 79 _puts("\n"); 80 } 81 _puts("***************************************************************************\n"); 82 _tty_release_lock( 0 ); 74 _printf( (char*)temp ); 75 _printf("\n"); 76 } 77 _printf("**************************************************************************\n"); 83 78 } // end display_fat_cache() 84 79 #endif … … 202 197 203 198 // access fat 204 if( _ioc_read( mode, // mode for IOC driver 199 if( _ioc_read( 0, // channel 200 mode, // mode for IOC driver 205 201 lba, // sector index 206 202 fat.fat_cache, // fat cache 207 203 1 ) ) // one sector 208 204 { 209 _tty_get_lock( 0 ); 210 _puts("[FAT_ERROR] in get_next cluster_id() cannot read block "); 211 _putd( lba ); 212 _puts("\n"); 213 _tty_release_lock( 0 ); 205 _printf("[FAT_ERROR] in get_next cluster_id() " 206 "cannot read block %x\n", lba ); 214 207 return 1; 215 208 } … … 271 264 272 265 #if GIET_DEBUG_FAT 273 _tty_get_lock( 0 ); 274 _puts("\n[FAT DEBUG] filename "); 275 _puts( string ); 276 _tty_release_lock( 0 ); 266 _printf("\n[FAT DEBUG] filename %s", string ); 277 267 #endif 278 268 … … 282 272 283 273 #if GIET_DEBUG_FAT 284 _tty_get_lock( 0 ); 285 _puts(" converted to 8.3 SFN format : "); 286 _puts( sfn_string ); 287 _puts("\n"); 288 _tty_release_lock( 0 ); 274 _printf(" converted to 8.3 SFN format : %s\n", sfn_string ); 289 275 #endif 290 276 … … 298 284 299 285 #if GIET_DEBUG_FAT 300 _tty_get_lock( 0 ); 301 _puts(" converted to 8.3 SFN format : "); 302 _puts( string ); 303 _puts("\n"); 304 _tty_release_lock( 0 ); 286 _printf(" converted to 8.3 SFN format : %s\n", sfn_string ); 305 287 #endif 306 288 … … 358 340 359 341 #if GIET_DEBUG_FAT 360 _tty_get_lock( 0 ); 361 _puts(" converted to 8.3 SFN format : "); 362 _puts( sfn_string ); 363 _puts("\n"); 364 _tty_release_lock( 0 ); 342 _printf(" converted to 8.3 SFN format : %s\n", sfn_string ); 365 343 #endif 366 344 … … 524 502 is_sfn = is_short( file_name, sfn ); 525 503 526 if ( _ioc_read( IOC_KERNEL_MODE, // mode for IOC driver 504 if ( _ioc_read( 0, // channel 505 IOC_KERNEL_MODE, // mode for IOC driver 527 506 lba, // sector index 528 507 fat.fat_cache, // buffer address 529 508 1 ) ) // one sector 530 509 { 531 _tty_get_lock( 0 ); 532 _puts("[FAT ERROR] in update_entry() cannot read sector "); 533 _putd( lba ); 534 _puts("\n"); 535 _tty_release_lock( 0 ); 510 _printf("[FAT ERROR] in update_entry() cannot read sector %x\n", lba ); 536 511 return 1; 537 512 } … … 562 537 else if (ord == NO_MORE_ENTRY ) // end of directory : return 563 538 { 564 _tty_get_lock( 0 ); 565 _puts("[FAT ERROR] in update_entry() end of directory reaches "); 566 _puts("\n"); 567 _tty_release_lock( 0 ); 539 _printf("[FAT ERROR] in update_entry() : reaches end of directory\n"); 568 540 return 1; 569 541 } … … 591 563 else if (ord == NO_MORE_ENTRY ) // end of directory : return 592 564 { 593 _tty_get_lock( 0 ); 594 _puts("[FAT ERROR] in update_entry() end of directory reaches "); 595 _puts("\n"); 596 _tty_release_lock( 0 ); 565 _printf("[FAT ERROR] in update_entry() reaches end of directory\n"); 597 566 return 1; 598 567 } … … 643 612 } 644 613 645 return _ioc_write( IOC_KERNEL_MODE, 646 lba, 647 fat.fat_cache, 648 1 ); 649 } 650 ////////////////////////////////////////////////////////////////////////////////// 651 // This function update FS_INFO, for new last cluster allocated and number of free 652 // cluster. 614 return _ioc_write( 0, // channel 615 IOC_KERNEL_MODE, // mode 616 lba, // sector index 617 fat.fat_cache, // source buffer 618 1 ); // one sector 619 } 620 ////////////////////////////////////////////////////////////////////////////////// 621 // This function update FS_INFO: 622 // last cluster allocated and number of free cluster. 653 623 // Return 0 in case of success, > 0 if failure. 654 624 ////////////////////////////////////////////////////////////////////////////////// … … 658 628 659 629 #if GIET_DEBUG_FAT 660 _tty_get_lock( 0 ); 661 _puts("\n[FAT DEBUG] Enter in update_fs_info()\n"); 662 _tty_release_lock( 0 ); 630 _printf("\n[FAT DEBUG] Enter update_fs_info()\n"); 663 631 #endif 664 632 … … 670 638 else // miss cache 671 639 { 672 if ( _ioc_read( IOC_KERNEL_MODE, // mode for IOC driver 640 if ( _ioc_read( 0, // channel 641 IOC_KERNEL_MODE, // mode for IOC driver 673 642 lba, // sector index 674 fat.fat_cache, // fat cache643 fat.fat_cache, // source buffer 675 644 1 ) ) // one sector 676 645 { 677 _tty_get_lock( 0 ); 678 _puts("[FAT_ERROR] in update_fat() cannot read block "); 679 _putd( lba ); 680 _puts("\n"); 681 _tty_release_lock( 0 ); 646 _printf("[FAT_ERROR] in update_fat() cannot read block %x\n", lba ); 682 647 return 1; 683 648 } … … 686 651 write_entry( FS_FREE_CLUSTER_HINT, fat.fat_cache, fat.last_cluster_allocated ); 687 652 } 688 return _ioc_write( IOC_KERNEL_MODE, 689 lba, 690 fat.fat_cache, 691 1 ); 653 return _ioc_write( 0, // channel 654 IOC_KERNEL_MODE, // mode 655 lba, // sector index 656 fat.fat_cache, // source buffer 657 1 ); // one sector 692 658 } 693 659 … … 703 669 704 670 #if GIET_DEBUG_FAT 705 _tty_get_lock( 0 ); 706 _puts("\n[FAT DEBUG] Enter in update_fat() :\n"); 707 _puts(" - Cluster to update = "); 708 _putd( cluster ); 709 _puts("\n"); 710 _puts(" - Value to write = "); 711 _putd( value ); 712 _puts("\n"); 713 _tty_release_lock( 0 ); 671 _printf("\n[FAT DEBUG] Enter update_fat() : cluster = %x / value = %x\n", 672 cluster, value ); 714 673 #endif 715 674 … … 720 679 else // miss cache 721 680 { 722 if ( _ioc_read( IOC_KERNEL_MODE, // mode for IOC driver 681 if ( _ioc_read( 0, // channel 682 IOC_KERNEL_MODE, // mode for IOC driver 723 683 lba, // sector index 724 fat.fat_cache, // fat cache684 fat.fat_cache, // source buffer 725 685 1 ) ) // one sector 726 686 { 727 _tty_get_lock( 0 ); 728 _puts("[FAT_ERROR] in update_fat() cannot read block "); 729 _putd( lba ); 730 _puts("\n"); 731 _tty_release_lock( 0 ); 687 _printf("[FAT_ERROR] in update_fat() cannot read block %x\n"); 732 688 return 1; 733 689 } … … 735 691 write_entry( ((cluster % 128) << 2), 4, fat.fat_cache, value ); 736 692 } 737 return _ioc_write( IOC_KERNEL_MODE, 738 lba, 739 fat.fat_cache, 740 1 ); 693 return _ioc_write( 0, // channel 694 IOC_KERNEL_MODE, // mode 695 lba, // sector indexs 696 fat.fat_cache, // source buffer 697 1 ); // one sector 741 698 } 742 699 … … 759 716 if ( get_next_cluster_id( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER) 760 717 { 761 _tty_get_lock( 0 ); 762 _puts("\n[FAT ERROR] in _fat_allocate() : first free_cluster isnt free\n"); 763 _tty_release_lock( 0 ); 718 _printf("\n[FAT ERROR] in _fat_allocate() : first free_cluster not free\n"); 764 719 return -1; 765 720 } … … 767 722 if ( count > fat.number_free_cluster ) 768 723 { 769 _tty_get_lock( 0 ); 770 _puts("\n[FAT ERROR] in _fat_allocate() : Not enough free cluster(s) for this allocation\n"); 771 _tty_release_lock( 0 ); 724 _printf("\n[FAT ERROR] in _fat_allocate() : Not enough free cluster(s)\n"); 772 725 return -1; 773 726 } 774 727 775 728 #if GIET_DEBUG_FAT 776 _tty_get_lock( 0 ); 777 _puts("\n[FAT DEBUG] Enter in _fat_allocate() :\n"); 778 _puts(" - Need to allocate "); 779 _putd( count ); 780 _puts(" cluster(s) for file "); 781 _putd( fd_id ); 782 _puts("\n"); 783 _tty_release_lock( 0 ); 729 _printf("\n[FAT DEBUG] Enter in _fat_allocate() for file %d\n", fd_id ); 784 730 #endif 785 731 … … 795 741 796 742 #if GIET_DEBUG_FAT 797 _tty_get_lock( 0 ); 798 _puts("\n[FAT DEBUG] Cluster to update is : "); 799 _putd( last_cluster_file ); 800 _puts("\n"); 801 _puts("[FAT DEBUG] Free cluster is : "); 802 _putd( free_cluster ); 803 _puts("\n"); 804 _puts("[FAT DEBUG] Number of cluster need to be allocated : "); 805 _putd( cluster_to_allocate ); 806 _puts("\n"); 807 _tty_release_lock( 0 ); 743 _printf("\n[FAT DEBUG] cluster to update = %x / free cluster = %x / clusters required = %d\n", 744 last_cluster_file, free_cluster, cluster_to_allocate ); 808 745 #endif 809 746 … … 812 749 if ( update_fat( last_cluster_file, free_cluster ) ) 813 750 { 814 _tty_get_lock( 0 ); 815 _puts("\n[FAT ERROR] in _fat_allocate() : update fat for file "); 816 _putd( fd_id ); 817 _puts(" failed\n"); 818 _tty_release_lock( 0 ); 751 _printf("\n[FAT ERROR] in _fat_allocate() : update fat failed\n"); 819 752 return -1; 820 753 } … … 831 764 if ( update_fat( last_cluster_file, END_OF_CHAIN_CLUSTER ) ) 832 765 { 833 _tty_get_lock( 0 ); 834 _puts("\n[FAT ERROR] in _fat_allocate() : update fat for file "); 835 _putd( fd_id ); 836 _puts(" failed\n"); 837 _tty_release_lock( 0 ); 766 _printf("\n[FAT ERROR] in _fat_allocate() : update fat failed\n"); 838 767 return -1; 839 768 } … … 845 774 if ( get_next_cluster_id( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER) 846 775 { 847 _tty_get_lock( 0 ); 848 _puts("\n[FAT ERROR] in _fat_allocate() : free_cluster isnt free\n"); 849 _tty_release_lock( 0 ); 776 _printf("\n[FAT ERROR] in _fat_allocate() : free_cluster not free\n"); 850 777 return -1; 851 778 } … … 859 786 if ( update_fs_info() ) 860 787 { 861 _tty_get_lock( 0 ); 862 _puts("\n[FAT ERROR] in _fat_allocate() : update fs_info for file "); 863 _putd( fd_id ); 864 _puts(" failed\n"); 865 _tty_release_lock( 0 ); 788 _printf("\n[FAT ERROR] in _fat_allocate() : update fs_info failed\n"); 866 789 return -1; 867 790 } … … 895 818 896 819 #if GIET_DEBUG_FAT 897 _tty_get_lock( 0 ); 898 _puts("\n[FAT DEBUG] enter _scan_directory() searching dir/file : "); 899 _puts( file_name ); 900 _puts("\n"); 901 _tty_release_lock( 0 ); 820 _printf("\n[FAT DEBUG] enter _scan_directory() searching dir/file %s", filename ); 902 821 #endif 903 822 … … 920 839 // load first cluster sector from DATA region into FAT cache 921 840 // other sectors will be loaded inside loop as required 922 if( _ioc_read( mode, // mode for IOC driver 841 if( _ioc_read( 0, // channel 842 mode, // mode for IOC driver 923 843 lba, // sector index 924 844 fat.fat_cache, // buffer address 925 845 1 ) ) // one sector 926 846 { 927 _tty_get_lock( 0 ); 928 _puts("[FAT ERROR] in scan directory() cannot read sector "); 929 _putd( lba ); 930 _puts("\n"); 931 _tty_release_lock( 0 ); 847 _printf("[FAT ERROR] in scan directory() cannot read sector %x\n", lba ); 932 848 return -1; 933 849 } … … 935 851 fat.cache_lba = lba; 936 852 937 938 939 853 #if GIET_DEBUG_FAT 854 display_fat_cache(); 855 #endif 940 856 941 857 // in this loop we scan all names in directory identified by cluster: … … 961 877 block_id = fat.sectors_per_cluster; 962 878 } 963 if( _ioc_read( mode, // mode for IOC driver 879 if( _ioc_read( 0, // channel 880 mode, // mode for IOC driver 964 881 lba, // sector index 965 882 fat.fat_cache, // buffer address 966 883 1 ) ) // one sector 967 884 { 968 _tty_get_lock( 0 ); 969 _puts("[FAT ERROR] in scan directory() cannot read sector "); 970 _putd( lba ); 971 _puts("\n"); 972 _tty_release_lock( 0 ); 885 _printf("[FAT ERROR] in scan directory() cannot read sector %x\n", lba ); 973 886 return -1; 974 887 } … … 1072 985 *lba_dir_entry = lba; 1073 986 1074 #if GIET_DEBUG_FAT1075 _tty_get_lock( 0 );1076 _puts("\n[FAT DEBUG] FILE FOUND\n");1077 _tty_release_lock( 0 );1078 #endif1079 987 return read_cluster( dir_entry ); 1080 988 } … … 1094 1002 unsigned int dir_cluster ) 1095 1003 { 1096 _tty_get_lock( 0 ); 1097 _puts("\n[FAT ERROR] _fat_create() not implemented\n"); 1098 _tty_release_lock( 0 ); 1004 _printf("\n[FAT ERROR] _fat_create() not implemented\n"); 1099 1005 return 0; 1100 1006 } //end _fat_create() … … 1115 1021 1116 1022 #if GIET_DEBUG_FAT 1117 _tty_get_lock( 0 ); 1118 _puts("\n[FAT DEBUG] Enter _fat_init() / fat_cache_base = "); 1119 _putx( (unsigned int)fat.fat_cache ); 1120 _puts("\n"); 1121 _tty_release_lock( 0 ); 1023 unsigned int procid = _get_procid(); 1024 unsigned int cid = procid / NB_PROCS_MAX; 1025 unsigned int lpid = procid % NB_PROCS_MAX; 1026 unsigned int x = cid >> Y_WIDTH; 1027 unsigned int y = cid & ((1<<Y_WIDTH) - 1); 1028 1029 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] enters _fat_init()\n", 1030 x, y, lpid ); 1122 1031 #endif 1123 1032 1124 1033 // load Master Boot Record (sector 0) into fat cache 1125 if ( _ioc_read( mode, // mode for IOC driver 1034 if ( _ioc_read( 0, // channel 1035 mode, // mode for IOC driver 1126 1036 0, // sector index 1127 1037 fat.fat_cache, // buffer address 1128 1038 1 ) ) // one sector 1129 1039 { 1130 _tty_get_lock( 0 ); 1131 _puts("\n[FAT ERROR] in _fat_init() cannot load Boot Sector\n"); 1132 _tty_release_lock( 0 ); 1040 _printf("\n[FAT ERROR] in _fat_init() cannot load Boot Sector\n"); 1133 1041 return -1; 1134 1042 } 1135 1043 fat.cache_lba = 0; 1136 1044 1045 #if GIET_DEBUG_FAT 1046 display_fat_cache(); 1047 #endif 1048 1137 1049 // checking Boot sector integrity 1138 1050 if( MBR_SIGNATURE_VALUE != read_entry( MBR_SIGNATURE_POSITION, fat.fat_cache, 1)) 1139 1051 { 1140 _tty_get_lock( 0 ); 1141 _puts("\n[FAT ERROR] Boot sector not recognized or corrupt \n"); 1142 _tty_release_lock( 0 ); 1052 _printf("\n[FAT ERROR] Boot sector not recognized or corrupt \n"); 1143 1053 return -1; 1144 1054 } 1145 1055 1146 1056 #if GIET_DEBUG_FAT 1147 _tty_get_lock( 0 ); 1148 _puts("\n[FAT DEBUG] Boot Sector Loaded\n"); 1149 _tty_release_lock( 0 ); 1057 _printf("\n[FAT DEBUG] Boot Sector Loaded\n"); 1150 1058 #endif 1151 1059 … … 1155 1063 1156 1064 // load Partition Boot Record (first partition sector) into fat cache 1157 if ( _ioc_read( mode, // mode for IOC driver 1065 if ( _ioc_read( 0, // channel 1066 mode, // mode for IOC driver 1158 1067 fat.partition_lba, // sector index 1159 1068 fat.fat_cache, // buffer address 1160 1069 1 ) ) // one sector 1161 1070 { 1162 _tty_get_lock( 0 ); 1163 _puts("\n[FAT ERROR] in _fat_init() cannot load block "); 1164 _putd( fat.partition_lba ); 1165 _puts("\n"); 1166 _tty_release_lock( 0 ); 1071 _printf("\n[FAT ERROR] in _fat_init() cannot load block %x\n", fat.partition_lba ); 1167 1072 return -1; 1168 1073 } … … 1170 1075 1171 1076 #if GIET_DEBUG_FAT 1172 _tty_get_lock( 0 ); 1173 _puts("\n[FAT DEBUG] Partition First Sector Loaded\n"); 1174 _tty_release_lock( 0 ); 1077 _printf("\n[FAT DEBUG] Partition First Sector Loaded\n"); 1175 1078 #endif 1176 1079 … … 1179 1082 if( read_entry( BPB_BYTSPERSEC, fat.fat_cache, 1 ) != 512 ) 1180 1083 { 1181 _tty_get_lock( 0 ); 1182 _puts("\n[FAT ERROR] The sector size must be 512 bytes\n"); 1183 _tty_release_lock( 0 ); 1084 _printf("\n[FAT ERROR] The sector size must be 512 bytes\n"); 1184 1085 return -1; 1185 1086 } 1186 1087 if( read_entry( BPB_RSVDSECCNT, fat.fat_cache, 1 ) != 32 ) 1187 1088 { 1188 _tty_get_lock( 0 ); 1189 _puts("\n[FAT ERROR] The RSVD region in FAT32 must be 32 sectors\n"); 1190 _tty_release_lock( 0 ); 1089 _printf("\n[FAT ERROR] The RSVD region in FAT32 must be 32 sectors\n"); 1191 1090 return -1; 1192 1091 } 1193 1092 if( read_entry( BPB_NUMFATS, fat.fat_cache, 1 ) != 1 ) 1194 1093 { 1195 _tty_get_lock( 0 ); 1196 _puts("\n[FAT ERROR] The number of FAT copies in FAT region must be 1\n"); 1197 _tty_release_lock( 0 ); 1094 _printf("\n[FAT ERROR] The number of FAT copies in FAT region must be 1\n"); 1198 1095 return -1; 1199 1096 } 1200 1097 if( (read_entry( BPB_FAT32_FATSZ32, fat.fat_cache, 1 ) & 0xF) != 0 ) 1201 1098 { 1202 _tty_get_lock( 0 ); 1203 _puts("\n[FAT ERROR] The FAT region in FAT32 must be multiple of 32 sectors\n"); 1204 _tty_release_lock( 0 ); 1099 _printf("\n[FAT ERROR] The FAT region in FAT32 must be multiple of 32 sectors\n"); 1205 1100 return -1; 1206 1101 } 1207 1208 1102 if( read_entry( BPB_FAT32_ROOTCLUS, fat.fat_cache, 1 ) != 2 ) 1209 1103 { 1210 _tty_get_lock( 0 ); 1211 _puts("\n[FAT ERROR] The first cluster index must be 2\n"); 1212 _tty_release_lock( 0 ); 1104 _printf("\n[FAT ERROR] The first cluster index must be 2\n"); 1213 1105 return -1; 1214 1106 } … … 1227 1119 1228 1120 #if GIET_DEBUG_FAT 1229 _tty_get_lock( 0 ); 1230 _puts("\n[FAT DEBUG] FS_INFO Sector = "); 1231 _putd(fat.fs_info_lba); 1232 _puts("\n"); 1233 _tty_release_lock( 0 ); 1121 _printf("\n[FAT DEBUG] FS_INFO Sector = %x\n", fat.fs_info_lba ); 1234 1122 #endif 1235 1123 1236 1124 // load FS_INFO into fat cache 1237 if ( _ioc_read( mode, // mode for IOC driver 1125 if ( _ioc_read( 0, // channel 1126 mode, // mode for IOC driver 1238 1127 fat.fs_info_lba, // sector index 1239 1128 fat.fat_cache, // buffer address 1240 1129 1 ) ) // one sector 1241 1130 { 1242 _tty_get_lock( 0 ); 1243 _puts("\n[FAT ERROR] in _fat_init() cannot load FS_INFO Sector\n"); 1244 _tty_release_lock( 0 ); 1131 _printf("\n[FAT ERROR] in _fat_init() cannot load FS_INFO Sector\n"); 1245 1132 return -1; 1246 1133 } … … 1251 1138 1252 1139 #if GIET_DEBUG_FAT 1253 _tty_get_lock( 0 ); 1254 _puts("\n[FAT DEBUG] Number of Free Clusters = "); 1255 _putd(fat.number_free_cluster); 1256 _puts("\n"); 1257 _puts("\n[FAT DEBUG] Last known cluster allocated = "); 1258 _putd(fat.last_cluster_allocated); 1259 _puts("\n"); 1260 _puts("\n[FAT DEBUG] FS_INFO Sector Loaded\n"); 1261 _tty_release_lock( 0 ); 1262 #endif 1263 1264 1265 #if GIET_DEBUG_FAT 1266 _tty_get_lock( 0 ); 1267 _puts("\n[FAT DEBUG] Exit _fat_init()\n"); 1268 _tty_release_lock( 0 ); 1140 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] exit _fat_init() / " 1141 "free clusters = %x / last allocated cluster = %x\n", 1142 fat.number_free_cluster, fat.last_cluster_allocated ); 1269 1143 #endif 1270 1144 … … 1275 1149 void _fat_print() 1276 1150 { 1277 _p uts("\n################################ FAT32 ###############################");1278 _p uts("\nFAT initialised "); _putx(fat.initialised );1279 _p uts("\nSector Size (bytes) "); _putx(fat.sector_size );1280 _p uts("\nSectors per cluster "); _putx(fat.sectors_per_cluster );1281 _p uts("\nPartition size (sectors) "); _putx(fat.partition_sectors );1282 _p uts("\nPartition first lba "); _putx(fat.partition_lba );1283 _p uts("\nData region first lba "); _putx(fat.data_lba );1284 _p uts("\nNumber of sectors for one FAT "); _putx(fat.fat_sectors );1285 _p uts("\n######################################################################\n");1151 _printf("\n########################## FAT32 ###########################"); 1152 _printf("\nFAT initialised %d", fat.initialised ); 1153 _printf("\nSector Size (bytes) %x", fat.sector_size ); 1154 _printf("\nSectors per cluster %x", fat.sectors_per_cluster ); 1155 _printf("\nPartition size (sectors) %x", fat.partition_sectors ); 1156 _printf("\nPartition first lba %x", fat.partition_lba ); 1157 _printf("\nData region first lba %x", fat.data_lba ); 1158 _printf("\nNumber of sectors for one FAT %x", fat.fat_sectors ); 1159 _printf("\n############################################################\n"); 1286 1160 } 1287 1161 … … 1294 1168 // a new file is created and introduced in the directory. 1295 1169 // Finally, it sets a new open file in the file descriptors array. 1170 // The same file can be open several times by differents taks. 1296 1171 /////////////////////////////////////////////////////////////////////////////// 1297 1172 // Returns file descriptor index if success, returns -1 if error. … … 1311 1186 1312 1187 #if GIET_DEBUG_FAT 1313 _tty_get_lock( 0 ); 1314 _puts("\n[FAT DEBUG] enter _fat_open() for file "); 1315 _puts( pathname ); 1316 _puts("\n"); 1317 _tty_release_lock( 0 ); 1318 #endif 1319 1320 // check FAT initialised 1188 unsigned int procid = _get_procid(); 1189 unsigned int cid = procid / NB_PROCS_MAX; 1190 unsigned int lpid = procid % NB_PROCS_MAX; 1191 unsigned int x = cid >> Y_WIDTH; 1192 unsigned int y = cid & ((1<<Y_WIDTH) - 1); 1193 1194 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] enters _fat_open() for file %s\n", 1195 x, y, lpid, pathname ); 1196 #endif 1197 1198 // checking arguments 1199 if ( creat ) 1200 { 1201 _printf("[FAT ERROR] in _fat_open() : create not supported yet\n"); 1202 return -1; 1203 } 1204 1205 // takes the FAT lock for exclusive access 1206 _get_lock( &fat.lock ); 1207 1208 #if GIET_DEBUG_FAT 1209 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] takes the FAT lock\n", 1210 x, y, lpid ); 1211 #endif 1212 1213 // FAT initialisation if required 1321 1214 if( fat.initialised != FAT_INITIALISED ) 1322 1215 { 1323 1216 if ( _fat_init( mode ) ) 1324 1217 { 1325 _puts("[FAT ERROR] Cannot initialize FAT descriptor from Boot Sector\n"); 1326 _exit(); 1327 } 1328 1329 #if GIET_DEBUG_FAT 1330 _tty_get_lock( 0 ); 1331 _puts("\n[FAT DEBUG] FAT initialisation completed at cycle "); 1332 _putd(_get_proctime()); 1333 _puts("\n"); 1218 _printf("[FAT ERROR] in _fat_open() : Cannot initialize FAT descriptor\n"); 1219 1220 // release FAT lock 1221 _release_lock( &fat.lock ); 1222 1223 return -1; 1224 } 1225 1226 #if GIET_DEBUG_FAT 1227 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] initialises FAT descriptor\n", 1228 x, y, lpid ); 1334 1229 _fat_print(); 1335 _tty_release_lock( 0 ); 1336 #endif 1230 #endif 1231 1337 1232 } 1338 1233 … … 1350 1245 1351 1246 #if GIET_DEBUG_FAT 1352 _tty_get_lock( 0 ); 1353 _puts("\n[FAT DEBUG] _fat_open : search dir/file : "); 1354 _puts( name ); 1355 _puts("\n"); 1356 _tty_release_lock( 0 ); 1247 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] search dir/file : %s\n", 1248 x, y, lpid, name ); 1357 1249 #endif 1358 1250 … … 1373 1265 else if ( cluster == END_OF_CHAIN_CLUSTER ) 1374 1266 { 1375 _tty_get_lock( 0 ); 1376 _puts("\n[FAT ERROR] in _fat_open() for file "); 1377 _puts( pathname ); 1378 _puts(" : cannot found name "); 1379 _puts( name ); 1380 _puts("\n"); 1381 _tty_release_lock( 0 ); 1267 _printf("\n[FAT ERROR] in _fat_open() cannot found %s\n", name ); 1268 1269 // release FAT lock 1270 _release_lock( &fat.lock ); 1271 1382 1272 return -1; 1383 1273 } 1384 1274 } 1385 1386 #if GIET_DEBUG_FAT1387 _tty_get_lock( 0 );1388 _puts("\n[FAT DEBUG] File ");1389 _puts( pathname );1390 _puts(" found\n");1391 _tty_release_lock( 0 );1392 #endif1393 1275 1394 1276 // check the next value for cluster index found … … 1414 1296 1415 1297 #if GIET_DEBUG_FAT 1416 _tty_get_lock( 0 ); 1417 _puts("\n[FAT DEBUG] file "); 1418 _puts( pathname ); 1419 _puts(" open with fd_id = "); 1420 _putd( fd_id ); 1421 _puts("\n"); 1422 _tty_release_lock( 0 ); 1423 #endif 1298 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] open file %s with fd = %d\n", 1299 x, y, lpid, pathname, fd_id ); 1300 #endif 1301 1302 // release FAT lock 1303 _release_lock( &fat.lock ); 1424 1304 1425 1305 return fd_id; … … 1427 1307 else 1428 1308 { 1429 _tty_get_lock( 0 ); 1430 _puts("\n[FAT ERROR] in _fat_open() for file "); 1431 _puts( pathname ); 1432 _puts(" : file descriptor array full\n "); 1433 _tty_release_lock( 0 ); 1309 _printf("\n[FAT ERROR] in _fat_open() for file %s : fd array full\n", 1310 pathname ); 1311 1312 // release FAT lock 1313 _release_lock( &fat.lock ); 1314 1434 1315 return -1; 1435 1316 } … … 1437 1318 else 1438 1319 { 1439 _tty_get_lock( 0 ); 1440 _puts("\n[FAT ERROR] in _fat_open() for file "); 1441 _puts( pathname ); 1442 _puts(" : file found, but bad cluster\n"); 1443 _tty_release_lock( 0 ); 1320 _printf("\n[FAT ERROR] in _fat_open() for file %s : bad cluster\n", 1321 pathname ); 1322 1323 // release FAT lock 1324 _release_lock( &fat.lock ); 1325 1444 1326 return -1; 1445 1327 } … … 1461 1343 1462 1344 #if GIET_DEBUG_FAT 1463 _tty_get_lock( 0 ); 1464 _puts("\n[FAT DEBUG] Enter _fat_read() for file "); 1465 _puts( fat.fd[fd_id].name ); 1466 _puts("\n - buffer base = "); 1467 _putx( (unsigned int)buffer ); 1468 _puts("\n - skipped sectors = "); 1469 _putd( offset ); 1470 _puts("\n - read sectors = "); 1471 _putd( count ); 1472 _tty_release_lock( 0 ); 1345 unsigned int procid = _get_procid(); 1346 unsigned int cid = procid / NB_PROCS_MAX; 1347 unsigned int lpid = procid % NB_PROCS_MAX; 1348 unsigned int x = cid >> Y_WIDTH; 1349 unsigned int y = cid & ((1<<Y_WIDTH) - 1); 1350 1351 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] enters _fat_read() for file %s\n", 1352 " - buffer vbase = %x\n" 1353 " - skipped sectors = %x\n" 1354 " - read sectors = %x\n", 1355 x, y, lpid, fat.fd[fd_id].name, (unsigned int)buffer, offset, count ); 1473 1356 #endif 1474 1357 … … 1490 1373 if ( fd_id >= GIET_OPEN_FILES_MAX ) 1491 1374 { 1492 _tty_get_lock( 0 ); 1493 _puts("\n[FAT ERROR] in _fat_read() : illegal file descriptor index\n"); 1494 _tty_release_lock( 0 ); 1375 _printf("\n[FAT ERROR] in _fat_read() : illegal file descriptor index\n"); 1495 1376 return -1; 1496 1377 } 1497 1378 if ( fat.fd[fd_id].used != 1 ) 1498 1379 { 1499 _tty_get_lock( 0 ); 1500 _puts("\n[FAT ERROR] in _fat_read() : file not open\n"); 1501 _tty_release_lock( 0 ); 1380 _printf("\n[FAT ERROR] in _fat_read() : file not open\n"); 1502 1381 return -1; 1503 1382 } 1504 1383 if ( ((unsigned int)buffer & 0x1FF) != 0 ) 1505 1384 { 1506 _tty_get_lock( 0 ); 1507 _puts("\n[FAT ERROR] in _fat_read() : memory buffer not sector aligned\n"); 1508 _tty_release_lock( 0 ); 1385 _printf("\n[FAT ERROR] in _fat_read() : memory buffer not sector aligned\n"); 1509 1386 return -1; 1510 1387 } 1511 1388 if ( offset >= file_sectors ) 1512 1389 { 1513 _tty_get_lock( 0 ); 1514 _puts("\n[FAT ERROR] offset larger than number of sectors in file\n"); 1515 _puts(" - offset = "); 1516 _putd( offset ); 1517 _puts(" - file_sectors = "); 1518 _putd( file_sectors ); 1519 _tty_release_lock( 0 ); 1390 _printf("\n[FAT ERROR] offset larger than number of sectors\n"); 1520 1391 return -1; 1521 1392 } … … 1533 1404 1534 1405 #if GIET_DEBUG_FAT 1535 _tty_get_lock( 0 ); 1536 _puts("\n - first cluster = "); 1537 _putd( cluster ); 1538 _puts("\n - skiped clusters = "); 1539 _putd( clusters_to_skip ); 1540 _puts("\n"); 1541 _tty_release_lock( 0 ); 1406 _printf(" - first cluster = %x\n" 1407 " - skiped clusters = %x\n", 1408 cluster, clusters_to_skip ); 1542 1409 #endif 1543 1410 … … 1568 1435 1569 1436 #if GIET_DEBUG_FAT 1570 _tty_get_lock( 0 ); 1571 _puts("\n[FAT DEBUG] _fat_read() IOC request : buf = "); 1572 _putx( (unsigned int)dst ); 1573 _puts(" / lba = "); 1574 _putd( lba ); 1575 _puts(" / sectors = "); 1576 _putd( iter_sectors ); 1577 _puts("\n"); 1578 _tty_release_lock( 0 ); 1579 #endif 1580 1581 if( _ioc_read( mode, // mode for IOC driver 1437 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] makes an IOC read :" 1438 " buf = %x / lba = %x / sectors = %d\n", 1439 x, y, lpid, (unsigned int)dst, lba, iter_sectors ); 1440 #endif 1441 1442 if( _ioc_read( 0, // channel 1443 mode, // mode for IOC driver 1582 1444 lba, // first sector index 1583 1445 dst, // buffer address 1584 1446 iter_sectors ) ) // number of sectors 1585 1447 { 1586 _tty_get_lock( 0 ); 1587 _puts("\n[FAT ERROR] in _fat_read() cannot load block "); 1588 _putd( lba ); 1589 _puts("\n"); 1590 _tty_release_lock( 0 ); 1448 _printf("\n[FAT ERROR] in _fat_read() cannot load block %x\n", lba ); 1591 1449 return -1; 1592 1450 } … … 1653 1511 1654 1512 #if GIET_DEBUG_FAT 1655 _tty_get_lock( 0);1656 _puts("\n[FAT DEBUG] Enter _fat_write() for file ");1657 _puts( fat.fd[fd_id].name );1658 _puts("\n - buffer base = ");1659 _putx( (unsigned int)buffer);1660 _puts("\n - skipped sectors = "); 1661 _p utd( offset );1662 _puts("\n - write sectors = "); 1663 _putd( count ); 1664 _puts("\n - file size (sectors) = ");1665 _putd( file_sectors ); 1666 _puts("\n - need allocate = ");1667 allocate ? _puts( "True" ) : _puts( "False");1668 _tty_release_lock( 0);1513 unsigned int procid = _get_procid(); 1514 unsigned int cid = procid / NB_PROCS_MAX; 1515 unsigned int lpid = procid % NB_PROCS_MAX; 1516 unsigned int x = cid >> Y_WIDTH; 1517 unsigned int y = cid & ((1<<Y_WIDTH) - 1); 1518 1519 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] enters _fat_write() for file %s\n", 1520 " - buffer vbase = %x\n" 1521 " - skipped sectors = %x\n" 1522 " - write sectors = %x\n" 1523 " - file sectors = %x\n" 1524 " - need allocate = %d\n", 1525 x, y, lpid, fat.fd[fd_id].name, (unsigned int)buffer, 1526 offset, count, file_sectors, allocate ); 1669 1527 #endif 1670 1528 … … 1672 1530 if ( fd_id >= GIET_OPEN_FILES_MAX ) 1673 1531 { 1674 _tty_get_lock( 0 ); 1675 _puts("\n[FAT ERROR] in _fat_write() : illegal file descriptor index\n"); 1676 _tty_release_lock( 0 ); 1532 _printf("\n[FAT ERROR] in _fat_write() : illegal file descriptor index\n"); 1677 1533 return -1; 1678 1534 } 1679 1535 if ( fat.fd[fd_id].used != 1 ) 1680 1536 { 1681 _tty_get_lock( 0 ); 1682 _puts("\n[FAT ERROR] in _fat_write() : file not open\n"); 1683 _tty_release_lock( 0 ); 1537 _printf("\n[FAT ERROR] in _fat_write() : file not open\n"); 1684 1538 return -1; 1685 1539 } 1686 1540 if ( ((unsigned int)buffer & 0x1FF) != 0 ) 1687 1541 { 1688 _tty_get_lock( 0 ); 1689 _puts("\n[FAT ERROR] in _fat_write() : memory buffer not sector aligned\n"); 1690 _tty_release_lock( 0 ); 1542 _printf("\n[FAT ERROR] in _fat_write() : memory buffer not sector aligned\n"); 1691 1543 return -1; 1692 1544 } … … 1696 1548 if ( _fat_allocate( fd_id, (required_cluster - current_cluster) ) < 0 ) 1697 1549 { 1698 _tty_get_lock( 0 ); 1699 _puts("\n[FAT ERROR] in _fat_write() : fat_allocate for file "); 1700 _putd( fd_id ); 1701 _puts(" failed\n"); 1702 _tty_release_lock( 0 ); 1550 _printf("\n[FAT ERROR] in _fat_write() : fat_allocate failed\n"); 1703 1551 return -1; 1704 1552 } … … 1713 1561 1714 1562 #if GIET_DEBUG_FAT 1715 _tty_get_lock( 0 ); 1716 _puts("\n - first cluster = "); 1717 _putd( cluster ); 1718 _puts("\n - skiped clusters = "); 1719 _putd( clusters_to_skip ); 1720 _puts("\n"); 1721 _tty_release_lock( 0 ); 1563 _printf(" - first cluster = %x\n" 1564 " - skiped clusters = %x\n", 1565 cluster, clusters_to_skip ); 1722 1566 #endif 1723 1567 … … 1748 1592 1749 1593 #if GIET_DEBUG_FAT 1750 _tty_get_lock( 0 ); 1751 _puts("\n[FAT DEBUG] _fat_write() IOC request : buf = "); 1752 _putx( (unsigned int)src ); 1753 _puts(" / lba = "); 1754 _putd( lba ); 1755 _puts(" / sectors = "); 1756 _putd( iter_sectors ); 1757 _puts("\n"); 1758 _tty_release_lock( 0 ); 1759 #endif 1760 1761 if( _ioc_write( mode, // mode for IOC driver 1594 _printf("\n[FAT DEBUG] Processor[%d,%d,%d] makes an IOC write : " 1595 "buf = %x / lba = %x / sectors = %x\n", 1596 x, y, lpid, (unsigned int)src, lba, iter_sectors ); 1597 #endif 1598 1599 if( _ioc_write( 0, // channel 1600 mode, // mode for IOC driver 1762 1601 lba, // first sector index 1763 src, // buffer address1602 src, // source buffer address 1764 1603 iter_sectors ) ) // number of sectors 1765 1604 { 1766 _tty_get_lock( 0 ); 1767 _puts("\n[FAT ERROR] in _fat_write() cannot write block "); 1768 _putd( lba ); 1769 _puts("\n"); 1770 _tty_release_lock( 0 ); 1605 _printf("\n[FAT ERROR] in _fat_write() cannot write block %x\n", lba ); 1771 1606 return -1; 1772 1607 } … … 1792 1627 if ( update_entry(fd_id, DIR_FILE_SIZE, fat.fd[fd_id].file_size) ) 1793 1628 { 1794 _tty_get_lock( 0 ); 1795 _puts("\n[FAT ERROR] in _fat_write() update entry for file "); 1796 _putd( fd_id ); 1797 _puts(" failed\n"); 1798 _tty_release_lock( 0 ); 1629 _printf("\n[FAT ERROR] in _fat_write() update entry failed\n"); 1799 1630 return -1; 1800 1631 } … … 1826 1657 else 1827 1658 { 1828 _tty_get_lock( 0 ); 1829 _puts("\n[FAT ERROR] in _fat_fstat() : illegal file descriptor index\n"); 1830 _tty_release_lock( 0 ); 1659 _printf("\n[FAT ERROR] in _fat_fstat() : illegal file descriptor index\n"); 1831 1660 return -1; 1832 1661 } … … 1847 1676 else 1848 1677 { 1849 _tty_get_lock( 0 ); 1850 _puts("\n[FAT ERROR] in _fat_close() : illegal file descriptor index\n"); 1851 _tty_release_lock( 0 ); 1678 _printf("\n[FAT ERROR] in _fat_close() : illegal file descriptor index\n"); 1852 1679 return -1; 1853 1680 } … … 1863 1690 unsigned int flags ) // unused: TODO 1864 1691 { 1865 return _fat_open( IOC_KERNEL_MODE, // we KERNEL_MODE, because1692 return _fat_open( IOC_KERNEL_MODE, // we use KERNEL_MODE, because 1866 1693 pathname, // we need to write into FAT cache 1867 0 ); 1694 0 ); // no creation if not found 1868 1695 } 1869 1696 … … 1909 1736 unsigned int whence ) 1910 1737 { 1911 _tty_get_lock( 0 ); 1912 _puts("[GIET ERROR] _fat_user_lseek function not implemented\n"); 1913 _tty_release_lock( 0 ); 1738 _printf("[GIET ERROR] _fat_user_lseek() not implemented\n"); 1914 1739 _exit(); 1915 1740 return 0; -
soft/giet_vm/giet_fat32/fat32.h
r291 r295 143 143 unsigned int cluster_size; // sector_size * sector_per_cluster (bytes) 144 144 unsigned int fat_sectors; // number of sectors occupied by one FAT copy 145 unsigned int partition_sectors; // total number of sectors (RESVD + FAT +DATA)145 unsigned int partition_sectors; // total number of sectors (RESVD+FAT+DATA) 146 146 unsigned int partition_lba; // lba of first partiton sector 147 147 unsigned int data_lba; // lba of first data sector … … 150 150 unsigned int number_free_cluster; // number of free clusters 151 151 unsigned int fs_info_lba; // lba of fs_info 152 unsigned int lock; // lock protecting exclusive access 152 153 } fat32_fs_t; 153 154 /***************************************************************************************/
Note: See TracChangeset
for help on using the changeset viewer.