From 1a059f9f2685dd728f31feb7c62c89ce22c55485 Mon Sep 17 00:00:00 2001 From: Anton Schwarz Date: Thu, 25 Mar 2021 15:11:26 +0100 Subject: [PATCH 1/6] Added source and header files for crc32c-checksum. Also added them to the cmake file. --- src/XrdCks/XrdCksCalccrc32C.cc | 10 ++++++ src/XrdCks/XrdCksCalccrc32C.hh | 65 ++++++++++++++++++++++++++++++++++ src/XrdUtils.cmake | 1 + 3 files changed, 76 insertions(+) create mode 100644 src/XrdCks/XrdCksCalccrc32C.cc create mode 100644 src/XrdCks/XrdCksCalccrc32C.hh diff --git a/src/XrdCks/XrdCksCalccrc32C.cc b/src/XrdCks/XrdCksCalccrc32C.cc new file mode 100644 index 00000000000..796aee81828 --- /dev/null +++ b/src/XrdCks/XrdCksCalccrc32C.cc @@ -0,0 +1,10 @@ +#include "XrdCks/XrdCksCalccrc32C.hh" +void XrdCksCalccrc32C::Update(const char *Buff, int Blen) +{ + C32CResult = (unsigned int)crc32c(C32CResult, Buff, Blen); +} +const char *XrdCksCalccrc32C::Type(int &csSz) +{ + csSz = sizeof(TheResult); + return "crc32c"; +} \ No newline at end of file diff --git a/src/XrdCks/XrdCksCalccrc32C.hh b/src/XrdCks/XrdCksCalccrc32C.hh new file mode 100644 index 00000000000..d277dac3dd2 --- /dev/null +++ b/src/XrdCks/XrdCksCalccrc32C.hh @@ -0,0 +1,65 @@ +#ifndef __XRDCKSCALCCRC32_HH__ +#define __XRDCKSCALCCRC32_HH__ +/******************************************************************************/ +/* */ +/* X r d C k s C a l c c r c 3 2 . h h */ +/* */ +/* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */ +/* All Rights Reserved */ +/* Produced by Andrew Hanushevsky for Stanford University under contract */ +/* DE-AC02-76-SFO0515 with the Department of Energy */ +/* */ +/* This file is part of the XRootD software suite. */ +/* */ +/* XRootD is free software: you can redistribute it and/or modify it under */ +/* the terms of the GNU Lesser General Public License as published by the */ +/* Free Software Foundation, either version 3 of the License, or (at your */ +/* option) any later version. */ +/* */ +/* XRootD 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 Lesser General Public */ +/* License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License */ +/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ +/* COPYING (GPL license). If not, see . */ +/* */ +/* The copyright holder's institutional names and contributor's names may not */ +/* be used to endorse or promote products derived from this software without */ +/* specific prior written permission of the institution or contributor. */ +/******************************************************************************/ + +#include +#include +#include +#include + +#include "XrdCks/XrdCksCalc.hh" +#include "XrdSys/XrdSysPlatform.hh" +#include "XrdOuc/XrdOucCRC32C.hh" + +class XrdCksCalccrc32C : public XrdCksCalc +{ +public: + char *Final() + { + TheResult = C32CResult; +#ifndef Xrd_Big_Endian + TheResult = htonl(TheResult); +#endif + return (char *)&TheResult; + } + void Init() { C32CResult = CRC32C_XINIT; } + XrdCksCalc *New() {return (XrdCksCalc *)new XrdCksCalccrc32C;} + void Update(const char *Buff, int BLen); + const char *Type(int &csSz); + XrdCksCalccrc32C() { Init(); } + virtual ~XrdCksCalccrc32C() {} + +private: + static const unsigned int CRC32C_XINIT = 0; + unsigned int C32CResult; + unsigned int TheResult; +}; +#endif \ No newline at end of file diff --git a/src/XrdUtils.cmake b/src/XrdUtils.cmake index 9131c4f2c20..a4558018a1f 100644 --- a/src/XrdUtils.cmake +++ b/src/XrdUtils.cmake @@ -213,6 +213,7 @@ add_library( #----------------------------------------------------------------------------- XrdCks/XrdCksAssist.cc XrdCks/XrdCksAssist.hh XrdCks/XrdCksCalccrc32.cc XrdCks/XrdCksCalccrc32.hh + XrdCks/XrdCksCalccrc32C.cc XrdCks/XrdCksCalccrc32C.hh XrdCks/XrdCksCalcmd5.cc XrdCks/XrdCksCalcmd5.hh XrdCks/XrdCksConfig.cc XrdCks/XrdCksConfig.hh XrdCks/XrdCksLoader.cc XrdCks/XrdCksLoader.hh From cbfe495e9f41a2d7ae597981a177b7bd27856570 Mon Sep 17 00:00:00 2001 From: Anton Schwarz Date: Tue, 30 Mar 2021 19:59:45 +0200 Subject: [PATCH 2/6] added crc32c to natively supported checksums, typos --- src/XrdCks/XrdCks.hh | 2 +- src/XrdCks/XrdCksCalccrc32C.hh | 6 +++--- src/XrdCks/XrdCksManager.cc | 10 +++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/XrdCks/XrdCks.hh b/src/XrdCks/XrdCks.hh index 97b7d286daf..88ba82af862 100644 --- a/src/XrdCks/XrdCks.hh +++ b/src/XrdCks/XrdCks.hh @@ -48,7 +48,7 @@ class XrdSysPlugin; /******************************************************************************/ /* X r d C k s P C B */ /******************************************************************************/ -/*! The XrdCksPCB object defines a callabck hat allows he caller to monitor the +/*! The XrdCksPCB object defines a callback hat allows he caller to monitor the progress of a checksum calculation (calc or verify). */ diff --git a/src/XrdCks/XrdCksCalccrc32C.hh b/src/XrdCks/XrdCksCalccrc32C.hh index d277dac3dd2..00fb073cf3f 100644 --- a/src/XrdCks/XrdCksCalccrc32C.hh +++ b/src/XrdCks/XrdCksCalccrc32C.hh @@ -1,5 +1,5 @@ -#ifndef __XRDCKSCALCCRC32_HH__ -#define __XRDCKSCALCCRC32_HH__ +#ifndef __XRDCKSCALCCRC32C_HH__ +#define __XRDCKSCALCCRC32C_HH__ /******************************************************************************/ /* */ /* X r d C k s C a l c c r c 3 2 . h h */ @@ -51,7 +51,7 @@ public: return (char *)&TheResult; } void Init() { C32CResult = CRC32C_XINIT; } - XrdCksCalc *New() {return (XrdCksCalc *)new XrdCksCalccrc32C;} + XrdCksCalc *New() { return (XrdCksCalc *)new XrdCksCalccrc32C; } void Update(const char *Buff, int BLen); const char *Type(int &csSz); XrdCksCalccrc32C() { Init(); } diff --git a/src/XrdCks/XrdCksManager.cc b/src/XrdCks/XrdCksManager.cc index c0e144800c4..9aa850aee0b 100644 --- a/src/XrdCks/XrdCksManager.cc +++ b/src/XrdCks/XrdCksManager.cc @@ -41,6 +41,7 @@ #include "XrdCks/XrdCksCalc.hh" #include "XrdCks/XrdCksCalcadler32.hh" #include "XrdCks/XrdCksCalccrc32.hh" +#include "XrdCks/XrdCksCalccrc32C.hh" #include "XrdCks/XrdCksCalcmd5.hh" #include "XrdCks/XrdCksLoader.hh" #include "XrdCks/XrdCksManager.hh" @@ -76,8 +77,9 @@ XrdCksManager::XrdCksManager(XrdSysError *erP, int rdsz, XrdVersionInfo &vInfo, // strcpy(csTab[0].Name, "adler32"); strcpy(csTab[1].Name, "crc32"); - strcpy(csTab[2].Name, "md5"); - csLast = 2; + strcpy(csTab[2].Name, "crc32c"); + strcpy(csTab[3].Name, "md5"); + csLast = 3; // Compute the i/o size // @@ -295,6 +297,8 @@ int XrdCksManager::Init(const char *ConfigFN, const char *DfltCalc) csTab[i].Obj = new XrdCksCalcadler32; else if (!strcmp("crc32", csTab[i].Name)) csTab[i].Obj = new XrdCksCalccrc32; + else if (!strcmp("crc32c", csTab[i].Name)) + csTab[i].Obj = new XrdCksCalccrc32C; else if (!strcmp("md5", csTab[i].Name)) csTab[i].Obj = new XrdCksCalcmd5; else {eDest->Emsg("Config", "Invalid native checksum -", @@ -589,7 +593,7 @@ int XrdCksManager::Set(const char *Pfn, XrdCksData &Cks, int myTime) XrdOucXAttr xCS; csInfo *csIP = &csTab[0]; -// Verify the incomming checksum for correctness +// Verify the incoming checksum for correctness // if (csLast < 0 || (*Cks.Name && !(csIP = Find(Cks.Name)))) return -ENOTSUP; if (Cks.Length != csIP->Len) return -EDOM; From e572f569e12df5a066c8c03306c9d0753eb9e657 Mon Sep 17 00:00:00 2001 From: Anton Schwarz Date: Wed, 31 Mar 2021 20:01:24 +0200 Subject: [PATCH 3/6] rebasing --- src/XrdCks/XrdCksCalccrc32C.hh | 9 ++++++--- src/XrdCks/XrdCksManager.cc | 4 ++-- src/XrdOuc/XrdOucCache.cc | 6 ++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/XrdCks/XrdCksCalccrc32C.hh b/src/XrdCks/XrdCksCalccrc32C.hh index 00fb073cf3f..ab5a88b078f 100644 --- a/src/XrdCks/XrdCksCalccrc32C.hh +++ b/src/XrdCks/XrdCksCalccrc32C.hh @@ -2,9 +2,9 @@ #define __XRDCKSCALCCRC32C_HH__ /******************************************************************************/ /* */ -/* X r d C k s C a l c c r c 3 2 . h h */ +/* X r d C k s C a l c c r c 3 2 C . h h */ /* */ -/* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */ +/* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */ /* All Rights Reserved */ /* Produced by Andrew Hanushevsky for Stanford University under contract */ /* DE-AC02-76-SFO0515 with the Department of Energy */ @@ -50,7 +50,10 @@ public: #endif return (char *)&TheResult; } - void Init() { C32CResult = CRC32C_XINIT; } + void Init() + { + C32CResult = CRC32C_XINIT; + } XrdCksCalc *New() { return (XrdCksCalc *)new XrdCksCalccrc32C; } void Update(const char *Buff, int BLen); const char *Type(int &csSz); diff --git a/src/XrdCks/XrdCksManager.cc b/src/XrdCks/XrdCksManager.cc index 9aa850aee0b..9aca5564558 100644 --- a/src/XrdCks/XrdCksManager.cc +++ b/src/XrdCks/XrdCksManager.cc @@ -282,7 +282,7 @@ int XrdCksManager::Init(const char *ConfigFN, const char *DfltCalc) if (i) {csInfo Temp = csTab[i]; csTab[i] = csTab[0]; csTab[0] = Temp;} } -// See if there are any chacksums to configure +// See if there are any checksums to configure // if (csLast < 0) {eDest->Emsg("Config", "No checksums defined; cannot configure!"); @@ -400,7 +400,7 @@ XrdCksManager::csInfo *XrdCksManager::Find(const char *Name) return 0; } -// Attempte to dynamically load this object +// Attempt to dynamically load this object // { char buff[2048]; *buff = 0; diff --git a/src/XrdOuc/XrdOucCache.cc b/src/XrdOuc/XrdOucCache.cc index 0bc524eb89d..a72b242e461 100644 --- a/src/XrdOuc/XrdOucCache.cc +++ b/src/XrdOuc/XrdOucCache.cc @@ -44,6 +44,12 @@ int XrdOucCacheIO::pgRead(char *buff, { int bytes; +// Make sure the offset is on a 4K boundary and the size is a multiple of +// 4k as well (we use simple and for this). +// + if ((offs & XrdSys::PageMask) + || (rdlen & XrdSys::PageMask)) return -EINVAL; + // Read the data into the buffer // bytes = Read(buff, offs, rdlen); From f62cb58868dd629b72b5e3986fc9bf8857f0a72f Mon Sep 17 00:00:00 2001 From: Anton Schwarz Date: Sat, 3 Apr 2021 14:16:36 +0200 Subject: [PATCH 4/6] used the correct library --- src/XrdCks/XrdCksCalccrc32C.cc | 28 +++++++++++++++++++++++++--- src/XrdCks/XrdCksCalccrc32C.hh | 26 +++++++++----------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/XrdCks/XrdCksCalccrc32C.cc b/src/XrdCks/XrdCksCalccrc32C.cc index 796aee81828..ed351ee3005 100644 --- a/src/XrdCks/XrdCksCalccrc32C.cc +++ b/src/XrdCks/XrdCksCalccrc32C.cc @@ -1,10 +1,32 @@ #include "XrdCks/XrdCksCalccrc32C.hh" -void XrdCksCalccrc32C::Update(const char *Buff, int Blen) + +void XrdCksCalccrc32C::Update(const char *Buff, int BLen) { - C32CResult = (unsigned int)crc32c(C32CResult, Buff, Blen); + C32CResult = (unsigned int)XrdOucCRC::Calc32C(Buff, BLen, C32CResult); } + const char *XrdCksCalccrc32C::Type(int &csSz) { csSz = sizeof(TheResult); return "crc32c"; -} \ No newline at end of file +} + +XrdCksCalc *XrdCksCalccrc32C::New() { return (XrdCksCalc *)new XrdCksCalccrc32C; } + +void XrdCksCalccrc32C::Init() +{ + C32CResult = C32C_XINIT; +} + +char *XrdCksCalccrc32C::Final() +{ + TheResult = C32CResult; +#ifndef Xrd_Big_Endian + TheResult = htonl(TheResult); +#endif + return (char *)&TheResult; +} + +XrdCksCalccrc32C::XrdCksCalccrc32C() { Init(); } + +XrdCksCalccrc32C::~XrdCksCalccrc32C() {}; \ No newline at end of file diff --git a/src/XrdCks/XrdCksCalccrc32C.hh b/src/XrdCks/XrdCksCalccrc32C.hh index ab5a88b078f..9972dead952 100644 --- a/src/XrdCks/XrdCksCalccrc32C.hh +++ b/src/XrdCks/XrdCksCalccrc32C.hh @@ -37,31 +37,23 @@ #include "XrdCks/XrdCksCalc.hh" #include "XrdSys/XrdSysPlatform.hh" -#include "XrdOuc/XrdOucCRC32C.hh" +#include "XrdOuc/XrdOucCRC.hh" class XrdCksCalccrc32C : public XrdCksCalc { public: - char *Final() - { - TheResult = C32CResult; -#ifndef Xrd_Big_Endian - TheResult = htonl(TheResult); -#endif - return (char *)&TheResult; - } - void Init() - { - C32CResult = CRC32C_XINIT; - } - XrdCksCalc *New() { return (XrdCksCalc *)new XrdCksCalccrc32C; } + char *Final(); + + void Init(); + + XrdCksCalc *New(); void Update(const char *Buff, int BLen); const char *Type(int &csSz); - XrdCksCalccrc32C() { Init(); } - virtual ~XrdCksCalccrc32C() {} + XrdCksCalccrc32C(); + virtual ~XrdCksCalccrc32C(); private: - static const unsigned int CRC32C_XINIT = 0; + static const unsigned int C32C_XINIT = 0; unsigned int C32CResult; unsigned int TheResult; }; From 423b572146b1129e48ef3562db8489a3060d9db6 Mon Sep 17 00:00:00 2001 From: Anton Schwarz Date: Sat, 10 Apr 2021 16:57:55 +0200 Subject: [PATCH 5/6] added checksums to xrdcl... --- src/XrdCl/XrdClCheckSumManager.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/XrdCl/XrdClCheckSumManager.cc b/src/XrdCl/XrdClCheckSumManager.cc index 473c55165ae..34af7b3421d 100644 --- a/src/XrdCl/XrdClCheckSumManager.cc +++ b/src/XrdCl/XrdClCheckSumManager.cc @@ -26,6 +26,7 @@ #include "XrdCks/XrdCksCalc.hh" #include "XrdCks/XrdCksCalcmd5.hh" #include "XrdCks/XrdCksCalccrc32.hh" +#include "XrdCks/XrdCksCalccrc32C.hh" #include "XrdCks/XrdCksCalcadler32.hh" #include "XrdSys/XrdSysE2T.hh" #include "XrdSys/XrdSysPthread.hh" @@ -48,6 +49,7 @@ namespace XrdCl pLoader = new XrdCksLoader( XrdVERSIONINFOVAR( XrdCl ) ); pCalculators["md5"] = new XrdCksCalcmd5(); pCalculators["crc32"] = new XrdCksCalccrc32; + pCalculators["crc32c"] = new XrdCksCalccrc32C; pCalculators["adler32"] = new XrdCksCalcadler32; } From 99c467c5c6b5a5b41d4aab1176973422470f7372 Mon Sep 17 00:00:00 2001 From: Anton Schwarz Date: Mon, 26 Jul 2021 08:11:35 +0200 Subject: [PATCH 6/6] added attribution --- src/XrdCks/XrdCksCalccrc32C.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/XrdCks/XrdCksCalccrc32C.cc b/src/XrdCks/XrdCksCalccrc32C.cc index ed351ee3005..12bd303fcaf 100644 --- a/src/XrdCks/XrdCksCalccrc32C.cc +++ b/src/XrdCks/XrdCksCalccrc32C.cc @@ -1,5 +1,22 @@ #include "XrdCks/XrdCksCalccrc32C.hh" +/* + C++ implementation of CRC-32C checksums based upon + unattributed library functions. + + This file contains: + functions implementing the methods of the XrdCksCalc class + + Provided by: + Anton Schwarz + University of Heidelberg + July 26, 2021 + + Status: + Public Domain + +*/ + void XrdCksCalccrc32C::Update(const char *Buff, int BLen) { C32CResult = (unsigned int)XrdOucCRC::Calc32C(Buff, BLen, C32CResult);