XRootD
XrdOucN2No2p Class Reference
+ Inheritance diagram for XrdOucN2No2p:
+ Collaboration diagram for XrdOucN2No2p:

Public Member Functions

 XrdOucN2No2p (XrdSysError *erp, const char *lroot, const char *pfx, int fnmax, char sc)
 
virtual ~XrdOucN2No2p ()
 
virtual int lfn2pfn (const char *lfn, char *buff, int blen)
 
virtual int lfn2rfn (const char *lfn, char *buff, int blen)
 
virtual int pfn2lfn (const char *pfn, char *buff, int blen)
 
- Public Member Functions inherited from XrdOucName2Name
 XrdOucName2Name ()
 Constructor. More...
 
virtual ~XrdOucName2Name ()
 Destructor. More...
 

Detailed Description

Definition at line 68 of file XrdOucN2No2p.cc.

Constructor & Destructor Documentation

◆ XrdOucN2No2p()

XrdOucN2No2p::XrdOucN2No2p ( XrdSysError erp,
const char *  lroot,
const char *  pfx,
int  fnmax,
char  sc 
)
inline

Definition at line 78 of file XrdOucN2No2p.cc.

80  : eDest(erp), sChar(sc),
81  oidPfx(strdup(pfx)), oidPsz(strlen(pfx)), oidMax(fnmax)
82  {if (!lroot) {lRoot = 0; lRLen = 0;}
83  else {lRoot = strdup(lroot);
84  lRLen = strlen(lroot);
85  if (lRoot[lRLen-1] == '/')
86  {lRoot[lRLen-1] = 0; lRLen--;}
87  }
88  }

◆ ~XrdOucN2No2p()

virtual XrdOucN2No2p::~XrdOucN2No2p ( )
inlinevirtual

Definition at line 90 of file XrdOucN2No2p.cc.

90  {if (oidPfx) free(oidPfx);
91  if (lRoot) free(lRoot);
92  }

Member Function Documentation

◆ lfn2pfn()

int XrdOucN2No2p::lfn2pfn ( const char *  lfn,
char *  buff,
int  blen 
)
virtual

Map a logical file name to a physical file name.

Parameters
lfn-> Logical file name.
buff-> Buffer where the physical file name of an existing file is to be placed. It must end with a null byte.
blenThe length of the buffer.
Returns
Success: Zero. Failure: An errno number describing the failure; typically EINVAL - The supplied lfn is invalid. ENAMETOOLONG - The buffer is too small for the pfn.

Implements XrdOucName2Name.

Definition at line 108 of file XrdOucN2No2p.cc.

109 {
110 // If have a local root then prefix result with it (make sure it fits)
111 //
112  if (lRoot)
113  {if (lRLen >= blen-1) return ENAMETOOLONG;
114  strcpy(buff, lRoot);
115  buff += lRLen; blen -= lRLen;
116  }
117 
118 // Now just to the transformation so that we can ref the oid as a file
119 //
120  return pfn2lfn(lfn, buff, blen);
121 }
virtual int pfn2lfn(const char *pfn, char *buff, int blen)

References pfn2lfn().

+ Here is the call graph for this function:

◆ lfn2rfn()

virtual int XrdOucN2No2p::lfn2rfn ( const char *  lfn,
char *  buff,
int  blen 
)
inlinevirtual

Map a logical file name to the name the file would have in a remote storage system (e.g. Mass Storage System at a remote location).

Parameters
lfn-> Logical file name.
buff-> Buffer where the remote file name is to be placed. It need not actually exist in that location but could be created there with that name. It must end with a null byte.
blenThe length of the buffer.
Returns
Success: Zero. Failure: An errno number describing the failure; typically EINVAL - The supplied lfn is invalid. ENAMETOOLONG - The buffer is too small for the pfn.

Implements XrdOucName2Name.

Definition at line 74 of file XrdOucN2No2p.cc.

74 {return -ENOTSUP;}

◆ pfn2lfn()

int XrdOucN2No2p::pfn2lfn ( const char *  pfn,
char *  buff,
int  blen 
)
virtual

Map a physical file name to it's logical file name.

Parameters
pfn-> Physical file name. This is always a valid name of either an existing file or a file that could been created.
buff-> Buffer where the logical file name is to be placed. It need not actually exist but could be created with that name. It must end with a null byte.
blenThe length of the buffer.
Returns
Success: Zero. Failure: An errno number describing the failure; typically EINVAL - The supplied lfn is invalid. ENAMETOOLONG - The buffer is too small for the pfn.

Implements XrdOucName2Name.

Definition at line 127 of file XrdOucN2No2p.cc.

128 {
129  const char *sP;
130  char *bP;
131  std::string pstr;
132  int pfnLen = strlen(pfn);
133 
134 // If the pfn starts with a slash then do nothing
135 //
136  if (*pfn == '/')
137  {if (pfnLen >= blen) return ENAMETOOLONG;
138  strcpy(buff, pfn);
139  return 0;
140  }
141 
142 // If there are any slashes in the object id we need to remove them
143 //
144  if ((sP = index(pfn, '/')))
145  {pstr = pfn;
146  std::replace(pstr.begin(), pstr.end(), '/', sChar);
147  pfn = pstr.c_str();
148  }
149 
150 // Create the object distribution subpath. The format is based on the
151 // actual length of the object id and what we can use in this file system.
152 // We make special allowances for short object ID's that can screw this up.
153 //
154  if (pfnLen <= oidMax)
155  {unsigned long hVal = XrdOucHashVal2(pfn, pfnLen);
156  unsigned long sVal = ((int)sizeof(unsigned long) > 4 ? 32 : 16);
157  char subP[8];
158  if (pfnLen <= (int)sizeof(unsigned long)) hVal = hVal ^ (hVal >> sVal);
159  subP[1] = h2c[(hVal & 0x0f)]; hVal >>= 4; subP[0] = h2c[(hVal & 0x0f)];
160  subP[2] = '/'; hVal >>= 4;
161  subP[4] = h2c[(hVal & 0x0f)]; hVal >>= 4; subP[3] = h2c[(hVal & 0x0f)];
162  subP[5] = '/'; subP[6] = 0;
163  int n = snprintf(buff, blen, "%s%s%s", oidPfx, subP, pfn);
164  return (n < blen ? 0 : ENAMETOOLONG);
165  }
166 
167 // The object id is longer than what is allowed for a file name. So, we
168 // convert the name to a number of directories using object id fragments.
169 // Check if we even have a chance here (note we may be one byte too many).
170 //
171  if ((oidPsz + pfnLen + (pfnLen/oidMax)) >= blen) return ENAMETOOLONG;
172 
173 // Prepare to segement the oid
174 //
175  strcpy(buff, oidPfx); bP = buff + oidPsz; blen -= oidPsz;
176 
177 // Copy over segments separated by a slash
178 //
179  while(blen > oidMax && pfnLen > oidMax)
180  {strncpy(bP, pfn, oidMax);
181  bP += oidMax; blen -= oidMax;
182  pfn += oidMax; pfnLen -= oidMax;
183  if (blen > 0) {*bP++ = '/'; blen--;}
184  }
185 
186 // Copy the final segment if we have room
187 //
188  if (blen <= pfnLen) return ENAMETOOLONG;
189  strcpy(bP, pfn);
190  return 0;
191 }
unsigned long XrdOucHashVal2(const char *KeyVal, int KeyLen)

References XrdOucHashVal2().

Referenced by lfn2pfn().

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

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