mirror of
https://github.com/akuker/RASCSI.git
synced 2025-01-17 19:30:44 +00:00
Fix issue 422 (#425)
* Use the effective filename when checking for duplicates * Fixed check for asynchronous notifications * Added additional filename check * Applied fix also for attach
This commit is contained in:
parent
7e546e2cb8
commit
817c1cde31
@ -728,7 +728,7 @@ int SCSICD::ReadToc(const DWORD *cdb, BYTE *buf)
|
|||||||
|
|
||||||
void SCSICD::GetEventStatusNotification(SASIDEV *controller)
|
void SCSICD::GetEventStatusNotification(SASIDEV *controller)
|
||||||
{
|
{
|
||||||
if (!ctrl->cmd[1] & 0x01) {
|
if (!(ctrl->cmd[1] & 0x01)) {
|
||||||
// Asynchronous notification is optional and not supported by rascsi
|
// Asynchronous notification is optional and not supported by rascsi
|
||||||
controller->Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::INVALID_FIELD_IN_CDB);
|
controller->Error(ERROR_CODES::sense_key::ILLEGAL_REQUEST, ERROR_CODES::asc::INVALID_FIELD_IN_CDB);
|
||||||
return;
|
return;
|
||||||
|
@ -619,22 +619,6 @@ bool Attach(int fd, const PbDeviceDefinition& pb_device, Device *map[], bool dry
|
|||||||
filepath.SetPath(filename.c_str());
|
filepath.SetPath(filename.c_str());
|
||||||
string initial_filename = filepath.GetPath();
|
string initial_filename = filepath.GetPath();
|
||||||
|
|
||||||
try {
|
|
||||||
try {
|
|
||||||
file_support->Open(filepath);
|
|
||||||
}
|
|
||||||
catch(const file_not_found_exception&) {
|
|
||||||
// If the file does not exist search for it in the default image folder
|
|
||||||
filepath.SetPath(string(rascsi_image.GetDefaultImageFolder() + "/" + filename).c_str());
|
|
||||||
file_support->Open(filepath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(const io_exception& e) {
|
|
||||||
delete device;
|
|
||||||
|
|
||||||
return ReturnStatus(fd, false, "Tried to open an invalid or non-existing file '" + initial_filename + "': " + e.getmsg());
|
|
||||||
}
|
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
int unit;
|
int unit;
|
||||||
if (FileSupport::GetIdsForReservedFile(filepath, id, unit)) {
|
if (FileSupport::GetIdsForReservedFile(filepath, id, unit)) {
|
||||||
@ -644,6 +628,30 @@ bool Attach(int fd, const PbDeviceDefinition& pb_device, Device *map[], bool dry
|
|||||||
return ReturnStatus(fd, false, error);
|
return ReturnStatus(fd, false, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
file_support->Open(filepath);
|
||||||
|
}
|
||||||
|
catch(const file_not_found_exception&) {
|
||||||
|
// If the file does not exist search for it in the default image folder
|
||||||
|
filepath.SetPath(string(rascsi_image.GetDefaultImageFolder() + "/" + filename).c_str());
|
||||||
|
|
||||||
|
if (FileSupport::GetIdsForReservedFile(filepath, id, unit)) {
|
||||||
|
delete device;
|
||||||
|
|
||||||
|
error << "Image file '" << filename << "' is already used by ID " << id << ", unit " << unit;
|
||||||
|
return ReturnStatus(fd, false, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_support->Open(filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const io_exception& e) {
|
||||||
|
delete device;
|
||||||
|
|
||||||
|
return ReturnStatus(fd, false, "Tried to open an invalid or non-existing file '" + initial_filename + "': " + e.getmsg());
|
||||||
|
}
|
||||||
|
|
||||||
file_support->ReserveFile(filepath, device->GetId(), device->GetLun());
|
file_support->ReserveFile(filepath, device->GetId(), device->GetLun());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -737,17 +745,6 @@ bool Insert(int fd, const PbDeviceDefinition& pb_device, Device *device, bool dr
|
|||||||
LOGINFO("Insert %sfile '%s' requested into %s ID %d, unit %d", pb_device.protected_() ? "protected " : "",
|
LOGINFO("Insert %sfile '%s' requested into %s ID %d, unit %d", pb_device.protected_() ? "protected " : "",
|
||||||
filename.c_str(), device->GetType().c_str(), pb_device.id(), pb_device.unit());
|
filename.c_str(), device->GetType().c_str(), pb_device.id(), pb_device.unit());
|
||||||
|
|
||||||
int id;
|
|
||||||
int unit;
|
|
||||||
Filepath filepath;
|
|
||||||
filepath.SetPath(filename.c_str());
|
|
||||||
string initial_filename = filepath.GetPath();
|
|
||||||
if (FileSupport::GetIdsForReservedFile(filepath, id, unit)) {
|
|
||||||
ostringstream error;
|
|
||||||
error << "Image file '" << filename << "' is already used by ID " << id << ", unit " << unit;
|
|
||||||
return ReturnStatus(fd, false, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pb_device.block_size()) {
|
if (pb_device.block_size()) {
|
||||||
Disk *disk = dynamic_cast<Disk *>(device);
|
Disk *disk = dynamic_cast<Disk *>(device);
|
||||||
if (disk && disk->IsSectorSizeConfigurable()) {
|
if (disk && disk->IsSectorSizeConfigurable()) {
|
||||||
@ -762,6 +759,18 @@ bool Insert(int fd, const PbDeviceDefinition& pb_device, Device *device, bool dr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int id;
|
||||||
|
int unit;
|
||||||
|
Filepath filepath;
|
||||||
|
filepath.SetPath(filename.c_str());
|
||||||
|
string initial_filename = filepath.GetPath();
|
||||||
|
|
||||||
|
if (FileSupport::GetIdsForReservedFile(filepath, id, unit)) {
|
||||||
|
ostringstream error;
|
||||||
|
error << "Image file '" << filename << "' is already used by ID " << id << ", unit " << unit;
|
||||||
|
return ReturnStatus(fd, false, error);
|
||||||
|
}
|
||||||
|
|
||||||
FileSupport *file_support = dynamic_cast<FileSupport *>(device);
|
FileSupport *file_support = dynamic_cast<FileSupport *>(device);
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
@ -770,12 +779,20 @@ bool Insert(int fd, const PbDeviceDefinition& pb_device, Device *device, bool dr
|
|||||||
catch(const file_not_found_exception&) {
|
catch(const file_not_found_exception&) {
|
||||||
// If the file does not exist search for it in the default image folder
|
// If the file does not exist search for it in the default image folder
|
||||||
filepath.SetPath((rascsi_image.GetDefaultImageFolder() + "/" + filename).c_str());
|
filepath.SetPath((rascsi_image.GetDefaultImageFolder() + "/" + filename).c_str());
|
||||||
|
|
||||||
|
if (FileSupport::GetIdsForReservedFile(filepath, id, unit)) {
|
||||||
|
ostringstream error;
|
||||||
|
error << "Image file '" << filename << "' is already used by ID " << id << ", unit " << unit;
|
||||||
|
return ReturnStatus(fd, false, error);
|
||||||
|
}
|
||||||
|
|
||||||
file_support->Open(filepath);
|
file_support->Open(filepath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const io_exception& e) {
|
catch(const io_exception& e) {
|
||||||
return ReturnStatus(fd, false, "Tried to open an invalid or non-existing file '" + initial_filename + "': " + e.getmsg());
|
return ReturnStatus(fd, false, "Tried to open an invalid or non-existing file '" + initial_filename + "': " + e.getmsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
file_support->ReserveFile(filepath, device->GetId(), device->GetLun());
|
file_support->ReserveFile(filepath, device->GetId(), device->GetLun());
|
||||||
|
|
||||||
// Only non read-only devices support protect/unprotect.
|
// Only non read-only devices support protect/unprotect.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user