23 #define SYNC_FLAGS O_SYNC 25 #define SYNC_FLAGS (0) 37 "FwSignedSizeType is not large enough to store values of type off_t");
39 "FwSignedSizeType is not large enough to store values of type ssize_t");
40 static_assert(
sizeof(
FwSizeType) >=
sizeof(
size_t),
"FwSizeType is not large enough to store values of type size_t");
43 static_assert(std::numeric_limits<FwSignedSizeType>::max() >= std::numeric_limits<off_t>::max(),
44 "Maximum value of FwSignedSizeType less than the maximum value of off_t. Configure a larger type.");
45 static_assert(std::numeric_limits<FwSizeType>::max() >=
OFF_T_MAX_LIMIT,
46 "Maximum value of FwSizeType less than the maximum value of off_t. Configure a larger type.");
47 static_assert(std::numeric_limits<FwSignedSizeType>::max() >= std::numeric_limits<ssize_t>::max(),
48 "Maximum value of FwSignedSizeType less than the maximum value of ssize_t. Configure a larger type.");
50 "Minimum value of FwSignedSizeType larger than the minimum value of off_t. Configure a larger type.");
52 "Minimum value of FwSizeType larger than the minimum value of ssize_t. Configure a larger type.");
53 static_assert(std::numeric_limits<FwSizeType>::max() >= std::numeric_limits<size_t>::max(),
54 "Maximum value of FwSizeType less than the maximum value of size_t. Configure a larger type.");
69 mode_t PosixFile::map_open_create_mode(
const U32 create_mode) {
106 switch (requested_mode) {
108 mode_flags = O_RDONLY;
111 mode_flags = O_WRONLY | O_CREAT;
118 O_WRONLY | O_CREAT | O_TRUNC | ((overwrite == PosixFile::OverwriteType::OVERWRITE) ? 0 : O_EXCL);
121 mode_flags = O_WRONLY | O_CREAT | O_APPEND;
129 int errno_store = errno;
154 int errno_store = errno;
158 (void)::lseek(this->m_handle.
m_file_descriptor, static_cast<off_t>(current_position), SEEK_SET);
159 size_result =
static_cast<FwSizeType>(end_of_file);
169 int errno_store = errno;
173 position_result =
static_cast<FwSizeType>(actual);
181 (std::numeric_limits<off_t>::max() - length) < offset) {
182 status = Os::File::Status::BAD_SIZE;
188 #if _POSIX_C_SOURCE >= 200112L && !(defined(FPRIME_SYNTHETIC_FALLOCATE) && FPRIME_SYNTHETIC_FALLOCATE) 191 ::posix_fallocate(this->m_handle.
m_file_descriptor, static_cast<off_t>(offset), static_cast<off_t>(length));
196 if (Os::File::Status::NOT_SUPPORTED == status) {
199 status = this->
size(file_size);
203 status = this->
position(file_position);
205 if (file_position > static_cast<FwSizeType>(std::numeric_limits<FwSignedSizeType>::max()) ||
206 file_size > static_cast<FwSizeType>(std::numeric_limits<FwSignedSizeType>::max())) {
207 status = Os::File::Status::BAD_SIZE;
211 const FwSizeType write_length = (offset + length) - file_size;
212 status = this->
seek(static_cast<FwSignedSizeType>(file_size), PosixFile::SeekType::ABSOLUTE);
215 for (
FwSizeType i = 0; i < write_length; i++) {
218 this->
write(reinterpret_cast<const U8*>(
"\0"), write_size, PosixFile::WaitType::NO_WAIT);
226 this->
seek(static_cast<FwSignedSizeType>(file_position), PosixFile::SeekType::ABSOLUTE);
237 if (offset > std::numeric_limits<off_t>::max()) {
240 off_t actual = ::lseek(this->m_handle.
m_file_descriptor, static_cast<off_t>(offset),
241 (seekType == SeekType::ABSOLUTE) ? SEEK_SET : SEEK_CUR);
242 int errno_store = errno;
245 }
else if ((seekType == SeekType::ABSOLUTE) && (actual != offset)) {
255 int errno_store = errno;
266 (
size > (std::numeric_limits<FwSizeType>::max() / 2)) ? std::numeric_limits<FwSizeType>::max() :
size * 2;
276 static_cast<size_t>(
size - accumulated));
279 int errno_store = errno;
281 if (EINTR != errno_store) {
288 else if (read_size == 0) {
291 accumulated +=
static_cast<FwSizeType>(read_size);
306 (
size > (std::numeric_limits<FwSizeType>::max() / 2)) ? std::numeric_limits<FwSizeType>::max() :
size * 2;
317 static_cast<size_t>(
size - accumulated));
320 int errno_store = errno;
322 if (EINTR != errno_store) {
328 accumulated +=
static_cast<FwSizeType>(write_size);
335 int errno_store = errno;
343 return &this->m_handle;
Status size(FwSizeType &size_result) override
get size of currently open file
base implementation of FileHandle
Status preallocate(FwSizeType offset, FwSizeType length) override
pre-allocate file storage
A catch-all for other errors. Have to look in implementation-specific code.
PlatformSizeType FwSizeType
PosixFile()=default
constructor
static const UnsignedSSizeT SSIZE_T_MAX_LIMIT
Open file for writing; writes don't return until data is on disk.
int m_file_descriptor
Posix file descriptor.
PlatformSignedSizeType FwSignedSizeType
posix implementation of Os::File
Status write(const U8 *buffer, FwSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
static constexpr int ERROR_RETURN_VALUE
static constexpr int INVALID_FILE_DESCRIPTOR
Status read(U8 *buffer, FwSizeType &size, WaitType wait) override
read data from this file into supplied buffer bounded by size
void close() override
close the file, if not opened then do nothing
uint8_t U8
8-bit unsigned integer
PosixFile & operator=(const PosixFile &other)
assignment operator that copies the internal representation
static U32 min(const U32 a, const U32 b)
Operation was successful.
Status seek(FwSignedSizeType offset, SeekType seekType) override
seek the file pointer to the given offset
File::Status errno_to_file_status(int errno_input)
std::make_unsigned< ssize_t >::type UnsignedSSizeT
static const UnsignedOffT OFF_T_MAX_LIMIT
Status flush() override
flush file contents to storage
FileHandle * getHandle() override
returns the raw file handle
Status position(FwSizeType &position_result) override
get file pointer position of the currently open file
std::make_unsigned< off_t >::type UnsignedOffT
Os::FileInterface::Status open(const char *path, Mode mode, OverwriteType overwrite) override
open file with supplied path and mode
Open file for writing and truncates file if it exists, ie same flags as creat()