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.cc b/src/XrdCks/XrdCksCalccrc32C.cc new file mode 100644 index 00000000000..12bd303fcaf --- /dev/null +++ b/src/XrdCks/XrdCksCalccrc32C.cc @@ -0,0 +1,49 @@ +#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); +} + +const char *XrdCksCalccrc32C::Type(int &csSz) +{ + csSz = sizeof(TheResult); + return "crc32c"; +} + +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 new file mode 100644 index 00000000000..9972dead952 --- /dev/null +++ b/src/XrdCks/XrdCksCalccrc32C.hh @@ -0,0 +1,60 @@ +#ifndef __XRDCKSCALCCRC32C_HH__ +#define __XRDCKSCALCCRC32C_HH__ +/******************************************************************************/ +/* */ +/* X r d C k s C a l c c r c 3 2 C . h h */ +/* */ +/* (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 */ +/* */ +/* 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/XrdOucCRC.hh" + +class XrdCksCalccrc32C : public XrdCksCalc +{ +public: + char *Final(); + + void Init(); + + XrdCksCalc *New(); + void Update(const char *Buff, int BLen); + const char *Type(int &csSz); + XrdCksCalccrc32C(); + virtual ~XrdCksCalccrc32C(); + +private: + static const unsigned int C32C_XINIT = 0; + unsigned int C32CResult; + unsigned int TheResult; +}; +#endif \ No newline at end of file diff --git a/src/XrdCks/XrdCksManager.cc b/src/XrdCks/XrdCksManager.cc index c0e144800c4..9aca5564558 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 // @@ -280,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!"); @@ -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 -", @@ -396,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; @@ -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; 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; } 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); 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