mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-10 17:29:35 +00:00
* Initial RTC skeleton * Added device info * Added TEST UNIT READY * Fixed command dispatcher * First untested naive implementation * Comment update * Code cleanup * More code cleanup * Updated date/time encoding * Updated versioning * Use standard RaSCSI INQUIRY version for SCRT device * Manpage update * Added shortcut for SCRT type * Added support for rtc "filename" * RTC supports LUNs > 0 * Fixed LUN count * Renaming * Renaming * Manpage update * Initial naive implementation * SCRA is removable * Updated command list * Added controller field * Shut down works, bus free phase is not yet entered * Clear caches on shutdown * Expose BusFree() * Moved code * Logging update * Moved code * Moved code * Added comment * Logging update * Code cleanup * Service device is not removable anymore (was only needed for testing) * Manpage update * Added comment * Comment update * Version update * Renaming * Comment update * Comment update * Renaming * Fixed typo * Added convenience method * Property handling optimization * Code cleanup * Code cleanup * Code cleanup, introduced base class * Added TODO * More code cleanup * Removed unnecessary assignments * Moved code * Removed forward declaration * Added base class * INclude cleanup * Moved scsi_command enum * Fixed warnings * Addressing circular dependencies * Removed duplicate enum * include file cleanup * Include cleanup * Reduced dependencies to Disk class (replaced by Device), fixed TODO * Include cleanup * PrimaryDevice implements ReportLuns * Inheritance update * Removed duplicate code * Moved code to base class * Cleanup * Removed duplicate field * Updated command dispatchign * Comment update * Moved code * Updated method visibilities * Moved MODE SENSE/MODE SELECT base code
163 lines
3.0 KiB
C++
163 lines
3.0 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator RaSCSI (*^..^*)
|
|
// for Raspberry Pi
|
|
//
|
|
// Copyright (C) 2021 Uwe Seimet
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#include <cassert>
|
|
#include <sstream>
|
|
#include "rascsi_version.h"
|
|
#include "os.h"
|
|
#include "log.h"
|
|
#include "exceptions.h"
|
|
#include "device.h"
|
|
|
|
Device::Device(const string& type)
|
|
{
|
|
assert(type.length() == 4);
|
|
|
|
this->type = type;
|
|
|
|
vendor = DEFAULT_VENDOR;
|
|
char rev[5];
|
|
sprintf(rev, "%02d%02d", rascsi_major_version, rascsi_minor_version);
|
|
revision = rev;
|
|
|
|
ready = false;
|
|
reset = false;
|
|
attn = false;
|
|
supported_luns = 32;
|
|
protectable = false;
|
|
write_protected = false;
|
|
read_only = false;
|
|
stoppable = false;
|
|
stopped = false;
|
|
removable = false;
|
|
removed = false;
|
|
lockable = false;
|
|
locked = false;
|
|
block_size_configurable = false;
|
|
supports_params = false;
|
|
|
|
id = 0;
|
|
lun = 0;
|
|
|
|
status_code = STATUS_NOERROR;
|
|
}
|
|
|
|
void Device::Reset()
|
|
{
|
|
locked = false;
|
|
attn = false;
|
|
reset = false;
|
|
}
|
|
|
|
void Device::SetProtected(bool write_protected)
|
|
{
|
|
if (!read_only) {
|
|
this->write_protected = write_protected;
|
|
}
|
|
}
|
|
|
|
void Device::SetVendor(const string& vendor)
|
|
{
|
|
if (vendor.empty() || vendor.length() > 8) {
|
|
throw illegal_argument_exception("Vendor '" + vendor + "' must be between 1 and 8 characters");
|
|
}
|
|
|
|
this->vendor = vendor;
|
|
}
|
|
|
|
void Device::SetProduct(const string& product, bool force)
|
|
{
|
|
// Changing the device name is not SCSI compliant
|
|
if (!this->product.empty() && !force) {
|
|
return;
|
|
}
|
|
|
|
if (product.empty() || product.length() > 16) {
|
|
throw illegal_argument_exception("Product '" + product + "' must be between 1 and 16 characters");
|
|
}
|
|
|
|
this->product = product;
|
|
}
|
|
|
|
void Device::SetRevision(const string& revision)
|
|
{
|
|
if (revision.empty() || revision.length() > 4) {
|
|
throw illegal_argument_exception("Revision '" + revision + "' must be between 1 and 4 characters");
|
|
}
|
|
|
|
this->revision = revision;
|
|
}
|
|
|
|
const string Device::GetPaddedName() const
|
|
{
|
|
string name = vendor;
|
|
name.append(8 - vendor.length(), ' ');
|
|
name += product;
|
|
name.append(16 - product.length(), ' ');
|
|
name += revision;
|
|
name.append(4 - revision.length(), ' ');
|
|
|
|
assert(name.length() == 28);
|
|
|
|
return name;
|
|
}
|
|
|
|
const string Device::GetParam(const string& key)
|
|
{
|
|
return params.find(key) != params.end() ? params[key] : "";
|
|
}
|
|
|
|
void Device::SetStatusCode(int status_code)
|
|
{
|
|
if (status_code) {
|
|
LOGDEBUG("Error status: Sense Key $%02X, ASC $%02X, ASCQ $%02X", status_code >> 16, (status_code >> 8 &0xff), status_code & 0xff);
|
|
}
|
|
|
|
this->status_code = status_code;
|
|
}
|
|
|
|
bool Device::Start()
|
|
{
|
|
if (!ready) {
|
|
return false;
|
|
}
|
|
|
|
stopped = false;
|
|
|
|
return true;
|
|
}
|
|
|
|
void Device::Stop()
|
|
{
|
|
ready = false;
|
|
attn = false;
|
|
stopped = true;
|
|
}
|
|
|
|
bool Device::Eject(bool force)
|
|
{
|
|
if (!ready || !removable) {
|
|
return false;
|
|
}
|
|
|
|
// Must be unlocked if there is no force flag
|
|
if (!force && locked) {
|
|
return false;
|
|
}
|
|
|
|
ready = false;
|
|
attn = false;
|
|
removed = true;
|
|
write_protected = false;
|
|
locked = false;
|
|
stopped = true;
|
|
|
|
return true;
|
|
}
|