Changeset 654 for soft/giet_vm/giet_fat32/fat32.c
- Timestamp:
- Jul 22, 2015, 2:31:34 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_fat32/fat32.c
r653 r654 2800 2800 // -8 : "Cannot update FS_INFO sector" 2801 2801 // -9 : "file descriptor array full" 2802 // -10 : "cannot truncate file" 2802 2803 /////////////////////////////////////////////////////////////////////////////// 2803 2804 int _fat_open( char* pathname, // absolute path from root … … 2812 2813 // get flags 2813 2814 unsigned int create = ((flags & O_CREATE) != 0); 2814 unsigned int read_only = ((flags & O_RDONLY) != 0); 2815 unsigned int read_only = ((flags & O_RDONLY) != 0); 2816 unsigned int truncate = ((flags & O_TRUNC) != 0); 2815 2817 2816 2818 #if GIET_DEBUG_FAT … … 2925 2927 return -8; 2926 2928 } 2929 2930 // no need to truncate a new file 2931 truncate = 0; 2927 2932 } 2928 2933 else // code == 0 … … 2936 2941 x , y , p , pathname , child ); 2937 2942 #endif 2938 2939 2943 } 2940 2944 … … 2947 2951 2948 2952 // set file descriptor if an empty slot has been found 2949 if ( fd_id < GIET_OPEN_FILES_MAX ) 2950 { 2951 // update file descriptor 2952 _fat.fd[fd_id].allocated = 1; 2953 _fat.fd[fd_id].seek = 0; 2954 _fat.fd[fd_id].read_only = read_only; 2955 _fat.fd[fd_id].inode = child; 2956 2957 // increment the refcount 2958 child->count = child->count + 1; 2959 2960 // releases the lock 2953 if ( fd_id >= GIET_OPEN_FILES_MAX ) 2954 { 2961 2955 _spin_lock_release( &_fat.fat_lock ); 2956 _printf("\n[FAT ERROR] in _fat_open() : File-Descriptors-Array full\n"); 2957 return -9; 2958 } 2959 2960 // update file descriptor 2961 _fat.fd[fd_id].allocated = 1; 2962 _fat.fd[fd_id].seek = 0; 2963 _fat.fd[fd_id].read_only = read_only; 2964 _fat.fd[fd_id].inode = child; 2965 2966 // increment the refcount 2967 child->count = child->count + 1; 2968 2969 // truncate the file if requested 2970 if ( truncate && !read_only && !child->is_dir ) 2971 { 2972 // empty file 2973 child->size = 0; 2974 child->levels = _get_levels_from_size( child->size ); 2975 2976 // release File-Cache (keep root node) 2977 _release_cache_memory( child->cache, child->levels ); 2978 2979 // release clusters allocated to file/dir in DATA region 2980 if ( _clusters_release( child->cluster ) ) 2981 { 2982 _spin_lock_release( &_fat.fat_lock ); 2983 _printf("\n[FAT ERROR] in _fat_open() : can't truncate file\n"); 2984 return -10; 2985 } 2986 2987 // update parent directory entry (size and cluster index) 2988 if ( _update_dir_entry( child ) ) 2989 { 2990 _spin_lock_release( &_fat.fat_lock ); 2991 _printf("\n[FAT ERROR] in _fat_open() : can't truncate file\n"); 2992 return -10; 2993 } 2994 } 2995 2996 // releases the lock 2997 _spin_lock_release( &_fat.fat_lock ); 2962 2998 2963 2999 #if GIET_DEBUG_FAT … … 2967 3003 x , y , p , fd_id , pathname , read_only ); 2968 3004 #endif 2969 return fd_id; 2970 } 2971 else 2972 { 2973 _spin_lock_release( &_fat.fat_lock ); 2974 _printf("\n[FAT ERROR] in _fat_open() : File-Descriptors-Array full\n"); 2975 return -9; 2976 } 3005 return fd_id; 2977 3006 } // end _fat_open() 2978 3007 … … 3394 3423 } 3395 3424 3396 // update parent directory entry (size an cluster index)3425 // update parent directory entry (size and cluster index) 3397 3426 if ( _update_dir_entry( inode ) ) 3398 3427 {
Note: See TracChangeset
for help on using the changeset viewer.