- Timestamp:
- Mar 17, 2016, 12:34:40 PM (9 years ago)
- Location:
- soft/giet_vm/giet_fat32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r798 r807 576 576 fat_cache_desc_t* pdesc; 577 577 unsigned int* buffer; 578 if ( _get_fat_cache_buffer( cluster_id, 579 &pdesc ) ) return 1; 578 if ( _get_fat_cache_buffer( cluster_id, &pdesc ) ) return 1; 580 579 581 580 // get value from FAT slot … … 600 599 fat_cache_desc_t* pdesc; 601 600 unsigned int* buffer; 602 if ( _get_fat_cache_buffer( cluster_id, 603 &pdesc ) ) return 1; 601 if ( _get_fat_cache_buffer( cluster_id, &pdesc ) ) return 1; 604 602 605 603 // set value into FAT slot … … 792 790 if ( pdesc != NULL ) 793 791 { 794 // check dirty795 if ( pdesc->dirty )796 _printf("\n[FAT ERROR] _release_cache_memory(): dirty cluster\n");797 798 792 _free( pdesc->buffer ); 799 793 _free( pdesc ); … … 848 842 { 849 843 // get next cluster 850 if ( _get_fat_entry( current , &next ) ) 851 { 852 _printf("\n[FAT ERROR] in _one_cluster_allocate() scanning FAT\n"); 853 return 1; 854 } 844 if ( _get_fat_entry( current , &next ) ) return 1; 855 845 856 846 // increment number of allocated clusters … … 875 865 876 866 // update allocated FAT slot 877 if ( _set_fat_entry( new , END_OF_CHAIN_CLUSTER_MAX ) ) 878 { 879 _printf("\n[FAT ERROR] in _one_cluster_allocate() accessing FAT\n"); 880 return 1; 881 } 867 if ( _set_fat_entry( new , END_OF_CHAIN_CLUSTER_MAX ) ) return 1; 882 868 883 869 // update FAT descriptor global variables … … 892 878 else // not the last : update previous last cluster in FAT 893 879 { 894 if ( _set_fat_entry( last , new ) ) 895 { 896 _printf("\n[FAT ERROR] in _one_cluster_allocate() accessing FAT\n"); 897 return 1; 898 } 880 if ( _set_fat_entry( last , new ) ) return 1; 899 881 } 900 882 … … 936 918 // get next cluster 937 919 unsigned int next; 938 if ( _get_fat_entry( cluster , &next ) ) 939 { 940 _printf("\n[FAT ERROR] in _cluster_release() scanning Fat-Cache" 941 " for cluster %x\n", cluster ); 942 return 1; 943 } 920 if ( _get_fat_entry( cluster , &next ) ) return 1; 944 921 945 922 // call _cluster_release() on next cluster 946 923 if ( _cluster_release( next ) ) return 1; 924 925 // release cluster 926 if ( _set_fat_entry( cluster , FREE_CLUSTER ) ) return 1; 927 928 // Update free_cluster _hint and free_clusters_number in FAT descriptor 929 _fat.free_clusters_number++; 930 if ( cluster < _fat.free_cluster_hint ) _fat.free_cluster_hint = cluster; 947 931 } 948 932 949 // In both cases (terminal or not) release cluster 950 if ( _set_fat_entry( cluster , FREE_CLUSTER ) ) 951 { 952 _printf("\n[FAT ERROR] in _cluster_release() updating Fat-Cache" 953 " for cluster %x\n", cluster ); 954 return 1; 955 } 956 957 // Update free_cluster _hint and free_clusters_number in FAT descriptor 958 _fat.free_clusters_number++; 959 if ( cluster < _fat.free_cluster_hint ) _fat.free_cluster_hint = cluster; 933 // do nothing if terminal case : cluster == END_OF_CHAIN 960 934 961 935 return 0; … … 2425 2399 2426 2400 //////////////////////////////////////////////////////////////////// 2427 int _fat_open( char* pathname, // absolute path from root2428 unsigned int flags ) // O_CREAT and O_RDONLY2401 int _fat_open( char* pathname, // absolute path from root 2402 unsigned int flags ) // O_CREAT / O_RDONLY / O_TRUNC 2429 2403 { 2430 2404 unsigned int fd_id; // index in File-Descriptor-Array … … 2438 2412 unsigned int read_only = ((flags & O_RDONLY) != 0); 2439 2413 unsigned int truncate = ((flags & O_TRUNC) != 0); 2414 unsigned int append = ((flags & O_APPEND) != 0); 2440 2415 2441 2416 #if GIET_DEBUG_FAT … … 2604 2579 } 2605 2580 2606 // set file descriptorif an empty slot has been found2581 // check if an empty slot has been found 2607 2582 if ( fd_id >= GIET_OPEN_FILES_MAX ) 2608 2583 { … … 2614 2589 } 2615 2590 2591 // truncate the file if requested 2592 if ( truncate && !read_only && !child->is_dir && child->size != 0 ) 2593 { 2594 // release File-Cache (keep root node) 2595 _release_cache_memory( child->cache, child->levels ); 2596 2597 // release clusters allocated to file/dir in DATA region 2598 if ( _all_clusters_release( child ) ) 2599 { 2600 _spin_lock_release( &_fat.fat_lock ); 2601 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2602 2603 _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n"); 2604 return GIET_FAT32_IO_ERROR; 2605 } 2606 2607 // update parent directory entry (size and cluster index) 2608 if ( _update_dir_entry( child ) ) 2609 { 2610 _spin_lock_release( &_fat.fat_lock ); 2611 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT ); 2612 2613 _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n"); 2614 return GIET_FAT32_IO_ERROR; 2615 } 2616 2617 // update inode 2618 child->size = 0; 2619 child->levels = 1; 2620 } 2621 2616 2622 // update file descriptor 2617 2623 _fat.fd[fd_id].allocated = 1; 2618 _fat.fd[fd_id].seek = 0;2619 2624 _fat.fd[fd_id].read_only = read_only; 2620 2625 _fat.fd[fd_id].inode = child; 2626 _fat.fd[fd_id].seek = ( append ) ? child->size : 0; 2621 2627 2622 2628 // increment the refcount 2623 2629 child->count = child->count + 1; 2624 2625 // truncate the file if requested2626 if ( truncate && !read_only && !child->is_dir && child->size != 0 )2627 {2628 // empty file2629 child->size = 0;2630 child->levels = _get_levels_from_size( child->size );2631 2632 // release File-Cache (keep root node)2633 _release_cache_memory( child->cache, child->levels );2634 2635 // release clusters allocated to file/dir in DATA region2636 if ( _all_clusters_release( child ) )2637 {2638 _spin_lock_release( &_fat.fat_lock );2639 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );2640 2641 _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n");2642 return GIET_FAT32_IO_ERROR;2643 }2644 2645 // update parent directory entry (size and cluster index)2646 if ( _update_dir_entry( child ) )2647 {2648 _spin_lock_release( &_fat.fat_lock );2649 _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );2650 2651 _printf("\n[FAT ERROR] _fat_open(): can't truncate file\n");2652 return GIET_FAT32_IO_ERROR;2653 }2654 }2655 2630 2656 2631 #if GIET_DEBUG_FAT … … 4120 4095 { 4121 4096 _printf("\n[FAT ERROR] in _get_fat_cache_buffer() : " 4122 "cluster_id %d too large ", cluster_id );4097 "cluster_id %d too large\n", cluster_id ); 4123 4098 return GIET_FAT32_IO_ERROR; 4124 4099 } -
soft/giet_vm/giet_fat32/fat32_shared.h
r773 r807 39 39 #define O_TRUNC 0x10 40 40 #define O_CREAT 0x20 41 #define O_APPEND 0x40 41 42 42 43 /********************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.