From d80fbec03da497cc303d42d98266cbea0a9e3a90 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Thu, 8 Sep 2022 04:45:00 +0200 Subject: [PATCH] Added support for .hd1 (SCSI-1) image files (#828) * Added support for .hd1 (SCSI-1) image files * Update c-cpp.yml * Fixed unit test warnings * Fixed wrong scan default default (must be 1, not -1) * Updated max length check * Removed file not present in develop branch * Added unit test * Added workflow configurations and README updates (#832) * automated test try 1 * filter branches * filter branches * filter branches * filter branches * filter branches * Configured build and test CI workflows * enable for all branches * Update README.md * Update README.md Co-authored-by: Tony Kuker * Fix simple SonarCloud issues (#834) * 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 * Update c-cpp.yml * Finalized merge Co-authored-by: akuker <34318535+akuker@users.noreply.github.com> Co-authored-by: Tony Kuker --- doc/rascsi.1 | 1 + doc/rascsi_man_page.txt | 1 + src/raspberrypi/devices/device_factory.cpp | 3 ++- src/raspberrypi/devices/mode_page_device.cpp | 2 +- src/raspberrypi/devices/scsihd.cpp | 8 ++++++-- src/raspberrypi/devices/scsihd.h | 9 +++++++-- src/raspberrypi/rascsi.cpp | 3 ++- src/raspberrypi/test/device_factory_test.cpp | 2 ++ src/raspberrypi/test/mode_pages_test.cpp | 1 + 9 files changed, 23 insertions(+), 7 deletions(-) diff --git a/doc/rascsi.1 b/doc/rascsi.1 index 5b7c0877..92652948 100644 --- a/doc/rascsi.1 +++ b/doc/rascsi.1 @@ -25,6 +25,7 @@ The number (n) after the ID or HD identifier specifies the ID number for that de For SCSI: The ID is limited from 0-7. However, typically SCSI ID 7 is reserved for the "initiator" (the host computer). The LUN is limited from 0-31. .PP RaSCSI will determine the type of device based upon the file extension of the FILE argument. + hd1: SCSI Hard Disk image (generic, non-removable, SCSI-1) hds: SCSI Hard Disk image (generic, non-removable) hdr: SCSI Hard Disk image (generic, removable) hdn: SCSI Hard Disk image (NEC GENUINE) diff --git a/doc/rascsi_man_page.txt b/doc/rascsi_man_page.txt index f2187222..9950e90c 100644 --- a/doc/rascsi_man_page.txt +++ b/doc/rascsi_man_page.txt @@ -23,6 +23,7 @@ DESCRIPTION RaSCSI will determine the type of device based upon the file extension of the FILE argument. + hd1: SCSI Hard Disk image (generic, non-removable, SCSI-1) hds: SCSI Hard Disk image (generic, non-removable) hdr: SCSI Hard Disk image (generic, removable) hdn: SCSI Hard Disk image (NEC GENUINE) diff --git a/src/raspberrypi/devices/device_factory.cpp b/src/raspberrypi/devices/device_factory.cpp index d58b43f4..f8ba24cf 100644 --- a/src/raspberrypi/devices/device_factory.cpp +++ b/src/raspberrypi/devices/device_factory.cpp @@ -55,6 +55,7 @@ DeviceFactory::DeviceFactory() : sector_sizes({}), geometries({}), default_param default_params[SCLP]["cmd"] = "lp -oraw %f"; default_params[SCLP]["timeout"] = "30"; + extension_mapping["hd1"] = SCHD; extension_mapping["hds"] = SCHD; extension_mapping["hda"] = SCHD; extension_mapping["hdn"] = SCHD; @@ -172,7 +173,7 @@ Device *DeviceFactory::CreateDevice(PbDeviceType type, const string& filename, i if (string ext = GetExtension(filename); ext == "hdn" || ext == "hdi" || ext == "nhd") { device = make_unique(); } else { - device = make_unique(sector_sizes[SCHD], false); + device = make_unique(sector_sizes[SCHD], false, ext == "hd1" ? scsi_level::SCSI_1_CCS : scsi_level::SCSI_2); // Some Apple tools require a particular drive identification if (ext == "hda") { diff --git a/src/raspberrypi/devices/mode_page_device.cpp b/src/raspberrypi/devices/mode_page_device.cpp index 9f71ddeb..22399631 100644 --- a/src/raspberrypi/devices/mode_page_device.cpp +++ b/src/raspberrypi/devices/mode_page_device.cpp @@ -32,7 +32,7 @@ bool ModePageDevice::Dispatch() int ModePageDevice::AddModePages(const DWORD *cdb, BYTE *buf, int max_length) const { - if (max_length <= 0) { + if (max_length < 0) { return 0; } diff --git a/src/raspberrypi/devices/scsihd.cpp b/src/raspberrypi/devices/scsihd.cpp index acca418a..3173701b 100644 --- a/src/raspberrypi/devices/scsihd.cpp +++ b/src/raspberrypi/devices/scsihd.cpp @@ -13,6 +13,7 @@ // [ SCSI hard disk ] // //--------------------------------------------------------------------------- + #include "scsihd.h" #include "fileio.h" #include "rascsi_exceptions.h" @@ -21,8 +22,11 @@ static const char *DEFAULT_PRODUCT = "SCSI HD"; -SCSIHD::SCSIHD(const unordered_set& sector_sizes, bool removable) : Disk(removable ? "SCRM" : "SCHD") +SCSIHD::SCSIHD(const unordered_set& sector_sizes, bool removable, scsi_defs::scsi_level level) + : Disk(removable ? "SCRM" : "SCHD") { + this->scsi_level = level; + SetSectorSizes(sector_sizes); } @@ -95,7 +99,7 @@ void SCSIHD::Open(const Filepath& path) vector SCSIHD::InquiryInternal() const { - return HandleInquiry(device_type::DIRECT_ACCESS, scsi_level::SCSI_2, IsRemovable()); + return HandleInquiry(device_type::DIRECT_ACCESS, scsi_level, IsRemovable()); } void SCSIHD::ModeSelect(const DWORD *cdb, const BYTE *buf, int length) diff --git a/src/raspberrypi/devices/scsihd.h b/src/raspberrypi/devices/scsihd.h index eea8dd11..271701f4 100644 --- a/src/raspberrypi/devices/scsihd.h +++ b/src/raspberrypi/devices/scsihd.h @@ -22,8 +22,9 @@ class SCSIHD : public Disk, public FileSupport { public: - SCSIHD(const unordered_set&, bool); - ~SCSIHD() override = default; + + SCSIHD(const unordered_set&, bool, scsi_defs::scsi_level = scsi_level::SCSI_2); + virtual ~SCSIHD() {} void FinalizeSetup(const Filepath&, off_t); @@ -36,4 +37,8 @@ public: void AddFormatPage(map>&, bool) const override; void AddVendorPage(map>&, int, bool) const override; + +private: + + scsi_defs::scsi_level scsi_level; }; diff --git a/src/raspberrypi/rascsi.cpp b/src/raspberrypi/rascsi.cpp index ecc29921..7105220c 100644 --- a/src/raspberrypi/rascsi.cpp +++ b/src/raspberrypi/rascsi.cpp @@ -106,7 +106,8 @@ void Banner(int argc, char* argv[]) FPRT(stdout," m is the optional logical unit (LUN) (0-31).\n"); FPRT(stdout," FILE is a disk image file, \"daynaport\", \"bridge\", \"printer\" or \"services\".\n\n"); FPRT(stdout," Image type is detected based on file extension if no explicit type is specified.\n"); - FPRT(stdout," hds : SCSI HD image (Non-removable generic HD image)\n"); + FPRT(stdout," hd1 : SCSI-1 HD image (Non-removable generic SCSI-1 HD image)\n"); + FPRT(stdout," hds : SCSI HD image (Non-removable generic SCSI HD image)\n"); FPRT(stdout," hdr : SCSI HD image (Removable generic HD image)\n"); FPRT(stdout," hdn : SCSI HD image (NEC GENUINE)\n"); FPRT(stdout," hdi : SCSI HD image (Anex86 HD image)\n"); diff --git a/src/raspberrypi/test/device_factory_test.cpp b/src/raspberrypi/test/device_factory_test.cpp index 1a57ea42..ef1fd2e1 100644 --- a/src/raspberrypi/test/device_factory_test.cpp +++ b/src/raspberrypi/test/device_factory_test.cpp @@ -15,6 +15,7 @@ TEST(DeviceFactoryTest, GetTypeForFile) { + EXPECT_EQ(device_factory.GetTypeForFile("test.hd1"), SCHD); EXPECT_EQ(device_factory.GetTypeForFile("test.hds"), SCHD); EXPECT_EQ(device_factory.GetTypeForFile("test.HDS"), SCHD); EXPECT_EQ(device_factory.GetTypeForFile("test.hda"), SCHD); @@ -37,6 +38,7 @@ TEST(DeviceFactoryTest, LifeCycle) { Device *device = device_factory.CreateDevice(UNDEFINED, "services", -1); EXPECT_NE(nullptr, device); + EXPECT_EQ("SCHS", device->GetType()); list devices = device_factory.GetAllDevices(); EXPECT_EQ(1, devices.size()); diff --git a/src/raspberrypi/test/mode_pages_test.cpp b/src/raspberrypi/test/mode_pages_test.cpp index 5c0de6a9..403db572 100644 --- a/src/raspberrypi/test/mode_pages_test.cpp +++ b/src/raspberrypi/test/mode_pages_test.cpp @@ -29,6 +29,7 @@ TEST(ModePagesTest, ModePageDevice_AddModePages) MockModePageDevice device; cdb[2] = 0x3f; + EXPECT_EQ(0, device.AddModePages(cdb, buf, 0)) << "Allocation length was not limited"; EXPECT_EQ(1, device.AddModePages(cdb, buf, 1)) << "Allocation length was not limited"; cdb[2] = 0x00;