From 3b250f0eff14b2815d30dd959307c9539d17a5d8 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Wed, 15 Sep 2021 17:40:34 +0200 Subject: [PATCH] Added copy support to rasctl --- doc/rasctl.1 | 7 +++++-- doc/rasctl_man_page.txt | 7 +++++-- src/raspberrypi/rasctl.cpp | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/doc/rasctl.1 b/doc/rasctl.1 index db6c592e..cf16da96 100644 --- a/doc/rasctl.1 +++ b/doc/rasctl.1 @@ -40,7 +40,7 @@ The rascsi host to connect to, default is 'localhost'. .BR \-l\fI List all of the devices that are currently being emulated by RaSCSI, as well as their current status. .TP -.BR \-m\fI " "\fIOLD_NAME:NEW_NAME +.BR \-m\fI " "\fICURRENT_NAME:NEW_NAME Rename an image file in the default image folder. .TP .BR \-p\fI " " \fIPORT @@ -55,9 +55,12 @@ Display server-side settings like available images or supported device types. .BR \-v\fI " " \fI Display the rascsi version. .TP -.BR \-x\fI " "\fIFILENAME +.BR \-w\fI " "\fIFILENAME Delete an image file in the default image folder. .TP +.BR \-x\fI " "\fICURRENT_NAME:NEW_NAME +Copy an image file in the default image folder. +.TP .BR \-i\fI " " \fIID ID is the SCSI ID that you want to control. (0-7) .TP diff --git a/doc/rasctl_man_page.txt b/doc/rasctl_man_page.txt index d5e24cfc..bed9750c 100644 --- a/doc/rasctl_man_page.txt +++ b/doc/rasctl_man_page.txt @@ -35,7 +35,7 @@ OPTIONS -l List all of the devices that are currently being emulated by RaSCSI, as well as their current status. - -m OLD_NAME:NEW_NAME + -m CURRENT_NAME:NEW_NAME Rename an image file in the default image folder. -p PORT @@ -49,9 +49,12 @@ OPTIONS -v Display the rascsi version. - -x FILENAME + -w FILENAME Delete an image file in the default image folder. + -x CURRENT_NAME:NEW_NAME + Copy an image file in the default image folder. + -i ID ID is the SCSI ID that you want to control. (0-7) -c CMD Command is the operation being requested. Options are: diff --git a/src/raspberrypi/rasctl.cpp b/src/raspberrypi/rasctl.cpp index 9f1dd58a..46f534be 100644 --- a/src/raspberrypi/rasctl.cpp +++ b/src/raspberrypi/rasctl.cpp @@ -249,7 +249,26 @@ void CommandRenameImage(const string&hostname, int port, const string& image_par command.add_params(image_params.substr(separatorPos + 1)); } else { - cerr << "Error: Invalid file description '" << image_params << "', format is OLD_NAME:NEW_NAME" << endl; + cerr << "Error: Invalid file description '" << image_params << "', format is CURRENT_NAME:NEW_NAME" << endl; + exit(EXIT_FAILURE); + } + + PbResult result; + SendCommand(hostname.c_str(), port, command, result); +} + +void CommandCopyImage(const string&hostname, int port, const string& image_params) +{ + PbCommand command; + command.set_operation(COPY_IMAGE); + + size_t separatorPos = image_params.find(COMPONENT_SEPARATOR); + if (separatorPos != string::npos) { + command.add_params(image_params.substr(0, separatorPos)); + command.add_params(image_params.substr(separatorPos + 1)); + } + else { + cerr << "Error: Invalid file description '" << image_params << "', format is CURENT_NAME:NEW_NAME" << endl; exit(EXIT_FAILURE); } @@ -558,7 +577,7 @@ int main(int argc, char* argv[]) opterr = 1; int opt; - while ((opt = getopt(argc, argv, "a:b:c:d:f:g:h:i:m:n:p:r:t:u:x:lsv")) != -1) { + while ((opt = getopt(argc, argv, "a:b:c:d:f:g:h:i:m:n:p:r:t:u:x:w:lsv")) != -1) { switch (opt) { case 'i': device->set_id(optarg[0] - '0'); @@ -676,6 +695,11 @@ int main(int argc, char* argv[]) break; case 'x': + command.set_operation(COPY_IMAGE); + image_params = optarg; + break; + + case 'w': command.set_operation(DELETE_IMAGE); image_params = optarg; break; @@ -711,6 +735,10 @@ int main(int argc, char* argv[]) CommandRenameImage(hostname, port, image_params); exit(EXIT_SUCCESS); + case COPY_IMAGE: + CommandCopyImage(hostname, port, image_params); + exit(EXIT_SUCCESS); + case DEVICE_INFO: CommandDeviceInfo(hostname, port, command); exit(EXIT_SUCCESS);