Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
aa629531
Commit
aa629531
authored
Sep 06, 2016
by
Victor Kotlyar
Browse files
Moved castor::utils::CRC into cta/common
parent
75bc3be2
Changes
6
Hide whitespace changes
Inline
Side-by-side
common/CMakeLists.txt
View file @
aa629531
...
...
@@ -23,6 +23,8 @@ find_package (libuuid REQUIRED)
add_subdirectory
(
exception
)
set_source_files_properties
(
CRC.cpp PROPERTIES COMPILE_FLAGS -O2
)
set
(
COMMON_LIB_SRC_FILES
dataStructures/AdminHost.cpp
dataStructures/AdminUser.cpp
...
...
@@ -102,6 +104,7 @@ set (COMMON_LIB_SRC_FILES
remoteFS/RemotePath.cpp
remoteFS/RemotePathAndStatus.cpp
SmartFd.cpp
CRC.cpp
threading/ChildProcess.cpp
threading/Daemon.cpp
threading/Mutex.cpp
...
...
@@ -141,6 +144,7 @@ set (COMMON_UNIT_TESTS_LIB_SRC_FILES
log/StringLoggerTest.cpp
remoteFS/RemotePathTest.cpp
SmartFdTest.cpp
CRCTest.cpp
threading/DaemonTest.cpp
threading/SocketPairTest.cpp
threading/ThreadingBlockingQTests.cpp
...
...
tapeserver/castor/utils
/CRC.cpp
→
common
/CRC.cpp
View file @
aa629531
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"c
astor/utils
/CRC.hpp"
#include
"c
ommon
/CRC.hpp"
#include
<stdint.h>
namespace
cta
{
//-----------------------------------------------------------------------------
// crcRS_sw
//-----------------------------------------------------------------------------
uint32_t
castor
::
utils
::
CRC
::
crcRS_sw
(
const
uint32_t
crcInit
,
uint32_t
crcRS_sw
(
const
uint32_t
crcInit
,
const
uint32_t
cnt
,
const
void
*
const
start
)
{
static
const
uint32_t
crcTable
[
256
]
=
{
0x00000000
,
0x38CF3801
,
0x70837002
,
0x484C4803
,
0xE01BE004
,
0xD8D4D805
,
...
...
@@ -87,7 +86,7 @@ uint32_t castor::utils::CRC::crcRS_sw (const uint32_t crcInit,
//-----------------------------------------------------------------------------
// crc32c_sw
//-----------------------------------------------------------------------------
uint32_t
castor
::
utils
::
CRC
::
crc32c_sw
(
const
uint32_t
crcInit
,
uint32_t
crc32c_sw
(
const
uint32_t
crcInit
,
const
uint32_t
cnt
,
const
void
*
const
start
)
{
static
const
uint32_t
crcTable
[
256
]
=
{
...
...
@@ -194,7 +193,7 @@ uint32_t crc32c_intel_le_hw_64b(const uint32_t crcInit,
//-----------------------------------------------------------------------------
// crc32c_hw
//-----------------------------------------------------------------------------
uint32_t
castor
::
utils
::
CRC
::
crc32c_hw
(
const
uint32_t
crcInit
,
uint32_t
crc32c_hw
(
const
uint32_t
crcInit
,
const
uint32_t
cnt
,
const
void
*
const
start
)
{
/* Do CPU 64 instruction */
...
...
@@ -217,7 +216,7 @@ uint32_t castor::utils::CRC::crc32c_hw (const uint32_t crcInit,
//-----------------------------------------------------------------------------
// crc32c
//-----------------------------------------------------------------------------
uint32_t
castor
::
utils
::
CRC
::
crc32c
(
const
uint32_t
crcInit
,
const
uint32_t
cnt
,
uint32_t
crc32c
(
const
uint32_t
crcInit
,
const
uint32_t
cnt
,
const
void
*
const
start
)
{
int
sse42
;
...
...
@@ -228,7 +227,7 @@ uint32_t castor::utils::CRC::crc32c(const uint32_t crcInit, const uint32_t cnt,
//-----------------------------------------------------------------------------
// addCrc32cToMemoryBlock
//-----------------------------------------------------------------------------
uint32_t
castor
::
utils
::
CRC
::
addCrc32cToMemoryBlock
(
const
uint32_t
crcInit
,
uint32_t
addCrc32cToMemoryBlock
(
const
uint32_t
crcInit
,
const
uint32_t
cnt
,
uint8_t
*
start
)
{
if
(
cnt
==
0
)
return
0
;
//no such thing as a zero length block in SSC (write NOP)
...
...
@@ -245,7 +244,7 @@ uint32_t castor::utils::CRC::addCrc32cToMemoryBlock(const uint32_t crcInit,
//-----------------------------------------------------------------------------
// verifyCrc32cForMemoryBlockWithCrc32c
//-----------------------------------------------------------------------------
bool
castor
::
utils
::
CRC
::
verifyCrc32cForMemoryBlockWithCrc32c
(
bool
verifyCrc32cForMemoryBlockWithCrc32c
(
const
uint32_t
crcInit
,
const
uint32_t
cnt
,
const
uint8_t
*
start
)
{
if
(
cnt
<=
4
)
return
false
;
//block is too small to be valid, cannot check CRC
...
...
@@ -260,3 +259,5 @@ bool castor::utils::CRC::verifyCrc32cForMemoryBlockWithCrc32c(
return
false
;
//block CRC is incorrect
return
true
;
}
}
// namespace cta
\ No newline at end of file
tapeserver/castor/utils
/CRC.hpp
→
common
/CRC.hpp
View file @
aa629531
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include
<stdint.h>
namespace
castor
{
namespace
utils
{
namespace
CRC
{
namespace
cta
{
/**
* Set of CRC functions.
*/
...
...
@@ -130,6 +123,5 @@ uint32_t addCrc32cToMemoryBlock(const uint32_t crcInit,
bool
verifyCrc32cForMemoryBlockWithCrc32c
(
const
uint32_t
crcInit
,
const
uint32_t
cnt
,
const
uint8_t
*
start
);
}
// namespace CRC
}
// namespace utils
}
// namespace castor
}
// namespace cta
tapeserver/castor/utils
/CRCTest.cpp
→
common
/CRCTest.cpp
View file @
aa629531
/******************************************************************************
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
*
@author Castor Dev team, castor-dev@cern.ch
****************************************************************************
*/
*
You should have received a copy of the GNU General Public License
*
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
"c
astor/utils
/CRC.hpp"
#include
"c
ommon
/CRC.hpp"
#include
<gtest/gtest.h>
...
...
@@ -29,7 +24,7 @@
namespace
unitTests
{
class
ca
stor
_CRC
:
public
::
testing
::
Test
{
class
c
t
a_CRC
:
public
::
testing
::
Test
{
protected:
virtual
void
SetUp
()
{
...
...
@@ -39,8 +34,8 @@ protected:
}
};
TEST_F
(
ca
stor
_CRC
,
testCRCRS_sw
)
{
using
namespace
ca
stor
::
utils
::
CRC
;
TEST_F
(
c
t
a_CRC
,
testCRCRS_sw
)
{
using
namespace
c
t
a
;
const
uint8_t
block1
[]
=
{
2
,
3
,
5
,
7
,
11
,
13
,
17
,
19
,
23
,
29
,
31
,
37
,
41
,
43
,
47
,
53
,
59
,
61
,
67
,
71
,
73
,
79
,
83
,
89
,
97
,
101
,
103
,
107
,
109
,
113
,
127
,
...
...
@@ -59,8 +54,8 @@ TEST_F(castor_CRC, testCRCRS_sw) {
ASSERT_EQ
(
computedCRC3
,
0x754ED37E
);
}
TEST_F
(
ca
stor
_CRC
,
testCRC32C_sw
)
{
using
namespace
ca
stor
::
utils
::
CRC
;
TEST_F
(
c
t
a_CRC
,
testCRC32C_sw
)
{
using
namespace
c
t
a
;
const
uint8_t
block1
[]
=
{
2
,
3
,
5
,
7
,
11
,
13
,
17
,
19
,
23
,
29
,
31
,
37
,
41
,
43
,
47
,
53
,
59
,
61
,
67
,
71
,
73
,
79
,
83
,
89
,
97
,
101
,
103
,
107
,
109
,
113
,
127
,
...
...
@@ -78,8 +73,8 @@ TEST_F(castor_CRC, testCRC32C_sw) {
ASSERT_EQ
(
computedCRC2
,
0x56DAB0A6
);
ASSERT_EQ
(
computedCRC3
,
0x56DAB0A6
);
}
TEST_F
(
ca
stor
_CRC
,
testCRC32C_hw
)
{
using
namespace
ca
stor
::
utils
::
CRC
;
TEST_F
(
c
t
a_CRC
,
testCRC32C_hw
)
{
using
namespace
c
t
a
;
/* check if we have SSE4_2 to test hardware CRC32C */
int
sse42
;
...
...
@@ -103,8 +98,8 @@ TEST_F(castor_CRC, testCRC32C_hw) {
ASSERT_EQ
(
computedCRC3
,
0x56DAB0A6
);
}
}
TEST_F
(
ca
stor
_CRC
,
testCRC32C
)
{
using
namespace
ca
stor
::
utils
::
CRC
;
TEST_F
(
c
t
a_CRC
,
testCRC32C
)
{
using
namespace
c
t
a
;
const
uint8_t
block1
[]
=
{
2
,
3
,
5
,
7
,
11
,
13
,
17
,
19
,
23
,
29
,
31
,
37
,
41
,
43
,
47
,
53
,
59
,
61
,
67
,
71
,
73
,
79
,
83
,
89
,
97
,
101
,
103
,
107
,
109
,
113
,
127
,
...
...
tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp
View file @
aa629531
...
...
@@ -26,7 +26,7 @@
#include
"castor/tape/tapeserver/drive/DriveGeneric.hpp"
#include
"castor/utils/Timer.hpp"
#include
"c
astor/utils
/CRC.hpp"
#include
"c
ommon
/CRC.hpp"
#include
"common/exception/MemException.hpp"
namespace
castor
{
...
...
@@ -703,7 +703,7 @@ void drive::DriveGeneric::writeBlock(const void * data, size_t count) {
}
memcpy
(
dataWithCrc32c
,
data
,
count
);
const
size_t
countWithCrc32c
=
ca
stor
::
utils
::
CRC
::
addCrc32cToMemoryBlock
(
c
t
a
::
addCrc32cToMemoryBlock
(
SCSI
::
logicBlockProtectionMethod
::
CRC32CSeed
,
count
,
dataWithCrc32c
);
if
(
countWithCrc32c
!=
...
...
@@ -771,7 +771,7 @@ ssize_t drive::DriveGeneric::readBlock(void * data, size_t count) {
delete
[]
dataWithCrc32c
;
throw
cta
::
exception
::
Exception
(
"In DriveGeneric::readBlock: wrong data block size, checksum cannot fit"
);
}
if
(
ca
stor
::
utils
::
CRC
::
verifyCrc32cForMemoryBlockWithCrc32c
(
if
(
c
t
a
::
verifyCrc32cForMemoryBlockWithCrc32c
(
SCSI
::
logicBlockProtectionMethod
::
CRC32CSeed
,
res
,
dataWithCrc32c
))
{
// everything is fine here do mem copy
...
...
@@ -835,7 +835,7 @@ void drive::DriveGeneric::readExactBlock(void * data, size_t count, std::string
delete
[]
dataWithCrc32c
;
throw
UnexpectedSize
(
context
);
}
if
(
ca
stor
::
utils
::
CRC
::
verifyCrc32cForMemoryBlockWithCrc32c
(
if
(
c
t
a
::
verifyCrc32cForMemoryBlockWithCrc32c
(
SCSI
::
logicBlockProtectionMethod
::
CRC32CSeed
,
res
,
dataWithCrc32c
))
{
// everything is fine here do mem copy
...
...
tapeserver/castor/utils/CMakeLists.txt
View file @
aa629531
...
...
@@ -22,11 +22,9 @@ cmake_minimum_required (VERSION 2.6)
include_directories
(
/usr/include/shift
)
include_directories
(
${
PROJECT_SOURCE_DIR
}
/tapeserver
)
set_source_files_properties
(
CRC.cpp PROPERTIES COMPILE_FLAGS -O2
)
set
(
UTILS_LIB_SRC_FILES
SmartFILEPtr.cpp
Timer.cpp
CRC.cpp
utils.cpp
../common/CastorConfiguration.cpp
../System.cpp
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment