Changeset 808


Ignore:
Timestamp:
Mar 17, 2016, 2:18:30 PM (9 years ago)
Author:
alain
Message:

Introduce the O_WRONLY and O_RDWR flags for the giet_fat_open system call.

Location:
soft/giet_vm/giet_fat32
Files:
3 edited

Legend:

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

    r807 r808  
    24092409   
    24102410    // get flags
    2411     unsigned int create    = ((flags & O_CREAT)  != 0);
    2412     unsigned int read_only = ((flags & O_RDONLY) != 0);
    2413     unsigned int truncate  = ((flags & O_TRUNC)  != 0);
    2414     unsigned int append    = ((flags & O_APPEND) != 0);
     2411    unsigned int create     = ((flags & O_CREAT)  != 0);
     2412    unsigned int read_only  = ((flags & O_RDONLY) != 0);
     2413    unsigned int write_only = ((flags & O_WRONLY) != 0);
     2414    unsigned int truncate   = ((flags & O_TRUNC)  != 0);
     2415    unsigned int append     = ((flags & O_APPEND) != 0);
    24152416
    24162417#if GIET_DEBUG_FAT
     
    26232624    _fat.fd[fd_id].allocated  = 1;
    26242625    _fat.fd[fd_id].read_only  = read_only;
     2626    _fat.fd[fd_id].write_only = write_only;
    26252627    _fat.fd[fd_id].inode      = child;
    26262628    _fat.fd[fd_id].seek       = ( append ) ? child->size : 0;
     
    28212823    }
    28222824
    2823     // check fd_id overflow
    2824     if ( fd_id >= GIET_OPEN_FILES_MAX )
    2825     {
    2826         _printf("\n[FAT ERROR] in _fat_read(): illegal file descriptor\n");
    2827         return GIET_FAT32_INVALID_FD;
    2828     }
    2829 
    2830     // check file open
    2831     if ( _fat.fd[fd_id].allocated == 0 )
    2832     {
    2833         _printf("\n[FAT ERROR] in _fat_read(): file not open\n");
    2834         return GIET_FAT32_NOT_OPEN;
    2835     }
    2836 
    28372825    // takes the FAT lock and register it in thread context
    28382826    static_scheduler_t*  psched = _get_sched();
     
    28412829    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
    28422830           
     2831    // check fd_id overflow
     2832    if ( fd_id >= GIET_OPEN_FILES_MAX )
     2833    {
     2834        _spin_lock_release( &_fat.fat_lock );
     2835        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2836
     2837        _printf("\n[FAT ERROR] in _fat_read(): illegal file descriptor\n");
     2838        return GIET_FAT32_INVALID_FD;
     2839    }
     2840
     2841    // check file open
     2842    if ( _fat.fd[fd_id].allocated == 0 )
     2843    {
     2844        _spin_lock_release( &_fat.fat_lock );
     2845        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2846
     2847        _printf("\n[FAT ERROR] in _fat_read(): file not open\n");
     2848        return GIET_FAT32_NOT_OPEN;
     2849    }
     2850
     2851    // check file readable
     2852    if ( _fat.fd[fd_id].write_only )
     2853    {
     2854        _spin_lock_release( &_fat.fat_lock );
     2855        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
     2856
     2857        _printf("\n[FAT ERROR] _fat_read(): file <%s> is write-only\n",
     2858                _fat.fd[fd_id].inode->name );
     2859        return GIET_FAT32_WRITE_ONLY;
     2860    }
     2861
    28432862    // get special modes
    28442863    unsigned int physical_addressing = modes & FAT_PADDR_MODE;
  • soft/giet_vm/giet_fat32/fat32.h

    r787 r808  
    186186    char                 allocated;              // file descriptor allocated
    187187    char                 read_only;              // write protected
    188     char                 reserved[6];            // reserved
     188    char                 write_only;             // read protected
     189    char                 reserved[5];            // reserved
    189190}   fat_file_desc_t;
    190191
  • soft/giet_vm/giet_fat32/fat32_shared.h

    r807 r808  
    3737
    3838#define O_RDONLY                0x01
     39#define O_WRONLY                0x02
     40#define O_RDWR                  0x00
    3941#define O_TRUNC                 0x10
    4042#define O_CREAT                 0x20
     
    8385#define GIET_FAT32_NO_MORE_ENTRIES      (-18)
    8486#define GIET_FAT32_BUFFER_TOO_SMALL     (-19)
     87#define GIET_FAT32_WRITE_ONLY           (-20)
    8588
    8689#endif // _FAT32_SHARED
Note: See TracChangeset for help on using the changeset viewer.