StormByte-System 2.0.0
C++26 process and environment module of the StormByte suite
 
Loading...
Searching...
No Matches
device.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-System.
5 *
6 * StormByte-System original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-System source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte Base tree), which
23 * remains under its own license.
24 *
25 * Neither license grants any patent rights. Any patent licenses required
26 * to use this software or third-party components must be obtained separately
27 * from the patent holders.
28 *
29 * StormByte-System is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU Lesser General Public License for more details.
33 *
34 * You should have received a copy of the GNU Lesser General Public License
35 * version 3 along with StormByte-System. If not, see
36 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
37 *
38 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
39 */
40
41#pragma once
42
43#include <StormByte/bitmask.hxx>
44#include <StormByte/error.hxx>
45#include <StormByte/size.hxx>
48
49#include <cstdint>
50#include <filesystem>
51#include <string>
52#include <string_view>
53#include <system_error>
54
89 public:
96 enum class Error {
97 Success = 0,
98 BrokenSymlink,
99 DeviceNotFound,
100 NotADevice,
101 Permission,
102 ProbeFailed
103 };
104
111 enum class Kind {
112 HDD,
113 SSD,
114 NVMeGen3,
115 NVMeGen4,
116 NVMeGen5,
117 USBHDD,
118 USBStick,
119 Network
120 };
121
128 enum class AccessFlag: std::uint8_t {
129 Readable = 0x01,
130 Writable = 0x02
131 };
132
137 class STORMBYTE_SYSTEM_PUBLIC Access: public StormByte::Bitmask<Access, AccessFlag> {
138 public:
139 using Bitmask::Bitmask;
140 };
141
148 struct Throughput {
149 std::size_t read_bps;
150 std::size_t write_bps;
151 };
152
163
173 explicit Device(const StormByte::String::String& path) noexcept;
174
179 explicit Device(std::string_view path) noexcept;
180
185 explicit Device(std::wstring_view path) noexcept;
186
191 explicit Device(const std::filesystem::path& path) noexcept;
192
196 Device(const Device&) = default;
197
201 Device(Device&&) noexcept = default;
202
206 Device& operator=(const Device&) = default;
207
211 Device& operator=(Device&&) noexcept = default;
212
216 virtual ~Device() = default;
217
229 explicit operator bool() const noexcept;
230
235 StormByte::Error::Fault Fault() const noexcept;
236
241 const StormByte::String::String& Path() const noexcept;
242
254 enum Kind Kind() const noexcept;
255
260 class Access Access() const noexcept;
261
268 virtual struct Throughput Throughput() const noexcept;
269
276 virtual struct Window Window() const noexcept;
277
280 private:
281 StormByte::String::String m_path;
282 };
283}
284
288template<>
289struct StormByte::Error::Domain<StormByte::System::Device::Error> {
290 static constexpr const char* Name = "StormByte.System.Device";
291
298 switch (e) {
300 return "Success";
302 return "Broken symbolic link";
304 return "Device not found";
306 return "Path is not a classifiable device";
308 return "Device permission denied";
310 return "Device probe failed";
311 }
312 return "Unknown Device error";
313 }
314};
315
316namespace StormByte::System {
322
328 STORMBYTE_SYSTEM_PUBLIC std::error_code make_error_code(Device::Error e) noexcept;
329}
330
331namespace std {
335 template<>
336 struct is_error_code_enum<StormByte::System::Device::Error>: true_type {};
337}
Bitmask of AccessFlag.
Definition device.hxx:137
Query object for the medium behind a filesystem accessor.
Definition device.hxx:88
Error
Device classification and probe enumerators.
Definition device.hxx:96
@ NotADevice
The path exists but is not a classifiable file, directory or device node.
@ ProbeFailed
Classification I/O failed.
@ BrokenSymlink
The path is a symlink whose target does not exist.
@ DeviceNotFound
No volume or node could be resolved.
@ Permission
The process may not stat or access this path.
Device(const StormByte::String::String &path) noexcept
Store an owned UTF-8 accessor.
Device(std::string_view path) noexcept
Store a UTF-8 accessor view.
Device(std::wstring_view path) noexcept
Store a wide accessor as UTF-8 text.
Device(const std::filesystem::path &path) noexcept
Store a filesystem path as UTF-8 text.
AccessFlag
Transfer permission of this path for this process.
Definition device.hxx:128
Device(Device &&) noexcept=default
Move constructor.
Kind
Classified storage or network medium.
Definition device.hxx:111
Device(const Device &)=default
Copy constructor.
System module of the StormByte suite.
Definition device.hxx:58
const StormByte::Error::Category< Device::Error > & device_category() noexcept
Category singleton for Device::Error.
STL namespace.
static std::string Message(StormByte::System::Device::Error e)
Text for one Device enumerator.
Definition device.hxx:297
Nominal sequential rates of the resolved medium.
Definition device.hxx:148
std::size_t write_bps
Nominal sequential write.
Definition device.hxx:150
std::size_t read_bps
Nominal sequential read.
Definition device.hxx:149
Suggested transfer windows derived from Throughput.
Definition device.hxx:159
StormByte::Size write
Suggested write window.
Definition device.hxx:161
StormByte::Size read
Suggested read window.
Definition device.hxx:160
#define STORMBYTE_SYSTEM_PUBLIC
Definition visibility.h:53