#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) |
|
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.
◆ XrdCksManager()
XrdCksManager::XrdCksManager |
( |
XrdSysError * |
erP, |
|
|
int |
iosz, |
|
|
XrdVersionInfo & |
vInfo, |
|
|
bool |
autoload = false |
|
) |
| |
Definition at line 66 of file XrdCksManager.cc.
68 :
XrdCks(erP), myVersion(vInfo)
78 strcpy(csTab[0].
Name,
"adler32");
79 strcpy(csTab[1].
Name,
"crc32");
80 strcpy(csTab[2].
Name,
"crc32c");
81 strcpy(csTab[3].
Name,
"md5");
86 if (rdsz <= 65536) segSize = 67108864;
87 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 94 of file XrdCksManager.cc.
97 for (i = 0; i <= csLast; i++)
98 {
if (csTab[i].Obj && csTab[i].doDel) csTab[i].Obj->Recycle();
99 if (csTab[i].
Path) free( csTab[i].
Path);
100 if (csTab[i].Parms) free( csTab[i].Parms);
101 if (csTab[i].Plugin)
delete csTab[i].Plugin;
103 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 152 of file XrdCksManager.cc.
158 ~ioFD() {
if (FD >= 0)
close(FD);}
162 off_t Offset=0, fileSize;
163 size_t ioSize, calcSize;
168 if ((In.FD =
open(Pfn, O_RDONLY)) < 0)
return -errno;
173 if (!(
Stat.st_mode & S_IFREG))
return -EPERM;
174 calcSize = fileSize =
Stat.st_size;
175 MTime =
Stat.st_mtime;
179 ioSize = (fileSize < (off_t)segSize ? fileSize : segSize); rc = 0;
181 {
if ((inBuff = (
char *)mmap(0, ioSize, PROT_READ,
182 #
if defined(__FreeBSD__)
183 MAP_RESERVED0040|MAP_PRIVATE, In.FD, Offset)) == MAP_FAILED)
184 #elif defined(__GNU__)
185 MAP_PRIVATE, In.FD, Offset)) == MAP_FAILED)
187 MAP_NORESERVE|MAP_PRIVATE, In.FD, Offset)) == MAP_FAILED)
189 {rc = errno;
eDest->
Emsg(
"Cks", rc,
"memory map", Pfn);
break;}
190 madvise(inBuff, ioSize, MADV_SEQUENTIAL);
191 csP->Update(inBuff, ioSize);
192 calcSize -= ioSize; Offset += ioSize;
193 if (munmap(inBuff, ioSize) < 0)
194 {rc = errno;
eDest->
Emsg(
"Cks",rc,
"unmap memory for",Pfn);
break;}
195 if (calcSize < (
size_t)segSize) ioSize = calcSize;
200 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 110 of file XrdCksManager.cc.
113 csInfo *csIP = &csTab[0];
119 if (csLast < 0)
return -ENOTSUP;
120 if (!(*Cks.
Name)) Cks.
Set(csIP->Name);
121 else if (!(csIP = Find(Cks.
Name)))
return -ENOTSUP;
128 if (!(csP = csIP->Obj->New()))
return -ENOMEM;
132 if (!(rc =
Calc(Pfn, MTime, csP)))
134 Cks.fmTime =
static_cast<long long>(MTime);
135 Cks.
csTime =
static_cast<int>(time(0) - MTime);
140 memcpy(&
xCS.Attr.Cks, &Cks,
sizeof(
xCS.Attr.Cks));
141 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 216 of file XrdCksManager.cc.
225 if (!(val =
Cfg.GetToken()) || !val[0])
226 {
eDest->
Emsg(
"Config",
"checksum name not specified");
return 1;}
228 {
eDest->
Emsg(
"Config",
"checksum name too long");
return 1;}
233 val =
Cfg.GetToken(&parms);
234 if (val && val[0]) path = strdup(val);
235 else {
eDest->
Emsg(
"Config",
"library path missing for ckslib digest",name);
241 for (i = 0; i < csMax; i++)
242 if (!(*csTab[i].
Name) || !strcmp(csTab[i].
Name, name))
break;
247 {
eDest->
Emsg(
"Config",
"too many checksums specified");
248 if (path) free(path);
250 }
else if (!(*csTab[i].
Name)) csLast = i;
254 strcpy(csTab[i].
Name, name);
255 if (csTab[i].
Path) free(csTab[i].
Path);
256 csTab[i].Path = path;
257 if (csTab[i].Parms) free(csTab[i].Parms);
258 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 437 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 454 of file XrdCksManager.cc.
462 if (csLast < 0)
return -ENOTSUP;
464 if (!
xCS.Attr.Cks.Set(Cks.
Name))
return -ENOTSUP;
468 if ((rc =
xCS.Get(Pfn)) <= 0)
return (rc && rc != -
ENOATTR ? rc : -ESRCH);
472 nFault = strcmp(
xCS.Attr.Cks.Name, Cks.
Name);
477 if ((rc =
ModTime(Pfn, MTime)))
return rc;
481 return (Cks.fmTime != MTime || nFault
483 ? -ESTALE :
int(Cks.
Length));
static const int ValuSize
virtual int ModTime(const char *Pfn, time_t &MTime)
References 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 269 of file XrdCksManager.cc.
276 {
for (i = 0; i < csLast; i++)
if (!strcmp(csTab[i].
Name, DfltCalc))
break;
278 {
eDest->
Emsg(
"Config", DfltCalc,
"cannot be made the default; "
282 if (i) {csInfo Temp = csTab[i]; csTab[i] = csTab[0]; csTab[0] = Temp;}
288 {
eDest->
Emsg(
"Config",
"No checksums defined; cannot configure!");
294 for (i = 0; i <= csLast; i++)
295 {
if (csTab[i].
Path) {
if (!(
Config(ConfigFN, csTab[i])))
return 0;}
296 else {
if (!strcmp(
"adler32", csTab[i].
Name))
298 else if (!strcmp(
"crc32", csTab[i].
Name))
300 else if (!strcmp(
"crc32c", csTab[i].
Name))
302 else if (!strcmp(
"md5", csTab[i].
Name))
304 else {
eDest->
Emsg(
"Config",
"Invalid native checksum -",
308 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 490 of file XrdCksManager.cc.
492 static const char *vPfx =
"XrdCks.";
493 static const int vPln = strlen(vPfx);
500 if (Blen < 2)
return 0;
505 {
if (csLast < 0)
return 0;
507 while(i <= csLast && Blen > 1)
508 {n = strlen(csTab[i].
Name);
509 if (n >= Blen)
break;
510 if (bP != Buff) *bP++ = Sep;
511 strcpy(bP, csTab[i].
Name); bP += n; *bP = 0;
513 return (bP == Buff ? 0 : Buff);
524 {
if (vP->
Nlen > vPln && !strncmp(vP->
Name, vPfx, vPln))
525 {n = vP->
Nlen - vPln;
526 if (n >= Blen)
break;
527 if (bP != Buff) *bP++ = Sep;
528 strcpy(bP, vP->
Name + vPln); bP += n; *bP = 0;
536 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 557 of file XrdCksManager.cc.
560 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 567 of file XrdCksManager.cc.
569 csInfo *csIP = &csTab[0];
573 if (name && !(csIP = Find(name)))
return 0;
574 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 591 of file XrdCksManager.cc.
594 csInfo *csIP = &csTab[0];
598 if (csLast < 0 || (*Cks.
Name && !(csIP = Find(Cks.
Name))))
return -ENOTSUP;
599 if (Cks.
Length != csIP->Len)
return -EDOM;
600 memcpy(&
xCS.Attr.Cks, &Cks,
sizeof(
xCS.Attr.Cks));
608 xCS.Attr.Cks.fmTime =
static_cast<long long>(MTime);
609 xCS.Attr.Cks.csTime =
static_cast<int>(time(0) - MTime);
References XrdCksData::Length, ModTime(), XrdCksData::Name, and xCS.
Referenced by XrdCksManOss::Set().
◆ 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 581 of file XrdCksManager.cc.
583 csInfo *iP = (
Name != 0 ? Find(
Name) : &csTab[0]);
584 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 621 of file XrdCksManager.cc.
625 csInfo *csIP = &csTab[0];
630 if (csLast < 0 || (*Cks.
Name && !(csIP = Find(Cks.
Name))))
return -ENOTSUP;
631 xCS.Attr.Cks.Set(csIP->Name);
635 if ((rc =
ModTime(Pfn, MTime)))
return rc;
639 if ((rc =
xCS.Get(Pfn)) < 0)
return rc;
643 if (!rc ||
xCS.Attr.Cks.fmTime != MTime
644 || strcmp(
xCS.Attr.Cks.Name, csIP->Name)
645 ||
xCS.Attr.Cks.Length != csIP->Len)
646 {strcpy(
xCS.Attr.Cks.Name, Cks.
Name);
647 if ((rc =
Calc(Pfn,
xCS.Attr.Cks, 1)) < 0)
return rc;
652 return (
xCS.Attr.Cks.Length == Cks.
Length
653 && !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: