libcosmos
Linux C++ System Programming Library
|
A file only backed by memory, not by an actual file system. More...
#include <MemFile.hxx>
Public Types | |
enum class | OpenFlag : unsigned int { CLOEXEC = MFD_CLOEXEC , ALLOW_SEALING = MFD_ALLOW_SEALING , HUGETLB = MFD_HUGETLB } |
Available open settings for the MemFile type. More... | |
enum class | HugePageSize : unsigned int { DEFAULT = 0 , HUGE_2MB = 21 , HUGE_8MB = 23 , HUGE_16MB = 24 , HUGE_32MB = 25 , HUGE_256MB = 28 , HUGE_512MB = 29 , HUGE_1GB = 30 , HUGE_2GB = 31 , HUGE_16GB = 34 } |
PageSize specification if OpenFlag::HUGETLB is set. More... | |
using | OpenFlags = BitMask<OpenFlag> |
Collection of flags used when creating the MemFile type. | |
![]() | |
enum class | SeekType : int { SET = SEEK_SET , CUR = SEEK_CUR , END = SEEK_END , DATA = SEEK_DATA , HOLE = SEEK_HOLE } |
Different methods for changing the file read/write position. More... | |
Public Member Functions | |
MemFile (const SysString name, const OpenFlags flags=OpenFlags{OpenFlag::CLOEXEC}, const HugePageSize tlb_ps=HugePageSize::DEFAULT) | |
void | create (const SysString name, const OpenFlags flags=OpenFlags{OpenFlag::CLOEXEC}, const HugePageSize tlb_ps=HugePageSize::DEFAULT) |
Create a new MemFile using the given settings. | |
![]() | |
FileBase (const FileBase &)=delete | |
FileBase & | operator= (const FileBase &)=delete |
virtual void | close () |
Close the current file object. | |
bool | isOpen () const |
Returns whether currently a FileDescriptor is opened. | |
FileDescriptor | fd () const |
Allows access to the underlying fd with const semantics. | |
void | truncate (const off_t length) |
![]() | |
StreamIO (FileDescriptor &fd) | |
StreamIO (const StreamIO &)=delete | |
StreamIO & | operator= (const StreamIO &)=delete |
StreamIO & | operator= (StreamIO &&) noexcept |
size_t | read (void *buf, size_t length) |
Read up to length bytes from the file into buf . | |
size_t | write (const void *buf, size_t length) |
Write up to length bytes from buf into the underlying file. | |
size_t | write (const std::string_view data) |
string_view wrapper around write(const void*, size_t). | |
void | readAll (void *buf, size_t length) |
Read all length bytes from the underlying file. | |
void | readAll (std::string &s, size_t length) |
Like readAll(void*, size_t) using an STL string. | |
void | writeAll (const void *buf, size_t length) |
Write all length bytes into the underlying file. | |
void | writeAll (const std::string_view data) |
string_view wrapper around writeAll(const void*, size_t). | |
bool | read (ReadIOVector &iovec) |
Read data from file into a vector of data regions. | |
bool | write (WriteIOVector &iovec) |
Write data to file from a vector of data regions. | |
void | readAll (ReadIOVector &iovec) |
Read into all data regions specified in iovec . | |
void | writeAll (WriteIOVector &iovec) |
Write all data regions specified in iovec . | |
off_t | seek (const SeekType type, off_t off) |
Seek to the given offset based on the given offset type . | |
off_t | seekFromStart (off_t off) |
Seek to the given offset relative to the start of the file. | |
off_t | seekFromCurrent (off_t off) |
Seek to the given offset relative to the current file position. | |
off_t | seekFromEnd (off_t off) |
Seek to the given offset relative to the end of the file. | |
Additional Inherited Members | |
![]() | |
FileBase (const FileDescriptor fd=FileDescriptor{}) | |
FileBase (FileBase &&other) noexcept | |
FileBase & | operator= (FileBase &&other) noexcept |
![]() | |
FileDescriptor | m_fd |
![]() | |
FileDescriptor & | m_stream_fd |
A file only backed by memory, not by an actual file system.
This type can create memory backed files that are not visible in the file system. As a speciality this type of file allows adding seals via FileDescriptor::addSeals().
Files created by this type are always opened in OpenMode::READ_WRITE.
Definition at line 22 of file MemFile.hxx.
using cosmos::MemFile::OpenFlags = BitMask<OpenFlag> |
Collection of flags used when creating the MemFile type.
Definition at line 34 of file MemFile.hxx.
|
strong |
PageSize specification if OpenFlag::HUGETLB is set.
Definition at line 37 of file MemFile.hxx.
|
strong |
Available open settings for the MemFile type.
Enumerator | |
---|---|
CLOEXEC | Apply close-on-exec semantics. |
ALLOW_SEALING | Allow MemFD file sealing operations. |
HUGETLB | Create the file in the HugeTLB file system. |
Definition at line 27 of file MemFile.hxx.
|
inlineexplicit |
Definition at line 56 of file MemFile.hxx.
void cosmos::MemFile::create | ( | const SysString | name, |
const OpenFlags | flags = OpenFlags{OpenFlag::CLOEXEC}, | ||
const HugePageSize | tlb_ps = HugePageSize::DEFAULT ) |
Create a new MemFile using the given settings.
Create a new memory file using the given flags and optional page size. The name
is only for debugging purposes and is used as an identifier in the /proc file system.
Definition at line 10 of file MemFile.cxx.