Added copy support to rasctl

This commit is contained in:
Uwe Seimet
2021-09-15 17:40:34 +02:00
parent 4cfeb32aa8
commit 3b250f0eff
3 changed files with 40 additions and 6 deletions

View File

@@ -40,7 +40,7 @@ The rascsi host to connect to, default is 'localhost'.
.BR \-l\fI .BR \-l\fI
List all of the devices that are currently being emulated by RaSCSI, as well as their current status. List all of the devices that are currently being emulated by RaSCSI, as well as their current status.
.TP .TP
.BR \-m\fI " "\fIOLD_NAME:NEW_NAME .BR \-m\fI " "\fICURRENT_NAME:NEW_NAME
Rename an image file in the default image folder. Rename an image file in the default image folder.
.TP .TP
.BR \-p\fI " " \fIPORT .BR \-p\fI " " \fIPORT
@@ -55,9 +55,12 @@ Display server-side settings like available images or supported device types.
.BR \-v\fI " " \fI .BR \-v\fI " " \fI
Display the rascsi version. Display the rascsi version.
.TP .TP
.BR \-x\fI " "\fIFILENAME .BR \-w\fI " "\fIFILENAME
Delete an image file in the default image folder. Delete an image file in the default image folder.
.TP .TP
.BR \-x\fI " "\fICURRENT_NAME:NEW_NAME
Copy an image file in the default image folder.
.TP
.BR \-i\fI " " \fIID .BR \-i\fI " " \fIID
ID is the SCSI ID that you want to control. (0-7) ID is the SCSI ID that you want to control. (0-7)
.TP .TP

View File

@@ -35,7 +35,7 @@ OPTIONS
-l List all of the devices that are currently being emulated by -l List all of the devices that are currently being emulated by
RaSCSI, as well as their current status. 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. Rename an image file in the default image folder.
-p PORT -p PORT
@@ -49,9 +49,12 @@ OPTIONS
-v Display the rascsi version. -v Display the rascsi version.
-x FILENAME -w FILENAME
Delete an image file in the default image folder. 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) -i ID ID is the SCSI ID that you want to control. (0-7)
-c CMD Command is the operation being requested. Options are: -c CMD Command is the operation being requested. Options are:

View File

@@ -249,7 +249,26 @@ void CommandRenameImage(const string&hostname, int port, const string& image_par
command.add_params(image_params.substr(separatorPos + 1)); command.add_params(image_params.substr(separatorPos + 1));
} }
else { 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); exit(EXIT_FAILURE);
} }
@@ -558,7 +577,7 @@ int main(int argc, char* argv[])
opterr = 1; opterr = 1;
int opt; 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) { switch (opt) {
case 'i': case 'i':
device->set_id(optarg[0] - '0'); device->set_id(optarg[0] - '0');
@@ -676,6 +695,11 @@ int main(int argc, char* argv[])
break; break;
case 'x': case 'x':
command.set_operation(COPY_IMAGE);
image_params = optarg;
break;
case 'w':
command.set_operation(DELETE_IMAGE); command.set_operation(DELETE_IMAGE);
image_params = optarg; image_params = optarg;
break; break;
@@ -711,6 +735,10 @@ int main(int argc, char* argv[])
CommandRenameImage(hostname, port, image_params); CommandRenameImage(hostname, port, image_params);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case COPY_IMAGE:
CommandCopyImage(hostname, port, image_params);
exit(EXIT_SUCCESS);
case DEVICE_INFO: case DEVICE_INFO:
CommandDeviceInfo(hostname, port, command); CommandDeviceInfo(hostname, port, command);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);