forked from openebs-archive/node-disk-manager
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scsiinquirypage.go
69 lines (55 loc) · 2.12 KB
/
scsiinquirypage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Copyright 2018 The OpenEBS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// SCSI command definitions.
package smart
import (
"bytes"
"encoding/binary"
"fmt"
)
// commands used to fetch various information of a disk from a set of defined
// scsi pages
const (
SCSIInquiry = 0x12 // inquiry command
// Minimum length of standard INQUIRY response
INQRespLen = 56
)
// scsiInquiry sends an INQUIRY command to a SCSI device and returns an
// InquiryResponse struct.
func (d *SCSIDev) scsiInquiry() (InquiryResponse, error) {
var response InquiryResponse
respBuf := make([]byte, INQRespLen)
// Use cdb6 to send scsi inquiry command
// TODO: Use cdb10 or cdb16 also as a fallthrough command to if
// cdb6 fails for a particular device
cdb := CDB6{SCSIInquiry}
binary.BigEndian.PutUint16(cdb[3:], uint16(len(respBuf)))
// return error if sending scsi cdb6 command fails
if err := d.sendSCSICDB(cdb[:], &respBuf); err != nil {
return response, err
}
binary.Read(bytes.NewBuffer(respBuf), NativeEndian, &response)
return response, nil
}
// getValue returns the value of the attributes fetched using inquiry
// command using Inquiry response struct
func (inquiry InquiryResponse) getValue() map[string]string {
InqRespMap := make(map[string]string)
SPCVersionValue := fmt.Sprintf("%.d", (inquiry.Version - 0x02))
InqRespMap[Compliance] = "SPC-" + SPCVersionValue
InqRespMap[Vendor] = fmt.Sprintf("%.8s", inquiry.VendorID)
InqRespMap[ModelNumber] = fmt.Sprintf("%.16s", inquiry.ProductID)
InqRespMap[FirmwareRev] = fmt.Sprintf("%.4s", inquiry.ProductRev)
InqRespMap[SerialNumber] = fmt.Sprintf("%.20s", inquiry.SerialNumber)
return InqRespMap
}