diff --git a/tapeserver/castor/tape/tapeserver/SCSI/Structures.hpp b/tapeserver/castor/tape/tapeserver/SCSI/Structures.hpp index 1e3f3e6de171a64fb04574f1817887e32bc42123..c5d1edbc1f817b42f6825be9998e9440c1c98ab0 100644 --- a/tapeserver/castor/tape/tapeserver/SCSI/Structures.hpp +++ b/tapeserver/castor/tape/tapeserver/SCSI/Structures.hpp @@ -122,7 +122,7 @@ namespace SCSI { } /** - * Helper function to deal with endianness. + * Helper function to deal with endianness: 6-byte version * * The REOWP SCSI command assigns 48 bits to store the LOGICAL OBJECT IDENTIFIER (although other * commands use 64 bits or sometimes 32 bits). This function converts the 48-bit byte array @@ -131,7 +131,7 @@ namespace SCSI { * @param t byte array in SCSI order representing a 48-bit number * @return 64-bit unsigned integer */ - inline uint64_t toU48(const unsigned char(& t)[6]) + inline uint64_t toU64(const unsigned char(& t)[6]) { /* Like network, SCSI is BigEndian */ return (uint64_t) ntohl ( (*(uint64_t *) t << 32) >> 16) << 32 | ntohl(*(uint64_t *) t >>16); diff --git a/tapeserver/castor/tape/tapeserver/SCSI/StructuresTest.cpp b/tapeserver/castor/tape/tapeserver/SCSI/StructuresTest.cpp index 1aab34efc7662ddfc0f06a760699959c52445a26..5986f9427384e7a947a33fd1a00fe87a5935734d 100644 --- a/tapeserver/castor/tape/tapeserver/SCSI/StructuresTest.cpp +++ b/tapeserver/castor/tape/tapeserver/SCSI/StructuresTest.cpp @@ -656,6 +656,11 @@ namespace unitTests { ASSERT_EQ( -433494437, castor::tape::SCSI::Structures::toS32(num)); } + TEST(castor_tape_SCSI_Structures, toU64_6byte) { + unsigned char num[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE }; + ASSERT_EQ ( 0xDEADBEEFCAFEULL, castor::tape::SCSI::Structures::toU64(num)); + } + TEST(castor_tape_SCSI_Structures, toU64) { unsigned char num[8] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xFA, 0xDE }; ASSERT_EQ ( 0xDEADBEEFCAFEFADEULL, castor::tape::SCSI::Structures::toU64(num)); @@ -952,9 +957,9 @@ namespace unitTests { buff[2] = 0xFF; buff[3] = 0xFF; // In this record, the logical object identifier is 6 bytes (48 bits). - ASSERT_EQ(0U, castor::tape::SCSI::Structures::toU48(readEndOfWrapPositionDataShortForm.logicalObjectIdentifier)); + ASSERT_EQ(0U, castor::tape::SCSI::Structures::toU64(readEndOfWrapPositionDataShortForm.logicalObjectIdentifier)); buff[4] = 0xAB; buff[5] = 0xCD; buff[6] = 0xEF; buff[7] = 0x12; buff[8] = 0x34; buff[9] = 0x56; - ASSERT_EQ(0xABCDEF123456, castor::tape::SCSI::Structures::toU48(readEndOfWrapPositionDataShortForm.logicalObjectIdentifier)); + ASSERT_EQ(0xABCDEF123456, castor::tape::SCSI::Structures::toU64(readEndOfWrapPositionDataShortForm.logicalObjectIdentifier)); } TEST(castor_tape_SCSI_Structures, readEndOfWrapPositionDataLongForm_t) { @@ -986,10 +991,10 @@ namespace unitTests { buff[offset + 4] = 0xFF; buff[offset + 5] = 0xFF; // In this record, the logical object identifier is 6 bytes (48 bits). - ASSERT_EQ(0U, castor::tape::SCSI::Structures::toU48(readEndOfWrapPositionDataLongForm.wrapDescriptor[wrap].logicalObjectIdentifier)); + ASSERT_EQ(0U, castor::tape::SCSI::Structures::toU64(readEndOfWrapPositionDataLongForm.wrapDescriptor[wrap].logicalObjectIdentifier)); buff[offset + 6] = 0xAB; buff[offset + 7] = 0xCD; buff[offset + 8] = 0xEF; buff[offset + 9] = 0x12; buff[offset + 10] = 0x34; buff[offset + 11] = 0x56; - ASSERT_EQ(0xABCDEF123456, castor::tape::SCSI::Structures::toU48(readEndOfWrapPositionDataLongForm.wrapDescriptor[wrap].logicalObjectIdentifier)); + ASSERT_EQ(0xABCDEF123456, castor::tape::SCSI::Structures::toU64(readEndOfWrapPositionDataLongForm.wrapDescriptor[wrap].logicalObjectIdentifier)); } }