mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-14 14:29:33 +00:00
SCSI Dump Usability Enhancements & Cleanup (#1026)
Co-authored-by: Tony Kuker <akuker@gmail.com>
This commit is contained in:
parent
35447cc1c6
commit
5b3626dcf5
|
@ -9,3 +9,4 @@ AlignTrailingComments: True
|
||||||
AllowShortEnumsOnASingleLine: True
|
AllowShortEnumsOnASingleLine: True
|
||||||
AlignConsecutiveAssignments: Consecutive
|
AlignConsecutiveAssignments: Consecutive
|
||||||
ColumnLimit: 120
|
ColumnLimit: 120
|
||||||
|
PointerAlignment: Left
|
|
@ -21,10 +21,12 @@ using namespace std;
|
||||||
|
|
||||||
unique_ptr<BUS> GPIOBUS_Factory::Create(BUS::mode_e mode)
|
unique_ptr<BUS> GPIOBUS_Factory::Create(BUS::mode_e mode)
|
||||||
{
|
{
|
||||||
|
unique_ptr<BUS> return_ptr;
|
||||||
|
|
||||||
|
try {
|
||||||
// TODO Make the factory a friend of GPIOBUS and make the GPIOBUS constructor private
|
// TODO Make the factory a friend of GPIOBUS and make the GPIOBUS constructor private
|
||||||
// so that clients cannot use it anymore but have to use the factory.
|
// so that clients cannot use it anymore but have to use the factory.
|
||||||
// Also make Init() private.
|
// Also make Init() private.
|
||||||
unique_ptr<BUS> return_ptr;
|
|
||||||
SBC_Version::Init();
|
SBC_Version::Init();
|
||||||
if (SBC_Version::IsBananaPi()) {
|
if (SBC_Version::IsBananaPi()) {
|
||||||
LOGTRACE("Creating GPIOBUS_BananaM2p")
|
LOGTRACE("Creating GPIOBUS_BananaM2p")
|
||||||
|
@ -40,5 +42,10 @@ unique_ptr<BUS> GPIOBUS_Factory::Create(BUS::mode_e mode)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return_ptr->Reset();
|
return_ptr->Reset();
|
||||||
|
} catch (const invalid_argument&) {
|
||||||
|
LOGERROR("Exception while trying to initialize GPIO bus. Are you running as root?")
|
||||||
|
return_ptr = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return return_ptr;
|
return return_ptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,5 +15,5 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const vector<char *> args(argv, argv + argc);
|
const vector<char *> args(argv, argv + argc);
|
||||||
|
|
||||||
return RasDump().run(args);
|
return ScsiDump().run(args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,61 +6,66 @@
|
||||||
// Powered by XM6 TypeG Technology.
|
// Powered by XM6 TypeG Technology.
|
||||||
// Copyright (C) 2016-2020 GIMONS
|
// Copyright (C) 2016-2020 GIMONS
|
||||||
// Copyright (C) 2022 Uwe Seimet
|
// Copyright (C) 2022 Uwe Seimet
|
||||||
|
// Copyright (C) 2022 akuker
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
// TODO Evaluate CHECK CONDITION after sending a command
|
// TODO Evaluate CHECK CONDITION after sending a command
|
||||||
// TODO Send IDENTIFY message in order to support LUNS > 7
|
// TODO Send IDENTIFY message in order to support LUNS > 7
|
||||||
|
|
||||||
#include "shared/log.h"
|
|
||||||
#include "shared/piscsi_util.h"
|
|
||||||
#include "shared/piscsi_exceptions.h"
|
|
||||||
#include "shared/piscsi_version.h"
|
|
||||||
#include "hal/gpiobus_factory.h"
|
|
||||||
#include "hal/gpiobus.h"
|
|
||||||
#include "hal/systimer.h"
|
|
||||||
#include "scsidump/scsidump_core.h"
|
#include "scsidump/scsidump_core.h"
|
||||||
#include <sys/stat.h>
|
#include "hal/gpiobus.h"
|
||||||
|
#include "hal/gpiobus_factory.h"
|
||||||
|
#include "hal/systimer.h"
|
||||||
|
#include "shared/log.h"
|
||||||
|
#include "shared/piscsi_exceptions.h"
|
||||||
|
#include "shared/piscsi_util.h"
|
||||||
|
#include "shared/piscsi_version.h"
|
||||||
|
#include <chrono>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <unistd.h>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace spdlog;
|
using namespace spdlog;
|
||||||
using namespace scsi_defs;
|
using namespace scsi_defs;
|
||||||
using namespace piscsi_util;
|
using namespace piscsi_util;
|
||||||
|
|
||||||
void RasDump::CleanUp()
|
void ScsiDump::CleanUp()
|
||||||
{
|
{
|
||||||
if (bus != nullptr) {
|
if (bus != nullptr) {
|
||||||
bus->Cleanup();
|
bus->Cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::KillHandler(int)
|
void ScsiDump::KillHandler(int)
|
||||||
{
|
{
|
||||||
CleanUp();
|
CleanUp();
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RasDump::Banner(const vector<char *>& args) const
|
bool ScsiDump::Banner(const vector<char*>& args) const
|
||||||
{
|
{
|
||||||
cout << piscsi_util::Banner("(Hard Disk Dump/Restore Utility)");
|
cout << piscsi_util::Banner("(Hard Disk Dump/Restore Utility)");
|
||||||
|
|
||||||
if (args.size() < 2 || string(args[1]) == "-h") {
|
if (args.size() < 2 || string(args[1]) == "-h" || string(args[1]) == "--help") {
|
||||||
cout << "Usage: " << args[0] << " -t ID[:LUN] [-i BID] -f FILE [-v] [-r] [-s BUFFER_SIZE]\n"
|
cout << "Usage: " << args[0] << " -t ID[:LUN] [-i BID] -f FILE [-v] [-r] [-s BUFFER_SIZE] [-p]\n"
|
||||||
<< " ID is the target device ID (0-7).\n"
|
<< " ID is the target device ID (0-7).\n"
|
||||||
<< " LUN is the optional target device LUN (0-7). Default is 0.\n"
|
<< " LUN is the optional target device LUN (0-7). Default is 0.\n"
|
||||||
<< " BID is the PiSCSI board ID (0-7). Default is 7.\n"
|
<< " BID is the PiSCSI board ID (0-7). Default is 7.\n"
|
||||||
<< " FILE is the dump file path.\n"
|
<< " FILE is the dump file path.\n"
|
||||||
<< " BUFFER_SIZE is the transfer buffer size, at least "
|
<< " BUFFER_SIZE is the transfer buffer size in bytes, at least " << to_string(MINIMUM_BUFFER_SIZE)
|
||||||
<< to_string(MINIMUM_BUFFER_SIZE / 1024) << " KiB. Default is 1 MiB.\n"
|
<< " bytes. Default is 1 MiB.\n"
|
||||||
<< " -v Enable verbose logging.\n"
|
<< " -v Enable verbose logging.\n"
|
||||||
<< " -r Restore instead of dump.\n" << flush;
|
<< " -r Restore instead of dump.\n"
|
||||||
|
<< " -p Generate .properties file to be used with the PiSCSI web interface. Only valid for dump mode.\n"
|
||||||
|
<< flush;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +73,7 @@ bool RasDump::Banner(const vector<char *>& args) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RasDump::Init() const
|
bool ScsiDump::Init() const
|
||||||
{
|
{
|
||||||
// Interrupt handler setting
|
// Interrupt handler setting
|
||||||
if (signal(SIGINT, KillHandler) == SIG_ERR || signal(SIGHUP, KillHandler) == SIG_ERR ||
|
if (signal(SIGINT, KillHandler) == SIG_ERR || signal(SIGHUP, KillHandler) == SIG_ERR ||
|
||||||
|
@ -81,14 +86,14 @@ bool RasDump::Init() const
|
||||||
return bus != nullptr;
|
return bus != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::ParseArguments(const vector<char *>& args)
|
void ScsiDump::ParseArguments(const vector<char*>& args)
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
int buffer_size = DEFAULT_BUFFER_SIZE;
|
int buffer_size = DEFAULT_BUFFER_SIZE;
|
||||||
|
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
while ((opt = getopt(static_cast<int>(args.size()), args.data(), "i:f:s:t:rv")) != -1) {
|
while ((opt = getopt(static_cast<int>(args.size()), args.data(), "i:f:s:t:rvp")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'i':
|
case 'i':
|
||||||
if (!GetAsUnsignedInt(optarg, initiator_id) || initiator_id > 7) {
|
if (!GetAsUnsignedInt(optarg, initiator_id) || initiator_id > 7) {
|
||||||
|
@ -112,8 +117,7 @@ void RasDump::ParseArguments(const vector<char *>& args)
|
||||||
if (!error.empty()) {
|
if (!error.empty()) {
|
||||||
throw parser_exception(error);
|
throw parser_exception(error);
|
||||||
}
|
}
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
set_level(level::debug);
|
set_level(level::debug);
|
||||||
|
@ -123,6 +127,10 @@ void RasDump::ParseArguments(const vector<char *>& args)
|
||||||
restore = true;
|
restore = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
properties_file = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +147,7 @@ void RasDump::ParseArguments(const vector<char *>& args)
|
||||||
buffer = vector<uint8_t>(buffer_size);
|
buffer = vector<uint8_t>(buffer_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::WaitPhase(phase_t phase) const
|
void ScsiDump::WaitPhase(phase_t phase) const
|
||||||
{
|
{
|
||||||
LOGDEBUG("Waiting for %s phase", BUS::GetPhaseStrRaw(phase))
|
LOGDEBUG("Waiting for %s phase", BUS::GetPhaseStrRaw(phase))
|
||||||
|
|
||||||
|
@ -152,11 +160,11 @@ void RasDump::WaitPhase(phase_t phase) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw parser_exception("Expected " + string(BUS::GetPhaseStrRaw(phase)) + " phase, actual phase is "
|
throw parser_exception("Expected " + string(BUS::GetPhaseStrRaw(phase)) + " phase, actual phase is " +
|
||||||
+ string(BUS::GetPhaseStrRaw(bus->GetPhase())));
|
string(BUS::GetPhaseStrRaw(bus->GetPhase())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::Selection() const
|
void ScsiDump::Selection() const
|
||||||
{
|
{
|
||||||
// Set initiator and target ID
|
// Set initiator and target ID
|
||||||
auto data = static_cast<byte>(1 << initiator_id);
|
auto data = static_cast<byte>(1 << initiator_id);
|
||||||
|
@ -170,7 +178,7 @@ void RasDump::Selection() const
|
||||||
bus->SetSEL(false);
|
bus->SetSEL(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::Command(scsi_command cmd, vector<uint8_t>& cdb) const
|
void ScsiDump::Command(scsi_command cmd, vector<uint8_t>& cdb) const
|
||||||
{
|
{
|
||||||
LOGDEBUG("Executing %s", command_mapping.find(cmd)->second.second)
|
LOGDEBUG("Executing %s", command_mapping.find(cmd)->second.second)
|
||||||
|
|
||||||
|
@ -180,14 +188,15 @@ void RasDump::Command(scsi_command cmd, vector<uint8_t>& cdb) const
|
||||||
|
|
||||||
cdb[0] = static_cast<uint8_t>(cmd);
|
cdb[0] = static_cast<uint8_t>(cmd);
|
||||||
cdb[1] = static_cast<uint8_t>(static_cast<byte>(cdb[1]) | static_cast<byte>(target_lun << 5));
|
cdb[1] = static_cast<uint8_t>(static_cast<byte>(cdb[1]) | static_cast<byte>(target_lun << 5));
|
||||||
if (static_cast<int>(cdb.size()) != bus->SendHandShake(cdb.data(), static_cast<int>(cdb.size()), BUS::SEND_NO_DELAY)) {
|
if (static_cast<int>(cdb.size()) !=
|
||||||
|
bus->SendHandShake(cdb.data(), static_cast<int>(cdb.size()), BUS::SEND_NO_DELAY)) {
|
||||||
BusFree();
|
BusFree();
|
||||||
|
|
||||||
throw parser_exception(command_mapping.find(cmd)->second.second + string(" failed"));
|
throw parser_exception(command_mapping.find(cmd)->second.second + string(" failed"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::DataIn(int length)
|
void ScsiDump::DataIn(int length)
|
||||||
{
|
{
|
||||||
WaitPhase(phase_t::datain);
|
WaitPhase(phase_t::datain);
|
||||||
|
|
||||||
|
@ -196,7 +205,7 @@ void RasDump::DataIn(int length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::DataOut(int length)
|
void ScsiDump::DataOut(int length)
|
||||||
{
|
{
|
||||||
WaitPhase(phase_t::dataout);
|
WaitPhase(phase_t::dataout);
|
||||||
|
|
||||||
|
@ -205,7 +214,7 @@ void RasDump::DataOut(int length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::Status() const
|
void ScsiDump::Status() const
|
||||||
{
|
{
|
||||||
WaitPhase(phase_t::status);
|
WaitPhase(phase_t::status);
|
||||||
|
|
||||||
|
@ -214,7 +223,7 @@ void RasDump::Status() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::MessageIn() const
|
void ScsiDump::MessageIn() const
|
||||||
{
|
{
|
||||||
WaitPhase(phase_t::msgin);
|
WaitPhase(phase_t::msgin);
|
||||||
|
|
||||||
|
@ -223,12 +232,12 @@ void RasDump::MessageIn() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::BusFree() const
|
void ScsiDump::BusFree() const
|
||||||
{
|
{
|
||||||
bus->Reset();
|
bus->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::TestUnitReady() const
|
void ScsiDump::TestUnitReady() const
|
||||||
{
|
{
|
||||||
vector<uint8_t> cdb(6);
|
vector<uint8_t> cdb(6);
|
||||||
Command(scsi_command::eCmdTestUnitReady, cdb);
|
Command(scsi_command::eCmdTestUnitReady, cdb);
|
||||||
|
@ -240,7 +249,7 @@ void RasDump::TestUnitReady() const
|
||||||
BusFree();
|
BusFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::RequestSense()
|
void ScsiDump::RequestSense()
|
||||||
{
|
{
|
||||||
vector<uint8_t> cdb(6);
|
vector<uint8_t> cdb(6);
|
||||||
cdb[4] = 0xff;
|
cdb[4] = 0xff;
|
||||||
|
@ -255,7 +264,7 @@ void RasDump::RequestSense()
|
||||||
BusFree();
|
BusFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::Inquiry()
|
void ScsiDump::Inquiry()
|
||||||
{
|
{
|
||||||
vector<uint8_t> cdb(6);
|
vector<uint8_t> cdb(6);
|
||||||
cdb[4] = 0xff;
|
cdb[4] = 0xff;
|
||||||
|
@ -270,7 +279,7 @@ void RasDump::Inquiry()
|
||||||
BusFree();
|
BusFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<uint64_t, uint32_t> RasDump::ReadCapacity()
|
pair<uint64_t, uint32_t> ScsiDump::ReadCapacity()
|
||||||
{
|
{
|
||||||
vector<uint8_t> cdb(10);
|
vector<uint8_t> cdb(10);
|
||||||
Command(scsi_command::eCmdReadCapacity10, cdb);
|
Command(scsi_command::eCmdReadCapacity10, cdb);
|
||||||
|
@ -318,7 +327,7 @@ pair<uint64_t, uint32_t> RasDump::ReadCapacity()
|
||||||
return make_pair(capacity, sector_size);
|
return make_pair(capacity, sector_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::Read10(uint32_t bstart, uint32_t blength, uint32_t length)
|
void ScsiDump::Read10(uint32_t bstart, uint32_t blength, uint32_t length)
|
||||||
{
|
{
|
||||||
vector<uint8_t> cdb(10);
|
vector<uint8_t> cdb(10);
|
||||||
cdb[2] = (uint8_t)(bstart >> 24);
|
cdb[2] = (uint8_t)(bstart >> 24);
|
||||||
|
@ -338,7 +347,7 @@ void RasDump::Read10(uint32_t bstart, uint32_t blength, uint32_t length)
|
||||||
BusFree();
|
BusFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::Write10(uint32_t bstart, uint32_t blength, uint32_t length)
|
void ScsiDump::Write10(uint32_t bstart, uint32_t blength, uint32_t length)
|
||||||
{
|
{
|
||||||
vector<uint8_t> cdb(10);
|
vector<uint8_t> cdb(10);
|
||||||
cdb[2] = (uint8_t)(bstart >> 24);
|
cdb[2] = (uint8_t)(bstart >> 24);
|
||||||
|
@ -358,7 +367,7 @@ void RasDump::Write10(uint32_t bstart, uint32_t blength, uint32_t length)
|
||||||
BusFree();
|
BusFree();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasDump::WaitForBusy() const
|
void ScsiDump::WaitForBusy() const
|
||||||
{
|
{
|
||||||
// Wait for busy for up to 2 s
|
// Wait for busy for up to 2 s
|
||||||
int count = 10000;
|
int count = 10000;
|
||||||
|
@ -378,7 +387,7 @@ void RasDump::WaitForBusy() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int RasDump::run(const vector<char *>& args)
|
int ScsiDump::run(const vector<char*>& args)
|
||||||
{
|
{
|
||||||
if (!Banner(args)) {
|
if (!Banner(args)) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -400,8 +409,7 @@ int RasDump::run(const vector<char *>& args)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return DumpRestore();
|
return DumpRestore();
|
||||||
}
|
} catch (const parser_exception& e) {
|
||||||
catch(const parser_exception& e) {
|
|
||||||
cerr << "Error: " << e.what() << endl;
|
cerr << "Error: " << e.what() << endl;
|
||||||
|
|
||||||
CleanUp();
|
CleanUp();
|
||||||
|
@ -414,9 +422,9 @@ int RasDump::run(const vector<char *>& args)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RasDump::DumpRestore()
|
int ScsiDump::DumpRestore()
|
||||||
{
|
{
|
||||||
const auto [capacity, sector_size] = GetDeviceInfo();
|
const auto inq_info = GetDeviceInfo();
|
||||||
|
|
||||||
fstream fs;
|
fstream fs;
|
||||||
fs.open(filename, (restore ? ios::in : ios::out) | ios::binary);
|
fs.open(filename, (restore ? ios::in : ios::out) | ios::binary);
|
||||||
|
@ -432,34 +440,33 @@ int RasDump::DumpRestore()
|
||||||
off_t size;
|
off_t size;
|
||||||
if (struct stat st; !stat(filename.c_str(), &st)) {
|
if (struct stat st; !stat(filename.c_str(), &st)) {
|
||||||
size = st.st_size;
|
size = st.st_size;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw parser_exception("Can't determine file size");
|
throw parser_exception("Can't determine file size");
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Restore file size: " << size << " bytes\n";
|
cout << "Restore file size: " << size << " bytes\n";
|
||||||
if (size > (off_t)(sector_size * capacity)) {
|
if (size > (off_t)(inq_info.sector_size * inq_info.capacity)) {
|
||||||
cout << "WARNING: File size is larger than disk size\n" << flush;
|
cout << "WARNING: File size is larger than disk size\n" << flush;
|
||||||
} else if (size < (off_t)(sector_size * capacity)) {
|
} else if (size < (off_t)(inq_info.sector_size * inq_info.capacity)) {
|
||||||
throw parser_exception("File size is smaller than disk size");
|
throw parser_exception("File size is smaller than disk size");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
cout << "Starting dump\n" << flush;
|
cout << "Starting dump\n" << flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dump by buffer size
|
// Dump by buffer size
|
||||||
auto dsiz = static_cast<int>(buffer.size());
|
auto dsiz = static_cast<int>(buffer.size());
|
||||||
const int duni = dsiz / sector_size;
|
const int duni = dsiz / inq_info.sector_size;
|
||||||
auto dnum = static_cast<int>((capacity * sector_size) / dsiz);
|
auto dnum = static_cast<int>((inq_info.capacity * inq_info.sector_size) / dsiz);
|
||||||
|
|
||||||
|
auto start_time = chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < dnum; i++) {
|
for (i = 0; i < dnum; i++) {
|
||||||
if (restore) {
|
if (restore) {
|
||||||
fs.read((char*)buffer.data(), dsiz);
|
fs.read((char*)buffer.data(), dsiz);
|
||||||
Write10(i * duni, duni, dsiz);
|
Write10(i * duni, duni, dsiz);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Read10(i * duni, duni, dsiz);
|
Read10(i * duni, duni, dsiz);
|
||||||
fs.write((const char*)buffer.data(), dsiz);
|
fs.write((const char*)buffer.data(), dsiz);
|
||||||
}
|
}
|
||||||
|
@ -468,20 +475,21 @@ int RasDump::DumpRestore()
|
||||||
throw parser_exception("File I/O failed");
|
throw parser_exception("File I/O failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << ((i + 1) * 100 / dnum) << "%" << " (" << ( i + 1) * duni << "/" << capacity << ")\n" << flush;
|
cout << ((i + 1) * 100 / dnum) << "%"
|
||||||
|
<< " (" << (i + 1) * duni << "/" << inq_info.capacity << ")\n"
|
||||||
|
<< flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rounding on capacity
|
// Rounding on capacity
|
||||||
dnum = capacity % duni;
|
dnum = inq_info.capacity % duni;
|
||||||
dsiz = dnum * sector_size;
|
dsiz = dnum * inq_info.sector_size;
|
||||||
if (dnum > 0) {
|
if (dnum > 0) {
|
||||||
if (restore) {
|
if (restore) {
|
||||||
fs.read((char*)buffer.data(), dsiz);
|
fs.read((char*)buffer.data(), dsiz);
|
||||||
if (!fs.fail()) {
|
if (!fs.fail()) {
|
||||||
Write10(i * duni, dnum, dsiz);
|
Write10(i * duni, dnum, dsiz);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Read10(i * duni, dnum, dsiz);
|
Read10(i * duni, dnum, dsiz);
|
||||||
fs.write((const char*)buffer.data(), dsiz);
|
fs.write((const char*)buffer.data(), dsiz);
|
||||||
}
|
}
|
||||||
|
@ -490,13 +498,30 @@ int RasDump::DumpRestore()
|
||||||
throw parser_exception("File I/O failed");
|
throw parser_exception("File I/O failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "100% (" << capacity << "/" << capacity << ")\n" << flush;
|
cout << "100% (" << inq_info.capacity << "/" << inq_info.capacity << ")\n" << flush;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto stop_time = chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
auto duration = chrono::duration_cast<chrono::seconds>(stop_time - start_time).count();
|
||||||
|
|
||||||
|
cout << divider_str << "\n";
|
||||||
|
cout << "Transfered : " << to_string(inq_info.capacity * inq_info.sector_size) << " bytes ["
|
||||||
|
<< to_string(inq_info.capacity * inq_info.sector_size / 1024 / 1024) << "MiB]\n";
|
||||||
|
cout << "Total time: " << to_string(duration) << " seconds (" << to_string(duration / 60) << " minutes\n";
|
||||||
|
cout << "Averate transfer rate: " << to_string((inq_info.capacity * inq_info.sector_size / 8) / duration)
|
||||||
|
<< " bytes per second (" << to_string((inq_info.capacity * inq_info.sector_size / 8) / duration / 1024)
|
||||||
|
<< " KiB per second)\n";
|
||||||
|
cout << divider_str << "\n";
|
||||||
|
|
||||||
|
if (properties_file && !restore) {
|
||||||
|
GeneratePropertiesFile(filename, inq_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<uint64_t, uint32_t> RasDump::GetDeviceInfo()
|
ScsiDump::inquiry_info_t ScsiDump::GetDeviceInfo()
|
||||||
{
|
{
|
||||||
// Assert RST for 1 ms
|
// Assert RST for 1 ms
|
||||||
bus->SetRST(true);
|
bus->SetRST(true);
|
||||||
|
@ -504,21 +529,30 @@ pair<uint64_t, uint32_t> RasDump::GetDeviceInfo()
|
||||||
nanosleep(&ts, nullptr);
|
nanosleep(&ts, nullptr);
|
||||||
bus->SetRST(false);
|
bus->SetRST(false);
|
||||||
|
|
||||||
|
cout << divider_str << "\n";
|
||||||
|
cout << "PiSCSI board ID: " << initiator_id << "\n";
|
||||||
|
cout << divider_str << "\n" << flush;
|
||||||
cout << "Target device ID: " << target_id << ", LUN: " << target_lun << "\n";
|
cout << "Target device ID: " << target_id << ", LUN: " << target_lun << "\n";
|
||||||
cout << "PiSCSI board ID: " << initiator_id << "\n" << flush;
|
|
||||||
|
|
||||||
Inquiry();
|
Inquiry();
|
||||||
|
|
||||||
|
inquiry_info_t inq_info;
|
||||||
|
|
||||||
// Display INQUIRY information
|
// Display INQUIRY information
|
||||||
array<char, 17> str = {};
|
array<char, 17> str = {};
|
||||||
memcpy(str.data(), &buffer[8], 8);
|
memcpy(str.data(), &buffer[8], 8);
|
||||||
cout << "Vendor: " << str.data() << "\n";
|
cout << "Vendor: " << str.data() << "\n";
|
||||||
|
inq_info.vendor = string(str.data());
|
||||||
|
|
||||||
str.fill(0);
|
str.fill(0);
|
||||||
memcpy(str.data(), &buffer[16], 16);
|
memcpy(str.data(), &buffer[16], 16);
|
||||||
cout << "Product: " << str.data() << "\n";
|
cout << "Product: " << str.data() << "\n";
|
||||||
|
inq_info.product = string(str.data());
|
||||||
|
|
||||||
str.fill(0);
|
str.fill(0);
|
||||||
memcpy(str.data(), &buffer[32], 4);
|
memcpy(str.data(), &buffer[32], 4);
|
||||||
cout << "Revision: " << str.data() << "\n" << flush;
|
cout << "Revision: " << str.data() << "\n" << flush;
|
||||||
|
inq_info.revision = string(str.data());
|
||||||
|
|
||||||
if (auto type = static_cast<device_type>(buffer[0]);
|
if (auto type = static_cast<device_type>(buffer[0]);
|
||||||
type != device_type::DIRECT_ACCESS && type != device_type::CD_ROM && type != device_type::OPTICAL_MEMORY) {
|
type != device_type::DIRECT_ACCESS && type != device_type::CD_ROM && type != device_type::OPTICAL_MEMORY) {
|
||||||
|
@ -530,11 +564,39 @@ pair<uint64_t, uint32_t> RasDump::GetDeviceInfo()
|
||||||
RequestSense();
|
RequestSense();
|
||||||
|
|
||||||
const auto [capacity, sector_size] = ReadCapacity();
|
const auto [capacity, sector_size] = ReadCapacity();
|
||||||
|
inq_info.capacity = capacity;
|
||||||
|
inq_info.sector_size = sector_size;
|
||||||
|
|
||||||
cout << "Number of sectors: " << capacity << "\n"
|
cout << "Sectors: " << capacity << "\n"
|
||||||
<< "Sector size: " << sector_size << " bytes\n"
|
<< "Sector size: " << sector_size << " bytes\n"
|
||||||
<< "Capacity: " << sector_size * capacity / 1024 / 1024 << " MiB ("
|
<< "Capacity: " << sector_size * capacity / 1024 / 1024 << " MiB (" << sector_size * capacity
|
||||||
<< sector_size * capacity << " bytes)\n\n" << flush;
|
<< " bytes)\n"
|
||||||
|
<< divider_str << "\n\n"
|
||||||
|
<< flush;
|
||||||
|
|
||||||
return make_pair(capacity, sector_size);
|
return inq_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScsiDump::GeneratePropertiesFile(const string& filename, const inquiry_info_t& inq_info)
|
||||||
|
{
|
||||||
|
string prop_filename = filename + ".properties";
|
||||||
|
string prop_str;
|
||||||
|
stringstream prop_stream(prop_str);
|
||||||
|
|
||||||
|
prop_stream << "{" << endl;
|
||||||
|
prop_stream << " \"vendor\": \"" << inq_info.vendor << "\"," << endl;
|
||||||
|
prop_stream << " \"product\": \"" << inq_info.product << "\"," << endl;
|
||||||
|
prop_stream << " \"revision\": \"" << inq_info.revision << "\"," << endl;
|
||||||
|
prop_stream << " \"block_size\": \"" << to_string(inq_info.sector_size) << "\"," << endl;
|
||||||
|
prop_stream << "}" << endl;
|
||||||
|
|
||||||
|
FILE* fp = fopen(prop_filename.c_str(), "w");
|
||||||
|
if (fp) {
|
||||||
|
fputs(prop_stream.str().c_str(), fp);
|
||||||
|
} else {
|
||||||
|
LOGWARN("Unable to open output file %s", prop_filename.c_str())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
|
@ -9,33 +9,44 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "shared/scsi.h"
|
|
||||||
#include "hal/bus.h"
|
#include "hal/bus.h"
|
||||||
|
#include "shared/scsi.h"
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class RasDump
|
class ScsiDump
|
||||||
{
|
{
|
||||||
static const int MINIMUM_BUFFER_SIZE = 1024 * 64;
|
static const int MINIMUM_BUFFER_SIZE = 1024 * 64;
|
||||||
static const int DEFAULT_BUFFER_SIZE = 1024 * 1024;
|
static const int DEFAULT_BUFFER_SIZE = 1024 * 1024;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ScsiDump() = default;
|
||||||
RasDump() = default;
|
~ScsiDump() = default;
|
||||||
~RasDump() = default;
|
|
||||||
|
|
||||||
int run(const vector<char*>&);
|
int run(const vector<char*>&);
|
||||||
|
|
||||||
private:
|
struct inquiry_info_struct {
|
||||||
|
string vendor;
|
||||||
|
string product;
|
||||||
|
string revision;
|
||||||
|
uint32_t sector_size;
|
||||||
|
uint64_t capacity;
|
||||||
|
};
|
||||||
|
using inquiry_info_t = struct inquiry_info_struct;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Protected for testability
|
||||||
|
static void GeneratePropertiesFile(const string& filename, const inquiry_info_t& inq_info);
|
||||||
|
|
||||||
|
private:
|
||||||
bool Banner(const vector<char*>&) const;
|
bool Banner(const vector<char*>&) const;
|
||||||
bool Init() const;
|
bool Init() const;
|
||||||
void ParseArguments(const vector<char*>&);
|
void ParseArguments(const vector<char*>&);
|
||||||
int DumpRestore();
|
int DumpRestore();
|
||||||
pair<uint64_t, uint32_t> GetDeviceInfo();
|
inquiry_info_t GetDeviceInfo();
|
||||||
void WaitPhase(phase_t) const;
|
void WaitPhase(phase_t) const;
|
||||||
void Selection() const;
|
void Selection() const;
|
||||||
void Command(scsi_defs::scsi_command, vector<uint8_t>&) const;
|
void Command(scsi_defs::scsi_command, vector<uint8_t>&) const;
|
||||||
|
@ -69,4 +80,8 @@ private:
|
||||||
string filename;
|
string filename;
|
||||||
|
|
||||||
bool restore = false;
|
bool restore = false;
|
||||||
|
|
||||||
|
bool properties_file = false;
|
||||||
|
|
||||||
|
static inline const string divider_str = "----------------------------------------";
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,16 +34,21 @@ FILE *__wrap_fopen(const char *__restrict __filename, const char *__restrict __m
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
path new_filename;
|
path new_filename;
|
||||||
|
auto in_filename = path(__filename);
|
||||||
bool create_directory = false;
|
bool create_directory = false;
|
||||||
|
|
||||||
// If we're trying to open up the device tree soc ranges,
|
// If we're trying to open up the device tree soc ranges,
|
||||||
// re-direct it to a temporary local file.
|
// re-direct it to a temporary local file.
|
||||||
if (string(__filename) == "/proc/device-tree/soc/ranges") {
|
if ((string(__filename) == "/proc/device-tree/soc/ranges") ||
|
||||||
|
(string(__filename).find(".properties") != string::npos)) {
|
||||||
create_directory = true;
|
create_directory = true;
|
||||||
new_filename = test_data_temp_path;
|
new_filename = test_data_temp_path;
|
||||||
new_filename += path(__filename);
|
if (!in_filename.has_parent_path()) {
|
||||||
|
new_filename += "/";
|
||||||
|
}
|
||||||
|
new_filename += in_filename;
|
||||||
} else {
|
} else {
|
||||||
new_filename = path(__filename);
|
new_filename = in_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (create_directory) {
|
if (create_directory) {
|
||||||
|
|
72
cpp/test/scsidump_test.cpp
Normal file
72
cpp/test/scsidump_test.cpp
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SCSI Target Emulator PiSCSI
|
||||||
|
// for Raspberry Pi
|
||||||
|
//
|
||||||
|
// Copyright (C) 2022 akuker
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "mocks.h"
|
||||||
|
#include "scsidump/scsidump_core.h"
|
||||||
|
#include "test/test_shared.h"
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace filesystem;
|
||||||
|
|
||||||
|
class TestableScsidump : public ScsiDump
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void PublicGeneratePropertiesFile(const string& filename, const inquiry_info_t& inq_info)
|
||||||
|
{
|
||||||
|
ScsiDump::GeneratePropertiesFile(filename, inq_info);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(ScsiDumpTest, GeneratePropertiesFile)
|
||||||
|
{
|
||||||
|
// Basic test
|
||||||
|
const string prop_file_name = "test.properties";
|
||||||
|
ScsiDump::inquiry_info_t test_data = {
|
||||||
|
.vendor = "PISCSI", .product = "TEST PRODUCT", .revision = "REV1", .sector_size = 1000, .capacity = 100};
|
||||||
|
TestableScsidump::PublicGeneratePropertiesFile("test", test_data);
|
||||||
|
|
||||||
|
string expected_str = "{\n"
|
||||||
|
" \"vendor\": \"PISCSI\",\n"
|
||||||
|
" \"product\": \"TEST PRODUCT\",\n"
|
||||||
|
" \"revision\": \"REV1\",\n"
|
||||||
|
" \"block_size\": \"1000\",\n}"
|
||||||
|
"\n";
|
||||||
|
EXPECT_EQ(ReadTempFileToString(prop_file_name), expected_str);
|
||||||
|
|
||||||
|
// Long string test
|
||||||
|
test_data = {.vendor = "01234567",
|
||||||
|
.product = "0123456789ABCDEF",
|
||||||
|
.revision = "0123",
|
||||||
|
.sector_size = UINT32_MAX,
|
||||||
|
.capacity = UINT64_MAX};
|
||||||
|
TestableScsidump::PublicGeneratePropertiesFile("test", test_data);
|
||||||
|
|
||||||
|
expected_str = "{\n"
|
||||||
|
" \"vendor\": \"01234567\",\n"
|
||||||
|
" \"product\": \"0123456789ABCDEF\",\n"
|
||||||
|
" \"revision\": \"0123\",\n"
|
||||||
|
" \"block_size\": \"4294967295\",\n"
|
||||||
|
"}\n";
|
||||||
|
EXPECT_EQ(ReadTempFileToString(prop_file_name), expected_str);
|
||||||
|
|
||||||
|
// Empty data test
|
||||||
|
test_data = {.vendor = "", .product = "", .revision = "", .sector_size = 0, .capacity = 0};
|
||||||
|
TestableScsidump::PublicGeneratePropertiesFile("test", test_data);
|
||||||
|
|
||||||
|
expected_str = "{\n"
|
||||||
|
" \"vendor\": \"\",\n"
|
||||||
|
" \"product\": \"\",\n"
|
||||||
|
" \"revision\": \"\",\n"
|
||||||
|
" \"block_size\": \"0\",\n"
|
||||||
|
"}\n";
|
||||||
|
EXPECT_EQ(ReadTempFileToString(prop_file_name), expected_str);
|
||||||
|
}
|
|
@ -13,6 +13,8 @@
|
||||||
#include "shared/piscsi_exceptions.h"
|
#include "shared/piscsi_exceptions.h"
|
||||||
#include "shared/piscsi_version.h"
|
#include "shared/piscsi_version.h"
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -132,6 +134,16 @@ void CleanupAllTempFiles()
|
||||||
remove_all(test_data_temp_path);
|
remove_all(test_data_temp_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string ReadTempFileToString(const string& filename)
|
||||||
|
{
|
||||||
|
path temp_file = test_data_temp_path / path(filename);
|
||||||
|
ifstream in_fs(temp_file);
|
||||||
|
stringstream buffer;
|
||||||
|
buffer << in_fs.rdbuf();
|
||||||
|
|
||||||
|
return buffer.str();
|
||||||
|
}
|
||||||
|
|
||||||
int GetInt16(const vector<byte>& buf, int offset)
|
int GetInt16(const vector<byte>& buf, int offset)
|
||||||
{
|
{
|
||||||
assert(buf.size() > static_cast<size_t>(offset) + 1);
|
assert(buf.size() > static_cast<size_t>(offset) + 1);
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "shared/scsi.h"
|
|
||||||
#include "generated/piscsi_interface.pb.h"
|
#include "generated/piscsi_interface.pb.h"
|
||||||
#include <string>
|
#include "shared/scsi.h"
|
||||||
#include <memory>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace filesystem;
|
using namespace filesystem;
|
||||||
|
@ -26,13 +26,12 @@ extern const path test_data_temp_path;
|
||||||
|
|
||||||
shared_ptr<PrimaryDevice> CreateDevice(PbDeviceType, MockAbstractController&, const string& = "");
|
shared_ptr<PrimaryDevice> CreateDevice(PbDeviceType, MockAbstractController&, const string& = "");
|
||||||
|
|
||||||
void TestInquiry(PbDeviceType, scsi_defs::device_type, scsi_defs::scsi_level, const string&,
|
void TestInquiry(PbDeviceType, scsi_defs::device_type, scsi_defs::scsi_level, const string&, int, bool,
|
||||||
int, bool, const string& = "");
|
const string& = "");
|
||||||
|
|
||||||
pair<int, path> OpenTempFile();
|
pair<int, path> OpenTempFile();
|
||||||
path CreateTempFile(int);
|
path CreateTempFile(int);
|
||||||
|
|
||||||
|
|
||||||
// create a file with the specified data
|
// create a file with the specified data
|
||||||
void CreateTempFileWithData(const string&, vector<uint8_t>&);
|
void CreateTempFileWithData(const string&, vector<uint8_t>&);
|
||||||
|
|
||||||
|
@ -40,5 +39,7 @@ void DeleteTempFile(const string&);
|
||||||
// Call this at the end of every test case to make sure things are cleaned up
|
// Call this at the end of every test case to make sure things are cleaned up
|
||||||
void CleanupAllTempFiles();
|
void CleanupAllTempFiles();
|
||||||
|
|
||||||
|
string ReadTempFileToString(const string& filename);
|
||||||
|
|
||||||
int GetInt16(const vector<byte>&, int);
|
int GetInt16(const vector<byte>&, int);
|
||||||
uint32_t GetInt32(const vector<byte>&, int);
|
uint32_t GetInt32(const vector<byte>&, int);
|
||||||
|
|
|
@ -9,31 +9,53 @@ scsidump \- SCSI disk dumping tool for PiSCSI
|
||||||
[\fB\-s\fR \fIBUFFER_SIZE\fR]
|
[\fB\-s\fR \fIBUFFER_SIZE\fR]
|
||||||
[\fB\-r\fR]
|
[\fB\-r\fR]
|
||||||
[\fB\-v\fR]
|
[\fB\-v\fR]
|
||||||
|
[\fB\-p\fR]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.B scsidump
|
.B scsidump
|
||||||
samples the data on physical SCSI storage media, including hard drives and MO drives, and stores it to an image file. It can also restore from a dumped file onto physical SCSI storage media. Can be connected directly, through a STANDARD PiSCSI board, or a FULLSPEC PiSCSI board.
|
has two modes of operation: dump and restore. These can be used with physical storage media, including hard drives and magneto optical drives. Dump mode can be used with read-only media such as CD/DVD drives.
|
||||||
|
|
||||||
Set its own ID with the BID option. Defaults to 7 if ommitted.
|
When operating in dump mode, scsidump will copy all data from a remote SCSI drive to an image on the local filesystem. If enabled, it will also generate a .properties file that can be used to more closely emulate the source drive.
|
||||||
|
|
||||||
|
If you are operating in restore mode, scsidump will copy the data from a local binary image to a remote physical SCSI drive. The remote SCSI drive MUST be writable.
|
||||||
|
|
||||||
|
.SH NOTES
|
||||||
|
|
||||||
|
.B scsidump
|
||||||
|
requires either a direct connection (one without transceivers) or a FULLSPEC PiSCSI/RaSCSI board.
|
||||||
|
|
||||||
|
If the generated drive image is intended to be used with PiSCSI, the drive image should be moved by the user to ~/images (or the location specified to the piscsi service).
|
||||||
|
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
.BR \-t\fI " "\fIID[:LUN]
|
.BR \-t\fI " "\fIID[:LUN]
|
||||||
SCSI ID and optional LUN of the target device.
|
SCSI ID and optional LUN of the remote SCSI device. The remote SCSI device will be functioning as the "Target" device.
|
||||||
.TP
|
.TP
|
||||||
.BR \-i\fI " "\fIBID
|
.BR \-i\fI " "\fIBID
|
||||||
SCSI ID of the PiSCSI device.
|
SCSI ID of the PiSCSI device. If not specified, the PiSCSI device will use ID 7. The PiSCSI host will be functioning as the "Initiator" device.
|
||||||
.TP
|
.TP
|
||||||
.BR \-f\fI " "\fIFILE
|
.BR \-f\fI " "\fIFILE
|
||||||
Path to the dump file.
|
Path to the dump file.
|
||||||
.TP
|
.TP
|
||||||
.BR \-s\fI " "\fIBUFFER_SIZE
|
.BR \-s\fI " "\fIBUFFER_SIZE
|
||||||
The transfer buffer size, at least 64 KiB. Default is 64 KiB.
|
The transfer buffer size, specified in bytes. Default is 1 MiB. This is specified in bytes with a minimum value of 65536 (64 KiB).
|
||||||
.TP
|
.TP
|
||||||
.BR \-r\fI
|
.BR \-r\fI
|
||||||
Run in restore mode.
|
Run in restore mode. Defaults to dump mode if not specified.
|
||||||
.TP
|
.TP
|
||||||
.BR \-v\fI
|
.BR \-v\fI
|
||||||
Enable verbose logging.
|
Enable verbose logging.
|
||||||
|
.TP
|
||||||
|
.BR \-p\fI
|
||||||
|
Generate a .properties file that is compatible with the PiSCSI web interface. The output filename will match the image filename with ".properties" appended. The generated file should be moved to ~/.config/piscsi.
|
||||||
|
|
||||||
|
.SH EXAMPLES
|
||||||
|
Dump Mode: [SCSI Drive] ---> [PiSCSI host]
|
||||||
|
Launch scsidump to dump an all data from SCSI ID 3 with block size 64 KiB, store it to the local filesystem as a drive image named outimage.hda, and generate the outimage.hda.properties file with the drive's INQUIRY information:
|
||||||
|
scsidump -t 3 -f ./outimage.hda -s 65536 -p
|
||||||
|
|
||||||
|
Restore Mode: [PiSCSI host] ---> [SCSI Drive]
|
||||||
|
Launch scsidump to restore/upload a drive image from the local file system to SCSI ID 0 with block size 1MiB:
|
||||||
|
scsidump -r -t 0 -f ./outimage.hda -s 1048576
|
||||||
|
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
scsictl(1), piscsi(1), scsimon(1)
|
scsictl(1), piscsi(1), scsimon(1)
|
||||||
|
|
|
@ -8,31 +8,46 @@ NAME
|
||||||
scsidump - SCSI disk dumping tool for PiSCSI
|
scsidump - SCSI disk dumping tool for PiSCSI
|
||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
scsidump -t ID[:LUN] [-i BID] -f FILE [-s BUFFER_SIZE] [-r] [-v]
|
scsidump -t ID[:LUN] [-i BID] -f FILE [-s BUFFER_SIZE] [-r] [-v] [-p]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
scsidump samples the data on physical SCSI storage media, including hard drives and MO drives, and stores it to an image
|
scsidump has two modes of operation: dump and restore. These can be used with physical storage media, including hard drives and magneto optical drives. Dump mode can be used with read-only media such as CD/DVD drives.
|
||||||
file. It can also restore from a dumped file onto physical SCSI storage media. Can be connected directly, through a STAN‐
|
|
||||||
DARD PiSCSI board, or a FULLSPEC PiSCSI board.
|
|
||||||
|
|
||||||
Set its own ID with the BID option. Defaults to 7 if ommitted.
|
When operating in dump mode, scsidump will copy all data from a remote SCSI drive to an image on the local filesystem. If enabled, it will also generate a .properties file that can be used to more closely emulate the source drive.
|
||||||
|
|
||||||
|
If you are operating in restore mode, scsidump will copy the data from a local binary image to a remote physical SCSI drive. The remote SCSI drive MUST be writable.
|
||||||
|
|
||||||
|
NOTES
|
||||||
|
scsidump requires either a direct connection (one without transceivers) or a FULLSPEC PiSCSI/RaSCSI board.
|
||||||
|
|
||||||
|
If the generated drive image is intended to be used with PiSCSI, the drive image should be moved to ~/images (or the location specified to the piscsi service).
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
-t ID[:LUN]
|
-t ID[:LUN]
|
||||||
SCSI ID and optional LUN of the target device.
|
SCSI ID and optional LUN of the remote SCSI device. The remote SCSI device will be functioning as the "Target" device.
|
||||||
|
|
||||||
-i BID SCSI ID of the PiSCSI device.
|
-i BID SCSI ID of the PiSCSI device. If not specified, the PiSCSI device will use ID 7. The PiSCSI host will be functioning as the "Initiator" device.
|
||||||
|
|
||||||
-f FILE
|
-f FILE
|
||||||
Path to the dump file.
|
Path to the dump file.
|
||||||
|
|
||||||
-s BUFFER_SIZE
|
-s BUFFER_SIZE
|
||||||
The transfer buffer size, at least 64 KiB. Default is 64 KiB.
|
The transfer buffer size, specified in bytes. Default is 1 MiB. This is specified in bytes with a minimum value of 65536 (64 KiB).
|
||||||
|
|
||||||
-r Run in restore mode.
|
-r Run in restore mode. Defaults to dump mode if not specified.
|
||||||
|
|
||||||
-v Enable verbose logging.
|
-v Enable verbose logging.
|
||||||
|
|
||||||
|
-p Generate a .properties file that is compatible with the PiSCSI web interface. The output filename will match the image filename with ".properties" appended. The generated file should be moved to ~/.config/piscsi.
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
Dump Mode: [SCSI Drive] ---> [PiSCSI host] Launch scsidump to dump an all data from SCSI ID 3 with block size 64 KiB, store it to the local filesystem as a drive image named outimage.hda, and generate the outimage.hda.properties file with the drive's INQUIRY
|
||||||
|
information:
|
||||||
|
scsidump -t 3 -f ./outimage.hda -s 65536 -p
|
||||||
|
|
||||||
|
Restore Mode: [PiSCSI host] ---> [SCSI Drive] Launch scsidump to restore/upload a drive image from the local file system to SCSI ID 0 with block size 1MiB:
|
||||||
|
scsidump -r -t 0 -f ./outimage.hda -s 1048576
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
scsictl(1), piscsi(1), scsimon(1)
|
scsictl(1), piscsi(1), scsimon(1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user