xrootd
XrdPosixXrootd.hh
Go to the documentation of this file.
00001 #ifndef __XRDPOSIXXROOTD_H__
00002 #define __XRDPOSIXXROOTD_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                        X r d P o s i x X r o o t d                         */
00006 /*                                                                            */
00007 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00011 /* Modified by Frank Winklmeier to add the full Posix file system definition. */
00012 /******************************************************************************/
00013 
00014 #include <dirent.h>
00015 #include <unistd.h>
00016 #include <sys/stat.h>
00017 #include <sys/statvfs.h>
00018 #include <sys/types.h>
00019 
00020 #if defined(__macos__) || defined(__FreeBSD__)
00021 #include <sys/param.h>
00022 #include <sys/mount.h>
00023 #else
00024 #include <sys/statfs.h>
00025 #endif
00026 
00027 #include "XrdPosix/XrdPosixOsDep.hh"
00028 #include "XrdSys/XrdSysPthread.hh"
00029 
00030 class XrdOucEnv;
00031 class XrdPosixCallBack;
00032 class XrdPosixFile;
00033 class XrdPosixDir;
00034 
00035 class XrdPosixXrootd
00036 {
00037 public:
00038 
00039 // POSIX methods
00040 //
00041 static int     Close(int fildes, int Stream=0);
00042 
00043 static int     Closedir(DIR *dirp);
00044 
00045 static int     Fstat(int fildes, struct stat *buf);
00046 
00047 static int     Fsync(int fildes);
00048 
00049 static int     Ftruncate(int fildes, off_t offset);
00050 
00051 static long long Getxattr (const char *path, const char *name,
00052                            void *value, unsigned long long size);
00053 
00054 static off_t   Lseek(int fildes, off_t offset, int whence);
00055 
00056 static int     Mkdir(const char *path, mode_t mode);
00057 
00058 static const int isStream = 0x40000000; // Internal for Open oflag
00059 
00060 static int     Open(const char *path, int oflag, mode_t mode=0,
00061                     XrdPosixCallBack *cbP=0);
00062 
00063 static DIR*    Opendir(const char *path);
00064   
00065 static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset);
00066   
00067 static ssize_t Read(int fildes, void *buf, size_t nbyte);
00068 
00069 static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt);
00070 
00071 static struct dirent*   Readdir  (DIR *dirp);
00072 static struct dirent64* Readdir64(DIR *dirp);
00073 
00074 static int     Readdir_r  (DIR *dirp, struct dirent   *entry, struct dirent   **result);
00075 static int     Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result);
00076 
00077 static int     Rename(const char *oldpath, const char *newpath);
00078 
00079 static void    Rewinddir(DIR *dirp);
00080 
00081 static int     Rmdir(const char *path);
00082 
00083 static void    Seekdir(DIR *dirp, long loc);
00084 
00085 static int     Stat(const char *path, struct stat *buf);
00086 
00087 static int     Statfs(const char *path, struct statfs *buf);
00088 
00089 static int     Statvfs(const char *path, struct statvfs *buf);
00090 
00091 static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
00092 
00093 static long    Telldir(DIR *dirp);
00094 
00095 static int     Truncate(const char *path, off_t offset);
00096 
00097 static int     Unlink(const char *path);
00098 
00099 static ssize_t Write(int fildes, const void *buf, size_t nbyte);
00100 
00101 static ssize_t Write(int fildes, void *buf, size_t nbyte, off_t offset);
00102 
00103 static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt);
00104 
00105 // Some non POSIX methods
00106 //
00107 static int     Access(const char *path, int amode);
00108 
00109 static int     endPoint(int FD, char *Buff, int Blen);
00110 
00111 static bool    isXrootdDir(DIR *dirp);
00112 
00113 static int     mapError(int rc);
00114 
00115 static
00116 inline bool    myFD(int fd) {return fd >= baseFD && fd <= (highFD+baseFD)
00117                                       && myFiles && myFiles[fd-baseFD];
00118                             }
00119 
00120 static void    OpenCB(XrdPosixFile *fp, void *cbArg, int res);
00121 
00122 static int     QueryChksum(const char *, time_t &, char *, int);
00123 
00124 static long long QueryOpaque(const char*, char*, int);
00125 
00126 static void    setDebug(int val);
00127 
00128 static void    setEnv(const char *var, const char *val);
00129 
00130 static void    setEnv(const char *var, long val);
00131 
00132 static int     Debug;
00133 
00134 /* There must be one instance of this object per executable image. Typically,
00135    this object is declared in main() or at file level. This is necessary to
00136    properly do one-time initialization of the static members. When declaring
00137    this object, you can pass the following information:
00138    maxfd  - maximum number of simultaneous files to support (i.e. fdlimit).
00139             The value returned by getrlimit() over-rides the passed value
00140             unless maxfd is negative. When negative, abs(maxfd) becomes the
00141             absolute maximum and shadow file descriptors are not used.
00142    maxdir - maximum number of open directories that can be supported. This
00143             is independent of maxfd.
00144    maxthr - maximum number of threads to use for the callback function.
00145 */
00146                XrdPosixXrootd(int maxfd=255, int maxdir=255, int maxthr=255);
00147               ~XrdPosixXrootd();
00148 
00149 private:
00150 
00151 static void                  initEnv();
00152 static void                  initEnv(char *eData);
00153 static void                  initEnv(XrdOucEnv &, const char *, long long &);
00154 static int                   Fault(XrdPosixFile *fp, int complete=1);
00155 static XrdPosixFile         *findFP(int fildes, int glk=0);
00156 static XrdPosixDir          *findDIR(DIR *dirp, int glk=0);
00157 static void                  initStat(struct stat *buf);
00158 static void                  initXdev(dev_t &st_dev, dev_t &st_rdev);
00159 static int                   mapFlags(int flags);
00160 static int                   mapMode(mode_t Mode);
00161 
00162 static XrdSysMutex    myMutex;
00163 static XrdPosixFile **myFiles;
00164 static XrdPosixDir  **myDirs;
00165 static int            lastFD;
00166 static int            highFD;
00167 static int            baseFD;
00168 static int            freeFD;
00169 static int            lastDir;
00170 static int            highDir;
00171 static int            devNull;
00172 static int            pllOpen;
00173 static int            maxThreads;
00174 static int            initDone;
00175 };
00176 #endif