From cbd1a8cf7822aa97996104f6597469ab8b791ecf Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 3 Sep 2019 22:40:18 -0400 Subject: [PATCH] Factors out command termination, adds a default implementation of test unit ready. --- Storage/MassStorage/SCSI/DirectAccessDevice.cpp | 6 +----- Storage/MassStorage/SCSI/Target.hpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Storage/MassStorage/SCSI/DirectAccessDevice.cpp b/Storage/MassStorage/SCSI/DirectAccessDevice.cpp index f09f94367..6b2de9d68 100644 --- a/Storage/MassStorage/SCSI/DirectAccessDevice.cpp +++ b/Storage/MassStorage/SCSI/DirectAccessDevice.cpp @@ -19,11 +19,7 @@ bool DirectAccessDevice::read(const Target::CommandState &state, Target::Respond if(!device_) return false; responder.send_data(device_->get_block(state.address()), [] (const Target::CommandState &state, Target::Responder &responder) { - responder.send_message(Target::Responder::Message::CommandComplete, [] (const Target::CommandState &state, Target::Responder &responder) { - responder.send_status(Target::Responder::Status::Good, [] (const Target::CommandState &state, Target::Responder &responder) { - responder.end_command(); - }); - }); + responder.terminate_command(Target::Responder::Status::Good); }); return true; diff --git a/Storage/MassStorage/SCSI/Target.hpp b/Storage/MassStorage/SCSI/Target.hpp index 9d25eb8fa..3977a1dff 100644 --- a/Storage/MassStorage/SCSI/Target.hpp +++ b/Storage/MassStorage/SCSI/Target.hpp @@ -79,6 +79,16 @@ struct Responder { Ends the SCSI command. */ virtual void end_command() = 0; + /*! + Terminates a SCSI command, sending the proper sequence of status and message phases. + */ + void terminate_command(Status status) { + send_message(Target::Responder::Message::CommandComplete, [status] (const Target::CommandState &state, Target::Responder &responder) { + responder.send_status(status, [] (const Target::CommandState &state, Target::Responder &responder) { + responder.end_command(); + }); + }); + } }; /*! @@ -92,7 +102,11 @@ struct Responder { */ struct Executor { /* Group 0 commands. */ - bool test_unit_ready(const CommandState &, Responder &) { return false; } + bool test_unit_ready(const CommandState &, Responder &responder) { + /* "Returns zero status if addressed unit is powered on and ready. */ + responder.terminate_command(Target::Responder::Status::Good); + return true; + } bool rezero_unit(const CommandState &, Responder &) { return false; } bool request_sense(const CommandState &, Responder &) { return false; } bool format_unit(const CommandState &, Responder &) { return false; }