FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
ns_linux Namespace Reference

Linux-specific system operations. More...

Functions

bool poll_with_timeout (int fd, short events, std::chrono::milliseconds const &timeout)
 Waits for a file descriptor to be ready for I/O with a timeout.
 
template<typename Data>
ssize_t read_with_timeout (int fd, std::chrono::milliseconds const &timeout, std::span< Data > buf)
 Reads from the file descriptor with a timeout.
 
template<typename Data>
ssize_t write_with_timeout (int fd, std::chrono::milliseconds const &timeout, std::span< Data > buf)
 Writes to the file descriptor with a timeout.
 
int open_with_timeout (fs::path const &path_file_src, std::chrono::milliseconds timeout, int oflag)
 Opens a given file with a timeout.
 
template<typename Data>
ssize_t open_read_with_timeout (fs::path const &path_file_src, std::chrono::milliseconds const &timeout, std::span< Data > buf)
 Opens and reads from the given input file.
 
template<typename Data>
ssize_t open_write_with_timeout (fs::path const &path_file_src, std::chrono::milliseconds const &timeout, std::span< Data > buf)
 Opens and writes to the given input file.
 
Value< bool > module_check (std::string_view str_name)
 Checks if the linux kernel has a module loaded that matches the input name.
 

Detailed Description

Linux-specific system operations.

Provides Linux kernel-specific functionality including kernel module availability checking, system capability detection, and OS-level feature queries. Used to verify FUSE module availability and other kernel features required by FlatImage.

Function Documentation

◆ module_check()

Value< bool > ns_linux::module_check ( std::string_view str_name)
inlinenodiscard

Checks if the linux kernel has a module loaded that matches the input name.

Parameters
str_nameName of the module to check for
Returns
Value<bool> The boolean result, or the respective internal error

Definition at line 243 of file linux.hpp.

Here is the caller graph for this function:

◆ open_read_with_timeout()

template<typename Data>
ssize_t ns_linux::open_read_with_timeout ( fs::path const & path_file_src,
std::chrono::milliseconds const & timeout,
std::span< Data > buf )
inlinenodiscard

Opens and reads from the given input file.

Template Parameters
DataType of data elements in the buffer
Parameters
path_file_srcPath to the file to open and read
timeoutThe timeout in std::chrono::milliseconds
bufThe buffer in which to store the read data
Returns
ssize_t The number of bytes read or -1 on error. On error, errno is set appropriately (ETIMEDOUT if timeout expires, or standard open()/read() error codes).

Definition at line 205 of file linux.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_with_timeout()

int ns_linux::open_with_timeout ( fs::path const & path_file_src,
std::chrono::milliseconds timeout,
int oflag )
inlinenodiscard

Opens a given file with a timeout.

Parameters
path_file_srcPath for the file to open
timeoutThe timeout in std::chrono::milliseconds
oflagThe open flags O_*
Returns
int The file descriptor or -1 on error. On error, errno is set appropriately (ETIMEDOUT on timeout).
Note
Thread-safe implementation using O_NONBLOCK and retry logic. For FIFOs: Opens with O_NONBLOCK. For writes (O_WRONLY), retries until reader connects or timeout. For reads (O_RDONLY), succeeds immediately but may not have a writer yet. This approach is simpler than pthread_cancel and avoids blocking syscalls entirely. For regular files: opens normally without timeout.

Definition at line 143 of file linux.hpp.

Here is the caller graph for this function:

◆ open_write_with_timeout()

template<typename Data>
ssize_t ns_linux::open_write_with_timeout ( fs::path const & path_file_src,
std::chrono::milliseconds const & timeout,
std::span< Data > buf )
inlinenodiscard

Opens and writes to the given input file.

Template Parameters
DataType of data elements in the buffer
Parameters
path_file_srcPath to the file to open and write
timeoutThe timeout in std::chrono::milliseconds
bufThe buffer with the data to write
Returns
ssize_t The number of bytes written or -1 on error. On error, errno is set appropriately (ETIMEDOUT if timeout expires, or standard open()/write() error codes).

Definition at line 226 of file linux.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ poll_with_timeout()

bool ns_linux::poll_with_timeout ( int fd,
short events,
std::chrono::milliseconds const & timeout )
inlinenodiscard

Waits for a file descriptor to be ready for I/O with a timeout.

Parameters
fdThe file descriptor to poll
eventsPoll events (POLLIN for read, POLLOUT for write)
timeoutThe timeout in std::chrono::milliseconds
Returns
bool True if ready, false on timeout or error (errno set appropriately)

Definition at line 53 of file linux.hpp.

Here is the caller graph for this function:

◆ read_with_timeout()

template<typename Data>
ssize_t ns_linux::read_with_timeout ( int fd,
std::chrono::milliseconds const & timeout,
std::span< Data > buf )
inlinenodiscard

Reads from the file descriptor with a timeout.

Template Parameters
DataType of data elements in the buffer
Parameters
fdThe file descriptor
timeoutThe timeout in std::chrono::milliseconds
bufThe buffer in which to store the read data
Returns
ssize_t The number of read bytes or -1 on error. On error, errno is set appropriately (ETIMEDOUT if timeout expires, or standard read() error codes).
Note
If timeout expires, returns -1 with errno = ETIMEDOUT. Thread-safe using poll().

Definition at line 89 of file linux.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_with_timeout()

template<typename Data>
ssize_t ns_linux::write_with_timeout ( int fd,
std::chrono::milliseconds const & timeout,
std::span< Data > buf )
inlinenodiscard

Writes to the file descriptor with a timeout.

Template Parameters
DataType of data elements in the buffer
Parameters
fdThe file descriptor
timeoutThe timeout in std::chrono::milliseconds
bufThe buffer with the data to write
Returns
ssize_t The number of written bytes or -1 on error. On error, errno is set appropriately (ETIMEDOUT if timeout expires, or standard write() error codes).
Note
If timeout expires, returns -1 with errno = ETIMEDOUT. Thread-safe using poll().

Definition at line 115 of file linux.hpp.

Here is the call graph for this function:
Here is the caller graph for this function: