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