F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Os::File Class Reference

#include <Os/File.hpp>

Public Types

enum  Mode {
  OPEN_NO_MODE , OPEN_READ , OPEN_WRITE , OPEN_SYNC_WRITE ,
  OPEN_SYNC_DIRECT_WRITE , OPEN_CREATE , OPEN_APPEND
}
 
enum  Status {
  OP_OK , DOESNT_EXIST , NO_SPACE , NO_PERMISSION ,
  BAD_SIZE , NOT_OPENED , FILE_EXISTS , OTHER_ERROR
}
 

Public Member Functions

 File ()
 Constructor.
 
virtual ~File ()
 Destructor. Will close file if still open.
 
Status prealloc (NATIVE_INT_TYPE offset, NATIVE_INT_TYPE len)
 
Status open (const char *fileName, Mode mode)
 open file. Writing creates file if it doesn't exist
 
Status open (const char *fileName, Mode mode, bool include_excl)
 open file. Writing creates file if it doesn't exist
 
bool isOpen ()
 check if file descriptor is open or not.
 
Status seek (NATIVE_INT_TYPE offset, bool absolute=true)
 seek to location. If absolute = true, absolute from beginning of file
 
Status flush ()
 flush data to disk. No-op on systems that do not support.
 
Status read (void *buffer, NATIVE_INT_TYPE &size, bool waitForFull=true)
 waitForFull = true to wait for all bytes to be read
 
Status write (const void *buffer, NATIVE_INT_TYPE &size, bool waitForDone=true)
 write size; will return amount written or errno
 
Status bulkWrite (const void *buffer, NATIVE_UINT_TYPE &totalSize, NATIVE_INT_TYPE chunkSize)
 write size; will return amount written or errno
 
void close ()
 close file
 
NATIVE_INT_TYPE getLastError ()
 read back last error code (typically errno)
 
const char * getLastErrorString ()
 get a string of the last error (typically from strerror)
 
Status calculateCRC32 (U32 &crc)
 calculates the CRC32 of the file
 

Static Public Member Functions

static Status niceCRC32 (U32 &crc, const char *fileName)
 Calculates CRC32 of file, not burdening FS.
 

Detailed Description

Definition at line 10 of file File.hpp.

Member Enumeration Documentation

◆ Mode

Enumerator
OPEN_NO_MODE 

File mode not yet selected.

OPEN_READ 

Open file for reading.

OPEN_WRITE 

Open file for writing.

OPEN_SYNC_WRITE 

Open file for writing; writes don't return until data is on disk.

OPEN_SYNC_DIRECT_WRITE 

Open file for writing, bypassing all caching. Requires data alignment.

OPEN_CREATE 

Open file for writing and truncates file if it exists, ie same flags as creat()

OPEN_APPEND 

Open file for appending.

Definition at line 13 of file File.hpp.

◆ Status

Enumerator
OP_OK 

Operation was successful.

DOESNT_EXIST 

File doesn't exist (for read)

NO_SPACE 

No space left.

NO_PERMISSION 

No permission to read/write file.

BAD_SIZE 

Invalid size parameter.

NOT_OPENED 

file hasn't been opened yet

FILE_EXISTS 

file already exist (for CREATE with O_EXCL enabled)

OTHER_ERROR 

A catch-all for other errors. Have to look in implementation-specific code.

Definition at line 23 of file File.hpp.

Constructor & Destructor Documentation

◆ File()

Os::File::File ( )

Constructor.

Definition at line 8 of file File.cpp.

◆ ~File()

Os::File::~File ( )
virtual

Destructor. Will close file if still open.

Definition at line 10 of file File.cpp.

Member Function Documentation

◆ bulkWrite()

File::Status Os::File::bulkWrite ( const void *  buffer,
NATIVE_UINT_TYPE totalSize,
NATIVE_INT_TYPE  chunkSize 
)

write size; will return amount written or errno

Definition at line 316 of file File.cpp.

◆ calculateCRC32()

File::Status Os::File::calculateCRC32 ( U32 &  crc)

calculates the CRC32 of the file

Definition at line 420 of file File.cpp.

◆ close()

void Os::File::close ( )

close file

Definition at line 36 of file File.cpp.

◆ flush()

File::Status Os::File::flush ( )

flush data to disk. No-op on systems that do not support.

Definition at line 382 of file File.cpp.

◆ getLastError()

NATIVE_INT_TYPE Os::File::getLastError ( )

read back last error code (typically errno)

Definition at line 38 of file File.cpp.

◆ getLastErrorString()

const char * Os::File::getLastErrorString ( )

get a string of the last error (typically from strerror)

Definition at line 42 of file File.cpp.

◆ isOpen()

bool Os::File::isOpen ( )

check if file descriptor is open or not.

Definition at line 20 of file File.cpp.

◆ niceCRC32()

File::Status Os::File::niceCRC32 ( U32 &  crc,
const char *  fileName 
)
static

Calculates CRC32 of file, not burdening FS.

Definition at line 16 of file FileCommon.cpp.

◆ open() [1/2]

File::Status Os::File::open ( const char *  fileName,
File::Mode  mode 
)

open file. Writing creates file if it doesn't exist

Definition at line 12 of file File.cpp.

◆ open() [2/2]

File::Status Os::File::open ( const char *  fileName,
File::Mode  mode,
bool  include_excl 
)

open file. Writing creates file if it doesn't exist

Definition at line 16 of file File.cpp.

◆ prealloc()

File::Status Os::File::prealloc ( NATIVE_INT_TYPE  offset,
NATIVE_INT_TYPE  len 
)

Definition at line 118 of file File.cpp.

◆ read()

File::Status Os::File::read ( void *  buffer,
NATIVE_INT_TYPE size,
bool  waitForFull = true 
)

waitForFull = true to wait for all bytes to be read

read data from file; returns amount read or errno.

Definition at line 28 of file File.cpp.

◆ seek()

File::Status Os::File::seek ( NATIVE_INT_TYPE  offset,
bool  absolute = true 
)

seek to location. If absolute = true, absolute from beginning of file

Definition at line 24 of file File.cpp.

◆ write()

File::Status Os::File::write ( const void *  buffer,
NATIVE_INT_TYPE size,
bool  waitForDone = true 
)

write size; will return amount written or errno

Definition at line 32 of file File.cpp.


The documentation for this class was generated from the following files: