Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/pip/python/web/jinja2-3.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmark authored Jan 13, 2024
2 parents 708bebe + 2f483fd commit 83f4fea
Show file tree
Hide file tree
Showing 91 changed files with 1,485 additions and 1,024 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: make -j $(nproc) test

- name: Run unit tests
run: (set -o pipefail && bin/fullspec/piscsi_test | tee piscsi_test_log.txt)
run: (set -o pipefail && bin/piscsi_test | tee piscsi_test_log.txt)

- name: Upload logs
uses: actions/upload-artifact@v3
Expand Down
12 changes: 0 additions & 12 deletions cpp/.clang-format

This file was deleted.

3 changes: 0 additions & 3 deletions cpp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ obj
bin
coverage
generated
.project
.cproject
.settings
53 changes: 0 additions & 53 deletions cpp/.vscode/launch.json

This file was deleted.

19 changes: 0 additions & 19 deletions cpp/.vscode/tasks.json

This file was deleted.

4 changes: 2 additions & 2 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ COVERAGE_DIR = coverage
COVERAGE_FILE = piscsi.dat
OS_FILES = ../os_integration

OBJDIR := obj/$(shell echo $(CONNECT_TYPE) | tr '[:upper:]' '[:lower:]')
BINDIR := bin/$(shell echo $(CONNECT_TYPE) | tr '[:upper:]' '[:lower:]')
OBJDIR := obj
BINDIR := bin

BIN_ALL = \
$(BINDIR)/$(PISCSI) \
Expand Down
4 changes: 4 additions & 0 deletions cpp/controllers/scsi_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@ bool ScsiController::XferOutBlockOriented(bool cont)
LogTrace("Done with DaynaPort Set Multicast Address");
break;

case scsi_command::eCmdSetIfaceMode:
LogTrace("Done with setting DaynaPort MAC address (ignore)");
break;

default:
stringstream s;
s << "Received an unexpected command ($" << setfill('0') << setw(2) << hex
Expand Down
52 changes: 7 additions & 45 deletions cpp/devices/device_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
//---------------------------------------------------------------------------

#include "shared/network_util.h"
#include "shared/piscsi_util.h"
#include "scsihd.h"
#include "scsihd_nec.h"
#include "scsimo.h"
Expand All @@ -20,39 +20,14 @@

using namespace std;
using namespace piscsi_util;
using namespace network_util;

DeviceFactory::DeviceFactory()
{
sector_sizes[SCHD] = { 512, 1024, 2048, 4096 };
sector_sizes[SCRM] = { 512, 1024, 2048, 4096 };
sector_sizes[SCMO] = { 512, 1024, 2048, 4096 };
sector_sizes[SCCD] = { 512, 2048};

extension_mapping["hd1"] = SCHD;
extension_mapping["hds"] = SCHD;
extension_mapping["hda"] = SCHD;
extension_mapping["hdn"] = SCHD;
extension_mapping["hdi"] = SCHD;
extension_mapping["nhd"] = SCHD;
extension_mapping["hdr"] = SCRM;
extension_mapping["mos"] = SCMO;
extension_mapping["iso"] = SCCD;
extension_mapping["is1"] = SCCD;

device_mapping["bridge"] = SCBR;
device_mapping["daynaport"] = SCDP;
device_mapping["printer"] = SCLP;
device_mapping["services"] = SCHS;
}

PbDeviceType DeviceFactory::GetTypeForFile(const string& filename) const
{
if (const auto& it = extension_mapping.find(GetExtensionLowerCase(filename)); it != extension_mapping.end()) {
if (const auto& it = EXTENSION_MAPPING.find(GetExtensionLowerCase(filename)); it != EXTENSION_MAPPING.end()) {
return it->second;
}

if (const auto& it = device_mapping.find(filename); it != device_mapping.end()) {
if (const auto& it = DEVICE_MAPPING.find(filename); it != DEVICE_MAPPING.end()) {
return it->second;
}

Expand All @@ -75,8 +50,7 @@ shared_ptr<PrimaryDevice> DeviceFactory::CreateDevice(PbDeviceType type, int lun
if (const string ext = GetExtensionLowerCase(filename); ext == "hdn" || ext == "hdi" || ext == "nhd") {
device = make_shared<SCSIHD_NEC>(lun);
} else {
device = make_shared<SCSIHD>(lun, sector_sizes.find(type)->second, false,
ext == "hd1" ? scsi_level::scsi_1_ccs : scsi_level::scsi_2);
device = make_shared<SCSIHD>(lun, false, ext == "hd1" ? scsi_level::scsi_1_ccs : scsi_level::scsi_2);

// Some Apple tools require a particular drive identification
if (ext == "hda") {
Expand All @@ -88,17 +62,17 @@ shared_ptr<PrimaryDevice> DeviceFactory::CreateDevice(PbDeviceType type, int lun
}

case SCRM:
device = make_shared<SCSIHD>(lun, sector_sizes.find(type)->second, true);
device = make_shared<SCSIHD>(lun, true, scsi_level::scsi_2);
device->SetProduct("SCSI HD (REM.)");
break;

case SCMO:
device = make_shared<SCSIMO>(lun, sector_sizes.find(type)->second);
device = make_shared<SCSIMO>(lun);
device->SetProduct("SCSI MO");
break;

case SCCD:
device = make_shared<SCSICD>(lun, sector_sizes.find(type)->second,
device = make_shared<SCSICD>(lun,
GetExtensionLowerCase(filename) == "is1" ? scsi_level::scsi_1_ccs : scsi_level::scsi_2);
device->SetProduct("SCSI CD-ROM");
break;
Expand Down Expand Up @@ -135,15 +109,3 @@ shared_ptr<PrimaryDevice> DeviceFactory::CreateDevice(PbDeviceType type, int lun

return device;
}

// TODO Move to respective device, which may require changes in the SCSI_HD/SCSIHD_NEC inheritance hierarchy
unordered_set<uint32_t> DeviceFactory::GetSectorSizes(PbDeviceType type) const
{
const auto& it = sector_sizes.find(type);
if (it != sector_sizes.end()) {
return it->second;
}
else {
return {};
}
}
31 changes: 21 additions & 10 deletions cpp/devices/device_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

#pragma once

#include "shared/piscsi_util.h"
#include <string>
#include <unordered_set>
#include <unordered_map>
#include "generated/piscsi_interface.pb.h"

Expand All @@ -27,19 +25,32 @@ class DeviceFactory

public:

DeviceFactory();
DeviceFactory() = default;
~DeviceFactory() = default;

shared_ptr<PrimaryDevice> CreateDevice(PbDeviceType, int, const string&) const;
PbDeviceType GetTypeForFile(const string&) const;
unordered_set<uint32_t> GetSectorSizes(PbDeviceType type) const;
const auto& GetExtensionMapping() const { return extension_mapping; }
const auto& GetExtensionMapping() const { return EXTENSION_MAPPING; }

private:

unordered_map<PbDeviceType, unordered_set<uint32_t>> sector_sizes;

unordered_map<string, PbDeviceType, piscsi_util::StringHash, equal_to<>> extension_mapping;

unordered_map<string, PbDeviceType, piscsi_util::StringHash, equal_to<>> device_mapping;
const inline static unordered_map<string, PbDeviceType, piscsi_util::StringHash, equal_to<>> EXTENSION_MAPPING = {
{ "hd1", SCHD },
{ "hds", SCHD },
{ "hda", SCHD },
{ "hdn", SCHD },
{ "hdi", SCHD },
{ "nhd", SCHD },
{ "hdr", SCRM },
{ "mos", SCMO },
{ "is1", SCCD },
{ "iso", SCCD }
};

const inline static unordered_map<string, PbDeviceType, piscsi_util::StringHash, equal_to<>> DEVICE_MAPPING = {
{ "bridge", SCBR },
{ "daynaport", SCDP },
{ "printer", SCLP },
{ "services", SCHS }
};
};
18 changes: 8 additions & 10 deletions cpp/devices/device_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ void DeviceLogger::Error(const string& message) const

void DeviceLogger::Log(level::level_enum level, const string& message) const
{
if (!message.empty() &&
(log_device_id == -1 ||
(log_device_id == id && (log_device_lun == -1 || log_device_lun == lun)))) {
if (lun == -1) {
log(level, "(ID " + to_string(id) + ") - " + message);
}
else {
log(level, "(ID:LUN " + to_string(id) + ":" + to_string(lun) + ") - " + message);
}
}
if ((log_device_id == -1 || log_device_id == id) && (lun == -1 || log_device_lun == -1 || log_device_lun == lun)) {
if (lun == -1) {
log(level, "(ID " + to_string(id) + ") - " + message);
}
else {
log(level, "(ID:LUN " + to_string(id) + ":" + to_string(lun) + ") - " + message);
}
}
}

void DeviceLogger::SetIdAndLun(int i, int l)
Expand Down
16 changes: 11 additions & 5 deletions cpp/devices/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,26 +695,32 @@ uint32_t Disk::GetSectorSizeInBytes() const

void Disk::SetSectorSizeInBytes(uint32_t size_in_bytes)
{
if (DeviceFactory device_factory; !device_factory.GetSectorSizes(GetType()).contains(size_in_bytes)) {
throw io_exception("Invalid sector size of " + to_string(size_in_bytes) + " byte(s)");
if (!GetSupportedSectorSizes().contains(size_in_bytes)) {
throw io_exception("Invalid sector size of " + to_string(size_in_bytes) + " byte(s)");
}
uint64_t current_blocks = GetBlockCount();
uint32_t current_size_shift_count = size_shift_count;
uint64_t current_size = current_blocks << current_size_shift_count;

size_shift_count = CalculateShiftCount(size_in_bytes);
assert(size_shift_count);
if ((current_blocks > 0) && (current_size_shift_count > 0)) {
SetBlockCount(current_size >> size_shift_count);
}
}

uint32_t Disk::GetConfiguredSectorSize() const
{
return configured_sector_size;
}

bool Disk::SetConfiguredSectorSize(const DeviceFactory& device_factory, uint32_t configured_size)
bool Disk::SetConfiguredSectorSize(uint32_t configured_size)
{
if (!device_factory.GetSectorSizes(GetType()).contains(configured_size)) {
if (!supported_sector_sizes.contains(configured_size)) {
return false;
}

configured_sector_size = configured_size;
configured_sector_size = configured_size;

return true;
}
Expand Down
16 changes: 8 additions & 8 deletions cpp/devices/disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "shared/scsi.h"
#include "shared/piscsi_util.h"
#include "device_factory.h"
#include "disk_track.h"
#include "disk_cache.h"
#include "interfaces/scsi_block_commands.h"
Expand All @@ -35,8 +34,7 @@ class Disk : public StorageDevice, private ScsiBlockCommands

unique_ptr<DiskCache> cache;

// The supported configurable sector sizes, empty if not configurable
unordered_set<uint32_t> sector_sizes;
unordered_set<uint32_t> supported_sector_sizes;
uint32_t configured_sector_size = 0;

// Sector size shift count (9=512, 10=1024, 11=2048, 12=4096)
Expand All @@ -50,7 +48,9 @@ class Disk : public StorageDevice, private ScsiBlockCommands

public:

using StorageDevice::StorageDevice;
Disk(PbDeviceType type, int lun, const unordered_set<uint32_t>& s)
: StorageDevice(type, lun), supported_sector_sizes(s) {}
~Disk() override = default;

bool Init(const param_map&) override;
void CleanUp() override;
Expand All @@ -64,8 +64,9 @@ class Disk : public StorageDevice, private ScsiBlockCommands
virtual int Read(span<uint8_t> , uint64_t);

uint32_t GetSectorSizeInBytes() const;
bool IsSectorSizeConfigurable() const { return !sector_sizes.empty(); }
bool SetConfiguredSectorSize(const DeviceFactory&, uint32_t);
bool IsSectorSizeConfigurable() const { return supported_sector_sizes.size() > 1; }
const auto& GetSupportedSectorSizes() const { return supported_sector_sizes; }
bool SetConfiguredSectorSize(uint32_t);
void FlushCache() override;

vector<PbStatistics> GetStatistics() const override;
Expand Down Expand Up @@ -111,15 +112,14 @@ class Disk : public StorageDevice, private ScsiBlockCommands

void SetUpCache(off_t, bool = false);
void ResizeCache(const string&, bool);

bool GetRawMode() const { return (cache?cache->GetRawMode():false); }
void SetUpModePages(map<int, vector<byte>>&, int, bool) const override;
void AddErrorPage(map<int, vector<byte>>&, bool) const;
virtual void AddFormatPage(map<int, vector<byte>>&, bool) const;
virtual void AddDrivePage(map<int, vector<byte>>&, bool) const;
void AddCachePage(map<int, vector<byte>>&, bool) const;

unordered_set<uint32_t> GetSectorSizes() const;
void SetSectorSizes(const unordered_set<uint32_t>& sizes) { sector_sizes = sizes; }
void SetSectorSizeInBytes(uint32_t);
uint32_t GetSectorSizeShiftCount() const { return size_shift_count; }
void SetSectorSizeShiftCount(uint32_t count) { size_shift_count = count; }
Expand Down
Loading

0 comments on commit 83f4fea

Please sign in to comment.