F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
SandboxedFile.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Os/SandboxedFile.hpp
3 // \brief A directory-sandboxed wrapper around Os::File
4 // ======================================================================
5 #ifndef Os_SandboxedFile_hpp_
6 #define Os_SandboxedFile_hpp_
7 
9 #include <Os/File.hpp>
10 #include <Os/FilePathUtils.hpp>
11 
12 namespace Os {
13 
42  public:
43  SandboxedFile(const SandboxedFile&) = delete;
44  SandboxedFile& operator=(const SandboxedFile&) = delete;
45 
50  SandboxedFile();
51 
54 
67  void configure(const char* allowedDirectory);
68 
72  bool isConfigured() const;
73 
74  // -------------------------------------------------------
75  // Os::File-equivalent interface
76  // -------------------------------------------------------
77 
88  Os::FileInterface::Status open(const char* path,
91 
93  void close();
94 
97  bool isOpen() const;
98 
103 
108 
114 
120 
124 
131 
137 
144 
150 
155 
158  const char* getSandboxDirectory() const;
159 
160  private:
162  Os::File m_file;
163 
165  Fw::FileNameString m_allowedDirectory;
166 
168  bool m_configured;
169 };
170 
171 } // namespace Os
172 
173 #endif
void configure(const char *allowedDirectory)
Configure the allowed sandbox directory.
Os::FileInterface::Status flush()
Flush file contents to storage.
PlatformSizeType FwSizeType
bool isOpen() const
Check if the file is open.
Os::FileInterface::Status calculateCrc(U32 &crc)
Calculate CRC32 of the entire file.
Os::FileInterface::Status position(FwSizeType &position_result)
Get file pointer position.
Os::FileInterface::Status seek(FwSignedSizeType offset, Os::FileInterface::SeekType seekType)
Seek file pointer.
A wrapper around Os::File that restricts file access to an allowed directory.
~SandboxedFile()
Destroy the SandboxedFile (closes the underlying file if open)
PlatformSignedSizeType FwSignedSizeType
SandboxedFile & operator=(const SandboxedFile &)=delete
Non-copy-assignable.
SandboxedFile()
Construct a SandboxedFile with default sandbox of /
const char * getSandboxDirectory() const
Get the configured sandbox directory.
Os::FileInterface::Status open(const char *path, Os::FileInterface::Mode mode, Os::FileInterface::OverwriteType overwrite=Os::FileInterface::NO_OVERWRITE)
Open a file, validating the path against the sandbox directory.
bool isConfigured() const
Check if a sandbox directory has been configured.
Os::FileInterface::Status size(FwSizeType &size_result)
Get size of currently open file.
Os::FileInterface::Status write(const U8 *buffer, FwSizeType &size, Os::FileInterface::WaitType wait)
Write data to the file.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
Do NOT overwrite existing files.
Definition: File.hpp:59
Os::FileInterface::Status preallocate(FwSizeType offset, FwSizeType length)
Pre-allocate file storage.
Os::FileInterface::Status read(U8 *buffer, FwSizeType &size, Os::FileInterface::WaitType wait)
Read data from the file.
void close()
Close the file.