F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
File.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/Posix/File.hpp
3 // \brief posix implementation for Os::File, header and test definitions
4 // ======================================================================
5 #include <Os/File.hpp>
6 #ifndef OS_POSIX_FILE_HPP
7 #define OS_POSIX_FILE_HPP
8 
9 #include <sys/stat.h>
10 
11 namespace Os {
12 namespace Posix {
13 namespace File {
14 
17 struct PosixFileHandle : public FileHandle {
18  static constexpr int INVALID_FILE_DESCRIPTOR = -1;
19  static constexpr int ERROR_RETURN_VALUE = -1;
20 
23 };
24 
31 class PosixFile : public FileInterface {
32  public:
35  PosixFile() = default;
36 
38  PosixFile(const PosixFile& other);
39 
41  PosixFile& operator=(const PosixFile& other);
42 
45  ~PosixFile() override = default;
46 
47  // ------------------------------------
48  // Functions overrides
49  // ------------------------------------
50 
67  Os::FileInterface::Status open(const char* path, Mode mode, OverwriteType overwrite) override;
68 
74  void close() override;
75 
82  Status size(FwSizeType& size_result) override;
83 
90  Status position(FwSizeType& position_result) override;
91 
104  Status preallocate(FwSizeType offset, FwSizeType length) override;
105 
115  Status seek(FwSignedSizeType offset, SeekType seekType) override;
116 
124  Status flush() override;
125 
144  Status read(U8* buffer, FwSizeType& size, WaitType wait) override;
145 
164  Status write(const U8* buffer, FwSizeType& size, WaitType wait) override;
165 
173  FileHandle* getHandle() override;
174 
175  private:
183  static mode_t map_open_create_mode(const U32 create_mode);
184 
185  private:
187  PosixFileHandle m_handle;
188 };
189 } // namespace File
190 } // namespace Posix
191 } // namespace Os
192 
193 #endif // OS_POSIX_FILE_HPP
Status size(FwSizeType &size_result) override
get size of currently open file
Definition: File.cpp:144
base implementation of FileHandle
Definition: File.hpp:24
Status preallocate(FwSizeType offset, FwSizeType length) override
pre-allocate file storage
Definition: File.cpp:177
PlatformSizeType FwSizeType
PosixFile()=default
constructor
int m_file_descriptor
Posix file descriptor.
Definition: File.hpp:22
PlatformSignedSizeType FwSignedSizeType
posix implementation of Os::File
Definition: File.hpp:31
~PosixFile() override=default
destructor
Status write(const U8 *buffer, FwSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
Definition: File.cpp:301
static constexpr int ERROR_RETURN_VALUE
Definition: File.hpp:19
static constexpr int INVALID_FILE_DESCRIPTOR
Definition: File.hpp:18
Status read(U8 *buffer, FwSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
Definition: File.cpp:261
void close() override
close the file, if not opened then do nothing
Definition: File.cpp:136
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
PosixFile & operator=(const PosixFile &other)
assignment operator that copies the internal representation
Definition: File.cpp:62
Status seek(FwSignedSizeType offset, SeekType seekType) override
seek the file pointer to the given offset
Definition: File.cpp:235
Status flush() override
flush file contents to storage
Definition: File.cpp:252
FileHandle * getHandle() override
returns the raw file handle
Definition: File.cpp:342
Status position(FwSizeType &position_result) override
get file pointer position of the currently open file
Definition: File.cpp:164
Os::FileInterface::Status open(const char *path, Mode mode, OverwriteType overwrite) override
open file with supplied path and mode
Definition: File.cpp:101