Merge branch 'master' into nbd
This commit is contained in:
commit
cd55079217
7 changed files with 61 additions and 9 deletions
|
@ -7,10 +7,9 @@
|
|||
|
||||
|
||||
disk_backend_esp32::disk_backend_esp32(const std::string & filename) :
|
||||
filename(filename),
|
||||
fh(new File32())
|
||||
{
|
||||
if (!fh->open(filename.c_str(), O_RDWR))
|
||||
error_exit(true, "rk05: cannot open \"%s\"", filename.c_str());
|
||||
}
|
||||
|
||||
disk_backend_esp32::~disk_backend_esp32()
|
||||
|
@ -20,6 +19,17 @@ disk_backend_esp32::~disk_backend_esp32()
|
|||
delete fh;
|
||||
}
|
||||
|
||||
bool disk_backend_esp32::begin()
|
||||
{
|
||||
if (!fh->open(filename.c_str(), O_RDWR)) {
|
||||
DOLOG(ll_error, true, "rk05: cannot open \"%s\"", filename.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool disk_backend_esp32::read(const off_t offset, const size_t n, uint8_t *const target)
|
||||
{
|
||||
DOLOG(debug, false, "disk_backend_esp32::read: read %zu bytes from offset %zu", n, offset);
|
||||
|
|
|
@ -7,12 +7,15 @@
|
|||
class disk_backend_esp32 : public disk_backend
|
||||
{
|
||||
private:
|
||||
File32 *const fh { nullptr };
|
||||
const std::string filename;
|
||||
File32 *const fh { nullptr };
|
||||
|
||||
public:
|
||||
disk_backend_esp32(const std::string & filename);
|
||||
virtual ~disk_backend_esp32();
|
||||
|
||||
bool begin();
|
||||
|
||||
bool read(const off_t offset, const size_t n, uint8_t *const target);
|
||||
|
||||
bool write(const off_t offset, const size_t n, const uint8_t *const from);
|
||||
|
|
|
@ -147,11 +147,22 @@ std::pair<std::vector<disk_backend *>, std::vector<disk_backend *> > select_disk
|
|||
if (fh.open(selected_file.c_str(), O_RDWR)) {
|
||||
fh.close();
|
||||
|
||||
disk_backend *temp = new disk_backend_esp32(selected_file);
|
||||
|
||||
if (!temp->begin()) {
|
||||
c->put_string("Cannot use: ");
|
||||
c->put_string_lf(selected_file.c_str());
|
||||
|
||||
delete temp;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == '1')
|
||||
return { { new disk_backend_esp32(selected_file) }, { } };
|
||||
return { { temp }, { } };
|
||||
|
||||
if (ch == '2')
|
||||
return { { }, { new disk_backend_esp32(selected_file) } };
|
||||
return { { }, { temp } };
|
||||
}
|
||||
|
||||
c->put_string_lf("open failed");
|
||||
|
|
|
@ -10,6 +10,8 @@ public:
|
|||
disk_backend();
|
||||
virtual ~disk_backend();
|
||||
|
||||
virtual bool begin() = 0;
|
||||
|
||||
virtual bool read(const off_t offset, const size_t n, uint8_t *const target) = 0;
|
||||
|
||||
virtual bool write(const off_t offset, const size_t n, const uint8_t *const from) = 0;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "disk_backend_file.h"
|
||||
|
@ -6,7 +7,7 @@
|
|||
|
||||
|
||||
disk_backend_file::disk_backend_file(const std::string & filename) :
|
||||
fd(open(filename.c_str(), O_RDWR))
|
||||
filename(filename)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -15,6 +16,19 @@ disk_backend_file::~disk_backend_file()
|
|||
close(fd);
|
||||
}
|
||||
|
||||
bool disk_backend_file::begin()
|
||||
{
|
||||
fd = open(filename.c_str(), O_RDWR);
|
||||
|
||||
if (fd == -1) {
|
||||
DOLOG(ll_error, true, "disk_backend_file: cannot open \"%s\": %s", filename.c_str(), strerror(errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool disk_backend_file::read(const off_t offset, const size_t n, uint8_t *const target)
|
||||
{
|
||||
DOLOG(debug, false, "disk_backend_file::read: read %zu bytes from offset %zu", n, offset);
|
||||
|
|
|
@ -6,12 +6,16 @@
|
|||
class disk_backend_file : public disk_backend
|
||||
{
|
||||
private:
|
||||
const int fd { -1 };
|
||||
const std::string filename;
|
||||
|
||||
int fd { -1 };
|
||||
|
||||
public:
|
||||
disk_backend_file(const std::string & filename);
|
||||
virtual ~disk_backend_file();
|
||||
|
||||
bool begin();
|
||||
|
||||
bool read(const off_t offset, const size_t n, uint8_t *const target);
|
||||
|
||||
bool write(const off_t offset, const size_t n, const uint8_t *const from);
|
||||
|
|
12
main.cpp
12
main.cpp
|
@ -82,6 +82,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
std::string test;
|
||||
|
||||
disk_backend *temp_d = nullptr;
|
||||
|
||||
int opt = -1;
|
||||
while((opt = getopt(argc, argv, "hm:T:r:R:p:ndtL:b:l:s:Q:")) != -1)
|
||||
{
|
||||
|
@ -134,11 +136,17 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 'R':
|
||||
rk05_files.push_back(new disk_backend_file(optarg));
|
||||
temp_d = new disk_backend_file(optarg);
|
||||
if (!temp_d->begin())
|
||||
error_exit(false, "Cannot use file \"%s\" for RK05", optarg);
|
||||
rk05_files.push_back(temp_d);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
rl02_files.push_back(new disk_backend_file(optarg));
|
||||
temp_d = new disk_backend_file(optarg);
|
||||
if (!temp_d->begin())
|
||||
error_exit(false, "Cannot use file \"%s\" for RL02", optarg);
|
||||
rl02_files.push_back(temp_d);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
|
|
Loading…
Add table
Reference in a new issue