--- nono/vm/scsidev.cpp 2026/04/29 17:04:47 1.1.1.7 +++ nono/vm/scsidev.cpp 2026/04/29 17:04:56 1.1.1.10 @@ -9,14 +9,14 @@ #include "scsidev.h" #include "config.h" #include "mainapp.h" -#include "mystring.h" // // SCSI デバイス // // コンストラクタ -SCSIDevice::SCSIDevice() +SCSIDevice::SCSIDevice(const std::string& objname_) + : inherited(objname_) { } @@ -30,7 +30,8 @@ SCSIDevice::~SCSIDevice() // // コンストラクタ -SCSIHostDevice::SCSIHostDevice() +SCSIHostDevice::SCSIHostDevice(const std::string& objname_) + : inherited(objname_) { devtype = SCSI::DevType::Initiator; @@ -114,7 +115,7 @@ SCSIHostDevice::Init() } } if (!typestr.empty()) { - putmsg("%s target #%d %s", GetConfigName(), id, + putmsgn("%s target #%d %s", GetConfigName(), id, typestr.c_str()); } } @@ -334,7 +335,7 @@ class SCSICmdRead6 : public SCSICmd if (blks == 0) { blks = 256; } - parent->putlog(1, "READ6 LBA=0x%x blks=0x%x", lba, blks); + parent->putlogf(1, lstr("READ6 LBA=0x%x blks=0x%x", lba, blks)); if (((uint64)lba + (uint64)blks) * parent->GetBlocksize() > hdparent->GetSize()) @@ -398,7 +399,7 @@ class SCSICmdWrite6 : public SCSICmd } SCSI::XferPhase DoneDataOut() override { - parent->putlog(1, "WRITE6 LBA=0x%x blks=0x%x", lba, blks); + parent->putlogf(1, lstr("WRITE6 LBA=0x%x blks=0x%x", lba, blks)); if (hdparent->writeprotect == false) { memcpy(hdparent->mem + (lba * parent->GetBlocksize()), buf.data(), buf.size()); @@ -500,7 +501,8 @@ class SCSICmdModeSense6 : public SCSICmd parent->ClearSense(); // 未実装 (XXX センスデータは適当) - parent->putlog(1, "ModeSense(6) PageCode $%02x 未実装", pagecode); + parent->putlogf(1, lstr("ModeSense(6) PageCode $%02x 未実装", + pagecode)); parent->sensekey = SCSI::SenseKey::IllegalRequest; parent->senseasc = SCSI::ASC::InvalidFieldInCDB; status_byte = SCSI::StatusByte::CheckCondition; @@ -524,7 +526,7 @@ class SCSICmdStartStopUnit : public SCSI // XXX それっぽい時間待つくらいはしてもいいかも知れない SCSI::XferPhase Command(std::vector& cmdseq) override { - parent->putlog(1, "StartStopUnit"); + parent->putlogf(1, lstr("StartStopUnit")); return inherited::Command(cmdseq); } }; @@ -547,7 +549,7 @@ class SCSICmdReadCapacity : public SCSIC // PMI=1 は未サポート if ((cmdseq[8] & 0x01) != 0) { - parent->putmsg("SCSI ReadCapacity PMI=1 not supported"); + parent->putlogf(0, lstr("SCSI ReadCapacity PMI=1 not supported")); } // 応答データは @@ -588,7 +590,7 @@ class SCSICmdRead10 : public SCSICmd parent->ClearSense(); if ((cmdseq[1] & 0x01)) { - parent->putmsg("SCSI Read(10) RelAdr not supported"); + parent->putlogf(0, lstr("SCSI Read(10) RelAdr not supported")); } lba = cmdseq[2] << 24; @@ -597,7 +599,7 @@ class SCSICmdRead10 : public SCSICmd lba |= cmdseq[5]; blks = cmdseq[7] << 8; blks |= cmdseq[8]; - parent->putlog(1, "READ10 LBA=0x%x blks=0x%x", lba, blks); + parent->putlogf(1, lstr("READ10 LBA=0x%x blks=0x%x", lba, blks)); if (((uint64)lba + (uint64)blks) * parent->GetBlocksize() > hdparent->GetSize()) @@ -659,7 +661,7 @@ class SCSICmdWrite10 : public SCSICmd } SCSI::XferPhase DoneDataOut() override { - parent->putlog(1, "WRITE10 LBA=0x%x blks=0x%x", lba, blks); + parent->putlogf(1, lstr("WRITE10 LBA=0x%x blks=0x%x", lba, blks)); if (hdparent->writeprotect == false) { memcpy(hdparent->mem + (lba * parent->GetBlocksize()), buf.data(), buf.size()); @@ -701,11 +703,10 @@ class SCSICmdNotSupportedCommand : publi // // コンストラクタ -SCSITarget::SCSITarget(SCSIHostDevice *h, int id, std::vector& inq) +SCSITarget::SCSITarget(const std::string& objname_, + SCSIHostDevice *h, int id, std::vector& inq) + : inherited(objname_) { - logname = "scsitarget"; - devname = "SCSITarget"; - inquiry_data = inq; // ホストへのリンク (所有関係のないポインタ) host = h; @@ -717,6 +718,20 @@ SCSITarget::~SCSITarget() { } +// 電源オン +bool +SCSITarget::PowerOn() +{ + ClearSense(); + cmdseq.clear(); + cmdlen = 0; + cmd.reset(); + bytecount = 0; + lastbyte = false; + + return true; +} + // バスリセットされた (SCSIBus から呼ばれる) void SCSITarget::BusResetCB() @@ -839,7 +854,7 @@ SCSITarget::TransferCB() for (const auto& v : cmdseq) { cmdbuf += string_format(" $%02x", v); } - putlog("%s", cmdbuf.c_str()); + putlogn("%s", cmdbuf.c_str()); } // 最終バイトを受信したらコマンドを選択 DispatchCmd(); @@ -1018,9 +1033,10 @@ SCSITarget::DispatchCmd() // コンストラクタ SCSIHD::SCSIHD(SCSIHostDevice *h, int id) - : inherited(h, id, inquiry_data) + : inherited(string_format("SCSIHD%d", id), h, id, inquiry_data) { - devname = "SCSIHD"; + AddAlias(string_format("HD%d", id)); + devtype = SCSI::DevType::HD; }