mirror of https://github.com/akuker/RASCSI.git
Revert "scsictl: Create files with binary/JSON or text format protobuf data (#1369)"
This reverts commit abc5c4b9ac
.
This commit is contained in:
parent
4d1a10cb6b
commit
28959aaf97
|
@ -6,7 +6,6 @@
|
||||||
// Powered by XM6 TypeG Technology.
|
// Powered by XM6 TypeG Technology.
|
||||||
// Copyright (C) 2016-2020 GIMONS
|
// Copyright (C) 2016-2020 GIMONS
|
||||||
// Copyright (C) 2020-2023 Contributors to the PiSCSI project
|
// Copyright (C) 2020-2023 Contributors to the PiSCSI project
|
||||||
// Copyright (C) 2021-2023 Uwe Seimet
|
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -19,16 +18,11 @@
|
||||||
#include "scsictl/scsictl_parser.h"
|
#include "scsictl/scsictl_parser.h"
|
||||||
#include "scsictl/scsictl_commands.h"
|
#include "scsictl/scsictl_commands.h"
|
||||||
#include "scsictl/scsictl_core.h"
|
#include "scsictl/scsictl_core.h"
|
||||||
#include <google/protobuf/util/json_util.h>
|
|
||||||
#include <google/protobuf/text_format.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace google::protobuf;
|
|
||||||
using namespace google::protobuf::util;
|
|
||||||
using namespace piscsi_interface;
|
using namespace piscsi_interface;
|
||||||
using namespace piscsi_util;
|
using namespace piscsi_util;
|
||||||
using namespace protobuf_util;
|
using namespace protobuf_util;
|
||||||
|
@ -39,7 +33,7 @@ void ScsiCtl::Banner(const vector<char *>& args) const
|
||||||
cout << piscsi_util::Banner("(Controller App)")
|
cout << piscsi_util::Banner("(Controller App)")
|
||||||
<< "\nUsage: " << args[0] << " -i ID[:LUN] [-c CMD] [-C FILE] [-t TYPE] [-b BLOCK_SIZE] [-n NAME] [-f FILE|PARAM] "
|
<< "\nUsage: " << args[0] << " -i ID[:LUN] [-c CMD] [-C FILE] [-t TYPE] [-b BLOCK_SIZE] [-n NAME] [-f FILE|PARAM] "
|
||||||
<< "[-F IMAGE_FOLDER] [-L LOG_LEVEL] [-h HOST] [-p PORT] [-r RESERVED_IDS] "
|
<< "[-F IMAGE_FOLDER] [-L LOG_LEVEL] [-h HOST] [-p PORT] [-r RESERVED_IDS] "
|
||||||
<< "[-C FILENAME:FILESIZE] [-d FILENAME] [-B FILENAME] [-J FILENAME] [-T FILENAME] [-R CURRENT_NAME:NEW_NAME] "
|
<< "[-C FILENAME:FILESIZE] [-d FILENAME] [-w FILENAME] [-R CURRENT_NAME:NEW_NAME] "
|
||||||
<< "[-x CURRENT_NAME:NEW_NAME] [-z LOCALE] "
|
<< "[-x CURRENT_NAME:NEW_NAME] [-z LOCALE] "
|
||||||
<< "[-e] [-E FILENAME] [-D] [-I] [-l] [-m] [o] [-O] [-P] [-s] [-S] [-v] [-V] [-y] [-X]\n"
|
<< "[-e] [-E FILENAME] [-D] [-I] [-l] [-m] [o] [-O] [-P] [-s] [-S] [-v] [-V] [-y] [-X]\n"
|
||||||
<< " where ID[:LUN] ID := {0-" << (ControllerManager::GetScsiIdMax() - 1) << "},"
|
<< " where ID[:LUN] ID := {0-" << (ControllerManager::GetScsiIdMax() - 1) << "},"
|
||||||
|
@ -72,7 +66,7 @@ int ScsiCtl::run(const vector<char *>& args) const
|
||||||
PbCommand command;
|
PbCommand command;
|
||||||
PbDeviceDefinition* device = command.add_devices();
|
PbDeviceDefinition* device = command.add_devices();
|
||||||
device->set_id(-1);
|
device->set_id(-1);
|
||||||
string hostname = "localhost";
|
const char *hostname = "localhost";
|
||||||
int port = 6868;
|
int port = 6868;
|
||||||
string param;
|
string param;
|
||||||
string log_level;
|
string log_level;
|
||||||
|
@ -80,9 +74,6 @@ int ScsiCtl::run(const vector<char *>& args) const
|
||||||
string reserved_ids;
|
string reserved_ids;
|
||||||
string image_params;
|
string image_params;
|
||||||
string filename;
|
string filename;
|
||||||
string filename_json;
|
|
||||||
string filename_binary;
|
|
||||||
string filename_text;
|
|
||||||
string token;
|
string token;
|
||||||
bool list = false;
|
bool list = false;
|
||||||
|
|
||||||
|
@ -91,7 +82,7 @@ int ScsiCtl::run(const vector<char *>& args) const
|
||||||
opterr = 1;
|
opterr = 1;
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(static_cast<int>(args.size()), args.data(),
|
while ((opt = getopt(static_cast<int>(args.size()), args.data(),
|
||||||
"e::lmos::vDINOSTVXa:b:c:d:f:h:i:n:p:r:t:x:z:B:C:E:F:J:L:P::R:Z:")) != -1) {
|
"e::lmos::vDINOSTVXa:b:c:d:f:h:i:n:p:r:t:x:z:C:E:F:L:P::R:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'i':
|
case 'i':
|
||||||
if (const string error = SetIdAndLun(*device, optarg); !error.empty()) {
|
if (const string error = SetIdAndLun(*device, optarg); !error.empty()) {
|
||||||
|
@ -132,12 +123,8 @@ int ScsiCtl::run(const vector<char *>& args) const
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'E':
|
case 'E':
|
||||||
filename = optarg;
|
|
||||||
if (filename.empty()) {
|
|
||||||
cerr << "Error: Missing filename" << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
command.set_operation(IMAGE_FILE_INFO);
|
command.set_operation(IMAGE_FILE_INFO);
|
||||||
|
filename = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'e':
|
case 'e':
|
||||||
|
@ -158,34 +145,6 @@ int ScsiCtl::run(const vector<char *>& args) const
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
hostname = optarg;
|
hostname = optarg;
|
||||||
if (hostname.empty()) {
|
|
||||||
cerr << "Error: Missing hostname" << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'B':
|
|
||||||
filename_binary = optarg;
|
|
||||||
if (filename_binary.empty()) {
|
|
||||||
cerr << "Error: Missing filename" << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'J':
|
|
||||||
filename_json = optarg;
|
|
||||||
if (filename_json.empty()) {
|
|
||||||
cerr << "Error: Missing filename" << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'Z':
|
|
||||||
filename_text = optarg;
|
|
||||||
if (filename_text.empty()) {
|
|
||||||
cerr << "Error: Missing filename" << endl;
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'I':
|
case 'I':
|
||||||
|
@ -301,16 +260,6 @@ int ScsiCtl::run(const vector<char *>& args) const
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filename_json.empty()) {
|
|
||||||
return ExportAsJson(command, filename_json);
|
|
||||||
}
|
|
||||||
if (!filename_binary.empty()) {
|
|
||||||
return ExportAsBinary(command, filename_binary);
|
|
||||||
}
|
|
||||||
if (!filename_text.empty()) {
|
|
||||||
return ExportAsText(command, filename_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetParam(command, "token", token);
|
SetParam(command, "token", token);
|
||||||
SetParam(command, "locale", locale);
|
SetParam(command, "locale", locale);
|
||||||
|
|
||||||
|
@ -341,48 +290,3 @@ int ScsiCtl::run(const vector<char *>& args) const
|
||||||
|
|
||||||
return status ? EXIT_SUCCESS : EXIT_FAILURE;
|
return status ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScsiCtl::ExportAsBinary(const PbCommand &command, const string &filename) const
|
|
||||||
{
|
|
||||||
const string binary = command.SerializeAsString();
|
|
||||||
|
|
||||||
ofstream out;
|
|
||||||
out.open(filename, ios::binary);
|
|
||||||
out << binary;
|
|
||||||
if (out.fail()) {
|
|
||||||
cerr << "Error: Can't create protobuf binary file '" << filename << "'" << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ScsiCtl::ExportAsJson(const PbCommand &command, const string &filename) const
|
|
||||||
{
|
|
||||||
string json;
|
|
||||||
MessageToJsonString(command, &json);
|
|
||||||
|
|
||||||
ofstream out(filename);
|
|
||||||
out << json;
|
|
||||||
if (out.fail()) {
|
|
||||||
cerr << "Error: Can't create protobuf JSON file '" << filename << "'" << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ScsiCtl::ExportAsText(const PbCommand &command, const string &filename) const
|
|
||||||
{
|
|
||||||
string text;
|
|
||||||
TextFormat::PrintToString(command, &text);
|
|
||||||
|
|
||||||
ofstream out(filename);
|
|
||||||
out << text;
|
|
||||||
if (out.fail()) {
|
|
||||||
cerr << "Error: Can't create protobuf text format file '" << filename << "'" << endl;
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// SCSI Target Emulator PiSCSI
|
// SCSI Target Emulator PiSCSI
|
||||||
// for Raspberry Pi
|
// for Raspberry Pi
|
||||||
//
|
//
|
||||||
// Copyright (C) 2022-2023 Uwe Seimet
|
// Copyright (C) 2022 Uwe Seimet
|
||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -28,8 +28,4 @@ class ScsiCtl
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Banner(const vector<char *>&) const;
|
void Banner(const vector<char *>&) const;
|
||||||
|
|
||||||
int ExportAsBinary(const PbCommand&, const string&) const;
|
|
||||||
int ExportAsJson(const PbCommand&, const string&) const;
|
|
||||||
int ExportAsText(const PbCommand&, const string&) const;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,10 +17,6 @@ scsictl \- Sends management commands to the piscsi process
|
||||||
\fB\-T\fR |
|
\fB\-T\fR |
|
||||||
\fB\-V\fR |
|
\fB\-V\fR |
|
||||||
\fB\-X\fR |
|
\fB\-X\fR |
|
||||||
\fB\-Z\fR |
|
|
||||||
[\fB\-d\fR \fIFILENAME\fR] |
|
|
||||||
[\fB\-B\fR \fIFILENAME\fR] |
|
|
||||||
[\fB\-J\fR \fIFILENAME\fR] |
|
|
||||||
[\fB\-C\fR \fIFILENAME:FILESIZE\fR] |
|
[\fB\-C\fR \fIFILENAME:FILESIZE\fR] |
|
||||||
[\fB\-E\fR \fIFILENAME\fR] |
|
[\fB\-E\fR \fIFILENAME\fR] |
|
||||||
[\fB\-F\fR \fIIMAGE_FOLDER\fR] |
|
[\fB\-F\fR \fIIMAGE_FOLDER\fR] |
|
||||||
|
@ -121,15 +117,6 @@ Shut down the piscsi process.
|
||||||
.BR \-d\fI " "\fIFILENAME
|
.BR \-d\fI " "\fIFILENAME
|
||||||
Delete an image file in the default image folder.
|
Delete an image file in the default image folder.
|
||||||
.TP
|
.TP
|
||||||
.BR \-B\fI " "\fIFILENAME
|
|
||||||
Do not send command to piscsi but write it to a protobuf binary file.
|
|
||||||
.TP
|
|
||||||
.BR \-J\fI " "\fIFILENAME
|
|
||||||
Do not send command to piscsi but write it to a protobuf JSON file.
|
|
||||||
.TP
|
|
||||||
.BR \-Z\fI " "\fIFILENAME
|
|
||||||
Do not send command to piscsi but write it to a protobuf text format file.
|
|
||||||
.TP
|
|
||||||
.BR \-x\fI " "\fICURRENT_NAME:NEW_NAME
|
.BR \-x\fI " "\fICURRENT_NAME:NEW_NAME
|
||||||
Copy an image file in the default image folder.
|
Copy an image file in the default image folder.
|
||||||
.TP
|
.TP
|
||||||
|
|
|
@ -7,11 +7,10 @@ NAME
|
||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
scsictl -e | -l | -m | -o | -v | -D | -I | -L | -O | -P | -S | -T | -V
|
scsictl -e | -l | -m | -o | -v | -D | -I | -L | -O | -P | -S | -T | -V
|
||||||
| -X | -Z | [-d FILENAME] | [-B FILENAME] | [-J FILENAME] | [-C FILE‐
|
| -X | [-C FILENAME:FILESIZE] | [-E FILENAME] | [-F IMAGE_FOLDER] | [-R
|
||||||
NAME:FILESIZE] | [-E FILENAME] | [-F IMAGE_FOLDER] | [-R CUR‐
|
CURRENT_NAME:NEW_NAME] | [-c CMD] | [-f FILE|PARAM] | [-g LOG_LEVEL] |
|
||||||
RENT_NAME:NEW_NAME] | [-c CMD] | [-f FILE|PARAM] | [-g LOG_LEVEL] | [-h
|
[-h HOST] | [-i ID[:LUN]] | [-n NAME] | [-p PORT] | [-r RESERVED_IDS] |
|
||||||
HOST] | [-i ID[:LUN]] | [-n NAME] | [-p PORT] | [-r RESERVED_IDS] | [-s
|
[-s [FOLDER_PATTERN:FILE_PATTERN:OPERATIONS]] | [-t TYPE] | [-x CUR‐
|
||||||
[FOLDER_PATTERN:FILE_PATTERN:OPERATIONS]] | [-t TYPE] | [-x CUR‐
|
|
||||||
RENT_NAME:NEW_NAME] | [-z LOCALE]
|
RENT_NAME:NEW_NAME] | [-z LOCALE]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
|
@ -94,18 +93,6 @@ OPTIONS
|
||||||
-d FILENAME
|
-d FILENAME
|
||||||
Delete an image file in the default image folder.
|
Delete an image file in the default image folder.
|
||||||
|
|
||||||
-B FILENAME
|
|
||||||
Do not send command to piscsi but write it to a protobuf binary
|
|
||||||
file.
|
|
||||||
|
|
||||||
-J FILENAME
|
|
||||||
Do not send command to piscsi but write it to a protobuf JSON
|
|
||||||
file.
|
|
||||||
|
|
||||||
-Z FILENAME
|
|
||||||
Do not send command to piscsi but write it to a protobuf text
|
|
||||||
format file.
|
|
||||||
|
|
||||||
-x CURRENT_NAME:NEW_NAME
|
-x CURRENT_NAME:NEW_NAME
|
||||||
Copy an image file in the default image folder.
|
Copy an image file in the default image folder.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue