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 /* */ 00012 /* This file is part of the XRootD software suite. */ 00013 /* */ 00014 /* XRootD is free software: you can redistribute it and/or modify it under */ 00015 /* the terms of the GNU Lesser General Public License as published by the */ 00016 /* Free Software Foundation, either version 3 of the License, or (at your */ 00017 /* option) any later version. */ 00018 /* */ 00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00022 /* License for more details. */ 00023 /* */ 00024 /* You should have received a copy of the GNU Lesser General Public License */ 00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00027 /* */ 00028 /* The copyright holder's institutional names and contributor's names may not */ 00029 /* be used to endorse or promote products derived from this software without */ 00030 /* specific prior written permission of the institution or contributor. */ 00031 /* Modified by Frank Winklmeier to add the full Posix file system definition. */ 00032 /******************************************************************************/ 00033 00034 #include <dirent.h> 00035 #include <unistd.h> 00036 #include <sys/stat.h> 00037 #include <sys/statvfs.h> 00038 #include <sys/types.h> 00039 00040 #if defined(__APPLE__) || defined(__FreeBSD__) 00041 #include <sys/param.h> 00042 #include <sys/mount.h> 00043 #else 00044 #include <sys/statfs.h> 00045 #endif 00046 00047 #include "XrdPosix/XrdPosixOsDep.hh" 00048 #include "XrdSys/XrdSysPthread.hh" 00049 00050 struct XrdOucIOVec; 00051 00052 class XrdScheduler; 00053 class XrdOucCache; 00054 class XrdOucCache2; 00055 class XrdOucEnv; 00056 class XrdOucName2Name; 00057 class XrdSysLogger; 00058 class XrdPosixCallBack; 00059 class XrdPosixCallBackIO; 00060 class XrdPosixFile; 00061 class XrdPosixInfo; 00062 00063 //----------------------------------------------------------------------------- 00065 //----------------------------------------------------------------------------- 00066 00067 class XrdPosixXrootd 00068 { 00069 public: 00070 friend class XrdPosixConfig; 00071 00072 //----------------------------------------------------------------------------- 00074 //----------------------------------------------------------------------------- 00075 00076 static int Access(const char *path, int amode); 00077 00078 //----------------------------------------------------------------------------- 00080 //----------------------------------------------------------------------------- 00081 00082 static int Close(int fildes); 00083 00084 //----------------------------------------------------------------------------- 00086 //----------------------------------------------------------------------------- 00087 00088 static int Closedir(DIR *dirp); 00089 00090 //----------------------------------------------------------------------------- 00099 //----------------------------------------------------------------------------- 00100 00101 static int endPoint(int FD, char *Buff, int Blen); 00102 00103 //----------------------------------------------------------------------------- 00105 //----------------------------------------------------------------------------- 00106 00107 static int Fstat(int fildes, struct stat *buf); 00108 00109 //----------------------------------------------------------------------------- 00111 //----------------------------------------------------------------------------- 00112 00113 static int Fsync(int fildes); 00114 00115 static void Fsync(int fildes, XrdPosixCallBackIO *cbp); // Async extension! 00116 00117 //----------------------------------------------------------------------------- 00119 //----------------------------------------------------------------------------- 00120 00121 static int Ftruncate(int fildes, off_t offset); 00122 00123 //----------------------------------------------------------------------------- 00141 00142 static long long Getxattr (const char *path, const char *name, 00143 void *value, unsigned long long size); 00144 00145 //----------------------------------------------------------------------------- 00147 //----------------------------------------------------------------------------- 00148 00149 static off_t Lseek(int fildes, off_t offset, int whence); 00150 00151 //----------------------------------------------------------------------------- 00153 //----------------------------------------------------------------------------- 00154 00155 static int Mkdir(const char *path, mode_t mode); 00156 00157 //----------------------------------------------------------------------------- 00167 //----------------------------------------------------------------------------- 00168 00169 static const int isStream = 0x40000000; // Internal for Open oflag 00170 00171 static int Open(const char *path, int oflag, mode_t mode=0, 00172 XrdPosixCallBack *cbP=0); 00173 00174 //----------------------------------------------------------------------------- 00176 //----------------------------------------------------------------------------- 00177 00178 static DIR* Opendir(const char *path); 00179 00180 //----------------------------------------------------------------------------- 00182 //----------------------------------------------------------------------------- 00183 00184 static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset); 00185 00186 static void Pread(int fildes, void *buf, size_t nbyte, off_t offset, 00187 XrdPosixCallBackIO *cbp); // Async extension! 00188 00189 //----------------------------------------------------------------------------- 00191 //----------------------------------------------------------------------------- 00192 00193 static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset); 00194 00195 static void Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset, 00196 XrdPosixCallBackIO *cbp); // Async extension! 00197 00198 //----------------------------------------------------------------------------- 00209 //----------------------------------------------------------------------------- 00210 00211 static int QueryChksum(const char *path, time_t &mtime, 00212 char *buff, int blen); 00213 00214 //----------------------------------------------------------------------------- 00224 //----------------------------------------------------------------------------- 00225 00226 static long long QueryOpaque(const char *path, char *buff, int blen); 00227 00228 //----------------------------------------------------------------------------- 00230 //----------------------------------------------------------------------------- 00231 00232 static ssize_t Read(int fildes, void *buf, size_t nbyte); 00233 00234 //----------------------------------------------------------------------------- 00236 //----------------------------------------------------------------------------- 00237 00238 static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt); 00239 00240 //----------------------------------------------------------------------------- 00244 //----------------------------------------------------------------------------- 00245 00246 static struct dirent* Readdir (DIR *dirp); 00247 static struct dirent64* Readdir64(DIR *dirp); 00248 00249 //----------------------------------------------------------------------------- 00253 //----------------------------------------------------------------------------- 00254 00255 static int Readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result); 00256 static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result); 00257 00258 //----------------------------------------------------------------------------- 00260 //----------------------------------------------------------------------------- 00261 00262 static int Rename(const char *oldpath, const char *newpath); 00263 00264 //----------------------------------------------------------------------------- 00266 //----------------------------------------------------------------------------- 00267 00268 static void Rewinddir(DIR *dirp); 00269 00270 //----------------------------------------------------------------------------- 00272 //----------------------------------------------------------------------------- 00273 00274 static int Rmdir(const char *path); 00275 00276 //----------------------------------------------------------------------------- 00278 //----------------------------------------------------------------------------- 00279 00280 static void Seekdir(DIR *dirp, long loc); 00281 00282 //----------------------------------------------------------------------------- 00284 //----------------------------------------------------------------------------- 00285 00286 static int Stat(const char *path, struct stat *buf); 00287 00288 //----------------------------------------------------------------------------- 00291 //----------------------------------------------------------------------------- 00292 00293 static int Statfs(const char *path, struct statfs *buf); 00294 00295 //----------------------------------------------------------------------------- 00297 //----------------------------------------------------------------------------- 00298 00299 static int Statvfs(const char *path, struct statvfs *buf); 00300 00301 //----------------------------------------------------------------------------- 00303 //----------------------------------------------------------------------------- 00304 00305 static long Telldir(DIR *dirp); 00306 00307 //----------------------------------------------------------------------------- 00309 //----------------------------------------------------------------------------- 00310 00311 static int Truncate(const char *path, off_t offset); 00312 00313 //----------------------------------------------------------------------------- 00315 //----------------------------------------------------------------------------- 00316 00317 static int Unlink(const char *path); 00318 00319 //----------------------------------------------------------------------------- 00332 //----------------------------------------------------------------------------- 00333 00334 static void VRead(int fildes, const XrdOucIOVec *readV, int n, 00335 XrdPosixCallBackIO *cbp); // Async extension! 00336 00337 static ssize_t VRead(int fildes, const XrdOucIOVec *readV, int n); 00338 00339 //----------------------------------------------------------------------------- 00341 //----------------------------------------------------------------------------- 00342 00343 static ssize_t Write(int fildes, const void *buf, size_t nbyte); 00344 00345 //----------------------------------------------------------------------------- 00347 //----------------------------------------------------------------------------- 00348 00349 static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt); 00350 00351 //----------------------------------------------------------------------------- 00354 //----------------------------------------------------------------------------- 00355 00356 inline int fdOrigin() {return baseFD;} 00357 00358 static bool isXrootdDir(DIR *dirp); 00359 00360 static bool myFD(int fd); 00361 00362 /* There must be one instance of this object per executable image. Typically, 00363 this object is declared in main() or at file level. This is necessary to 00364 properly do one-time initialization of the static members. When declaring 00365 this object, you can pass the following information: 00366 maxfd - maximum number of simultaneous files and directories to support. 00367 The value returned by getrlimit() over-rides the passed value 00368 unless maxfd is negative. When negative, abs(maxfd) becomes the 00369 absolute maximum and shadow file descriptors are not used. 00370 maxdir - Ignored, only here for backward compatability. 00371 maxthr - Ignored, only here for backward compatability. 00372 */ 00373 XrdPosixXrootd(int maxfd=255, int maxdir=0, int maxthr=0); 00374 ~XrdPosixXrootd(); 00375 00376 // The following methods were always considered private. They are no longer 00377 // used and will be removed on the next major release! They are only here for 00378 // now to keep ABI compatability for the 4.x and prior releases. 00379 // 00380 static void setCache(XrdOucCache *cP); 00381 static void setCache(XrdOucCache2 *cP); 00382 static void setDebug(int val, bool doDebug=false); 00383 static void setEnv(const char *kword, int kval); 00384 static void setIPV4(bool userv4); 00385 static void setLogger(XrdSysLogger *logP); 00386 static void setNumCB(int numcb); 00387 static void setN2N(XrdOucName2Name *pN2N, int opts=0); 00388 static void setSched(XrdScheduler *sP); 00389 00390 private: 00391 00392 static int Fault(XrdPosixFile *fp, int ecode); 00393 static void initStat(struct stat *buf); 00394 static void initXdev(dev_t &st_dev, dev_t &st_rdev); 00395 00396 static int Open(const char *path, int oflag, mode_t mode, 00397 XrdPosixCallBack *cbP, XrdPosixInfo *infoP); 00398 static bool OpenCache(XrdPosixFile &file, XrdPosixInfo &Info); 00399 00400 static int baseFD; 00401 static int initDone; 00402 }; 00403 #endif