44#include < fcntl.h>
55#include < sys/ioctl.h>
66#include < unistd.h>
7+ #include < QArrayDataPointer>
78
89QVector<unsigned char > AsciiView::readSMARTData (const QString& device_path) {
910 int fd;
@@ -14,7 +15,12 @@ QVector<unsigned char> AsciiView::readSMARTData(const QString& device_path) {
1415 unsigned char sense_buffer[SENSE_BUFFER_LEN ];
1516 sg_io_hdr_t io_hdr;
1617 QVector<unsigned char > result;
18+
1719 fd = open (device_path.toStdString ().c_str (), O_RDONLY );
20+ if (fd < 0 ) {
21+ return result;
22+ }
23+
1824 memset (&io_hdr, 0 , sizeof (sg_io_hdr_t ));
1925 io_hdr.interface_id = ' S' ;
2026 io_hdr.cmd_len = SMART_READ_CMD_LEN ;
@@ -28,9 +34,11 @@ QVector<unsigned char> AsciiView::readSMARTData(const QString& device_path) {
2834
2935 if (ioctl (fd, SG_IO , &io_hdr) < 0 ) {
3036 close (fd);
37+ return result;
3138 }
3239
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 );
3442
3543 memset (&io_hdr, 0 , sizeof (sg_io_hdr_t ));
3644 io_hdr.interface_id = ' S' ;
@@ -45,9 +53,13 @@ QVector<unsigned char> AsciiView::readSMARTData(const QString& device_path) {
4553
4654 if (ioctl (fd, SG_IO , &io_hdr) < 0 ) {
4755 close (fd);
56+ return result;
4857 }
4958
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+
5163 close (fd);
5264 return result;
5365}
0 commit comments