Added PROTECT_IMAGE, UNPROTECT_IMAGE

This commit is contained in:
Uwe Seimet 2021-09-17 11:11:22 +02:00
parent 9266852ae2
commit 7018ccac64
5 changed files with 78 additions and 21 deletions

View File

@ -5,6 +5,7 @@ rasctl \- Sends management commands to the rascsi process
.B rasctl .B rasctl
\fB\-l\fR | \fB\-l\fR |
\fB\-s\fR | \fB\-s\fR |
[\fB\-d\fR \fIIMAGE_FOLDER\fR]
[\fB\-g\fR \fILOG_LEVEL\fR] [\fB\-g\fR \fILOG_LEVEL\fR]
[\fB\-h\fR \fIHOST\fR] [\fB\-h\fR \fIHOST\fR]
[\fB\-p\fR \fIPORT\fR] [\fB\-p\fR \fIPORT\fR]
@ -31,6 +32,9 @@ Note: The command and type arguments are case insensitive. Only the first letter
.BR \-a\fI " "\fIFILENAME:FILESIZE .BR \-a\fI " "\fIFILENAME:FILESIZE
Create an image file in the default image folder with the specified name and size in bytes. Create an image file in the default image folder with the specified name and size in bytes.
.TP .TP
.BR \-g\fI " "\fIIMAGE_FOLDER
Set the default image folder.
.TP
.BR \-g\fI " "\fILOG_LEVEL .BR \-g\fI " "\fILOG_LEVEL
Set the rascsi log level (trace, debug, info, warn, err, critical, off). Set the rascsi log level (trace, debug, info, warn, err, critical, off).
.TP .TP

View File

@ -6,8 +6,9 @@ NAME
rasctl - Sends management commands to the rascsi process rasctl - Sends management commands to the rascsi process
SYNOPSIS SYNOPSIS
rasctl -l | -s | [-g LOG_LEVEL] [-h HOST] [-p PORT] [-r RESERVED_IDS] rasctl -l | -s | [-d IMAGE_FOLDER] [-g LOG_LEVEL] [-h HOST] [-p PORT]
[-v] -i ID [-c CMD] [-f FILE|PARAM] [-n NAME] [-t TYPE] [-u UNIT] [-r RESERVED_IDS] [-v] -i ID [-c CMD] [-f FILE|PARAM] [-n NAME] [-t
TYPE] [-u UNIT]
DESCRIPTION DESCRIPTION
rasctl Sends commands to the rascsi process to make configuration ad rasctl Sends commands to the rascsi process to make configuration ad
@ -25,6 +26,9 @@ OPTIONS
Create an image file in the default image folder with the speci Create an image file in the default image folder with the speci
fied name and size in bytes. fied name and size in bytes.
-g IMAGE_FOLDER
Set the default image folder.
-g LOG_LEVEL -g LOG_LEVEL
Set the rascsi log level (trace, debug, info, warn, err, criti Set the rascsi log level (trace, debug, info, warn, err, criti
cal, off). cal, off).

View File

@ -914,6 +914,39 @@ bool CopyImage(int fd, const PbCommand& command)
return ReturnStatus(fd); return ReturnStatus(fd);
} }
bool SetImagePermissions(int fd, const PbCommand& command)
{
string filename = GetParam(command, "file");
if (filename.empty()) {
return ReturnStatus(fd, false, "Missing image filename");
}
if (filename.find('/') != string::npos) {
return ReturnStatus(fd, false, "The image filename '" + filename + "' must not contain a path");
}
filename = default_image_folder + "/" + filename;
bool protect = command.operation() == PROTECT_IMAGE;
int permissions = protect ? S_IRUSR | S_IRGRP | S_IROTH : S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
if (chmod(filename.c_str(), permissions) == -1) {
ostringstream error;
error << "Can't " << (protect ? "protect" : "unprotect") << " image file '" << filename << "': " << strerror(errno);
return ReturnStatus(fd, false, error.str());
}
if (protect) {
LOGINFO("%s", string("Protected image file '" + filename + "'").c_str());
}
else {
LOGINFO("%s", string("Unprotected image file '" + filename + "'").c_str());
}
return ReturnStatus(fd);
}
void DetachAll() void DetachAll()
{ {
Device *map[devices.size()]; Device *map[devices.size()];
@ -1381,6 +1414,10 @@ bool ProcessCmd(const int fd, const PbCommand& command)
case COPY_IMAGE: case COPY_IMAGE:
return CopyImage(fd, command); return CopyImage(fd, command);
case PROTECT_IMAGE:
case UNPROTECT_IMAGE:
return SetImagePermissions(fd, command);
default: default:
// This is a device-specific command handled below // This is a device-specific command handled below
break; break;

View File

@ -104,6 +104,16 @@ enum PbOperation {
// "to": The destination filename, relative to the default image folder. It must not contain a slash. // "to": The destination filename, relative to the default image folder. It must not contain a slash.
// The destination filename must not yet exist. // The destination filename must not yet exist.
COPY_IMAGE = 18; COPY_IMAGE = 18;
// Write-protect an image file.
// Parameters:
// "file": The filename, relative to the default image folder. It must not contain a slash.
PROTECT_IMAGE = 19;
// Make an image file writable.
// Parameters:
// "file": The filename, relative to the default image folder. It must not contain a slash.
UNPROTECT_IMAGE = 20;
} }
// The properties supported by a device // The properties supported by a device

View File

@ -532,19 +532,21 @@ int main(int argc, char* argv[])
cerr << "SCSI Target Emulator RaSCSI Controller" << endl; cerr << "SCSI Target Emulator RaSCSI Controller" << endl;
cerr << "version " << rascsi_get_version_string() << " (" << __DATE__ << ", " << __TIME__ << ")" << endl; cerr << "version " << rascsi_get_version_string() << " (" << __DATE__ << ", " << __TIME__ << ")" << endl;
cerr << "Usage: " << argv[0] << " -i ID [-u UNIT] [-c CMD] [-t TYPE] [-b BLOCK_SIZE] [-n NAME] [-f FILE|PARAM] "; cerr << "Usage: " << argv[0] << " -i ID [-u UNIT] [-c CMD] [-t TYPE] [-b BLOCK_SIZE] [-n NAME] [-f FILE|PARAM] ";
cerr << "[-d DEFAULT_IMAGE_FOLDER] [-g LOG_LEVEL] [-h HOST] [-p PORT] [-r RESERVED_IDS] [-l] [-v]" << endl; cerr << "[-d IMAGE_FOLDER] [-g LOG_LEVEL] [-h HOST] [-p PORT] [-r RESERVED_IDS] ";
cerr << " where ID := {0|1|2|3|4|5|6|7}" << endl; cerr << "[-a FILENAME:FILESIZE] [-w FILENAME] [-m CURRENT_NAME:NEW_NAME] [-x CURRENT_NAME:NEW_NAME] ";
cerr << " UNIT := {0|1}, default setting is 0." << endl; cerr << "[-l] [-v]" << endl;
cerr << " where ID := {0-7}" << endl;
cerr << " UNIT := {0|1}, default is 0" << endl;
cerr << " CMD := {attach|detach|insert|eject|protect|unprotect|show}" << endl; cerr << " CMD := {attach|detach|insert|eject|protect|unprotect|show}" << endl;
cerr << " TYPE := {sahd|schd|scrm|sccd|scmo|scbr|scdp} or convenience type {hd|rm|mo|cd|bridge|daynaport}" << endl; cerr << " TYPE := {sahd|schd|scrm|sccd|scmo|scbr|scdp} or convenience type {hd|rm|mo|cd|bridge|daynaport}" << endl;
cerr << " BLOCK_SIZE := {256|512|1024|2048|4096) bytes per hard disk drive block" << endl; cerr << " BLOCK_SIZE := {256|512|1024|2048|4096) bytes per hard disk drive block" << endl;
cerr << " NAME := name of device to attach (VENDOR:PRODUCT:REVISION)" << endl; cerr << " NAME := name of device to attach (VENDOR:PRODUCT:REVISION)" << endl;
cerr << " FILE|PARAM := image file path or device-specific parameter" << endl; cerr << " FILE|PARAM := image file path or device-specific parameter" << endl;
cerr << " DEFAULT_IMAGE_FOLDER := default location for image files, default is '~/images'" << endl; cerr << " IMAGE_FOLDER := default location for image files, default is '~/images'" << endl;
cerr << " HOST := rascsi host to connect to, default is 'localhost'" << endl; cerr << " HOST := rascsi host to connect to, default is 'localhost'" << endl;
cerr << " PORT := rascsi port to connect to, default is 6868" << endl; cerr << " PORT := rascsi port to connect to, default is 6868" << endl;
cerr << " RESERVED_IDS := comma-separated list of IDs to reserve" << endl; cerr << " RESERVED_IDS := comma-separated list of IDs to reserve" << endl;
cerr << " LOG_LEVEL := log level {trace|debug|info|warn|err|critical|off}, default is 'trace'" << endl; cerr << " LOG_LEVEL := log level {trace|debug|info|warn|err|critical|off}, default is 'info'" << endl;
cerr << " If CMD is 'attach' or 'insert' the FILE parameter is required." << endl; cerr << " If CMD is 'attach' or 'insert' the FILE parameter is required." << endl;
cerr << "Usage: " << argv[0] << " -l" << endl; cerr << "Usage: " << argv[0] << " -l" << endl;
cerr << " Print device list." << endl; cerr << " Print device list." << endl;