Changeset 458
- Timestamp:
- Dec 5, 2014, 3:48:29 PM (10 years ago)
- Location:
- soft/giet_vm/giet_fat32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r443 r458 23 23 #include <giet_config.h> 24 24 #include <fat32.h> 25 #include <tty _driver.h>25 #include <tty0.h> 26 26 #include <ioc_driver.h> 27 27 #include <utils.h> … … 725 725 if ( _get_next_cluster( IOC_KERNEL_MODE, free_cluster ) != FREE_CLUSTER) 726 726 { 727 _puts("\n[FAT ERROR] in _fat_allocate() : first free _cluster not free\n");727 _puts("\n[FAT ERROR] in _fat_allocate() : first free cluster not free\n"); 728 728 return -1; 729 729 } … … 755 755 _putx( last_cluster_file ); 756 756 _puts(" / free cluster = "); 757 _putx( free -cluster );757 _putx( free_cluster ); 758 758 _puts(" / clusters required = "); 759 _putx( cluster_to 759 _putx( cluster_to_allocate ); 760 760 _puts("\n"); 761 761 #endif … … 853 853 _puts(","); 854 854 _putd( p ); 855 _puts("] enters for ") 855 _puts("] enters for "); 856 856 _puts( file_name ); 857 857 _puts(" / is_sfn = "); … … 1018 1018 _puts(" / cluster = "); 1019 1019 _putx( searched_cluster ); 1020 _puts("\n") 1020 _puts("\n"); 1021 1021 #endif 1022 1022 … … 1044 1044 1045 1045 ////////////////////////////////////////////////////////////////////////// 1046 // This function initializes the FAT structure, including the 1047 // files descriptors array, from informations found in the boot record. 1046 // This function initializes the FAT structure, including the open 1047 // files descriptors array and the lock protecting the FAT, 1048 // from informations found in the boot record. 1049 // This should be done only once. 1048 1050 ////////////////////////////////////////////////////////////////////////// 1049 1051 // Return 0 if success, Return -1 if failure … … 1065 1067 _puts(","); 1066 1068 _putd( p ); 1067 _puts("] enters"); 1068 if ( mode == IOC_BOOT_MODE ) _puts(" / IOC_BOOT_MODE\n"); 1069 if ( mode == IOC_KERNEL_MODE ) _puts(" / IOC_KERNEL_MODE\n"); 1070 if ( mode == IOC_USER_MODE ) _puts(" / IOC_USER_MODE\n"); 1071 #endif 1072 1069 _puts("] enters _fat_init()"); 1070 if ( mode == IOC_BOOT_MODE ) _puts(" in BOOT_MODE\n"); 1071 if ( mode == IOC_KERNEL_MODE ) _puts(" in KERNEL_MODE\n"); 1072 if ( mode == IOC_USER_MODE ) _puts(" in USER_MODE\n"); 1073 #endif 1074 1075 // FAT initialisation should be done only once 1076 if ( fat.initialised == FAT_INITIALISED ) 1077 { 1078 _puts("\n[FAT WARNING] Strange initialisation of a FAT already initialised...\n"); 1079 return 0; 1080 } 1081 1073 1082 // load Boot Record (VBR) into fat cache 1074 1083 if ( _ioc_read( 0, // channel … … 1118 1127 fat.fat_lba = _read_entry( BPB_RSVDSECCNT, fat.fat_cache, 1 ); 1119 1128 fat.data_lba = fat.fat_lba + fat.fat_sectors; 1120 fat.fat_lock.value = 0;1121 1129 fat.initialised = FAT_INITIALISED; 1130 1131 // initalise the lock protecting the FAT 1132 _lock_init( &fat.fat_lock ); 1122 1133 1123 1134 // initialise file descriptor array … … 1148 1159 #if GIET_DEBUG_FAT 1149 1160 _fat_print(); 1150 _puts("\n[FAT DEBUG] _fat_init() :P[");1161 _puts("\n[FAT DEBUG] P["); 1151 1162 _putd( x ); 1152 1163 _puts(","); … … 1154 1165 _puts(","); 1155 1166 _putd( p ); 1156 _puts("] exit \n");1167 _puts("] exit _fat_init()\n"); 1157 1168 #endif 1158 1169 … … 1177 1188 /////////////////////////////////////////////////////////////////////////////// 1178 1189 // This function checks that the kernel FAT structure has been initialised. 1179 // It makes the FAT initialisation if it is the first open request. 1180 // This function searches a file identified by the "pathname" argument. 1190 // It searches a file identified by the "pathname" argument. 1181 1191 // It starts from root (cluster 2) to scan successively each subdirectory. 1182 1192 // When the file is not found, but the path is found, and "creat" is set, … … 1206 1216 unsigned int p = procid & ((1<<P_WIDTH)-1); 1207 1217 1218 _puts("\n[FAT DEBUG] P["); 1219 _putd( x ); 1220 _puts(","); 1221 _putd( y ); 1222 _puts(","); 1223 _putd( p ); 1224 _puts("] enters _fat_open() for path "); 1225 _puts( pathname ); 1226 _puts("\n"); 1227 #endif 1228 1229 // checking creat argument 1230 if ( creat ) 1231 { 1232 _puts("[FAT ERROR] in _fat_open() : create not supported yet\n"); 1233 return -1; 1234 } 1235 1236 // checking FAT initialised 1237 if( fat.initialised != FAT_INITIALISED ) 1238 { 1239 _puts("[FAT ERROR] in _fat_open() : FAT not initialised\n"); 1240 return -1; 1241 } 1242 // takes the FAT lock for exclusive access 1243 _lock_acquire( &fat.fat_lock ); 1244 1245 #if GIET_DEBUG_FAT 1208 1246 _puts("\n[FAT DEBUG] _fat_open() : P["); 1209 1247 _putd( x ); … … 1212 1250 _puts(","); 1213 1251 _putd( p ); 1214 _puts("] enters for path ");1215 _puts( pathname );1216 _puts("\n");1217 #endif1218 1219 // checking arguments1220 if ( creat )1221 {1222 _puts("[FAT ERROR] in _fat_open() : create not supported yet\n");1223 return -1;1224 }1225 1226 // takes the FAT lock for exclusive access1227 _get_lock( &fat.fat_lock );1228 1229 #if GIET_DEBUG_FAT1230 _puts("\n[FAT DEBUG] _fat_open() : P[");1231 _putd( x );1232 _puts(",");1233 _putd( y );1234 _puts(",");1235 _putd( p );1236 1252 _puts("] takes the FAT lock\n"); 1237 1253 #endif 1238 1239 // FAT initialisation if required1240 if( fat.initialised != FAT_INITIALISED )1241 {1242 if ( _fat_init( mode ) )1243 {1244 _puts("[FAT ERROR] in _fat_open() : Cannot initialize FAT descriptor\n");1245 _release_lock( &fat.fat_lock );1246 return -1;1247 }1248 }1249 1254 1250 1255 // Scan the directories, starting from the root directory (cluster 2) … … 1291 1296 _puts( name ); 1292 1297 _puts("\n"); 1293 _ release_lock( &fat.fat_lock );1298 _lock_release( &fat.fat_lock ); 1294 1299 return -1; 1295 1300 } … … 1346 1351 1347 1352 // release FAT lock 1348 _ release_lock( &fat.fat_lock );1353 _lock_release( &fat.fat_lock ); 1349 1354 1350 1355 return fd_id; … … 1355 1360 _puts( pathname ); 1356 1361 _puts(" : fd array full\n"); 1357 _ release_lock( &fat.fat_lock );1362 _lock_release( &fat.fat_lock ); 1358 1363 return -1; 1359 1364 } … … 1364 1369 _puts( pathname ); 1365 1370 _puts(" : bad cluster\n"); 1366 _ release_lock( &fat.fat_lock );1371 _lock_release( &fat.fat_lock ); 1367 1372 return -1; 1368 1373 } -
soft/giet_vm/giet_fat32/fat32.h
r354 r458 10 10 11 11 #include "giet_config.h" 12 #include " utils.h"12 #include "locks.h" 13 13 14 14 /*************** Partition Boot Sector Format ******************************************/ … … 138 138 { 139 139 char fat_cache[512]; // FAT cache: 1 sector = 128 cluster indexes 140 giet_lock_t fat_lock; // lock protecting exclusive access140 spin_lock_t fat_lock; // lock protecting exclusive access 141 141 file_desc_t fd[GIET_OPEN_FILES_MAX]; // file descriptors array 142 142 unsigned int initialised; // contains 0xBABEF00D when FAT initialised
Note: See TracChangeset
for help on using the changeset viewer.