update ModeSense6 function

This commit is contained in:
Lei Xue
2017-07-05 21:23:13 +08:00
parent 1d95f1d376
commit 8ce8ade3d4
6 changed files with 141 additions and 43 deletions
+11 -6
View File
@@ -96,20 +96,25 @@ func (sbc SBCSCSIDeviceProtocol) InitLu(lu *api.SCSILu) error {
}
pages := []api.ModePage{}
// Vendor uniq - However most apps seem to call for mode page 0
pages = append(pages, api.ModePage{0, 0, []byte{}})
//pages = append(pages, api.ModePage{0, 0, []byte{}})
// Disconnect page
pages = append(pages, api.ModePage{2, 0, []byte{0x80, 0x80, 0, 0xa, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}})
pages = append(pages, api.ModePage{2, 0, 14, []byte{0x80, 0x80, 0, 0xa, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}})
// Caching Page
pages = append(pages, api.ModePage{8, 0, []byte{0x14, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0}})
pages = append(pages, api.ModePage{8, 0, 18, []byte{0x14, 0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0, 0x4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}})
// Control page
pages = append(pages, api.ModePage{0x0a, 0, []byte{2, 0x10, 0, 0, 0, 0, 0, 0, 2, 0}})
pages = append(pages, api.ModePage{0x0a, 0, 10, []byte{2, 0x10, 0, 0, 0, 0, 0, 0, 2, 0, 0x08, 0, 0, 0, 0, 0, 0, 0}})
// Control Extensions mode page: TCMOS:1
pages = append(pages, api.ModePage{0x0a, 1, []byte{0x04, 0x00, 0x00}})
pages = append(pages, api.ModePage{0x0a, 1, 0x1c, []byte{0x04, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}})
// Informational Exceptions Control page
pages = append(pages, api.ModePage{0x1c, 0, []byte{8, 0, 0, 0, 0, 0, 0, 0, 0, 0}})
pages = append(pages, api.ModePage{0x1c, 0, 10, []byte{8, 0, 0, 0, 0, 0, 0, 0, 0, 0}})
lu.ModePages = pages
mbd := util.MarshalUint32(uint32(0xffffffff))
if size := lu.Size >> lu.BlockShift; size>>32 == 0 {
mbd = util.MarshalUint32(uint32(size))
}
lu.ModeBlockDescriptor = append(mbd, util.MarshalUint32(uint32(1<<lu.BlockShift))...)
return nil
}
+95 -11
View File
@@ -354,7 +354,7 @@ func SPCReportLuns(host int, cmd *api.SCSICommand) api.SAMStat {
// LUN list length
buf.Write(util.MarshalUint32(availLength))
cmd.InSDBBuffer.Resid = int32(actualLength)
cmd.InSDBBuffer.Resid = uint32(actualLength)
// Skip through to byte 4, Reserved
for i := 0; i < 4; i++ {
@@ -474,13 +474,17 @@ func SPCModeSense(host int, cmd *api.SCSICommand) api.SAMStat {
var (
scb = cmd.SCB.Bytes()
mode6 = (scb[0] == 0x1a)
dbd = scb[1] & 0x8 /* Disable Block Descriptors */
dbd = scb[1] & 0x8 // Disable Block Descriptors
pcode = scb[2] & 0x3f
pctrl = (scb[2] & 0xc0) >> 6
subpcode = scb[3]
blkDesctionLen = 0
key = ILLEGAL_REQUEST
asc = ASC_INVALID_FIELD_IN_CDB
data []byte
allocLen uint32
remainLen uint32
i uint32
)
if dbd == 0 {
blkDesctionLen = 8
@@ -489,11 +493,91 @@ func SPCModeSense(host int, cmd *api.SCSICommand) api.SAMStat {
asc = ASC_SAVING_PARMS_UNSUP
goto sense
}
_ = dbd
_ = pcode
_ = subpcode
_ = mode6
_ = blkDesctionLen
if mode6 {
allocLen = uint32(scb[4])
// set header
for i = 0; i < 4 && i < allocLen; i++ {
data = append(data, 0x00)
}
} else {
allocLen = uint32(util.GetUnalignedUint16(scb[7:9]))
// set header
for i = 0; i < 8 && i < allocLen; i++ {
data = append(data, 0x00)
}
}
remainLen = allocLen - uint32(len(data))
if dbd == 0 && remainLen >= 8 {
data = append(data, cmd.Device.ModeBlockDescriptor...)
}
if pcode == 0x3f {
for _, pg := range cmd.Device.ModePages {
if pg.SubPageCode == 0 {
if remainLen < 2+uint32(pg.Size) {
break
}
data = append(data, pg.PageCode)
data = append(data, pg.Size)
} else {
if remainLen < 4+uint32(pg.Size) {
break
}
data = append(data, pg.PageCode|0x40)
data = append(data, pg.SubPageCode)
data = append(data, (pg.Size>>8)&0xff)
data = append(data, pg.Size&0xff)
}
if pctrl == 1 {
data = append(data, pg.Data[pg.Size:]...)
} else {
data = append(data, pg.Data[:pg.Size]...)
}
}
} else {
var pg *api.ModePage
for _, p := range cmd.Device.ModePages {
if p.PageCode == pcode && p.SubPageCode == subpcode {
pg = &p
break
}
}
if pg == nil {
goto sense
}
if remainLen >= 2+uint32(pg.Size) {
if pg.SubPageCode == 0 {
data = append(data, pg.PageCode)
data = append(data, pg.Size)
if pctrl == 1 {
data = append(data, pg.Data[pg.Size:]...)
} else {
data = append(data, pg.Data[:pg.Size]...)
}
} else if remainLen >= 4+uint32(pg.Size) {
data = append(data, pg.PageCode|0x40)
data = append(data, pg.SubPageCode)
data = append(data, (pg.Size>>8)&0xff)
data = append(data, pg.Size&0xff)
if pctrl == 1 {
data = append(data, pg.Data[pg.Size:]...)
} else {
data = append(data, pg.Data[:pg.Size]...)
}
}
}
}
if mode6 {
data[0] = uint8(len(data) - 1)
data[3] = uint8(blkDesctionLen)
} else {
data[0] = uint8((len(data) - 2) >> 8)
data[1] = uint8(len(data) - 2)
data[6] = uint8(blkDesctionLen >> 8)
data[7] = uint8(blkDesctionLen)
}
cmd.InSDBBuffer.Resid = uint32(len(data))
cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data)
return api.SAMStatGood
sense:
BuildSenseData(cmd, key, asc)
@@ -660,7 +744,7 @@ func SPCPRReadKeys(host int, cmd *api.SCSICommand) api.SAMStat {
cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data)
}
cmd.InSDBBuffer.Resid = int32(additionLength)
cmd.InSDBBuffer.Resid = uint32(additionLength)
return api.SAMStatGood
sense:
cmd.InSDBBuffer.Resid = 0
@@ -715,7 +799,7 @@ func SPCPRReadReservation(host int, cmd *api.SCSICommand) api.SAMStat {
cmd.InSDBBuffer.Buffer = bytes.NewBuffer(data)
}
cmd.InSDBBuffer.Resid = int32(additionLength)
cmd.InSDBBuffer.Resid = uint32(additionLength)
return api.SAMStatGood
sense:
@@ -760,7 +844,7 @@ func SPCPRReportCapabilities(host int, cmd *api.SCSICommand) api.SAMStat {
} else {
actualLength = availLength
}
cmd.InSDBBuffer.Resid = int32(actualLength)
cmd.InSDBBuffer.Resid = uint32(actualLength)
return api.SAMStatGood
sense:
cmd.InSDBBuffer.Resid = 0
@@ -1257,7 +1341,7 @@ func SPCRequestSense(host int, cmd *api.SCSICommand) api.SAMStat {
if cmd.SenseBuffer != nil {
data.Write(cmd.SenseBuffer.Bytes()[:actualLength])
}
cmd.InSDBBuffer.Resid = int32(actualLength)
cmd.InSDBBuffer.Resid = uint32(actualLength)
cmd.InSDBBuffer.Buffer = data
// reset sense buffer in cmnd