#include <XrdCksManager.hh>
|
| XrdCksManager (XrdSysError *erP, int iosz, XrdVersionInfo &vInfo, bool autoload=false) |
|
virtual | ~XrdCksManager () |
|
virtual int | Calc (const char *Pfn, XrdCksData &Cks, int doSet=1) |
|
virtual int | Config (const char *Token, char *Line) |
|
virtual int | Del (const char *Pfn, XrdCksData &Cks) |
|
virtual int | Get (const char *Pfn, XrdCksData &Cks) |
|
virtual int | Init (const char *ConfigFN, const char *AddCalc=0) |
|
virtual char * | List (const char *Pfn, char *Buff, int Blen, char Sep=' ') |
|
virtual const char * | Name (int seqNum=0) |
|
virtual XrdCksCalc * | Object (const char *name) |
|
virtual int | Set (const char *Pfn, XrdCksData &Cks, int myTime=0) |
|
void | SetOpts (int opt) |
|
virtual int | Size (const char *Name=0) |
|
virtual int | Ver (const char *Pfn, XrdCksData &Cks) |
|
| XrdCks (XrdSysError *erP) |
| Constructor. More...
|
|
virtual | ~XrdCks () |
| Destructor. More...
|
|
virtual int | Calc (const char *Xfn, XrdCksData &Cks, XrdCksPCB *pcbP, int doSet=1) |
|
virtual int | Ver (const char *Xfn, XrdCksData &Cks, XrdCksPCB *pcbP) |
|
|
virtual int | Calc (const char *Pfn, time_t &MTime, XrdCksCalc *CksObj) |
|
virtual int | ModTime (const char *Pfn, time_t &MTime) |
|
Definition at line 48 of file XrdCksManager.hh.
◆ anonymous enum
◆ XrdCksManager()
XrdCksManager::XrdCksManager |
( |
XrdSysError * |
erP, |
|
|
int |
iosz, |
|
|
XrdVersionInfo & |
vInfo, |
|
|
bool |
autoload = false |
|
) |
| |
Definition at line 75 of file XrdCksManager.cc.
77 :
XrdCks(erP), myVersion(vInfo)
87 strcpy(csTab[0].
Name,
"adler32");
88 strcpy(csTab[1].
Name,
"crc32");
89 strcpy(csTab[2].
Name,
"crc32c");
90 strcpy(csTab[3].
Name,
"md5");
95 if (rdsz <= 65536) segSize = 67108864;
96 else segSize = ((rdsz/65536) + (rdsz%65536 != 0)) * 65536;
virtual const char * Name(int seqNum=0)
XrdCks(XrdSysError *erP)
Constructor.
References Name().
◆ ~XrdCksManager()
XrdCksManager::~XrdCksManager |
( |
| ) |
|
|
virtual |
Definition at line 103 of file XrdCksManager.cc.
106 for (i = 0; i <= csLast; i++)
107 {
if (csTab[i].Obj && csTab[i].doDel) csTab[i].Obj->Recycle();
108 if (csTab[i].
Path) free( csTab[i].
Path);
109 if (csTab[i].Parms) free( csTab[i].Parms);
110 if (csTab[i].Plugin)
delete csTab[i].Plugin;
112 if (cksLoader)
delete cksLoader;
References Path.
◆ Calc() [1/2]
int XrdCksManager::Calc |
( |
const char * |
Pfn, |
|
|
time_t & |
MTime, |
|
|
XrdCksCalc * |
CksObj |
|
) |
| |
|
protectedvirtual |
Reimplemented in XrdCksManOss.
Definition at line 161 of file XrdCksManager.cc.
167 ~ioFD() {
if (FD >= 0)
close(FD);}
171 off_t Offset=0, fileSize;
172 size_t ioSize, calcSize;
177 if ((In.FD =
open(Pfn, O_RDONLY)) < 0)
return -errno;
182 if (!(
Stat.st_mode & S_IFREG))
return -EPERM;
183 calcSize = fileSize =
Stat.st_size;
184 MTime =
Stat.st_mtime;
188 ioSize = (fileSize < (off_t)segSize ? fileSize : segSize); rc = 0;
190 {
if ((inBuff = (
char *)mmap(0, ioSize, PROT_READ,
191 #
if defined(__FreeBSD__)
192 MAP_RESERVED0040|MAP_PRIVATE, In.FD, Offset)) == MAP_FAILED)
193 #elif defined(__GNU__)
194 MAP_PRIVATE, In.FD, Offset)) == MAP_FAILED)
196 MAP_NORESERVE|MAP_PRIVATE, In.FD, Offset)) == MAP_FAILED)
198 {rc = errno;
eDest->
Emsg(
"Cks", rc,
"memory map", Pfn);
break;}
199 madvise(inBuff, ioSize, MADV_SEQUENTIAL);
200 csP->Update(inBuff, ioSize);
201 calcSize -= ioSize; Offset += ioSize;
202 if (munmap(inBuff, ioSize) < 0)
203 {rc = errno;
eDest->
Emsg(
"Cks",rc,
"unmap memory for",Pfn);
break;}
204 if (calcSize < (
size_t)segSize) ioSize = calcSize;
209 if (calcSize)
return (rc ? -rc : -EIO);
int stat(const char *path, struct stat *buf)
int open(const char *path, int oflag,...)
int fstat(int fildes, struct stat *buf)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
References close, XrdCks::eDest, XrdSysError::Emsg(), fstat(), open(), Stat, stat(), and XrdCksCalc::Update().
◆ Calc() [2/2]
int XrdCksManager::Calc |
( |
const char * |
Xfn, |
|
|
XrdCksData & |
Cks, |
|
|
int |
doSet = 1 |
|
) |
| |
|
virtual |
Calculate a new checksum for a physical file using the checksum algorithm named in the Cks parameter.
- Parameters
-
Xfn | The logical or physical name of the file to be checksumed. |
Cks | For input, it specifies the checksum algorithm to be used. For output, the checksum value is returned upon success. |
doSet | When true, the new value must replace any existing value in the Xfn's extended file attributes. |
pcbP | In the second form, the pointer to the callback object. A nil pointer does not invoke any callback. |
- Returns
- Success: zero with Cks structure holding the checksum value. Failure: -errno (see significant error numbers below).
Implements XrdCks.
Reimplemented in XrdCksManOss.
Definition at line 119 of file XrdCksManager.cc.
122 csInfo *csIP = &csTab[0];
128 if (csLast < 0)
return -ENOTSUP;
129 if (!(*Cks.
Name)) Cks.
Set(csIP->Name);
130 else if (!(csIP = Find(Cks.
Name)))
return -ENOTSUP;
137 if (!(csP = csIP->Obj->New()))
return -ENOMEM;
141 if (!(rc =
Calc(Pfn, MTime, csP)))
143 Cks.fmTime =
static_cast<long long>(MTime);
144 Cks.
csTime =
static_cast<int>(time(0) - MTime);
149 memcpy(&
xCS.Attr.Cks, &Cks,
sizeof(
xCS.Attr.Cks));
150 if ((rc =
xCS.Set(Pfn)))
return -rc;
XrdOucXAttr< XrdCksXAttr > xCS
virtual void Recycle()
Recycle the checksum object as it is no longer needed. A default is given.
int Set(const char *csName)
virtual int Calc(const char *Pfn, XrdCksData &Cks, int doSet=1)
References XrdCksData::csTime, XrdCksCalc::Final(), XrdCksData::Length, XrdCksData::Name, XrdCksCalc::New(), XrdCksCalc::Recycle(), XrdCksData::Set(), XrdCksData::Value, and xCS.
Referenced by XrdCksManOss::Calc(), and Ver().
◆ Config()
int XrdCksManager::Config |
( |
const char * |
Token, |
|
|
char * |
Line |
|
) |
| |
|
virtual |
Parse a configuration directives specific to the checksum manager.
- Parameters
-
Token | Points to the directive that triggered the call. |
Line | All the characters after the directive. |
- Returns
- Success: 1 Failure: 0
Implements XrdCks.
Definition at line 225 of file XrdCksManager.cc.
234 if (!(val =
Cfg.GetToken()) || !val[0])
235 {
eDest->
Emsg(
"Config",
"checksum name not specified");
return 1;}
237 {
eDest->
Emsg(
"Config",
"checksum name too long");
return 1;}
242 val =
Cfg.GetToken(&parms);
243 if (val && val[0]) path = strdup(val);
244 else {
eDest->
Emsg(
"Config",
"library path missing for ckslib digest",name);
250 for (i = 0; i < csMax; i++)
251 if (!(*csTab[i].
Name) || !strcmp(csTab[i].
Name, name))
break;
256 {
eDest->
Emsg(
"Config",
"too many checksums specified");
257 if (path) free(path);
259 }
else if (!(*csTab[i].
Name)) csLast = i;
263 strcpy(csTab[i].
Name, name);
264 if (csTab[i].
Path) free(csTab[i].
Path);
265 csTab[i].Path = path;
266 if (csTab[i].Parms) free(csTab[i].Parms);
267 csTab[i].Parms = (parms && *parms ? strdup(parms) : 0);
static const int NameSize
static void toLower(char *str)
References XrdNetPMarkConfig::Cfg, XrdCks::eDest, XrdSysError::Emsg(), Name(), XrdCksData::NameSize, Path, and XrdOucUtils::toLower().
Referenced by Init().
◆ Del()
int XrdCksManager::Del |
( |
const char * |
Xfn, |
|
|
XrdCksData & |
Cks |
|
) |
| |
|
virtual |
Delete the checksum from the Xfn's xattrs.
- Parameters
-
Xfn | The logical or physical name of the file to be checksumed. |
Cks | Specifies the checksum type to delete. |
- Returns
- Success: 0 Failure: -errno (see significant error numbers below).
Implements XrdCks.
Reimplemented in XrdCksManOss.
Definition at line 446 of file XrdCksManager.cc.
References XrdCksData::Name, and xCS.
Referenced by XrdCksManOss::Del().
◆ Get()
int XrdCksManager::Get |
( |
const char * |
Xfn, |
|
|
XrdCksData & |
Cks |
|
) |
| |
|
virtual |
Retreive the checksum from the Xfn's xattrs and return it and indicate whether or not it is stale (i.e. the file modification has changed or the name and length are not the expected values).
- Parameters
-
Xfn | The logical or physical name of the file to be checksumed. |
Cks | For input, it specifies the checksum type to return. For output, the checksum value is returned upon success. |
- Returns
- Success: The length of the binary checksum in the Cks structure. Failure: -errno (see significant error numbers below).
Implements XrdCks.
Reimplemented in XrdCksManOss.
Definition at line 463 of file XrdCksManager.cc.
471 if (csLast < 0)
return -ENOTSUP;
473 if (!
xCS.Attr.Cks.Set(Cks.
Name))
return -ENOTSUP;
477 if ((rc =
xCS.Get(Pfn)) <= 0)
return (rc && rc != -
ENOATTR ? rc : -ESRCH);
481 nFault = strcmp(
xCS.Attr.Cks.Name, Cks.
Name);
488 else if ((rc =
ModTime(Pfn, MTime)))
return rc;
492 return (Cks.fmTime != MTime || nFault
494 ? -ESTALE :
int(Cks.
Length));
static const int ValuSize
virtual int ModTime(const char *Pfn, time_t &MTime)
References Cks_nomtchk, ENOATTR, XrdCksData::Length, ModTime(), Name(), XrdCksData::Name, XrdCksData::Set(), XrdCksData::ValuSize, and xCS.
Referenced by XrdCksManOss::Get().
◆ Init()
int XrdCksManager::Init |
( |
const char * |
ConfigFN, |
|
|
const char * |
DfltCalc = 0 |
|
) |
| |
|
virtual |
Fully initialize the manager which includes loading any plugins.
- Parameters
-
ConfigFN | Points to the configuration file path. |
DfltCalc | Is the default checksum and should be defaulted if NULL. The default implementation defaults this to adler32. A default is only needed should the checksum name in the XrdCksData object be omitted. |
- Returns
- Success: 1 Failure: 0
Implements XrdCks.
Definition at line 278 of file XrdCksManager.cc.
285 {
for (i = 0; i < csLast; i++)
if (!strcmp(csTab[i].
Name, DfltCalc))
break;
287 {
eDest->
Emsg(
"Config", DfltCalc,
"cannot be made the default; "
291 if (i) {csInfo Temp = csTab[i]; csTab[i] = csTab[0]; csTab[0] = Temp;}
297 {
eDest->
Emsg(
"Config",
"No checksums defined; cannot configure!");
303 for (i = 0; i <= csLast; i++)
304 {
if (csTab[i].
Path) {
if (!(
Config(ConfigFN, csTab[i])))
return 0;}
305 else {
if (!strcmp(
"adler32", csTab[i].
Name))
307 else if (!strcmp(
"crc32", csTab[i].
Name))
309 else if (!strcmp(
"crc32c", csTab[i].
Name))
311 else if (!strcmp(
"md5", csTab[i].
Name))
313 else {
eDest->
Emsg(
"Config",
"Invalid native checksum -",
317 csTab[i].Obj->Type(csTab[i].Len);
virtual int Config(const char *Token, char *Line)
References Config(), XrdCks::eDest, XrdSysError::Emsg(), Name(), and Path.
◆ List()
char * XrdCksManager::List |
( |
const char * |
Xfn, |
|
|
char * |
Buff, |
|
|
int |
Blen, |
|
|
char |
Sep = ' ' |
|
) |
| |
|
virtual |
List names of the checksums associated with a Xfn or all supported ones.
- Parameters
-
Xfn | The logical or physical file name whose checksum names are to be returned. When Xfn is null, return all supported checksum algorithm names. |
Buff | Points to a buffer, at least 64 bytes in length, to hold a "Sep" separated list of checksum names. |
Blen | The length of the buffer. |
Sep | The separation character to be used between adjacent names. |
- Returns
- Success: Pointer to Buff holding at least one checksum name. Failure: A nil pointer is returned.
Implements XrdCks.
Reimplemented in XrdCksManOss.
Definition at line 501 of file XrdCksManager.cc.
503 static const char *vPfx =
"XrdCks.";
504 static const int vPln = strlen(vPfx);
511 if (Blen < 2)
return 0;
516 {
if (csLast < 0)
return 0;
518 while(i <= csLast && Blen > 1)
519 {n = strlen(csTab[i].
Name);
520 if (n >= Blen)
break;
521 if (bP != Buff) *bP++ = Sep;
522 strcpy(bP, csTab[i].
Name); bP += n; *bP = 0;
524 return (bP == Buff ? 0 : Buff);
535 {
if (vP->
Nlen > vPln && !strncmp(vP->
Name, vPfx, vPln))
536 {n = vP->
Nlen - vPln;
537 if (n >= Blen)
break;
538 if (bP != Buff) *bP++ = Sep;
539 strcpy(bP, vP->
Name + vPln); bP += n; *bP = 0;
547 return (bP == Buff ? 0 : Buff);
virtual char * List(const char *Pfn, char *Buff, int Blen, char Sep=' ')
char Name[1]
Start of the name (size of struct is dynamic)
int Nlen
The length of the attribute name that follows.
virtual void Free(AList *aPL)=0
AList * Next
-> next element.
References XrdSysXAttr::Free(), Name(), XrdSysXAttr::AList::Name, XrdSysXAttr::AList::Next, XrdSysXAttr::AList::Nlen, and XrdSysFAttr::Xat.
Referenced by XrdCksManOss::List().
◆ ModTime()
int XrdCksManager::ModTime |
( |
const char * |
Pfn, |
|
|
time_t & |
MTime |
|
) |
| |
|
protectedvirtual |
◆ Name()
const char * XrdCksManager::Name |
( |
int |
seqNum = 0 | ) |
|
|
virtual |
Get the name of the checksums associated with a sequence number. Note that Name() may be called prior to final config to see if there are any chksums to configure and avoid unintended errors.
- Parameters
-
seqNum | The sequence number. Zero signifies the default name. Higher numbers are alternates. |
- Returns
- Success: Pointer to the name. Failure: A nil pointer is returned (no more alternates exist).
Implements XrdCks.
Definition at line 568 of file XrdCksManager.cc.
571 return (seqNum < 0 || seqNum > csLast ? 0 : csTab[seqNum].
Name);
Referenced by XrdCksManager(), Config(), Get(), Init(), List(), and Size().
◆ Object()
XrdCksCalc * XrdCksManager::Object |
( |
const char * |
name | ) |
|
|
virtual |
Get a new XrdCksCalc object that can calculate the checksum corresponding to the specified name or the default object if name is a null pointer. The object can be used to compute checksums on the fly. The object's Recycle() method must be used to delete it.
- Parameters
-
name | The name of the checksum algorithm. If null, use the default one. |
- Returns
- Success: A pointer to the object is returned. Failure: Zero if no corresponding object exists.
Reimplemented from XrdCks.
Definition at line 578 of file XrdCksManager.cc.
580 csInfo *csIP = &csTab[0];
584 if (name && !(csIP = Find(name)))
return 0;
585 return csIP->Obj->New();
◆ Set()
int XrdCksManager::Set |
( |
const char * |
Xfn, |
|
|
XrdCksData & |
Cks, |
|
|
int |
myTime = 0 |
|
) |
| |
|
virtual |
Set a file's checksum in the extended attributes along with the file's mtime and the time of setting.
- Parameters
-
Xfn | The logical or physical name of the file to be set. |
Cks | Specifies the checksum name and value. |
myTime | When true then the fmTime and gmTime in the Cks structure are to be used; as opposed to the current time. |
- Returns
- Success: zero is returned. Failure: -errno (see significant error numbers below).
Implements XrdCks.
Reimplemented in XrdCksManOss.
Definition at line 602 of file XrdCksManager.cc.
605 csInfo *csIP = &csTab[0];
609 if (csLast < 0 || (*Cks.
Name && !(csIP = Find(Cks.
Name))))
return -ENOTSUP;
610 if (Cks.
Length != csIP->Len)
return -EDOM;
611 memcpy(&
xCS.Attr.Cks, &Cks,
sizeof(
xCS.Attr.Cks));
619 xCS.Attr.Cks.fmTime =
static_cast<long long>(MTime);
620 xCS.Attr.Cks.csTime =
static_cast<int>(time(0) - MTime);
References XrdCksData::Length, ModTime(), XrdCksData::Name, and xCS.
Referenced by XrdCksManOss::Set().
◆ SetOpts()
void XrdCksManager::SetOpts |
( |
int |
opt | ) |
|
◆ Size()
int XrdCksManager::Size |
( |
const char * |
Name = 0 | ) |
|
|
virtual |
Get the binary length of the checksum with the corresponding name.
- Parameters
-
Name | The checksum algorithm name. If null, use the default name. |
- Returns
- Success: checksum length. Failure: Zero if the checksum name does not exist.
Implements XrdCks.
Definition at line 592 of file XrdCksManager.cc.
594 csInfo *iP = (
Name != 0 ? Find(
Name) : &csTab[0]);
595 return (iP != 0 ? iP->Len : 0);
References Name().
◆ Ver()
int XrdCksManager::Ver |
( |
const char * |
Xfn, |
|
|
XrdCksData & |
Cks |
|
) |
| |
|
virtual |
Retreive the checksum from the Xfn's xattrs and compare it to the supplied checksum. If the checksum is not available or is stale, a new checksum is calculated and written to the extended attributes.
- Parameters
-
Xfn | The logical or physical name of the file to be verified. |
Cks | Specifies the checksum name and value. |
pcbP | In the second form, the pointer to the callback object. A nil pointer does not invoke any callback. |
- Returns
- Success: True Failure: False (the checksums do not match) or -errno indicating that verification could not be performed (see significant error numbers below).
Implements XrdCks.
Reimplemented in XrdCksManOss.
Definition at line 638 of file XrdCksManager.cc.
642 csInfo *csIP = &csTab[0];
647 if (csLast < 0 || (*Cks.
Name && !(csIP = Find(Cks.
Name))))
return -ENOTSUP;
648 xCS.Attr.Cks.Set(csIP->Name);
652 if ((rc =
ModTime(Pfn, MTime)))
return rc;
656 if ((rc =
xCS.Get(Pfn)) < 0)
return rc;
660 if (!rc ||
xCS.Attr.Cks.fmTime != MTime
661 || strcmp(
xCS.Attr.Cks.Name, csIP->Name)
662 ||
xCS.Attr.Cks.Length != csIP->Len)
663 {strcpy(
xCS.Attr.Cks.Name, Cks.
Name);
664 if ((rc =
Calc(Pfn,
xCS.Attr.Cks, 1)) < 0)
return rc;
669 return (
xCS.Attr.Cks.Length == Cks.
Length
670 && !memcmp(
xCS.Attr.Cks.Value, Cks.
Value, csIP->Len));
References Calc(), XrdCksData::Length, ModTime(), XrdCksData::Name, XrdCksData::Value, and xCS.
Referenced by XrdCksManOss::Ver().
The documentation for this class was generated from the following files: