ublk-cpp v0.0
Loading...
Searching...
No Matches
path.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <cassert>
9#include <cstddef>
10#include <cstdint>
11#include <format>
12#include <string>
13
14namespace ublk {
15namespace detail {
16
17inline void fill_dev_path(char *data, size_t size, uint32_t dev_id) {
18 assert(size > 0);
19 auto res = std::format_to_n(data, static_cast<std::ptrdiff_t>(size - 1),
20 "/dev/ublkc{}", dev_id);
21 *res.out = '\0';
22}
23
24inline std::string dev_path(uint32_t dev_id) {
25 return std::format("/dev/ublkc{}", dev_id);
26}
27
28inline constexpr size_t DEV_PATH_LEN = 32;
29
30template <typename T> struct DevPathBuf {
31 static_assert(alignof(T) <= DEV_PATH_LEN,
32 "payload alignment must not exceed DEV_PATH_LEN");
33 char path[DEV_PATH_LEN];
34 T payload = {};
35
36 DevPathBuf(uint32_t dev_id) { fill_dev_path(path, sizeof(path), dev_id); }
37};
38
39} // namespace detail
40} // namespace ublk
The main namespace of the ublk-cpp library.
Definition ublk.hpp:21