XRootD
XrdOssPath Class Reference

#include <XrdOssPath.hh>

+ Collaboration diagram for XrdOssPath:

Classes

struct  fnInfo
 

Public Types

enum  theSfx {
  isBase =0 ,
  isAnew =1 ,
  sfxMigF =1 ,
  isFail =2 ,
  isLock =3 ,
  isPin =4 ,
  sfxMigL =4 ,
  sfxMemF =4 ,
  isMkeep =5 ,
  isMlock =6 ,
  isMmap =7 ,
  sfxMemL =7 ,
  isPfn =8 ,
  sfxLast =8 ,
  sfxNum =9
}
 

Public Member Functions

 XrdOssPath ()
 
 ~XrdOssPath ()
 

Static Public Member Functions

static int Convert (char *dst, int dln, const char *oldP, const char *newP)
 
static const char * Extract (char *path, char *lbuf, int &lbsz)
 
static char * genPath (const char *inPath, const char *cgrp, char *sfx)
 
static char * genPFN (char *dst, int dln, const char *src)
 
static char * genPFN (fnInfo &Info, char *buff, int blen, const char *Path=0)
 
static int getCname (const char *path, char *Cache, char *lbuf=0, int lbsz=0)
 
static int InitPrefix ()
 
static int isXA (const char *path)
 
static theSfx pathType (const char *Path, int chkWhat=chkAll)
 
static void Trim2Base (char *eP)
 

Static Public Attributes

static const int chkAll = 0x07
 
static const int chkMem = 0x01
 
static const int chkMig = 0x02
 
static const int chkPfn = 0x04
 
static const char * Sfx [sfxNum]
 
static const int sfxLen = 4
 
static const char xChar = '%'
 

Detailed Description

Definition at line 35 of file XrdOssPath.hh.


Class Documentation

◆ XrdOssPath::fnInfo

struct XrdOssPath::fnInfo

Definition at line 39 of file XrdOssPath.hh.

+ Collaboration diagram for XrdOssPath::fnInfo:
Class Members
const char * Path
int Plen
const char * Sfx
char * Slash

Member Enumeration Documentation

◆ theSfx

Enumerator
isBase 
isAnew 
sfxMigF 
isFail 
isLock 
isPin 
sfxMigL 
sfxMemF 
isMkeep 
isMlock 
isMmap 
sfxMemL 
isPfn 
sfxLast 
sfxNum 

Definition at line 68 of file XrdOssPath.hh.

68  {isBase =0, isAnew =1,
69  sfxMigF=1, isFail=2, isLock =3, isPin =4, sfxMigL=4,
70  sfxMemF=4, isMkeep=5, isMlock=6, isMmap=7, sfxMemL=7,
71  isPfn=8, sfxLast=8, sfxNum =9
72  };

Constructor & Destructor Documentation

◆ XrdOssPath()

XrdOssPath::XrdOssPath ( )
inline

Definition at line 86 of file XrdOssPath.hh.

86 {}

◆ ~XrdOssPath()

XrdOssPath::~XrdOssPath ( )
inline

Definition at line 87 of file XrdOssPath.hh.

87 {}

Member Function Documentation

◆ Convert()

int XrdOssPath::Convert ( char *  dst,
int  dln,
const char *  oldP,
const char *  newP 
)
static

Definition at line 75 of file XrdOssPath.cc.

76 {
77  int i;
78 
79 // Copy all the char up to the first % into the new link buffer
80 //
81  for (i = 0; oldP[i] && oldP[i] != xChar; i++) *dst++ = oldP[i];
82 
83 // Now make sure the resulting name will fit
84 //
85  if ((i + static_cast<int>(strlen(newP))) >= dln) return -ENAMETOOLONG;
86 
87 // Complete the name
88 //
89  XrdOssTAMP(dst, newP);
90  return 0;
91 }
#define XrdOssTAMP(dst, src)
Definition: XrdOssPath.cc:50
static const char xChar
Definition: XrdOssPath.hh:47

References xChar, and XrdOssTAMP.

Referenced by XrdOssSys::RenameLink().

+ Here is the caller graph for this function:

◆ Extract()

const char * XrdOssPath::Extract ( char *  path,
char *  lbuf,
int &  lbsz 
)
static

Definition at line 97 of file XrdOssPath.cc.

98 {
99  struct stat Stat;
100  char *pP;
101  int j, lnklen = 0;
102 
103 // If path is 0, the caller already has read the link; else read it.
104 //
105  if (!path) lnklen = lbsz;
106  else if (!lstat(path, &Stat) && S_ISLNK(Stat.st_mode))
107  {if ((lnklen = readlink(path, lbuf, lbsz-1)) < 0) *lbuf = 0;
108  else *(lbuf+lnklen) = 0;
109  }
110  else {lnklen = strlen(path);
111  if (lnklen >= lbsz) lnklen = lbsz-1;
112  strncpy(lbuf, path, lnklen); *(lbuf+lnklen) = '\0';
113  }
114 
115 // Extract out the cache group name from "<path>/cgroup/nn/fn" if possible
116 //
117  if (lnklen >= 4 && lbuf[lnklen-1] == xChar && (pP=posCname(lbuf,lnklen,j)))
118  {*(pP+j) = '\0';
119  if (pP != lbuf) *(pP-1) = '\0';
120  return pP;
121  }
122 
123 // This is not a normal cache, so do something reasonable
124 //
125  if ((pP = index(lbuf, xChar))) *pP = '\0';
126  else *(lbuf+1) = '\0';
127  return "public";
128 }
struct stat Stat
Definition: XrdCks.cc:49
int stat(const char *path, struct stat *buf)
int lstat(const char *path, struct stat *buf)

References lstat(), Stat, stat(), and xChar.

+ Here is the call graph for this function:

◆ genPath()

char * XrdOssPath::genPath ( const char *  inPath,
const char *  cgrp,
char *  sfx 
)
static

Definition at line 134 of file XrdOssPath.cc.

135 {
136  char *dirP, cgbuff[XrdOssSpace::minSNbsz], pbuff[MAXPATHLEN+64], *pP = pbuff;
137  int n;
138 
139 // Check if the group name is already in the path
140 //
141  strcpy(pbuff, inPath); strcpy(cgbuff, cgrp); strcat(cgbuff, "/");
142  do {if ((dirP = index(pP, '/')) && !strcmp(dirP+1, cgbuff)) break;
143  pP = dirP+1;
144  } while(dirP);
145 
146 // If the group name is not in the path, add the group name to it.
147 //
148  if (!dirP)
149  {dirP = pbuff + strlen(inPath) - 1;
150  strcpy(dirP+1, cgbuff);
151  }
152 
153 // Construct a suffix that will allow us to quickly find the group name
154 // We rely on the fact that group names are typically less than 16 characters
155 // and cache group paths are less than 240 characters
156 //
157  if ((n = strlen(cgrp)) > 15) sfx[2] = 'f';
158  else sfx[2] = h2c[n];
159  n = (dirP - pbuff + 1) & 0xff;
160  sfx[1] = h2c[(n & 0x0f)]; n = n >> 4; sfx[0] = h2c[(n & 0x0f)];
161  sfx[3] = xChar;
162 
163 // Return the path
164 //
165  return strdup(pbuff);
166 }
static const int minSNbsz
Definition: XrdOssSpace.hh:45

References XrdOssSpace::minSNbsz, and xChar.

Referenced by XrdOssCache_FS::XrdOssCache_FS().

+ Here is the caller graph for this function:

◆ genPFN() [1/2]

char * XrdOssPath::genPFN ( char *  dst,
int  dln,
const char *  src 
)
static

Definition at line 225 of file XrdOssPath.cc.

226 {
227  char *pP;
228 
229  if (!(pP = (char *) index(src, xChar))|| dln <= (int)strlen(pP)) return 0;
230 
231  while(*pP) {*dst++ = (*pP == xChar ? '/' : *pP); pP++;}
232 
233  *dst = '\0';
234  return dst;
235 }

References xChar.

◆ genPFN() [2/2]

char * XrdOssPath::genPFN ( fnInfo Info,
char *  buff,
int  blen,
const char *  Path = 0 
)
static

Definition at line 172 of file XrdOssPath.cc.

173 {
174  static XrdSysMutex myMutex;
175  static int mySeq = 0;
176  union {int bin;
177  char chr[4];} Seq;
178  char *bP = buff;
179 
180 // Construct old style path if we have a path present (i.e., non-xa path)
181 //
182  if (Path)
183  {const char *pap = Path;
184  if ((Info.Plen + static_cast<int>(strlen(Path))) >= blen)
185  {*buff = '\0'; return 0;}
186  memcpy(bP, Info.Path, Info.Plen);
187  bP += Info.Plen;
188  XrdOssTAMP(bP, pap);
189  Info.Slash = buff;
190  return 0;
191  }
192 
193  if (! *pfnPfx) {
194  *bP = '\0';
195  return bP;
196  }
197 
198 // Increment the sequence number
199 //
200  myMutex.Lock();
201  Seq.bin = mySeq++;
202  myMutex.UnLock();
203 
204 // Construct the path (buffer will be big enough)
205 //
206  memcpy(bP, Info.Path, Info.Plen);
207  bP += Info.Plen;
208  *bP++ = h2c[((Seq.bin>>4) & 0x0f)];
209  *bP++ = h2c[( Seq.bin & 0x0f)];
210  Info.Slash= bP;
211  *bP++ = '/';
212  strcpy(bP, pfnPfx);
213  bP = bin2hex(Seq.chr, sizeof(Seq.chr), bP+strlen(pfnPfx));
214  memcpy(bP, Info.Sfx, sfxLen);
215  bP += sfxLen;
216  *bP = '\0';
217 
218 // All done
219 //
220  return bP;
221 }
@ Info
XrdOucString Path
static const int sfxLen
Definition: XrdOssPath.hh:49

References Info, XrdSysMutex::Lock(), Path, sfxLen, XrdSysMutex::UnLock(), and XrdOssTAMP.

Referenced by XrdOssCache::Alloc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCname()

int XrdOssPath::getCname ( const char *  path,
char *  Cache,
char *  lbuf = 0,
int  lbsz = 0 
)
static

Definition at line 241 of file XrdOssPath.cc.

243 {
244  struct stat lbuff;
245  char *xP, lnkbuff[MAXPATHLEN+64];
246  int j, lnklen = 0;
247 
248 // Set up local buffer or remote buffer
249 //
250  if (!lbuf) {lbuf = lnkbuff; lbsz = MAXPATHLEN;}
251 
252 // If path is 0, the caller already has read the link; else read it.
253 //
254  if (!path) lnklen = lbsz;
255  else if (!lstat(path, &lbuff) && S_ISLNK(lbuff.st_mode))
256  lnklen = readlink(path, lbuf, lbsz);
257 
258 // Check if the symlink references a new cache. If not then the cache group is
259 // always deemed to be public.
260 //
261  if (lnklen < 4 || lbuf[lnklen-1] != xChar)
262  {strcpy(Cache, "public"); return (lnklen < 0 ? 0 : lnklen);}
263 
264 // Extract out the cache group name from "<path>/cgroup/nn/fn"
265 //
266  if (!(xP = posCname(lbuf, lnklen, j))) strcpy(Cache, "public");
267  else {strncpy(Cache, xP, j); *(Cache+j)='\0';}
268 
269 // All done
270 //
271  return lnklen;
272 }
XrdCmsCache Cache
Definition: XrdPfcFile.hh:204

References XrdCms::Cache, lstat(), stat(), and xChar.

Referenced by XrdOssSys::getCname(), and XrdOssSys::Reloc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InitPrefix()

int XrdOssPath::InitPrefix ( )
static

Definition at line 340 of file XrdOssPath.cc.

341 {
342  union {int binT;
343  char chrT[4];} xT;
344 
345  size_t plen = sizeof(pfnPfx) - 4*sizeof(xT.binT) - 1;
346 
347  if (plen < 1) return 1;
348 
349  char *bp = pfnPfx;
350 
351  time_t theTime = time(0);
352  xT.binT = static_cast<int>(theTime);
353  bp = bin2hex(xT.chrT, sizeof(xT.binT), bp);
354 
355  pid_t pid = getpid();
356  xT.binT = static_cast<int> (pid);
357  bp = bin2hex(xT.chrT, sizeof(xT.binT), bp);
358 
359  XrdNetAddr theAddr(0);
360  int rc = XrdNetUtils::Encode(theAddr.NetAddr(), bp, plen);
361 
362  if ( rc < 0 ) {
363  pfnPfx[0] = '\0';
364  return 1;
365  }
366 
367  return 0;
368 }
static int Encode(const XrdNetSockAddr *sadr, char *buff, int blen, int port=-1)
Definition: XrdNetUtils.cc:120

References XrdNetUtils::Encode(), and XrdNetAddrInfo::NetAddr().

Referenced by XrdOssSys::Configure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isXA()

static int XrdOssPath::isXA ( const char *  path)
inlinestatic

Definition at line 64 of file XrdOssPath.hh.

64 {return path[strlen(path)-1] == xChar;}

References xChar.

◆ pathType()

XrdOssPath::theSfx XrdOssPath::pathType ( const char *  Path,
int  chkWhat = chkAll 
)
static

Definition at line 278 of file XrdOssPath.cc.

279 {
280  static const int chkMM = chkMem | chkMig;
281 
282  char *Dot;
283  int i, iBeg, iEnd;
284 
285 // Compute ending test
286 //
287  if ( chkWhat & chkAll) {iBeg = 0; iEnd = int(sfxLast);}
288  else if ((chkWhat & chkMM ) == chkMM) {iBeg = 1; iEnd = int(sfxMemL);}
289  else if ( chkWhat & chkMig) {iBeg = 1; iEnd = int(sfxMigL);}
290  else if ( chkWhat & chkMem) {iBeg = int(sfxMemF);iEnd = int(sfxMigL);}
291  else {iBeg = 0; iEnd = 0;}
292 
293 // Convert path to suffix number
294 //
295  if ((Dot = (char *) rindex(Path, '.')))
296  for (i = iBeg; i < iEnd; i++) if (!strcmp(Dot,Sfx[i])) return theSfx(i+1);
297  return isBase;
298 }
static const int chkAll
Definition: XrdOssPath.hh:80
static const int chkMem
Definition: XrdOssPath.hh:77
static const char * Sfx[sfxNum]
Definition: XrdOssPath.hh:75
static const int chkMig
Definition: XrdOssPath.hh:78

References chkAll, chkMem, chkMig, isBase, Path, Sfx, sfxLast, sfxMemF, sfxMemL, and sfxMigL.

◆ Trim2Base()

void XrdOssPath::Trim2Base ( char *  eP)
static

Definition at line 304 of file XrdOssPath.cc.

305 {
306  int oneMore = (*eP == xChar);
307 
308 // Trim to the cache group name in "<path>/cgroup/nn/fn" or "<path>/fn"
309 //
310  do {eP--;} while(*eP != '/');
311  if (oneMore) do {eP--;} while(*eP != '/');
312  *(eP+1) = '\0';
313 }

References xChar.

Referenced by XrdOssCache::Adjust(), XrdOssSys::BreakLink(), XrdOssCache::Find(), XrdOssSys::RenameLink(), and XrdOssAt::Unlink().

+ Here is the caller graph for this function:

Member Data Documentation

◆ chkAll

const int XrdOssPath::chkAll = 0x07
static

Definition at line 80 of file XrdOssPath.hh.

Referenced by pathType().

◆ chkMem

const int XrdOssPath::chkMem = 0x01
static

Definition at line 77 of file XrdOssPath.hh.

Referenced by pathType().

◆ chkMig

const int XrdOssPath::chkMig = 0x02
static

Definition at line 78 of file XrdOssPath.hh.

Referenced by pathType().

◆ chkPfn

const int XrdOssPath::chkPfn = 0x04
static

Definition at line 79 of file XrdOssPath.hh.

◆ Sfx

const char * XrdOssPath::Sfx
static
Initial value:
=
{".anew", ".fail", ".lock", ".pin",
".mmap", ".mkeep", ".mlock",".pfn", 0}

Definition at line 75 of file XrdOssPath.hh.

Referenced by pathType().

◆ sfxLen

const int XrdOssPath::sfxLen = 4
static

Definition at line 49 of file XrdOssPath.hh.

Referenced by genPFN().

◆ xChar

const char XrdOssPath::xChar = '%'
static

The documentation for this class was generated from the following files: