FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
ns_filesystems::ns_utils Namespace Reference

Filesystem utility functions. More...

Classes

struct  Instance
 Represents an instance. More...
 

Functions

bool is_busy (fs::path const &path_dir)
 Checks if a filesystem path is currently in use by any active process.
 
Value< void > wait_busy (fs::path const &path_dir, std::chrono::nanoseconds timeout)
 Waits for a filesystem path to become available (not busy).
 
std::vector< Instanceget_instances (fs::path const &path_dir_instances)
 Get the running FlatImage instances.
 
std::vector< fs::path > get_mounted_layers (fs::path const &path_dir_layers)
 Get a path for each layer directory.
 

Detailed Description

Filesystem utility functions.

Provides utility functions for filesystem management including busy state detection by scanning /proc/[pid]/mountinfo, layer enumeration, and instance cleanup operations. Supports filesystem state queries and validation for safe mount/unmount operations.

Function Documentation

◆ get_instances()

std::vector< Instance > ns_filesystems::ns_utils::get_instances ( fs::path const & path_dir_instances)
inlinenodiscard

Get the running FlatImage instances.

Enumerates all active FlatImage instances by scanning the instance directory. Each subdirectory in path_dir_instances is expected to be named after a process ID (PID).

Parameters
path_dir_instancesPath to FIM_DIR_INSTANCE of a FlatImage application
Returns
std::vector<Instance> A vector of Instance{pid,path} structures for all active instances, sorted by PID

Definition at line 137 of file utils.hpp.

Here is the caller graph for this function:

◆ get_mounted_layers()

std::vector< fs::path > ns_filesystems::ns_utils::get_mounted_layers ( fs::path const & path_dir_layers)
inlinenodiscard

Get a path for each layer directory.

Each entry in path_dir_layers is expected to be a directory representing a filesystem layer. The function filters and collects only valid directories, excluding any files or invalid entries.

Parameters
path_dir_layersPath to the layer directory
Returns
std::vector<fs::path> A vector of filesystem paths for all mounted layers, sorted in ascending order

Definition at line 164 of file utils.hpp.

Here is the caller graph for this function:

◆ is_busy()

bool ns_filesystems::ns_utils::is_busy ( fs::path const & path_dir)
inline

Checks if a filesystem path is currently in use by any active process.

Scans all processes in /proc/[pid]/mountinfo to determine if the given path is mounted or actively used. Iterates through each process's mount information and returns true if the path is found in any mountinfo entry, indicating the path is busy/in-use.

Parameters
path_dirThe filesystem path to check for busy status.
Returns
true if the path is found in any process's mount information (indicating busy state), false if no processes have mounted or are using the path.

Definition at line 50 of file utils.hpp.

Here is the caller graph for this function:

◆ wait_busy()

Value< void > ns_filesystems::ns_utils::wait_busy ( fs::path const & path_dir,
std::chrono::nanoseconds timeout )
inlinenodiscard

Waits for a filesystem path to become available (not busy).

Polls the is_busy() function at 100ms intervals until either the path becomes available or the timeout is reached. Uses chrono duration for precise time tracking.

Parameters
path_dirThe filesystem path to monitor for busy status.
timeoutMaximum time to wait before timing out (accepts any chrono duration type).
Returns
Value<void> Success if the path became available within the timeout, or an error if the timeout was reached while the path was still busy.

Definition at line 92 of file utils.hpp.

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