Ignore:
Timestamp:
Dec 9, 2013, 5:26:37 PM (11 years ago)
Author:
devigne
Message:

Add a new syscall : giet_fat_fstat, allowing to a user application to know the
size (in sectors) of an open file.

File:
1 edited

Legend:

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

    r259 r260  
    13091309
    13101310/////////////////////////////////////////////////////////////////////////////////
     1311// Return stats of a file identified by "fd".
     1312// (Only the file_size in sectors for this moment)
     1313/////////////////////////////////////////////////////////////////////////////////
     1314// Returns file size (on sectors) on success, -1 on failure.
     1315/////////////////////////////////////////////////////////////////////////////////
     1316int _fat_fstat( unsigned int fd_id )
     1317{
     1318    unsigned int file_size    = 0;
     1319    unsigned int file_sectors = 0;
     1320
     1321    if( (fd_id < GIET_OPEN_FILES_MAX) )
     1322    {
     1323        file_size = fat.fd[fd_id].file_size;
     1324
     1325        if ( file_size & 0x1FF ) file_sectors = (file_size >> 9) + 1;
     1326        else                     file_sectors = (file_size >> 9);
     1327
     1328        return file_sectors;
     1329    }
     1330    else
     1331    {
     1332        _tty_get_lock( 0 );
     1333        _puts("\n[FAT ERROR] in _fat_fstat() : illegal file descriptor index\n");
     1334        _tty_release_lock( 0 );
     1335        return -1;
     1336    }
     1337} // end _fat_fstat()
     1338
     1339/////////////////////////////////////////////////////////////////////////////////
    13111340// Close the file identified by the file_descriptor index.
    13121341/////////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.