Changeset 300 for soft/giet_vm/giet_fat32/fat32.c
- Timestamp:
- Apr 10, 2014, 2:33:56 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r295 r300 6 6 ////////////////////////////////////////////////////////////////////////////////// 7 7 // The fat32.h and fat32.c files define a library of access functions 8 // to a FAT32 partitionon a block device. It is intended to be used8 // 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 10 // This code uses functions defined in the utils.c and drivers.c files. … … 175 175 ///////////////////////////////////////////////////////////////////////////////// 176 176 // This function search the FAT (using the FAT cache), and returns 177 // the next cluster index from the cur ent cluster index in the FAT.177 // the next cluster index from the current cluster index in the FAT. 178 178 // remark: a sector of FAT contains 128 cluster indexes. 179 179 ///////////////////////////////////////////////////////////////////////////////// … … 182 182 { 183 183 // compute lba of the sector containing the cluster index 184 unsigned int lba = fat. partition_lba + 32+ (cluster / 128);184 unsigned int lba = fat.fat_lba + (cluster / 128); 185 185 186 186 if ( lba == fat.cache_lba ) // hit in cache … … 666 666 unsigned int value ) 667 667 { 668 unsigned int lba = fat. partition_lba + 32+ (cluster / 128);668 unsigned int lba = fat.fat_lba + (cluster / 128); 669 669 670 670 #if GIET_DEBUG_FAT … … 818 818 819 819 #if GIET_DEBUG_FAT 820 _printf("\n[FAT DEBUG] enter _scan_directory() searching dir/file %s", file name );820 _printf("\n[FAT DEBUG] enter _scan_directory() searching dir/file %s", file_name ); 821 821 #endif 822 822 … … 1030 1030 x, y, lpid ); 1031 1031 #endif 1032 1033 // load Master Boot Record (sector 0) into fat cache1034 if ( _ioc_read( 0, // channel1035 mode, // mode for IOC driver1036 0, // sector index1037 fat.fat_cache, // buffer address1038 1 ) ) // one sector1039 {1040 _printf("\n[FAT ERROR] in _fat_init() cannot load Boot Sector\n");1041 return -1;1042 }1043 fat.cache_lba = 0;1044 1032 1045 #if GIET_DEBUG_FAT 1046 display_fat_cache(); 1047 #endif 1048 1049 // checking Boot sector integrity 1050 if( MBR_SIGNATURE_VALUE != read_entry( MBR_SIGNATURE_POSITION, fat.fat_cache, 1)) 1051 { 1052 _printf("\n[FAT ERROR] Boot sector not recognized or corrupt \n"); 1053 return -1; 1054 } 1055 1056 #if GIET_DEBUG_FAT 1057 _printf("\n[FAT DEBUG] Boot Sector Loaded\n"); 1058 #endif 1059 1060 // initialise fat descriptor from Boot sector 1061 fat.partition_lba = read_entry( FIRST_PARTITION_BEGIN_LBA, fat.fat_cache, 1 ); 1062 fat.partition_sectors = read_entry( FIRST_PARTITION_SIZE, fat.fat_cache, 1 ); 1063 1064 // load Partition Boot Record (first partition sector) into fat cache 1033 // load Boot Record (VBR) into fat cache 1065 1034 if ( _ioc_read( 0, // channel 1066 1035 mode, // mode for IOC driver 1067 fat.partition_lba,// sector index1036 0, // sector index 1068 1037 fat.fat_cache, // buffer address 1069 1038 1 ) ) // one sector 1070 1039 { 1071 _printf("\n[FAT ERROR] in _fat_init() cannot load block %x\n", fat.partition_lba);1040 _printf("\n[FAT ERROR] in _fat_init() cannot load VBR\n"); 1072 1041 return -1; 1073 1042 } 1074 fat.cache_lba = fat.partition_lba; 1075 1076 #if GIET_DEBUG_FAT 1077 _printf("\n[FAT DEBUG] Partition First Sector Loaded\n"); 1078 #endif 1079 1043 fat.cache_lba = 0; 1044 1045 #if GIET_DEBUG_FAT 1046 _printf("\n[FAT DEBUG] Boot Sector Loaded\n"); 1047 #endif 1080 1048 1081 1049 // checking various FAT32 assuptions from boot sector … … 1085 1053 return -1; 1086 1054 } 1087 if( read_entry( BPB_RSVDSECCNT, fat.fat_cache, 1 ) != 32 )1088 {1089 _printf("\n[FAT ERROR] The RSVD region in FAT32 must be 32 sectors\n");1090 return -1;1091 }1092 1055 if( read_entry( BPB_NUMFATS, fat.fat_cache, 1 ) != 1 ) 1093 1056 { … … 1105 1068 return -1; 1106 1069 } 1107 fat.fs_info_lba = read_entry( BPB_FAT32_FSINFO, fat.fat_cache, 1 ) + fat.partition_lba; 1108 1109 // initialise fat descriptor from partition first sector 1070 // FS Info always in sector 1 1071 fat.fs_info_lba = read_entry( BPB_FAT32_FSINFO, fat.fat_cache, 1 ); 1072 1073 // initialise fat descriptor from VBR 1110 1074 fat.sectors_per_cluster = read_entry( BPB_SECPERCLUS, fat.fat_cache, 1 ); 1111 1075 fat.sector_size = read_entry( BPB_BYTSPERSEC, fat.fat_cache, 1 ); 1112 1076 fat.cluster_size = fat.sectors_per_cluster * 512; 1113 1077 fat.fat_sectors = read_entry( BPB_FAT32_FATSZ32, fat.fat_cache, 1 ); 1114 fat.data_lba = 32 + fat.fat_sectors + fat.partition_lba; 1078 fat.fat_lba = read_entry( BPB_RSVDSECCNT, fat.fat_cache, 1 ); 1079 fat.data_lba = fat.fat_lba + fat.fat_sectors; 1115 1080 fat.initialised = FAT_INITIALISED; 1116 1081 … … 1153 1118 _printf("\nSector Size (bytes) %x", fat.sector_size ); 1154 1119 _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 ); 1120 _printf("\nFAT region first lba %x", fat.fat_lba ); 1157 1121 _printf("\nData region first lba %x", fat.data_lba ); 1158 1122 _printf("\nNumber of sectors for one FAT %x", fat.fat_sectors );
Note: See TracChangeset
for help on using the changeset viewer.