From 6bbaa956ed0f9670051ed8ccc53cafc29916fe08 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Tue, 25 Oct 2022 10:29:57 +0200 Subject: [PATCH 1/4] Use C++ filesystem library/iostreams for I/O, added unit tests (#911) (#934) * Use C++ filesystem library/iostreams for I/O (issue #911) * Added unit tests --- src/raspberrypi/Makefile | 7 +- .../controllers/scsi_controller.cpp | 2 + src/raspberrypi/controllers/scsi_controller.h | 2 +- src/raspberrypi/devices/cd_track.cpp | 7 +- src/raspberrypi/devices/cd_track.h | 11 +- src/raspberrypi/devices/cfilesystem.cpp | 1 - src/raspberrypi/devices/cfilesystem.h | 4 + src/raspberrypi/devices/ctapdriver.cpp | 6 +- src/raspberrypi/devices/ctapdriver.h | 3 +- src/raspberrypi/devices/disk.cpp | 22 +- src/raspberrypi/devices/disk_cache.cpp | 7 +- src/raspberrypi/devices/disk_cache.h | 6 +- src/raspberrypi/devices/disk_track.cpp | 47 ++-- src/raspberrypi/devices/disk_track.h | 11 +- src/raspberrypi/devices/scsi_daynaport.cpp | 4 +- src/raspberrypi/devices/scsi_host_bridge.h | 2 +- src/raspberrypi/devices/scsi_printer.cpp | 73 +++-- src/raspberrypi/devices/scsi_printer.h | 16 +- src/raspberrypi/devices/scsicd.cpp | 107 ++----- src/raspberrypi/devices/scsihd.cpp | 18 +- src/raspberrypi/devices/scsihd.h | 8 +- src/raspberrypi/devices/scsihd_nec.cpp | 69 ++--- src/raspberrypi/devices/scsihd_nec.h | 4 +- src/raspberrypi/devices/scsimo.cpp | 12 +- src/raspberrypi/devices/scsimo.h | 2 + src/raspberrypi/devices/storage_device.cpp | 23 +- src/raspberrypi/devices/storage_device.h | 5 +- src/raspberrypi/filepath.cpp | 101 ------- src/raspberrypi/filepath.h | 51 ---- src/raspberrypi/rascsi.cpp | 13 +- src/raspberrypi/rascsi/rascsi_executor.cpp | 18 +- src/raspberrypi/rascsi/rascsi_image.cpp | 260 ++++++++++-------- src/raspberrypi/rascsi/rascsi_image.h | 4 + src/raspberrypi/rascsi/rascsi_response.cpp | 13 +- src/raspberrypi/rasdump.cpp | 9 +- .../{fileio.cpp => rasdump_fileio.cpp} | 33 +-- .../{fileio.h => rasdump_fileio.h} | 6 +- src/raspberrypi/test/host_services_test.cpp | 15 +- src/raspberrypi/test/mocks.h | 1 + .../test/protobuf_serializer_test.cpp | 38 ++- src/raspberrypi/test/rascsi_executor_test.cpp | 35 +-- src/raspberrypi/test/rascsi_image_test.cpp | 25 +- src/raspberrypi/test/scsi_printer_test.cpp | 10 + src/raspberrypi/test/scsicd_test.cpp | 94 ++++++- src/raspberrypi/test/scsihd_nec_test.cpp | 164 ++++++++++- src/raspberrypi/test/scsihd_test.cpp | 63 ++++- src/raspberrypi/test/scsimo_test.cpp | 26 +- src/raspberrypi/test/storage_device_test.cpp | 62 +++-- src/raspberrypi/test/test_shared.cpp | 31 +-- src/raspberrypi/test/test_shared.h | 7 +- 50 files changed, 824 insertions(+), 734 deletions(-) delete mode 100644 src/raspberrypi/filepath.cpp delete mode 100644 src/raspberrypi/filepath.h rename src/raspberrypi/{fileio.cpp => rasdump_fileio.cpp} (76%) rename src/raspberrypi/{fileio.h => rasdump_fileio.h} (80%) diff --git a/src/raspberrypi/Makefile b/src/raspberrypi/Makefile index 81df7e83..fd90e8aa 100644 --- a/src/raspberrypi/Makefile +++ b/src/raspberrypi/Makefile @@ -92,9 +92,7 @@ SRC_SHARED = \ protobuf_serializer.cpp SRC_RASCSI_CORE = \ - bus.cpp \ - filepath.cpp \ - fileio.cpp + bus.cpp SRC_RASCSI_CORE += $(shell find ./rascsi -name '*.cpp') SRC_RASCSI_CORE += $(shell find ./controllers -name '*.cpp') SRC_RASCSI_CORE += $(shell find ./devices -name '*.cpp') @@ -116,8 +114,7 @@ SRC_RASCTL = rasctl.cpp SRC_RASDUMP = \ rasdump.cpp \ bus.cpp \ - filepath.cpp \ - fileio.cpp \ + rasdump_fileio.cpp \ rascsi_version.cpp SRC_RASDUMP += $(shell find ./hal -name '*.cpp') diff --git a/src/raspberrypi/controllers/scsi_controller.cpp b/src/raspberrypi/controllers/scsi_controller.cpp index 031e82c4..49e34382 100644 --- a/src/raspberrypi/controllers/scsi_controller.cpp +++ b/src/raspberrypi/controllers/scsi_controller.cpp @@ -27,6 +27,8 @@ using namespace scsi_defs; +const int ScsiController::LUN_MAX = 32; + ScsiController::ScsiController(shared_ptr bus, int target_id) : AbstractController(bus, target_id, LUN_MAX) { // The initial buffer size will default to either the default buffer size OR diff --git a/src/raspberrypi/controllers/scsi_controller.h b/src/raspberrypi/controllers/scsi_controller.h index 3d545b7d..3016866b 100644 --- a/src/raspberrypi/controllers/scsi_controller.h +++ b/src/raspberrypi/controllers/scsi_controller.h @@ -52,7 +52,7 @@ class ScsiController : public AbstractController public: // Maximum number of logical units - static const int LUN_MAX = 32; + static const int LUN_MAX; ScsiController(shared_ptr, int); ~ScsiController() override = default; diff --git a/src/raspberrypi/devices/cd_track.cpp b/src/raspberrypi/devices/cd_track.cpp index f32b7621..1a389f3b 100644 --- a/src/raspberrypi/devices/cd_track.cpp +++ b/src/raspberrypi/devices/cd_track.cpp @@ -30,7 +30,7 @@ void CDTrack::Init(int track, uint32_t first, uint32_t last) last_lba = last; } -void CDTrack::SetPath(bool cdda, const Filepath& path) +void CDTrack::SetPath(bool cdda, string_view path) { assert(valid); @@ -41,12 +41,11 @@ void CDTrack::SetPath(bool cdda, const Filepath& path) imgpath = path; } -void CDTrack::GetPath(Filepath& path) const +string CDTrack::GetPath() const { assert(valid); - // Return the path (by reference) - path = imgpath; + return imgpath; } //--------------------------------------------------------------------------- diff --git a/src/raspberrypi/devices/cd_track.h b/src/raspberrypi/devices/cd_track.h index 0e097399..a980333e 100644 --- a/src/raspberrypi/devices/cd_track.h +++ b/src/raspberrypi/devices/cd_track.h @@ -14,7 +14,9 @@ #pragma once -#include "filepath.h" +#include + +using namespace std; class CDTrack final { @@ -26,8 +28,8 @@ public: void Init(int track, uint32_t first, uint32_t last); // Properties - void SetPath(bool cdda, const Filepath& path); // Set the path - void GetPath(Filepath& path) const; // Get the path + void SetPath(bool, string_view); // Set the path + string GetPath() const; // Get the path uint32_t GetFirst() const; // Get the start LBA uint32_t GetLast() const; // Get the last LBA uint32_t GetBlocks() const; // Get the number of blocks @@ -41,5 +43,6 @@ private: uint32_t first_lba = 0; // First LBA uint32_t last_lba = 0; // Last LBA bool audio = false; // Audio track flag - Filepath imgpath; // Image file path + + string imgpath; // Image file path }; diff --git a/src/raspberrypi/devices/cfilesystem.cpp b/src/raspberrypi/devices/cfilesystem.cpp index 61c7433a..ea0d297f 100644 --- a/src/raspberrypi/devices/cfilesystem.cpp +++ b/src/raspberrypi/devices/cfilesystem.cpp @@ -19,7 +19,6 @@ #include "os.h" #include "log.h" -#include "filepath.h" #include "cfilesystem.h" #include #include diff --git a/src/raspberrypi/devices/cfilesystem.h b/src/raspberrypi/devices/cfilesystem.h index 47bce73f..ff08ea2d 100644 --- a/src/raspberrypi/devices/cfilesystem.h +++ b/src/raspberrypi/devices/cfilesystem.h @@ -13,6 +13,10 @@ #pragma once +using TCHAR = char; + +static const int FILEPATH_MAX = 260; + //--------------------------------------------------------------------------- // // Status code definitions diff --git a/src/raspberrypi/devices/ctapdriver.cpp b/src/raspberrypi/devices/ctapdriver.cpp index 7dae785a..14342bb2 100644 --- a/src/raspberrypi/devices/ctapdriver.cpp +++ b/src/raspberrypi/devices/ctapdriver.cpp @@ -373,20 +373,20 @@ bool CTapDriver::Init(const unordered_map& const_params) #endif } -void CTapDriver::OpenDump(const Filepath& path) { +void CTapDriver::OpenDump(const string& path) { if (m_pcap == nullptr) { m_pcap = pcap_open_dead(DLT_EN10MB, 65535); } if (m_pcap_dumper != nullptr) { pcap_dump_close(m_pcap_dumper); } - m_pcap_dumper = pcap_dump_open(m_pcap, path.GetPath()); + m_pcap_dumper = pcap_dump_open(m_pcap, path.c_str()); if (m_pcap_dumper == nullptr) { LOGERROR("Can't open pcap file: %s", pcap_geterr(m_pcap)) throw io_exception("Can't open pcap file"); } - LOGTRACE("%s Opened %s for dumping", __PRETTY_FUNCTION__, path.GetPath()) + LOGTRACE("%s Opened %s for dumping", __PRETTY_FUNCTION__, path.c_str()) } bool CTapDriver::Enable() const diff --git a/src/raspberrypi/devices/ctapdriver.h b/src/raspberrypi/devices/ctapdriver.h index 6200451c..87ac757e 100644 --- a/src/raspberrypi/devices/ctapdriver.h +++ b/src/raspberrypi/devices/ctapdriver.h @@ -13,7 +13,6 @@ #include #include -#include "filepath.h" #include #include #include @@ -33,7 +32,7 @@ public: CTapDriver& operator=(const CTapDriver&) = default; bool Init(const unordered_map&); - void OpenDump(const Filepath& path); // Capture packets + void OpenDump(const string& path); // Capture packets void GetMacAddr(BYTE *mac) const; int Receive(BYTE *buf); int Send(const BYTE *buf, int len); diff --git a/src/raspberrypi/devices/disk.cpp b/src/raspberrypi/devices/disk.cpp index 823a4ccb..c4d40024 100644 --- a/src/raspberrypi/devices/disk.cpp +++ b/src/raspberrypi/devices/disk.cpp @@ -14,7 +14,6 @@ // //--------------------------------------------------------------------------- -#include "fileio.h" #include "rascsi_exceptions.h" #include "dispatcher.h" #include "scsi_command_util.h" @@ -79,17 +78,13 @@ bool Disk::Dispatch(scsi_command cmd) void Disk::SetUpCache(off_t image_offset, bool raw) { - Filepath path; - path.SetPath(GetFilename().c_str()); - cache = make_unique(path, size_shift_count, (uint32_t)GetBlockCount(), image_offset); + cache = make_unique(GetFilename(), size_shift_count, (uint32_t)GetBlockCount(), image_offset); cache->SetRawMode(raw); } -void Disk::ResizeCache(const string& filename, bool raw) +void Disk::ResizeCache(const string& path, bool raw) { - Filepath path; - path.SetPath(filename.c_str()); - cache.reset(new DiskCache(path, GetSectorSizeShiftCount(), (uint32_t)GetBlockCount())); + cache.reset(new DiskCache(path, size_shift_count, (uint32_t)GetBlockCount())); cache->SetRawMode(raw); } @@ -501,8 +496,7 @@ int Disk::Read(const vector&, vector& buf, uint64_t block) throw scsi_exception(sense_key::MEDIUM_ERROR, asc::READ_FAULT); } - // Success - return 1 << size_shift_count; + return GetSectorSizeInBytes(); } int Disk::WriteCheck(uint64_t block) @@ -519,18 +513,14 @@ int Disk::WriteCheck(uint64_t block) throw scsi_exception(sense_key::DATA_PROTECT, asc::WRITE_PROTECTED); } - // Success - return 1 << size_shift_count; + return GetSectorSizeInBytes(); } void Disk::Write(const vector&, const vector& buf, uint64_t block) { LOGTRACE("%s", __PRETTY_FUNCTION__) - // Error if not ready - if (!IsReady()) { - throw scsi_exception(sense_key::NOT_READY); - } + CheckReady(); // Error if the total number of blocks is exceeded if (block >= GetBlockCount()) { diff --git a/src/raspberrypi/devices/disk_cache.cpp b/src/raspberrypi/devices/disk_cache.cpp index 5bee54e8..478295f9 100644 --- a/src/raspberrypi/devices/disk_cache.cpp +++ b/src/raspberrypi/devices/disk_cache.cpp @@ -14,18 +14,17 @@ // //--------------------------------------------------------------------------- +#include "os.h" #include "disk_track.h" #include "disk_cache.h" #include #include -DiskCache::DiskCache(const Filepath& path, int size, uint32_t blocks, off_t imgoff) - : sec_size(size), sec_blocks(blocks), imgoffset(imgoff) +DiskCache::DiskCache(const string& path, int size, uint32_t blocks, off_t imgoff) + : sec_path(path), sec_size(size), sec_blocks(blocks), imgoffset(imgoff) { assert(blocks > 0); assert(imgoff >= 0); - - sec_path = path; } bool DiskCache::Save() const diff --git a/src/raspberrypi/devices/disk_cache.h b/src/raspberrypi/devices/disk_cache.h index 822481b1..f6ccec64 100644 --- a/src/raspberrypi/devices/disk_cache.h +++ b/src/raspberrypi/devices/disk_cache.h @@ -15,9 +15,9 @@ #pragma once -#include "filepath.h" #include #include +#include using namespace std; @@ -34,7 +34,7 @@ public: uint32_t serial; // Serial }; - DiskCache(const Filepath& path, int size, uint32_t blocks, off_t imgoff = 0); + DiskCache(const string&, int, uint32_t, off_t = 0); ~DiskCache() = default; void SetRawMode(bool b) { cd_raw = b; } // CD-ROM raw mode setting @@ -55,7 +55,7 @@ private: // Internal data array cache = {}; // Cache management uint32_t serial = 0; // Last serial number - Filepath sec_path; // Path + string sec_path; // Path int sec_size; // Sector Size (8=256, 9=512, 10=1024, 11=2048, 12=4096) int sec_blocks; // Blocks per sector bool cd_raw = false; // CD-ROM RAW mode diff --git a/src/raspberrypi/devices/disk_track.cpp b/src/raspberrypi/devices/disk_track.cpp index 58337f7e..bcd506f8 100644 --- a/src/raspberrypi/devices/disk_track.cpp +++ b/src/raspberrypi/devices/disk_track.cpp @@ -15,8 +15,8 @@ //--------------------------------------------------------------------------- #include "log.h" -#include "fileio.h" #include "disk_track.h" +#include DiskTrack::~DiskTrack() { @@ -46,7 +46,7 @@ void DiskTrack::Init(int track, int size, int sectors, bool raw, off_t imgoff) dt.imgoffset = imgoff; } -bool DiskTrack::Load(const Filepath& path) +bool DiskTrack::Load(const string& path) { // Not needed if already loaded if (dt.init) { @@ -97,24 +97,21 @@ bool DiskTrack::Load(const Filepath& path) dt.changemap.resize(dt.sectors); fill(dt.changemap.begin(), dt.changemap.end(), false); - // Read from File - Fileio fio; - if (!fio.OpenDIO(path, Fileio::OpenMode::ReadOnly)) { + ifstream in(path, ios::binary); + if (in.fail()) { return false; } if (dt.raw) { // Split Reading for (int i = 0; i < dt.sectors; i++) { - // Seek - if (!fio.Seek(offset)) { - fio.Close(); + in.seekg(offset); + if (in.fail()) { return false; } - // Read - if (!fio.Read(&dt.buffer[i << dt.size], 1 << dt.size)) { - fio.Close(); + in.read((char *)&dt.buffer[i << dt.size], 1 << dt.size); + if (in.fail()) { return false; } @@ -123,16 +120,15 @@ bool DiskTrack::Load(const Filepath& path) } } else { // Continuous reading - if (!fio.Seek(offset)) { - fio.Close(); + in.seekg(offset); + if (in.fail()) { return false; } - if (!fio.Read(dt.buffer, length)) { - fio.Close(); + in.read((char *)dt.buffer, length); + if (in.fail()) { return false; } } - fio.Close(); // Set a flag and end normally dt.init = true; @@ -140,7 +136,7 @@ bool DiskTrack::Load(const Filepath& path) return true; } -bool DiskTrack::Save(const Filepath& path) +bool DiskTrack::Save(const string& path) { // Not needed if not initialized if (!dt.init) { @@ -169,9 +165,8 @@ bool DiskTrack::Save(const Filepath& path) // Calculate length per sector const int length = 1 << dt.size; - // Open file - Fileio fio; - if (!fio.Open(path, Fileio::OpenMode::ReadWrite)) { + ofstream out(path, ios::in | ios::out | ios::binary); + if (out.fail()) { return false; } @@ -183,9 +178,8 @@ bool DiskTrack::Save(const Filepath& path) // Initialize write size total = 0; - // Seek - if (!fio.Seek(offset + ((off_t)i << dt.size))) { - fio.Close(); + out.seekp(offset + ((off_t)i << dt.size)); + if (out.fail()) { return false; } @@ -201,9 +195,8 @@ bool DiskTrack::Save(const Filepath& path) total += length; } - // Write - if (!fio.Write(&dt.buffer[i << dt.size], total)) { - fio.Close(); + out.write((const char *)&dt.buffer[i << dt.size], total); + if (out.fail()) { return false; } @@ -215,8 +208,6 @@ bool DiskTrack::Save(const Filepath& path) } } - fio.Close(); - // Drop the change flag and exit fill(dt.changemap.begin(), dt.changemap.end(), false); dt.changed = false; diff --git a/src/raspberrypi/devices/disk_track.h b/src/raspberrypi/devices/disk_track.h index 20bc1a51..3a421848 100644 --- a/src/raspberrypi/devices/disk_track.h +++ b/src/raspberrypi/devices/disk_track.h @@ -15,9 +15,10 @@ #pragma once -#include "filepath.h" +#include "os.h" #include #include +#include using namespace std; @@ -31,7 +32,7 @@ class DiskTrack BYTE *buffer; // Data buffer bool init; // Is it initilized? bool changed; // Changed flag - std::vector changemap; // Changed map + vector changemap; // Changed map bool raw; // RAW mode flag off_t imgoffset; // Offset to actual data } dt = {}; @@ -48,12 +49,12 @@ private: friend class DiskCache; void Init(int track, int size, int sectors, bool raw = false, off_t imgoff = 0); - bool Load(const Filepath& path); - bool Save(const Filepath& path); + bool Load(const string& path); + bool Save(const string& path); // Read / Write bool ReadSector(vector&, int) const; // Sector Read - bool WriteSector(const vector& buf, int); // Sector Write + bool WriteSector(const vector& buf, int); // Sector Write int GetTrack() const { return dt.track; } // Get track }; diff --git a/src/raspberrypi/devices/scsi_daynaport.cpp b/src/raspberrypi/devices/scsi_daynaport.cpp index 3f06465f..3567f1ae 100644 --- a/src/raspberrypi/devices/scsi_daynaport.cpp +++ b/src/raspberrypi/devices/scsi_daynaport.cpp @@ -91,9 +91,7 @@ bool SCSIDaynaPort::Init(const unordered_map& params) void SCSIDaynaPort::Open() { - Filepath path; - path.SetPath(GetFilename().c_str()); - m_tap.OpenDump(path); + m_tap.OpenDump(GetFilename().c_str()); } vector SCSIDaynaPort::InquiryInternal() const diff --git a/src/raspberrypi/devices/scsi_host_bridge.h b/src/raspberrypi/devices/scsi_host_bridge.h index 8bbcda7d..89d16396 100644 --- a/src/raspberrypi/devices/scsi_host_bridge.h +++ b/src/raspberrypi/devices/scsi_host_bridge.h @@ -39,7 +39,7 @@ public: bool Dispatch(scsi_command) override; // TODO Remove as soon as SCSIBR is not a subclass of Disk anymore - void Open() override { super::ValidateFile(GetFilename()); } + void Open() override { super::ValidateFile(); } // Commands vector InquiryInternal() const override; diff --git a/src/raspberrypi/devices/scsi_printer.cpp b/src/raspberrypi/devices/scsi_printer.cpp index dad93733..921206bb 100644 --- a/src/raspberrypi/devices/scsi_printer.cpp +++ b/src/raspberrypi/devices/scsi_printer.cpp @@ -17,6 +17,7 @@ // 2. The client triggers printing with SYNCHRONIZE BUFFER. Each SYNCHRONIZE BUFFER results in // the print command for this printer (see below) to be called for the data not yet printed. // +// It is recommended to reserve the printer device before printing and to release it afterwards. // The command to be used for printing can be set with the "cmd" property when attaching the device. // By default the data to be printed are sent to the printer unmodified, using "lp -oraw %f". This // requires that the client uses a printer driver compatible with the respective printer, or that the @@ -33,8 +34,10 @@ #include "scsi_command_util.h" #include "dispatcher.h" #include "scsi_printer.h" +#include using namespace std; +using namespace filesystem; using namespace scsi_defs; using namespace scsi_command_util; @@ -43,13 +46,18 @@ SCSIPrinter::SCSIPrinter(int lun) : PrimaryDevice(SCLP, lun) dispatcher.Add(scsi_command::eCmdTestUnitReady, "TestUnitReady", &SCSIPrinter::TestUnitReady); dispatcher.Add(scsi_command::eCmdPrint, "Print", &SCSIPrinter::Print); dispatcher.Add(scsi_command::eCmdSynchronizeBuffer, "SynchronizeBuffer", &SCSIPrinter::SynchronizeBuffer); - dispatcher.Add(scsi_command::eCmdStopPrint, "StopPrint", &SCSIPrinter::StopPrint); + // STOP PRINT is identical with TEST UNIT READY, it just returns the status + dispatcher.Add(scsi_command::eCmdStopPrint, "StopPrint", &SCSIPrinter::TestUnitReady); // Required also in this class in order to fulfill the ScsiPrinterCommands interface contract dispatcher.Add(scsi_command::eCmdReserve6, "ReserveUnit", &SCSIPrinter::ReserveUnit); dispatcher.Add(scsi_command::eCmdRelease6, "ReleaseUnit", &SCSIPrinter::ReleaseUnit); dispatcher.Add(scsi_command::eCmdSendDiag, "SendDiagnostic", &SCSIPrinter::SendDiagnostic); + error_code error; + file_template = temp_directory_path(error); //NOSONAR Publicly writable directory is fine here + file_template += PRINTER_FILE_PATTERN; + SupportsParams(true); SetReady(true); } @@ -109,70 +117,75 @@ void SCSIPrinter::Print() void SCSIPrinter::SynchronizeBuffer() { - if (fd == -1) { - LOGWARN("Missing printer output file") + if (!out.is_open()) { + LOGWARN("Nothing to print") throw scsi_exception(sense_key::ABORTED_COMMAND); } - struct stat st; - fstat(fd, &st); - - close(fd); - fd = -1; - string cmd = GetParam("cmd"); const size_t file_position = cmd.find("%f"); assert(file_position != string::npos); cmd.replace(file_position, 2, filename); - LOGTRACE("%s", string("Printing file with size of " + to_string(st.st_size) +" byte(s)").c_str()) + error_code error; + + LOGTRACE("Printing file '%s' with %s byte(s)", filename.c_str(), to_string(file_size(path(filename), error)).c_str()) LOGDEBUG("Executing '%s'", cmd.c_str()) if (system(cmd.c_str())) { - LOGERROR("Printing failed, the printing system might not be configured") + LOGERROR("Printing file '%s' failed, the printing system might not be configured", filename.c_str()) - unlink(filename); + Cleanup(); throw scsi_exception(sense_key::ABORTED_COMMAND); } - unlink(filename); + Cleanup(); EnterStatusPhase(); } -void SCSIPrinter::StopPrint() -{ - // Command implementations are identical - TestUnitReady(); -} - bool SCSIPrinter::WriteByteSequence(vector& buf, uint32_t length) { - if (fd == -1) { - strcpy(filename, TMP_FILE_PATTERN); //NOSONAR Using strcpy is safe here - fd = mkstemp(filename); + if (!out.is_open()) { + vector f(file_template.begin(), file_template.end()); + f.push_back(0); + + // There is no C++ API that generates a file with a unique name + const int fd = mkstemp(f.data()); if (fd == -1) { - LOGERROR("Can't create printer output file '%s': %s", filename, strerror(errno)) + LOGERROR("Can't create printer output file for pattern '%s': %s", filename.c_str(), strerror(errno)) return false; } + close(fd); - LOGTRACE("Created printer output file '%s'", filename) + filename = f.data(); + + out.open(filename, ios::binary); + if (out.fail()) { + throw scsi_exception(sense_key::ABORTED_COMMAND); + } + + LOGTRACE("Created printer output file '%s'", filename.c_str()) } - LOGTRACE("Appending %d byte(s) to printer output file '%s'", length, filename) + LOGTRACE("Appending %d byte(s) to printer output file '%s'", length, filename.c_str()) - return (uint32_t)write(fd, buf.data(), length) == length; + out.write((const char*)buf.data(), length); + + return !out.fail(); } void SCSIPrinter::Cleanup() { - if (fd != -1) { - close(fd); - fd = -1; + if (out.is_open()) { + out.close(); - unlink(filename); + error_code error; + remove(path(filename), error); + + filename = ""; } } diff --git a/src/raspberrypi/devices/scsi_printer.h b/src/raspberrypi/devices/scsi_printer.h index 1972df7d..8c4d4c09 100644 --- a/src/raspberrypi/devices/scsi_printer.h +++ b/src/raspberrypi/devices/scsi_printer.h @@ -12,16 +12,18 @@ #include "interfaces/scsi_printer_commands.h" #include "primary_device.h" +#include #include #include +using namespace std; + class SCSIPrinter : public PrimaryDevice, ScsiPrinterCommands //NOSONAR Custom destructor cannot be removed { - static constexpr const char *TMP_FILE_PATTERN = "/tmp/rascsi_sclp-XXXXXX"; //NOSONAR Using /tmp is safe - static const int TMP_FILENAME_LENGTH = string_view(TMP_FILE_PATTERN).size(); - static const int NOT_RESERVED = -2; + static constexpr const char *PRINTER_FILE_PATTERN = "/rascsi_sclp-XXXXXX"; + public: explicit SCSIPrinter(int); @@ -39,7 +41,6 @@ public: void SendDiagnostic() override { PrimaryDevice::SendDiagnostic(); } void Print() override; void SynchronizeBuffer(); - void StopPrint(); bool WriteByteSequence(vector&, uint32_t) override; @@ -49,6 +50,9 @@ private: Dispatcher dispatcher; - char filename[TMP_FILENAME_LENGTH + 1]; //NOSONAR mkstemp() requires a modifiable string - int fd = -1; + string file_template; + + string filename; + + ofstream out; }; diff --git a/src/raspberrypi/devices/scsicd.cpp b/src/raspberrypi/devices/scsicd.cpp index aa793a18..10188cc7 100644 --- a/src/raspberrypi/devices/scsicd.cpp +++ b/src/raspberrypi/devices/scsicd.cpp @@ -14,12 +14,12 @@ // //--------------------------------------------------------------------------- -#include "fileio.h" #include "rascsi_exceptions.h" #include "scsi_command_util.h" #include "dispatcher.h" #include "scsicd.h" #include +#include using namespace scsi_defs; using namespace scsi_command_util; @@ -50,48 +50,29 @@ void SCSICD::Open() rawfile = false; ClearTrack(); - // Open as read-only - Filepath path; - path.SetPath(GetFilename().c_str()); - Fileio fio; - if (!fio.Open(path, Fileio::OpenMode::ReadOnly)) { - throw file_not_found_exception("Can't open CD-ROM file '" + GetFilename() + "'"); - } - // Default sector size is 2048 bytes SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 2048); - // Close and transfer for physical CD access - if (path.GetPath()[0] == '\\') { - // Close - fio.Close(); - - // Open physical CD + if (GetFilename()[0] == '\\') { OpenPhysical(); } else { - if (GetFileSize() < 4) { - fio.Close(); - throw io_exception("CD-ROM file size must be at least 4 bytes"); + // Judge whether it is a CUE sheet or an ISO file + array cue; + ifstream in(GetFilename(), ios::binary); + in.read(cue.data(), cue.size()); + if (!in.good()) { + throw io_exception("Can't read header of CD-ROM file '" + GetFilename() + "'"); } - // Judge whether it is a CUE sheet or an ISO file - array file; - fio.Read((BYTE *)file.data(), 4); - file[4] = '\0'; - fio.Close(); - - // If it starts with FILE, consider it as a CUE sheet - if (!strcasecmp(file.data(), "FILE")) { - throw io_exception("Opening CUE CD-ROM files is not supported"); + // If it starts with FILE consider it a CUE sheet + if (!strncasecmp(cue.data(), "FILE", cue.size())) { + throw io_exception("CUE CD-ROM files are not supported"); } else { OpenIso(); } } - // Successful opening - assert(GetBlockCount() > 0); - - super::ValidateFile(GetFilename()); + super::ValidateFile(); SetUpCache(0, rawfile); @@ -106,80 +87,56 @@ void SCSICD::Open() void SCSICD::OpenIso() { - // Open as read-only - Fileio fio; - if (!fio.Open(GetFilename().c_str(), Fileio::OpenMode::ReadOnly)) { - throw io_exception("Can't open ISO CD-ROM file"); - } - - // Get file size const off_t size = GetFileSize(); - if (size < 0x800) { - fio.Close(); + if (size < 2048) { throw io_exception("ISO CD-ROM file size must be at least 2048 bytes"); } - // Read the first 12 bytes and close - array header; - if (!fio.Read(header.data(), header.size())) { - fio.Close(); + // Validate header + array header; + ifstream in(GetFilename(), ios::binary); + in.read(header.data(), header.size()); + if (!in.good()) { throw io_exception("Can't read header of ISO CD-ROM file"); } - // Check if it is RAW format - array sync; - sync.fill(0xff); - sync[0] = 0x00; - sync[11] = 0x00; + // Check if it is in RAW format + array sync = {}; + // 00,FFx10,00 is presumed to be RAW format + fill_n(sync.begin() + 1, 10, 0xff); rawfile = false; - if (memcmp(header.data(), sync.data(), sync.size()) == 0) { - // 00,FFx10,00, so it is presumed to be RAW format - if (!fio.Read(header.data(), 4)) { - fio.Close(); - throw io_exception("Can't read header of raw ISO CD-ROM file"); - } + if (memcmp(header.data(), sync.data(), sync.size()) == 0) { // Supports MODE1/2048 or MODE1/2352 only - if (header[3] != 0x01) { + if (header[15] != 0x01) { // Different mode - fio.Close(); throw io_exception("Illegal raw ISO CD-ROM file header"); } // Set to RAW file rawfile = true; } - fio.Close(); if (rawfile) { - // Size must be a multiple of 2536 if (size % 2536) { throw io_exception("Raw ISO CD-ROM file size must be a multiple of 2536 bytes but is " + to_string(size) + " bytes"); } - // Set the number of blocks - SetBlockCount((uint32_t)(size / 0x930)); + SetBlockCount((uint32_t)(size / 2352)); } else { - // Set the number of blocks SetBlockCount((uint32_t)(size >> GetSectorSizeShiftCount())); } CreateDataTrack(); } +// TODO This code is only executed if the filename starts with a `\`, but fails to open files starting with `\`. void SCSICD::OpenPhysical() { - // Open as read-only - Fileio fio; - if (!fio.Open(GetFilename().c_str(), Fileio::OpenMode::ReadOnly)) { - throw file_not_found_exception("Can't open CD-ROM file '" + GetFilename() + "'"); - } - fio.Close(); - // Get size off_t size = GetFileSize(); - if (size < 0x800) { + if (size < 2048) { throw io_exception("CD-ROM file size must be at least 2048 bytes"); } @@ -198,9 +155,7 @@ void SCSICD::CreateDataTrack() assert(!tracks.size()); auto track = make_unique(); track->Init(1, 0, (int)GetBlockCount() - 1); - Filepath path; - path.SetPath(GetFilename().c_str()); - track->SetPath(false, path); + track->SetPath(false, GetFilename()); tracks.push_back(move(track)); dataindex = 0; } @@ -287,12 +242,8 @@ int SCSICD::Read(const vector& cdb, vector& buf, uint64_t block) SetBlockCount(tracks[index]->GetBlocks()); assert(GetBlockCount() > 0); - // Recreate the disk cache - Filepath path; - tracks[index]->GetPath(path); - // Re-assign disk cache (no need to save) - ResizeCache(path.GetPath(), rawfile); + ResizeCache(tracks[index]->GetPath(), rawfile); // Reset data index dataindex = index; diff --git a/src/raspberrypi/devices/scsihd.cpp b/src/raspberrypi/devices/scsihd.cpp index ba830ac4..7e6b22cd 100644 --- a/src/raspberrypi/devices/scsihd.cpp +++ b/src/raspberrypi/devices/scsihd.cpp @@ -5,17 +5,15 @@ // // Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp) // Copyright (C) 2014-2020 GIMONS +// Copyright (C) 2022 Uwe Seimet // Copyright (C) akuker // // Licensed under the BSD 3-Clause License. // See LICENSE file in the project root folder. // -// [ SCSI hard disk ] -// //--------------------------------------------------------------------------- #include "scsihd.h" -#include "fileio.h" #include "rascsi_exceptions.h" #include "scsi_command_util.h" @@ -56,23 +54,15 @@ string SCSIHD::GetProductData() const return DEFAULT_PRODUCT + " " + to_string(capacity) + " " + unit; } -void SCSIHD::FinalizeSetup(off_t size, off_t image_offset) +void SCSIHD::FinalizeSetup(off_t image_offset) { - // Effective size must be a multiple of the sector size - size = (size / GetSectorSizeInBytes()) * GetSectorSizeInBytes(); - - // 2 TiB is the current maximum - if (size > 2LL * 1024 * 1024 * 1024 * 1024) { - throw io_exception("Drive capacity cannot exceed 2 TiB"); - } + super::ValidateFile(); // For non-removable media drives set the default product name based on the drive capacity if (!IsRemovable()) { SetProduct(GetProductData(), false); } - super::ValidateFile(GetFilename()); - SetUpCache(image_offset); } @@ -86,7 +76,7 @@ void SCSIHD::Open() SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 512); SetBlockCount((uint32_t)(size >> GetSectorSizeShiftCount())); - FinalizeSetup(size); + FinalizeSetup(0); } vector SCSIHD::InquiryInternal() const diff --git a/src/raspberrypi/devices/scsihd.h b/src/raspberrypi/devices/scsihd.h index f93279bb..a7cddb55 100644 --- a/src/raspberrypi/devices/scsihd.h +++ b/src/raspberrypi/devices/scsihd.h @@ -5,19 +5,21 @@ // // Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp) // Copyright (C) 2014-2020 GIMONS +// Copyright (C) 2022 Uwe Seimet // Copyright (C) akuker // // Licensed under the BSD 3-Clause License. // See LICENSE file in the project root folder. // -// [ SCSI hard disk ] -// //--------------------------------------------------------------------------- #pragma once +#include "scsi.h" #include "disk.h" #include +#include +#include class SCSIHD : public Disk { @@ -28,7 +30,7 @@ public: SCSIHD(int, const unordered_set&, bool, scsi_defs::scsi_level = scsi_level::SCSI_2); ~SCSIHD() override = default; - void FinalizeSetup(off_t, off_t = 0); + void FinalizeSetup(off_t); void Open() override; diff --git a/src/raspberrypi/devices/scsihd_nec.cpp b/src/raspberrypi/devices/scsihd_nec.cpp index e81312fe..23248de3 100644 --- a/src/raspberrypi/devices/scsihd_nec.cpp +++ b/src/raspberrypi/devices/scsihd_nec.cpp @@ -14,11 +14,13 @@ // //--------------------------------------------------------------------------- -#include "scsihd_nec.h" -#include "fileio.h" #include "rascsi_exceptions.h" +#include "rasutil.h" #include "scsi_command_util.h" +#include "scsihd_nec.h" +#include +using namespace ras_util; using namespace scsi_command_util; const unordered_set SCSIHD_NEC::sector_sizes = { 512 }; @@ -27,64 +29,38 @@ void SCSIHD_NEC::Open() { assert(!IsReady()); - // Open as read-only - Filepath path; - path.SetPath(GetFilename().c_str()); - Fileio fio; - if (!fio.Open(path, Fileio::OpenMode::ReadOnly)) { - throw file_not_found_exception("Can't open hard disk file '" + GetFilename() + '"'); - } - off_t size = GetFileSize(); - // NEC root sector - array root_sector; - if (size < (off_t)root_sector.size() || !fio.Read(root_sector.data(), root_sector.size())) { - fio.Close(); + array root_sector; + ifstream in(GetFilename(), ios::binary); + in.read(root_sector.data(), root_sector.size()); + if (!in.good() || size < (off_t)root_sector.size()) { throw io_exception("Can't read NEC hard disk file root sector"); } - fio.Close(); // Effective size must be a multiple of 512 size = (size / 512) * 512; // Determine parameters by extension - const auto [image_size, sector_size] = SetParameters(path.GetFileExt(), root_sector, (int)size); + const auto [image_size, sector_size] = SetParameters(root_sector, (int)size); - if (sector_size == 0) { - throw io_exception("Invalid NEC drive sector size"); - } - - // Image size consistency check - if (image_offset + image_size > size || image_size % sector_size != 0) { - throw io_exception("Image size consistency check failed"); - } - - // Calculate sector size - for (size = 16; size > 0; --size) { - if ((1 << size) == sector_size) - break; - } - if (size <= 0 || size > 16) { - throw io_exception("Invalid NEC disk size"); - } SetSectorSizeShiftCount((uint32_t)size); SetBlockCount(image_size >> GetSectorSizeShiftCount()); - FinalizeSetup(size, image_offset); + FinalizeSetup(image_offset); } -pair SCSIHD_NEC::SetParameters(const string& extension, const array& root_sector, int size) +pair SCSIHD_NEC::SetParameters(const array& data, int size) { - string ext = extension; - transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + array root_sector = {}; + memcpy(root_sector.data(), data.data(), root_sector.size()); int image_size; int sector_size; // PC-9801-55 NEC compatible? - if (ext == ".hdn") { + if (const string ext = GetExtensionLowerCase(GetFilename()); ext == "hdn") { // Assuming sector size 512, number of sectors 25, number of heads 8 as default settings image_offset = 0; image_size = size; @@ -96,7 +72,7 @@ pair SCSIHD_NEC::SetParameters(const string& extension, const array SCSIHD_NEC::SetParameters(const string& extension, const array SCSIHD_NEC::SetParameters(const string& extension, const array size) { + throw io_exception("NEC image offset/size consistency check failed"); + } + + if (CalculateShiftCount(sector_size) == 0) { + throw io_exception("Invalid NEC sector size of " + to_string(sector_size) + " byte(s)"); + } + return make_pair(image_size, sector_size); } diff --git a/src/raspberrypi/devices/scsihd_nec.h b/src/raspberrypi/devices/scsihd_nec.h index 59b95391..ba7d3c3e 100644 --- a/src/raspberrypi/devices/scsihd_nec.h +++ b/src/raspberrypi/devices/scsihd_nec.h @@ -47,14 +47,14 @@ protected: private: - pair SetParameters(const string&, const array&, int); + pair SetParameters(const array&, int); static int GetInt16LittleEndian(const BYTE *); static int GetInt32LittleEndian(const BYTE *); static const unordered_set sector_sizes; - // Image file offset (NEC only) + // Image file offset off_t image_offset = 0; // Geometry data diff --git a/src/raspberrypi/devices/scsimo.cpp b/src/raspberrypi/devices/scsimo.cpp index b2680ea6..a1c52b07 100644 --- a/src/raspberrypi/devices/scsimo.cpp +++ b/src/raspberrypi/devices/scsimo.cpp @@ -12,7 +12,6 @@ // //--------------------------------------------------------------------------- -#include "fileio.h" #include "rascsi_exceptions.h" #include "scsi_command_util.h" #include "scsimo.h" @@ -43,21 +42,14 @@ void SCSIMO::Open() { assert(!IsReady()); - off_t size = GetFileSize(); - - // 2 TiB is the current maximum - if (size > 2LL * 1024 * 1024 * 1024 * 1024) { - throw io_exception("Drive capacity cannot exceed 2 TiB"); - } - // For some capacities there are hard-coded, well-defined sector sizes and block counts - if (!SetGeometryForCapacity(size)) { + if (const off_t size = GetFileSize(); !SetGeometryForCapacity(size)) { // Sector size (default 512 bytes) and number of blocks SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 512); SetBlockCount(size >> GetSectorSizeShiftCount()); } - super::ValidateFile(GetFilename()); + super::ValidateFile(); SetUpCache(0); diff --git a/src/raspberrypi/devices/scsimo.h b/src/raspberrypi/devices/scsimo.h index 4dbe4656..414e546e 100644 --- a/src/raspberrypi/devices/scsimo.h +++ b/src/raspberrypi/devices/scsimo.h @@ -15,6 +15,8 @@ #pragma once #include "disk.h" +#include +#include using Geometry = pair; diff --git a/src/raspberrypi/devices/storage_device.cpp b/src/raspberrypi/devices/storage_device.cpp index bcb4c31e..b8bc655c 100644 --- a/src/raspberrypi/devices/storage_device.cpp +++ b/src/raspberrypi/devices/storage_device.cpp @@ -23,14 +23,22 @@ StorageDevice::StorageDevice(PbDeviceType type, int lun) : ModePageDevice(type, SetStoppable(true); } -void StorageDevice::ValidateFile(const string& file) +void StorageDevice::ValidateFile() { if (blocks == 0) { throw io_exception(string(GetTypeString()) + " device has 0 blocks"); } + if (!exists(path(filename))) { + throw file_not_found_exception("Image file '" + filename + "' for " + GetTypeString() + " device does not exist"); + } + + if (GetFileSize() > 2LL * 1024 * 1024 * 1024 * 1024) { + throw io_exception("Drive capacity cannot exceed 2 TiB"); + } + // TODO Check for duplicate handling of these properties (-> rascsi_executor.cpp) - if (access(file.c_str(), W_OK)) { + if (access(filename.c_str(), W_OK)) { // Permanently write-protected SetReadOnly(true); SetProtectable(false); @@ -65,16 +73,13 @@ void StorageDevice::UnreserveFile() filename = ""; } -bool StorageDevice::GetIdsForReservedFile(const string& file, int& id, int& lun) +pair StorageDevice::GetIdsForReservedFile(const string& file) { if (const auto& it = reserved_files.find(file); it != reserved_files.end()) { - id = it->second.first; - lun = it->second.second; - - return true; + return make_pair(it->second.first, it->second.second); } - return false; + return make_pair(-1, -1); } void StorageDevice::UnreserveAll() @@ -94,7 +99,7 @@ bool StorageDevice::IsReadOnlyFile() const off_t StorageDevice::GetFileSize() const { - // filesystem::file_size cannot be used here because gcc < 10.3.0 cannot handled more than 2 GiB + // filesystem::file_size cannot be used here because gcc < 10.3.0 cannot handle more than 2 GiB if (struct stat st; !stat(filename.c_str(), &st)) { return st.st_size; } diff --git a/src/raspberrypi/devices/storage_device.h b/src/raspberrypi/devices/storage_device.h index caea0b3a..93a0a153 100644 --- a/src/raspberrypi/devices/storage_device.h +++ b/src/raspberrypi/devices/storage_device.h @@ -28,7 +28,6 @@ public: virtual void Open() = 0; - void ValidateFile(const string&); string GetFilename() const { return filename; } void SetFilename(string_view f) { filename = f; } @@ -45,10 +44,12 @@ public: static unordered_map GetReservedFiles() { return reserved_files; } static void SetReservedFiles(const unordered_map& r) { reserved_files = r; } - static bool GetIdsForReservedFile(const string&, int&, int&); + static pair GetIdsForReservedFile(const string&); protected: + void ValidateFile(); + bool IsMediumChanged() const { return medium_changed; } void SetMediumChanged(bool b) { medium_changed = b; } diff --git a/src/raspberrypi/filepath.cpp b/src/raspberrypi/filepath.cpp deleted file mode 100644 index 50e14d38..00000000 --- a/src/raspberrypi/filepath.cpp +++ /dev/null @@ -1,101 +0,0 @@ -//--------------------------------------------------------------------------- -// -// X68000 EMULATOR "XM6" -// -// Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp) -// Copyright (C) 2012-2020 GIMONS -// [ File path (subset) ] -// -//--------------------------------------------------------------------------- - -#include "filepath.h" -#include -#include -#include -#include - -Filepath& Filepath::operator=(const Filepath& path) -{ - // Set path (split internally) - SetPath(path.GetPath()); - - return *this; -} - -//--------------------------------------------------------------------------- -// -// File settings (user) for MBCS -// -//--------------------------------------------------------------------------- -void Filepath::SetPath(const char *path) -{ - assert(path); - assert(strlen(path) < _MAX_PATH); - - // Copy pathname - strcpy(m_szPath, path); - - // Split - Split(); -} - -//--------------------------------------------------------------------------- -// -// Split paths -// -//--------------------------------------------------------------------------- -void Filepath::Split() -{ - // Initialize the parts - m_szDir[0] = '\0'; - m_szFile[0] = '\0'; - m_szExt[0] = '\0'; - - // Split - char *pDir = strdup(m_szPath); - const char *pDirName = dirname(pDir); - char *pBase = strdup(m_szPath); - const char *pBaseName = basename(pBase); - const char *pExtName = strrchr(pBaseName, '.'); - - // Transmit - if (pDirName) { - strcpy(m_szDir, pDirName); - strcat(m_szDir, "/"); - } - - if (pExtName) { - strcpy(m_szExt, pExtName); - } - - if (pBaseName) { - strcpy(m_szFile, pBaseName); - } - - // Release - free(pDir); - free(pBase); -} - -//--------------------------------------------------------------------------- -// -// File name + extension acquisition -// The returned pointer is temporary. Copy immediately. -// -//--------------------------------------------------------------------------- -const char *Filepath::GetFileExt() const -{ - - // Merge into static buffer - strcpy(FileExt, m_szExt); - - // Return as LPCTSTR - return (const char *)FileExt; -} - -//--------------------------------------------------------------------------- -// -// Filename and extension -// -//--------------------------------------------------------------------------- -TCHAR Filepath::FileExt[_MAX_FNAME + _MAX_DIR]; diff --git a/src/raspberrypi/filepath.h b/src/raspberrypi/filepath.h deleted file mode 100644 index 3ee3cb5a..00000000 --- a/src/raspberrypi/filepath.h +++ /dev/null @@ -1,51 +0,0 @@ -//--------------------------------------------------------------------------- -// -// X68000 EMULATOR "XM6" -// -// Copyright (C) 2001-2006 PI.(ytanaka@ipc-tokai.or.jp) -// Copyright (C) 2012-2020 GIMONS -// [ File path (subset) ] -// -//--------------------------------------------------------------------------- - -#pragma once - -#include "os.h" - -using TCHAR = char; - -static const int _MAX_EXT = 256; -static const int _MAX_DIR = 256; -static const int _MAX_PATH = 260; -static const int _MAX_FNAME = 256; -static const int FILEPATH_MAX = _MAX_PATH; - -//=========================================================================== -// -// File path -// Assignment operators are prepared here -// -//=========================================================================== -class Filepath -{ -public: - - Filepath() = default; - ~Filepath() = default; - Filepath(Filepath&) = default; - Filepath& operator=(const Filepath&); - - void SetPath(const char *); // File settings (user) for MBCS - const char *GetPath() const { return m_szPath; } // Get path name - const char *GetFileExt() const; // Get short name (LPCTSTR) - -private: - - void Split(); // Split the path - TCHAR m_szPath[_MAX_PATH] = {}; // File path - TCHAR m_szDir[_MAX_DIR] = {}; // Directory - TCHAR m_szFile[_MAX_FNAME] = {}; // File - TCHAR m_szExt[_MAX_EXT] = {}; // Extension - - static TCHAR FileExt[_MAX_FNAME + _MAX_DIR]; // Short name (TCHAR) -}; diff --git a/src/raspberrypi/rascsi.cpp b/src/raspberrypi/rascsi.cpp index 312a58af..e4e5cf8f 100644 --- a/src/raspberrypi/rascsi.cpp +++ b/src/raspberrypi/rascsi.cpp @@ -98,22 +98,22 @@ void Banner(int argc, char* argv[]) bool InitBus() { +#ifdef USE_SEL_EVENT_ENABLE SBC_Version::Init(); +#endif + // GPIOBUS creation bus = GPIOBUS_Factory::Create(); - controller_manager = make_shared(bus); rascsi_response = make_shared(device_factory, *controller_manager, ScsiController::LUN_MAX); executor = make_shared(*rascsi_response, rascsi_image, device_factory, *controller_manager); - // GPIO Initialization if (!bus->Init()) { return false; } - // Bus Reset bus->Reset(); return true; @@ -125,7 +125,6 @@ void Cleanup() service.Cleanup(); - // Clean up and discard the bus bus->Cleanup(); } @@ -149,7 +148,7 @@ bool ReadAccessToken(const char *filename) return false; } - ifstream token_file(filename, ifstream::in); + ifstream token_file(filename); if (token_file.fail()) { cerr << "Can't open access token file '" << optarg << "'" << endl; return false; @@ -157,19 +156,15 @@ bool ReadAccessToken(const char *filename) getline(token_file, access_token); if (token_file.fail()) { - token_file.close(); cerr << "Can't read access token file '" << optarg << "'" << endl; return false; } if (access_token.empty()) { - token_file.close(); cerr << "Access token file '" << optarg << "' must not be empty" << endl; return false; } - token_file.close(); - return true; } diff --git a/src/raspberrypi/rascsi/rascsi_executor.cpp b/src/raspberrypi/rascsi/rascsi_executor.cpp index 67702b73..b0da6570 100644 --- a/src/raspberrypi/rascsi/rascsi_executor.cpp +++ b/src/raspberrypi/rascsi/rascsi_executor.cpp @@ -397,6 +397,7 @@ bool RascsiExecutor::Insert(const CommandContext& context, const PbDeviceDefinit bool RascsiExecutor::Detach(const CommandContext& context, shared_ptr device, bool dryRun) const { + cerr << "AAA " << device->GetId() << endl; auto controller = controller_manager.FindController(device->GetId()); if (controller == nullptr) { return context.ReturnLocalizedError(LocalizationKey::ERROR_DETACH); @@ -408,6 +409,9 @@ bool RascsiExecutor::Detach(const CommandContext& context, shared_ptrGetId(); + if (!controller->RemoveDevice(device)) { return context.ReturnLocalizedError(LocalizationKey::ERROR_DETACH); } @@ -421,8 +425,8 @@ bool RascsiExecutor::Detach(const CommandContext& context, shared_ptrUnreserveFile(); } - LOGINFO("%s", ("Detached " + string(device->GetTypeString()) + " device with ID " - + to_string(device->GetId()) + ", unit " + to_string(device->GetLun())).c_str()) + LOGINFO("%s", ("Detached " + string(device->GetTypeString()) + " device with ID " + to_string(id) + + ", unit " + to_string(device->GetLun())).c_str()) } return true; @@ -544,11 +548,9 @@ bool RascsiExecutor::ValidateImageFile(const CommandContext& context, shared_ptr return true; } - int id; - int lun; - if (StorageDevice::GetIdsForReservedFile(filename, id, lun)) { + if (const auto [id1, lun1] = StorageDevice::GetIdsForReservedFile(filename); id1 != -1 || lun1 != -1) { return context.ReturnLocalizedError(LocalizationKey::ERROR_IMAGE_IN_USE, filename, - to_string(id), to_string(lun)); + to_string(id1), to_string(lun1)); } string effective_filename = filename; @@ -557,9 +559,9 @@ bool RascsiExecutor::ValidateImageFile(const CommandContext& context, shared_ptr // If the file does not exist search for it in the default image folder effective_filename = rascsi_image.GetDefaultFolder() + "/" + filename; - if (StorageDevice::GetIdsForReservedFile(effective_filename, id, lun)) { + if (const auto [id2, lun2] = StorageDevice::GetIdsForReservedFile(effective_filename); id2 != -1 || lun2 != -1) { return context.ReturnLocalizedError(LocalizationKey::ERROR_IMAGE_IN_USE, filename, - to_string(id), to_string(lun)); + to_string(id2), to_string(lun2)); } if (!StorageDevice::FileExists(effective_filename)) { diff --git a/src/raspberrypi/rascsi/rascsi_image.cpp b/src/raspberrypi/rascsi/rascsi_image.cpp index 3e066880..cc60ddc1 100644 --- a/src/raspberrypi/rascsi/rascsi_image.cpp +++ b/src/raspberrypi/rascsi/rascsi_image.cpp @@ -7,21 +7,20 @@ // //--------------------------------------------------------------------------- -#include -#include #include "log.h" #include "devices/disk.h" #include "protobuf_util.h" #include "command_context.h" #include "rascsi_image.h" +#include +#include +#include #include #include #include -#ifdef __linux__ -#include -#endif using namespace std; +using namespace filesystem; using namespace rascsi_interface; using namespace protobuf_util; @@ -39,16 +38,20 @@ bool RascsiImage::CheckDepth(string_view filename) const bool RascsiImage::CreateImageFolder(const CommandContext& context, const string& filename) const { if (const size_t filename_start = filename.rfind('/'); filename_start != string::npos) { - const string folder = filename.substr(0, filename_start); + const auto folder = path(filename.substr(0, filename_start)); // Checking for existence first prevents an error if the top-level folder is a softlink - if (struct stat st; stat(folder.c_str(), &st)) { - std::error_code error; - filesystem::create_directories(folder, error); - if (error) { - context.ReturnStatus(false, "Can't create image folder '" + folder + "': " + strerror(errno)); - return false; - } + if (error_code error; exists(folder, error)) { + return true; + } + + try { + create_directories(folder); + + return ChangeOwner(context, folder, false); + } + catch(const filesystem_error& e) { + return context.ReturnStatus(false, "Can't create image folder '" + string(folder) + "': " + e.what()); } } @@ -63,9 +66,9 @@ string RascsiImage::SetDefaultFolder(const string& f) string folder = f; - // If a relative path is specified the path is assumed to be relative to the user's home directory + // If a relative path is specified, the path is assumed to be relative to the user's home directory if (folder[0] != '/') { - folder = GetHomeDir() + "/" + f; + folder = GetHomeDir() + "/" + folder; } else { if (folder.find("/home/") != 0) { @@ -73,13 +76,17 @@ string RascsiImage::SetDefaultFolder(const string& f) } } - struct stat info; - stat(folder.c_str(), &info); - if (!S_ISDIR(info.st_mode) || access(folder.c_str(), F_OK) == -1) { - return "Folder '" + f + "' does not exist or is not accessible"; + // Resolve a potential symlink + auto p = path(folder); + if (error_code error; is_symlink(p, error)) { + p = read_symlink(p); } - default_folder = folder; + if (error_code error; !is_directory(p, error)) { + return "'" + string(p) + "' is not a valid folder"; + } + + default_folder = string(p); LOGINFO("Default image folder set to '%s'", default_folder.c_str()) @@ -104,7 +111,7 @@ bool RascsiImage::CreateImage(const CommandContext& context, const PbCommand& co const string size = GetParam(command, "size"); if (size.empty()) { - return context.ReturnStatus(false, "Can't create image file '" + full_filename + "': Missing image size"); + return context.ReturnStatus(false, "Can't create image file '" + full_filename + "': Missing file size"); } off_t len; @@ -125,38 +132,30 @@ bool RascsiImage::CreateImage(const CommandContext& context, const PbCommand& co return false; } - const string permission = GetParam(command, "read_only"); - // Since rascsi is running as root ensure that others can access the file - const int permissions = !strcasecmp(permission.c_str(), "true") ? - S_IRUSR | S_IRGRP | S_IROTH : S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + const bool read_only = GetParam(command, "read_only") == "true"; - const int image_fd = open(full_filename.c_str(), O_CREAT|O_WRONLY, permissions); - if (image_fd == -1) { - return context.ReturnStatus(false, "Can't create image file '" + full_filename + "': " + string(strerror(errno))); + error_code error; + path file(full_filename); + try { + ofstream s(file); + s.close(); + + if (!ChangeOwner(context, file, read_only)) { + return false; + } + + resize_file(file, len); + } + catch(const filesystem_error& e) { + remove(file, error); + + return context.ReturnStatus(false, "Can't create image file '" + full_filename + "': " + e.what()); } -#ifndef __linux__ - close(image_fd); - - unlink(full_filename.c_str()); - - return false; -#else - if (fallocate(image_fd, 0, 0, len)) { - close(image_fd); - - unlink(full_filename.c_str()); - - return context.ReturnStatus(false, "Can't allocate space for image file '" + full_filename + "': " + string(strerror(errno))); - } - - close(image_fd); - - LOGINFO("%s", string("Created " + string(permissions & S_IWUSR ? "": "read-only ") + "image file '" + full_filename + + LOGINFO("%s", string("Created " + string(read_only ? "read-only " : "") + "image file '" + full_filename + "' with a size of " + to_string(len) + " bytes").c_str()) return context.ReturnStatus(); -#endif } bool RascsiImage::DeleteImage(const CommandContext& context, const PbCommand& command) const @@ -172,28 +171,35 @@ bool RascsiImage::DeleteImage(const CommandContext& context, const PbCommand& co const string full_filename = GetFullName(filename); - int id; - if (int lun; StorageDevice::GetIdsForReservedFile(full_filename, id, lun)) { + const auto [id, lun] = StorageDevice::GetIdsForReservedFile(full_filename); + if (id == -1 || lun == -1) { return context.ReturnStatus(false, "Can't delete image file '" + full_filename + - "', it is currently being used by device ID " + to_string(id) + ", unit " + to_string(lun)); + "', it is currently being used by device ID " + to_string(id) + ", LUN " + to_string(lun)); } - if (remove(full_filename.c_str())) { - return context.ReturnStatus(false, "Can't delete image file '" + full_filename + "': " + string(strerror(errno))); + try { + remove(path(full_filename)); + } + catch(const filesystem_error& e) { + return context.ReturnStatus(false, "Can't delete image file '" + full_filename + "': " + e.what()); } // Delete empty subfolders size_t last_slash = filename.rfind('/'); while (last_slash != string::npos) { - string folder = filename.substr(0, last_slash); - string full_folder = GetFullName(folder); + const string folder = filename.substr(0, last_slash); + const auto full_folder = path(GetFullName(folder)); if (error_code error; !filesystem::is_empty(full_folder, error) || error) { break; } - if (remove(full_folder.c_str())) { - return context.ReturnStatus(false, "Can't delete empty image folder '" + full_folder + "'"); + try { + remove(full_folder); + } + catch(const filesystem_error& e) { + return context.ReturnStatus(false, "Can't delete empty image folder '" + string(full_folder) + + "': " + e.what()); } last_slash = folder.rfind('/'); @@ -216,8 +222,11 @@ bool RascsiImage::RenameImage(const CommandContext& context, const PbCommand& co return false; } - if (rename(from.c_str(), to.c_str())) { - return context.ReturnStatus(false, "Can't rename/move image file '" + from + "' to '" + to + "': " + string(strerror(errno))); + try { + rename(path(from), path(to)); + } + catch(const filesystem_error& e) { + return context.ReturnStatus(false, "Can't rename/move image file '" + from + "' to '" + to + "': " + e.what()); } LOGINFO("Renamed/Moved image file '%s' to '%s'", from.c_str(), to.c_str()) @@ -233,69 +242,46 @@ bool RascsiImage::CopyImage(const CommandContext& context, const PbCommand& comm return false; } - struct stat st; - if (lstat(from.c_str(), &st)) { - return context.ReturnStatus(false, "Can't access source image file '" + from + "': " + string(strerror(errno))); + if (access(from.c_str(), R_OK)) { + return context.ReturnStatus(false, "Can't read source image file '" + from + "'"); } if (!CreateImageFolder(context, to)) { return false; } + path f(from); + path t(to); + // Symbolic links need a special handling - if ((st.st_mode & S_IFMT) == S_IFLNK) { - if (symlink(filesystem::read_symlink(from).c_str(), to.c_str())) { - return context.ReturnStatus(false, "Can't copy symlink '" + from + "': " + string(strerror(errno))); + if (error_code error; is_symlink(f, error)) { + try { + copy_symlink(f, t); + } + catch(const filesystem_error& e) { + return context.ReturnStatus(false, "Can't copy image file symlink '" + from + "': " + e.what()); } - LOGINFO("Copied symlink '%s' to '%s'", from.c_str(), to.c_str()) + LOGINFO("Copied image file symlink '%s' to '%s'", from.c_str(), to.c_str()) return context.ReturnStatus(); } - const int fd_src = open(from.c_str(), O_RDONLY, 0); - if (fd_src == -1) { - return context.ReturnStatus(false, "Can't open source image file '" + from + "': " + string(strerror(errno))); + try { + copy_file(f, t); + + permissions(t, GetParam(command, "read_only") == "true" ? + perms::owner_read | perms::group_read | perms::others_read : + perms::owner_read | perms::group_read | perms::others_read | + perms::owner_write | perms::group_write); } - - const string permission = GetParam(command, "read_only"); - // Since rascsi is running as root ensure that others can access the file - const int permissions = !strcasecmp(permission.c_str(), "true") ? - S_IRUSR | S_IRGRP | S_IROTH : S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - - const int fd_dst = open(to.c_str(), O_WRONLY | O_CREAT, permissions); - if (fd_dst == -1) { - close(fd_src); - - return context.ReturnStatus(false, "Can't open destination image file '" + to + "': " + string(strerror(errno))); + catch(const filesystem_error& e) { + return context.ReturnStatus(false, "Can't copy image file '" + from + "' to '" + to + "': " + e.what()); } -#ifndef __linux__ - close(fd_dst); - close(fd_src); - - unlink(to.c_str()); - - LOGWARN("Copying image files is only supported under Linux") - - return false; -#else - if (sendfile(fd_dst, fd_src, nullptr, st.st_size) == -1) { - close(fd_dst); - close(fd_src); - - unlink(to.c_str()); - - return context.ReturnStatus(false, "Can't copy image file '" + from + "' to '" + to + "': " + string(strerror(errno))); - } - - close(fd_dst); - close(fd_src); - LOGINFO("Copied image file '%s' to '%s'", from.c_str(), to.c_str()) return context.ReturnStatus(); -#endif } bool RascsiImage::SetImagePermissions(const CommandContext& context, const PbCommand& command) const @@ -316,10 +302,15 @@ bool RascsiImage::SetImagePermissions(const CommandContext& context, const PbCom const bool protect = command.operation() == PROTECT_IMAGE; - if (const int permissions = protect ? S_IRUSR | S_IRGRP | S_IROTH : S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - chmod(filename.c_str(), permissions) == -1) { - return context.ReturnStatus(false, "Can't " + string(protect ? "protect" : "unprotect") + " image file '" + filename + "': " + - strerror(errno)); + try { + permissions(path(filename), protect ? + perms::owner_read | perms::group_read | perms::others_read : + perms::owner_read | perms::group_read | perms::others_read | + perms::owner_write | perms::group_write); + } + catch(const filesystem_error& e) { + return context.ReturnStatus(false, "Can't " + string(protect ? "protect" : "unprotect") + " image file '" + + filename + "': " + e.what()); } if (protect) { @@ -369,23 +360,45 @@ bool RascsiImage::ValidateParams(const CommandContext& context, const PbCommand& bool RascsiImage::IsValidSrcFilename(const string& filename) { // Source file must exist and must be a regular file or a symlink - struct stat st; - return !stat(filename.c_str(), &st) && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)); + path file(filename); + return is_regular_file(file) || is_symlink(file); } bool RascsiImage::IsValidDstFilename(const string& filename) { // Destination file must not yet exist - struct stat st; - return stat(filename.c_str(), &st); + try { + return !exists(path(filename)); + } + catch(const filesystem_error&) { + return true; + } +} + +bool RascsiImage::ChangeOwner(const CommandContext& context, const path& filename, bool read_only) +{ + const auto [uid, gid] = GetUidAndGid(); + if (chown(filename.c_str(), uid, gid)) { + // Remember the current error before the next filesystem operation + const int e = errno; + + error_code error; + remove(filename, error); + + return context.ReturnStatus(false, "Can't change ownership of '" + string(filename) + "': " + strerror(e)); + } + + permissions(filename, read_only ? + perms::owner_read | perms::group_read | perms::others_read : + perms::owner_read | perms::group_read | perms::others_read | + perms::owner_write | perms::group_write); + + return true; } string RascsiImage::GetHomeDir() { - int uid = getuid(); - if (const char *sudo_user = getenv("SUDO_UID"); sudo_user != nullptr) { - uid = stoi(sudo_user); - } + const auto [uid, gid] = GetUidAndGid(); passwd pwd = {}; passwd *p_pwd; @@ -398,3 +411,22 @@ string RascsiImage::GetHomeDir() return "/home/pi"; } } + +pair RascsiImage::GetUidAndGid() +{ + int uid = getuid(); + if (const char *sudo_user = getenv("SUDO_UID"); sudo_user != nullptr) { + uid = stoi(sudo_user); + } + + passwd pwd = {}; + passwd *p_pwd; + array pwbuf; + + int gid = -1; + if (!getpwuid_r(uid, &pwd, pwbuf.data(), pwbuf.size(), &p_pwd)) { + gid = pwd.pw_gid; + } + + return make_pair(uid, gid); +} diff --git a/src/raspberrypi/rascsi/rascsi_image.h b/src/raspberrypi/rascsi/rascsi_image.h index deb4b80a..d10bacc4 100644 --- a/src/raspberrypi/rascsi/rascsi_image.h +++ b/src/raspberrypi/rascsi/rascsi_image.h @@ -12,8 +12,10 @@ #include "rascsi_interface.pb.h" #include "command_context.h" #include +#include using namespace std; +using namespace filesystem; using namespace rascsi_interface; class RascsiImage @@ -42,7 +44,9 @@ private: static bool IsValidSrcFilename(const string&); static bool IsValidDstFilename(const string&); + static bool ChangeOwner(const CommandContext&, const path&, bool); static string GetHomeDir(); + static pair GetUidAndGid(); string default_folder; diff --git a/src/raspberrypi/rascsi/rascsi_response.cpp b/src/raspberrypi/rascsi/rascsi_response.cpp index 3e4388be..58042cbe 100644 --- a/src/raspberrypi/rascsi/rascsi_response.cpp +++ b/src/raspberrypi/rascsi/rascsi_response.cpp @@ -14,7 +14,10 @@ #include "rascsi_version.h" #include "rascsi_interface.pb.h" #include "rascsi_response.h" +#include +using namespace std; +using namespace filesystem; using namespace rascsi_interface; using namespace protobuf_util; @@ -112,7 +115,7 @@ bool RascsiResponse::GetImageFile(PbImageFile& image_file, const string& default image_file.set_read_only(access(f.c_str(), W_OK)); - // filesystem::file_size cannot be used here because gcc < 10.3.0 cannot handled more than 2 GiB + // filesystem::file_size cannot be used here because gcc < 10.3.0 cannot handle files of more than 2 GiB if (struct stat st; !stat(f.c_str(), &st) && !S_ISDIR(st.st_mode)) { image_file.set_size(st.st_size); return true; @@ -140,6 +143,7 @@ void RascsiResponse::GetAvailableImages(PbImageFilesInfo& image_files_info, cons return; } + // C++ filesystem cannot be used here because gcc < 10.3.0 cannot handle files of more than 2 GiB const dirent *dir; while ((dir = readdir(d))) { string filename = GetNextImageFile(dir, folder); @@ -526,10 +530,11 @@ string RascsiResponse::GetNextImageFile(const dirent *dir, const string& folder) const string filename = folder + "/" + dir->d_name; + const bool file_exists = exists(path(filename)); + + // filesystem::file_size cannot be used here because gcc < 10.3.0 cannot handle files of more than 2 GiB struct stat st; - - const bool file_exists = !stat(filename.c_str(), &st); - + stat(filename.c_str(), &st); if (dir->d_type == DT_REG && file_exists && !st.st_size) { LOGWARN("File '%s' in image folder '%s' is empty", dir->d_name, folder.c_str()) return ""; diff --git a/src/raspberrypi/rasdump.cpp b/src/raspberrypi/rasdump.cpp index afffff46..decb7644 100644 --- a/src/raspberrypi/rasdump.cpp +++ b/src/raspberrypi/rasdump.cpp @@ -13,8 +13,7 @@ #include #include #include "os.h" -#include "fileio.h" -#include "filepath.h" +#include "rasdump_fileio.h" #include "hal/gpiobus.h" #include "hal/gpiobus_factory.h" #include "hal/systimer.h" @@ -40,7 +39,7 @@ static const int BUFSIZE = 1024 * 64; // Buffer size of about 64KB unique_ptr bus; // GPIO Bus // Bus int targetid; // Target ID int boardid; // Board ID (own ID) -Filepath hdsfile; // HDS file +string hdsfile; // HDS file bool restore; // Restore flag BYTE buffer[BUFSIZE]; // Work Buffer int result; // Result Code @@ -207,7 +206,7 @@ bool ParseArgument(int argc, char* argv[]) return false; } - hdsfile.SetPath(file); + hdsfile = file; return true; } @@ -837,7 +836,7 @@ int main(int argc, char* argv[]) } else { omode = Fileio::OpenMode::WriteOnly; } - if (!fio.Open(hdsfile.GetPath(), omode)) { + if (!fio.Open(hdsfile.c_str(), omode)) { fprintf(stderr, "Error : Can't open hds file\n"); // Cleanup diff --git a/src/raspberrypi/fileio.cpp b/src/raspberrypi/rasdump_fileio.cpp similarity index 76% rename from src/raspberrypi/fileio.cpp rename to src/raspberrypi/rasdump_fileio.cpp index 2061e6c1..af21efc2 100644 --- a/src/raspberrypi/fileio.cpp +++ b/src/raspberrypi/rasdump_fileio.cpp @@ -8,7 +8,7 @@ // //--------------------------------------------------------------------------- -#include "fileio.h" +#include "rasdump_fileio.h" #include #include #include @@ -60,27 +60,6 @@ bool Fileio::Open(const char *fname, OpenMode mode) return Open(fname, mode, false); } -bool Fileio::Open(const Filepath& path, OpenMode mode) -{ - return Open(path.GetPath(), mode); -} - -bool Fileio::OpenDIO(const char *fname, OpenMode mode) -{ - // Open with included O_DIRECT - if (!Open(fname, mode, true)) { - // Normal mode retry (tmpfs etc.) - return Open(fname, mode, false); - } - - return true; -} - -bool Fileio::OpenDIO(const Filepath& path, OpenMode mode) -{ - return OpenDIO(path.GetPath(), mode); -} - bool Fileio::Read(BYTE *buffer, int size) const { assert(buffer); @@ -99,14 +78,6 @@ bool Fileio::Write(const BYTE *buffer, int size) const return write(handle, buffer, size) == size; } -bool Fileio::Seek(off_t offset) const -{ - assert(handle >= 0); - assert(offset >= 0); - - return lseek(handle, offset, SEEK_SET) == offset; -} - off_t Fileio::GetFileSize() const { assert(handle >= 0); @@ -118,7 +89,7 @@ off_t Fileio::GetFileSize() const const off_t end = lseek(handle, 0, SEEK_END); // Return to start position - Seek(cur); + lseek(handle, cur, SEEK_SET); return end; } diff --git a/src/raspberrypi/fileio.h b/src/raspberrypi/rasdump_fileio.h similarity index 80% rename from src/raspberrypi/fileio.h rename to src/raspberrypi/rasdump_fileio.h index 7d6c7785..ed15b5da 100644 --- a/src/raspberrypi/fileio.h +++ b/src/raspberrypi/rasdump_fileio.h @@ -10,7 +10,7 @@ #pragma once -#include "filepath.h" +#include "os.h" #include class Fileio @@ -29,9 +29,6 @@ public: Fileio& operator=(const Fileio&) = default; bool Open(const char *fname, OpenMode mode); - bool Open(const Filepath& path, OpenMode mode); - bool OpenDIO(const Filepath& path, OpenMode mode); - bool Seek(off_t offset) const; bool Read(BYTE *buffer, int size) const; bool Write(const BYTE *buffer, int size) const; off_t GetFileSize() const; @@ -40,7 +37,6 @@ public: private: bool Open(const char *fname, OpenMode mode, bool directIO); - bool OpenDIO(const char *fname, OpenMode mode); int handle = -1; }; diff --git a/src/raspberrypi/test/host_services_test.cpp b/src/raspberrypi/test/host_services_test.cpp index c887a82f..1af61557 100644 --- a/src/raspberrypi/test/host_services_test.cpp +++ b/src/raspberrypi/test/host_services_test.cpp @@ -14,6 +14,12 @@ using namespace std; +void HostServices_SetUpModePages(map>& pages) +{ + EXPECT_EQ(1, pages.size()) << "Unexpected number of mode pages"; + EXPECT_EQ(10, pages[32].size()); +} + TEST(HostServicesTest, Dispatch) { TestDispatch(SCHS); @@ -146,7 +152,12 @@ TEST(HostServicesTest, SetUpModePages) MockHostServices services(0, controller_manager); map> pages; + // Non changeable services.SetUpModePages(pages, 0x3f, false); - EXPECT_EQ(1, pages.size()) << "Unexpected number of mode pages"; - EXPECT_EQ(10, pages[32].size()); + HostServices_SetUpModePages(pages); + + // Changeable + pages.clear(); + services.SetUpModePages(pages, 0x3f, true); + HostServices_SetUpModePages(pages); } diff --git a/src/raspberrypi/test/mocks.h b/src/raspberrypi/test/mocks.h index 6253466a..2468daa1 100644 --- a/src/raspberrypi/test/mocks.h +++ b/src/raspberrypi/test/mocks.h @@ -331,6 +331,7 @@ class MockSCSIHD : public SCSIHD //NOSONAR Ignore inheritance hierarchy depth in FRIEND_TEST(DiskTest, ConfiguredSectorSize); FRIEND_TEST(ScsiHdTest, SupportsSaveParameters); FRIEND_TEST(ScsiHdTest, FinalizeSetup); + FRIEND_TEST(ScsiHdTest, GetProductData); FRIEND_TEST(ScsiHdTest, SetUpModePages); FRIEND_TEST(RascsiExecutorTest, SetSectorSize); FRIEND_TEST(ScsiHdTest, ModeSelect); diff --git a/src/raspberrypi/test/protobuf_serializer_test.cpp b/src/raspberrypi/test/protobuf_serializer_test.cpp index d8028155..c5727239 100644 --- a/src/raspberrypi/test/protobuf_serializer_test.cpp +++ b/src/raspberrypi/test/protobuf_serializer_test.cpp @@ -11,7 +11,9 @@ #include "rascsi_exceptions.h" #include "rascsi_interface.pb.h" #include "protobuf_serializer.h" +#include +using namespace filesystem; using namespace rascsi_interface; TEST(ProtobufSerializerTest, SerializeMessage) @@ -37,28 +39,25 @@ TEST(ProtobufSerializerTest, DeserializeMessage) EXPECT_THROW(serializer.DeserializeMessage(fd, result), io_exception) << "Reading the message header must fail"; close(fd); - string filename; - fd = OpenTempFile(filename); - EXPECT_NE(-1, fd); + auto [fd1, filename1] = OpenTempFile(); // Data size -1 buf = { byte{0xff}, byte{0xff}, byte{0xff}, byte{0xff} }; - EXPECT_EQ(buf.size(), write(fd, buf.data(), buf.size())); - close(fd); - fd = open(filename.c_str(), O_RDONLY); - EXPECT_NE(-1, fd); - EXPECT_THROW(serializer.DeserializeMessage(fd, result), io_exception) << "Invalid header was not rejected"; - unlink(filename.c_str()); + EXPECT_EQ(buf.size(), write(fd1, buf.data(), buf.size())); + close(fd1); + fd1 = open(filename1.c_str(), O_RDONLY); + EXPECT_NE(-1, fd1); + EXPECT_THROW(serializer.DeserializeMessage(fd1, result), io_exception) << "Invalid header was not rejected"; + remove(filename1); - fd = OpenTempFile(filename); - EXPECT_NE(-1, fd); + auto [fd2, filename2] = OpenTempFile(); // Data size 2 buf = { byte{0x02}, byte{0x00}, byte{0x00}, byte{0x00} }; - EXPECT_EQ(buf.size(), write(fd, buf.data(), buf.size())); - close(fd); - fd = open(filename.c_str(), O_RDONLY); - EXPECT_NE(-1, fd); - EXPECT_THROW(serializer.DeserializeMessage(fd, result), io_exception) << "Invalid data were not rejected"; - unlink(filename.c_str()); + EXPECT_EQ(buf.size(), write(fd2, buf.data(), buf.size())); + close(fd2); + fd2 = open(filename2.c_str(), O_RDONLY); + EXPECT_NE(-1, fd2); + EXPECT_THROW(serializer.DeserializeMessage(fd2, result), io_exception) << "Invalid data were not rejected"; + remove(filename2); } TEST(ProtobufSerializerTest, SerializeDeserializeMessage) @@ -67,8 +66,7 @@ TEST(ProtobufSerializerTest, SerializeDeserializeMessage) result.set_status(true); ProtobufSerializer serializer; - string filename; - int fd = OpenTempFile(filename); + auto [fd, filename] = OpenTempFile(); EXPECT_NE(-1, fd); serializer.SerializeMessage(fd, result); close(fd); @@ -78,7 +76,7 @@ TEST(ProtobufSerializerTest, SerializeDeserializeMessage) EXPECT_NE(-1, fd); serializer.DeserializeMessage(fd, result); close(fd); - unlink(filename.c_str()); + remove(filename); EXPECT_TRUE(result.status()); } diff --git a/src/raspberrypi/test/rascsi_executor_test.cpp b/src/raspberrypi/test/rascsi_executor_test.cpp index c691d7cd..18c55a71 100644 --- a/src/raspberrypi/test/rascsi_executor_test.cpp +++ b/src/raspberrypi/test/rascsi_executor_test.cpp @@ -18,8 +18,9 @@ #include "rascsi/rascsi_response.h" #include "rascsi/rascsi_image.h" #include "rascsi/rascsi_executor.h" -#include +#include +using namespace filesystem; using namespace rascsi_interface; using namespace protobuf_util; @@ -279,39 +280,39 @@ TEST_F(RascsiExecutorTest, Attach) SetParam(definition, "file", "/non_existing_file"); EXPECT_FALSE(executor.Attach(context, definition, false)) << "Drive with non-existing image file not rejected"; - string filename = CreateTempFile(1); - SetParam(definition, "file", filename); + path filename = CreateTempFile(1); + SetParam(definition, "file", filename.c_str()); EXPECT_THROW(executor.Attach(context, definition, false), io_exception) << "Too small image file not rejected"; - unlink(filename.c_str()); + remove(filename); filename = CreateTempFile(512); - SetParam(definition, "file", filename); + SetParam(definition, "file", filename.c_str()); bool result = executor.Attach(context, definition, false); - unlink(filename.c_str()); + remove(filename); EXPECT_TRUE(result); controller_manager.DeleteAllControllers(); filename = CreateTempFile(513); - SetParam(definition, "file", filename); + SetParam(definition, "file", filename.c_str()); result = executor.Attach(context, definition, false); - unlink(filename.c_str()); + remove(filename); EXPECT_TRUE(result); definition.set_type(PbDeviceType::SCCD); definition.set_unit(LUN + 1); filename = CreateTempFile(2048); - SetParam(definition, "file", filename); + SetParam(definition, "file", filename.c_str()); result = executor.Attach(context, definition, false); - unlink(filename.c_str()); + remove(filename); EXPECT_TRUE(result); definition.set_type(PbDeviceType::SCMO); definition.set_unit(LUN + 2); SetParam(definition, "read_only", "true"); filename = CreateTempFile(4096); - SetParam(definition, "file", filename); + SetParam(definition, "file", filename.c_str()); result = executor.Attach(context, definition, false); - unlink(filename.c_str()); + remove(filename); EXPECT_TRUE(result); controller_manager.DeleteAllControllers(); @@ -360,16 +361,16 @@ TEST_F(RascsiExecutorTest, Insert) SetParam(definition, "file", "/non_existing_file"); EXPECT_FALSE(executor.Insert(context, definition, device, false)); - string filename = CreateTempFile(1); - SetParam(definition, "file", filename); + path filename = CreateTempFile(1); + SetParam(definition, "file", filename.c_str()); EXPECT_THROW(executor.Insert(context, definition, device, false), io_exception) << "Too small image file not rejected"; - unlink(filename.c_str()); + remove(filename); filename = CreateTempFile(512); - SetParam(definition, "file", filename); + SetParam(definition, "file", filename.c_str()); const bool result = executor.Insert(context, definition, device, false); - unlink(filename.c_str()); + remove(filename); EXPECT_TRUE(result); } diff --git a/src/raspberrypi/test/rascsi_image_test.cpp b/src/raspberrypi/test/rascsi_image_test.cpp index ac14ca4c..643abce2 100644 --- a/src/raspberrypi/test/rascsi_image_test.cpp +++ b/src/raspberrypi/test/rascsi_image_test.cpp @@ -52,7 +52,7 @@ TEST(RascsiImageTest, CreateImage) EXPECT_FALSE(image.CreateImage(context, command)) << "Size must be reported as invalid"; SetParam(command, "size", "513"); - EXPECT_FALSE(image.CreateImage(context, command)) << "Size must be reported as invalid"; + EXPECT_FALSE(image.CreateImage(context, command)) << "Size must be reported as not a multiple of 512"; // Further tests would modify the filesystem } @@ -68,6 +68,11 @@ TEST(RascsiImageTest, DeleteImage) SetParam(command, "file", "/a/b/c/filename"); EXPECT_FALSE(image.DeleteImage(context, command)) << "Depth must be reported as invalid"; + MockStorageDevice device; + device.ReserveFile("filename", 0, 0); + SetParam(command, "file", "filename"); + EXPECT_FALSE(image.DeleteImage(context, command)) << "File must be reported as in use"; + // Further testing would modify the filesystem } @@ -77,17 +82,14 @@ TEST(RascsiImageTest, RenameImage) PbCommand command; RascsiImage image; - EXPECT_FALSE(image.RenameImage(context, command)) << "Filenames must be reported as missing"; - - SetParam(command, "to", "/a/b/c/filename_to"); - EXPECT_FALSE(image.RenameImage(context, command)) << "Depth must be reported as invalid"; - - SetParam(command, "to", "filename_to"); EXPECT_FALSE(image.RenameImage(context, command)) << "Source filename must be reported as missing"; SetParam(command, "from", "/a/b/c/filename_from"); EXPECT_FALSE(image.RenameImage(context, command)) << "Depth must be reported as invalid"; + SetParam(command, "from", "filename_from"); + EXPECT_FALSE(image.RenameImage(context, command)) << "Source file must be reported as missing"; + // Further testing would modify the filesystem } @@ -97,17 +99,14 @@ TEST(RascsiImageTest, CopyImage) PbCommand command; RascsiImage image; - EXPECT_FALSE(image.CopyImage(context, command)) << "Filenames must be reported as missing"; - - SetParam(command, "to", "/a/b/c/filename_to"); - EXPECT_FALSE(image.CopyImage(context, command)) << "Depth must be reported as invalid"; - - SetParam(command, "to", "filename_to"); EXPECT_FALSE(image.CopyImage(context, command)) << "Source filename must be reported as missing"; SetParam(command, "from", "/a/b/c/filename_from"); EXPECT_FALSE(image.CopyImage(context, command)) << "Depth must be reported as invalid"; + SetParam(command, "from", "filename_from"); + EXPECT_FALSE(image.CopyImage(context, command)) << "Source file must be reported as missing"; + // Further testing would modify the filesystem } diff --git a/src/raspberrypi/test/scsi_printer_test.cpp b/src/raspberrypi/test/scsi_printer_test.cpp index 8880329d..586458f3 100644 --- a/src/raspberrypi/test/scsi_printer_test.cpp +++ b/src/raspberrypi/test/scsi_printer_test.cpp @@ -104,6 +104,16 @@ TEST(ScsiPrinterTest, StopPrint) EXPECT_EQ(status::GOOD, controller.GetStatus()); } +TEST(ScsiPrinterTest, SynchronizeBuffer) +{ + NiceMock controller(make_shared(), 0); + auto printer = CreateDevice(SCLP, controller); + + EXPECT_THROW(printer->Dispatch(scsi_command::eCmdSynchronizeBuffer), scsi_exception) << "Nothing to print"; + + // Further testing would use the printing system +} + TEST(ScsiPrinterTest, WriteByteSequence) { NiceMock controller(make_shared(), 0); diff --git a/src/raspberrypi/test/scsicd_test.cpp b/src/raspberrypi/test/scsicd_test.cpp index 732652cb..7d4d62db 100644 --- a/src/raspberrypi/test/scsicd_test.cpp +++ b/src/raspberrypi/test/scsicd_test.cpp @@ -9,6 +9,23 @@ #include "mocks.h" #include "rascsi_exceptions.h" +#include +#include + +using namespace std; +using namespace filesystem; + +void ScsiCdTest_SetUpModePages(map>& pages) +{ + EXPECT_EQ(7, pages.size()) << "Unexpected number of mode pages"; + EXPECT_EQ(12, pages[1].size()); + EXPECT_EQ(24, pages[3].size()); + EXPECT_EQ(24, pages[4].size()); + EXPECT_EQ(12, pages[8].size()); + EXPECT_EQ(8, pages[13].size()); + EXPECT_EQ(16, pages[14].size()); + EXPECT_EQ(30, pages[48].size()); +} TEST(ScsiCdTest, Inquiry) { @@ -26,15 +43,76 @@ TEST(ScsiCdTest, SetUpModePages) const unordered_set sector_sizes; MockSCSICD cd(0, sector_sizes); + // Non changeable cd.SetUpModePages(pages, 0x3f, false); - EXPECT_EQ(7, pages.size()) << "Unexpected number of mode pages"; - EXPECT_EQ(12, pages[1].size()); - EXPECT_EQ(24, pages[3].size()); - EXPECT_EQ(24, pages[4].size()); - EXPECT_EQ(12, pages[8].size()); - EXPECT_EQ(8, pages[13].size()); - EXPECT_EQ(16, pages[14].size()); - EXPECT_EQ(30, pages[48].size()); + ScsiCdTest_SetUpModePages(pages); + + // Changeable + pages.clear(); + cd.SetUpModePages(pages, 0x3f, true); + ScsiCdTest_SetUpModePages(pages); +} + +TEST(ScsiCdTest, Open) +{ + const unordered_set sector_sizes; + MockSCSICD cd_iso(0, sector_sizes); + MockSCSICD cd_cue(0, sector_sizes); + MockSCSICD cd_raw(0, sector_sizes); + MockSCSICD cd_physical(0, sector_sizes); + + EXPECT_THROW(cd_iso.Open(), io_exception) << "Missing filename"; + + path filename = CreateTempFile(2047); + cd_iso.SetFilename(string(filename)); + EXPECT_THROW(cd_iso.Open(), io_exception) << "ISO CD-ROM image file size too small"; + remove(filename); + + filename = CreateTempFile(2* 2048); + cd_iso.SetFilename(string(filename)); + cd_iso.Open(); + EXPECT_EQ(2, cd_iso.GetBlockCount()); + remove(filename); + + filename = CreateTempFile(0); + ofstream out; + out.open(filename); + array cue = { 'F', 'I', 'L', 'E' }; + out.write(cue.data(), cue.size()); + out.close(); + resize_file(filename, 2 * 2048); + cd_cue.SetFilename(string(filename)); + EXPECT_THROW(cd_cue.Open(), io_exception) << "CUE CD-ROM files are not supported"; + + filename = CreateTempFile(0); + out.open(filename); + array header; + header.fill(0xff); + header[0] = 0; + header[11] = 0; + out.write(header.data(), header.size()); + out.close(); + resize_file(filename, 2 * 2535); + cd_raw.SetFilename(string(filename)); + EXPECT_THROW(cd_raw.Open(), io_exception) << "Illegal raw ISO CD-ROM header"; + header[15] = 0x01; + filename = CreateTempFile(0); + out.open(filename); + out.write(header.data(), header.size()); + out.close(); + resize_file(filename, 2 * 2535); + cd_raw.SetFilename(string(filename)); + EXPECT_THROW(cd_raw.Open(), io_exception) << "Raw ISO CD-ROM image file size must be a multiple of 2536"; + resize_file(filename, 2 * 2536); + cd_raw.Open(); + EXPECT_EQ(2, cd_raw.GetBlockCount()); + remove(filename); + + filename = CreateTempFile(2* 2048); + cd_physical.SetFilename("\\" + string(filename)); + // The respective code in SCSICD appears to be broken, see https://github.com/akuker/RASCSI/issues/919 + EXPECT_THROW(cd_physical.Open(), io_exception) << "Invalid physical CD-ROM file"; + remove(filename); } TEST(ScsiCdTest, ReadToc) diff --git a/src/raspberrypi/test/scsihd_nec_test.cpp b/src/raspberrypi/test/scsihd_nec_test.cpp index f312300f..b0e1f948 100644 --- a/src/raspberrypi/test/scsihd_nec_test.cpp +++ b/src/raspberrypi/test/scsihd_nec_test.cpp @@ -8,10 +8,24 @@ //--------------------------------------------------------------------------- #include "mocks.h" +#include "rascsi_exceptions.h" #include "controllers/controller_manager.h" #include "devices/scsihd_nec.h" +#include +#include using namespace std; +using namespace filesystem; + +void ScsiHdNecTest_SetUpModePages(map>& pages) +{ + EXPECT_EQ(5, pages.size()) << "Unexpected number of mode pages"; + EXPECT_EQ(12, pages[1].size()); + EXPECT_EQ(24, pages[3].size()); + EXPECT_EQ(20, pages[4].size()); + EXPECT_EQ(12, pages[8].size()); + EXPECT_EQ(30, pages[48].size()); +} TEST(ScsiHdNecTest, Inquiry) { @@ -23,13 +37,14 @@ TEST(ScsiHdNecTest, SetUpModePages) map> pages; MockSCSIHD_NEC hd(0); + // Non changeable hd.SetUpModePages(pages, 0x3f, false); - EXPECT_EQ(5, pages.size()) << "Unexpected number of mode pages"; - EXPECT_EQ(12, pages[1].size()); - EXPECT_EQ(24, pages[3].size()); - EXPECT_EQ(20, pages[4].size()); - EXPECT_EQ(12, pages[8].size()); - EXPECT_EQ(30, pages[48].size()); + ScsiHdNecTest_SetUpModePages(pages); + + // Changeable + pages.clear(); + hd.SetUpModePages(pages, 0x3f, true); + ScsiHdNecTest_SetUpModePages(pages); } TEST(ScsiHdNecTest, TestAddFormatPage) @@ -46,10 +61,13 @@ TEST(ScsiHdNecTest, TestAddFormatPage) EXPECT_EQ(0, (int)page_3[20]); hd.SetRemovable(true); + // Non changeable hd.SetUpModePages(pages, 0x03, false); page_3 = pages[3]; EXPECT_EQ(0x20, (int)page_3[20]); + pages.clear(); + // Changeable hd.SetUpModePages(pages, 0x03, true); EXPECT_EQ(0xffff, GetInt16(page_3, 12)); } @@ -61,6 +79,140 @@ TEST(ScsiHdNecTest, TestAddDrivePage) hd.SetBlockCount(0x1234); hd.SetReady(true); + // Non changeable hd.SetUpModePages(pages, 0x04, false); EXPECT_EQ(1, pages.size()) << "Unexpected number of mode pages"; + + pages.clear(); + // Changeable + hd.SetUpModePages(pages, 0x04, true); + EXPECT_EQ(1, pages.size()) << "Unexpected number of mode pages"; +} + +TEST(ScsiHdNecTest, SetParameters) +{ + MockSCSIHD_NEC hd_hdn(0); + MockSCSIHD_NEC hd_hdi(0); + MockSCSIHD_NEC hd_nhd(0); + + EXPECT_THROW(hd_hdn.Open(), io_exception) << "Missing filename"; + + path tmp = CreateTempFile(511); + hd_hdn.SetFilename(string(tmp)); + EXPECT_THROW(hd_hdn.Open(), io_exception) << "Root sector file is too small"; + remove(tmp); + + tmp = CreateTempFile(512); + hd_hdn.SetFilename(string(tmp)); + EXPECT_THROW(hd_hdn.Open(), io_exception) << "Invalid file extension"; + + const auto hdn = path((string)tmp + ".HDN"); + rename(tmp, hdn); + hd_hdn.SetFilename(string(hdn)); + hd_hdn.Open(); + remove(hdn); + + tmp = CreateTempFile(512); + const auto hdi = path((string)tmp + ".hdi"); + rename(tmp, hdi); + hd_hdi.SetFilename(string(hdi)); + EXPECT_THROW(hd_hdi.Open(), io_exception) << "Invalid sector size"; + + ofstream out; + out.open(hdi); + const array cylinders1 = { 1, 0, 0, 0 }; + out.seekp(28); + out.write(cylinders1.data(), cylinders1.size()); + const array heads1 = { 1, 0, 0, 0 }; + out.seekp(24); + out.write(heads1.data(), heads1.size()); + const array sectors1 = { 1, 0, 0, 0 }; + out.seekp(20); + out.write(sectors1.data(), sectors1.size()); + const array sector_size1 = { 0, 2, 0, 0 }; + out.seekp(16); + out.write(sector_size1.data(), sector_size1.size()); + const array image_size = { 0, 2, 0, 0 }; + out.seekp(12); + out.write(image_size.data(), image_size.size()); + out.close(); + resize_file(hdi, 512); + hd_hdi.Open(); + + remove(hdi); + + tmp = CreateTempFile(512); + const auto nhd = path((string)tmp + ".nhd"); + rename(tmp, nhd); + hd_nhd.SetFilename(string(nhd)); + EXPECT_THROW(hd_nhd.Open(), io_exception) << "Invalid file format"; + + out.open(nhd); + out << "T98HDDIMAGE.R0"; + out.close(); + resize_file(nhd, 512); + EXPECT_THROW(hd_nhd.Open(), io_exception) << "Invalid sector size"; + + out.open(nhd); + out << "T98HDDIMAGE.R0"; + // 512 bytes per sector + array sector_size2 = { 0, 2 }; + out.seekp(0x11c); + out.write(sector_size2.data(), sector_size2.size()); + out.close(); + resize_file(nhd, 512); + EXPECT_THROW(hd_nhd.Open(), io_exception) << "Drive has 0 blocks"; + + out.open(nhd); + out << "T98HDDIMAGE.R0"; + const array cylinders2 = { 1, 0 }; + out.seekp(0x114); + out.write(cylinders2.data(), cylinders2.size()); + const array heads2 = { 1, 0 }; + out.seekp(0x118); + out.write(heads2.data(), heads2.size()); + const array sectors2 = { 1, 0 }; + out.seekp(0x11a); + out.write(sectors2.data(), sectors2.size()); + out.seekp(0x11c); + out.write(sector_size2.data(), sector_size2.size()); + const array image_offset = { 1, 0, 0, 0 }; + out.seekp(0x110); + out.write(image_offset.data(), image_offset.size()); + out.close(); + resize_file(nhd, 512); + EXPECT_THROW(hd_nhd.Open(), io_exception) << "Invalid image offset/size"; + + out.open(nhd); + out << "T98HDDIMAGE.R0"; + out.seekp(0x114); + out.write(cylinders2.data(), cylinders2.size()); + out.seekp(0x118); + out.write(heads2.data(), heads2.size()); + out.seekp(0x11a); + out.write(sectors2.data(), sectors2.size()); + // 1 byte per sector + sector_size2 = { 1, 0 }; + out.seekp(0x11c); + out.write(sector_size2.data(), sector_size2.size()); + out.close(); + resize_file(nhd, 512); + EXPECT_THROW(hd_nhd.Open(), io_exception) << "Invalid NEC disk/sector size"; + + out.open(nhd); + out << "T98HDDIMAGE.R0"; + out.seekp(0x114); + out.write(cylinders2.data(), cylinders2.size()); + out.seekp(0x118); + out.write(heads2.data(), heads2.size()); + out.seekp(0x11a); + out.write(sectors2.data(), sectors2.size()); + sector_size2 = { 0, 2 }; + out.seekp(0x11c); + out.write(sector_size2.data(), sector_size2.size()); + out.close(); + resize_file(nhd, 512); + hd_nhd.Open(); + + remove(nhd); } diff --git a/src/raspberrypi/test/scsihd_test.cpp b/src/raspberrypi/test/scsihd_test.cpp index 02096d9f..30ba5d1a 100644 --- a/src/raspberrypi/test/scsihd_test.cpp +++ b/src/raspberrypi/test/scsihd_test.cpp @@ -11,15 +11,25 @@ #include "rascsi_exceptions.h" #include "devices/scsihd.h" +void ScsiHdTest_SetUpModePages(map>& pages) +{ + EXPECT_EQ(5, pages.size()) << "Unexpected number of mode pages"; + EXPECT_EQ(12, pages[1].size()); + EXPECT_EQ(24, pages[3].size()); + EXPECT_EQ(24, pages[4].size()); + EXPECT_EQ(12, pages[8].size()); + EXPECT_EQ(30, pages[48].size()); +} + TEST(ScsiHdTest, Inquiry) { TestInquiry(SCHD, device_type::DIRECT_ACCESS, scsi_level::SCSI_2, "RaSCSI ", 0x1f, false); + TestInquiry(SCHD, device_type::DIRECT_ACCESS, scsi_level::SCSI_1_CCS, "RaSCSI ", 0x1f, false, ".hd1"); } TEST(ScsiHdTest, SupportsSaveParameters) { - map> pages; const unordered_set sector_sizes; MockSCSIHD hd(0, sector_sizes, false); @@ -28,19 +38,42 @@ TEST(ScsiHdTest, SupportsSaveParameters) TEST(ScsiHdTest, FinalizeSetup) { - map> pages; const unordered_set sector_sizes; MockSCSIHD hd(0, sector_sizes, false); hd.SetSectorSizeInBytes(1024); - EXPECT_THROW(hd.FinalizeSetup(2LL * 1024 * 1024 * 1024 * 1024 + hd.GetSectorSizeInBytes(), 0), io_exception) - << "Unsupported drive capacity"; - EXPECT_THROW(hd.FinalizeSetup(0), io_exception) << "Device has 0 blocks"; +} - hd.SetBlockCount(1); - hd.FinalizeSetup(2LL * 1024 * 1024 * 1024 * 1024); - hd.FinalizeSetup(2LL * 1024 * 1024 * 1024 * 1024 + hd.GetSectorSizeInBytes() - 1); +TEST(ScsiHdTest, GetProductData) +{ + const unordered_set sector_sizes; + MockSCSIHD hd_kb(0, sector_sizes, false); + MockSCSIHD hd_mb(0, sector_sizes, false); + MockSCSIHD hd_gb(0, sector_sizes, false); + + const path filename = CreateTempFile(1); + hd_kb.SetFilename(string(filename)); + hd_kb.SetSectorSizeInBytes(1024); + hd_kb.SetBlockCount(1); + hd_kb.FinalizeSetup(0); + string s = hd_kb.GetProduct(); + EXPECT_NE(string::npos, s.find("1 KiB")); + + hd_mb.SetFilename(string(filename)); + hd_mb.SetSectorSizeInBytes(1024); + hd_mb.SetBlockCount(1'048'576 / 1024); + hd_mb.FinalizeSetup(0); + s = hd_mb.GetProduct(); + EXPECT_NE(string::npos, s.find("1 MiB")); + + hd_gb.SetFilename(string(filename)); + hd_gb.SetSectorSizeInBytes(1024); + hd_gb.SetBlockCount(1'099'511'627'776 / 1024); + hd_gb.FinalizeSetup(0); + s = hd_gb.GetProduct(); + EXPECT_NE(string::npos, s.find("1 GiB")); + remove(filename); } TEST(ScsiHdTest, SetUpModePages) @@ -49,14 +82,14 @@ TEST(ScsiHdTest, SetUpModePages) const unordered_set sector_sizes; MockSCSIHD hd(0, sector_sizes, false); - hd.SetReady(false); + // Non changeable hd.SetUpModePages(pages, 0x3f, false); - EXPECT_EQ(5, pages.size()) << "Unexpected number of mode pages"; - EXPECT_EQ(12, pages[1].size()); - EXPECT_EQ(24, pages[3].size()); - EXPECT_EQ(24, pages[4].size()); - EXPECT_EQ(12, pages[8].size()); - EXPECT_EQ(30, pages[48].size()); + ScsiHdTest_SetUpModePages(pages); + + // Changeable + pages.clear(); + hd.SetUpModePages(pages, 0x3f, true); + ScsiHdTest_SetUpModePages(pages); } TEST(ScsiHdTest, ModeSelect) diff --git a/src/raspberrypi/test/scsimo_test.cpp b/src/raspberrypi/test/scsimo_test.cpp index 42d56874..14d1b8e0 100644 --- a/src/raspberrypi/test/scsimo_test.cpp +++ b/src/raspberrypi/test/scsimo_test.cpp @@ -9,6 +9,17 @@ #include "mocks.h" +void ScsiMo_SetUpModePages(map>& pages) +{ + EXPECT_EQ(6, pages.size()) << "Unexpected number of mode pages"; + EXPECT_EQ(12, pages[1].size()); + EXPECT_EQ(24, pages[3].size()); + EXPECT_EQ(24, pages[4].size()); + EXPECT_EQ(4, pages[6].size()); + EXPECT_EQ(12, pages[8].size()); + EXPECT_EQ(12, pages[32].size()); +} + TEST(ScsiMoTest, Inquiry) { TestInquiry(SCMO, device_type::OPTICAL_MEMORY, scsi_level::SCSI_2, "RaSCSI SCSI MO ", 0x1f, true); @@ -29,15 +40,14 @@ TEST(ScsiMoTest, SetUpModePages) const unordered_set sector_sizes; MockSCSIMO mo(0, sector_sizes); - mo.SetReady(false); + // Non changeable mo.SetUpModePages(pages, 0x3f, false); - EXPECT_EQ(6, pages.size()) << "Unexpected number of mode pages"; - EXPECT_EQ(12, pages[1].size()); - EXPECT_EQ(24, pages[3].size()); - EXPECT_EQ(24, pages[4].size()); - EXPECT_EQ(4, pages[6].size()); - EXPECT_EQ(12, pages[8].size()); - EXPECT_EQ(12, pages[32].size()); + ScsiMo_SetUpModePages(pages); + + // Changeable + pages.clear(); + mo.SetUpModePages(pages, 0x3f, true); + ScsiMo_SetUpModePages(pages); } TEST(ScsiMoTest, TestAddVendorPage) diff --git a/src/raspberrypi/test/storage_device_test.cpp b/src/raspberrypi/test/storage_device_test.cpp index 87a46b4c..651859ae 100644 --- a/src/raspberrypi/test/storage_device_test.cpp +++ b/src/raspberrypi/test/storage_device_test.cpp @@ -10,7 +10,9 @@ #include "mocks.h" #include "rascsi_exceptions.h" #include "devices/storage_device.h" -#include +#include + +using namespace filesystem; TEST(StorageDeviceTest, Filename) { @@ -25,26 +27,35 @@ TEST(StorageDeviceTest, ValidateFile) MockStorageDevice device; device.SetBlockCount(0); - EXPECT_THROW(device.ValidateFile("/non_existing_file"), io_exception); + device.SetFilename("/non_existing_file"); + EXPECT_THROW(device.ValidateFile(), io_exception); - device.SetReadOnly(false); - device.SetProtectable(true); device.SetBlockCount(1); - device.ValidateFile("/non_existing_file"); - EXPECT_TRUE(device.IsReadOnly()); - EXPECT_FALSE(device.IsProtectable()); - EXPECT_FALSE(device.IsStopped()); - EXPECT_FALSE(device.IsRemoved()); - EXPECT_FALSE(device.IsLocked()); + EXPECT_THROW(device.ValidateFile(), io_exception); + const path filename = CreateTempFile(1); + device.SetFilename(string(filename)); device.SetReadOnly(false); device.SetProtectable(true); - device.ValidateFile("/dev/null"); + device.ValidateFile(); EXPECT_FALSE(device.IsReadOnly()); EXPECT_TRUE(device.IsProtectable()); EXPECT_FALSE(device.IsStopped()); EXPECT_FALSE(device.IsRemoved()); EXPECT_FALSE(device.IsLocked()); + + permissions(filename, perms::owner_read); + device.SetReadOnly(false); + device.SetProtectable(true); + device.ValidateFile(); + EXPECT_TRUE(device.IsReadOnly()); + EXPECT_FALSE(device.IsProtectable()); + EXPECT_FALSE(device.IsProtected()); + EXPECT_FALSE(device.IsStopped()); + EXPECT_FALSE(device.IsRemoved()); + EXPECT_FALSE(device.IsLocked()); + + remove(filename); } TEST(StorageDeviceTest, MediumChanged) @@ -62,21 +73,24 @@ TEST(StorageDeviceTest, GetIdsForReservedFile) { const int ID = 1; const int LUN = 2; + StorageDevice::UnreserveAll(); MockStorageDevice device; device.SetFilename("filename"); - int id; - int lun; - EXPECT_FALSE(StorageDevice::GetIdsForReservedFile("filename", id, lun)); + const auto [id1, lun1] = StorageDevice::GetIdsForReservedFile("filename"); + EXPECT_EQ(-1, id1); + EXPECT_EQ(-1, lun1); device.ReserveFile("filename", ID, LUN); - EXPECT_TRUE(StorageDevice::GetIdsForReservedFile("filename", id, lun)); - EXPECT_EQ(ID, id); - EXPECT_EQ(LUN, lun); + const auto [id2, lun2] = StorageDevice::GetIdsForReservedFile("filename"); + EXPECT_EQ(ID, id2); + EXPECT_EQ(LUN, lun2); device.UnreserveFile(); - EXPECT_FALSE(StorageDevice::GetIdsForReservedFile("filename", id, lun)); + const auto [id3, lun3] = StorageDevice::GetIdsForReservedFile("filename"); + EXPECT_EQ(-1, id3); + EXPECT_EQ(-1, lun3); } TEST(StorageDeviceTest, UnreserveAll) @@ -85,9 +99,9 @@ TEST(StorageDeviceTest, UnreserveAll) device.ReserveFile("filename", 2, 31); StorageDevice::UnreserveAll(); - int id; - int lun; - EXPECT_FALSE(StorageDevice::GetIdsForReservedFile("filename", id, lun)); + const auto [id, lun] = StorageDevice::GetIdsForReservedFile("filename"); + EXPECT_EQ(-1, id); + EXPECT_EQ(-1, lun); } TEST(StorageDeviceTest, GetSetReservedFiles) @@ -128,10 +142,10 @@ TEST(StorageDeviceTest, GetFileSize) { MockStorageDevice device; - const string filename = CreateTempFile(512); - device.SetFilename(filename); + const path filename = CreateTempFile(512); + device.SetFilename(filename.c_str()); const off_t size = device.GetFileSize(); - unlink(filename.c_str()); + remove(filename); EXPECT_EQ(512, size); device.SetFilename("/non_existing_file"); diff --git a/src/raspberrypi/test/test_shared.cpp b/src/raspberrypi/test/test_shared.cpp index 5addf1f7..fd47067e 100644 --- a/src/raspberrypi/test/test_shared.cpp +++ b/src/raspberrypi/test/test_shared.cpp @@ -14,8 +14,10 @@ #include #include #include +#include using namespace std; +using namespace filesystem; shared_ptr CreateDevice(PbDeviceType type, MockAbstractController& controller, const string& extension) { @@ -65,33 +67,31 @@ void TestDispatch(PbDeviceType type) NiceMock controller(make_shared(), 0); auto device = CreateDevice(type, controller); - EXPECT_FALSE(device->Dispatch(scsi_command::eCmdIcd)) << "Command is not supported by this class"; + EXPECT_FALSE(device->Dispatch(scsi_command::eCmdIcd)) << "Command is not supported by this class"; } -int OpenTempFile(string& file) +pair OpenTempFile() { - char filename[] = "/tmp/rascsi_test-XXXXXX"; //NOSONAR mkstemp() requires a modifiable string + const string filename = string(temp_directory_path()) + "/rascsi_test-XXXXXX"; //NOSONAR Publicly writable directory is fine here + vector f(filename.begin(), filename.end()); + f.push_back(0); - const int fd = mkstemp(filename); - EXPECT_NE(-1, fd) << "Couldn't create temporary file '" << filename << "'"; + const int fd = mkstemp(f.data()); + EXPECT_NE(-1, fd) << "Couldn't create temporary file '" << f.data() << "'"; - file = filename; - - return fd; + return make_pair(fd, path(f.data())); } -string CreateTempFile(int size) +path CreateTempFile(int size) { - char filename[] = "/tmp/rascsi_test-XXXXXX"; //NOSONAR mkstemp() requires a modifiable string + const auto [fd, filename] = OpenTempFile(); + vector data(size); - - const int fd = mkstemp(filename); - const size_t count = write(fd, data.data(), data.size()); close(fd); EXPECT_EQ(count, data.size()) << "Couldn't create temporary file '" << string(filename) << "'"; - return filename; + return path(filename); } int GetInt16(const vector& buf, int offset) @@ -106,6 +106,5 @@ uint32_t GetInt32(const vector& buf, int offset) assert(buf.size() > (size_t)offset + 3); return ((uint32_t)buf[offset] << 24) | ((uint32_t)buf[offset + 1] << 16) | - ((uint32_t)buf[offset + 2] << 8) | (uint32_t)buf[offset + 3]; + ((uint32_t)buf[offset + 2] << 8) | (uint32_t)buf[offset + 3]; } - diff --git a/src/raspberrypi/test/test_shared.h b/src/raspberrypi/test/test_shared.h index 90c839a5..0bc07118 100644 --- a/src/raspberrypi/test/test_shared.h +++ b/src/raspberrypi/test/test_shared.h @@ -13,8 +13,10 @@ #include "rascsi_interface.pb.h" #include #include +#include using namespace std; +using namespace filesystem; using namespace rascsi_interface; class PrimaryDevice; @@ -27,9 +29,8 @@ void TestInquiry(PbDeviceType, scsi_defs::device_type, scsi_defs::scsi_level, co void TestDispatch(PbDeviceType); -int OpenTempFile(string&); -string CreateTempFile(int); +pair OpenTempFile(); +path CreateTempFile(int); int GetInt16(const vector&, int); uint32_t GetInt32(const vector&, int); - From 4b109a70b01ac48f1f118721337a97d61e5d53aa Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Tue, 25 Oct 2022 08:51:04 -0700 Subject: [PATCH 2/4] Improve Web UI integration tests (#939) * Remove deprecated critital log level from test * Move drive_properties back into template data sets * Move properties data integrity checks to test code * Streamline the drive formatting logic --- python/web/src/templates/drives.html | 6 ++--- python/web/src/templates/index.html | 8 +++--- python/web/src/web.py | 3 ++- python/web/src/web_utils.py | 38 +++++++-------------------- python/web/tests/api/test_misc.py | 13 +++++++++ python/web/tests/api/test_settings.py | 2 +- 6 files changed, 33 insertions(+), 37 deletions(-) diff --git a/python/web/src/templates/drives.html b/python/web/src/templates/drives.html index 059c26fd..28f2ab7b 100644 --- a/python/web/src/templates/drives.html +++ b/python/web/src/templates/drives.html @@ -13,7 +13,7 @@ {{ _("Description") }} {{ _("Action") }} -{% for hd in env['drive_properties']['hd_conf']|sort(attribute='name') %} +{% for hd in drive_properties['hd_conf']|sort(attribute='name') %} {% if hd.url != "" %} @@ -48,7 +48,7 @@ {{ _("Description") }} {{ _("Action") }} -{% for cd in env['drive_properties']['cd_conf']|sort(attribute='name') %} +{% for cd in drive_properties['cd_conf']|sort(attribute='name') %} {% if cd.url != "" %} @@ -88,7 +88,7 @@ {{ _("Description") }} {{ _("Action") }} -{% for rm in env['drive_properties']['rm_conf']|sort(attribute='name') %} +{% for rm in drive_properties['rm_conf']|sort(attribute='name') %} {% if rm.url != "" %} diff --git a/python/web/src/templates/index.html b/python/web/src/templates/index.html index 541fba70..96246f43 100644 --- a/python/web/src/templates/index.html +++ b/python/web/src/templates/index.html @@ -392,21 +392,21 @@ {{ _("None") }} {% if type == "SCCD" %} - {% for drive in env["drive_properties"]["cd_conf"] | sort(attribute='name') %} + {% for drive in drive_properties["cd_conf"] | sort(attribute='name') %} {% endfor %} {% endif %} {% if type == "SCRM" %} - {% for drive in env["drive_properties"]["rm_conf"] | sort(attribute='name') %} + {% for drive in drive_properties["rm_conf"] | sort(attribute='name') %} {% endfor %} {% endif %} {% if type == "SCMO" %} - {% for drive in env["drive_properties"]["mo_conf"] | sort(attribute='name') %} + {% for drive in drive_properties["mo_conf"] | sort(attribute='name') %} @@ -581,7 +581,7 @@ - {% for drive in env["drive_properties"]["hd_conf"] | sort(attribute='name') %} + {% for drive in drive_properties["hd_conf"] | sort(attribute='name') %} diff --git a/python/web/src/web.py b/python/web/src/web.py index 989a8ca7..6e79f405 100644 --- a/python/web/src/web.py +++ b/python/web/src/web.py @@ -98,7 +98,6 @@ def get_env_info(): "cd_suffixes": tuple(server_info["sccd"]), "rm_suffixes": tuple(server_info["scrm"]), "mo_suffixes": tuple(server_info["scmo"]), - "drive_properties": format_drive_properties(APP.config["RASCSI_DRIVE_PROPERTIES"]), } @@ -249,6 +248,7 @@ def index(): image_suffixes_to_create=image_suffixes_to_create, valid_image_suffixes=valid_image_suffixes, max_file_size=int(int(MAX_FILE_SIZE) / 1024 / 1024), + drive_properties=format_drive_properties(APP.config["RASCSI_DRIVE_PROPERTIES"]), RESERVATIONS=RESERVATIONS, CFG_DIR=CFG_DIR, AFP_DIR=AFP_DIR, @@ -278,6 +278,7 @@ def drive_list(): return response( template="drives.html", files=file_cmd.list_images()["files"], + drive_properties=format_drive_properties(APP.config["RASCSI_DRIVE_PROPERTIES"]), ) diff --git a/python/web/src/web_utils.py b/python/web/src/web_utils.py index 4c6d5ba5..02ba45d9 100644 --- a/python/web/src/web_utils.py +++ b/python/web/src/web_utils.py @@ -153,29 +153,25 @@ def format_drive_properties(drive_properties): cd_conf = [] rm_conf = [] mo_conf = [] - FORMAT_FILTER = "{:,.2f}" for device in drive_properties: - # Add fallback device names, since other code relies on this data for display - if not device["name"]: - if device["product"]: - device["name"] = device["product"] - else: - device["name"] = "Unknown Device" + # Fallback for when the properties data is corrupted, to avoid crashing the web app. + # The integration tests will catch this scenario, but relies on the web app not crashing. + if not device.get("name"): + device["name"] = "" + + device["secure_name"] = secure_filename(device["name"]) + + if device.get("size"): + device["size_mb"] = f'{device["size"] / 1024 / 1024:,.2f}' + if device["device_type"] == "SCHD": - device["secure_name"] = secure_filename(device["name"]) - device["size_mb"] = FORMAT_FILTER.format(device["size"] / 1024 / 1024) hd_conf.append(device) elif device["device_type"] == "SCCD": - device["size_mb"] = _("N/A") cd_conf.append(device) elif device["device_type"] == "SCRM": - device["secure_name"] = secure_filename(device["name"]) - device["size_mb"] = FORMAT_FILTER.format(device["size"] / 1024 / 1024) rm_conf.append(device) elif device["device_type"] == "SCMO": - device["secure_name"] = secure_filename(device["name"]) - device["size_mb"] = FORMAT_FILTER.format(device["size"] / 1024 / 1024) mo_conf.append(device) return { @@ -193,21 +189,7 @@ def get_properties_by_drive_name(drives, drive_name): drives.sort(key=lambda item: item.get("name")) drive_props = None - prev_drive = {"name": ""} for drive in drives: - # TODO: Make this check into an integration test - if "name" not in drive: - logging.warning( - "Device without a name exists in the drive properties database. This is a bug." - ) - break - # TODO: Make this check into an integration test - if drive["name"] == prev_drive["name"]: - logging.warning( - "Device with duplicate name \"%s\" in drive properties database. This is a bug.", - drive["name"], - ) - prev_drive = drive if drive["name"] == drive_name: drive_props = drive diff --git a/python/web/tests/api/test_misc.py b/python/web/tests/api/test_misc.py index ba8f1836..41db0280 100644 --- a/python/web/tests/api/test_misc.py +++ b/python/web/tests/api/test_misc.py @@ -39,6 +39,19 @@ def test_show_named_drive_presets(http_client): response = http_client.get("/drive/list") response_data = response.json() + prev_drive = {"name": ""} + for drive in ( + response_data["data"]["drive_properties"]["hd_conf"] + + response_data["data"]["drive_properties"]["cd_conf"] + + response_data["data"]["drive_properties"]["rm_conf"] + + response_data["data"]["drive_properties"]["mo_conf"] + ): + # Test that the named drive has a name + assert drive["name"] != "" + # Test that "name" is unique for each named drive + assert drive["name"] != prev_drive["name"] + prev_drive = drive + assert response.status_code == 200 assert response_data["status"] == STATUS_SUCCESS assert "files" in response_data["data"] diff --git a/python/web/tests/api/test_settings.py b/python/web/tests/api/test_settings.py index e50612d0..18d3d3b9 100644 --- a/python/web/tests/api/test_settings.py +++ b/python/web/tests/api/test_settings.py @@ -31,7 +31,7 @@ def test_set_language(http_client, locale, confirm_message): # route("/logs/level", methods=["POST"]) -@pytest.mark.parametrize("level", ["trace", "debug", "info", "warn", "err", "critical", "off"]) +@pytest.mark.parametrize("level", ["trace", "debug", "info", "warn", "err", "off"]) def test_set_log_level(http_client, level): response = http_client.post( "/logs/level", From 08194af424561e33a543ce4711e0efe6cc90e830 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Tue, 25 Oct 2022 12:59:30 -0700 Subject: [PATCH 3/4] Move C++ code into cpp/ dir (#941) - Moved C++ code to cpp/ from src/raspberrypi - Related updates to Makefile, easyinstall.sh, and the github build rules - Removed the native X68k C code in src/x68k from the repo --- .github/workflows/build_code.yml | 8 +- .github/workflows/run_tests.yml | 2 +- {src/raspberrypi => cpp}/.clang-format | 0 {src/raspberrypi => cpp}/.gitignore | 0 {src/raspberrypi => cpp}/.vscode/launch.json | 0 .../raspberrypi => cpp}/.vscode/settings.json | 0 {src/raspberrypi => cpp}/.vscode/tasks.json | 0 {src/raspberrypi => cpp}/Makefile | 4 +- {src/raspberrypi => cpp}/bus.cpp | 0 {src/raspberrypi => cpp}/bus.h | 0 {src/raspberrypi => cpp}/config.h | 0 .../controllers/abstract_controller.cpp | 0 .../controllers/abstract_controller.h | 0 .../controllers/controller_manager.cpp | 0 .../controllers/controller_manager.h | 0 .../controllers/phase_handler.h | 0 .../controllers/scsi_controller.cpp | 0 .../controllers/scsi_controller.h | 0 {src/raspberrypi => cpp}/devices/cd_track.cpp | 0 {src/raspberrypi => cpp}/devices/cd_track.h | 0 .../devices/cfilesystem.cpp | 0 .../raspberrypi => cpp}/devices/cfilesystem.h | 0 .../devices/ctapdriver.cpp | 0 {src/raspberrypi => cpp}/devices/ctapdriver.h | 0 {src/raspberrypi => cpp}/devices/device.cpp | 0 {src/raspberrypi => cpp}/devices/device.h | 0 .../devices/device_factory.cpp | 0 .../devices/device_factory.h | 0 {src/raspberrypi => cpp}/devices/disk.cpp | 0 {src/raspberrypi => cpp}/devices/disk.h | 0 .../devices/disk_cache.cpp | 0 {src/raspberrypi => cpp}/devices/disk_cache.h | 0 .../devices/disk_track.cpp | 0 {src/raspberrypi => cpp}/devices/disk_track.h | 0 {src/raspberrypi => cpp}/devices/dispatcher.h | 0 .../devices/host_services.cpp | 0 .../devices/host_services.h | 0 .../devices/interfaces/scsi_block_commands.h | 0 .../devices/interfaces/scsi_mmc_commands.h | 0 .../interfaces/scsi_primary_commands.h | 0 .../interfaces/scsi_printer_commands.h | 0 .../devices/mode_page_device.cpp | 0 .../devices/mode_page_device.h | 0 .../devices/primary_device.cpp | 0 .../devices/primary_device.h | 0 .../devices/scsi_command_util.cpp | 0 .../devices/scsi_command_util.h | 0 .../devices/scsi_daynaport.cpp | 0 .../devices/scsi_daynaport.h | 0 .../devices/scsi_host_bridge.cpp | 0 .../devices/scsi_host_bridge.h | 0 .../devices/scsi_printer.cpp | 0 .../devices/scsi_printer.h | 0 {src/raspberrypi => cpp}/devices/scsicd.cpp | 0 {src/raspberrypi => cpp}/devices/scsicd.h | 0 {src/raspberrypi => cpp}/devices/scsihd.cpp | 0 {src/raspberrypi => cpp}/devices/scsihd.h | 0 .../devices/scsihd_nec.cpp | 0 {src/raspberrypi => cpp}/devices/scsihd_nec.h | 0 {src/raspberrypi => cpp}/devices/scsimo.cpp | 0 {src/raspberrypi => cpp}/devices/scsimo.h | 0 .../devices/storage_device.cpp | 0 .../devices/storage_device.h | 0 {src/raspberrypi => cpp}/hal/gpiobus.cpp | 0 {src/raspberrypi => cpp}/hal/gpiobus.h | 0 {src/raspberrypi => cpp}/hal/gpiobus_aibom.h | 0 .../hal/gpiobus_allwinner.cpp | 0 .../hal/gpiobus_allwinner.h | 0 .../hal/gpiobus_factory.cpp | 0 .../raspberrypi => cpp}/hal/gpiobus_factory.h | 0 .../hal/gpiobus_fullspec.h | 0 .../hal/gpiobus_gamernium.h | 0 .../hal/gpiobus_raspberry.cpp | 0 .../hal/gpiobus_raspberry.h | 0 .../hal/gpiobus_standard.h | 0 {src/raspberrypi => cpp}/hal/sbc_version.cpp | 0 {src/raspberrypi => cpp}/hal/sbc_version.h | 0 {src/raspberrypi => cpp}/hal/systimer.cpp | 0 {src/raspberrypi => cpp}/hal/systimer.h | 0 .../hal/systimer_allwinner.cpp | 0 .../hal/systimer_allwinner.h | 0 .../hal/systimer_raspberry.cpp | 0 .../hal/systimer_raspberry.h | 0 {src/raspberrypi => cpp}/launch_sudo.sh | 0 {src/raspberrypi => cpp}/log.h | 0 .../monitor/data_sample.cpp | 0 .../raspberrypi => cpp}/monitor/data_sample.h | 0 .../monitor/sm_html_report.cpp | 0 .../monitor/sm_json_report.cpp | 0 {src/raspberrypi => cpp}/monitor/sm_reports.h | 0 .../monitor/sm_vcd_report.cpp | 0 {src/raspberrypi => cpp}/os.h | 0 .../os_integration/dhcpcd.conf.patch | 0 .../os_integration/rascsi.conf | 0 .../os_integration/rascsi.service | 0 .../os_integration/rascsi_bridge | 0 .../protobuf_serializer.cpp | 0 .../raspberrypi => cpp}/protobuf_serializer.h | 0 {src/raspberrypi => cpp}/protobuf_util.cpp | 0 {src/raspberrypi => cpp}/protobuf_util.h | 0 {src/raspberrypi => cpp}/rascsi.cpp | 0 .../rascsi/command_context.cpp | 0 .../rascsi/command_context.h | 0 {src/raspberrypi => cpp}/rascsi/localizer.cpp | 0 {src/raspberrypi => cpp}/rascsi/localizer.h | 0 .../rascsi/rascsi_executor.cpp | 0 .../rascsi/rascsi_executor.h | 0 .../rascsi/rascsi_image.cpp | 0 .../raspberrypi => cpp}/rascsi/rascsi_image.h | 0 .../rascsi/rascsi_response.cpp | 0 .../rascsi/rascsi_response.h | 0 .../rascsi/rascsi_service.cpp | 0 .../rascsi/rascsi_service.h | 0 {src/raspberrypi => cpp}/rascsi_exceptions.h | 0 .../rascsi_interface.proto | 0 {src/raspberrypi => cpp}/rascsi_version.cpp | 0 {src/raspberrypi => cpp}/rascsi_version.h | 0 {src/raspberrypi => cpp}/rasctl.cpp | 0 .../rasctl/rasctl_commands.cpp | 0 .../rasctl/rasctl_commands.h | 0 .../rasctl/rasctl_display.cpp | 0 .../rasctl/rasctl_display.h | 0 .../rasctl/rasctl_parser.cpp | 0 .../rasctl/rasctl_parser.h | 0 {src/raspberrypi => cpp}/rasdump.cpp | 0 {src/raspberrypi => cpp}/rasdump_fileio.cpp | 0 {src/raspberrypi => cpp}/rasdump_fileio.h | 0 {src/raspberrypi => cpp}/rasutil.cpp | 0 {src/raspberrypi => cpp}/rasutil.h | 0 {src/raspberrypi => cpp}/scsi.h | 0 {src/raspberrypi => cpp}/scsimon.cpp | 0 .../test/abstract_controller_test.cpp | 0 {src/raspberrypi => cpp}/test/bus_test.cpp | 0 .../test/command_context_test.cpp | 0 .../test/controller_manager_test.cpp | 0 .../test/ctapdriver_test.cpp | 0 .../test/device_factory_test.cpp | 0 {src/raspberrypi => cpp}/test/device_test.cpp | 0 {src/raspberrypi => cpp}/test/disk_test.cpp | 0 .../raspberrypi => cpp}/test/gpiobus_test.cpp | 0 .../test/host_services_test.cpp | 0 .../test/localizer_test.cpp | 0 {src/raspberrypi => cpp}/test/mocks.h | 0 .../test/mode_page_device_test.cpp | 0 .../test/phase_handler_test.cpp | 0 .../test/primary_device_test.cpp | 0 .../test/protobuf_serializer_test.cpp | 0 .../test/protobuf_util_test.cpp | 0 .../test/rascsi_exceptions_test.cpp | 0 .../test/rascsi_executor_test.cpp | 0 .../test/rascsi_image_test.cpp | 0 .../test/rascsi_response_test.cpp | 0 .../test/rascsi_service_test.cpp | 0 .../test/rasctl_commands_test.cpp | 0 .../test/rasctl_display_test.cpp | 0 .../test/rasctl_parser_test.cpp | 0 .../raspberrypi => cpp}/test/rasutil_test.cpp | 0 .../test/scsi_command_util_test.cpp | 0 .../test/scsi_controller_test.cpp | 0 .../test/scsi_daynaport_test.cpp | 0 .../test/scsi_host_bridge_test.cpp | 0 .../test/scsi_printer_test.cpp | 0 {src/raspberrypi => cpp}/test/scsicd_test.cpp | 0 .../test/scsihd_nec_test.cpp | 0 {src/raspberrypi => cpp}/test/scsihd_test.cpp | 0 {src/raspberrypi => cpp}/test/scsimo_test.cpp | 0 .../test/storage_device_test.cpp | 0 {src/raspberrypi => cpp}/test/test_setup.cpp | 0 {src/raspberrypi => cpp}/test/test_shared.cpp | 0 {src/raspberrypi => cpp}/test/test_shared.h | 0 easyinstall.sh | 7 +- src/x68k/RASCTL/Makefile | 13 - src/x68k/RASCTL/RASCTL.C | 433 --- src/x68k/RASDRV/BRIDGE.C | 2430 ----------------- src/x68k/RASDRV/BRIDGE.H | 255 -- src/x68k/RASDRV/Makefile | 17 - src/x68k/RASDRV/RASDRV.S | 193 -- src/x68k/RASETHER/Makefile | 33 - src/x68k/RASETHER/asmsub.s | 22 - src/x68k/RASETHER/main.c | 282 -- src/x68k/RASETHER/main.h | 81 - src/x68k/RASETHER/re.s | 574 ---- src/x68k/RASETHER/scsictl.c | 537 ---- src/x68k/RASETHER/scsictl.h | 40 - 184 files changed, 11 insertions(+), 4920 deletions(-) rename {src/raspberrypi => cpp}/.clang-format (100%) rename {src/raspberrypi => cpp}/.gitignore (100%) rename {src/raspberrypi => cpp}/.vscode/launch.json (100%) rename {src/raspberrypi => cpp}/.vscode/settings.json (100%) rename {src/raspberrypi => cpp}/.vscode/tasks.json (100%) rename {src/raspberrypi => cpp}/Makefile (98%) rename {src/raspberrypi => cpp}/bus.cpp (100%) rename {src/raspberrypi => cpp}/bus.h (100%) rename {src/raspberrypi => cpp}/config.h (100%) rename {src/raspberrypi => cpp}/controllers/abstract_controller.cpp (100%) rename {src/raspberrypi => cpp}/controllers/abstract_controller.h (100%) rename {src/raspberrypi => cpp}/controllers/controller_manager.cpp (100%) rename {src/raspberrypi => cpp}/controllers/controller_manager.h (100%) rename {src/raspberrypi => cpp}/controllers/phase_handler.h (100%) rename {src/raspberrypi => cpp}/controllers/scsi_controller.cpp (100%) rename {src/raspberrypi => cpp}/controllers/scsi_controller.h (100%) rename {src/raspberrypi => cpp}/devices/cd_track.cpp (100%) rename {src/raspberrypi => cpp}/devices/cd_track.h (100%) rename {src/raspberrypi => cpp}/devices/cfilesystem.cpp (100%) rename {src/raspberrypi => cpp}/devices/cfilesystem.h (100%) rename {src/raspberrypi => cpp}/devices/ctapdriver.cpp (100%) rename {src/raspberrypi => cpp}/devices/ctapdriver.h (100%) rename {src/raspberrypi => cpp}/devices/device.cpp (100%) rename {src/raspberrypi => cpp}/devices/device.h (100%) rename {src/raspberrypi => cpp}/devices/device_factory.cpp (100%) rename {src/raspberrypi => cpp}/devices/device_factory.h (100%) rename {src/raspberrypi => cpp}/devices/disk.cpp (100%) rename {src/raspberrypi => cpp}/devices/disk.h (100%) rename {src/raspberrypi => cpp}/devices/disk_cache.cpp (100%) rename {src/raspberrypi => cpp}/devices/disk_cache.h (100%) rename {src/raspberrypi => cpp}/devices/disk_track.cpp (100%) rename {src/raspberrypi => cpp}/devices/disk_track.h (100%) rename {src/raspberrypi => cpp}/devices/dispatcher.h (100%) rename {src/raspberrypi => cpp}/devices/host_services.cpp (100%) rename {src/raspberrypi => cpp}/devices/host_services.h (100%) rename {src/raspberrypi => cpp}/devices/interfaces/scsi_block_commands.h (100%) rename {src/raspberrypi => cpp}/devices/interfaces/scsi_mmc_commands.h (100%) rename {src/raspberrypi => cpp}/devices/interfaces/scsi_primary_commands.h (100%) rename {src/raspberrypi => cpp}/devices/interfaces/scsi_printer_commands.h (100%) rename {src/raspberrypi => cpp}/devices/mode_page_device.cpp (100%) rename {src/raspberrypi => cpp}/devices/mode_page_device.h (100%) rename {src/raspberrypi => cpp}/devices/primary_device.cpp (100%) rename {src/raspberrypi => cpp}/devices/primary_device.h (100%) rename {src/raspberrypi => cpp}/devices/scsi_command_util.cpp (100%) rename {src/raspberrypi => cpp}/devices/scsi_command_util.h (100%) rename {src/raspberrypi => cpp}/devices/scsi_daynaport.cpp (100%) rename {src/raspberrypi => cpp}/devices/scsi_daynaport.h (100%) rename {src/raspberrypi => cpp}/devices/scsi_host_bridge.cpp (100%) rename {src/raspberrypi => cpp}/devices/scsi_host_bridge.h (100%) rename {src/raspberrypi => cpp}/devices/scsi_printer.cpp (100%) rename {src/raspberrypi => cpp}/devices/scsi_printer.h (100%) rename {src/raspberrypi => cpp}/devices/scsicd.cpp (100%) rename {src/raspberrypi => cpp}/devices/scsicd.h (100%) rename {src/raspberrypi => cpp}/devices/scsihd.cpp (100%) rename {src/raspberrypi => cpp}/devices/scsihd.h (100%) rename {src/raspberrypi => cpp}/devices/scsihd_nec.cpp (100%) rename {src/raspberrypi => cpp}/devices/scsihd_nec.h (100%) rename {src/raspberrypi => cpp}/devices/scsimo.cpp (100%) rename {src/raspberrypi => cpp}/devices/scsimo.h (100%) rename {src/raspberrypi => cpp}/devices/storage_device.cpp (100%) rename {src/raspberrypi => cpp}/devices/storage_device.h (100%) rename {src/raspberrypi => cpp}/hal/gpiobus.cpp (100%) rename {src/raspberrypi => cpp}/hal/gpiobus.h (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_aibom.h (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_allwinner.cpp (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_allwinner.h (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_factory.cpp (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_factory.h (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_fullspec.h (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_gamernium.h (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_raspberry.cpp (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_raspberry.h (100%) rename {src/raspberrypi => cpp}/hal/gpiobus_standard.h (100%) rename {src/raspberrypi => cpp}/hal/sbc_version.cpp (100%) rename {src/raspberrypi => cpp}/hal/sbc_version.h (100%) rename {src/raspberrypi => cpp}/hal/systimer.cpp (100%) rename {src/raspberrypi => cpp}/hal/systimer.h (100%) rename {src/raspberrypi => cpp}/hal/systimer_allwinner.cpp (100%) rename {src/raspberrypi => cpp}/hal/systimer_allwinner.h (100%) rename {src/raspberrypi => cpp}/hal/systimer_raspberry.cpp (100%) rename {src/raspberrypi => cpp}/hal/systimer_raspberry.h (100%) rename {src/raspberrypi => cpp}/launch_sudo.sh (100%) rename {src/raspberrypi => cpp}/log.h (100%) rename {src/raspberrypi => cpp}/monitor/data_sample.cpp (100%) rename {src/raspberrypi => cpp}/monitor/data_sample.h (100%) rename {src/raspberrypi => cpp}/monitor/sm_html_report.cpp (100%) rename {src/raspberrypi => cpp}/monitor/sm_json_report.cpp (100%) rename {src/raspberrypi => cpp}/monitor/sm_reports.h (100%) rename {src/raspberrypi => cpp}/monitor/sm_vcd_report.cpp (100%) rename {src/raspberrypi => cpp}/os.h (100%) rename {src/raspberrypi => cpp}/os_integration/dhcpcd.conf.patch (100%) rename {src/raspberrypi => cpp}/os_integration/rascsi.conf (100%) rename {src/raspberrypi => cpp}/os_integration/rascsi.service (100%) rename {src/raspberrypi => cpp}/os_integration/rascsi_bridge (100%) rename {src/raspberrypi => cpp}/protobuf_serializer.cpp (100%) rename {src/raspberrypi => cpp}/protobuf_serializer.h (100%) rename {src/raspberrypi => cpp}/protobuf_util.cpp (100%) rename {src/raspberrypi => cpp}/protobuf_util.h (100%) rename {src/raspberrypi => cpp}/rascsi.cpp (100%) rename {src/raspberrypi => cpp}/rascsi/command_context.cpp (100%) rename {src/raspberrypi => cpp}/rascsi/command_context.h (100%) rename {src/raspberrypi => cpp}/rascsi/localizer.cpp (100%) rename {src/raspberrypi => cpp}/rascsi/localizer.h (100%) rename {src/raspberrypi => cpp}/rascsi/rascsi_executor.cpp (100%) rename {src/raspberrypi => cpp}/rascsi/rascsi_executor.h (100%) rename {src/raspberrypi => cpp}/rascsi/rascsi_image.cpp (100%) rename {src/raspberrypi => cpp}/rascsi/rascsi_image.h (100%) rename {src/raspberrypi => cpp}/rascsi/rascsi_response.cpp (100%) rename {src/raspberrypi => cpp}/rascsi/rascsi_response.h (100%) rename {src/raspberrypi => cpp}/rascsi/rascsi_service.cpp (100%) rename {src/raspberrypi => cpp}/rascsi/rascsi_service.h (100%) rename {src/raspberrypi => cpp}/rascsi_exceptions.h (100%) rename {src/raspberrypi => cpp}/rascsi_interface.proto (100%) rename {src/raspberrypi => cpp}/rascsi_version.cpp (100%) rename {src/raspberrypi => cpp}/rascsi_version.h (100%) rename {src/raspberrypi => cpp}/rasctl.cpp (100%) rename {src/raspberrypi => cpp}/rasctl/rasctl_commands.cpp (100%) rename {src/raspberrypi => cpp}/rasctl/rasctl_commands.h (100%) rename {src/raspberrypi => cpp}/rasctl/rasctl_display.cpp (100%) rename {src/raspberrypi => cpp}/rasctl/rasctl_display.h (100%) rename {src/raspberrypi => cpp}/rasctl/rasctl_parser.cpp (100%) rename {src/raspberrypi => cpp}/rasctl/rasctl_parser.h (100%) rename {src/raspberrypi => cpp}/rasdump.cpp (100%) rename {src/raspberrypi => cpp}/rasdump_fileio.cpp (100%) rename {src/raspberrypi => cpp}/rasdump_fileio.h (100%) rename {src/raspberrypi => cpp}/rasutil.cpp (100%) rename {src/raspberrypi => cpp}/rasutil.h (100%) rename {src/raspberrypi => cpp}/scsi.h (100%) rename {src/raspberrypi => cpp}/scsimon.cpp (100%) rename {src/raspberrypi => cpp}/test/abstract_controller_test.cpp (100%) rename {src/raspberrypi => cpp}/test/bus_test.cpp (100%) rename {src/raspberrypi => cpp}/test/command_context_test.cpp (100%) rename {src/raspberrypi => cpp}/test/controller_manager_test.cpp (100%) rename {src/raspberrypi => cpp}/test/ctapdriver_test.cpp (100%) rename {src/raspberrypi => cpp}/test/device_factory_test.cpp (100%) rename {src/raspberrypi => cpp}/test/device_test.cpp (100%) rename {src/raspberrypi => cpp}/test/disk_test.cpp (100%) rename {src/raspberrypi => cpp}/test/gpiobus_test.cpp (100%) rename {src/raspberrypi => cpp}/test/host_services_test.cpp (100%) rename {src/raspberrypi => cpp}/test/localizer_test.cpp (100%) rename {src/raspberrypi => cpp}/test/mocks.h (100%) rename {src/raspberrypi => cpp}/test/mode_page_device_test.cpp (100%) rename {src/raspberrypi => cpp}/test/phase_handler_test.cpp (100%) rename {src/raspberrypi => cpp}/test/primary_device_test.cpp (100%) rename {src/raspberrypi => cpp}/test/protobuf_serializer_test.cpp (100%) rename {src/raspberrypi => cpp}/test/protobuf_util_test.cpp (100%) rename {src/raspberrypi => cpp}/test/rascsi_exceptions_test.cpp (100%) rename {src/raspberrypi => cpp}/test/rascsi_executor_test.cpp (100%) rename {src/raspberrypi => cpp}/test/rascsi_image_test.cpp (100%) rename {src/raspberrypi => cpp}/test/rascsi_response_test.cpp (100%) rename {src/raspberrypi => cpp}/test/rascsi_service_test.cpp (100%) rename {src/raspberrypi => cpp}/test/rasctl_commands_test.cpp (100%) rename {src/raspberrypi => cpp}/test/rasctl_display_test.cpp (100%) rename {src/raspberrypi => cpp}/test/rasctl_parser_test.cpp (100%) rename {src/raspberrypi => cpp}/test/rasutil_test.cpp (100%) rename {src/raspberrypi => cpp}/test/scsi_command_util_test.cpp (100%) rename {src/raspberrypi => cpp}/test/scsi_controller_test.cpp (100%) rename {src/raspberrypi => cpp}/test/scsi_daynaport_test.cpp (100%) rename {src/raspberrypi => cpp}/test/scsi_host_bridge_test.cpp (100%) rename {src/raspberrypi => cpp}/test/scsi_printer_test.cpp (100%) rename {src/raspberrypi => cpp}/test/scsicd_test.cpp (100%) rename {src/raspberrypi => cpp}/test/scsihd_nec_test.cpp (100%) rename {src/raspberrypi => cpp}/test/scsihd_test.cpp (100%) rename {src/raspberrypi => cpp}/test/scsimo_test.cpp (100%) rename {src/raspberrypi => cpp}/test/storage_device_test.cpp (100%) rename {src/raspberrypi => cpp}/test/test_setup.cpp (100%) rename {src/raspberrypi => cpp}/test/test_shared.cpp (100%) rename {src/raspberrypi => cpp}/test/test_shared.h (100%) delete mode 100644 src/x68k/RASCTL/Makefile delete mode 100644 src/x68k/RASCTL/RASCTL.C delete mode 100644 src/x68k/RASDRV/BRIDGE.C delete mode 100644 src/x68k/RASDRV/BRIDGE.H delete mode 100644 src/x68k/RASDRV/Makefile delete mode 100644 src/x68k/RASDRV/RASDRV.S delete mode 100644 src/x68k/RASETHER/Makefile delete mode 100644 src/x68k/RASETHER/asmsub.s delete mode 100644 src/x68k/RASETHER/main.c delete mode 100644 src/x68k/RASETHER/main.h delete mode 100644 src/x68k/RASETHER/re.s delete mode 100644 src/x68k/RASETHER/scsictl.c delete mode 100644 src/x68k/RASETHER/scsictl.h diff --git a/.github/workflows/build_code.yml b/.github/workflows/build_code.yml index b57bb592..5ed9acd7 100644 --- a/.github/workflows/build_code.yml +++ b/.github/workflows/build_code.yml @@ -32,11 +32,11 @@ jobs: - name: make standard run: make all -j6 CONNECT_TYPE=STANDARD CROSS_COMPILE=arm-linux-gnueabihf- - working-directory: ./src/raspberrypi + working-directory: ./cpp - name: make fullspec run: make all -j6 CONNECT_TYPE=FULLSPEC CROSS_COMPILE=arm-linux-gnueabihf- - working-directory: ./src/raspberrypi + working-directory: ./cpp # We need to tar the binary outputs to retain the executable # file permission. Currently, actions/upload-artifact only @@ -44,11 +44,11 @@ jobs: # This is workaround for https://github.com/actions/upload-artifact/issues/38 - name: tar binary outputs run: tar -czvf rascsi.tar.gz ./bin - working-directory: ./src/raspberrypi + working-directory: ./cpp - name: upload artifacts uses: actions/upload-artifact@v2 with: name: arm-binaries - path: ./src/raspberrypi/rascsi.tar.gz + path: ./cpp/rascsi.tar.gz diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 00b3718f..d690aa22 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-22.04 env: MAKEFLAGS: -j2 # Number of available processors - SOURCES: src/raspberrypi + SOURCES: cpp SONAR_SCANNER_VERSION: 4.7.0.2747 SONAR_SERVER_URL: "https://sonarcloud.io" BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed diff --git a/src/raspberrypi/.clang-format b/cpp/.clang-format similarity index 100% rename from src/raspberrypi/.clang-format rename to cpp/.clang-format diff --git a/src/raspberrypi/.gitignore b/cpp/.gitignore similarity index 100% rename from src/raspberrypi/.gitignore rename to cpp/.gitignore diff --git a/src/raspberrypi/.vscode/launch.json b/cpp/.vscode/launch.json similarity index 100% rename from src/raspberrypi/.vscode/launch.json rename to cpp/.vscode/launch.json diff --git a/src/raspberrypi/.vscode/settings.json b/cpp/.vscode/settings.json similarity index 100% rename from src/raspberrypi/.vscode/settings.json rename to cpp/.vscode/settings.json diff --git a/src/raspberrypi/.vscode/tasks.json b/cpp/.vscode/tasks.json similarity index 100% rename from src/raspberrypi/.vscode/tasks.json rename to cpp/.vscode/tasks.json diff --git a/src/raspberrypi/Makefile b/cpp/Makefile similarity index 98% rename from src/raspberrypi/Makefile rename to cpp/Makefile index fd90e8aa..77da468f 100644 --- a/src/raspberrypi/Makefile +++ b/cpp/Makefile @@ -65,7 +65,7 @@ RSYSLOG_LOG = /var/log/rascsi.log USR_LOCAL_BIN = /usr/local/bin MAN_PAGE_DIR = /usr/local/man/man1 -DOC_DIR = ../../doc +DOC_DIR = ../doc COVERAGE_DIR = ./coverage COVERAGE_FILE = rascsi.dat OS_FILES = ./os_integration @@ -178,7 +178,7 @@ coverage: test lcov: CXXFLAGS += --coverage lcov: test - lcov -q -c -d . --include '*/raspberrypi/*' -o $(COVERAGE_FILE) --exclude '*/test/*' --exclude '*/interfaces/*' --exclude '*/rascsi_interface.pb*' + lcov -q -c -d . --include '*/cpp/*' -o $(COVERAGE_FILE) --exclude '*/test/*' --exclude '*/interfaces/*' --exclude '*/rascsi_interface.pb*' genhtml -q -o $(COVERAGE_DIR) --legend $(COVERAGE_FILE) docs: $(DOC_DIR)/rascsi_man_page.txt $(DOC_DIR)/rasctl_man_page.txt $(DOC_DIR)/scsimon_man_page.txt diff --git a/src/raspberrypi/bus.cpp b/cpp/bus.cpp similarity index 100% rename from src/raspberrypi/bus.cpp rename to cpp/bus.cpp diff --git a/src/raspberrypi/bus.h b/cpp/bus.h similarity index 100% rename from src/raspberrypi/bus.h rename to cpp/bus.h diff --git a/src/raspberrypi/config.h b/cpp/config.h similarity index 100% rename from src/raspberrypi/config.h rename to cpp/config.h diff --git a/src/raspberrypi/controllers/abstract_controller.cpp b/cpp/controllers/abstract_controller.cpp similarity index 100% rename from src/raspberrypi/controllers/abstract_controller.cpp rename to cpp/controllers/abstract_controller.cpp diff --git a/src/raspberrypi/controllers/abstract_controller.h b/cpp/controllers/abstract_controller.h similarity index 100% rename from src/raspberrypi/controllers/abstract_controller.h rename to cpp/controllers/abstract_controller.h diff --git a/src/raspberrypi/controllers/controller_manager.cpp b/cpp/controllers/controller_manager.cpp similarity index 100% rename from src/raspberrypi/controllers/controller_manager.cpp rename to cpp/controllers/controller_manager.cpp diff --git a/src/raspberrypi/controllers/controller_manager.h b/cpp/controllers/controller_manager.h similarity index 100% rename from src/raspberrypi/controllers/controller_manager.h rename to cpp/controllers/controller_manager.h diff --git a/src/raspberrypi/controllers/phase_handler.h b/cpp/controllers/phase_handler.h similarity index 100% rename from src/raspberrypi/controllers/phase_handler.h rename to cpp/controllers/phase_handler.h diff --git a/src/raspberrypi/controllers/scsi_controller.cpp b/cpp/controllers/scsi_controller.cpp similarity index 100% rename from src/raspberrypi/controllers/scsi_controller.cpp rename to cpp/controllers/scsi_controller.cpp diff --git a/src/raspberrypi/controllers/scsi_controller.h b/cpp/controllers/scsi_controller.h similarity index 100% rename from src/raspberrypi/controllers/scsi_controller.h rename to cpp/controllers/scsi_controller.h diff --git a/src/raspberrypi/devices/cd_track.cpp b/cpp/devices/cd_track.cpp similarity index 100% rename from src/raspberrypi/devices/cd_track.cpp rename to cpp/devices/cd_track.cpp diff --git a/src/raspberrypi/devices/cd_track.h b/cpp/devices/cd_track.h similarity index 100% rename from src/raspberrypi/devices/cd_track.h rename to cpp/devices/cd_track.h diff --git a/src/raspberrypi/devices/cfilesystem.cpp b/cpp/devices/cfilesystem.cpp similarity index 100% rename from src/raspberrypi/devices/cfilesystem.cpp rename to cpp/devices/cfilesystem.cpp diff --git a/src/raspberrypi/devices/cfilesystem.h b/cpp/devices/cfilesystem.h similarity index 100% rename from src/raspberrypi/devices/cfilesystem.h rename to cpp/devices/cfilesystem.h diff --git a/src/raspberrypi/devices/ctapdriver.cpp b/cpp/devices/ctapdriver.cpp similarity index 100% rename from src/raspberrypi/devices/ctapdriver.cpp rename to cpp/devices/ctapdriver.cpp diff --git a/src/raspberrypi/devices/ctapdriver.h b/cpp/devices/ctapdriver.h similarity index 100% rename from src/raspberrypi/devices/ctapdriver.h rename to cpp/devices/ctapdriver.h diff --git a/src/raspberrypi/devices/device.cpp b/cpp/devices/device.cpp similarity index 100% rename from src/raspberrypi/devices/device.cpp rename to cpp/devices/device.cpp diff --git a/src/raspberrypi/devices/device.h b/cpp/devices/device.h similarity index 100% rename from src/raspberrypi/devices/device.h rename to cpp/devices/device.h diff --git a/src/raspberrypi/devices/device_factory.cpp b/cpp/devices/device_factory.cpp similarity index 100% rename from src/raspberrypi/devices/device_factory.cpp rename to cpp/devices/device_factory.cpp diff --git a/src/raspberrypi/devices/device_factory.h b/cpp/devices/device_factory.h similarity index 100% rename from src/raspberrypi/devices/device_factory.h rename to cpp/devices/device_factory.h diff --git a/src/raspberrypi/devices/disk.cpp b/cpp/devices/disk.cpp similarity index 100% rename from src/raspberrypi/devices/disk.cpp rename to cpp/devices/disk.cpp diff --git a/src/raspberrypi/devices/disk.h b/cpp/devices/disk.h similarity index 100% rename from src/raspberrypi/devices/disk.h rename to cpp/devices/disk.h diff --git a/src/raspberrypi/devices/disk_cache.cpp b/cpp/devices/disk_cache.cpp similarity index 100% rename from src/raspberrypi/devices/disk_cache.cpp rename to cpp/devices/disk_cache.cpp diff --git a/src/raspberrypi/devices/disk_cache.h b/cpp/devices/disk_cache.h similarity index 100% rename from src/raspberrypi/devices/disk_cache.h rename to cpp/devices/disk_cache.h diff --git a/src/raspberrypi/devices/disk_track.cpp b/cpp/devices/disk_track.cpp similarity index 100% rename from src/raspberrypi/devices/disk_track.cpp rename to cpp/devices/disk_track.cpp diff --git a/src/raspberrypi/devices/disk_track.h b/cpp/devices/disk_track.h similarity index 100% rename from src/raspberrypi/devices/disk_track.h rename to cpp/devices/disk_track.h diff --git a/src/raspberrypi/devices/dispatcher.h b/cpp/devices/dispatcher.h similarity index 100% rename from src/raspberrypi/devices/dispatcher.h rename to cpp/devices/dispatcher.h diff --git a/src/raspberrypi/devices/host_services.cpp b/cpp/devices/host_services.cpp similarity index 100% rename from src/raspberrypi/devices/host_services.cpp rename to cpp/devices/host_services.cpp diff --git a/src/raspberrypi/devices/host_services.h b/cpp/devices/host_services.h similarity index 100% rename from src/raspberrypi/devices/host_services.h rename to cpp/devices/host_services.h diff --git a/src/raspberrypi/devices/interfaces/scsi_block_commands.h b/cpp/devices/interfaces/scsi_block_commands.h similarity index 100% rename from src/raspberrypi/devices/interfaces/scsi_block_commands.h rename to cpp/devices/interfaces/scsi_block_commands.h diff --git a/src/raspberrypi/devices/interfaces/scsi_mmc_commands.h b/cpp/devices/interfaces/scsi_mmc_commands.h similarity index 100% rename from src/raspberrypi/devices/interfaces/scsi_mmc_commands.h rename to cpp/devices/interfaces/scsi_mmc_commands.h diff --git a/src/raspberrypi/devices/interfaces/scsi_primary_commands.h b/cpp/devices/interfaces/scsi_primary_commands.h similarity index 100% rename from src/raspberrypi/devices/interfaces/scsi_primary_commands.h rename to cpp/devices/interfaces/scsi_primary_commands.h diff --git a/src/raspberrypi/devices/interfaces/scsi_printer_commands.h b/cpp/devices/interfaces/scsi_printer_commands.h similarity index 100% rename from src/raspberrypi/devices/interfaces/scsi_printer_commands.h rename to cpp/devices/interfaces/scsi_printer_commands.h diff --git a/src/raspberrypi/devices/mode_page_device.cpp b/cpp/devices/mode_page_device.cpp similarity index 100% rename from src/raspberrypi/devices/mode_page_device.cpp rename to cpp/devices/mode_page_device.cpp diff --git a/src/raspberrypi/devices/mode_page_device.h b/cpp/devices/mode_page_device.h similarity index 100% rename from src/raspberrypi/devices/mode_page_device.h rename to cpp/devices/mode_page_device.h diff --git a/src/raspberrypi/devices/primary_device.cpp b/cpp/devices/primary_device.cpp similarity index 100% rename from src/raspberrypi/devices/primary_device.cpp rename to cpp/devices/primary_device.cpp diff --git a/src/raspberrypi/devices/primary_device.h b/cpp/devices/primary_device.h similarity index 100% rename from src/raspberrypi/devices/primary_device.h rename to cpp/devices/primary_device.h diff --git a/src/raspberrypi/devices/scsi_command_util.cpp b/cpp/devices/scsi_command_util.cpp similarity index 100% rename from src/raspberrypi/devices/scsi_command_util.cpp rename to cpp/devices/scsi_command_util.cpp diff --git a/src/raspberrypi/devices/scsi_command_util.h b/cpp/devices/scsi_command_util.h similarity index 100% rename from src/raspberrypi/devices/scsi_command_util.h rename to cpp/devices/scsi_command_util.h diff --git a/src/raspberrypi/devices/scsi_daynaport.cpp b/cpp/devices/scsi_daynaport.cpp similarity index 100% rename from src/raspberrypi/devices/scsi_daynaport.cpp rename to cpp/devices/scsi_daynaport.cpp diff --git a/src/raspberrypi/devices/scsi_daynaport.h b/cpp/devices/scsi_daynaport.h similarity index 100% rename from src/raspberrypi/devices/scsi_daynaport.h rename to cpp/devices/scsi_daynaport.h diff --git a/src/raspberrypi/devices/scsi_host_bridge.cpp b/cpp/devices/scsi_host_bridge.cpp similarity index 100% rename from src/raspberrypi/devices/scsi_host_bridge.cpp rename to cpp/devices/scsi_host_bridge.cpp diff --git a/src/raspberrypi/devices/scsi_host_bridge.h b/cpp/devices/scsi_host_bridge.h similarity index 100% rename from src/raspberrypi/devices/scsi_host_bridge.h rename to cpp/devices/scsi_host_bridge.h diff --git a/src/raspberrypi/devices/scsi_printer.cpp b/cpp/devices/scsi_printer.cpp similarity index 100% rename from src/raspberrypi/devices/scsi_printer.cpp rename to cpp/devices/scsi_printer.cpp diff --git a/src/raspberrypi/devices/scsi_printer.h b/cpp/devices/scsi_printer.h similarity index 100% rename from src/raspberrypi/devices/scsi_printer.h rename to cpp/devices/scsi_printer.h diff --git a/src/raspberrypi/devices/scsicd.cpp b/cpp/devices/scsicd.cpp similarity index 100% rename from src/raspberrypi/devices/scsicd.cpp rename to cpp/devices/scsicd.cpp diff --git a/src/raspberrypi/devices/scsicd.h b/cpp/devices/scsicd.h similarity index 100% rename from src/raspberrypi/devices/scsicd.h rename to cpp/devices/scsicd.h diff --git a/src/raspberrypi/devices/scsihd.cpp b/cpp/devices/scsihd.cpp similarity index 100% rename from src/raspberrypi/devices/scsihd.cpp rename to cpp/devices/scsihd.cpp diff --git a/src/raspberrypi/devices/scsihd.h b/cpp/devices/scsihd.h similarity index 100% rename from src/raspberrypi/devices/scsihd.h rename to cpp/devices/scsihd.h diff --git a/src/raspberrypi/devices/scsihd_nec.cpp b/cpp/devices/scsihd_nec.cpp similarity index 100% rename from src/raspberrypi/devices/scsihd_nec.cpp rename to cpp/devices/scsihd_nec.cpp diff --git a/src/raspberrypi/devices/scsihd_nec.h b/cpp/devices/scsihd_nec.h similarity index 100% rename from src/raspberrypi/devices/scsihd_nec.h rename to cpp/devices/scsihd_nec.h diff --git a/src/raspberrypi/devices/scsimo.cpp b/cpp/devices/scsimo.cpp similarity index 100% rename from src/raspberrypi/devices/scsimo.cpp rename to cpp/devices/scsimo.cpp diff --git a/src/raspberrypi/devices/scsimo.h b/cpp/devices/scsimo.h similarity index 100% rename from src/raspberrypi/devices/scsimo.h rename to cpp/devices/scsimo.h diff --git a/src/raspberrypi/devices/storage_device.cpp b/cpp/devices/storage_device.cpp similarity index 100% rename from src/raspberrypi/devices/storage_device.cpp rename to cpp/devices/storage_device.cpp diff --git a/src/raspberrypi/devices/storage_device.h b/cpp/devices/storage_device.h similarity index 100% rename from src/raspberrypi/devices/storage_device.h rename to cpp/devices/storage_device.h diff --git a/src/raspberrypi/hal/gpiobus.cpp b/cpp/hal/gpiobus.cpp similarity index 100% rename from src/raspberrypi/hal/gpiobus.cpp rename to cpp/hal/gpiobus.cpp diff --git a/src/raspberrypi/hal/gpiobus.h b/cpp/hal/gpiobus.h similarity index 100% rename from src/raspberrypi/hal/gpiobus.h rename to cpp/hal/gpiobus.h diff --git a/src/raspberrypi/hal/gpiobus_aibom.h b/cpp/hal/gpiobus_aibom.h similarity index 100% rename from src/raspberrypi/hal/gpiobus_aibom.h rename to cpp/hal/gpiobus_aibom.h diff --git a/src/raspberrypi/hal/gpiobus_allwinner.cpp b/cpp/hal/gpiobus_allwinner.cpp similarity index 100% rename from src/raspberrypi/hal/gpiobus_allwinner.cpp rename to cpp/hal/gpiobus_allwinner.cpp diff --git a/src/raspberrypi/hal/gpiobus_allwinner.h b/cpp/hal/gpiobus_allwinner.h similarity index 100% rename from src/raspberrypi/hal/gpiobus_allwinner.h rename to cpp/hal/gpiobus_allwinner.h diff --git a/src/raspberrypi/hal/gpiobus_factory.cpp b/cpp/hal/gpiobus_factory.cpp similarity index 100% rename from src/raspberrypi/hal/gpiobus_factory.cpp rename to cpp/hal/gpiobus_factory.cpp diff --git a/src/raspberrypi/hal/gpiobus_factory.h b/cpp/hal/gpiobus_factory.h similarity index 100% rename from src/raspberrypi/hal/gpiobus_factory.h rename to cpp/hal/gpiobus_factory.h diff --git a/src/raspberrypi/hal/gpiobus_fullspec.h b/cpp/hal/gpiobus_fullspec.h similarity index 100% rename from src/raspberrypi/hal/gpiobus_fullspec.h rename to cpp/hal/gpiobus_fullspec.h diff --git a/src/raspberrypi/hal/gpiobus_gamernium.h b/cpp/hal/gpiobus_gamernium.h similarity index 100% rename from src/raspberrypi/hal/gpiobus_gamernium.h rename to cpp/hal/gpiobus_gamernium.h diff --git a/src/raspberrypi/hal/gpiobus_raspberry.cpp b/cpp/hal/gpiobus_raspberry.cpp similarity index 100% rename from src/raspberrypi/hal/gpiobus_raspberry.cpp rename to cpp/hal/gpiobus_raspberry.cpp diff --git a/src/raspberrypi/hal/gpiobus_raspberry.h b/cpp/hal/gpiobus_raspberry.h similarity index 100% rename from src/raspberrypi/hal/gpiobus_raspberry.h rename to cpp/hal/gpiobus_raspberry.h diff --git a/src/raspberrypi/hal/gpiobus_standard.h b/cpp/hal/gpiobus_standard.h similarity index 100% rename from src/raspberrypi/hal/gpiobus_standard.h rename to cpp/hal/gpiobus_standard.h diff --git a/src/raspberrypi/hal/sbc_version.cpp b/cpp/hal/sbc_version.cpp similarity index 100% rename from src/raspberrypi/hal/sbc_version.cpp rename to cpp/hal/sbc_version.cpp diff --git a/src/raspberrypi/hal/sbc_version.h b/cpp/hal/sbc_version.h similarity index 100% rename from src/raspberrypi/hal/sbc_version.h rename to cpp/hal/sbc_version.h diff --git a/src/raspberrypi/hal/systimer.cpp b/cpp/hal/systimer.cpp similarity index 100% rename from src/raspberrypi/hal/systimer.cpp rename to cpp/hal/systimer.cpp diff --git a/src/raspberrypi/hal/systimer.h b/cpp/hal/systimer.h similarity index 100% rename from src/raspberrypi/hal/systimer.h rename to cpp/hal/systimer.h diff --git a/src/raspberrypi/hal/systimer_allwinner.cpp b/cpp/hal/systimer_allwinner.cpp similarity index 100% rename from src/raspberrypi/hal/systimer_allwinner.cpp rename to cpp/hal/systimer_allwinner.cpp diff --git a/src/raspberrypi/hal/systimer_allwinner.h b/cpp/hal/systimer_allwinner.h similarity index 100% rename from src/raspberrypi/hal/systimer_allwinner.h rename to cpp/hal/systimer_allwinner.h diff --git a/src/raspberrypi/hal/systimer_raspberry.cpp b/cpp/hal/systimer_raspberry.cpp similarity index 100% rename from src/raspberrypi/hal/systimer_raspberry.cpp rename to cpp/hal/systimer_raspberry.cpp diff --git a/src/raspberrypi/hal/systimer_raspberry.h b/cpp/hal/systimer_raspberry.h similarity index 100% rename from src/raspberrypi/hal/systimer_raspberry.h rename to cpp/hal/systimer_raspberry.h diff --git a/src/raspberrypi/launch_sudo.sh b/cpp/launch_sudo.sh similarity index 100% rename from src/raspberrypi/launch_sudo.sh rename to cpp/launch_sudo.sh diff --git a/src/raspberrypi/log.h b/cpp/log.h similarity index 100% rename from src/raspberrypi/log.h rename to cpp/log.h diff --git a/src/raspberrypi/monitor/data_sample.cpp b/cpp/monitor/data_sample.cpp similarity index 100% rename from src/raspberrypi/monitor/data_sample.cpp rename to cpp/monitor/data_sample.cpp diff --git a/src/raspberrypi/monitor/data_sample.h b/cpp/monitor/data_sample.h similarity index 100% rename from src/raspberrypi/monitor/data_sample.h rename to cpp/monitor/data_sample.h diff --git a/src/raspberrypi/monitor/sm_html_report.cpp b/cpp/monitor/sm_html_report.cpp similarity index 100% rename from src/raspberrypi/monitor/sm_html_report.cpp rename to cpp/monitor/sm_html_report.cpp diff --git a/src/raspberrypi/monitor/sm_json_report.cpp b/cpp/monitor/sm_json_report.cpp similarity index 100% rename from src/raspberrypi/monitor/sm_json_report.cpp rename to cpp/monitor/sm_json_report.cpp diff --git a/src/raspberrypi/monitor/sm_reports.h b/cpp/monitor/sm_reports.h similarity index 100% rename from src/raspberrypi/monitor/sm_reports.h rename to cpp/monitor/sm_reports.h diff --git a/src/raspberrypi/monitor/sm_vcd_report.cpp b/cpp/monitor/sm_vcd_report.cpp similarity index 100% rename from src/raspberrypi/monitor/sm_vcd_report.cpp rename to cpp/monitor/sm_vcd_report.cpp diff --git a/src/raspberrypi/os.h b/cpp/os.h similarity index 100% rename from src/raspberrypi/os.h rename to cpp/os.h diff --git a/src/raspberrypi/os_integration/dhcpcd.conf.patch b/cpp/os_integration/dhcpcd.conf.patch similarity index 100% rename from src/raspberrypi/os_integration/dhcpcd.conf.patch rename to cpp/os_integration/dhcpcd.conf.patch diff --git a/src/raspberrypi/os_integration/rascsi.conf b/cpp/os_integration/rascsi.conf similarity index 100% rename from src/raspberrypi/os_integration/rascsi.conf rename to cpp/os_integration/rascsi.conf diff --git a/src/raspberrypi/os_integration/rascsi.service b/cpp/os_integration/rascsi.service similarity index 100% rename from src/raspberrypi/os_integration/rascsi.service rename to cpp/os_integration/rascsi.service diff --git a/src/raspberrypi/os_integration/rascsi_bridge b/cpp/os_integration/rascsi_bridge similarity index 100% rename from src/raspberrypi/os_integration/rascsi_bridge rename to cpp/os_integration/rascsi_bridge diff --git a/src/raspberrypi/protobuf_serializer.cpp b/cpp/protobuf_serializer.cpp similarity index 100% rename from src/raspberrypi/protobuf_serializer.cpp rename to cpp/protobuf_serializer.cpp diff --git a/src/raspberrypi/protobuf_serializer.h b/cpp/protobuf_serializer.h similarity index 100% rename from src/raspberrypi/protobuf_serializer.h rename to cpp/protobuf_serializer.h diff --git a/src/raspberrypi/protobuf_util.cpp b/cpp/protobuf_util.cpp similarity index 100% rename from src/raspberrypi/protobuf_util.cpp rename to cpp/protobuf_util.cpp diff --git a/src/raspberrypi/protobuf_util.h b/cpp/protobuf_util.h similarity index 100% rename from src/raspberrypi/protobuf_util.h rename to cpp/protobuf_util.h diff --git a/src/raspberrypi/rascsi.cpp b/cpp/rascsi.cpp similarity index 100% rename from src/raspberrypi/rascsi.cpp rename to cpp/rascsi.cpp diff --git a/src/raspberrypi/rascsi/command_context.cpp b/cpp/rascsi/command_context.cpp similarity index 100% rename from src/raspberrypi/rascsi/command_context.cpp rename to cpp/rascsi/command_context.cpp diff --git a/src/raspberrypi/rascsi/command_context.h b/cpp/rascsi/command_context.h similarity index 100% rename from src/raspberrypi/rascsi/command_context.h rename to cpp/rascsi/command_context.h diff --git a/src/raspberrypi/rascsi/localizer.cpp b/cpp/rascsi/localizer.cpp similarity index 100% rename from src/raspberrypi/rascsi/localizer.cpp rename to cpp/rascsi/localizer.cpp diff --git a/src/raspberrypi/rascsi/localizer.h b/cpp/rascsi/localizer.h similarity index 100% rename from src/raspberrypi/rascsi/localizer.h rename to cpp/rascsi/localizer.h diff --git a/src/raspberrypi/rascsi/rascsi_executor.cpp b/cpp/rascsi/rascsi_executor.cpp similarity index 100% rename from src/raspberrypi/rascsi/rascsi_executor.cpp rename to cpp/rascsi/rascsi_executor.cpp diff --git a/src/raspberrypi/rascsi/rascsi_executor.h b/cpp/rascsi/rascsi_executor.h similarity index 100% rename from src/raspberrypi/rascsi/rascsi_executor.h rename to cpp/rascsi/rascsi_executor.h diff --git a/src/raspberrypi/rascsi/rascsi_image.cpp b/cpp/rascsi/rascsi_image.cpp similarity index 100% rename from src/raspberrypi/rascsi/rascsi_image.cpp rename to cpp/rascsi/rascsi_image.cpp diff --git a/src/raspberrypi/rascsi/rascsi_image.h b/cpp/rascsi/rascsi_image.h similarity index 100% rename from src/raspberrypi/rascsi/rascsi_image.h rename to cpp/rascsi/rascsi_image.h diff --git a/src/raspberrypi/rascsi/rascsi_response.cpp b/cpp/rascsi/rascsi_response.cpp similarity index 100% rename from src/raspberrypi/rascsi/rascsi_response.cpp rename to cpp/rascsi/rascsi_response.cpp diff --git a/src/raspberrypi/rascsi/rascsi_response.h b/cpp/rascsi/rascsi_response.h similarity index 100% rename from src/raspberrypi/rascsi/rascsi_response.h rename to cpp/rascsi/rascsi_response.h diff --git a/src/raspberrypi/rascsi/rascsi_service.cpp b/cpp/rascsi/rascsi_service.cpp similarity index 100% rename from src/raspberrypi/rascsi/rascsi_service.cpp rename to cpp/rascsi/rascsi_service.cpp diff --git a/src/raspberrypi/rascsi/rascsi_service.h b/cpp/rascsi/rascsi_service.h similarity index 100% rename from src/raspberrypi/rascsi/rascsi_service.h rename to cpp/rascsi/rascsi_service.h diff --git a/src/raspberrypi/rascsi_exceptions.h b/cpp/rascsi_exceptions.h similarity index 100% rename from src/raspberrypi/rascsi_exceptions.h rename to cpp/rascsi_exceptions.h diff --git a/src/raspberrypi/rascsi_interface.proto b/cpp/rascsi_interface.proto similarity index 100% rename from src/raspberrypi/rascsi_interface.proto rename to cpp/rascsi_interface.proto diff --git a/src/raspberrypi/rascsi_version.cpp b/cpp/rascsi_version.cpp similarity index 100% rename from src/raspberrypi/rascsi_version.cpp rename to cpp/rascsi_version.cpp diff --git a/src/raspberrypi/rascsi_version.h b/cpp/rascsi_version.h similarity index 100% rename from src/raspberrypi/rascsi_version.h rename to cpp/rascsi_version.h diff --git a/src/raspberrypi/rasctl.cpp b/cpp/rasctl.cpp similarity index 100% rename from src/raspberrypi/rasctl.cpp rename to cpp/rasctl.cpp diff --git a/src/raspberrypi/rasctl/rasctl_commands.cpp b/cpp/rasctl/rasctl_commands.cpp similarity index 100% rename from src/raspberrypi/rasctl/rasctl_commands.cpp rename to cpp/rasctl/rasctl_commands.cpp diff --git a/src/raspberrypi/rasctl/rasctl_commands.h b/cpp/rasctl/rasctl_commands.h similarity index 100% rename from src/raspberrypi/rasctl/rasctl_commands.h rename to cpp/rasctl/rasctl_commands.h diff --git a/src/raspberrypi/rasctl/rasctl_display.cpp b/cpp/rasctl/rasctl_display.cpp similarity index 100% rename from src/raspberrypi/rasctl/rasctl_display.cpp rename to cpp/rasctl/rasctl_display.cpp diff --git a/src/raspberrypi/rasctl/rasctl_display.h b/cpp/rasctl/rasctl_display.h similarity index 100% rename from src/raspberrypi/rasctl/rasctl_display.h rename to cpp/rasctl/rasctl_display.h diff --git a/src/raspberrypi/rasctl/rasctl_parser.cpp b/cpp/rasctl/rasctl_parser.cpp similarity index 100% rename from src/raspberrypi/rasctl/rasctl_parser.cpp rename to cpp/rasctl/rasctl_parser.cpp diff --git a/src/raspberrypi/rasctl/rasctl_parser.h b/cpp/rasctl/rasctl_parser.h similarity index 100% rename from src/raspberrypi/rasctl/rasctl_parser.h rename to cpp/rasctl/rasctl_parser.h diff --git a/src/raspberrypi/rasdump.cpp b/cpp/rasdump.cpp similarity index 100% rename from src/raspberrypi/rasdump.cpp rename to cpp/rasdump.cpp diff --git a/src/raspberrypi/rasdump_fileio.cpp b/cpp/rasdump_fileio.cpp similarity index 100% rename from src/raspberrypi/rasdump_fileio.cpp rename to cpp/rasdump_fileio.cpp diff --git a/src/raspberrypi/rasdump_fileio.h b/cpp/rasdump_fileio.h similarity index 100% rename from src/raspberrypi/rasdump_fileio.h rename to cpp/rasdump_fileio.h diff --git a/src/raspberrypi/rasutil.cpp b/cpp/rasutil.cpp similarity index 100% rename from src/raspberrypi/rasutil.cpp rename to cpp/rasutil.cpp diff --git a/src/raspberrypi/rasutil.h b/cpp/rasutil.h similarity index 100% rename from src/raspberrypi/rasutil.h rename to cpp/rasutil.h diff --git a/src/raspberrypi/scsi.h b/cpp/scsi.h similarity index 100% rename from src/raspberrypi/scsi.h rename to cpp/scsi.h diff --git a/src/raspberrypi/scsimon.cpp b/cpp/scsimon.cpp similarity index 100% rename from src/raspberrypi/scsimon.cpp rename to cpp/scsimon.cpp diff --git a/src/raspberrypi/test/abstract_controller_test.cpp b/cpp/test/abstract_controller_test.cpp similarity index 100% rename from src/raspberrypi/test/abstract_controller_test.cpp rename to cpp/test/abstract_controller_test.cpp diff --git a/src/raspberrypi/test/bus_test.cpp b/cpp/test/bus_test.cpp similarity index 100% rename from src/raspberrypi/test/bus_test.cpp rename to cpp/test/bus_test.cpp diff --git a/src/raspberrypi/test/command_context_test.cpp b/cpp/test/command_context_test.cpp similarity index 100% rename from src/raspberrypi/test/command_context_test.cpp rename to cpp/test/command_context_test.cpp diff --git a/src/raspberrypi/test/controller_manager_test.cpp b/cpp/test/controller_manager_test.cpp similarity index 100% rename from src/raspberrypi/test/controller_manager_test.cpp rename to cpp/test/controller_manager_test.cpp diff --git a/src/raspberrypi/test/ctapdriver_test.cpp b/cpp/test/ctapdriver_test.cpp similarity index 100% rename from src/raspberrypi/test/ctapdriver_test.cpp rename to cpp/test/ctapdriver_test.cpp diff --git a/src/raspberrypi/test/device_factory_test.cpp b/cpp/test/device_factory_test.cpp similarity index 100% rename from src/raspberrypi/test/device_factory_test.cpp rename to cpp/test/device_factory_test.cpp diff --git a/src/raspberrypi/test/device_test.cpp b/cpp/test/device_test.cpp similarity index 100% rename from src/raspberrypi/test/device_test.cpp rename to cpp/test/device_test.cpp diff --git a/src/raspberrypi/test/disk_test.cpp b/cpp/test/disk_test.cpp similarity index 100% rename from src/raspberrypi/test/disk_test.cpp rename to cpp/test/disk_test.cpp diff --git a/src/raspberrypi/test/gpiobus_test.cpp b/cpp/test/gpiobus_test.cpp similarity index 100% rename from src/raspberrypi/test/gpiobus_test.cpp rename to cpp/test/gpiobus_test.cpp diff --git a/src/raspberrypi/test/host_services_test.cpp b/cpp/test/host_services_test.cpp similarity index 100% rename from src/raspberrypi/test/host_services_test.cpp rename to cpp/test/host_services_test.cpp diff --git a/src/raspberrypi/test/localizer_test.cpp b/cpp/test/localizer_test.cpp similarity index 100% rename from src/raspberrypi/test/localizer_test.cpp rename to cpp/test/localizer_test.cpp diff --git a/src/raspberrypi/test/mocks.h b/cpp/test/mocks.h similarity index 100% rename from src/raspberrypi/test/mocks.h rename to cpp/test/mocks.h diff --git a/src/raspberrypi/test/mode_page_device_test.cpp b/cpp/test/mode_page_device_test.cpp similarity index 100% rename from src/raspberrypi/test/mode_page_device_test.cpp rename to cpp/test/mode_page_device_test.cpp diff --git a/src/raspberrypi/test/phase_handler_test.cpp b/cpp/test/phase_handler_test.cpp similarity index 100% rename from src/raspberrypi/test/phase_handler_test.cpp rename to cpp/test/phase_handler_test.cpp diff --git a/src/raspberrypi/test/primary_device_test.cpp b/cpp/test/primary_device_test.cpp similarity index 100% rename from src/raspberrypi/test/primary_device_test.cpp rename to cpp/test/primary_device_test.cpp diff --git a/src/raspberrypi/test/protobuf_serializer_test.cpp b/cpp/test/protobuf_serializer_test.cpp similarity index 100% rename from src/raspberrypi/test/protobuf_serializer_test.cpp rename to cpp/test/protobuf_serializer_test.cpp diff --git a/src/raspberrypi/test/protobuf_util_test.cpp b/cpp/test/protobuf_util_test.cpp similarity index 100% rename from src/raspberrypi/test/protobuf_util_test.cpp rename to cpp/test/protobuf_util_test.cpp diff --git a/src/raspberrypi/test/rascsi_exceptions_test.cpp b/cpp/test/rascsi_exceptions_test.cpp similarity index 100% rename from src/raspberrypi/test/rascsi_exceptions_test.cpp rename to cpp/test/rascsi_exceptions_test.cpp diff --git a/src/raspberrypi/test/rascsi_executor_test.cpp b/cpp/test/rascsi_executor_test.cpp similarity index 100% rename from src/raspberrypi/test/rascsi_executor_test.cpp rename to cpp/test/rascsi_executor_test.cpp diff --git a/src/raspberrypi/test/rascsi_image_test.cpp b/cpp/test/rascsi_image_test.cpp similarity index 100% rename from src/raspberrypi/test/rascsi_image_test.cpp rename to cpp/test/rascsi_image_test.cpp diff --git a/src/raspberrypi/test/rascsi_response_test.cpp b/cpp/test/rascsi_response_test.cpp similarity index 100% rename from src/raspberrypi/test/rascsi_response_test.cpp rename to cpp/test/rascsi_response_test.cpp diff --git a/src/raspberrypi/test/rascsi_service_test.cpp b/cpp/test/rascsi_service_test.cpp similarity index 100% rename from src/raspberrypi/test/rascsi_service_test.cpp rename to cpp/test/rascsi_service_test.cpp diff --git a/src/raspberrypi/test/rasctl_commands_test.cpp b/cpp/test/rasctl_commands_test.cpp similarity index 100% rename from src/raspberrypi/test/rasctl_commands_test.cpp rename to cpp/test/rasctl_commands_test.cpp diff --git a/src/raspberrypi/test/rasctl_display_test.cpp b/cpp/test/rasctl_display_test.cpp similarity index 100% rename from src/raspberrypi/test/rasctl_display_test.cpp rename to cpp/test/rasctl_display_test.cpp diff --git a/src/raspberrypi/test/rasctl_parser_test.cpp b/cpp/test/rasctl_parser_test.cpp similarity index 100% rename from src/raspberrypi/test/rasctl_parser_test.cpp rename to cpp/test/rasctl_parser_test.cpp diff --git a/src/raspberrypi/test/rasutil_test.cpp b/cpp/test/rasutil_test.cpp similarity index 100% rename from src/raspberrypi/test/rasutil_test.cpp rename to cpp/test/rasutil_test.cpp diff --git a/src/raspberrypi/test/scsi_command_util_test.cpp b/cpp/test/scsi_command_util_test.cpp similarity index 100% rename from src/raspberrypi/test/scsi_command_util_test.cpp rename to cpp/test/scsi_command_util_test.cpp diff --git a/src/raspberrypi/test/scsi_controller_test.cpp b/cpp/test/scsi_controller_test.cpp similarity index 100% rename from src/raspberrypi/test/scsi_controller_test.cpp rename to cpp/test/scsi_controller_test.cpp diff --git a/src/raspberrypi/test/scsi_daynaport_test.cpp b/cpp/test/scsi_daynaport_test.cpp similarity index 100% rename from src/raspberrypi/test/scsi_daynaport_test.cpp rename to cpp/test/scsi_daynaport_test.cpp diff --git a/src/raspberrypi/test/scsi_host_bridge_test.cpp b/cpp/test/scsi_host_bridge_test.cpp similarity index 100% rename from src/raspberrypi/test/scsi_host_bridge_test.cpp rename to cpp/test/scsi_host_bridge_test.cpp diff --git a/src/raspberrypi/test/scsi_printer_test.cpp b/cpp/test/scsi_printer_test.cpp similarity index 100% rename from src/raspberrypi/test/scsi_printer_test.cpp rename to cpp/test/scsi_printer_test.cpp diff --git a/src/raspberrypi/test/scsicd_test.cpp b/cpp/test/scsicd_test.cpp similarity index 100% rename from src/raspberrypi/test/scsicd_test.cpp rename to cpp/test/scsicd_test.cpp diff --git a/src/raspberrypi/test/scsihd_nec_test.cpp b/cpp/test/scsihd_nec_test.cpp similarity index 100% rename from src/raspberrypi/test/scsihd_nec_test.cpp rename to cpp/test/scsihd_nec_test.cpp diff --git a/src/raspberrypi/test/scsihd_test.cpp b/cpp/test/scsihd_test.cpp similarity index 100% rename from src/raspberrypi/test/scsihd_test.cpp rename to cpp/test/scsihd_test.cpp diff --git a/src/raspberrypi/test/scsimo_test.cpp b/cpp/test/scsimo_test.cpp similarity index 100% rename from src/raspberrypi/test/scsimo_test.cpp rename to cpp/test/scsimo_test.cpp diff --git a/src/raspberrypi/test/storage_device_test.cpp b/cpp/test/storage_device_test.cpp similarity index 100% rename from src/raspberrypi/test/storage_device_test.cpp rename to cpp/test/storage_device_test.cpp diff --git a/src/raspberrypi/test/test_setup.cpp b/cpp/test/test_setup.cpp similarity index 100% rename from src/raspberrypi/test/test_setup.cpp rename to cpp/test/test_setup.cpp diff --git a/src/raspberrypi/test/test_shared.cpp b/cpp/test/test_shared.cpp similarity index 100% rename from src/raspberrypi/test/test_shared.cpp rename to cpp/test/test_shared.cpp diff --git a/src/raspberrypi/test/test_shared.h b/cpp/test/test_shared.h similarity index 100% rename from src/raspberrypi/test/test_shared.h rename to cpp/test/test_shared.h diff --git a/easyinstall.sh b/easyinstall.sh index e12324d9..b352ccbb 100755 --- a/easyinstall.sh +++ b/easyinstall.sh @@ -48,6 +48,7 @@ echo -e $logo USER=$(whoami) BASE=$(dirname "$(readlink -f "${0}")") +CPP_PATH="$BASE/cpp" VIRTUAL_DRIVER_PATH="$HOME/images" CFG_PATH="$HOME/.config/rascsi" WEB_INSTALL_PATH="$BASE/python/web" @@ -132,7 +133,7 @@ function cachePipPackages(){ # compile the RaSCSI binaries function compileRaScsi() { - cd "$BASE/src/raspberrypi" || exit 1 + cd "$CPP_PATH" || exit 1 echo "Compiling with ${CORES:-1} simultaneous cores..." make clean /etc/network/interfaces.d/rascsi_bridge' + sudo bash -c 'sed s/eth0/'"$LAN_INTERFACE"'/g '"$CPP_PATH"'/os_integration/rascsi_bridge > /etc/network/interfaces.d/rascsi_bridge' echo "Modified /etc/network/interfaces.d/rascsi_bridge" echo "Configuration completed!" diff --git a/src/x68k/RASCTL/Makefile b/src/x68k/RASCTL/Makefile deleted file mode 100644 index b10bd182..00000000 --- a/src/x68k/RASCTL/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Makefile for RASCTL.X -# - -CC = gcc -O2 -Wall -LK = hlk -l -x - -RASCTL.X : RASCTL.o - $(LK) -o $@ $^ libc.a libiocs.a libscsi.a libgnu.a - -RASCTL.o : RASCTL.C - $(CC) -c -o $@ $^ - \ No newline at end of file diff --git a/src/x68k/RASCTL/RASCTL.C b/src/x68k/RASCTL/RASCTL.C deleted file mode 100644 index c711683f..00000000 --- a/src/x68k/RASCTL/RASCTL.C +++ /dev/null @@ -1,433 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator RaSCSI (*^..^*) -// for Raspberry Pi -// Powered by XM6 TypeG Technology. -// -// Copyright (C) 2016-2021 GIMONS(Twitter:@kugimoto0715) -// -// [ Sending commands ] -// -//--------------------------------------------------------------------------- - -#include -#include -#include -#include -#include -#include -#include - -//--------------------------------------------------------------------------- -// -// Primitive definitions -// -//--------------------------------------------------------------------------- -typedef unsigned int UINT; -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned long DWORD; -typedef unsigned long long UL64; -typedef int BOOL; -typedef char TCHAR; -typedef char *LPTSTR; -typedef const char *LPCTSTR; -typedef const char *LPCSTR; - -#if !defined(FALSE) -#define FALSE 0 -#endif - -#if !defined(TRUE) -#define TRUE 1 -#endif - -//--------------------------------------------------------------------------- -// -// Constant definitions -// -//--------------------------------------------------------------------------- -#define ENOTCONN 107 - -//--------------------------------------------------------------------------- -// -// Struct definitions -// -//--------------------------------------------------------------------------- -typedef struct -{ - char DeviceType; - char RMB; - char ANSI_Ver; - char RDF; - char AddLen; - char RESV0; - char RESV1; - char OptFunc; - char VendorID[8]; - char ProductID[16]; - char FirmRev[4]; -} INQUIRY_T; - -typedef struct -{ - INQUIRY_T info; - char options[8]; -} INQUIRYOPT_T; - -//--------------------------------------------------------------------------- -// -// Global variables -// -//--------------------------------------------------------------------------- -int scsiid = -1; - -//--------------------------------------------------------------------------- -// -// Search for bridge device -// -//--------------------------------------------------------------------------- -BOOL SearchRaSCSI() -{ - int i; - INQUIRYOPT_T inq; - - for (i = 7; i >= 0; i--) { - // Search for bridge device - if (S_INQUIRY(sizeof(INQUIRY_T) , i, (struct INQUIRY*)&inq) < 0) { - continue; - } - - if (memcmp(&(inq.info.ProductID), "RASCSI BRIDGE", 13) != 0) { - continue; - } - - // Check if option functions are initialized - if (S_INQUIRY(sizeof(INQUIRYOPT_T) , i, (struct INQUIRY*)&inq) < 0) { - continue; - } - - if (inq.options[0] != '1') { - continue; - } - - // Confirm SCSI ID - scsiid = i; - return TRUE; - } - - return FALSE; -} - -//--------------------------------------------------------------------------- -// -// Get messages -// -//--------------------------------------------------------------------------- -BOOL ScsiGetMessage(BYTE *buf) -{ - unsigned char cmd[10]; - unsigned char sts; - unsigned char msg; - - if (S_SELECT(scsiid) != 0) { - return FALSE; - } - - cmd[0] = 0x28; - cmd[1] = 0; - cmd[2] = 0; - cmd[3] = 0; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[7] = 0x04; - cmd[8] = 0; - cmd[9] = 0; - if (S_CMDOUT(10, cmd) != 0) { - return FALSE; - } - - if (S_DATAIN_P(1024, buf) != 0) { - return FALSE; - } - - S_STSIN(&sts); - S_MSGIN(&msg); - - return TRUE; -} - -//--------------------------------------------------------------------------- -// -// Send messages -// -//--------------------------------------------------------------------------- -BOOL ScsiSendMessage(BYTE *buf) -{ - unsigned char cmd[10]; - unsigned char sts; - unsigned char msg; - - if (S_SELECT(scsiid) != 0) { - return FALSE; - } - - cmd[0] = 0x2a; - cmd[1] = 0; - cmd[2] = 0; - cmd[3] = 0; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[7] = 0x04; - cmd[8] = 0; - cmd[9] = 0; - if (S_CMDOUT(10, cmd) != 0) { - return FALSE; - } - - S_DATAOUT_P(1024, buf); - - S_STSIN(&sts); - S_MSGIN(&msg); - - return TRUE; -} - -//--------------------------------------------------------------------------- -// -// Send commands -// -//--------------------------------------------------------------------------- -BOOL SendCommand(char *buf) -{ - BYTE message[1024]; - - memset(message, 0x00, 1024); - memcpy(message, buf, strlen(buf)); - - if (ScsiSendMessage(message)) { - memset(message, 0x00, 1024); - if (ScsiGetMessage(message)) { - printf("%s", (char*)message); - return TRUE; - } - } - - return FALSE; -} - -//--------------------------------------------------------------------------- -// -// Main process -// -//--------------------------------------------------------------------------- -void main(int argc, char* argv[]) -{ - int opt; - int id; - int un; - int cmd; - int type; - char *file; - int len; - char *ext; - char buf[BUFSIZ]; - - id = -1; - un = 0; - cmd = -1; - type = -1; - file = NULL; - - // Display help - if (argc < 2) { - fprintf(stderr, "SCSI Target Emulator RaSCSI Controller\n"); - fprintf(stderr, - "Usage: %s -i ID [-u UNIT] [-c CMD] [-t TYPE] [-f FILE]\n", - argv[0]); - fprintf(stderr, " where ID := {0|1|2|3|4|5|6|7}\n"); - fprintf(stderr, " UNIT := {0|1} default setting is 0.\n"); - fprintf(stderr, " CMD := {attach|detach|insert|eject|protect}\n"); - fprintf(stderr, " TYPE := {hd|mo|cd|bridge}\n"); - fprintf(stderr, " FILE := image file path\n"); - fprintf(stderr, " CMD is 'attach' or 'insert' and FILE parameter is required.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Usage: %s -l\n\n", argv[0]); - fprintf(stderr, " Print device list.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Usage: %s --stop\n\n", argv[0]); - fprintf(stderr, " Stop rascsi prosess.\n"); - fprintf(stderr, "\n"); - fprintf(stderr, "Usage: %s --shutdown\n\n", argv[0]); - fprintf(stderr, " Shutdown raspberry pi.\n"); - exit(0); - } - - // Look for bridge device - if (!SearchRaSCSI()) { - fprintf(stderr, "Error: bridge not found\n"); - exit(ENOTCONN); - } - - // Argument parsing - opterr = 0; - while ((opt = getopt(argc, argv, "i:u:c:t:f:l-:")) != -1) { - switch (opt) { - case 'i': - id = optarg[0] - '0'; - break; - - case 'u': - un = optarg[0] - '0'; - break; - - case 'c': - switch (optarg[0]) { - case 'a': // ATTACH - case 'A': - cmd = 0; - break; - case 'd': // DETACH - case 'D': - cmd = 1; - break; - case 'i': // INSERT - case 'I': - cmd = 2; - break; - case 'e': // EJECT - case 'E': - cmd = 3; - break; - case 'p': // PROTECT - case 'P': - cmd = 4; - break; - } - break; - - case 't': - switch (optarg[0]) { - case 's': // HD(SASI) - case 'S': - case 'h': // HD(SCSI) - case 'H': - type = 0; - break; - case 'm': // MO - case 'M': - type = 2; - break; - case 'c': // CD - case 'C': - type = 3; - break; - case 'b': // BRIDGE - case 'B': - type = 4; - break; - } - break; - - case 'f': - file = optarg; - break; - - case 'l': - sprintf(buf, "list\n"); - SendCommand(buf); - exit(0); - - case '-': - if (strcmp(optarg, "shutdown") == 0) { - sprintf(buf, "shutdown\n"); - SendCommand(buf); - exit(0); - } else if (strcmp(optarg, "stop") == 0) { - sprintf(buf, "stop\n"); - SendCommand(buf); - exit(0); - } - break; - } - } - - // ID check - if (id < 0 || id > 7) { - fprintf(stderr, "Error : Invalid ID\n"); - exit(EINVAL); - } - - // Unit check - if (un < 0 || un > 1) { - fprintf(stderr, "Error : Invalid UNIT\n"); - exit(EINVAL); - } - - // Command check - if (cmd < 0) { - cmd = 0; // The default is 'attach' - } - - // Type check - if (cmd == 0 && type < 0) { - - // Attempt type detection from extension - len = file ? strlen(file) : 0; - if (len > 4 && file[len - 4] == '.') { - ext = &file[len - 3]; - if (strcasecmp(ext, "hdf") == 0 || - strcasecmp(ext, "hds") == 0 || - strcasecmp(ext, "hdn") == 0 || - strcasecmp(ext, "hdi") == 0 || - strcasecmp(ext, "nhd") == 0 || - strcasecmp(ext, "hda") == 0) { - // HD(SASI/SCSI) - type = 0; - } else if (strcasecmp(ext, "mos") == 0) { - // MO - type = 2; - } else if (strcasecmp(ext, "iso") == 0) { - // CD - type = 3; - } - } - - if (type < 0) { - fprintf(stderr, "Error : Invalid type\n"); - exit(EINVAL); - } - } - - // File check (the command is 'attach' with type HD) - if (cmd == 0 && type >= 0 && type <= 1) { - if (!file) { - fprintf(stderr, "Error : Invalid file path\n"); - exit(EINVAL); - } - } - - // File check (the command is 'insert') - if (cmd == 2) { - if (!file) { - fprintf(stderr, "Error : Invalid file path\n"); - exit(EINVAL); - } - } - - // Useless types are set to 0 - if (type < 0) { - type = 0; - } - - // Create command to send - sprintf(buf, "%d %d %d %d %s\n", id, un, cmd, type, file ? file : "-"); - if (!SendCommand(buf)) { - exit(ENOTCONN); - } - - // Quit - exit(0); -} diff --git a/src/x68k/RASDRV/BRIDGE.C b/src/x68k/RASDRV/BRIDGE.C deleted file mode 100644 index c9c85e71..00000000 --- a/src/x68k/RASDRV/BRIDGE.C +++ /dev/null @@ -1,2430 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator RaSCSI (*^..^*) -// for Raspberry Pi -// -// Powered by XM6 TypeG Technology. -// Copyright (C) 2016-2017 GIMONS -// [ Host Filesystem Bridge Driver ] -// -//--------------------------------------------------------------------------- - -#include -#include -#include -#include -#include -#include "bridge.h" - -//--------------------------------------------------------------------------- -// -// Variable definitions -// -//--------------------------------------------------------------------------- -volatile BYTE *request; // Request header address -DWORD command; // Command number -DWORD unit; // Unit number - -//=========================================================================== -// -/// File system (SCSI integration) -// -//=========================================================================== -typedef struct -{ - char DeviceType; - char RMB; - char ANSI_Ver; - char RDF; - char AddLen; - char RESV0; - char RESV1; - char OptFunc; - char VendorID[8]; - char ProductID[16]; - char FirmRev[4]; -} INQUIRY_T; - -int scsiid; // SCSI ID - -//--------------------------------------------------------------------------- -// -// Initialize -// -//--------------------------------------------------------------------------- -BOOL SCSI_Init(void) -{ - int i; - INQUIRY_T inq; - - // SCSI ID not set - scsiid = -1; - - for (i = 0; i <= 7; i++) { - if (S_INQUIRY(sizeof(INQUIRY_T) , i, (struct INQUIRY*)&inq) < 0) { - continue; - } - - if (memcmp(&(inq.ProductID), "RASCSI BRIDGE", 13) != 0) { - continue; - } - - // SCSI ID set - scsiid = i; - return TRUE; - } - - return FALSE; -} - -//--------------------------------------------------------------------------- -// -// Send commands -// -//--------------------------------------------------------------------------- -int SCSI_SendCmd(BYTE *buf, int len) -{ - int ret; - BYTE cmdbuf[10]; - BYTE sts; - BYTE msg; - BYTE retbuf[4]; - - ret = FS_FATAL_MEDIAOFFLINE; - - cmdbuf[0] = 0x2a; - cmdbuf[1] = 0; - cmdbuf[2] = 2; - cmdbuf[3] = command; - cmdbuf[4] = 0; - cmdbuf[5] = 0; - cmdbuf[6] = (BYTE)(len >> 16); - cmdbuf[7] = (BYTE)(len >> 8); - cmdbuf[8] = (BYTE)len; - cmdbuf[9] = 0; - - // Retry when select times out - if (S_SELECT(scsiid) != 0) { - S_RESET(); - if (S_SELECT(scsiid) != 0) { - return ret; - } - } - - if (S_CMDOUT(10, cmdbuf) != 0) { - return ret; - } - - if (S_DATAOUT_P(len, buf) != 0) { - return ret; - } - - if (S_STSIN(&sts) != 0) { - return ret; - } - - if (S_MSGIN(&msg) != 0) { - return ret; - } - - cmdbuf[0] = 0x28; - cmdbuf[1] = 0; - cmdbuf[2] = 2; - cmdbuf[3] = command; - cmdbuf[4] = 0; - cmdbuf[5] = 0; - cmdbuf[6] = 0; - cmdbuf[7] = 0; - cmdbuf[8] = 4; - cmdbuf[9] = 0; - - // Retry when select times out - if (S_SELECT(scsiid) != 0) { - S_RESET(); - if (S_SELECT(scsiid) != 0) { - return ret; - } - } - - if (S_CMDOUT(10, cmdbuf) != 0) { - return ret; - } - - if (S_DATAIN_P(4, retbuf) != 0) { - return ret; - } - - if (S_STSIN(&sts) != 0) { - return ret; - } - - if (S_MSGIN(&msg) != 0) { - return ret; - } - - ret = *(int*)retbuf; - return ret; -} - -//--------------------------------------------------------------------------- -// -// Call commands -// -//--------------------------------------------------------------------------- -int SCSI_CalCmd(BYTE *buf, int len, BYTE *outbuf, int outlen) -{ - int ret; - BYTE cmdbuf[10]; - BYTE sts; - BYTE msg; - BYTE retbuf[4]; - - ret = FS_FATAL_MEDIAOFFLINE; - - cmdbuf[0] = 0x2a; - cmdbuf[1] = 0; - cmdbuf[2] = 2; - cmdbuf[3] = command; - cmdbuf[4] = 0; - cmdbuf[5] = 0; - cmdbuf[6] = (BYTE)(len >> 16); - cmdbuf[7] = (BYTE)(len >> 8); - cmdbuf[8] = (BYTE)len; - cmdbuf[9] = 0; - - // Retry when select times out - if (S_SELECT(scsiid) != 0) { - S_RESET(); - if (S_SELECT(scsiid) != 0) { - return ret; - } - } - - if (S_CMDOUT(10, cmdbuf) != 0) { - return ret; - } - - if (S_DATAOUT_P(len, buf) != 0) { - return ret; - } - - if (S_STSIN(&sts) != 0) { - return ret; - } - - if (S_MSGIN(&msg) != 0) { - return ret; - } - - cmdbuf[0] = 0x28; - cmdbuf[1] = 0; - cmdbuf[2] = 2; - cmdbuf[3] = command; - cmdbuf[4] = 0; - cmdbuf[5] = 0; - cmdbuf[6] = 0; - cmdbuf[7] = 0; - cmdbuf[8] = 4; - cmdbuf[9] = 0; - - // Retry when select times out - if (S_SELECT(scsiid) != 0) { - S_RESET(); - if (S_SELECT(scsiid) != 0) { - return ret; - } - } - - if (S_CMDOUT(10, cmdbuf) != 0) { - return ret; - } - - if (S_DATAIN_P(4, retbuf) != 0) { - return ret; - } - - if (S_STSIN(&sts) != 0) { - return ret; - } - - if (S_MSGIN(&msg) != 0) { - return ret; - } - - // Stop receiving return data on error - ret = *(int*)retbuf; - if (ret < 0) { - return ret; - } - - cmdbuf[0] = 0x28; - cmdbuf[1] = 0; - cmdbuf[2] = 2; - cmdbuf[3] = command; - cmdbuf[4] = 0; - cmdbuf[5] = 0; - cmdbuf[6] = (BYTE)(outlen >> 16); - cmdbuf[7] = (BYTE)(outlen >> 8); - cmdbuf[8] = (BYTE)outlen; - cmdbuf[9] = 1; - - // Retry when select times out - if (S_SELECT(scsiid) != 0) { - S_RESET(); - if (S_SELECT(scsiid) != 0) { - return ret; - } - } - - if (S_CMDOUT(10, cmdbuf) != 0) { - return ret; - } - - if (S_DATAIN_P(outlen, outbuf) != 0) { - return ret; - } - - if (S_STSIN(&sts) != 0) { - return ret; - } - - if (S_MSGIN(&msg) != 0) { - return ret; - } - - ret = *(int*)retbuf; - return ret; -} - -//--------------------------------------------------------------------------- -// -// Get option data -// -//--------------------------------------------------------------------------- -BOOL SCSI_ReadOpt(BYTE *buf, int len) -{ - BYTE cmdbuf[10]; - BYTE sts; - BYTE msg; - - cmdbuf[0] = 0x28; - cmdbuf[1] = 0; - cmdbuf[2] = 2; - cmdbuf[3] = command; - cmdbuf[4] = 0; - cmdbuf[5] = 0; - cmdbuf[6] = (BYTE)(len >> 16); - cmdbuf[7] = (BYTE)(len >> 8); - cmdbuf[8] = (BYTE)len; - cmdbuf[9] = 2; - - // Retry when select times out - if (S_SELECT(scsiid) != 0) { - S_RESET(); - if (S_SELECT(scsiid) != 0) { - return FALSE; - } - } - - if (S_CMDOUT(10, cmdbuf) != 0) { - return FALSE; - } - - if (S_DATAIN_P(len, buf) != 0) { - return FALSE; - } - - if (S_STSIN(&sts) != 0) { - return FALSE; - } - - if (S_MSGIN(&msg) != 0) { - return FALSE; - } - - return TRUE; -} - -//--------------------------------------------------------------------------- -// -// Write option data -// -//--------------------------------------------------------------------------- -BOOL SCSI_WriteOpt(BYTE *buf, int len) -{ - BYTE cmdbuf[10]; - BYTE sts; - BYTE msg; - - cmdbuf[0] = 0x2a; - cmdbuf[1] = 0; - cmdbuf[2] = 2; - cmdbuf[3] = command; - cmdbuf[4] = 0; - cmdbuf[5] = 0; - cmdbuf[6] = (BYTE)(len >> 16); - cmdbuf[7] = (BYTE)(len >> 8); - cmdbuf[8] = (BYTE)len; - cmdbuf[9] = 1; - - // Retry when select times out - if (S_SELECT(scsiid) != 0) { - S_RESET(); - if (S_SELECT(scsiid) != 0) { - return FALSE; - } - } - - if (S_CMDOUT(10, cmdbuf) != 0) { - return FALSE; - } - - if (S_DATAOUT_P(len, buf) != 0) { - return FALSE; - } - - if (S_STSIN(&sts) != 0) { - return FALSE; - } - - if (S_MSGIN(&msg) != 0) { - return FALSE; - } - - return TRUE; -} - -//=========================================================================== -// -/// File System -// -//=========================================================================== - -//--------------------------------------------------------------------------- -// -// $40 - Device startup -// -//--------------------------------------------------------------------------- -DWORD FS_InitDevice(const argument_t* pArgument) -{ - return (DWORD)SCSI_SendCmd((BYTE*)pArgument, sizeof(argument_t)); -} - -//--------------------------------------------------------------------------- -// -// $41 - Directory check -// -//--------------------------------------------------------------------------- -int FS_CheckDir(const namests_t* pNamests) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - memcpy(&buf[i], pNamests, sizeof(namests_t)); - i += sizeof(namests_t); - - return SCSI_SendCmd(buf, i); -} - -//--------------------------------------------------------------------------- -// -// $42 - Create directory -// -//--------------------------------------------------------------------------- -int FS_MakeDir(const namests_t* pNamests) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - memcpy(&buf[i], pNamests, sizeof(namests_t)); - i += sizeof(namests_t); - - return SCSI_SendCmd(buf, i); -} - -//--------------------------------------------------------------------------- -// -// $43 - Delete directory -// -//--------------------------------------------------------------------------- -int FS_RemoveDir(const namests_t* pNamests) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - memcpy(&buf[i], pNamests, sizeof(namests_t)); - i += sizeof(namests_t); - - return SCSI_SendCmd(buf, i); -} - -//--------------------------------------------------------------------------- -// -// $44 - Change file name -// -//--------------------------------------------------------------------------- -int FS_Rename(const namests_t* pNamests, const namests_t* pNamestsNew) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - memcpy(&buf[i], pNamests, sizeof(namests_t)); - i += sizeof(namests_t); - - memcpy(&buf[i], pNamestsNew, sizeof(namests_t)); - i += sizeof(namests_t); - - return SCSI_SendCmd(buf, i); -} - -//--------------------------------------------------------------------------- -// -// $45 - Delete file -// -//--------------------------------------------------------------------------- -int FS_Delete(const namests_t* pNamests) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - memcpy(&buf[i], pNamests, sizeof(namests_t)); - i += sizeof(namests_t); - - return SCSI_SendCmd(buf, i); -} - -//--------------------------------------------------------------------------- -// -// $46 - Get/set file attribute -// -//--------------------------------------------------------------------------- -int FS_Attribute(const namests_t* pNamests, DWORD nHumanAttribute) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - memcpy(&buf[i], pNamests, sizeof(namests_t)); - i += sizeof(namests_t); - - dp = (DWORD*)&buf[i]; - *dp = nHumanAttribute; - i += sizeof(DWORD); - - return SCSI_SendCmd(buf, i); -} - -//--------------------------------------------------------------------------- -// -// $47 - File search -// -//--------------------------------------------------------------------------- -int FS_Files(DWORD nKey, - const namests_t* pNamests, files_t* info) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nKey; - i += sizeof(DWORD); - - memcpy(&buf[i], pNamests, sizeof(namests_t)); - i += sizeof(namests_t); - - memcpy(&buf[i], info, sizeof(files_t)); - i += sizeof(files_t); - - return SCSI_CalCmd(buf, i, (BYTE*)info, sizeof(files_t)); -} - -//--------------------------------------------------------------------------- -// -// $48 - Search next file -// -//--------------------------------------------------------------------------- -int FS_NFiles(DWORD nKey, files_t* info) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nKey; - i += sizeof(DWORD); - - memcpy(&buf[i], info, sizeof(files_t)); - i += sizeof(files_t); - - return SCSI_CalCmd(buf, i, (BYTE*)info, sizeof(files_t)); -} - -//--------------------------------------------------------------------------- -// -// $49 - Create new file -// -//--------------------------------------------------------------------------- -int FS_Create(DWORD nKey, - const namests_t* pNamests, fcb_t* pFcb, DWORD nAttribute, BOOL bForce) -{ - BYTE buf[256]; - DWORD *dp; - BOOL *bp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nKey; - i += sizeof(DWORD); - - memcpy(&buf[i], pNamests, sizeof(namests_t)); - i += sizeof(namests_t); - - memcpy(&buf[i], pFcb, sizeof(fcb_t)); - i += sizeof(fcb_t); - - dp = (DWORD*)&buf[i]; - *dp = nAttribute; - i += sizeof(DWORD); - - bp = (BOOL*)&buf[i]; - *bp = bForce; - i += sizeof(BOOL); - - return SCSI_CalCmd(buf, i, (BYTE*)pFcb, sizeof(fcb_t)); -} - -//--------------------------------------------------------------------------- -// -// $4A - File open -// -//--------------------------------------------------------------------------- -int FS_Open(DWORD nKey, - const namests_t* pNamests, fcb_t* pFcb) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nKey; - i += sizeof(DWORD); - - memcpy(&buf[i], pNamests, sizeof(namests_t)); - i += sizeof(namests_t); - - memcpy(&buf[i], pFcb, sizeof(fcb_t)); - i += sizeof(fcb_t); - - return SCSI_CalCmd(buf, i, (BYTE*)pFcb, sizeof(fcb_t)); -} - -//--------------------------------------------------------------------------- -// -// $4B - File close -// -//--------------------------------------------------------------------------- -int FS_Close(DWORD nKey, fcb_t* pFcb) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nKey; - i += sizeof(DWORD); - - memcpy(&buf[i], pFcb, sizeof(fcb_t)); - i += sizeof(fcb_t); - - return SCSI_CalCmd(buf, i, (BYTE*)pFcb, sizeof(fcb_t)); -} - -//--------------------------------------------------------------------------- -// -// $4C - Read file -// -//--------------------------------------------------------------------------- -int FS_Read(DWORD nKey, fcb_t* pFcb, BYTE* pAddress, DWORD nSize) -{ - BYTE buf[256]; - DWORD *dp; - int i; - int nResult; - - i = 0; - dp = (DWORD*)buf; - *dp = nKey; - i += sizeof(DWORD); - - memcpy(&buf[i], pFcb, sizeof(fcb_t)); - i += sizeof(fcb_t); - - dp = (DWORD*)&buf[i]; - *dp = nSize; - i += sizeof(DWORD); - - nResult = SCSI_CalCmd(buf, i, (BYTE*)pFcb, sizeof(fcb_t)); - - if (nResult > 0) { - SCSI_ReadOpt(pAddress, nResult); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $4D - Write file -// -//--------------------------------------------------------------------------- -int FS_Write(DWORD nKey, fcb_t* pFcb, BYTE* pAddress, DWORD nSize) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = nKey; - i += sizeof(DWORD); - - memcpy(&buf[i], pFcb, sizeof(fcb_t)); - i += sizeof(fcb_t); - - dp = (DWORD*)&buf[i]; - *dp = nSize; - i += sizeof(DWORD); - - if (nSize != 0) { - if (!SCSI_WriteOpt(pAddress, nSize)) { - return FS_FATAL_MEDIAOFFLINE; - } - } - - return SCSI_SendCmd(buf, i); -} - -//--------------------------------------------------------------------------- -// -// $4E - File seek -// -//--------------------------------------------------------------------------- -int FS_Seek(DWORD nKey, fcb_t* pFcb, DWORD nMode, int nOffset) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = nKey; - i += sizeof(DWORD); - - memcpy(&buf[i], pFcb, sizeof(fcb_t)); - i += sizeof(fcb_t); - - dp = (DWORD*)&buf[i]; - *dp = nMode; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nOffset; - i += sizeof(int); - - return SCSI_CalCmd(buf, i, (BYTE*)pFcb, sizeof(fcb_t)); -} - -//--------------------------------------------------------------------------- -// -// $4F - Get/set file time stamp -// -//--------------------------------------------------------------------------- -DWORD FS_TimeStamp(DWORD nKey, - fcb_t* pFcb, DWORD nHumanTime) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nKey; - i += sizeof(DWORD); - - memcpy(&buf[i], pFcb, sizeof(fcb_t)); - i += sizeof(fcb_t); - - dp = (DWORD*)&buf[i]; - *dp = nHumanTime; - i += sizeof(DWORD); - - return (DWORD)SCSI_CalCmd(buf, i, (BYTE*)pFcb, sizeof(fcb_t)); -} - -//--------------------------------------------------------------------------- -// -// $50 - Get capacity -// -//--------------------------------------------------------------------------- -int FS_GetCapacity(capacity_t* cap) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - return SCSI_CalCmd(buf, i, (BYTE*)cap, sizeof(capacity_t)); -} - -//--------------------------------------------------------------------------- -// -// $51 - Inspect/control drive status -// -//--------------------------------------------------------------------------- -int FS_CtrlDrive(ctrldrive_t* pCtrlDrive) -{ -#if 1 - // Do tentative processing here due to high load - switch (pCtrlDrive->status) { - case 0: // Inspect status - case 9: // Inspect status 2 - pCtrlDrive->status = 0x42; - return pCtrlDrive->status; - case 1: // Eject - case 2: // Eject forbidden 1 (not implemented) - case 3: // Eject allowed 1 (not implemented) - case 4: // Flash LED when media is not inserted (not implemented) - case 5: // Turn off LED when media is not inserted (not implemented) - case 6: // Eject forbidden 2 (not implemented) - case 7: // Eject allowed 2 (not implemented) - return 0; - - case 8: // Eject inspection - return 1; - } - - return -1; -#else - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - memcpy(&buf[i], pCtrlDrive, sizeof(ctrldrive_t)); - i += sizeof(ctrldrive_t); - - return SCSI_CalCmd(buf, i, (BYTE*)pCtrlDrive, sizeof(ctrldrive_t)); -#endif -} - -//--------------------------------------------------------------------------- -// -// $52 - Get DPB -// -//--------------------------------------------------------------------------- -int FS_GetDPB(dpb_t* pDpb) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - return SCSI_CalCmd(buf, i, (BYTE*)pDpb, sizeof(dpb_t)); -} - -//--------------------------------------------------------------------------- -// -// $53 - Read sector -// -//--------------------------------------------------------------------------- -int FS_DiskRead(BYTE* pBuffer, DWORD nSector, DWORD nSize) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nSector; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nSize; - i += sizeof(DWORD); - - return SCSI_CalCmd(buf, i, (BYTE*)pBuffer, 0x200); -} - -//--------------------------------------------------------------------------- -// -// $54 - Write sector -// -//--------------------------------------------------------------------------- -int FS_DiskWrite() -{ - BYTE buf[256]; - DWORD *dp; - - dp = (DWORD*)buf; - *dp = unit; - - return SCSI_SendCmd(buf, 4); -} - -//--------------------------------------------------------------------------- -// -// $55 - IOCTRL -// -//--------------------------------------------------------------------------- -int FS_Ioctrl(DWORD nFunction, ioctrl_t* pIoctrl) -{ - BYTE buf[256]; - DWORD *dp; - int i; - - i = 0; - dp = (DWORD*)buf; - *dp = unit; - i += sizeof(DWORD); - - dp = (DWORD*)&buf[i]; - *dp = nFunction; - i += sizeof(DWORD); - - memcpy(&buf[i], pIoctrl, sizeof(ioctrl_t)); - i += sizeof(ioctrl_t); - - return SCSI_CalCmd(buf, i, (BYTE*)pIoctrl, sizeof(ioctrl_t)); -} - -//--------------------------------------------------------------------------- -// -// $56 - Flush -// -//--------------------------------------------------------------------------- -int FS_Flush() -{ -#if 1 - // Not supported - return 0; -#else - BYTE buf[256]; - DWORD *dp; - - dp = (DWORD*)buf; - *dp = unit; - - return SCSI_SendCmd(buf, 4); -#endif -} - -//--------------------------------------------------------------------------- -// -// $57 - Media change check -// -//--------------------------------------------------------------------------- -int FS_CheckMedia() -{ -#if 1 - // Do tentative processing due to high load - return 0; -#else - BYTE buf[256]; - DWORD *dp; - - dp = (DWORD*)buf; - *dp = unit; - - return SCSI_SendCmd(buf, 4); -#endif -} - -//--------------------------------------------------------------------------- -// -// $58 - Lock -// -//--------------------------------------------------------------------------- -int FS_Lock() -{ -#if 1 - // Not supported - return 0; -#else - BYTE buf[256]; - DWORD *dp; - - dp = (DWORD*)buf; - *dp = unit; - - return SCSI_SendCmd(buf, 4); -#endif -} - -//=========================================================================== -// -// Command handlers -// -//=========================================================================== -#define GetReqByte(a) (request[a]) -#define SetReqByte(a,d) (request[a] = (d)) -#define GetReqWord(a) (*((WORD*)&request[a])) -#define SetReqWord(a,d) (*((WORD*)&request[a]) = (d)) -#define GetReqLong(a) (*((DWORD*)&request[a])) -#define SetReqLong(a,d) (*((DWORD*)&request[a]) = (d)) -#define GetReqAddr(a) ((BYTE*)((*((DWORD*)&request[a])) & 0x00ffffff)) - -//--------------------------------------------------------------------------- -// -// Read NAMESTS -// -//--------------------------------------------------------------------------- -void GetNameStsPath(BYTE *addr, namests_t* pNamests) -{ - DWORD i; - - ASSERT(this); - ASSERT(pNamests); - - // Wildcard data - pNamests->wildcard = *addr; - - // Drive number - pNamests->drive = addr[1]; - - // Pathname - for (i = 0; i < sizeof(pNamests->path); i++) { - pNamests->path[i] = addr[2 + i]; - } - - // Filename 1 - memset(pNamests->name, 0x20, sizeof(pNamests->name)); - - // File ending - memset(pNamests->ext, 0x20, sizeof(pNamests->ext)); - - // Filename 2 - memset(pNamests->add, 0, sizeof(pNamests->add)); -} - -//--------------------------------------------------------------------------- -// -// Read NAMESTS -// -//--------------------------------------------------------------------------- -void GetNameSts(BYTE *addr, namests_t* pNamests) -{ - DWORD i; - - ASSERT(this); - ASSERT(pNamests); - ASSERT(addr <= 0xFFFFFF); - - // Wildcard data - pNamests->wildcard = *addr; - - // Drive number - pNamests->drive = addr[1]; - - // Pathname - for (i = 0; i < sizeof(pNamests->path); i++) { - pNamests->path[i] = addr[2 + i]; - } - - // Filename 1 - for (i = 0; i < sizeof(pNamests->name); i++) { - pNamests->name[i] = addr[67 + i]; - } - - // File ending - for (i = 0; i < sizeof(pNamests->ext); i++) { - pNamests->ext[i] = addr[75 + i]; - } - - // Filename 2 - for (i = 0; i < sizeof(pNamests->add); i++) { - pNamests->add[i] = addr[78 + i]; - } -} - -//--------------------------------------------------------------------------- -// -// Read FILES -// -//--------------------------------------------------------------------------- -void GetFiles(BYTE *addr, files_t* pFiles) -{ - ASSERT(this); - ASSERT(pFiles); - ASSERT(addr <= 0xFFFFFF); - - // Search data - pFiles->fatr = *addr; - pFiles->sector = *((DWORD*)&addr[2]); - pFiles->offset = *((WORD*)&addr[8]);; - - pFiles->attr = 0; - pFiles->time = 0; - pFiles->date = 0; - pFiles->size = 0; - memset(pFiles->full, 0, sizeof(pFiles->full)); -} - -//--------------------------------------------------------------------------- -// -// Write FILES -// -//--------------------------------------------------------------------------- -void SetFiles(BYTE *addr, const files_t* pFiles) -{ - DWORD i; - - ASSERT(this); - ASSERT(pFiles); - - *((DWORD*)&addr[2]) = pFiles->sector; - *((WORD*)&addr[8]) = pFiles->offset; - - // File data - addr[21] = pFiles->attr; - *((WORD*)&addr[22]) = pFiles->time; - *((WORD*)&addr[24]) = pFiles->date; - *((DWORD*)&addr[26]) = pFiles->size; - - // Full filename - addr += 30; - for (i = 0; i < sizeof(pFiles->full); i++) { - *addr = pFiles->full[i]; - addr++; - } -} - -//--------------------------------------------------------------------------- -// -// Read FCB -// -//--------------------------------------------------------------------------- -void GetFcb(BYTE *addr, fcb_t* pFcb) -{ - ASSERT(this); - ASSERT(pFcb); - - // FCB data - pFcb->fileptr = *((DWORD*)&addr[6]); - pFcb->mode = *((WORD*)&addr[14]); - - // Attribute - pFcb->attr = addr[47]; - - // FCB data - pFcb->time = *((WORD*)&addr[58]); - pFcb->date = *((WORD*)&addr[60]); - pFcb->size = *((DWORD*)&addr[64]); -} - -//--------------------------------------------------------------------------- -// -// Write FCB -// -//--------------------------------------------------------------------------- -void SetFcb(BYTE *addr, const fcb_t* pFcb) -{ - ASSERT(this); - ASSERT(pFcb); - - // FCB data - *((DWORD*)&addr[6]) = pFcb->fileptr; - *((WORD*)&addr[14]) = pFcb->mode; - - // Attribute - addr[47] = pFcb->attr; - - // FCB data - *((WORD*)&addr[58]) = pFcb->time; - *((WORD*)&addr[60]) = pFcb->date; - *((DWORD*)&addr[64]) = pFcb->size; -} - -//--------------------------------------------------------------------------- -// -// Write CAPACITY -// -//--------------------------------------------------------------------------- -void SetCapacity(BYTE *addr, const capacity_t* pCapacity) -{ - ASSERT(this); - ASSERT(pCapacity); - - *((WORD*)&addr[0]) = pCapacity->freearea; - *((WORD*)&addr[2]) = pCapacity->clusters; - *((WORD*)&addr[4]) = pCapacity->sectors; - *((WORD*)&addr[6]) = pCapacity->bytes; -} - -//--------------------------------------------------------------------------- -// -// Write DPB -// -//--------------------------------------------------------------------------- -void SetDpb(BYTE *addr, const dpb_t* pDpb) -{ - ASSERT(this); - ASSERT(pDpb); - - // DPB data - *((WORD*)&addr[0]) = pDpb->sector_size; - addr[2] = pDpb->cluster_size; - addr[3] = pDpb->shift; - *((WORD*)&addr[4]) = pDpb->fat_sector; - addr[6] = pDpb->fat_max; - addr[7] = pDpb->fat_size; - *((WORD*)&addr[8]) = pDpb->file_max; - *((WORD*)&addr[10]) = pDpb->data_sector; - *((WORD*)&addr[12]) = pDpb->cluster_max; - *((WORD*)&addr[14]) = pDpb->root_sector; - addr[20] = pDpb->media; -} - -//--------------------------------------------------------------------------- -// -// Read IOCTRL -// -//--------------------------------------------------------------------------- -void GetIoctrl(DWORD param, DWORD func, ioctrl_t* pIoctrl) -{ - DWORD *lp; - - ASSERT(this); - ASSERT(pIoctrl); - - switch (func) { - case 2: - // Re-identify media - pIoctrl->param = param; - return; - - case -2: - // Configure options - lp = (DWORD*)param; - pIoctrl->param = *lp; - return; - } -} - -//--------------------------------------------------------------------------- -// -// Write IOCTRL -// -//--------------------------------------------------------------------------- -void SetIoctrl(DWORD param, DWORD func, ioctrl_t* pIoctrl) -{ - DWORD i; - BYTE *bp; - WORD *wp; - DWORD *lp; - - ASSERT(this); - ASSERT(pIoctrl); - - switch (func) { - case 0: - // Acquire media ID - wp = (WORD*)param; - *wp = pIoctrl->media; - return; - - case 1: - // Dummy for Human68k compatibility - lp = (DWORD*)param; - *lp = pIoctrl->param; - return; - - case -1: - // Resident evaluation - bp = (BYTE*)param; - for (i = 0; i < 8; i++) { - *bp = pIoctrl->buffer[i]; - bp++; - } - return; - - case -3: - // Acquire options - lp = (DWORD*)param; - *lp = pIoctrl->param; - return; - } -} - -//--------------------------------------------------------------------------- -// -// Read ARGUMENT -// -// When this exceeds the buffer size, interrupt transfer and exit. -// -//--------------------------------------------------------------------------- -void GetArgument(BYTE *addr, argument_t* pArgument) -{ - BOOL bMode; - BYTE *p; - DWORD i; - BYTE c; - - ASSERT(this); - ASSERT(pArgument); - - bMode = FALSE; - p = pArgument->buf; - for (i = 0; i < sizeof(pArgument->buf) - 2; i++) { - c = addr[i]; - *p++ = c; - if (bMode == 0) { - if (c == '\0') - return; - bMode = TRUE; - } else { - if (c == '\0') - bMode = FALSE; - } - } - - *p++ = '\0'; - *p = '\0'; -} - -//--------------------------------------------------------------------------- -// -// Write return value -// -//--------------------------------------------------------------------------- -void SetResult(DWORD nResult) -{ - DWORD code; - - ASSERT(this); - - // Handle fatal errors - switch (nResult) { - case FS_FATAL_INVALIDUNIT: - code = 0x5001; - goto fatal; - case FS_FATAL_INVALIDCOMMAND: - code = 0x5003; - goto fatal; - case FS_FATAL_WRITEPROTECT: - code = 0x700D; - goto fatal; - case FS_FATAL_MEDIAOFFLINE: - code = 0x7002; - fatal: - SetReqByte(3, (BYTE)code); - SetReqByte(4, code >> 8); - // @note When returning retryability, never overwrite with (a5 + 18). - // If you do that, the system will start behaving erratically if you hit Retry at the system error screen. - if (code & 0x2000) - break; - nResult = FS_INVALIDFUNC; - default: - SetReqLong(18, nResult); - break; - } -} - -//--------------------------------------------------------------------------- -// -// $40 - Device startup -// -// in (offset size) -// 0 1.b constant (22) -// 2 1.b command ($40/$c0) -// 18 1.l parameter address -// 22 1.b drive number -// out (offset size) -// 3 1.b error code (lower) -// 4 1.b '' (upper) -// 13 1.b number of units -// 14 1.l device driver exit address + 1 -// -// This is called command 0 when the driver is loaded similarly to a local drive, -// but there is no need to prepare BPB or its pointer array. -// Unlike other commands, only this command does not include a valid a5 + 1, -// since it doesn't expect 0 initialization etc., so be careful. -// -//--------------------------------------------------------------------------- -DWORD InitDevice(void) -{ - argument_t arg; - DWORD units; - - ASSERT(this); - ASSERT(fs); - - // Get option contents - GetArgument(GetReqAddr(18), &arg); - - // Contstruct the filesystem to the extent Human68k can support number of drivers etc. - units = FS_InitDevice(&arg); - - // Return number of drives - SetReqByte(13, units); - - return 0; -} - -//--------------------------------------------------------------------------- -// -// $41 - Directory check -// -// in (offset size) -// 14 1.L NAMESTS struct address -// -//--------------------------------------------------------------------------- -DWORD CheckDir(void) -{ - namests_t ns; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get filename to search - GetNameStsPath(GetReqAddr(14), &ns); - - // Call filesystem - nResult = FS_CheckDir(&ns); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $42 - Create directory -// -// in (offset size) -// 14 1.L NAMESTS struct address -// -//--------------------------------------------------------------------------- -DWORD MakeDir(void) -{ - namests_t ns; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get filename to search - GetNameSts(GetReqAddr(14), &ns); - - // Call filesystem - nResult = FS_MakeDir(&ns); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $43 - Delete directory -// -// in (offset size) -// 14 1.L NAMESTS struct address -// -//--------------------------------------------------------------------------- -DWORD RemoveDir(void) -{ - namests_t ns; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get filename to search - GetNameSts(GetReqAddr(14), &ns); - - // Call filesystem - nResult = FS_RemoveDir(&ns); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $44 - Change filename -// -// in (offset size) -// 14 1.L NAMESTS struct address old filename -// 18 1.L NAMESTS struct address new filename -// -//--------------------------------------------------------------------------- -DWORD Rename(void) -{ - namests_t ns; - namests_t ns_new; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get filename to search - GetNameSts(GetReqAddr(14), &ns); - GetNameSts(GetReqAddr(18), &ns_new); - - // Call filesystem - nResult = FS_Rename(&ns, &ns_new); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $45 - Delete file -// -// in (offset size) -// 14 1.L NAMESTS struct address -// -//--------------------------------------------------------------------------- -DWORD Delete(void) -{ - namests_t ns; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get filename to search - GetNameSts(GetReqAddr(14), &ns); - - // Call filesystem - nResult = FS_Delete(&ns); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $46 - Get/set file attribute -// -// in (offset size) -// 12 1.B Note that this becomes 0x01 when read from memory -// 13 1.B attribute; read from memory when $FF -// 14 1.L NAMESTS struct address -// -//--------------------------------------------------------------------------- -DWORD Attribute(void) -{ - namests_t ns; - DWORD attr; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get filename to search - GetNameSts(GetReqAddr(14), &ns); - - // Target attribute - attr = GetReqByte(13); - - // Call filesystem - nResult = FS_Attribute(&ns, attr); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $47 - File search -// -// in (offset size) -// 0 1.b constant (26) -// 1 1.b unit number -// 2 1.b command ($47/$c7) -// 13 1.b search attribute (Unused in WindrvXM. Written directly to search buffer.) -// 14 1.l Filename buffer (namests format) -// 18 1.l Search buffer (files format) Search data in progress and search results are written to this buffer. -// out (offset size) -// 3 1.b error code (lower) -// 4 1.b '' (upper) -// 18 1.l result status -// -// Search files from specified directory. Called from DOS _FILES. -// When a search fails, or succeeds but not using wildcards, -// we write -1 to the search buffer offset to make the next search fail. -// When a file is found, we set its data as well as the following data -// for the next search: sector number, offset, and in the case of the -// root directory, also the remaining sectors. The search drive, attribute, -// and path name are set in the DOS call processing, so writing is not needed. -// -// -// (offset size) -// 0 1.b NAMWLD 0: no wildcard -1:no specified file -// (number of chars of wildcard) -// 1 1.b NAMDRV drive number (A=0,B=1,...,Z=25) -// 2 65.b NAMPTH path ('\' + optional subdirectory + '\') -// 67 8.b NAMNM1 filename (first 8 chars) -// 75 3.b NAMEXT file ending -// 78 10.b NAMNM2 filename (remaining 10 chars) -// -// Note that 0x09 (TAB) is used for path separator, rather than 0x2F (/) or 0x5C (\) -// -//--------------------------------------------------------------------------- -DWORD Files(void) -{ - BYTE *files; - files_t info; - namests_t ns; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Memory for storing search in progress - files = GetReqAddr(18); - GetFiles(files, &info); - - // Get filename to search - GetNameSts(GetReqAddr(14), &ns); - - // Call filesystem - nResult = FS_Files((DWORD)files, &ns, &info); - - // Apply search results - if (nResult >= 0) { - SetFiles(files, &info); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $48 - Search next file -// -// in (offset size) -// 18 1.L FILES struct address -// -//--------------------------------------------------------------------------- -DWORD NFiles(void) -{ - BYTE *files; - files_t info; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Read work memory - files = GetReqAddr(18); - GetFiles(files, &info); - - // Call filesystem - nResult = FS_NFiles((DWORD)files, &info); - - // Apply search results - if (nResult >= 0) { - SetFiles(files, &info); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $49 - Create file (Create) -// -// in (offset size) -// 1 1.B unit number -// 13 1.B attribute -// 14 1.L NAMESTS struct address -// 18 1.L mode (0:_NEWFILE 1:_CREATE) -// 22 1.L FCB struct address -// -//--------------------------------------------------------------------------- -DWORD Create(void) -{ - namests_t ns; - BYTE *pFcb; - fcb_t fcb; - DWORD attr; - BOOL force; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get target filename - GetNameSts(GetReqAddr(14), &ns); - - // Get FCB - pFcb = GetReqAddr(22); - GetFcb(pFcb, &fcb); - - // Attribute - attr = GetReqByte(13); - - // Forced overwrite mode - force = (BOOL)GetReqLong(18); - - // Call filesystem - nResult = FS_Create((DWORD)pFcb, &ns, &fcb, attr, force); - - // Apply results - if (nResult >= 0) { - SetFcb(pFcb, &fcb); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $4A - File open -// -// in (offset size) -// 1 1.B unit number -// 14 1.L NAMESTS struct address -// 22 1.L FCB struct address -// Most parameters are already set in FCB. -// Overwrite time and date at the moment of opening. -// Overwrite if size is 0. -// -//--------------------------------------------------------------------------- -DWORD Open(void) -{ - namests_t ns; - BYTE *pFcb; - fcb_t fcb; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get target filename - GetNameSts(GetReqAddr(14), &ns); - - // Get FCB - pFcb = GetReqAddr(22); - GetFcb(pFcb, &fcb); - - // Call filesystem - nResult = FS_Open((DWORD)pFcb, &ns, &fcb); - - // Apply results - if (nResult >= 0) { - SetFcb(pFcb, &fcb); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $4B - File close -// -// in (offset size) -// 22 1.L FCB struct address -// -//--------------------------------------------------------------------------- -DWORD Close(void) -{ - BYTE *pFcb; - fcb_t fcb; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get FCB - pFcb = GetReqAddr(22); - GetFcb(pFcb, &fcb); - - // Call filesystem - nResult = FS_Close((DWORD)pFcb, &fcb); - - // Apply results - if (nResult >= 0) { - SetFcb(pFcb, &fcb); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $4C - Read file -// -// in (offset size) -// 14 1.L Reading buffer; Read the file contents here. -// 18 1.L Size; It may be set to values exceeding 16MB -// 22 1.L FCB struct address -// -// No guarantee for behavior when passing address where bus error occurs. -// -// In the 20th century, a small number of apps used a trick where reading a -// negative value meant "read all the files!" Wh, what? This file is over 16MB! -// -// Back then, anything over 4~12MB was treated as "inifity" and often truncated -// out of helpfulness, which is not needed in this day and age. -// On the other hand, it might be a good idea to truncate at 12MB or 16MB. -// -//--------------------------------------------------------------------------- -DWORD Read(void) -{ - BYTE *pFcb; - fcb_t fcb; - BYTE *pAddress; - DWORD nSize; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get FCB - pFcb = GetReqAddr(22); - GetFcb(pFcb, &fcb); - - // Read buffer - pAddress = GetReqAddr(14); - - // Read size - nSize = GetReqLong(18); - - // Clipping - if (nSize >= WINDRV_CLIPSIZE_MAX) { - nSize = WINDRV_CLIPSIZE_MAX; - } - - // Call filesystem - nResult = FS_Read((DWORD)pFcb, &fcb, pAddress, nSize); - - // Apply results - if (nResult >= 0) { - SetFcb(pFcb, &fcb); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $4D - Write file -// -// in (offset size) -// 14 1.L Write buffer; Write file contents here -// 18 1.L Size; If a negative number, treated the same as specifying file size -// 22 1.L FCB struct address -// -// No guarantee for behavior when passing address where bus error occurs. -// -//--------------------------------------------------------------------------- -DWORD Write(void) -{ - BYTE *pFcb; - fcb_t fcb; - BYTE *pAddress; - DWORD nSize; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get FCB - pFcb = GetReqAddr(22); - GetFcb(pFcb, &fcb); - - // Write buffer - pAddress = GetReqAddr(14); - - // Write size - nSize = GetReqLong(18); - - // Clipping - if (nSize >= WINDRV_CLIPSIZE_MAX) { - nSize = WINDRV_CLIPSIZE_MAX; - } - - // Call filesystem - nResult = FS_Write((DWORD)pFcb, &fcb, pAddress, nSize); - - // Apply results - if (nResult >= 0) { - SetFcb(pFcb, &fcb); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $4E - File seek -// -// in (offset size) -// 12 1.B This becomes 0x2B sometimes, and 0 other times -// 13 1.B mode -// 18 1.L offset -// 22 1.L FCB struct address -// -//--------------------------------------------------------------------------- -DWORD Seek(void) -{ - BYTE *pFcb; - fcb_t fcb; - DWORD nMode; - DWORD nOffset; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get FCB - pFcb = GetReqAddr(22); - GetFcb(pFcb, &fcb); - - // Seek mode - nMode = GetReqByte(13); - - // Seek offset - nOffset = GetReqLong(18); - - // Call filesystem - nResult = FS_Seek((DWORD)pFcb, &fcb, nMode, nOffset); - - // Apply results - if (nResult >= 0) { - SetFcb(pFcb, &fcb); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $4F - Get/set file timestamp -// -// in (offset size) -// 18 1.W DATE -// 20 1.W TIME -// 22 1.L FCB struct address -// -// Possible to change settings when FCB is opened in read mode too. -// Note: Cannot make the judgement of read-only with only FCB -// -//--------------------------------------------------------------------------- -DWORD TimeStamp(void) -{ - BYTE *pFcb; - fcb_t fcb; - DWORD nTime; - DWORD nResult; - - ASSERT(this); - ASSERT(fs); - - // Get FCB - pFcb = GetReqAddr(22); - GetFcb(pFcb, &fcb); - - // Get timestamp - nTime = GetReqLong(18); - - // Call filesystem - nResult = FS_TimeStamp((DWORD)pFcb, &fcb, nTime); - - // Apply results - if (nResult < 0xFFFF0000) { - SetFcb(pFcb, &fcb); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $50 - Get capacity -// -// in (offset size) -// 0 1.b constant (26) -// 1 1.b unit number -// 2 1.b command ($50/$d0) -// 14 1.l buffer address -// out (offset size) -// 3 1.b error code (lower) -// 4 1.b '' (upper) -// 18 1.l result status -// -// Get the total and available media capacity, as well as cluster / sector size. -// The contents to write to buffer follows. Returns number of bytes that can be -// used for result status. -// -// (offset size) -// 0 1.w available number of clusters -// 2 1.w total number of clusters -// 4 1.w number of sectors per 1 cluster -// 6 1.w number of bytes per 1 sector -// -//--------------------------------------------------------------------------- -DWORD GetCapacity(void) -{ - BYTE *pCapacity; - capacity_t cap; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get buffer - pCapacity = GetReqAddr(14); - -#if 0 - // Call filesystem - nResult = FS_GetCapacity(&cap); -#else - // Try skipping since the contents are always returned - cap.freearea = 0xFFFF; - cap.clusters = 0xFFFF; - cap.sectors = 64; - cap.bytes = 512; - nResult = 0x7FFF8000; -#endif - - // Apply results - if (nResult >= 0) { - SetCapacity(pCapacity, &cap); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $51 - Inspect/control drive status -// -// in (offset size) -// 1 1.B unit number -// 13 1.B status 0: status inspection 1: eject -// -//--------------------------------------------------------------------------- -DWORD CtrlDrive(void) -{ - ctrldrive_t ctrl; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get drive status - ctrl.status = GetReqByte(13); - - // Call filesystem - nResult = FS_CtrlDrive(&ctrl); - - // Apply results - if (nResult >= 0) { - SetReqByte(13, ctrl.status); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $52 - Get DPB -// -// in (offset size) -// 0 1.b constant (26) -// 1 1.b unit number -// 2 1.b command ($52/$d2) -// 14 1.l buffer address (points at starting address + 2) -// out (offset size) -// 3 1.b error code (lower) -// 4 1.b '' (upper) -// 18 1.l result status -// -// Specified media data is returned as DPB v1. Data needed to be set -// for this command are as follows (parantheses indicate what's set by DOS calls.) -// Note that the buffer adress is what's pointed at by offset 2. -// -// (offset size) -// 0 1.b (drive number) -// 1 1.b (unit number) -// 2 1.w number of bytes per 1 sector -// 4 1.b number of sectors - 1 per 1 cluster -// 5 1.b Number of cluster -> sector -// bit 7 = 1 in MS-DOS format FAT (16bit Intel array) -// 6 1.w FAT first sector number -// 8 1.b Number of FAT allocations -// 9 1.b Number of FAT controlled sectors (excluding duplicates) -// 10 1.w Number of files in the root directory -// 12 1.w First sector number of data memory -// 14 1.w Total number of clusters + 1 -// 16 1.w First sector number of root directory -// 18 1.l (Driver head address) -// 22 1.b (Physical drive name in lower-case) -// 23 1.b (DPB usage flag: normally 0) -// 24 1.l (Next DPB address) -// 28 1.w (Cluster number of current directory: normally 0) -// 30 64.b (Current directory name) -// -//--------------------------------------------------------------------------- -DWORD GetDPB(void) -{ - BYTE *pDpb; - dpb_t dpb; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get DPB - pDpb = GetReqAddr(14); - - // Call filesystem - nResult = FS_GetDPB(&dpb); - - // Apply results - if (nResult >= 0) { - SetDpb(pDpb, &dpb); - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $53 - Read sector -// -// in (offset size) -// 1 1.B unit number -// 14 1.L buffer address -// 18 1.L number of sectors -// 22 1.L sector number -// -//--------------------------------------------------------------------------- -DWORD DiskRead(void) -{ - BYTE *pAddress; - DWORD nSize; - DWORD nSector; - BYTE buffer[0x200]; - int nResult; - int i; - - ASSERT(this); - ASSERT(fs); - - pAddress = GetReqAddr(14); // Address (upper bit is extension flag) - nSize = GetReqLong(18); // Number of sectors - nSector = GetReqLong(22); // Sector number - - // Call filesystem - nResult = FS_DiskRead(buffer, nSector, nSize); - - // Apply results - if (nResult >= 0) { - for (i = 0; i < sizeof(buffer); i++) { - *pAddress = buffer[i]; - pAddress++; - } - } - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $54 - Write sector -// -// in (offset size) -// 1 1.B unit number -// 14 1.L buffer address -// 18 1.L number of sectors -// 22 1.L sector number -// -//--------------------------------------------------------------------------- -DWORD DiskWrite(void) -{ - BYTE *pAddress; - DWORD nSize; - DWORD nSector; - int nResult; - - ASSERT(this); - ASSERT(fs); - - pAddress = GetReqAddr(14); // Address (upper bit is extension flag) - nSize = GetReqLong(18); // Number of sectors - nSector = GetReqLong(22); // Sector number - - // Call filesystem - nResult = FS_DiskWrite(); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $55 - IOCTRL -// -// in (offset size) -// 1 1.B unit number -// 14 1.L parameter -// 18 1.W feature number -// -//--------------------------------------------------------------------------- -DWORD Ioctrl(void) -{ - DWORD param; - DWORD func; - ioctrl_t ioctrl; - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Get IOCTRL - param = GetReqLong(14); // Parameter - func = GetReqWord(18); // Feature number - GetIoctrl(param, func, &ioctrl); - - // Call filesystem - nResult = FS_Ioctrl(func, &ioctrl); - - // Apply results - if (nResult >= 0) - SetIoctrl(param, func, &ioctrl); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $56 - Flush -// -// in (offset size) -// 1 1.b unit number -// -//--------------------------------------------------------------------------- -DWORD Flush(void) -{ - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Call filesystem - nResult = FS_Flush(); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $57 - Media change check -// -// in (offset size) -// 0 1.b constant (26) -// 1 1.b unit number -// 2 1.b Command ($57/$d7) -// out (offset size) -// 3 1.b error code (lower) -// 4 1.b '' (upper) -// 18 1.l result status -// -// Checks if the media has been changed or not. Format if it has changed. -// The verification is done within this command. -// -//--------------------------------------------------------------------------- -DWORD CheckMedia(void) -{ - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Call filesystem - nResult = FS_CheckMedia(); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// $58 - Lock -// -// in (offset size) -// 1 1.b unit number -// -//--------------------------------------------------------------------------- -DWORD Lock(void) -{ - int nResult; - - ASSERT(this); - ASSERT(fs); - - // Call filesystem - nResult = FS_Lock(); - - return nResult; -} - -//--------------------------------------------------------------------------- -// -// Execute command -// -//--------------------------------------------------------------------------- -DWORD ExecuteCommand() -{ - ASSERT(this); - - // Clear error data - SetReqByte(3, 0); - SetReqByte(4, 0); - - // Command number - command = (DWORD)GetReqByte(2); // Bit 7 is verify flag - - // Unit number - unit = GetReqByte(1); - - // Command branching - switch (command & 0x7F) { - case 0x40: return InitDevice(); // $40 - Device startup - case 0x41: return CheckDir(); // $41 - Directory check - case 0x42: return MakeDir(); // $42 - Create directory - case 0x43: return RemoveDir(); // $43 - Delete directory - case 0x44: return Rename(); // $44 - Change file name - case 0x45: return Delete(); // $45 - Delete file - case 0x46: return Attribute(); // $46 - Get / set file attribute - case 0x47: return Files(); // $47 - Find file - case 0x48: return NFiles(); // $48 - Find next file - case 0x49: return Create(); // $49 - Create file - case 0x4A: return Open(); // $4A - Open file - case 0x4B: return Close(); // $4B - Close file - case 0x4C: return Read(); // $4C - Read file - case 0x4D: return Write(); // $4D - Write file - case 0x4E: return Seek(); // $4E - Seek file - case 0x4F: return TimeStamp(); // $4F - Get / set file timestamp - case 0x50: return GetCapacity();// $50 - Get capacity - case 0x51: return CtrlDrive(); // $51 - Inspect / control drive status - case 0x52: return GetDPB(); // $52 - Get DPB - case 0x53: return DiskRead(); // $53 - Read sectors - case 0x54: return DiskWrite(); // $54 - Write sectors - case 0x55: return Ioctrl(); // $55 - IOCTRL - case 0x56: return Flush(); // $56 - Flush - case 0x57: return CheckMedia(); // $57 - Media change check - case 0x58: return Lock(); // $58 - Lock - } - - return FS_FATAL_INVALIDCOMMAND; -} - -//--------------------------------------------------------------------------- -// -// Initialization -// -//--------------------------------------------------------------------------- -BOOL Init() -{ - ASSERT(this); - - return SCSI_Init(); -} - -//--------------------------------------------------------------------------- -// -// Execution -// -//--------------------------------------------------------------------------- -void Process(DWORD nA5) -{ - ASSERT(this); - ASSERT(nA5 <= 0xFFFFFF); - ASSERT(m_bAlloc); - ASSERT(m_bFree); - - // Request header address - request = (BYTE*)nA5; - - // Command execution - SetResult(ExecuteCommand()); -} diff --git a/src/x68k/RASDRV/BRIDGE.H b/src/x68k/RASDRV/BRIDGE.H deleted file mode 100644 index 1d531583..00000000 --- a/src/x68k/RASDRV/BRIDGE.H +++ /dev/null @@ -1,255 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator RaSCSI (*^..^*) -// for Raspberry Pi -// -// Powered by XM6 TypeG Technology. -// Copyright (C) 2016-2017 GIMONS -// [ Host Filesystem Bridge Driver ] -// -//--------------------------------------------------------------------------- - -#ifndef bridge_h -#define bridge_h - -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned long DWORD; -typedef int BOOL; - -#if !defined(FALSE) -#define FALSE 0 -#endif - -#if !defined(TRUE) -#define TRUE 1 -#endif - -#define FASTCALL -#define ASSERT(x) - -//--------------------------------------------------------------------------- -// -// Constant definitions -// -//--------------------------------------------------------------------------- -#define FILEPATH_MAX _MAX_PATH -#define WINDRV_CLIPSIZE_MAX 0xC00000 - -//--------------------------------------------------------------------------- -// -// Status code definitions -// -//--------------------------------------------------------------------------- -#define FS_INVALIDFUNC 0xFFFFFFFF // Executed an invalid function -#define FS_FILENOTFND 0xFFFFFFFE // The selected file can not be found -#define FS_DIRNOTFND 0xFFFFFFFD // The selected directory can not be found -#define FS_OVEROPENED 0xFFFFFFFC // There are too many files open -#define FS_CANTACCESS 0xFFFFFFFB // Can not access the direcory or volume -#define FS_NOTOPENED 0xFFFFFFFA // The selected handle is not opened -#define FS_INVALIDMEM 0xFFFFFFF9 // Memory management has been destroyed -#define FS_OUTOFMEM 0xFFFFFFF8 // Insufficient memory for execution -#define FS_INVALIDPTR 0xFFFFFFF7 // Selected an invalid memory management pointer -#define FS_INVALIDENV 0xFFFFFFF6 // Selected an invalid environment -#define FS_ILLEGALFMT 0xFFFFFFF5 // The exeucted file is in an invalid format -#define FS_ILLEGALMOD 0xFFFFFFF4 // Invalid open access mode -#define FS_INVALIDPATH 0xFFFFFFF3 // Mistake in selected file name -#define FS_INVALIDPRM 0xFFFFFFF2 // Called with an invalid parameter -#define FS_INVALIDDRV 0xFFFFFFF1 // Mistake in selected drive -#define FS_DELCURDIR 0xFFFFFFF0 // Unable to delete the current directory -#define FS_NOTIOCTRL 0xFFFFFFEF // Unable to use IOCTRL with the device -#define FS_LASTFILE 0xFFFFFFEE // Can not find any more files -#define FS_CANTWRITE 0xFFFFFFED // Selected file can not be written -#define FS_DIRALREADY 0xFFFFFFEC // Selected directory is already registered -#define FS_CANTDELETE 0xFFFFFFEB // Can not delete because of a file -#define FS_CANTRENAME 0xFFFFFFEA // Can not rename because of a file -#define FS_DISKFULL 0xFFFFFFE9 // Can not create a file because the disk is full -#define FS_DIRFULL 0xFFFFFFE8 // Can not create a file because the directory is full -#define FS_CANTSEEK 0xFFFFFFE7 // Can not seek in the selected location -#define FS_SUPERVISOR 0xFFFFFFE6 // Selected supervisor in supervisor mode -#define FS_THREADNAME 0xFFFFFFE5 // A thread with this name already exists -#define FS_BUFWRITE 0xFFFFFFE4 // Writing to inter-process communication buffers is disallowed -#define FS_BACKGROUND 0xFFFFFFE3 // Unable to start a background process -#define FS_OUTOFLOCK 0xFFFFFFE0 // Insufficient lock space -#define FS_LOCKED 0xFFFFFFDF // Can not access because it is locked -#define FS_DRIVEOPENED 0xFFFFFFDE // Selected drive has an open handler -#define FS_LINKOVER 0xFFFFFFDD // The symbolic link is nested over 16 times -#define FS_FILEEXIST 0xFFFFFFB0 // The file exists - -#define FS_FATAL_MEDIAOFFLINE 0xFFFFFFA3 // No media inserted -#define FS_FATAL_WRITEPROTECT 0xFFFFFFA2 // Write protected -#define FS_FATAL_INVALIDCOMMAND 0xFFFFFFA1 // Invalid command number -#define FS_FATAL_INVALIDUNIT 0xFFFFFFA0 // Invalid unit number - -#define HUMAN68K_PATH_MAX 96 // Longest path allowed in Human68k - -//=========================================================================== -// -/// Human68k name space -// -//=========================================================================== -/// File attribute bit -enum attribute_t { - AT_READONLY = 0x01, // Read only attribute - AT_HIDDEN = 0x02, // Hidden attribute - AT_SYSTEM = 0x04, // System attribute - AT_VOLUME = 0x08, // Volume label attribute - AT_DIRECTORY = 0x10, // Directory attribute - AT_ARCHIVE = 0x20, // Archive attribute - AT_ALL = 0xFF, // All attribute bits are 1 -}; - -/// File open modes -enum open_t { - OP_READ = 0, // Read - OP_WRITE = 1, // Write - OP_FULL = 2, // Read/Write - OP_MASK = 0x0F, // Decision mask - OP_SHARE_NONE = 0x10, // Sharing forbidden - OP_SHARE_READ = 0x20, // Read sharing - OP_SHARE_WRITE = 0x30, // Write sharing - OP_SHARE_FULL = 0x40, // Read/Write sharing - OP_SHARE_MASK = 0x70, // Sharing decision mask - OP_SPECIAL = 0x100, // Dictionary access -}; - -/// Seek types -enum seek_t { - SK_BEGIN = 0, // From the beginning of a file - SK_CURRENT = 1, // From the current location - SK_END = 2, // From the end of the file -}; - -/// Media byte -enum media_t { - MEDIA_2DD_10 = 0xE0, // 2DD/10 sector - MEDIA_1D_9 = 0xE5, // 1D/9 sector - MEDIA_2D_9 = 0xE6, // 2D/9 sector - MEDIA_1D_8 = 0xE7, // 1D/8 sector - MEDIA_2D_8 = 0xE8, // 2D/8 sector - MEDIA_2HT = 0xEA, // 2HT - MEDIA_2HS = 0xEB, // 2HS - MEDIA_2HDE = 0xEC, // 2DDE - MEDIA_1DD_9 = 0xEE, // 1DD/9 sector - MEDIA_1DD_8 = 0xEF, // 1DD/8 sector - MEDIA_MANUAL = 0xF1, // Remote drive (manual eject) - MEDIA_REMOVABLE = 0xF2, // Remote drive (removable) - MEDIA_REMOTE = 0xF3, // Remote drive - MEDIA_DAT = 0xF4, // SCSI-DAT - MEDIA_CDROM = 0xF5, // SCSI-CDROM - MEDIA_MO = 0xF6, // SCSI-MO - MEDIA_SCSI_HD = 0xF7, // SCSI-HD - MEDIA_SASI_HD = 0xF8, // SASI-HD - MEDIA_RAMDISK = 0xF9, // RAM disk - MEDIA_2HQ = 0xFA, // 2HQ - MEDIA_2DD_8 = 0xFB, // 2DD/8 sector - MEDIA_2DD_9 = 0xFC, // 2DD/9 sector - MEDIA_2HC = 0xFD, // 2HC - MEDIA_2HD = 0xFE, // 2HD -}; - -/// namests struct -typedef struct { - BYTE wildcard; // Wildcard character length - BYTE drive; // Drive number - BYTE path[65]; // Path (subdirectory +/) - BYTE name[8]; // File name (PADDING 0x20) - BYTE ext[3]; // Extension (PADDING 0x20) - BYTE add[10]; // File name addition (PADDING 0x00) -} namests_t; - -/// files struct -typedef struct { - BYTE fatr; // + 0 search attribute; read-only - BYTE pad1[3]; // padding -// BYTE drive; // + 1 drive number; read-only - DWORD sector; // + 2 directory sector; DOS _FILES first address substitute -// WORD cluster; // + 6 directory cluster; details unknown (unused) - WORD offset; // + 8 directory entry; write-only -// BYTE name[8]; // +10 working file name; write-only (unused) -// BYTE ext[3]; // +18 working extension; write-only (unused) - BYTE attr; // +21 file attribute; write-only - BYTE pad2; // padding - WORD time; // +22 last change time of day; write-only - WORD date; // +24 last change date; write-only - DWORD size; // +26 file size; write-only - BYTE full[23]; // +30 full name; write-only - BYTE pad3; // padding -} files_t; - -/// FCB\ -typedef struct { -// BYTE pad00[6]; // + 0~+ 5 (unused) - DWORD fileptr; // + 6~+ 9 file pointer -// BYTE pad01[4]; // +10~+13 (unused) - WORD mode; // +14~+15 open mode -// BYTE pad02[16]; // +16~+31 (unused) -// DWORD zero; // +32~+35 zeros are written when opened (unused) -// BYTE name[8]; // +36~+43 file name (PADDING 0x20) (unused) -// BYTE ext[3]; // +44~+46 extension (PADDING 0x20) (unused) - BYTE attr; // +47 file attribute -// BYTE add[10]; // +48~+57 file name addition (PADDING 0x00) (unused) - WORD time; // +58~+59 last change time of day - WORD date; // +60~+61 last change date -// WORD cluster; // +62~+63 cluster number (unused) - DWORD size; // +64~+67 file size -// BYTE pad03[28]; // +68~+95 FAT cache (unused) -} fcb_t; - -/// capacity struct -typedef struct { - WORD freearea; // + 0 Number of available clusters - WORD clusters; // + 2 Total number of clusters - WORD sectors; // + 4 Number of sectors per cluster - WORD bytes; // + 6 Number of bytes per sector -} capacity_t; - -/// ctrldrive struct -typedef struct { - BYTE status; // +13 status - BYTE pad[3]; // padding -} ctrldrive_t; - -/// DPB struct -typedef struct { - WORD sector_size; // + 0 Number of bytes in one sector - BYTE cluster_size; // + 2 Number sectors in one cluster -1 - BYTE shift; // + 3 Number of clustersector shifts - WORD fat_sector; // + 4 FAT first sector number - BYTE fat_max; // + 6 FAT storage quantity - BYTE fat_size; // + 7 FAT controlled sector number (excluding duplicates) - WORD file_max; // + 8 Number of files in the root directory - WORD data_sector; // +10 First sector number of data storage - WORD cluster_max; // +12 Total number of clusters +1 - WORD root_sector; // +14 First sector number of root directory -// DWORD driverentry; // +16 Device driver pointer (unused) - BYTE media; // +20 Media identifier -// BYTE flag; // +21 Flag used by DPB (unused) - BYTE pad; // padding -} dpb_t; - -/// Directory entry struct -typedef struct { - BYTE name[8]; // + 0 File name (PADDING 0x20) - BYTE ext[3]; // + 8 Extension (PADDING 0x20) - BYTE attr; // +11 File attribute - BYTE add[10]; // +12 File name addition (PADDING 0x00) - WORD time; // +22 Last change time of day - WORD date; // +24 Last change date - WORD cluster; // +26 Cluster number - DWORD size; // +28 File size -} dirent_t; - -/// IOCTRL parameter union -typedef union { - BYTE buffer[8]; // Access in byte units - DWORD param; // Parameter (First 4 bytes) - WORD media; // Media byte (First 2 bytes) -} ioctrl_t; - -/// Command line parameter struct -typedef struct { - BYTE buf[256]; // Command line argument -} argument_t; - -#endif // bridge_h diff --git a/src/x68k/RASDRV/Makefile b/src/x68k/RASDRV/Makefile deleted file mode 100644 index 4a449de3..00000000 --- a/src/x68k/RASDRV/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# -# Makefile for RASDRV.SYS -# - -CC = gcc -O2 -Wall -fomit-frame-pointer -AS = has -LK = hlk -l -x - -RASDRV.SYS : RASDRV.o BRIDGE.o - $(LK) -o $@ $^ libc.a libiocs.a libscsi.a - -RASDRV.o : RASDRV.S - $(AS) $^ - -BRIDGE.o : BRIDGE.C - $(CC) -c -o $@ $^ - \ No newline at end of file diff --git a/src/x68k/RASDRV/RASDRV.S b/src/x68k/RASDRV/RASDRV.S deleted file mode 100644 index 6eb0a848..00000000 --- a/src/x68k/RASDRV/RASDRV.S +++ /dev/null @@ -1,193 +0,0 @@ -*--------------------------------------------------------------------------- -* -* SCSI Target Emulator RaSCSI (*^..^*) -* for Raspberry Pi -* -* Powered by XM6 TypeG Technology. -* Copyright (C) 2016-2019 GIMONS -* [ Host Filesystem Bridge Driver ] -* -* Based on -* X68k Emulator Host Filesystem Driver version 0.27 -* Programmed By co -* -*--------------------------------------------------------------------------- - - CPU 68010 - - INCLUDE DOSCALL.MAC - INCLUDE IOCSCALL.MAC - -.XREF _Init, _Process ;bridge.c - -COMMAND EQU 2 Command number -ERRLOW EQU 3 Error code lower 8 bits -ERRHIGH EQU 4 Error code upper 8 bits -MXUNIT EQU 13 Number of units -DEVEND EQU 14 Driver exit address -BDEVNO EQU 22 Base drive number - -DDHEADER: - DC.L -1 +$00 Link pointer - DC.W $2040 +$04 Device attribute - DC.L DDSTRATEGY +$06 - DC.L DDENTRY_FIRST +$0A - DC.B '*EMUHOST' +$0E Device name - -DDREQUEST: - DC.L 0 - -DDSTRATEGY: - MOVE.L A5,DDREQUEST - RTS - -*Device driver entry -DDENTRY: - MOVE.L SP,(STACK_BUFF) - LEA (DEF_STACK),SP - MOVEM.L D1-D3/A0-A2,-(SP) - MOVEM.L DDREQUEST(PC),D0 D0.L: Request header address - MOVE.L D0,-(SP) - BSR _Process - ADDQ.L #4,SP - MOVEM.L (SP)+,D1-D3/A0-A2 - MOVEA.L (STACK_BUFF),SP - RTS - -KEEP_HERE: - -*First time only device driver entry -DDENTRY_FIRST: - MOVEM.L D1-D3/A0-A2/A5,-(SP) - MOVEA.L DDREQUEST(PC),A5 A5.L: Request header address -* CMPI.B #$40,COMMAND(A5) No need to check when Human68k is running -* BNE UNSUPPORTED Error: Not supported - -*Show title - PEA MESSAGE_TITLE(PC) - DOS _PRINT - ADDQ.L #4,SP - -*Device check -DEVICE_CHECK: - BSR _Init - - TST.L D0 - BEQ NOTFOUND Error: Device not found - -*Resident program start - LEA DDENTRY(PC),A1 - - LEA DDHEADER+$0A(PC),A0 - MOVE.L A1,(A0) Configure driver entry - MOVE.L #PROG_END,DEVEND(A5) Configure resident exit address - - ST.B MXUNIT(A5) Set negative number since port is considered unimplemented - JSR (A1) Execute driver entry - - TST.B MXUNIT(A5) Verify number of units - BLE NODRIVE Error: No drive - - MOVE.B BDEVNO(A5),D0 - MOVE.B MXUNIT(A5),D1 - LEA FIRSTDRIVE(PC),A0 - ADD.B D0,(A0) Overwrite start drive name - ADD.B D1,D0 Overwrite stop drive name - ADD.B D0,LASTDRIVE-FIRSTDRIVE(A0) - - PEA MESSAGE_DRIVENAME(PC) Normal: Drive A: - DOS _PRINT - - PEA MESSAGE_DRIVENAME2(PC) Normal: to Z: - SUBQ.B #2,D1 - BCS @F - DOS _PRINT -@@ ADDQ.L #8,SP - - PEA MESSAGE_DRIVENAME3(PC) Normal: was registered - BRA QUIT - -NOTFOUND: - PEA MESSAGE_NOTFOUND(PC) Error: Device not found - BRA ABORT - -UNSUPPORTED: - PEA MESSAGE_UNSUPPORTED(PC) Error: Not supported - BRA ABORT - -NODRIVE: - PEA MESSAGE_NODRIVE(PC) Error: No drive - -ABORT: - MOVE.B #$0D,ERRLOW(A5) - MOVE.B #$70,ERRHIGH(A5) - -QUIT: - DOS _PRINT - ADDQ.L #4,SP - - MOVEM.L (SP)+,D1-D3/A0-A2/A5 - RTS - -SECRET: - PEA MESSAGE_TITLE2(PC) - DOS _PRINT - PEA CREDIT(PC) - DOS _PRINT - ADDQ.L #8,SP - DOS _EXIT - - DATA - -*Error messages -MESSAGE_NOTFOUND: - DC.B 'Device not found',$0D,$0A,0 - -MESSAGE_UNSUPPORTED: - DC.B 'Not supported',$0D,$0A,0 - -MESSAGE_NODRIVE: - DC.B 'No drive',$0D,$0A,0 - -*Registration messages -MESSAGE_DRIVENAME: - DC.B 'Drive' -FIRSTDRIVE: - DC.B 'A:',0 -MESSAGE_DRIVENAME2: - DC.B ' to ' -LASTDRIVE: - DC.B '@:',0 -MESSAGE_DRIVENAME3: - DC.B ' was registered',$0D,$0A,0 - -*Title -MESSAGE_TITLE: - DC.B $0D,$0A -MESSAGE_TITLE2: - DC.B 'RaSCSI FileSystem Driver version 1.42',$0D,$0A,0 - -*Thanks! -CREDIT: - DC.B 'Coded by GIMONS',$0D,$0A - DC.B 'Special thanks to',$0D,$0A - DC.B 9,'co',$0D,$0A - DC.B 9,'PI.',$0D,$0A - DC.B 9,'Tachibana@Kuwashima Giken',$0D,$0A - DC.B 0 - - BSS - QUAD - -STACK_BUFF: - .DS.L 1 - - STACK - QUAD - - .DS.B 1024*2 -DEF_STACK: - - -PROG_END: - END SECRET diff --git a/src/x68k/RASETHER/Makefile b/src/x68k/RASETHER/Makefile deleted file mode 100644 index 92557b33..00000000 --- a/src/x68k/RASETHER/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -# -# Makefile for RASETHER.SYS -# - -TARGET = RASETHER.SYS - -OBJS = re.o asmsub.o main.o scsictl.o -LIBS = libc.a libgnu.a libscsi.a - -CC = gcc -O2 -Wall -fomit-frame-pointer -CFLAGS = -D__DOS_INLINE__ -D__IOCS_INLINE__ -#CFLAGS = -D__DOS_INLINE__ -D__IOCS_INLINE__ -DUSE_DMA - -AS = has -ASFLAGS = -LD = hlk -LDFLAGS = -l -x - -all: $(TARGET) - -$(TARGET): $(OBJS) - $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) - -scsictl.o: scsictl.c scsictl.h - $(COMPILE.c) $< - -main.o: main.c main.h scsictl.h - $(COMPILE.c) $< - -asmsub.o: asmsub.s - -# EOF - \ No newline at end of file diff --git a/src/x68k/RASETHER/asmsub.s b/src/x68k/RASETHER/asmsub.s deleted file mode 100644 index 87d85957..00000000 --- a/src/x68k/RASETHER/asmsub.s +++ /dev/null @@ -1,22 +0,0 @@ -* asmsub.s - - .xdef _DI, _EI * ne2000.c nagai. - - .text - .even - - - -_DI: - move.w sr,sendp_sr - ori.w #$700,sr - rts -_EI: - move.w sendp_sr,sr - rts - -sendp_sr: - .ds.w 1 - - - .even diff --git a/src/x68k/RASETHER/main.c b/src/x68k/RASETHER/main.c deleted file mode 100644 index 17cf4bce..00000000 --- a/src/x68k/RASETHER/main.c +++ /dev/null @@ -1,282 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator RaSCSI (*^..^*) -// for Raspberry Pi -// -// Powered by XM6 TypeG Technology. -// Copyright (C) 2016-2017 GIMONS -// [ RaSCSI Ethernet Main ] -// -// Based on -// Neptune-X board driver for Human-68k(ESP-X) version 0.03 -// Programed 1996-7 by Shi-MAD. -// Special thanks to Niggle, FIRST, yamapu ... -// -//--------------------------------------------------------------------------- - -#include -#include -#include -#include "main.h" -#include "scsictl.h" - -unsigned int scsiid; -int trap_no; -int num_of_prt; -struct prt PRT_LIST[NPRT]; - -// Multicast (not supported) -#ifdef MULTICAST -int num_of_multicast; -struct eaddr multicast_array[NMULTICAST]; -#endif - -/************************************************ - * * - ************************************************/ -static int sprint_eaddr(unsigned char* dst, void* e) -{ - unsigned char* p = e; - - return sprintf( - dst, - "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", - p[0], p[1], p[2], p[3], p[4], p[5]); -} - -/************************************************ - * Check if TRAP n can be used * - ************************************************/ -static int is_valid_trap(int trap_no) -{ - unsigned int addr; - - if (trap_no < 0 || 7 < trap_no) { - return 0; - } - - // Check if in use - addr = (unsigned int)_dos_intvcg(TRAP_VECNO(trap_no)); - - // Unused if the uppermost byte of the process address contains the vector number - if (addr & 0xff000000) { - return -1; - } - - return 0; -} - -/************************************************ - * Search for unused TRAP n * - ************************************************/ -static int search_trap_no(int def) -{ - int i; - - // If def is usable, choose that - if (is_valid_trap(def)) { - return def; - } - - for (i = 0; i <= 6; i++) { - if (is_valid_trap(i)) { - return i; - } - } - - return -1; -} - -/************************************************ - * vector set * - ************************************************/ -static void* trap_vector(int trap_no, void *func) -{ - return _dos_intvcs(TRAP_VECNO(trap_no), func); -} - -/************************************************ - * Init Function (call with ne.s initialize) * - ************************************************/ -int Initialize(void) -{ - unsigned char buff[128]; - unsigned char buff2[32]; - struct eaddr ether_addr; - - if (SearchRaSCSI()) - { - Print("Could not locate the RaSCSI Ethernet Adapter\r\n"); - return -1; - } - - if (InitList(NPRT) - || InitRaSCSI()) - { - Print("Failed to initialize the RaSCSI Ethernet Adapter Driver\r\n"); - return -1; - } - - memset(ðer_addr, 0x00, sizeof(ether_addr)); - GetMacAddr(ðer_addr); - - // Inspect unused trap number (prioritize specified number) - if (trap_no >= 0) { - trap_no = search_trap_no(trap_no); - } - - if (trap_no >= 0) { - // Hook the trap - trap_vector(trap_no, (void*)trap_entry); - sprintf(buff, " API trap number:%d ", trap_no); - } else { - sprintf(buff, " API trap number:n/a "); - } - Print(buff); - - sprintf(buff, "SCSI ID:%d ", scsiid); - Print(buff); - - sprint_eaddr(buff2, ether_addr.eaddr); - sprintf(buff, "MAC Addr:%s\r\n", buff2); - Print(buff); - - // Start polling - RegisterIntProcess(poll_interval); - - return 0; -} - -/************************************************ - * Initialize Protocol List * - ************************************************/ -int InitList(int n) -{ - struct prt* p; - int i; - - p = &PRT_LIST[0]; - for (i = 0; i < NPRT; i++, p++) { - p->type = -1; - p->func = 0; - p->malloc = (malloc_func)-1; - } - num_of_prt = 0; - -#ifdef MULTICAST - num_of_multicast = 0; -#endif - - return 0; -} - -/************************************************ - * Add Receive Handler (protocol) * - ************************************************/ -int AddList(int type, int_handler handler) -{ - struct prt* p; - int i, result; - - if (type == -1) { - return -1; - } - - result = -1; - - // overwrite if already exist - p = &PRT_LIST[0]; - for (i = 0; i < NPRT; i++, p++) { - if ((p->type == type && p->malloc != (malloc_func)-1) - || p->type == -1) - { - if (p->type == -1) - num_of_prt++; - - p->type = type; - p->func = handler; - p->malloc = (malloc_func)-1; - i++; - p++; - result = 0; - break; - } - } - - // clear if exist more - for (; i < NPRT; i++, p++) { - if (p->type == type && p->malloc != (malloc_func)-1) { - p->type = -1; - } - } - - return result; -} - -/************************************************ - * Delete Receive Handler (protocol) * - ************************************************/ -int DeleteList(int type) -{ - struct prt* p; - int i, result; - - if (type == -1) { - return -1; - } - - result = -1; - for (i = 0, p = &PRT_LIST[0]; i < NPRT; i++, p++) { - if (p->type == type && p->malloc != (malloc_func)-1) { - p->type = -1; - result = 0; - num_of_prt--; - } - } - - return result; -} - -/************************************************ - * Search Receive Handler (protocol) * - ************************************************/ -int_handler SearchList(int type) -{ - struct prt* p; - int i; - - if (type == -1) { - return 0; - } - - for (i = 0, p = &PRT_LIST[0]; i < NPRT; i++, p++) { - if (p->type == type) { - return p->func; - } - } - - return 0; -} - - -/************************************************ - * Search Receive Handler (protocol) * - ************************************************/ -int_handler SearchList2(int type, int n) -{ - struct prt *p; - int i, cur; - - if (type == -1) { - return NULL; - } - - cur = 0; - for (i = 0, p = &PRT_LIST[0]; i < NPRT; i++, p++) { - if (p->type == type && cur++ == n) { - return p->func; - } - } - - return NULL; -} diff --git a/src/x68k/RASETHER/main.h b/src/x68k/RASETHER/main.h deleted file mode 100644 index 68a41cee..00000000 --- a/src/x68k/RASETHER/main.h +++ /dev/null @@ -1,81 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator RaSCSI (*^..^*) -// for Raspberry Pi -// -// Powered by XM6 TypeG Technology. -// Copyright (C) 2016-2017 GIMONS -// [ RaSCSI Ethernet Main ] -// -// Based on -// Neptune-X board driver for Human-68k(ESP-X) version 0.03 -// Programed 1996-7 by Shi-MAD. -// Special thanks to Niggle, FIRST, yamapu ... -// -//--------------------------------------------------------------------------- - -#ifndef main_h -#define main_h - -#define ID_EN0 (('e'<<24)+('n'<<16)+('0'<<8)) -#undef MULTICAST - -// number of protocol type we can handle **EDIT this** -#define NPRT (16) - -// number of multicast address we can handle **EDIT this** -#define NMULTICAST (64) -/* However, multicast is not yet supported */ - -struct eaddr { - unsigned char eaddr [6]; -}; - -typedef void (*int_handler) (int, void*, int); -typedef void (*malloc_func) (unsigned int*); - -struct prt { - int type; - int_handler func; - malloc_func malloc; -}; - - -// Global variables -extern unsigned int scsiid; -extern int trap_no; -extern int num_of_prt; -extern struct prt PRT_LIST [NPRT]; - -#ifdef MULTICAST -extern int num_of_multicast; -extern struct eaddr multicast_array [NMULTICAST]; -#endif - - -// Prototype declarations -extern int Initialize (void); -extern int InitList (int); -extern int AddList (int, int_handler); -extern int DeleteList (int); -extern int_handler SearchList (int); -extern int_handler SearchList2 (int, int); -extern malloc_func GetMallocFunc (int, int); - -#ifdef MULTICAST -extern int AddMulticastArray (struct eaddr*); -extern void DelMulticastArray (struct eaddr*); -extern void MakeMulticastTable (unsigned char*); -#endif - - -// Function within ne.s -extern void trap_entry (void); - - -#include -#define Print _iocs_b_print - -#define TRAP_VECNO(n) (0x20 + n) - -#endif // main_h diff --git a/src/x68k/RASETHER/re.s b/src/x68k/RASETHER/re.s deleted file mode 100644 index 1ff0c65b..00000000 --- a/src/x68k/RASETHER/re.s +++ /dev/null @@ -1,574 +0,0 @@ -**--------------------------------------------------------------------------- -** -** SCSI Target Emulator RaSCSI (*^..^*) -** for Raspberry Pi -** -** Powered by XM6 TypeG Technology. -** Copyright (C) 2016-2017 GIMONS -** [ RaSCSI Ethernet Driver ] -** -** Based on -** Neptune-X board driver for Human-68k(ESP-X) version 0.03 -** Programed 1996-7 by Shi-MAD. -** Special thanks to Niggle, FIRST, yamapu ... -** -**--------------------------------------------------------------------------- - -* Include Files ----------------------- * - - .include doscall.mac - .include iocscall.mac - - -* Global Symbols ---------------------- * - -* -* For C language: external declarations -* - .xref _Initialize, _AddList, _SearchList, _DeleteList ;main.c - .xref _GetMacAddr, _SetMacAddr ;scsictl.c - .xref _SendPacket, _SetPacketReception ;scsictl.c -* .xref _AddMulticastAddr, _DelMulticastAddr ;not implemented - -* -* For C language: external functions -* - .xref _num_of_prt ;main.c Number of registered protocols - .xref _trap_no ;Used trap number - .xref _trans_counter ;scsictl.c Number of send/receive bytes - .xref _intr_type ;scsictl.c Type of interrupt - .xref _poll_interval ;scsictl.c Polling interval - - -* Text Section -------------------------------- * - - .cpu 68000 - .text - - -* -* Device Header -* -device_header: - .dc.l -1 ;link pointer - .dc $8000 ;device att. - .dc.l strategy_entry ;strategy entry - .dc.l interupt_entry ;interrupt entry - .dc.b '/dev/en0' ;device name - .dc.b 'EthD' ;for etherlib.a - .dc.b 'RASC' ;driver name (put in entry later) - -* Don not put anything between 'RASC' and superjsr_entry - -* -* Ether Driver Function Entry ( for DOS _SUPERJSR ) -* in: d0: command number -* a0: args -* -superjsr_entry: - movem.l d1-d7/a1-a7,-(sp) - -* move.l d0,-(sp) -* pea (mes11,pc) -* DOS _PRINT -* addq.l #4,sp -* move.l (sp)+,d0 -* .data -*mes11: .dc.b 'en0:spjEntry',13,10,0 -* .text - - bsr do_command - movem.l (sp)+,d1-d7/a1-a7 - rts ;normal return - - -* -* Ether Driver Function Entry ( for trap #n ) -* in: d0: command number -* a0: args -* -_trap_entry:: - movem.l d1-d7/a1-a7,-(sp) - -* move.l d0,-(sp) -* pea (mes10,pc) -* DOS _PRINT -* addq.l #4,sp -* move.l (sp)+,d0 -* .data -*mes10: .dc.b 'en0:trapEntry',13,10,0 -* .text - - bsr do_command - movem.l (sp)+,d1-d7/a1-a7 - rte ;interrupt return - - -* -* Assign each command -* -do_command: - moveq #FUNC_MIN,d1 - cmp.l d0,d1 - bgt error ;d0<-2 is an unsupported command number - moveq #FUNC_MAX,d1 - cmp.l d1,d0 - bgt error ;9) - .dc get_statistics-jumptable ;09 ... (Read out statistics ) -FUNC_MAX: .equ ($-jumptable)/2-1 - - -* -* Command -2: Return transfer counter address -* return: address -* -get_cnt_addr: - pea (_trans_counter,pc) - move.l (sp)+,d0 - rts - - -* -* Command -1: Return used trap number -* return: trap number to use (-1:use SUPERJSR) -* -driver_entry: -* pea (mesff,pc) -* DOS _PRINT -* addq.l #4,sp -* .data -*mesff: .dc.b 'DriverEntry',13,10,0 -* .text - - move.l (_trap_no,pc),d0 ;trap_no ... main.c variable - rts - - -* -* Command 00: Return driver version -* return: version number (Ex... for ver1.00 return 100) -* -get_driver_version: -* pea (mes00,pc) -* DOS _PRINT -* addq.l #4,sp -* .data -*mes00: .dc.b 'GetDriverVersion',13,10,0 -* .text - - moveq #3,d0 ;ver 0.03 - rts - - -* -* Command 01: Get current MAC address -* return: same as *dst -* -get_mac_addr: -* pea (mes01,pc) -* DOS _PRINT -* addq.l #4,sp -* .data -*mes01: .dc.b 'GetMacAddr',13,10,0 -* .text - - pea (a0) - pea (a0) - bsr _GetMacAddr ;scsictl.c function - addq.l #4,sp - move.l (sp)+,d0 ;Return d0 for parameter a0 - rts - -* -* Command 02: Get MAC address written to EEPROM -* return: same as *dst -* -get_prom_addr: -* pea (mes02,pc) -* DOS _PRINT -* addq.l #4,sp -* .data -*mes02: .dc.b 'GePromAddr',13,10,0 -* .text - - pea (a0) - pea (a0) - bsr _GetMacAddr ;scsictl.c function - addq.l #4,sp - move.l (sp)+,d0 ;Return d0 for parameter a0 - rts - -* -* Command 03: Set MAC address -* return: 0 (if no errors) -* -set_mac_addr: -* pea (mes03,pc) -* DOS _PRINT -* addq.l #4,sp -* .data -*mes03: .dc.b 'SetMacAddr',13,10,0 -* .text - - pea (a0) - bsr _SetMacAddr ;scsictl.c function - addq.l #4,sp - rts - - -* -* Command 04: Send packet -* packet contents: -* Distination MAC: 6 bytes -* Source(own) MAC: 6 bytes -* Protcol type: 2 bytes -* Data: ? bytes -* return: 0 (if no errors) -* -send_packet: -* pea (mes04,pc) -* DOS _PRINT -* addq.l #4,sp - - move.l (a0)+,d0 ;packet size - move.l (a0),-(sp) ;packet address - move.l d0,-(sp) - bsr _SendPacket ;scsictl.c function - addq.l #8,sp - -* move.l d0,-(sp) -* pea (mes04e,pc) -* DOS _PRINT -* addq.l #4,sp -* move.l (sp)+,d0 -* .data -*mes04: .dc.b 13,10,'SendPacket,13,10',0 -*mes04e:.dc.b 13,10,'SendPacket finished',13,10,0 -* .text - - rts - - -* -* Command 05: Set / add receive interrupt handler -* type: 0x00000800 IP packet -* 0x00000806 ARP packet -* return: 0 (if no errors) -* -set_int_addr: -* pea (mes05,pc) -* DOS _PRINT -* addq.l #4,sp -* .data -*mes05: .dc.b 'SetIntAddr',13,10,0 -* .text - - move.l (a0)+,d0 ;protocol number - move.l (a0),-(sp) ;address to handler function - move.l d0,-(sp) - bsr _AddList ;main.c function - addq.l #8,sp - tst.l d0 - bmi set_int_addr_rts ;Registration failed - - cmpi.l #1,(_num_of_prt) ;Permit interrupt if number of handlers is 1 - bne set_int_addr_rts - - pea (1) ;1= - bsr _SetPacketReception ;interrupt permitted ... scsictl.c - addq.l #4,sp - -* moveq #0,d0 ;SetPacketReception() always returns 0 so bypass -set_int_addr_rts: - rts - - -* -* Command 06: Get interrupt handler and address -* return: interupt address -* -get_int_addr: -* pea (mes07,pc) -* DOS _PRINT -* addq.l #4,sp -* .data -*mes07: .dc.b 'GetIntAddr',13,10,0 -* .text - - pea (a0) - bsr _SearchList - addq.l #4,sp - rts - - -* -* Command 07: Delete interrupt handler -* return: 0 (if no errors) -* -del_int_addr: -* pea (mes06,pc) -* DOS _PRINT -* addq.l #4,sp -* .data -*mes06: .dc.b 'DelIntAddr',13,10,0 -* .text - - pea (a0) - bsr _DeleteList ;main.c function - move.l d0,(sp)+ - bmi del_int_addr_ret ;Delete failed - - tst.l (_num_of_prt) ;Forbid interrupts if handlers are gone - bne del_int_addr_ret - - clr.l -(sp) ;0= - bsr _SetPacketReception ;Interrupt forbitten ... scsictl.c - addq.l #4,sp - -* moveq #0,d0 ;SetPacketReception() always returns 0 so bypass -del_int_addr_ret: - rts - - -* -* Command 08: Set multicast address -* -set_multicast_addr: -* pea (mes08,pc) -* .data -* DOS _PRINT -* addq.l #4,sp -*mes08: .dc.b 'SetMulticastAddr',13,10,0 -* .text - - moveq #0,d0 - rts - - -* -* Command 09: Read out statistics -* -get_statistics: -* pea (mes09,pc) -* DOS _PRINT -* addq.l #4,sp -* .data -*mes09: .dc.b 'GetStatistics',13,10,0 -* .text - - moveq #0,d0 - rts - -* -* Device Driver Entry -* -strategy_entry: - move.l a5,(request_buffer) - rts - - -interupt_entry: - move.l sp,(stack_buff) ;Use own stack area - lea (def_stack),sp ; - - movem.l d1-d7/a0-a5,-(sp) - movea.l (request_buffer,pc),a5 - tst.b (2,a5) - bne errorret - - pea (mestitle,pc) - DOS _PRINT - addq.l #4,sp - movea.l (18,a5),a4 -@@: - tst.b (a4)+ - bne @b - - moveq #0,d0 - move.l d0,(_trap_no) - move.l d0,(_intr_type) - moveq #1,d0 - move.l d0,(_poll_interval) - -arg_loop: - move.b (a4)+,d0 - beq arg_end - cmpi.b #'-',d0 - beq @f - cmpi.b #'/',d0 - bne param_errret -@@: - move.b (a4)+,d0 - beq param_errret -opt_loop: - andi.b #$df,d0 - cmpi.b #'I',d0 - beq opt_i - cmpi.b #'P',d0 - beq opt_p - cmpi.b #'T',d0 - beq opt_t - cmpi.b #'N',d0 - beq opt_n - bra param_errret - -opt_n: - moveq #-1,d0 - move.l d0,(_trap_no) - move.b (a4)+,d0 - beq arg_loop - bra opt_loop - -opt_t: - bsr get_num - tst.b d0 - bne param_errret - cmpi #6,d2 - bgt param_errret - move.l d2,(_trap_no) - move.b (a4)+,d0 - beq arg_loop - bra opt_loop - -opt_p: - bsr get_num - tst.b d0 - bne param_errret - cmpi #1,d2 - blt param_errret - cmpi #8,d2 - bgt param_errret - move.l d2,(_poll_interval) - move.b (a4)+,d0 - beq arg_loop - bra opt_loop - -opt_i: - bsr get_num - tst.b d0 - bne param_errret - cmpi #1,d2 - bgt param_errret - move.l d2,(_intr_type) - move.b (a4)+,d0 - beq arg_loop - bra opt_loop - -arg_end: - bsr _Initialize ;main.c function - ;Set I/O address - ;Get MAC address - ;Init protocol list - ;Init SCSICTL - ;Interrupt handler (set vector) - ;trap service (set vector) - tst.l d0 - bne errorret - -* moveq #0,d0 - move.l #prog_end,(14,a5) - bra intret - - -param_errret: - pea (mesparam_err,pc) - DOS _PRINT - addq.l #4,sp -errorret: - move #$5003,d0 -intret: - move.b d0,(4,a5) - lsr #8,d0 - move.b d0,(3,a5) - movem.l (sp)+,d1-d7/a0-a5 - - movea.l (stack_buff,pc),sp ;Restore stack pointer - rts - -get_num: - moveq #1,d0 - moveq #0,d1 - moveq #0,d2 -@@: - move.b (a4),d1 - subi.b #'0',d1 - bcs @f - cmpi.b #9,d1 - bgt @f - move.b #0,d0 - andi #$f,d1 - mulu #10,d2 - add d1,d2 - addq.l #1,a4 - bra @b -@@: - rts - - -* Data Section ------------------------ * - - .data -mestitle: - .dc.b 13,10 - .dc.b 'RaSCSI Ethernet Driver version 1.20 / Based on ether_ne.sys+M01L12',13,10 - .dc.b 0 -mesparam_err: - .dc.b 'Invalid parameter',13,10,0 - .even - - -* BSS --------------------------------- * - - .bss - .quad - -stack_buff: - .ds.l 1 -request_buffer: - .ds.l 1 -stack_buff_i: - .ds.l 1 - - -* Stack Section ----------------------- * - - .stack - .quad - -* -* Stack area -* - .ds.b 1024*8 -def_stack: - -prog_end: - .end - - -* EOF --------------------------------- * diff --git a/src/x68k/RASETHER/scsictl.c b/src/x68k/RASETHER/scsictl.c deleted file mode 100644 index 9051710b..00000000 --- a/src/x68k/RASETHER/scsictl.c +++ /dev/null @@ -1,537 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator RaSCSI (*^..^*) -// for Raspberry Pi -// -// Powered by XM6 TypeG Technology. -// Copyright (C) 2016-2017 GIMONS -// [ RaSCSI Ethernet SCSI Control Department ] -// -// Based on -// Neptune-X board driver for Human-68k(ESP-X) version 0.03 -// Programed 1996-7 by Shi-MAD. -// Special thanks to Niggle, FIRST, yamapu ... -// -//--------------------------------------------------------------------------- - -#include -#include -#include -#include -#include -#include "main.h" -#include "scsictl.h" - -typedef struct -{ - char DeviceType; - char RMB; - char ANSI_Ver; - char RDF; - char AddLen; - char RESV0; - char RESV1; - char OptFunc; - char VendorID[8]; - char ProductID[16]; - char FirmRev[4]; -} INQUIRY_T; - -typedef struct -{ - INQUIRY_T info; - char options[8]; -} INQUIRYOPT_T; - -#define MFP_AEB 0xe88003 -#define MFP_IERB 0xe88009 -#define MFP_IMRB 0xe88015 - -// Subroutine in asmsub.s -extern void DI(); -extern void EI(); - -volatile short* iocsexec = (short*)0xa0e; // Work when executin IOCS -struct trans_counter trans_counter; // Transfer counter -unsigned char rx_buff[2048]; // Receive buffer -int imr; // Interrupt permission flag -int scsistop; // SCSI stopped flag -int intr_type; // Interrupt type (0:V-DISP 1:TimerA) -int poll_interval; // Polling interval (configure) -int poll_current; // Polling interval (current) -int idle; // Idle counter - -#define POLLING_SLEEP 255 // 4-5s - -/************************************************ - * Execute command to get MAC address * - ************************************************/ -int SCSI_GETMACADDR(unsigned char *mac) -{ - unsigned char cmd[10]; - unsigned char sts; - unsigned char msg; - - if (S_SELECT(scsiid) != 0) { - return 0; - } - - cmd[0] = 0x28; - cmd[1] = 0; - cmd[2] = 1; - cmd[3] = 0; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[7] = 0; - cmd[8] = 6; - cmd[9] = 0; - if (S_CMDOUT(10, cmd) != 0) { - return 0; - } - -#ifdef USE_DMA - if (S_DATAIN(6, mac) != 0) { -#else - if (S_DATAIN_P(6, mac) != 0) { -#endif - return 0; - } - - S_STSIN(&sts); - S_MSGIN(&msg); - - return 1; -} - -/************************************************ - * Execute command to configure MAC address * - ************************************************/ -int SCSI_SETMACADDR(const unsigned char *mac) -{ - unsigned char cmd[10]; - unsigned char sts; - unsigned char msg; - - if (S_SELECT(scsiid) != 0) { - return 0; - } - - cmd[0] = 0x2a; - cmd[1] = 0; - cmd[2] = 1; - cmd[3] = 0; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[7] = 0; - cmd[8] = 6; - cmd[9] = 0; - if (S_CMDOUT(10, cmd) != 0) { - return 0; - } - -#ifdef USE_DMA - S_DATAOUT(6, mac); -#else - S_DATAOUT_P(6, mac); -#endif - - S_STSIN(&sts); - S_MSGIN(&msg); - - return 1; -} - -/************************************************ - * Execute command to get received packet size* - ************************************************/ -int SCSI_GETPACKETLEN(int *len) -{ - unsigned char cmd[10]; - unsigned char buf[2]; - unsigned char sts; - unsigned char msg; - - if (S_SELECT(scsiid) != 0) { - return 0; - } - - cmd[0] = 0x28; - cmd[1] = 0; - cmd[2] = 1; - cmd[3] = 1; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = 0; - cmd[7] = 0; - cmd[8] = 2; - cmd[9] = 0; - if (S_CMDOUT(10, cmd) != 0) { - return 0; - } - -#ifdef USE_DMA - if (S_DATAIN(2, buf) != 0) { -#else - if (S_DATAIN_P(2, buf) != 0) { -#endif - return 0; - } - - S_STSIN(&sts); - S_MSGIN(&msg); - - *len = (int)(buf[0] << 8) + (int)(buf[1]); - - return 1; -} - -/************************************************ - * Execute receive packet command * - ************************************************/ -int SCSI_GETPACKETBUF(unsigned char *buf, int len) -{ - unsigned char cmd[10]; - unsigned char sts; - unsigned char msg; - - if (S_SELECT(scsiid) != 0) { - return 0; - } - - cmd[0] = 0x28; - cmd[1] = 0; - cmd[2] = 1; - cmd[3] = 1; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = (unsigned char)(len >> 16); - cmd[7] = (unsigned char)(len >> 8); - cmd[8] = (unsigned char)len; - cmd[9] = 1; - if (S_CMDOUT(10, cmd) != 0) { - return 0; - } - -#ifdef USE_DMA - if (S_DATAIN(len, buf) != 0) { -#else - if (S_DATAIN_P(len, buf) != 0) { -#endif - return 0; - } - - S_STSIN(&sts); - S_MSGIN(&msg); - - return 1; -} - -/************************************************ - * Execute packet send command * - ************************************************/ -int SCSI_SENDPACKET(const unsigned char *buf, int len) -{ - unsigned char cmd[10]; - unsigned char sts; - unsigned char msg; - - if (S_SELECT(scsiid) != 0) { - return 0; - } - - cmd[0] = 0x2a; - cmd[1] = 0; - cmd[2] = 1; - cmd[3] = 1; - cmd[4] = 0; - cmd[5] = 0; - cmd[6] = (unsigned char)(len >> 16); - cmd[7] = (unsigned char)(len >> 8); - cmd[8] = (unsigned char)len; - cmd[9] = 0; - if (S_CMDOUT(10, cmd) != 0) { - return 0; - } - -#ifdef USE_DMA - S_DATAOUT(len, buf); -#else - S_DATAOUT_P(len, buf); -#endif - S_STSIN(&sts); - S_MSGIN(&msg); - - return 1; -} - -/************************************************ - * Get MAC address * - ************************************************/ -int GetMacAddr(struct eaddr* buf) -{ - if (SCSI_GETMACADDR(buf->eaddr) != 0) { - return 0; - } else { - return -1; - } -} - -/************************************************ - * Set MAC address * - ************************************************/ -int SetMacAddr(const struct eaddr* data) -{ - if (SCSI_SETMACADDR(data->eaddr) != 0) { - return 0; - } else { - return -1; - } -} - -/************************************************ - * Search RaSCSI * - ************************************************/ -int SearchRaSCSI() -{ - int i; - INQUIRYOPT_T inq; - - for (i = 0; i <= 7; i++) { - // Search for BRIDGE device - if (S_INQUIRY(sizeof(INQUIRY_T) , i, (struct INQUIRY*)&inq) < 0) { - continue; - } - - if (memcmp(&(inq.info.ProductID), "RASCSI BRIDGE", 13) != 0) { - continue; - } - - // Get TAP initialization status - if (S_INQUIRY(sizeof(INQUIRYOPT_T) , i, (struct INQUIRY*)&inq) < 0) { - continue; - } - - if (inq.options[1] != '1') { - continue; - } - - // Configure SCSI ID - scsiid = i; - return 0; - } - - return -1; -} - -/************************************************ - * Init RaSCSI method * - ************************************************/ -int InitRaSCSI(void) -{ -#ifdef MULTICAST - unsigned char multicast_table[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; -#endif - - imr = 0; - scsistop = 0; - poll_current = -1; - idle = 0; - - return 0; -} - -/************************************************ - * RaSCSI interrupt handler function (polling) * - ************************************************/ -void interrupt IntProcess(void) -{ - unsigned char phase; - unsigned int len; - int type; - int_handler func; - int i; - - // V-DISP GPIP interrupt idle count control - if (intr_type == 0) { - // Increment idle - idle++; - - // Skip if not yet next scheduled processing - if (idle < poll_current) { - return; - } - - // Clear idle counter - idle = 0; - } - - // Start interrupt - - // Only when interrupt is permitted - if (imr == 0) { - return; - } - - // Skip if executing IOCS - if (*iocsexec != -1) { - return; - } - - // Interrupt forbidden if receiving data - DI (); - - // Only in bus free phase - phase = S_PHASE(); - if (phase != 0) { - // Exit - goto ei_exit; - } - - // Receive data - if (SCSI_GETPACKETLEN(&len) == 0) { - // RaSCSI is stopped - scsistop = 1; - - // Reset polling interval (sleep) - UpdateIntProcess(POLLING_SLEEP); - - // Exit - goto ei_exit; - } - - // RaSCSI is stopped - if (scsistop) { - scsistop = 0; - - // Reset polling interval (hurry) - UpdateIntProcess(poll_interval); - } - - // Packets did not arrive - if (len == 0) { - // Exit - goto ei_exit; - } - - // Tranfer packets to receive buffer memory - if (SCSI_GETPACKETBUF(rx_buff, len) == 0) { - // Fail - goto ei_exit; - } - - // Interrupt permitted - EI (); - - // Split data by packet type - type = rx_buff[12] * 256 + rx_buff[13]; - i = 0; - while ((func = SearchList2(type, i))) { - i++; - func(len, (void*)&rx_buff, ID_EN0); - } - trans_counter.recv_byte += len; - return; - -ei_exit: - // Interrupt permitted - EI (); -} - -/************************************************ - * RaSCSI Send Packets Function (from ne.s) * - ************************************************/ -int SendPacket(int len, const unsigned char* data) -{ - if (len < 1) { - return 0; - } - - if (len > 1514) { // 6 + 6 + 2 + 1500 - return -1; // Error - } - - // If RaSCSI seems to be stopped, throw an error - if (scsistop) { - return -1; - } - - // Interrupt is not permitted during sending - DI (); - - // Send processing and raise send flag - if (SCSI_SENDPACKET(data, len) == 0) { - // Interrupt permitted - EI (); - return -1; - } - - // Interrupt permitted - EI (); - - // Finished requesting send - trans_counter.send_byte += len; - - return 0; -} - -/************************************************ - * RaSCSI Interrupt Permission Setting Function* - ************************************************/ -int SetPacketReception(int i) -{ - imr = i; - return 0; -} - -/************************************************ - * RaSCSI Interrupt Processing Registration * - ************************************************/ -void RegisterIntProcess(int n) -{ - volatile unsigned char *p; - - // Update polling interval (current) and clear idle counter - poll_current = n; - idle = 0; - - if (intr_type == 0) { - // Overwrite V-DISP GPIP interrupt vectors - // and enable interrupt - B_INTVCS(0x46, (int)IntProcess); - p = (unsigned char *)MFP_AEB; - *p = *p | 0x10; - p = (unsigned char *)MFP_IERB; - *p = *p | 0x40; - p = (unsigned char *)MFP_IMRB; - *p = *p | 0x40; - } else if (intr_type == 1) { - // Set TimerA counter mode - VDISPST(NULL, 0, 0); - VDISPST(IntProcess, 0, poll_current); - } -} - -/************************************************ - * RaSCSI Interrupt Processing Update * - ************************************************/ -void UpdateIntProcess(int n) -{ - // Do not update if polling interval (current) is the same - if (n == poll_current) { - return; - } - - // Update polling interval (current) and clear idle counter - poll_current = n; - idle = 0; - - if (intr_type == 1) { - // TimerA requires re-registering - VDISPST(NULL, 0, 0); - VDISPST(IntProcess, 0, poll_current); - } -} - -// EOF diff --git a/src/x68k/RASETHER/scsictl.h b/src/x68k/RASETHER/scsictl.h deleted file mode 100644 index a13ea178..00000000 --- a/src/x68k/RASETHER/scsictl.h +++ /dev/null @@ -1,40 +0,0 @@ -//--------------------------------------------------------------------------- -// -// SCSI Target Emulator RaSCSI (*^..^*) -// for Raspberry Pi -// -// Powered by XM6 TypeG Technology. -// Copyright (C) 2016-2017 GIMONS -// [ RaSCSI Ethernet SCSI Control Department ] -// -// Based on -// Neptune-X board driver for Human-68k(ESP-X) version 0.03 -// Programed 1996-7 by Shi-MAD. -// Special thanks to Niggle, FIRST, yamapu ... -// -//--------------------------------------------------------------------------- - -#ifndef scsictl_h -#define scsictl_h - -// Global variables -extern int intr_type; -extern int poll_interval; - -// Transfer counter -struct trans_counter { - unsigned int send_byte; - unsigned int recv_byte; -}; -extern struct trans_counter trans_counter; - -extern int SearchRaSCSI(); -extern int InitRaSCSI(void); -extern int GetMacAddr(struct eaddr* buf); -extern int SetMacAddr(const struct eaddr* data); -extern int SetPacketReception(int i); -extern int SendPacket(int len, const unsigned char* data); -extern void RegisterIntProcess(int n); -extern void UpdateIntProcess(int n); - -#endif // scsictl_h From 77a32bd8289cc46298ce7fb901bab50a087d76e1 Mon Sep 17 00:00:00 2001 From: Daniel Markstedt Date: Tue, 25 Oct 2022 17:41:20 -0700 Subject: [PATCH 4/4] Remove legacy robot framework tests (#942) --- test/robot/.gitignore | 4 - .../robot/Resources/linux_scsi_utils.resource | 204 ------------------ test/robot/Resources/linux_services.resource | 30 --- test/robot/Resources/rascsi_utils.resource | 156 -------------- test/robot/rascsi_cd-rom_functionality.robot | 65 ------ test/robot/rascsi_device_information.robot | 94 -------- test/robot/rascsi_service.robot | 25 --- test/robot/rasctl_options.robot | 33 --- 8 files changed, 611 deletions(-) delete mode 100644 test/robot/.gitignore delete mode 100644 test/robot/Resources/linux_scsi_utils.resource delete mode 100644 test/robot/Resources/linux_services.resource delete mode 100644 test/robot/Resources/rascsi_utils.resource delete mode 100644 test/robot/rascsi_cd-rom_functionality.robot delete mode 100644 test/robot/rascsi_device_information.robot delete mode 100644 test/robot/rascsi_service.robot delete mode 100644 test/robot/rasctl_options.robot diff --git a/test/robot/.gitignore b/test/robot/.gitignore deleted file mode 100644 index 03f3cf33..00000000 --- a/test/robot/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -log.html -output.xml -report.html - diff --git a/test/robot/Resources/linux_scsi_utils.resource b/test/robot/Resources/linux_scsi_utils.resource deleted file mode 100644 index f9f91300..00000000 --- a/test/robot/Resources/linux_scsi_utils.resource +++ /dev/null @@ -1,204 +0,0 @@ - -*** Settings *** -Library String -Library Collections - -*** Variables *** -${drive_mount_path} /mnt/temp_drive/ - -# Taken from https://en.wikipedia.org/wiki/SCSI_Peripheral_Device_Type -${Scsi_device_type_hard_drive} 0 -${Scsi_device_type_magnetic_tape} 1 -${Scsi_device_type_printer} 2 -${Scsi_device_type_processor} 3 -${Scsi_device_type_write_once_dev} 4 -${Scsi_device_type_cd_rom} 5 -${Scsi_device_type_scanner} 6 -${Scsi_device_type_optical_memory} 7 - -*** Keywords *** - -Rescan SCSI Bus - [Documentation] Commands Linux to re-scan the SCSI bus on the local host - ${result}= Run sudo bash -c "echo \\"- - -\\" > /sys/class/scsi_host/host0/scan" - ${lsscsi}= Run lsscsi - log ${lsscsi} - -SCSI ID ${scsi_id:\d+} is detected by Linux - [Documentation] Checks to see if a specific SCSI ID is found by lsscsi - ${result}= Run lsscsi - Log ${result} - Should Contain ${result} [0:0:${scsi_id}:0] - -Delete all SCSI devices from Linux - [Documentation] Remove all SCSI IDs from the Linux SCSI driver - FOR ${scsi_id} IN RANGE 0 7 - Delete SCSI ID ${scsi_id} from Linux - END - -Delete SCSI ID ${scsi_id:\d+} from Linux - [Documentation] Remove a SCSI ID from Linux. Basically, will un-do the Scan action - Run sudo bash -c "echo 1 > /sys/class/scsi_device/0:0:${scsi_id}:0/device/delete" 2>&1 > /dev/null - -SCSI ID ${scsi_id} reports vendor ${scsi_vendor} - [Documentation] Reads the SCSI vendor from sysfs and checks that it matches expected value - # Sleep 2 minutes - ${read_scsi_info}= OperatingSystem.Get File /sys/class/scsi_device/0:0:${scsi_id}:0/device/vendor - ${read_scsi_info}= Remove String Using Regexp ${read_scsi_info} ${\n} - Log Vendor ID read from sysfs was --${read_scsi_info}-- - Should Be Equal ${read_scsi_info} ${scsi_vendor} Incorrect SCSI vendor reported for ID ${scsi_id} - -SCSI ID ${scsi_id} reports revision ${scsi_rev} - [Documentation] Reads the SCSI vendor from sysfs and checks that it matches expected value - ${read_scsi_info}= OperatingSystem.Get File /sys/class/scsi_device/0:0:${scsi_id}:0/device/rev - ${read_scsi_info}= Remove String Using Regexp ${read_scsi_info} ${\n} - Log SCSI revision read from sysfs was ${read_scsi_info} - Should Be Equal ${read_scsi_info} ${scsi_rev} Incorrect SCSI version reported for ID ${scsi_id} - -SCSI ID ${scsi_id} reports model ${scsi_model} - [Documentation] Reads the SCSI vendor from sysfs and checks that it matches expected value - ${read_scsi_info}= OperatingSystem.Get File /sys/class/scsi_device/0:0:${scsi_id}:0/device/model - ${read_scsi_info}= Remove String Using Regexp ${read_scsi_info} ${\n} - Log SCSI model read from sysfs was --${read_scsi_info}-- - Should Be Equal ${read_scsi_info} ${scsi_model} Incorrect SCSI model reported for ID ${scsi_id} - -SCSI ID ${scsi_id} reports type ${scsi_type} - [Documentation] Reads the SCSI type from sysfs and checks that it matches expected value - ${read_scsi_info}= OperatingSystem.Get File /sys/class/scsi_device/0:0:${scsi_id}:0/device/type - ${read_scsi_info}= Remove String Using Regexp ${read_scsi_info} ${\n} - Log SCSI model read from sysfs was ${read_scsi_info} - Should Be Equal ${read_scsi_info} ${scsi_type} Incorrect SCSI type reported for ID ${scsi_id} - -Checksum of Data File ${file_name} from mounted drive - [Documentation] Calculate the checksum of the specified file from the mounted drive - ${sha_output}= Run sha512sum ${drive_mount_path}${file_name} - Log Checksum of the file was ${sha_output} - @{sha_output_list}= Split String ${sha_output} ${SPACE} - ${sha_signature}= Get From List ${sha_output_list} 0 - [Return] ${sha_signature} - -Get device id for SCSI ID ${scsi_id:/d+} - [Documentation] Lookup the device name (ex /dev/sr0) for the specified SCSI ID - ${lsscsi_output}= Run lsscsi --brief |grep \\\\[0\\\\:0\\\\:${scsi_id}\\\\:0\\\\] | cut -f 5 --delimiter=" " - Should Match Regexp ${lsscsi_output} \/dev\/[\\w\\d]+ Unable to find device ID for SCSI ID ${scsi_id} - [Return] ${lsscsi_output} - # log ${lsscsi_output} - # @{scsi_entries}= Split To Lines ${lsscsi_output} - # FOR ${cur_line} IN @{scsi_entries} - # Log ${cur_line} - # @{scsi_line}= SplitString ${cur_line} - # ${linux_id}= Set Variable ${scsi_line}[0] - # ${device_id}= Set Variable ${scsi_line}[1] - # Return From Keyword If "${linux_id}"=="[0:0:${scsi_id}:0]" ${device_id} - # END - # [Return] /dev/notfound - -Get size of device id ${device_id} in bytes - [Documentation] Decypher the output of lsblk to determine the size of the - ... specified device ID - ${bare_device_id}= Remove String Using Regexp ${device_id} \/dev\/ - ${lsblk_output}= Run lsblk --raw --bytes | grep ${bare_device_id} | cut -f 4 --delimiter=" " - [Return] ${lsblk_output} - -Get size of SCSI ID ${scsi_id} device in bytes - [Documentation] Given a SCSI ID, determine how big that drive is (in bytes) - ${device_id}= Get device id for SCSI ID ${scsi_id} - ${device_size}= Get size of device id ${device_id} in bytes - [Return] ${device_size} - -Get checksum of SCSI ID ${scsi_id} device - [Documentation] Calculate the checksum of the disk image on the RaSCSI host - ${device_id}= Get device id for SCSI ID ${scsi_id} - ${checksum}= Run Keyword Get checksum of file ${device_id} - [Return] ${checksum} - -Get checksum of file ${full_file_path} - ${checksum}= Run md5sum ${full_file_path} | cut -f 1 --delimiter=" " - [Return] ${checksum} - -Get filesystem type of SCSI ID ${scsi_id} - [Documentation] Get the type of file system for the specified scsi ID. It needs to be - ... mounted in order for this command to work - ${device_id}= Get device id for SCSI ID ${scsi_id} - ${raw}= Run mount | grep ${device_id} - log ${raw} - ${filesystem_type}= Run mount |grep ${device_id} |cut --delimiter=" " -f 5 - [Return] ${filesystem_type} - -The size of SCSI ID ${scsi_id} is equal to the size of ${image_name} - [Documentation] Get the size of the SCSI device specified and the size of the drive - ... image and make sure they're equal - ${device_size}= Get size of SCSI ID ${scsi_id} device in bytes - ${image_size}= Get Size of RaSCSI Image ${image_name} in bytes - Should be Equal ${device_size} ${image_size} The device size did not match the image size - -The checksum of SCSI ID ${scsi_id} is equal to the checksum of ${image_name} - [Documentation] Empty Keyword - ${device_checksum}= Get checksum of SCSI ID ${scsi_id} device - ${image_checksum}= Get checksum of RaSCSI Image ${image_name} - Should be Equal ${device_checksum} ${image_checksum} The device checksum did not match the image file - -Mount SCSI ID ${scsi_id} as ${folder_name} - [Documentation] Mount the specified SCSI ID at the specified path in /mnt - Run sudo mkdir -p /mnt/${folder_name} - ${device}= Get device id for SCSI ID ${scsi_id} - Run sudo mount ${device} /mnt/${folder_name} - ${df}= Run df -h - Log ${df} - -SCSI ID ${scsi_id} has been mounted at ${folder_name} - [Documentation] Check that the 'df' utility reports that the specified SCSI ID is - ... mounted at the path specified - ${device}= Get device id for SCSI ID ${scsi_id} - ${df_output}= Run mount | grep ${device} | cut --delimiter=" " -f 3 - log ${df_output} - -Unmount SCSI ID ${scsi_id} - [Documentation] Un-mount the drive specified. Currently, this doesn't use the drive ID. However, - ... it needs to be updated in the future to un-moune the correct device, instead of - ... of being hard-coded to a specific path. - ${device}= Get device id for SCSI ID ${scsi_id} - Run sudo umount ${device} - -The file ${filename} in the ${directory} directory matches the original in ISO ${drive_image} - [Documentation] Check that the file ready by the host through the RaSCSI interface and make sure - ... that the checksum matches the original file extracted from the ISO - ${host_file_checksum}= Get checksum of file /mnt/${directory}/${filename} - ${rascsi_file_checksum}= Get checksum of ${filename} from ISO ${drive_image} on the RaSCSI Host - Should be Equal ${host_file_checksum} ${rascsi_file_checksum} ${filename} did not match between the host and the RaSCSI - - -The filesystem type of SCSI ID ${scsi_id} is ${fs_type} - [Documentation] Fetches the filesystem type of the specified SCSI ID and checks that it matches - ${actual_fs_type}= Get filesystem type of SCSI ID ${scsi_id} - Should be Equal ${fs_type} ${actual_fs_type} Incorrect file system type detected - -The measured read speed for ${data_size} megabytes of data from SCSI ID ${scsi_id} is greater than ${expected_speed} KB/s - [Documentation] Read the specified amount of data from the SCSI drive and make sure that it is - ... greater than the specified threshold - [Teardown] Remove temporary file ${temp_filename} - ${device_id}= Get device id for SCSI ID ${scsi_id} - ${temp_filename}= Generate Random String 10 [LETTERS] - ${dd_time}= Run sudo dd if=${device_id} of=/tmp/${temp_filename} bs=1M count=${data_size} 2>&1 | awk '/copied/ {print $8}' - ${copy_time}= Convert to Number ${dd_time} - ${speed}= Evaluate (${data_size}*1024)/${copy_time} - Log Measured copy speed was ${speed} KB/s - Should be true ${speed}>=${expected_speed} Measured speed was not greater than minimum - # Run sudo rm /tmp/${temp_filename} - -Create an image named ${iso_name} from SCSI ID ${scsi_id} - [Documentation] Will create a disk image from the specified SCSI device - ${device_id}= Get device id for SCSI ID ${scsi_id} - ${dd_output}= Run sudo dd if=${device_id} of=/tmp/${iso_name} bs=1M 2>&1 - File Should Not be Empty /tmp/${iso_name} - -Local file ${local_file_name} matches RaSCSI file ${rascsi_file_name} - [Documentation] Calculates the checksum of the local file and the remote file - ... then ensures that they match - ${local_file_checksum}= Get checksum of file /tmp/${local_file_name} - ${remote_file_checksum}= Get checksum of RaSCSI Image ${rascsi_file_name} - Should be Equal ${local_file_checksum} ${remote_file_checksum} Files did not match - -Remove temporary file ${file_name} - [Documentation] Deletes the specified file from the temp directory - Run sudo rm /tmp/${file_name} \ No newline at end of file diff --git a/test/robot/Resources/linux_services.resource b/test/robot/Resources/linux_services.resource deleted file mode 100644 index e518e2f4..00000000 --- a/test/robot/Resources/linux_services.resource +++ /dev/null @@ -1,30 +0,0 @@ - -*** Settings *** -Library SSHLibrary -Library String - -*** Variables *** -#${Rascsi_Password} raspberry - -*** Keywords *** -The ${service_name} Service Should be Running - ${lc_service_name}= Convert To Lower Case ${service_name} - ${output}= Execute Command systemctl status ${lc_service_name} - Should Contain ${output} Active: active (running) ignore_case=True - -The ${service_name} Service Should be Stopped - ${lc_service_name}= Convert To Lower Case ${service_name} - ${output}= Execute Command systemctl status ${lc_service_name} - Should Contain Any ${output} Active: failed Active: inactive ignore_case=True - -The ${service_name} Service is Stopped - ${lc_service_name}= Convert To Lower Case ${service_name} - Execute Command systemctl stop ${lc_service_name} sudo=True sudo_password=${Rascsi_Password} - -The ${service_name} Service is Restarted - ${lc_service_name}= Convert To Lower Case ${service_name} - Execute Command systemctl restart ${lc_service_name} sudo=True sudo_password=${Rascsi_Password} - -The ${service_name} Service is Started - ${lc_service_name}= Convert To Lower Case ${service_name} - Execute Command systemctl start ${lc_service_name} sudo=True sudo_password=${Rascsi_Password} diff --git a/test/robot/Resources/rascsi_utils.resource b/test/robot/Resources/rascsi_utils.resource deleted file mode 100644 index 26d68627..00000000 --- a/test/robot/Resources/rascsi_utils.resource +++ /dev/null @@ -1,156 +0,0 @@ - -*** Settings *** -Library SSHLibrary -Library Process -Library String -Resource linux_services.resource - -*** Variables *** -${Rascsi_Host} rascsi.local -${Rascsi_Username} pi -${Rascsi_Password} raspberry - - -*** Keywords *** -Open Connection to Rascsi and Log In - Open Connection ${Rascsi_Host} - Login ${Rascsi_Username} ${Rascsi_Password} - -Create Blank Rascsi Drive Image of Size ${drive_size} megabytes named ${file_name} - [Documentation] Creates an empty drive image on the Rascsi host of the specified size and file name - Execute Command dd if=/dev/zero of=/home/pi/images/${file_name} bs=1M count=${drive_size} - -Delete drive image ${file_name} - [Documentation] Delete a disk drive image that was created on the raspberry pi - Remove File /home/pi/images/${file_name} - -Delete all RaSCSI drive images - [Documentation] Delete all of the temporary drive images that were created on the RaSCSI host - Remove File /home/pi/images/tmp_* - -Drive image ${drive_image_file} is attached as SCSI ID ${scsi_id} - [Documentation] Attaches an existing drive image to the RaSCSI - ${rasctl_output}= Execute Command rasctl -i ${scsi_id} -c attach -f /home/pi/images/${drive_image_file} - log ${rasctl_output} - ${rasctl_output}= Execute Command rasctl -l - log ${rasctl_output} - Rescan SCSI Bus - -CD-ROM drive is attached as SCSI ID ${scsi_id} - [Documentation] Attaches a CD-ROM device (without any media) to the RaSCSI - ${rasctl_output}= Execute Command rasctl -i ${scsi_id} -c attach -t cd - log ${rasctl_output} - ${rasctl_output}= Execute Command rasctl -l - log ${rasctl_output} - Rescan SCSI Bus - -Magneto Optical drive is attached as SCSI ID ${scsi_id} - [Documentation] Attaches a Magneto Optical device (without any media) to the RaSCSI - Execute Command rasctl -i ${scsi_id} -c attach -t mo - ${rasctl_output}= Execute Command rasctl -l - log ${rasctl_output} - Rescan SCSI Bus - - -Detach all RaSCSI SCSI Devices - [Documentation] Send detach commands for all of the SCSI IDs to make sure that there - ... aren't any left over before/after a test - FOR ${scsi_id} IN RANGE 0 7 - Detach RaSCSI SCSI ID ${scsi_id} - END - -Detach RaSCSI SCSI ID ${scsi_id:\d+} - [Documentation] Detaches the specified SCSI ID from Rascsi - Execute Command rasctl -c detach -i ${scsi_id} - -Rasctl reports SCSI ID ${scsi_id} of type ${type:CD|MO|HD} - [Documentation] Executes rasctl and verifies that the drive is configured as the specified type - ${rasctl_output}= Execute Command rasctl -l - log ${rasctl_output} - Should Contain ${rasctl_output} |${SPACE*2}${scsi_id}${SPACE}|${SPACE*2}0${SPACE}|${SPACE}SC${type}${SPACE}| - -# Create a ${iso_size} megabyte ISO named ${image_name} with random data -# [Documentation] Creates a file on the RaSCSI with random data (from /dev/urandom), -# ... then creates an ISO image with that data -# Execute Command mkdir /tmp/new_iso -# Execute Command dd if=/dev/urandom of=/tmp/new_iso/data.dat bs=1M count=${iso_size} -# Execute Command genisoimage -o /home/pi/images/${image_name} /tmp/new_iso/ - -Insert Removable Media ${image} into SCSI ID ${scsi_id} - Execute Command rasctl -c insert -i ${scsi_id} -f /home/pi/images/${image} - ${result}= Execute Command rasctl -l - Log ${result} - -Removable media ${image} is inserted into SCSI ID ${scsi_id:/d+} - [Documentation] Inserts the sepecified image name into the removable media drive - Execute Command rasctl -c insert -i ${scsi_id} -f /home/pi/images/${image} - -# Insert removable media ${image_name} into SCSI ID ${scsi_id:/d+} -# [Documentation] Inserts the sepecified image name into the removable media drive -# Execute Command rasctl -c insert -i ${scsi_id} -f /home/pi/images/${image_name} - -Eject removable media from SCSI ID ${scsi_id:/d+} - [Documentation] Inserts the sepecified image name into the removable media drive - Execute Command rasctl -c eject -i ${scsi_id} - -Checksum of Random Data File from RaSCSI - [Documentation] Calcualte the SHA signature of the random data that was generated - ... on the RaSCSI host - ${sha_output}= Execute Command sha512sum /tmp/new_iso/data.dat | cut -f 1 - Log Checksum of the file was ${sha_output} - [Return] ${sha_output} - -Get checksum of RaSCSI Image ${image_name} - [Documentation] Calculate the checksum of the disk image on the RaSCSI host - ${checksum}= Execute Command md5sum /home/pi/images/${image_name} | cut -f 1 --delimiter=" " - [Return] ${checksum} - -Get Size of RaSCSI Image ${image_name} in bytes - [Documentation] Return the size of the specified disk image in bytes - ${size_output}= Execute Command du -b /home/pi/images/${image_name} | cut -f 1 - [Return] ${size_output} - - -Get checksum of ${filename} from ISO ${image_name} on the RaSCSI Host - [Documentation] Extracts the specified file from the ISO, calculates the checksum - ... then returns that value - ${temp_dirname}= Generate Random String 10 [LETTERS] - Execute Command mkdir /tmp/${temp_dirname} sudo=True sudo_password=${Rascsi_Password} - Execute Command mount /home/pi/images/${image_name} /tmp/${temp_dirname} sudo=True sudo_password=${Rascsi_Password} - ${checksum}= Execute Command md5sum /tmp/${temp_dirname}/${filename} | cut -f 1 --delimiter=" " - Execute Command umount /tmp/${temp_dirname} sudo=True sudo_password=${Rascsi_Password} - Execute Command rm -rf /tmp/${temp_dirname} sudo=True sudo_password=${Rascsi_Password} - [Return] ${checksum} - -The RaSCSI service is configured to use port ${port_number} - [Documentation] Modifies the rascsi.service systemd configuration file to use the specified port - ... instead of the default. This will erase any other options that have been previously - ... set in your rascsi.service file. - Execute command sed -i 's/^ExecStart=.*/ExecStart=\\\/usr\\\/local\\\/bin\\\/rascsi -p ${port_number}/' /etc/systemd/system/rascsi.service sudo=True sudo_password=${Rascsi_Password} - Execute command systemctl daemon-reload sudo=True sudo_password=${Rascsi_Password} - ${service_file}= Execute command cat /etc/systemd/system/rascsi.service - log ${service_file} - -The RaSCSI service is configured to use default port - [Documentation] Restore the rascsi.service systemd configuration file to use the default rascsi - ... launch command - Execute command sed -i 's/^ExecStart=.*/ExecStart=\\\/usr\\\/local\\\/bin\\\/rascsi/' /etc/systemd/system/rascsi.service sudo=True sudo_password=${Rascsi_Password} - Execute command systemctl daemon-reload sudo=True sudo_password=${Rascsi_Password} - ${service_file}= Execute command cat /etc/systemd/system/rascsi.service - log ${service_file} - -RASCTL should connect on port ${port_number} - ${stdout_out} ${stderr_out}= Execute Command rasctl -l -p ${port_number} return_stderr=True - log ${stdout_out} - log ${stderr_out} - Should Contain ${stdout_out} No images currently attached - -RASCTL should not connect on port ${port_number} - ${stdout_out} ${stderr_out}= Execute Command rasctl -l -p ${port_number} return_stderr=True - log ${stdout_out} - log ${stderr_out} - Should Contain ${stderr_out} Error: Can't connect to rascsi process on host - -Kill all rascsi processes - ${result}= Execute command killall -9 rascsi sudo=True sudo_password=${Rascsi_Password} - log ${result} \ No newline at end of file diff --git a/test/robot/rascsi_cd-rom_functionality.robot b/test/robot/rascsi_cd-rom_functionality.robot deleted file mode 100644 index 05417fe3..00000000 --- a/test/robot/rascsi_cd-rom_functionality.robot +++ /dev/null @@ -1,65 +0,0 @@ -*** Settings *** -Documentation Test the RaSCSI CD-ROM emulation functionality. -Library OperatingSystem -Resource Resources/rascsi_utils.resource -Resource Resources/linux_services.resource -Resource Resources/linux_scsi_utils.resource - -Suite Setup Run Keywords Open Connection to Rascsi and Log In -... AND The Rascsi Service is Started -... AND The RaSCSI Service Should be Running -... AND Detach all RaSCSI SCSI Devices -Suite Teardown Run Keywords Detach all RaSCSI SCSI Devices -... AND Delete all SCSI devices from Linux -... AND Close All Connections - -Test Teardown Run Keywords Detach all RaSCSI SCSI Devices -... AND Delete all SCSI devices from Linux -... AND Delete all RaSCSI drive images - -*** Test Cases *** -MacOS formated ISO is mounted and correct size is reported - [Documentation] Mount a MacOS formatted ISO and check that its size is - ... detected correctly. Note that Linux is not able to - ... mount this image. Note: Marathon was chosen because - ... its a reasonably small image. Large images will make - ... this test take a LONG time. - Given CD-ROM Drive is attached as SCSI ID 6 - When Insert Removable Media marathon.iso into SCSI ID 6 - Then the size of SCSI ID 6 is equal to the size of marathon.iso - And the checksum of SCSI ID 6 is equal to the checksum of marathon.iso - -ISO-9660 formated ISO is mounted correct size is reported - [Documentation] Mount a pre-made IDS-9660 formatted ISO and check - ... that it is read correctly - [Teardown] Unmount SCSI ID 5 - Given CD-ROM Drive is attached as SCSI ID 5 - When Insert Removable Media ubuntu-12.04.5-server-amd64.iso into SCSI ID 5 - And Mount SCSI ID 5 as ubuntu - Then SCSI ID 5 has been mounted at ubuntu - And the size of SCSI ID 5 is equal to the size of ubuntu-12.04.5-server-amd64.iso - And the filesystem type of SCSI ID 5 is iso9660 - And the file pics/debian.jpg in the ubuntu directory matches the original in ISO ubuntu-12.04.5-server-amd64.iso - And the file install/vmlinuz in the ubuntu directory matches the original in ISO ubuntu-12.04.5-server-amd64.iso - -CD-ROM Read Speed is as fast as expected - [Documentation] Check that the read speed from the emulated CD-ROM is within - ... the expected range. This should detect if a change cause the - ... drive to slow down significantly - Given CD-ROM Drive is attached as SCSI ID 2 - When insert Removable Media ubuntu-12.04.5-server-amd64.iso into SCSI ID 2 - Then the measured read speed for 1 megabytes of data from SCSI ID 2 is greater than 750 KB/s - Then the measured read speed for 10 megabytes of data from SCSI ID 2 is greater than 950 KB/s - And the measured read speed for 100 megabytes of data from SCSI ID 2 is greater than 950 KB/s - - -Create an ISO from a RaSCSI CD-ROM device and verify it matches - [Documentation] On the RaSCSI, we'll mount an ISO, then on the host system, we - ... will generate a new ISO from the emulated CD-ROM and make sure - ... that it matches the original - [Teardown] Remove temporary file dup_simtower.iso - Given CD-ROM Drive is attached as SCSI ID 0 - When Insert removable media simtower.iso into SCSI ID 0 - And create an image named dup_simtower.iso from SCSI ID 0 - Then local file dup_simtower.iso matches RaSCSI file simtower.iso - diff --git a/test/robot/rascsi_device_information.robot b/test/robot/rascsi_device_information.robot deleted file mode 100644 index c76908dd..00000000 --- a/test/robot/rascsi_device_information.robot +++ /dev/null @@ -1,94 +0,0 @@ -*** Settings *** -Documentation Test that the RaSCSI reports SCSI information correctly. -Library OperatingSystem -Resource Resources/rascsi_utils.resource -Resource Resources/linux_services.resource -Resource Resources/linux_scsi_utils.resource - -Suite Setup Run Keywords Open Connection to Rascsi and Log In -... AND The Rascsi Service is Started -... AND The RaSCSI Service Should be Running -... AND Detach all RaSCSI SCSI Devices -Suite Teardown Run Keywords Detach all RaSCSI SCSI Devices -... AND Delete all SCSI devices from Linux -... AND Close All Connections - -Test Teardown Run Keywords Detach all RaSCSI SCSI Devices -... AND Delete all SCSI devices from Linux -... AND Delete all RaSCSI drive images - -*** Test Cases *** -Apple Hard Drive reports the correct device information - [Documentation] Create an empty Apple hard drive and verify that the SCSI - ... information is reported correctly to the Linux host - [Setup] Run Keyword and Ignore Error Delete drive image tmp_apple_drive.hda - Given Create Blank Rascsi Drive Image of Size 10 megabytes named tmp_apple_drive.hda - When Drive image tmp_apple_drive.hda is attached as SCSI ID 0 - Then Rasctl reports SCSI ID 0 of type HD - And SCSI ID 0 is detected by Linux - And SCSI ID 0 reports vendor ${SPACE}SEAGATE - And SCSI ID 0 reports revision 0200 - And SCSI ID 0 reports model ${SPACE*10}ST225N - And SCSI ID 0 reports type ${Scsi_device_type_hard_drive} - -XM6 Hard Drive reports the correct device information - [Documentation] Create an empty XM6 hard drive and verify that the SCSI - ... information is reported correctly to the Linux host - [Setup] Run Keyword and Ignore Error Delete drive image tmp_xm6_scsi_drive.hds - Given Create Blank Rascsi Drive Image of Size 10 megabytes named tmp_xm6_scsi_drive.hds - When Drive image tmp_xm6_scsi_drive.hds is attached as SCSI ID 1 - Then Rasctl reports SCSI ID 1 of type HD - And SCSI ID 1 is detected by Linux - And SCSI ID 1 reports vendor RaSCSI${SPACE*2} - And SCSI ID 1 reports revision 0200 - And SCSI ID 1 reports model PRODRIVE LPS10S${SPACE} - And SCSI ID 1 reports type ${Scsi_device_type_hard_drive} - -NEC Hard Drive reports the correct device information - [Documentation] Create an empty NEC hard drive and verify that the SCSI - ... information is reported correctly to the Linux host - [Setup] Run Keyword and Ignore Error Delete drive image tmp_nec_hard_drive.hdn - Given Create Blank Rascsi Drive Image of Size 10 megabytes named tmp_nec_hard_drive.hdn - When Drive image tmp_nec_hard_drive.hdn is attached as SCSI ID 2 - Then Rasctl reports SCSI ID 2 of type HD - And SCSI ID 2 is detected by Linux - And SCSI ID 2 reports vendor NECCSI${SPACE*2} - And SCSI ID 2 reports revision 0200 - And SCSI ID 2 reports model PRODRIVE LPS10S${SPACE} - And SCSI ID 2 reports type ${Scsi_device_type_hard_drive} - -Anex86 Hard Drive reports the correct device information - [Documentation] Create an empty Anex86 hard drive and verify that the SCSI - ... information is reported correctly to the Linux host - [Setup] Run Keyword and Ignore Error Delete drive image tmp_anex86_hard_drive.hdi - Given Create Blank Rascsi Drive Image of Size 10 megabytes named tmp_anex86_hard_drive.hdi - When Drive image tmp_anex86_hard_drive.hdi is attached as SCSI ID 3 - Then Rasctl reports SCSI ID 3 of type HD - And SCSI ID 3 is detected by Linux - And SCSI ID 3 reports vendor RaSCSI${SPACE*2} - And SCSI ID 3 reports revision 0200 - And SCSI ID 3 reports model CD-ROM CDU-55S${SPACE*2} - And SCSI ID 3 reports type ${Scsi_device_type_hard_drive} - -CD-ROM drive reports the correct device information - [Documentation] Create an CD-ROM drive with no media and verify that the SCSI - ... information is reported correctly to the Linux host - When CD-ROM Drive is attached as SCSI ID 4 - Then Rasctl reports SCSI ID 4 of type CD - And SCSI ID 4 is detected by Linux - And SCSI ID 4 reports vendor RaSCSI${SPACE*2} - And SCSI ID 4 reports revision 0200 - And SCSI ID 4 reports model CD-ROM CDU-55S${SPACE*2} - And SCSI ID 4 reports type ${Scsi_device_type_cd_rom} - -Magneto Optical drive reports the correct device information - [Documentation] Create an Magneto Optical drive with no media and verify - ... that the SCSI information is reported correctly to the - ... Linux host - When Magneto Optical drive is attached as SCSI ID 5 - Then Rasctl reports SCSI ID 5 of type MO - And SCSI ID 5 is detected by Linux - And SCSI ID 5 reports vendor RaSCSI${SPACE*2} - And SCSI ID 5 reports revision 0200 - And SCSI ID 5 reports model M2513A${SPACE*10} - And SCSI ID 5 reports type ${Scsi_device_type_optical_memory} diff --git a/test/robot/rascsi_service.robot b/test/robot/rascsi_service.robot deleted file mode 100644 index cc13f749..00000000 --- a/test/robot/rascsi_service.robot +++ /dev/null @@ -1,25 +0,0 @@ -*** Settings *** -Documentation Test that the RaSCSI service can be started and stopped. -Library OperatingSystem -Resource Resources/rascsi_utils.resource -Resource Resources/linux_services.resource - -Suite Setup Open Connection to Rascsi and Log In -Suite Teardown Close All Connections - -*** Test Cases *** -RaSCSI Service Can be Started as a Service - [Documentation] Start the Rascsi service and make sure it stays running - When The Rascsi Service is Started - Then The RaSCSI Service Should be Running - -RaSCSI Service Can be Stopped as a Service - [Documentation] Stop the Rascsi service and make sure it stays stopped - When the Rascsi Service is Stopped - Then the RaSCSI Service should be Stopped - -RaSCSI Service Can be Restarted as a Service - [Documentation] Restart the Rascsi service and make sure it stays running - Given The RaSCSI Service is Started - When The Rascsi Service is Restarted - Then the Rascsi Service should be Running diff --git a/test/robot/rasctl_options.robot b/test/robot/rasctl_options.robot deleted file mode 100644 index 6df7bbe6..00000000 --- a/test/robot/rasctl_options.robot +++ /dev/null @@ -1,33 +0,0 @@ -*** Settings *** -Documentation Test that the RaSCSI can be started on a configurable TCP port. -Library OperatingSystem -Resource Resources/rascsi_utils.resource -Resource Resources/linux_services.resource - -Suite Setup Open Connection to Rascsi and Log In -Suite Teardown Close All Connections - -*** Test Cases *** -RASCTL Works on the Default Port - [Documentation] Check that RaSCSI starts with the default port - [Teardown] Run Keywords Kill all rascsi processes The Rascsi service is Restarted - When The RaSCSI service is configured to use default port - And The RaSCSI service is Restarted - Then rasctl should connect on port 6868 - And rasctl should not connect on port 9999 - -RASCTL Works on User Specified Port 9999 - [Documentation] Check that RaSCSI works with a user specified port "9999" - [Teardown] Run Keywords The RaSCSI service is configured to use default port The Rascsi service is Restarted - When The RaSCSI service is configured to use port 9999 - And The RaSCSI service is Restarted - Then rasctl should connect on port 9999 - And rasctl should not connect on port 6868 - -RASCTL Works on User Specified Port 6869 - [Documentation] Check that RaSCSI works with a user specified port DEFAULT + 1 - [Teardown] Run Keywords The RaSCSI service is configured to use default port The Rascsi service is Restarted - When The RaSCSI service is configured to use port 6869 - And The RaSCSI service is Restarted - Then rasctl should connect on port 6869 - And rasctl should not connect on port 6868