Skip to content

Commit

Permalink
Merge issue_113
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 11, 2024
1 parent 116f3e7 commit d768349
Show file tree
Hide file tree
Showing 16 changed files with 508 additions and 149 deletions.
11 changes: 7 additions & 4 deletions cpp/initiator/initiator_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
using namespace s2p_util;
using namespace initiator_util;

int InitiatorExecutor::Execute(scsi_command cmd, span<uint8_t> cdb, span<uint8_t> buffer, int length, int timeout)
int InitiatorExecutor::Execute(scsi_command cmd, span<uint8_t> cdb, span<uint8_t> buffer, int length, int timeout,
bool log)
{
cdb[0] = static_cast<uint8_t>(cmd);
return Execute(cdb, buffer, length, timeout);
return Execute(cdb, buffer, length, timeout, log);
}

int InitiatorExecutor::Execute(span<uint8_t> cdb, span<uint8_t> buffer, int length, int timeout)
int InitiatorExecutor::Execute(span<uint8_t> cdb, span<uint8_t> buffer, int length, int timeout, bool log)
{
bus.Reset();

Expand Down Expand Up @@ -68,7 +69,9 @@ int InitiatorExecutor::Execute(span<uint8_t> cdb, span<uint8_t> buffer, int leng
}

if (static_cast<status_code>(status) != status_code::intermediate) {
LogStatus();
if (log) {
LogStatus();
}
return status;
}
}
Expand Down
10 changes: 7 additions & 3 deletions cpp/initiator/initiator_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@ class InitiatorExecutor

void SetTarget(int, int, bool);

// Execute command with a default timeout of 3 s
int Execute(scsi_command, span<uint8_t>, span<uint8_t>, int, int = 3);
int Execute(span<uint8_t>, span<uint8_t>, int, int = 3);
int Execute(scsi_command, span<uint8_t>, span<uint8_t>, int, int, bool);
int Execute(span<uint8_t>, span<uint8_t>, int, int, bool);

int GetByteCount() const
{
return byte_count;
}

logger& GetLogger()
{
return initiator_logger;
}

private:

bool Dispatch(span<uint8_t>, span<uint8_t>, int&);
Expand Down
2 changes: 1 addition & 1 deletion cpp/initiator/initiator_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tuple<sense_key, asc, int> initiator_util::GetSenseData(InitiatorExecutor &execu
array<uint8_t, 6> cdb = { };
cdb[4] = static_cast<uint8_t>(buf.size());

if (executor.Execute(scsi_command::request_sense, cdb, buf, static_cast<int>(buf.size()))) {
if (executor.Execute(scsi_command::request_sense, cdb, buf, static_cast<int>(buf.size()), 1, true)) {
error("Can't execute REQUEST SENSE");
return {sense_key {-1}, asc {-1}, -1};
}
Expand Down
60 changes: 60 additions & 0 deletions cpp/s2pdump/disk_executor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//---------------------------------------------------------------------------
//
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi
//
// Copyright (C) 2023-2024 Uwe Seimet
//
//---------------------------------------------------------------------------

#include "disk_executor.h"
#include "shared/memory_util.h"

using namespace spdlog;
using namespace memory_util;

pair<uint64_t, uint32_t> DiskExecutor::ReadCapacity()
{
vector<uint8_t> buffer(14);
vector<uint8_t> cdb(10);

if (initiator_executor->Execute(scsi_command::read_capacity_10, cdb, buffer, 8, 1, true)) {
return {0, 0};
}

uint64_t capacity = GetInt32(buffer, 0);

int sector_size_offset = 4;

if (static_cast<int32_t>(capacity) == -1) {
cdb.resize(16);
// READ CAPACITY(16), not READ LONG(16)
cdb[1] = 0x10;

if (initiator_executor->Execute(scsi_command::read_capacity_16_read_long_16, cdb, buffer, 14, 1, true)) {
return {0, 0};
}

capacity = GetInt64(buffer, 0);

sector_size_offset = 8;
}

return {capacity + 1, GetInt32(buffer, sector_size_offset)};
}

bool DiskExecutor::ReadWrite(span<uint8_t> buffer, uint32_t bstart, uint32_t blength, int length, bool is_write)
{
vector<uint8_t> cdb(10);
SetInt32(cdb, 2, bstart);
SetInt16(cdb, 7, blength);

return !initiator_executor->Execute(is_write ? scsi_command::write_10 : scsi_command::read_10, cdb, buffer, length,
10, true);
}

void DiskExecutor::SynchronizeCache()
{
vector<uint8_t> cdb(10);

initiator_executor->Execute(scsi_command::synchronize_cache_10, cdb, { }, 0, 3, true);
}
31 changes: 31 additions & 0 deletions cpp/s2pdump/disk_executor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//---------------------------------------------------------------------------
//
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi
//
// Copyright (C) 2023-2024 Uwe Seimet
//
//---------------------------------------------------------------------------

#pragma once

#include "s2pdump_executor.h"

using namespace std;

class DiskExecutor : public S2pDumpExecutor
{

public:

DiskExecutor(Bus &bus, int id, logger &l) : S2pDumpExecutor(bus, id, l)
{
}

pair<uint64_t, uint32_t> ReadCapacity();
bool ReadWrite(span<uint8_t>, uint32_t, uint32_t, int, bool);
void SynchronizeCache();

private:

unique_ptr<S2pDumpExecutor> s2pdump_executor;
};
Loading

0 comments on commit d768349

Please sign in to comment.