Skip to content
API Documentation
BastionGuard™
anonymous_namespace{device_enumerator.cpp} Namespace Reference

Functions

std::string trim (const std::string &s)
std::string read_text_file (const fs::path &p)
uint64_t read_u64_file (const fs::path &p)
bool starts_with (const std::string &s, const std::string &prefix)
bool is_real_disk_name (const std::string &name)

Function Documentation

◆ is_real_disk_name()

bool anonymous_namespace{device_enumerator.cpp}::is_real_disk_name ( const std::string & name)

Definition at line 39 of file device_enumerator.cpp.

39 {
40 return starts_with(name, "sd") ||
41 starts_with(name, "nvme") ||
42 starts_with(name, "mmcblk") ||
43 starts_with(name, "vd") ||
44 starts_with(name, "hd") ||
45 starts_with(name, "md") ||
46 starts_with(name, "dm-") ||
47 starts_with(name, "loop");
48 }
bool starts_with(const std::string &s, const std::string &prefix)

References is_real_disk_name(), and starts_with().

Referenced by is_real_disk_name().

◆ read_text_file()

std::string anonymous_namespace{device_enumerator.cpp}::read_text_file ( const fs::path & p)

Definition at line 20 of file device_enumerator.cpp.

20 {
21 std::ifstream f(p);
22 if (!f) return "";
23 std::ostringstream ss;
24 ss << f.rdbuf();
25 return trim(ss.str());
26 }
std::string trim(const std::string &s)

References read_text_file(), and trim().

Referenced by read_text_file().

◆ read_u64_file()

uint64_t anonymous_namespace{device_enumerator.cpp}::read_u64_file ( const fs::path & p)

Definition at line 28 of file device_enumerator.cpp.

28 {
29 std::ifstream f(p);
30 uint64_t v = 0;
31 if (f) f >> v;
32 return v;
33 }

References read_u64_file().

Referenced by read_u64_file().

◆ starts_with()

bool anonymous_namespace{device_enumerator.cpp}::starts_with ( const std::string & s,
const std::string & prefix )

Definition at line 35 of file device_enumerator.cpp.

35 {
36 return s.rfind(prefix, 0) == 0;
37 }

References starts_with().

Referenced by is_real_disk_name(), and starts_with().

◆ trim()

std::string anonymous_namespace{device_enumerator.cpp}::trim ( const std::string & s)

Definition at line 13 of file device_enumerator.cpp.

13 {
14 const auto start = s.find_first_not_of(" \t\r\n");
15 if (start == std::string::npos) return "";
16 const auto end = s.find_last_not_of(" \t\r\n");
17 return s.substr(start, end - start + 1);
18 }

References trim().

Referenced by read_text_file(), and trim().