mirror of
https://github.com/akuker/RASCSI.git
synced 2024-06-01 19:41:48 +00:00
05db0e4688
* Fixing SonarCloud issues, first round * Fixing SonarCLoud issues, next round * Fixing SonarQube issues, next round * Fixed warning * Replaced empty constructors/destructors with = default; * Fixed warning * Replaced new * Use constants instead of macros * Use structured binding declarations * Use init statements for if * Use string views * Use enum class, use using instead of typedef * Fixed more SonarCloud warnings * Replaced redundant/duplicate types with auto * Devlared methods const * Memory management update * Fixed warning * Added missing const * Improved RaScsiResponse memory management * Improved memory management * Improved memory management * Replaced macros by constants, removed unused constants * Made member private * Fixed warning * Added comment * Fixed shadowing warnings * Cleanup * Cleanup * Cleanup * Fixed shadowing warning * Removed unused code * Fixed more warnings * Removed obsolete casts * Fixed warnings * Removed unused field * Removed library not needed by rasctl * Include cleanup * Updated platform check for better compatibility * Improved check for invalid option. This prevents rasctl to break on macos. * Updated option check * Fixed typo * Added TODO * Removed macro * Scope update * Replaced macro * Added TODO, update memory management * Fixed typo * Replaced NULL by nullptr * Use more structured bindings * Added TODO * Use calloc instead of mallco to not need memset * Fixed warnings * Fixed SonarQube initialization issues * Fixed warning * Cleaned up override/virtual/final * Fixed warnings * Constructor update * Fixed tests * Improved memory management * Added missing const * Added const * Fixed two bugs reported by SonarCloud * Fix SonarCloud hotspot * Fixed memory management * Memory management update * Addressing hotspot by using strncpy * Fixed SonarCloud issues * Fixed SonarQube issues * Added missing const * Added const * Added const * Suppress false positive * Added SonarQube suppressions for false positives * Added suppresoin * Fixed code smells * Reverted changes that is a SonarQube issue, but caused problems with -O3 * Removed TODO based on review
84 lines
2.6 KiB
C++
84 lines
2.6 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
|
// for Raspberry Pi
|
|
//
|
|
// Copyright (C) 2022 Uwe Seimet
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#include "log.h"
|
|
#include "rascsi_exceptions.h"
|
|
#include "scsi_command_util.h"
|
|
|
|
using namespace scsi_defs;
|
|
|
|
void scsi_command_util::ModeSelect(const DWORD *cdb, const BYTE *buf, int length, int sector_size)
|
|
{
|
|
assert(length >= 0);
|
|
|
|
// PF
|
|
if (cdb[1] & 0x10) {
|
|
bool has_valid_page_code = false;
|
|
|
|
// Mode Parameter header
|
|
if (length >= 12) {
|
|
// Check the block length
|
|
if (buf[9] != (BYTE)(sector_size >> 16) || buf[10] != (BYTE)(sector_size >> 8) ||
|
|
buf[11] != (BYTE)sector_size) {
|
|
// See below for details
|
|
LOGWARN("In order to change the sector size use the -b option when launching rascsi");
|
|
throw scsi_error_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST);
|
|
}
|
|
|
|
buf += 12;
|
|
length -= 12;
|
|
}
|
|
|
|
// Parsing the page
|
|
// TODO The length handling is wrong in case of length < size
|
|
while (length > 0) {
|
|
// Format device page
|
|
if (int page = buf[0]; page == 0x03) {
|
|
// With this page the sector size for a subsequent FORMAT can be selected, but only very few
|
|
// drives support this, e.g FUJITSU M2624S
|
|
// We are fine as long as the current sector size remains unchanged
|
|
if (buf[0xc] != (BYTE)(sector_size >> 8) || buf[0xd] != (BYTE)sector_size) {
|
|
// With rascsi it is not possible to permanently (by formatting) change the sector size,
|
|
// because the size is an externally configurable setting only
|
|
LOGWARN("In order to change the sector size use the -b option when launching rascsi");
|
|
throw scsi_error_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST);
|
|
}
|
|
|
|
has_valid_page_code = true;
|
|
}
|
|
else {
|
|
LOGWARN("Unknown MODE SELECT page code: $%02X", page);
|
|
}
|
|
|
|
// Advance to the next page
|
|
int size = buf[1] + 2;
|
|
length -= size;
|
|
buf += size;
|
|
}
|
|
|
|
if (!has_valid_page_code) {
|
|
throw scsi_error_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST);
|
|
}
|
|
}
|
|
else {
|
|
// Vendor-specific parameters (SCSI-1) are not supported
|
|
throw scsi_error_exception(sense_key::ILLEGAL_REQUEST, asc::INVALID_FIELD_IN_PARAMETER_LIST);
|
|
}
|
|
}
|
|
|
|
void scsi_command_util::EnrichFormatPage(map<int, vector<BYTE>>& pages, bool changeable, int sector_size)
|
|
{
|
|
if (changeable) {
|
|
// The sector size is simulated to be changeable, see the MODE SELECT implementation for details
|
|
vector<BYTE>& format_page = pages[3];
|
|
format_page[12] = sector_size >> 8;
|
|
format_page[13] = sector_size;
|
|
}
|
|
}
|