XrdPosix.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                           X r d P o s i x . c c                            */
00004 /*                                                                            */
00005 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //           $Id: XrdPosix.cc 35287 2010-09-14 21:19:35Z ganis $
00012 
00013 const char *XrdPosixCVSID = "$Id: XrdPosix.cc 35287 2010-09-14 21:19:35Z ganis $";
00014 
00015 #include <stdarg.h>
00016 #include <stdio.h>
00017 #include <stdlib.h>
00018 #include <strings.h>
00019 #include <sys/param.h>
00020 #include <sys/types.h>
00021 #include <sys/stat.h>
00022 #include <fcntl.h>
00023 #include <unistd.h>
00024 #include <sys/uio.h>
00025 
00026 #include "XrdSys/XrdSysHeaders.hh"
00027 #include "XrdPosix/XrdPosixLinkage.hh"
00028 #include "XrdPosix/XrdPosixXrootd.hh"
00029 #include "XrdOuc/XrdOucTokenizer.hh"
00030 
00031 /******************************************************************************/
00032 /*                         L o c a l   C l a s s e s                          */
00033 /******************************************************************************/
00034   
00035 class XrdPosixXrootPath
00036 {
00037 public:
00038 
00039 void  CWD(const char *path);
00040 
00041 char *URL(const char *path, char *buff, int blen);
00042 
00043       XrdPosixXrootPath();
00044      ~XrdPosixXrootPath();
00045 
00046 private:
00047 
00048 struct xpath 
00049        {struct xpath *next;
00050         const  char  *server;
00051                int    servln;
00052         const  char  *path;
00053                int    plen;
00054         const  char  *nath;
00055                int    nlen;
00056 
00057         xpath(struct xpath *cur,
00058               const   char *pServ,
00059               const   char *pPath,
00060               const   char *pNath) : next(cur),
00061                                      server(pServ),
00062                                      servln(strlen(pServ)),
00063                                      path(pPath),
00064                                      plen(strlen(pPath)),
00065                                      nath(pNath),
00066                                      nlen(pNath ? strlen(pNath) : 0) {}
00067        ~xpath() {}
00068        };
00069 
00070 struct xpath *xplist;
00071 char         *pBase;
00072 char         *cwdPath;
00073 int           cwdPlen;
00074 };
00075 
00076 /******************************************************************************/
00077 /*         X r d P o s i x X r o o t P a t h   C o n s t r u c t o r          */
00078 /******************************************************************************/
00079 
00080 XrdPosixXrootPath::XrdPosixXrootPath()
00081     : xplist(0),
00082       pBase(0)
00083 {
00084    XrdOucTokenizer thePaths(0);
00085    char *plist = 0, *colon = 0, *subs = 0, *lp = 0, *tp = 0;
00086    int aOK = 0;
00087 
00088    cwdPath = 0; cwdPlen = 0;
00089 
00090    if (!(plist = getenv("XROOTD_VMP")) || !*plist) return;
00091    pBase = strdup(plist);
00092 
00093    thePaths.Attach(pBase);
00094 
00095    if ((lp = thePaths.GetLine())) while((tp = thePaths.GetToken()))
00096       {aOK = 1;
00097        if ((colon = rindex(tp, (int)':')) && *(colon+1) == '/')
00098           {if (!(subs = index(colon, (int)'='))) subs = 0;
00099               else if (*(subs+1) == '/') {*subs = '\0'; subs++;}
00100                       else if (*(subs+1)) aOK = 0;
00101                               else {*subs = '\0'; subs = (char*)"";}
00102           } else aOK = 0;
00103 
00104        if (aOK)
00105           {*colon++ = '\0';
00106            while(*(colon+1) == '/') colon++;
00107            xplist = new xpath(xplist, tp, colon, subs);
00108           } else cerr <<"XrdPosix: Invalid XROOTD_VMP token '" <<tp <<'"' <<endl;
00109       }
00110 }
00111 
00112 /******************************************************************************/
00113 /*          X r d P o s i x X r o o t P a t h   D e s t r u c t o r           */
00114 /******************************************************************************/
00115   
00116 XrdPosixXrootPath::~XrdPosixXrootPath()
00117 {
00118    struct xpath *xpnow;
00119 
00120    while((xpnow = xplist))
00121         {xplist = xplist->next; delete xpnow;}
00122 }
00123   
00124 /******************************************************************************/
00125 /*                     X r d P o s i x P a t h : : C W D                      */
00126 /******************************************************************************/
00127   
00128 void XrdPosixXrootPath::CWD(const char *path)
00129 {
00130    if (cwdPath) free(cwdPath);
00131    cwdPlen = strlen(path);
00132    if (*(path+cwdPlen-1) == '/') cwdPath = strdup(path);
00133       else if (cwdPlen <= MAXPATHLEN)
00134            {char buff[MAXPATHLEN+8];
00135             strcpy(buff, path); 
00136             *(buff+cwdPlen  ) = '/';
00137             *(buff+cwdPlen+1) = '\0';
00138             cwdPath = strdup(buff); cwdPlen++;
00139            }
00140 }
00141 
00142 /******************************************************************************/
00143 /*                     X r d P o s i x P a t h : : U R L                      */
00144 /******************************************************************************/
00145   
00146 char *XrdPosixXrootPath::URL(const char *path, char *buff, int blen)
00147 {
00148    const char   *rproto = "root://";
00149    const int     rprlen = strlen(rproto);
00150    const char   *xproto = "xroot://";
00151    const int     xprlen = strlen(xproto);
00152    struct xpath *xpnow = xplist;
00153    char tmpbuff[2048];
00154    int plen, pathlen = 0;
00155 
00156 // If this starts with 'root", then this is our path
00157 //
00158    if (!strncmp(rproto, path, rprlen)) return (char *)path;
00159 
00160 // If it starts with xroot, then convert it to be root
00161 //
00162    if (!strncmp(xproto, path, xprlen))
00163       {if (!buff) return (char *)1;
00164        if ((int(strlen(path))) > blen) return 0;
00165        strcpy(buff, path+1);
00166        return buff;
00167       }
00168 
00169 // If a relative path was specified, convert it to an abso9lute path
00170 //
00171    if (path[0] == '.' && path[1] == '/' && cwdPath)
00172       {pathlen = (strlen(path) + cwdPlen - 2);
00173        if (pathlen < (int)sizeof(tmpbuff))
00174           {strcpy(tmpbuff, cwdPath);
00175            strcpy(tmpbuff+cwdPlen, path+2);
00176            path = (const char *)tmpbuff;
00177           }  else return 0;
00178       }
00179 
00180 // Check if this path starts with one or our known paths
00181 //
00182    while(*(path+1) == '/') path++;
00183    while(xpnow)
00184         if (!strncmp(path, xpnow->path, xpnow->plen)) break;
00185            else xpnow = xpnow->next;
00186 
00187 // If we did not match a path, this is not our path.
00188 //
00189    if (!xpnow) return 0;
00190    if (!buff) return (char *)1;
00191 
00192 // Verify that we won't overflow the buffer
00193 //
00194    if (!pathlen) pathlen = strlen(path);
00195    plen = xprlen + pathlen + xpnow->servln + 2;
00196    if (xpnow->nath) plen =  plen - xpnow->plen + xpnow->nlen;
00197    if (plen >= blen) return 0;
00198 
00199 // Build the url
00200 //
00201    strcpy(buff, rproto);
00202    strcat(buff, xpnow->server);
00203    strcat(buff, "/");
00204    if (xpnow->nath) {strcat(buff, xpnow->nath); path += xpnow->plen;}
00205    if (*path != '/') strcat(buff, "/");
00206    strcat(buff, path);
00207    return buff;
00208 }
00209 
00210 /******************************************************************************/
00211 /*                        G l o b a l   O b j e c t s                         */
00212 /******************************************************************************/
00213   
00214        XrdPosixXrootd    Xroot;
00215 
00216        XrdPosixXrootPath XrootPath;
00217   
00218 extern XrdPosixLinkage   Xunix;
00219 
00220 /******************************************************************************/
00221 /*                       X r d P o s i x _ A c c e s s                        */
00222 /******************************************************************************/
00223   
00224 extern "C"
00225 {
00226 int XrdPosix_Access(const char *path, int amode)
00227 {
00228    char *myPath, buff[2048];
00229 
00230 // Make sure a path was passed
00231 //
00232    if (!path) {errno = EFAULT; return -1;}
00233 
00234 // Return the results of a mkdir of a Unix file system
00235 //
00236    if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
00237       return Xunix.Access(  path, amode);
00238 
00239 // Return the results of our version of access()
00240 //
00241    return Xroot.Access(myPath, amode);
00242 }
00243 }
00244 
00245 /******************************************************************************/
00246 /*                          X r d P o s i x _ A c l                           */
00247 /******************************************************************************/
00248 
00249 // This is a required addition for Solaris 10+ systems
00250 
00251 extern "C"
00252 {
00253 int XrdPosix_Acl(const char *path, int cmd, int nentries, void *aclbufp)
00254 {
00255    return (XrootPath.URL(path, 0, 0)
00256         ? Xunix.Acl("/tmp", cmd,nentries,aclbufp)
00257         : Xunix.Acl(path,   cmd,nentries,aclbufp));
00258 }
00259 }
00260   
00261 /******************************************************************************/
00262 /*                        X r d P o s i x _ C h d i r                         */
00263 /******************************************************************************/
00264 
00265 extern "C"
00266 {
00267 int XrdPosix_Chdir(const char *path)
00268 {
00269    int rc;
00270 
00271 // Set the working directory if the actual chdir succeeded
00272 //
00273    if (!(rc = Xunix.Chdir(path))) XrootPath.CWD(path);
00274    return rc;
00275 }
00276 }
00277   
00278 /******************************************************************************/
00279 /*                        X r d P o s i x _ C l o s e                         */
00280 /******************************************************************************/
00281 
00282 extern "C"
00283 {
00284 int XrdPosix_Close(int fildes)
00285 {
00286 
00287 // Return result of the close
00288 //
00289    return (Xroot.myFD(fildes) ? Xroot.Close(fildes) : Xunix.Close(fildes));
00290 }
00291 }
00292 
00293 /******************************************************************************/
00294 /*                     X r d P o s i x _ C l o s e d i r                      */
00295 /******************************************************************************/
00296 
00297 extern "C"
00298 {
00299 int XrdPosix_Closedir(DIR *dirp)
00300 {
00301 
00302    return (Xroot.isXrootdDir(dirp) ? Xroot.Closedir(dirp)
00303                                    : Xunix.Closedir(dirp));
00304 }
00305 }
00306 
00307 /******************************************************************************/
00308 /*                        X r d P o s i x _ C r e a t                         */
00309 /******************************************************************************/
00310   
00311 extern "C"
00312 {
00313 int     XrdPosix_Creat(const char *path, mode_t mode)
00314 {
00315    extern int XrdPosix_Open(const char *path, int oflag, ...);
00316 
00317    return XrdPosix_Open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
00318 }
00319 }
00320   
00321 /******************************************************************************/
00322 /*                       X r d P o s i x _ F c l o s e                        */
00323 /******************************************************************************/
00324 
00325 extern "C"
00326 {
00327 int XrdPosix_Fclose(FILE *stream)
00328 {
00329    int nullfd = fileno(stream);
00330 
00331 // Close the associated file
00332 //
00333    if (Xroot.myFD(nullfd)) Xroot.Close(nullfd, 1);
00334 
00335 // Now close the stream
00336 //
00337    return Xunix.Fclose(stream);
00338 }
00339 }
00340 
00341 /******************************************************************************/
00342 /*                        X r d P o s i x _ F c n t l                         */
00343 /******************************************************************************/
00344   
00345 extern "C"
00346 {
00347 int XrdPosix_Fcntl(int fd, int cmd, ...)
00348 {
00349    va_list ap;
00350    void *theArg;
00351 
00352    if (Xroot.myFD(fd)) return 0;
00353    va_start(ap, cmd);
00354    theArg = va_arg(ap, void *);
00355    va_end(ap);
00356    return Xunix.Fcntl64(fd, cmd, theArg);
00357 }
00358 }
00359 
00360 /******************************************************************************/
00361 /*                    X r d P o s i x _ F d a t a s y n c                     */
00362 /******************************************************************************/
00363   
00364 extern "C"
00365 {
00366 int XrdPosix_Fdatasync(int fildes)
00367 {
00368 
00369 // Return the result of the sync
00370 //
00371    return (Xroot.myFD(fildes) ? Xroot.Fsync(fildes)
00372                               : Xunix.Fsync(fildes));
00373 }
00374 }
00375 
00376 /******************************************************************************/
00377 /*                    X r d P o s i x _ F g e t x a t t r                     */
00378 /******************************************************************************/
00379   
00380 #ifdef __linux__
00381 extern "C"
00382 {
00383 long long XrdPosix_Fgetxattr (int fd, const char *name, void *value, 
00384                               unsigned long long size)
00385 {
00386    if (Xroot.myFD(fd)) {errno = ENOTSUP; return -1;}
00387    return Xunix.Fgetxattr(fd, name, value, size);
00388 }
00389 }
00390 #endif
00391 
00392 /******************************************************************************/
00393 /*                       X r d P o s i x _ F f l u s h                        */
00394 /******************************************************************************/
00395   
00396 extern "C"
00397 {
00398 int XrdPosix_Fflush(FILE *stream)
00399 {
00400 
00401 // Return the result of the fseek
00402 //
00403    if (!stream || !Xroot.myFD(fileno(stream)))
00404       return Xunix.Fflush(stream);
00405 
00406    return Xroot.Fsync(fileno(stream));
00407 }
00408 }
00409   
00410 /******************************************************************************/
00411 /*                        X r d P o s i x _ F o p e n                         */
00412 /******************************************************************************/
00413 
00414 #define ISMODE(x) !strcmp(mode, x)
00415   
00416 extern "C"
00417 {
00418 FILE *XrdPosix_Fopen(const char *path, const char *mode)
00419 {
00420    char *myPath, buff[2048];
00421    int erc, fd, omode;
00422    FILE *stream;
00423 
00424 // Transfer to unix if this is not our path
00425 //
00426    if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
00427       return Xunix.Fopen64(path, mode);
00428 
00429 // Translate the mode flags
00430 //
00431         if (ISMODE("r")  || ISMODE("rb"))                   omode = O_RDONLY;
00432    else if (ISMODE("w")  || ISMODE("wb"))                   omode = O_WRONLY
00433                                                         | O_CREAT | O_TRUNC;
00434    else if (ISMODE("a")  || ISMODE("ab"))                   omode = O_APPEND;
00435    else if (ISMODE("r+") || ISMODE("rb+") || ISMODE("r+b")) omode = O_RDWR;
00436    else if (ISMODE("w+") || ISMODE("wb+") || ISMODE("w+b")) omode = O_RDWR
00437                                                         | O_CREAT | O_TRUNC;
00438    else if (ISMODE("a+") || ISMODE("ab+") || ISMODE("a+b")) omode = O_APPEND;
00439    else {errno = EINVAL; return 0;}
00440 
00441 // Now open the file
00442 //
00443    if ((fd = Xroot.Open(myPath, omode | XrdPosixXrootd::isStream , 0)) < 0)
00444       return 0;
00445 
00446 // First obtain a free stream
00447 //
00448    if (!(stream = fdopen(fd, mode))) 
00449       {erc = errno; Xroot.Close(fd); errno = erc;}
00450 
00451 // All done
00452 //
00453    return stream;
00454 }
00455 }
00456 
00457 /******************************************************************************/
00458 /*                        X r d P o s i x _ F r e a d                         */
00459 /******************************************************************************/
00460   
00461 extern "C"
00462 {
00463 size_t XrdPosix_Fread(void *ptr, size_t size, size_t nitems, FILE *stream)
00464 {
00465    ssize_t bytes;
00466    size_t rc = 0;
00467    int fd = fileno(stream);
00468 
00469    if (!Xroot.myFD(fd)) return Xunix.Fread(ptr, size, nitems, stream);
00470 
00471    bytes = Xroot.Read(fd, ptr, size*nitems);
00472 
00473 // Get the right return code. Note that we cannot emulate the flags in sunx86
00474 //
00475         if (bytes > 0 && size) rc = bytes/size;
00476 #ifndef SUNX86
00477 #if defined(__linux__)
00478    else if (bytes < 0) stream->_flags |= _IO_ERR_SEEN;
00479    else                stream->_flags |= _IO_EOF_SEEN;
00480 #elif defined(__macos__)
00481    else if (bytes < 0) stream->_flags |= __SEOF;
00482    else                stream->_flags |= __SERR;
00483 #else
00484    else if (bytes < 0) stream->_flag  |= _IOERR;
00485    else                stream->_flag  |= _IOEOF;
00486 #endif
00487 #endif
00488 
00489    return rc;
00490 }
00491 }
00492   
00493 /******************************************************************************/
00494 /*                        X r d P o s i x _ F s e e k                         */
00495 /******************************************************************************/
00496   
00497 extern "C"
00498 {
00499 int XrdPosix_Fseek(FILE *stream, long offset, int whence)
00500 {
00501 
00502 // Return the result of the fseek
00503 //
00504    if (!Xroot.myFD(fileno(stream)))
00505       return Xunix.Fseek( stream, offset, whence);
00506 
00507    return (Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
00508 }
00509 }
00510 
00511 /******************************************************************************/
00512 /*                       X r d P o s i x _ F s e e k o                        */
00513 /******************************************************************************/
00514   
00515 extern "C"
00516 {
00517 int XrdPosix_Fseeko(FILE *stream, long long offset, int whence)
00518 {
00519 
00520 // Return the result of the fseek
00521 //
00522    if (!Xroot.myFD(fileno(stream)))
00523       return Xunix.Fseeko64(stream, offset, whence);
00524 
00525    return (Xroot.Lseek(fileno(stream), offset, whence) < 0 ? -1 : 0);
00526 }
00527 }
00528 
00529 /******************************************************************************/
00530 /*                        X r d P o s i x _ F s t a t                         */
00531 /******************************************************************************/
00532   
00533 extern "C"
00534 {
00535 int XrdPosix_Fstat(int fildes, struct stat *buf)
00536 {
00537 
00538 // Return result of the close
00539 //
00540    return (Xroot.myFD(fildes)
00541           ? Xroot.Fstat(fildes, buf)
00542 #ifdef __linux__
00543           : Xunix.Fstat64(_STAT_VER, fildes, (struct stat64 *)buf));
00544 #else
00545           : Xunix.Fstat64(           fildes, (struct stat64 *)buf));
00546 #endif
00547 }
00548 
00549 #ifdef __linux__
00550 int XrdPosix_FstatV(int ver, int fildes, struct stat *buf)
00551 {
00552    return (Xroot.myFD(fildes)
00553           ? Xroot.Fstat(fildes, buf)
00554           : Xunix.Fstat64(ver, fildes, (struct stat64 *)buf));
00555 }
00556 #endif
00557 }
00558 
00559 /******************************************************************************/
00560 /*                        X r d P o s i x _ F s y n c                         */
00561 /******************************************************************************/
00562   
00563 extern "C"
00564 {
00565 int XrdPosix_Fsync(int fildes)
00566 {
00567 
00568 // Return the result of the sync
00569 //
00570    return (Xroot.myFD(fildes) ? Xroot.Fsync(fildes)
00571                               : Xunix.Fsync(fildes));
00572 }
00573 }
00574   
00575 /******************************************************************************/
00576 /*                        X r d P o s i x _ F t e l l                         */
00577 /******************************************************************************/
00578   
00579 extern "C"
00580 {
00581 long XrdPosix_Ftell(FILE *stream)
00582 {
00583 
00584 // Return the result of the tell
00585 //
00586    if (!Xroot.myFD(fileno(stream))) return Xunix.Ftell(stream);
00587 
00588    return static_cast<long>(Xroot.Lseek(fileno(stream), 0, SEEK_CUR));
00589 }
00590 }
00591   
00592 /******************************************************************************/
00593 /*                       X r d P o s i x _ F t e l l o                        */
00594 /******************************************************************************/
00595   
00596 extern "C"
00597 {
00598 long long XrdPosix_Ftello(FILE *stream)
00599 {
00600 
00601 // Return the result of the tell
00602 //
00603    if (!Xroot.myFD(fileno(stream))) return Xunix.Ftello64(stream);
00604 
00605    return Xroot.Lseek(fileno(stream), 0, SEEK_CUR);
00606 }
00607 }
00608   
00609 /******************************************************************************/
00610 /*                    X r d P o s i x _ F t r u n c a t e                     */
00611 /******************************************************************************/
00612   
00613 extern "C"
00614 {
00615 int XrdPosix_Ftruncate(int fildes, long long offset)
00616 {
00617 
00618 // Return the result of the ftruncate
00619 //
00620    return (Xroot.myFD(fildes) ? Xroot.Ftruncate  (fildes, offset)
00621                               : Xunix.Ftruncate64(fildes, offset));
00622 }
00623 }
00624 
00625 /******************************************************************************/
00626 /*                       X r d P o s i x _ F w r i t e                        */
00627 /******************************************************************************/
00628   
00629 extern "C"
00630 {
00631 size_t XrdPosix_Fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream)
00632 {
00633    size_t bytes, rc = 0;
00634    int fd = fileno(stream);
00635 
00636    if (!Xroot.myFD(fd)) return Xunix.Fwrite(ptr, size, nitems, stream);
00637 
00638    bytes = Xroot.Write(fd, ptr, size*nitems);
00639 
00640 // Get the right return code. Note that we cannot emulate the flags in sunx86
00641 //
00642    if (bytes > 0 && size) rc = bytes/size;
00643 #ifndef SUNX86
00644 #if defined(__linux__)
00645       else stream->_flags |= _IO_ERR_SEEN;
00646 #elif defined(__macos__)
00647       else stream->_flags |= __SERR;
00648 #else
00649       else stream->_flag  |= _IOERR;
00650 #endif
00651 #endif
00652 
00653    return rc;
00654 }
00655 }
00656   
00657 /******************************************************************************/
00658 /*                     X r d P o s i x _ G e t x a t t r                      */
00659 /******************************************************************************/
00660   
00661 #ifdef __linux__
00662 extern "C"
00663 {
00664 long long XrdPosix_Getxattr (const char *path, const char *name, void *value, 
00665                              unsigned long long size)
00666 {
00667    char *myPath, buff[2048];
00668 
00669    if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
00670       return Xunix.Getxattr(path, name, value, size);
00671 
00672    return Xroot.Getxattr(myPath, name, value, size);
00673 }
00674 }
00675 #endif
00676 
00677 /******************************************************************************/
00678 /*                    X r d P o s i x _ L g e t x a t t r                     */
00679 /******************************************************************************/
00680   
00681 #ifdef __linux__
00682 extern "C"
00683 {
00684 long long XrdPosix_Lgetxattr (const char *path, const char *name, void *value, 
00685                               unsigned long long size)
00686 {
00687    if (XrootPath.URL(path, 0, 0)) {errno = ENOTSUP; return -1;}
00688    return Xunix.Lgetxattr(path, name, value, size);
00689 }
00690 }
00691 #endif
00692 
00693 /******************************************************************************/
00694 /*                        X r d P o s i x _ L s e e k                         */
00695 /******************************************************************************/
00696   
00697 extern "C"
00698 {
00699 long long XrdPosix_Lseek(int fildes, long long offset, int whence)
00700 {
00701 
00702 // Return the operation of the seek
00703 //
00704    return (Xroot.myFD(fildes) ? Xroot.Lseek  (fildes, offset, whence)
00705                               : Xunix.Lseek64(fildes, offset, whence));
00706 }
00707 }
00708 
00709 /******************************************************************************/
00710 /*                        X r d P o s i x _ L s t a t                         */
00711 /******************************************************************************/
00712   
00713 extern "C"
00714 {
00715 int XrdPosix_Lstat(const char *path, struct stat *buf)
00716 {
00717    char *myPath, buff[2048];
00718 
00719 // Make sure a path was passed
00720 //
00721    if (!path) {errno = EFAULT; return -1;}
00722 
00723 // Return the results of an open of a Unix file
00724 //
00725    return (!(myPath = XrootPath.URL(path, buff, sizeof(buff)))
00726 #ifdef __linux__
00727           ? Xunix.Lstat64(_STAT_VER, path, (struct stat64 *)buf)
00728 #else
00729           ? Xunix.Lstat64(           path, (struct stat64 *)buf)
00730 #endif
00731           : Xroot.Stat(myPath, buf));
00732 }
00733 }
00734   
00735 /******************************************************************************/
00736 /*                        X r d P o s i x _ M k d i r                         */
00737 /******************************************************************************/
00738 
00739 extern "C"
00740 {
00741 int XrdPosix_Mkdir(const char *path, mode_t mode)
00742 {
00743    char *myPath, buff[2048];
00744 
00745 // Make sure a path was passed
00746 //
00747    if (!path) {errno = EFAULT; return -1;}
00748 
00749 // Return the results of a mkdir of a Unix file system
00750 //
00751    if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
00752       return Xunix.Mkdir(path, mode);
00753 
00754 // Return the results of an mkdir of an xrootd file system
00755 //
00756    return Xroot.Mkdir(myPath, mode);
00757 }
00758 }
00759 
00760 /******************************************************************************/
00761 /*                         X r d P o s i x _ O p e n                          */
00762 /******************************************************************************/
00763   
00764 extern "C"
00765 {
00766 int XrdPosix_Open(const char *path, int oflag, ...)
00767 {
00768    char *myPath, buff[2048];
00769    va_list ap;
00770    int mode;
00771 
00772 // Make sure a path was passed
00773 //
00774    if (!path) {errno = EFAULT; return -1;}
00775 
00776 // Return the results of an open of a Unix file
00777 //
00778    if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
00779       {if (!(oflag & O_CREAT)) return Xunix.Open64(path, oflag);
00780        va_start(ap, oflag);
00781        mode = va_arg(ap, int);
00782        va_end(ap);
00783        return Xunix.Open64(path, oflag, (mode_t)mode);
00784       }
00785 
00786 // Return the results of an open of an xrootd file
00787 //
00788    if (!(oflag & O_CREAT)) return Xroot.Open(myPath, oflag);
00789    va_start(ap, oflag);
00790    mode = va_arg(ap, int);
00791    va_end(ap);
00792    return Xroot.Open(myPath, oflag, (mode_t)mode);
00793 }
00794 }
00795 
00796 /******************************************************************************/
00797 /*                       X r d P o s i x _ O p e n d i r                      */
00798 /******************************************************************************/
00799 
00800 extern "C"
00801 {
00802 DIR* XrdPosix_Opendir(const char *path)
00803 {
00804    char *myPath, buff[2048];
00805 
00806 // Make sure a path was passed
00807 //
00808    if (!path) {errno = EFAULT; return 0;}
00809    
00810 // Unix opendir
00811 //
00812    if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
00813       return Xunix.Opendir(path);
00814 
00815 // Xrootd opendir
00816 //
00817    return Xroot.Opendir(myPath);
00818 }
00819 }
00820 
00821 /******************************************************************************/
00822 /*                     X r d P o s i x _ P a t h c o n f                      */
00823 /******************************************************************************/
00824   
00825 // This is a required addition for Solaris 10+ systems
00826 
00827 extern "C"
00828 {
00829 long XrdPosix_Pathconf(const char *path, int name)
00830 {
00831    return (XrootPath.URL(path, 0, 0) ? Xunix.Pathconf("/tmp", name)
00832                                      : Xunix.Pathconf(path,   name));
00833 }
00834 }
00835 
00836 /******************************************************************************/
00837 /*                        X r d P o s i x _ P r e a d                         */
00838 /******************************************************************************/
00839   
00840 extern "C"
00841 {
00842 long long XrdPosix_Pread(int fildes, void *buf, unsigned long long nbyte,
00843                          long long offset)
00844 {
00845 
00846 // Return the results of the read
00847 //
00848    return (Xroot.myFD(fildes) ? Xroot.Pread  (fildes, buf, nbyte, offset)
00849                               : Xunix.Pread64(fildes, buf, nbyte, offset));
00850 }
00851 }
00852 
00853 /******************************************************************************/
00854 /*                       X r d P o s i x _ P w r i t e                        */
00855 /******************************************************************************/
00856   
00857 extern "C"
00858 {
00859 long long XrdPosix_Pwrite(int fildes, const void *buf, unsigned long long nbyte,
00860                           long long offset)
00861 {
00862 
00863 // Return the results of the write
00864 //
00865    return (Xroot.myFD(fildes) ? Xroot.Pwrite  (fildes, buf, nbyte, offset)
00866                               : Xunix.Pwrite64(fildes, buf, nbyte, offset));
00867 }
00868 }
00869 
00870 /******************************************************************************/
00871 /*                         X r d P o s i x _ R e a d                          */
00872 /******************************************************************************/
00873   
00874 extern "C"
00875 {
00876 long long XrdPosix_Read(int fildes, void *buf, unsigned long long nbyte)
00877 {
00878 
00879 // Return the results of the read
00880 //
00881    return (Xroot.myFD(fildes) ? Xroot.Read(fildes, buf, nbyte)
00882                               : Xunix.Read(fildes, buf, nbyte));
00883 }
00884 }
00885  
00886 /******************************************************************************/
00887 /*                        X r d P o s i x _ R e a d v                         */
00888 /******************************************************************************/
00889   
00890 extern "C"
00891 {
00892 long long XrdPosix_Readv(int fildes, const struct iovec *iov, int iovcnt)
00893 {
00894 
00895 // Return results of the readv
00896 //
00897    return (Xroot.myFD(fildes) ? Xroot.Readv(fildes, iov, iovcnt)
00898                               : Xunix.Readv(fildes, iov, iovcnt));
00899 }
00900 }
00901 
00902 /******************************************************************************/
00903 /*                      X r d P o s i x _ R e a d d i r                       */
00904 /******************************************************************************/
00905 
00906 extern "C"
00907 {
00908 // On some platforms both 32- and 64-bit versions are callable. so do the same
00909 //
00910 struct dirent   * XrdPosix_Readdir  (DIR *dirp)
00911 {
00912 
00913 // Return result of readdir
00914 //
00915    return (Xroot.isXrootdDir(dirp) ? Xroot.Readdir(dirp)
00916                                    : Xunix.Readdir(dirp));
00917 }
00918 
00919 struct dirent64 * XrdPosix_Readdir64(DIR *dirp)
00920 {
00921 
00922 // Return result of readdir
00923 //
00924    return (Xroot.isXrootdDir(dirp) ? Xroot.Readdir64(dirp)
00925                                    : Xunix.Readdir64(dirp));
00926 }
00927 }
00928 
00929 /******************************************************************************/
00930 /*                    X r d P o s i x _ R e a d d i r _ r                     */
00931 /******************************************************************************/
00932 
00933 extern "C"
00934 {
00935 int XrdPosix_Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
00936 {
00937 
00938 // Return result of readdir
00939 //
00940    return (Xroot.isXrootdDir(dirp) ? Xroot.Readdir_r(dirp,entry,result)
00941                                    : Xunix.Readdir_r(dirp,entry,result));
00942 }
00943 
00944 int XrdPosix_Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
00945 {
00946 
00947 // Return result of readdir
00948 //
00949    return (Xroot.isXrootdDir(dirp) ? Xroot.Readdir64_r(dirp,entry,result)
00950                                    : Xunix.Readdir64_r(dirp,entry,result));
00951 }
00952 }
00953 
00954 /******************************************************************************/
00955 /*                       X r d P o s i x _ R e n a m e                        */
00956 /******************************************************************************/
00957 
00958 extern "C"
00959 {
00960 int XrdPosix_Rename(const char *oldpath, const char *newpath)
00961 {
00962    char *oldPath, buffold[2048], *newPath, buffnew[2048];
00963 
00964 // Make sure a path was passed
00965 //
00966    if (!oldpath || !newpath) {errno = EFAULT; return -1;}
00967 
00968 // Return the results of a mkdir of a Unix file system
00969 //
00970    if (!(oldPath = XrootPath.URL(oldpath, buffold, sizeof(buffold)))
00971    ||  !(newPath = XrootPath.URL(newpath, buffnew, sizeof(buffnew))))
00972       return Xunix.Rename(oldpath, newpath);
00973 
00974 // Return the results of an mkdir of an xrootd file system
00975 //
00976    return Xroot.Rename(oldPath, newPath);
00977 }
00978 }
00979 
00980 /******************************************************************************/
00981 /*                    X r d P o s i x _ R e w i n d d i r                     */
00982 /******************************************************************************/
00983 
00984 extern "C"
00985 {
00986 void XrdPosix_Rewinddir(DIR *dirp)
00987 {
00988 
00989 // Return result of rewind
00990 //
00991    return (Xroot.isXrootdDir(dirp) ? Xroot.Rewinddir(dirp)
00992                                    : Xunix.Rewinddir(dirp));
00993 }
00994 }
00995 
00996 /******************************************************************************/
00997 /*                        X r d P o s i x _ R m d i r                         */
00998 /******************************************************************************/
00999 
01000 extern "C"
01001 {
01002 int XrdPosix_Rmdir(const char *path)
01003 {
01004    char *myPath, buff[2048];
01005 
01006 // Make sure a path was passed
01007 //
01008    if (!path) {errno = EFAULT; return -1;}
01009 
01010 // Return the results of a mkdir of a Unix file system
01011 //
01012    if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
01013       return Xunix.Rmdir(path);
01014 
01015 // Return the results of an mkdir of an xrootd file system
01016 //
01017    return Xroot.Rmdir(myPath);
01018 }
01019 }
01020 
01021 /******************************************************************************/
01022 /*                      X r d P o s i x _ S e e k d i r                       */
01023 /******************************************************************************/
01024 
01025 extern "C"
01026 {
01027 void XrdPosix_Seekdir(DIR *dirp, long loc)
01028 {
01029 
01030 // Call seekdir
01031 //
01032    (Xroot.isXrootdDir(dirp) ? Xroot.Seekdir(dirp, loc)
01033                             : Xunix.Seekdir(dirp, loc));
01034 }
01035 }
01036 
01037 /******************************************************************************/
01038 /*                         X r d P o s i x _ S t a t                          */
01039 /******************************************************************************/
01040   
01041 extern "C"
01042 {
01043 int XrdPosix_Stat(const char *path, struct stat *buf)
01044 {
01045    char *myPath, buff[2048];
01046 
01047 // Make sure a path was passed
01048 //
01049    if (!path) {errno = EFAULT; return -1;}
01050 
01051 // Return the results of an open of a Unix file
01052 //
01053    return (!(myPath = XrootPath.URL(path, buff, sizeof(buff)))
01054 #ifdef __linux__
01055           ? Xunix.Stat64(_STAT_VER, path, (struct stat64 *)buf)
01056 #else
01057           ? Xunix.Stat64(           path, (struct stat64 *)buf)
01058 #endif
01059           : Xroot.Stat(myPath, buf));
01060 }
01061 }
01062   
01063 /******************************************************************************/
01064 /*                       X r d P o s i x _ S t a t f s                        */
01065 /******************************************************************************/
01066   
01067 extern "C"
01068 {
01069 int XrdPosix_Statfs(const char *path, struct statfs *buf)
01070 {
01071    char *myPath, buff[2048];
01072 
01073 // Make sure a path was passed
01074 //
01075    if (!path) {errno = EFAULT; return -1;}
01076 
01077 // Return the results of an open of a Unix file
01078 //
01079    return ((myPath = XrootPath.URL(path, buff, sizeof(buff)))
01080           ? Xroot.Statfs(myPath, buf) 
01081           : Xunix.Statfs64(path, (struct statfs64 *)buf));
01082 }
01083 }
01084   
01085 /******************************************************************************/
01086 /*                      X r d P o s i x _ S t a t v f s                       */
01087 /******************************************************************************/
01088   
01089 extern "C"
01090 {
01091 int XrdPosix_Statvfs(const char *path, struct statvfs *buf)
01092 {
01093    char *myPath, buff[2048];
01094 
01095 // Make sure a path was passed
01096 //
01097    if (!path) {errno = EFAULT; return -1;}
01098 
01099 // Return the results of an open of a Unix file
01100 //
01101    return ((myPath = XrootPath.URL(path, buff, sizeof(buff)))
01102           ? Xroot.Statvfs(myPath, buf) 
01103           : Xunix.Statvfs64(path, (struct statvfs64 *)buf));
01104 }
01105 }
01106 
01107 /******************************************************************************/
01108 /*                      X r d P o s i x _ T e l l d i r                       */
01109 /******************************************************************************/
01110 
01111 extern "C"
01112 {
01113 long XrdPosix_Telldir(DIR *dirp)
01114 {
01115 
01116 // Return result of telldir
01117 //
01118    return (Xroot.isXrootdDir(dirp) ? Xroot.Telldir(dirp)
01119                                    : Xunix.Telldir(dirp));
01120 }
01121 }
01122 
01123 /******************************************************************************/
01124 /*                     X r d P o s i x _ T r u n c a t e                      */
01125 /******************************************************************************/
01126   
01127 extern "C"
01128 {
01129 int XrdPosix_Truncate(const char *path, long long offset)
01130 {
01131    char *myPath, buff[2048];
01132 
01133 // Make sure a path was passed
01134 //
01135    if (!path) {errno = EFAULT; return -1;}
01136 
01137 // Return the results of a truncate of a Unix file system
01138 //
01139    if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
01140       return Xunix.Truncate64(path, offset);
01141 
01142 // Return the results of an truncate of an xrootd file system
01143 //
01144    return Xroot.Truncate(myPath, offset);
01145 }
01146 }
01147   
01148 /******************************************************************************/
01149 /*                      X r d P o s i x _ U n l i n k                         */
01150 /******************************************************************************/
01151 
01152 extern "C"
01153 {
01154 int XrdPosix_Unlink(const char *path)
01155 {   
01156    char *myPath, buff[2048];
01157 
01158 // Make sure a path was passed
01159 //
01160    if (!path) {errno = EFAULT; return -1;}
01161 
01162 // Return the result of a unlink of a Unix file
01163 //
01164    if (!(myPath = XrootPath.URL(path, buff, sizeof(buff))))
01165       return Xunix.Unlink(path);
01166 
01167 // Return the results of an unlink of an xrootd file
01168 //
01169    return Xroot.Unlink(myPath);
01170 }
01171 }
01172 
01173 /******************************************************************************/
01174 /*                        X r d P o s i x _ W r i t e                         */
01175 /******************************************************************************/
01176   
01177 extern "C"
01178 {
01179 long long XrdPosix_Write(int fildes, const void *buf, unsigned long long nbyte)
01180 {
01181 
01182 // Return the results of the write
01183 //
01184    return (Xroot.myFD(fildes) ? Xroot.Write(fildes, buf, nbyte)
01185                               : Xunix.Write(fildes, buf, nbyte));
01186 }
01187 }
01188  
01189 /******************************************************************************/
01190 /*                       X r d P o s i x _ W r i t e v                        */
01191 /******************************************************************************/
01192   
01193 extern "C"
01194 {
01195 long long XrdPosix_Writev(int fildes, const struct iovec *iov, int iovcnt)
01196 {
01197 
01198 // Return results of the writev
01199 //
01200    return (Xroot.myFD(fildes) ? Xroot.Writev(fildes, iov, iovcnt)
01201                               : Xunix.Writev(fildes, iov, iovcnt));
01202 }
01203 }
01204 
01205 /******************************************************************************/
01206 /*                     X r d P o s i x _ i s M y P a t h                      */
01207 /******************************************************************************/
01208   
01209 int XrdPosix_isMyPath(const char *path)
01210 {
01211     return (0 != XrootPath.URL(path, 0, 0));
01212 }
01213 
01214 /******************************************************************************/
01215 /*                          X r d P o s i x _ U R L                           */
01216 /******************************************************************************/
01217   
01218 char *XrdPosix_URL(const char *path, char *buff, int blen)
01219 {
01220    return XrootPath.URL(path, buff, blen);
01221 }

Generated on Tue Jul 5 14:46:57 2011 for ROOT_528-00b_version by  doxygen 1.5.1