31 m_allowedDirectory = resolved;
59 return m_file.
open(resolvedPath, mode, overwrite);
71 return m_file.
size(size_result);
75 return m_file.
position(position_result);
83 return m_file.
seek(offset, seekType);
87 return m_file.
flush();
91 return m_file.
read(buffer,
size, wait);
111 return m_allowedDirectory.
toChar();
void configure(const char *allowedDirectory)
Configure the allowed sandbox directory.
Resolved path falls outside the allowed directory.
Status calculateCrc(U32 &crc)
calculate the CRC32 of the entire file
Os::FileInterface::Status flush()
Flush file contents to storage.
PlatformSizeType FwSizeType
bool isOpen() const
Check if the file is open.
Status preallocate(FwSizeType offset, FwSizeType length) override
pre-allocate file storage
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.
Status position(FwSizeType &position_result) override
get file pointer position of the currently open file
Status size(FwSizeType &size_result) override
get size of currently open file
~SandboxedFile()
Destroy the SandboxedFile (closes the underlying file if open)
Status checkContainment(const char *resolvedPath, const char *allowedDirectory)
Check whether an already-resolved path is within an allowed directory.
PlatformSignedSizeType FwSignedSizeType
SandboxedFile()
Construct an unconfigured SandboxedFile.
Status resolveDirectoryFromCwd(const char *path, char *resolvedOut, FwSizeType resolvedSize)
Resolve a directory path from CWD into the form checkContainment expects.
Os::FileInterface::Status open(const char *path, Mode mode)
open file with supplied path and mode
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.
Status seek(FwSignedSizeType offset, SeekType seekType) override
seek the file pointer to the given offset
static constexpr FwSizeType MAX_PATH_LENGTH
Maximum supported path length for resolution buffers.
bool isConfigured() const
Check if a sandbox directory has been configured.
void close() override
close the file, if not opened then do nothing
Status write(const U8 *buffer, FwSizeType &size)
write data to this file from the supplied buffer bounded by size
Os::FileInterface::Status size(FwSizeType &size_result)
Get size of currently open file.
const char * toChar() const
Convert to a C-style char*.
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
Status read(U8 *buffer, FwSizeType &size)
read data from this file into supplied buffer bounded by size
Status flush() override
flush file contents to storage
Path is valid and within the allowed directory.
Os::FileInterface::Status preallocate(FwSizeType offset, FwSizeType length)
Pre-allocate file storage.
Status resolveFromCwd(const char *path, char *resolvedOut, FwSizeType resolvedSize)
Resolve a path using CWD as the base for relative paths.
Os::FileInterface::Status read(U8 *buffer, FwSizeType &size, Os::FileInterface::WaitType wait)
Read data from the file.
void close()
Close the file.
bool isOpen() const
determine if the file is open