Changeset 651 for soft/giet_vm/giet_fat32
- Timestamp:
- Jul 22, 2015, 2:31:33 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r650 r651 407 407 408 408 ////////////////////////////////////////////////////////////////////////////////// 409 // This recursive function scan one File-Cache (or Fat-Cache) from root to leaves.410 // The cache 64-Tree infrastructure is kept, but all memory allocated for 4 Kbytes411 // buffers, and for buffer descriptors (in leaves) is released.412 // The cache is identified by the "root" an "levels" arguments.409 // This recursive function scans one File-Cache (or Fat-Cache) from root to 410 // leaves. All memory allocated for 4KB buffers, and buffer descriptors (in 411 // leaves) is released, along with the 64-Tree structure (root node is kept). 412 // The cache is identified by the "root" and "levels" arguments. 413 413 // It should not contain any dirty clusters. 414 // It returns 0 if success. 415 // It returns 1 if error. 416 ////////////////////////////////////////////////////////////////////////////////// 417 418 static unsigned int _release_cache_memory( fat_cache_node_t* root, 419 unsigned int levels ); 414 ////////////////////////////////////////////////////////////////////////////////// 415 416 static void _release_cache_memory( fat_cache_node_t* root, 417 unsigned int levels ); 420 418 421 419 ////////////////////////////////////////////////////////////////////////////////// … … 1397 1395 1398 1396 /////////////////////////////////////////////////////////////////// 1399 static unsigned int _release_cache_memory( fat_cache_node_t* root, 1400 unsigned int levels ) 1401 { 1402 unsigned int index; 1403 unsigned int ret = 0; 1397 static void _release_cache_memory( fat_cache_node_t* root, 1398 unsigned int levels ) 1399 { 1400 unsigned int i; 1404 1401 1405 1402 if ( levels == 1 ) // last level => children are cluster descriptors 1406 1403 { 1407 for( i ndex = 0 ; index < 64 ; index++ )1404 for( i = 0 ; i < 64 ; i++ ) 1408 1405 { 1409 fat_cache_desc_t* pdesc = root->children[i ndex];1406 fat_cache_desc_t* pdesc = root->children[i]; 1410 1407 1411 1408 if ( pdesc != NULL ) … … 1413 1410 // check dirty 1414 1411 if ( pdesc->dirty ) 1415 { 1416 _printf("\n[FAT_ERROR] in _release_cache_memory() : dirty cluster\n"); 1417 ret = 1; 1418 } 1419 else 1420 { 1421 _free( pdesc->buffer ); 1422 _free( pdesc ); 1423 root->children[index] = NULL; 1424 } 1412 _printf("\n[FAT ERROR] in _release_cache_memory() : dirty cluster\n"); 1413 1414 _free( pdesc->buffer ); 1415 _free( pdesc ); 1416 root->children[i] = NULL; 1425 1417 } 1426 1418 } … … 1428 1420 else // not the last level = recursive call on each children 1429 1421 { 1430 for( i ndex = 0 ; index < 64 ; index++ )1422 for( i = 0 ; i < 64 ; i++ ) 1431 1423 { 1432 fat_cache_node_t* cnode = root->children[index]; 1433 1434 if ( cnode != NULL ) ret = _release_cache_memory( root->children[index], 1435 levels - 1 ); 1436 } 1437 } 1438 return ret; 1424 fat_cache_node_t* cnode = root->children[i]; 1425 1426 if ( cnode != NULL ) 1427 { 1428 _release_cache_memory( cnode, levels - 1 ); 1429 _free( cnode ); 1430 root->children[i] = NULL; 1431 } 1432 } 1433 } 1439 1434 } // end _release_cache_memory() 1440 1435 … … 2400 2395 2401 2396 // release File-Cache 2402 if ( _release_cache_memory( inode->cache,2403 inode->levels ) ) return 1;2397 _release_cache_memory( inode->cache, inode->levels ); 2398 _free ( inode->cache ); 2404 2399 2405 2400 // remove inode from Inode-Tree … … 3005 3000 // in the file descriptors array. 3006 3001 // If the reference count is zero, it writes all dirty clusters on block device, 3007 // and releases the memory allocated to the file_cache: The cache 64-Tree 3008 // infrastructure (depending on file size) is kept, but all buffers and all 3009 // buffer descriptors are released. 3002 // and releases the memory allocated to the File_Cache. 3010 3003 ///////////////////////////////////////////////////////////////////////////////// 3011 3004 // Returns 0 on success. … … 3015 3008 // -3 : "File not open" 3016 3009 // -4 : "Cannot update DATA regions" 3017 // -5 : "Cannot release memory"3018 3010 ///////////////////////////////////////////////////////////////////////////////// 3019 3011 int _fat_close( unsigned int fd_id ) … … 3091 3083 #endif 3092 3084 3093 // release memory allocated to File-Cache 3094 if ( _release_cache_memory( inode->cache, 3095 inode-> levels ) ) 3096 { 3097 _spin_lock_release( &_fat.fat_lock ); 3098 _printf("\n[FAT ERROR] in _fat_close() : cannot release cache memory " 3099 "for file <%s>\n", _fat.fd[fd_id].inode->name ); 3100 return -5; 3101 } 3085 // release memory allocated to File-Cache (keep cache root node) 3086 _release_cache_memory( inode->cache, inode->levels ); 3102 3087 3103 3088 #if GIET_DEBUG_FAT
Note: See TracChangeset
for help on using the changeset viewer.