-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdisk_backend_nbd.h
More file actions
48 lines (37 loc) · 1.18 KB
/
Copy pathdisk_backend_nbd.h
File metadata and controls
48 lines (37 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// (C) 2018-2026 by Folkert van Heusden
// Released under MIT license
#if defined(BUILD_FOR_PICO2W)
#include <Arduino.h>
#include <WiFiClient.h>
#endif
#include <string>
#include <sys/types.h>
#include "disk_backend.h"
#include "gen.h"
#include "utils.h"
class disk_backend_nbd : public disk_backend
{
private:
const std::string host;
const unsigned port { 0 };
#if defined(BUILD_FOR_PICO2W)
WiFiClient handle;
#elif defined(TEENSY4_1)
qn::EthernetClient handle;
#else
int fd { -1 };
#endif
bool connect(const bool retry);
public:
disk_backend_nbd(const std::string & host, const unsigned port);
virtual ~disk_backend_nbd();
#if IS_POSIX
JsonDocument serialize() override;
static disk_backend_nbd *deserialize(const JsonVariantConst j);
#endif
std::string get_identifier() const override { return format("NBD:%s:%d", host.c_str(), port); }
void show_state(console *const cnsl) const override;
bool begin(const bool snapshots) override;
bool read(const off_t offset, const size_t n, uint8_t *const target, const size_t sector_size) override;
bool write(const off_t offset, const size_t n, const uint8_t *const from, const size_t sector_size) override;
};