Changeset 807 for soft


Ignore:
Timestamp:
Mar 17, 2016, 12:34:40 PM (8 years ago)
Author:
alain
Message:

Fix a bug in the O_TRUNC flag used by the giet_fat_open() system call.
Introduce support for the O_APPEND flag for the same system call.

Location:
soft/giet_vm/giet_fat32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_fat32/fat32.c

    r798 r807  
    576576    fat_cache_desc_t*  pdesc;
    577577    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;
    580579
    581580    // get value from FAT slot
     
    600599    fat_cache_desc_t*  pdesc;
    601600    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;           
    604602
    605603    // set value into FAT slot
     
    792790            if ( pdesc != NULL )
    793791            {
    794                 // check dirty
    795                 if ( pdesc->dirty )
    796                     _printf("\n[FAT ERROR] _release_cache_memory(): dirty cluster\n");
    797 
    798792                _free( pdesc->buffer );
    799793                _free( pdesc );
     
    848842    {
    849843        // 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;
    855845       
    856846        // increment number of allocated clusters
     
    875865
    876866    // 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;
    882868
    883869    // update FAT descriptor global variables
     
    892878    else                             // not the last : update previous last cluster in FAT
    893879    {
    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;
    899881    }
    900882
     
    936918        // get next cluster
    937919        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;
    944921
    945922        // call _cluster_release() on next cluster
    946923        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;
    947931    }       
    948932
    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
    960934
    961935    return 0;
     
    24252399
    24262400////////////////////////////////////////////////////////////////////
    2427 int _fat_open( char*        pathname,     // absolute path from root
    2428                unsigned int flags )       // O_CREAT and O_RDONLY
     2401int _fat_open( char*        pathname,      // absolute path from root
     2402               unsigned int flags )        // O_CREAT / O_RDONLY / O_TRUNC
    24292403{
    24302404    unsigned int         fd_id;            // index in File-Descriptor-Array
     
    24382412    unsigned int read_only = ((flags & O_RDONLY) != 0);
    24392413    unsigned int truncate  = ((flags & O_TRUNC)  != 0);
     2414    unsigned int append    = ((flags & O_APPEND) != 0);
    24402415
    24412416#if GIET_DEBUG_FAT
     
    26042579    }
    26052580
    2606     // set file descriptor if an empty slot has been found
     2581    // check if an empty slot has been found
    26072582    if ( fd_id >= GIET_OPEN_FILES_MAX )
    26082583    {
     
    26142589    }
    26152590
     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
    26162622    // update file descriptor
    26172623    _fat.fd[fd_id].allocated  = 1;
    2618     _fat.fd[fd_id].seek       = 0;
    26192624    _fat.fd[fd_id].read_only  = read_only;
    26202625    _fat.fd[fd_id].inode      = child;
     2626    _fat.fd[fd_id].seek       = ( append ) ? child->size : 0;
    26212627
    26222628    // increment the refcount
    26232629    child->count = child->count + 1;
    2624 
    2625     // truncate the file if requested
    2626     if ( truncate && !read_only && !child->is_dir && child->size != 0 )
    2627     {
    2628         // empty file
    2629         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 region
    2636         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     }
    26552630
    26562631#if GIET_DEBUG_FAT
     
    41204095    {
    41214096        _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 );
    41234098        return GIET_FAT32_IO_ERROR;
    41244099    }
  • soft/giet_vm/giet_fat32/fat32_shared.h

    r773 r807  
    3939#define O_TRUNC                 0x10
    4040#define O_CREAT                 0x20
     41#define O_APPEND                0x40
    4142
    4243/********************************************************************************
Note: See TracChangeset for help on using the changeset viewer.