4
4
#include < fcntl.h>
5
5
#include < sys/ioctl.h>
6
6
#include < unistd.h>
7
+ #include < QArrayDataPointer>
7
8
8
9
QVector<unsigned char > AsciiView::readSMARTData (const QString& device_path) {
9
10
int fd;
@@ -14,7 +15,12 @@ QVector<unsigned char> AsciiView::readSMARTData(const QString& device_path) {
14
15
unsigned char sense_buffer[SENSE_BUFFER_LEN];
15
16
sg_io_hdr_t io_hdr;
16
17
QVector<unsigned char > result;
18
+
17
19
fd = open (device_path.toStdString ().c_str (), O_RDONLY);
20
+ if (fd < 0 ) {
21
+ return result;
22
+ }
23
+
18
24
memset (&io_hdr, 0 , sizeof (sg_io_hdr_t ));
19
25
io_hdr.interface_id = ' S' ;
20
26
io_hdr.cmd_len = SMART_READ_CMD_LEN;
@@ -28,9 +34,11 @@ QVector<unsigned char> AsciiView::readSMARTData(const QString& device_path) {
28
34
29
35
if (ioctl (fd, SG_IO, &io_hdr) < 0 ) {
30
36
close (fd);
37
+ return result;
31
38
}
32
39
33
- result.append (QArrayDataPointer<unsigned char >::fromRawData (smart_read_resp, SMART_READ_RESP_LEN));
40
+ result.resize (SMART_READ_RESP_LEN);
41
+ memcpy (result.data (), smart_read_resp, SMART_READ_RESP_LEN);
34
42
35
43
memset (&io_hdr, 0 , sizeof (sg_io_hdr_t ));
36
44
io_hdr.interface_id = ' S' ;
@@ -45,9 +53,13 @@ QVector<unsigned char> AsciiView::readSMARTData(const QString& device_path) {
45
53
46
54
if (ioctl (fd, SG_IO, &io_hdr) < 0 ) {
47
55
close (fd);
56
+ return result;
48
57
}
49
58
50
- result.append (QArrayDataPointer<unsigned char >::fromRawData (inquiry_resp, INQUIRY_RESP_LEN));
59
+ int currentSize = result.size ();
60
+ result.resize (currentSize + INQUIRY_RESP_LEN);
61
+ memcpy (result.data () + currentSize, inquiry_resp, INQUIRY_RESP_LEN);
62
+
51
63
close (fd);
52
64
return result;
53
65
}
0 commit comments