Skip to content

Commit 4e18962

Browse files
committed
fix: prevent inquiry hangs
1 parent 2a542b4 commit 4e18962

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/machine/usb/msc/scsi.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (m *msc) scsiCmdBegin() {
5050
default:
5151
// We don't support this command, error out
5252
m.sendScsiError(csw.StatusFailed, scsi.SenseIllegalRequest, scsi.SenseCodeInvalidCmdOpCode)
53+
return
5354
}
5455

5556
if len(m.buf) == 0 {

src/machine/usb/msc/scsi_inquiry.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ func (m *msc) scsiEvpdInquiry(cmd scsi.Cmd, pageCode uint8) {
138138
// Set total bytes to the length of our response
139139
m.queuedBytes = uint32(len(m.buf))
140140
m.totalBytes = uint32(len(m.buf))
141+
142+
// Only send ZLP if the data length is a multiple of the max packet size
143+
if m.totalBytes%m.maxPacketSize == 0 {
144+
m.sendZLP = true
145+
}
141146
}
142147

143148
func (m *msc) scsiStdInquiry(cmd scsi.Cmd) {
@@ -162,4 +167,9 @@ func (m *msc) scsiStdInquiry(cmd scsi.Cmd) {
162167
copy(m.buf[16:32], m.productID[:])
163168
// bytes 32-35 - Product revision level
164169
copy(m.buf[32:36], m.productRev[:])
170+
171+
// Only send ZLP if the data length is a multiple of the max packet size
172+
if m.totalBytes%m.maxPacketSize == 0 {
173+
m.sendZLP = true
174+
}
165175
}

0 commit comments

Comments
 (0)