Commit 8c0a7d3a authored by Eric Cano's avatar Eric Cano
Browse files

Turned the inquiryCDB struct into a class, with auto setting of the opcode...

Turned the inquiryCDB struct into a class, with auto setting of the opcode (which is always the same) and adapted the usage.
parent 0e0fdcd4
......@@ -88,10 +88,8 @@ namespace Tape {
unsigned char dataBuff[130];
unsigned char senseBuff[256];
SCSI::Structures::inquiryCDB_t cdb;
memset(&cdb, 0, sizeof (cdb));
memset(&dataBuff, 0, sizeof (dataBuff));
/* Build command */
cdb.opCode = SCSI::Commands::INQUIRY;
/* Build command: nothing to do. We go with defaults. */
sg_io_hdr_t sgh;
memset(&sgh, 0, sizeof (sgh));
......
......@@ -21,6 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#pragma once
namespace SCSI {
/* Extracted from linux kernel's include/scsi/scsi.h. System-level include
is less complete */
......
......@@ -28,6 +28,8 @@
#include <algorithm>
#include <arpa/inet.h>
#include "Constants.hh"
namespace SCSI {
/**
* Structures as defined in the SCSI specifications, and helper functions for them.
......@@ -38,11 +40,11 @@ namespace SCSI {
* http://hackipedia.org/Hardware/SCSI/Stream%20Commands/SCSI%20Stream%20Commands%20-%203.pdf
*/
namespace Structures {
/*
* Inquiry CDB as described in SPC-4.
*/
typedef struct {
class inquiryCDB_t {
public:
unsigned char opCode;
unsigned char EVPD : 1;
......@@ -53,7 +55,8 @@ namespace SCSI {
char allocationLength[2];
unsigned char control;
} inquiryCDB_t;
inquiryCDB_t() { memset(this, 0, sizeof(*this)); opCode = SCSI::Commands::INQUIRY; }
};
/*
* Inquiry data as described in SPC-4.
......
......@@ -105,14 +105,17 @@ namespace UnitTests {
TEST(SCSI_Structures, inquiryCDB_t) {
SCSI::Structures::inquiryCDB_t inqCDB;
memset(&inqCDB, 0, sizeof(inqCDB));
unsigned char *buff = (unsigned char *)&inqCDB;
/*
* Make sure this struct is a POD (plain old data without virtual table)
* (and has the right size).
*/
ASSERT_EQ(6, sizeof(inqCDB));
ASSERT_EQ(0, inqCDB.opCode);
buff[0] = SCSI::Commands::INQUIRY;
ASSERT_EQ(SCSI::Commands::INQUIRY, inqCDB.opCode);
buff[0] = 0;
ASSERT_EQ(0, inqCDB.opCode);
ASSERT_EQ(0, inqCDB.EVPD);
buff[1] = 0x1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment