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) {
104 switch (requested_mode) {
106 mode_flags = O_RDONLY;
109 mode_flags = O_WRONLY | O_CREAT;
116 O_WRONLY | O_CREAT | O_TRUNC | ((overwrite == PosixFile::OverwriteType::OVERWRITE) ? 0 : O_EXCL);
119 mode_flags = O_WRONLY | O_CREAT | O_APPEND;
127 int errno_store = errno;
152 int errno_store = errno;
156 (void)::lseek(this->m_handle.
m_file_descriptor, static_cast<off_t>(current_position), SEEK_SET);
157 size_result =
static_cast<FwSizeType>(end_of_file);
167 int errno_store = errno;
171 position_result =
static_cast<FwSizeType>(actual);
179 (std::numeric_limits<off_t>::max() - length) < offset) {
180 status = Os::File::Status::BAD_SIZE;
186 #if _POSIX_C_SOURCE >= 200112L && !(defined(FPRIME_SYNTHETIC_FALLOCATE) && FPRIME_SYNTHETIC_FALLOCATE) 189 ::posix_fallocate(this->m_handle.
m_file_descriptor, static_cast<off_t>(offset), static_cast<off_t>(length));
194 if (Os::File::Status::NOT_SUPPORTED == status) {
197 status = this->
size(file_size);
201 status = this->
position(file_position);
203 if (file_position > static_cast<FwSizeType>(std::numeric_limits<FwSignedSizeType>::max()) ||
204 file_size > static_cast<FwSizeType>(std::numeric_limits<FwSignedSizeType>::max())) {
205 status = Os::File::Status::BAD_SIZE;
209 const FwSizeType write_length = (offset + length) - file_size;
210 status = this->
seek(static_cast<FwSignedSizeType>(file_size), PosixFile::SeekType::ABSOLUTE);
213 for (
FwSizeType i = 0; i < write_length; i++) {
216 this->
write(reinterpret_cast<const U8*>(
"\0"), write_size, PosixFile::WaitType::NO_WAIT);
224 this->
seek(static_cast<FwSignedSizeType>(file_position), PosixFile::SeekType::ABSOLUTE);
235 if (offset > std::numeric_limits<off_t>::max()) {
238 off_t actual = ::lseek(this->m_handle.
m_file_descriptor, static_cast<off_t>(offset),
239 (seekType == SeekType::ABSOLUTE) ? SEEK_SET : SEEK_CUR);
240 int errno_store = errno;
243 }
else if ((seekType == SeekType::ABSOLUTE) && (actual != offset)) {
253 int errno_store = errno;
264 (
size > (std::numeric_limits<FwSizeType>::max() / 2)) ? std::numeric_limits<FwSizeType>::max() :
size * 2;
274 static_cast<size_t>(
size - accumulated));
277 int errno_store = errno;
279 if (EINTR != errno_store) {
286 else if (read_size == 0) {
289 accumulated +=
static_cast<FwSizeType>(read_size);
304 (
size > (std::numeric_limits<FwSizeType>::max() / 2)) ? std::numeric_limits<FwSizeType>::max() :
size * 2;
315 static_cast<size_t>(
size - accumulated));
318 int errno_store = errno;
320 if (EINTR != errno_store) {
326 accumulated +=
static_cast<FwSizeType>(write_size);
333 int errno_store = errno;
341 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()