xrootd
XrdPosixXrootd.hh
Go to the documentation of this file.
1 #ifndef __XRDPOSIXXROOTD_H__
2 #define __XRDPOSIXXROOTD_H__
3 /******************************************************************************/
4 /* */
5 /* X r d P o s i x X r o o t d */
6 /* */
7 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /* Modified by Frank Winklmeier to add the full Posix file system definition. */
32 /******************************************************************************/
33 
34 #include <dirent.h>
35 #include <unistd.h>
36 #include <sys/stat.h>
37 #include <sys/statvfs.h>
38 #include <sys/types.h>
39 
40 #if defined(__APPLE__) || defined(__FreeBSD__)
41 #include <sys/param.h>
42 #include <sys/mount.h>
43 #else
44 #include <sys/statfs.h>
45 #endif
46 
48 #include "XrdSys/XrdSysPthread.hh"
49 
50 class XrdOucCache;
51 class XrdOucEnv;
52 class XrdPosixCallBack;
53 class XrdPosixFile;
54 class XrdPosixDir;
55 
57 {
58 public:
59 
60 // POSIX methods
61 //
62 static int Close(int fildes, int Stream=0);
63 
64 static int Closedir(DIR *dirp);
65 
66 static int Fstat(int fildes, struct stat *buf);
67 
68 static int Fsync(int fildes);
69 
70 static int Ftruncate(int fildes, off_t offset);
71 
72 static long long Getxattr (const char *path, const char *name,
73  void *value, unsigned long long size);
74 
75 static off_t Lseek(int fildes, off_t offset, int whence);
76 
77 static int Mkdir(const char *path, mode_t mode);
78 
79 static const int isStream = 0x40000000; // Internal for Open oflag
80 
81 static int Open(const char *path, int oflag, mode_t mode=0,
82  XrdPosixCallBack *cbP=0);
83 
84 static DIR* Opendir(const char *path);
85 
86 static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset);
87 
88 static ssize_t Read(int fildes, void *buf, size_t nbyte);
89 
90 static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt);
91 
92 static struct dirent* Readdir (DIR *dirp);
93 static struct dirent64* Readdir64(DIR *dirp);
94 
95 static int Readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result);
96 static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result);
97 
98 static int Rename(const char *oldpath, const char *newpath);
99 
100 static void Rewinddir(DIR *dirp);
101 
102 static int Rmdir(const char *path);
103 
104 static void Seekdir(DIR *dirp, long loc);
105 
106 static int Stat(const char *path, struct stat *buf);
107 
108 static int Statfs(const char *path, struct statfs *buf);
109 
110 static int Statvfs(const char *path, struct statvfs *buf);
111 
112 static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
113 
114 static long Telldir(DIR *dirp);
115 
116 static int Truncate(const char *path, off_t offset);
117 
118 static int Unlink(const char *path);
119 
120 static ssize_t Write(int fildes, const void *buf, size_t nbyte);
121 
122 static ssize_t Write(int fildes, void *buf, size_t nbyte, off_t offset);
123 
124 static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt);
125 
126 // Some non POSIX methods
127 //
128 static int Access(const char *path, int amode);
129 
130 static int endPoint(int FD, char *Buff, int Blen);
131 
132 static bool isXrootdDir(DIR *dirp);
133 
134 static int mapError(int rc);
135 
136 static
137 inline bool myFD(int fd) {return fd >= baseFD && fd <= (highFD+baseFD)
138  && myFiles && myFiles[fd-baseFD];
139  }
140 
141 static void OpenCB(XrdPosixFile *fp, void *cbArg, int res);
142 
143 static int QueryChksum(const char *, time_t &, char *, int);
144 
145 static long long QueryOpaque(const char*, char*, int);
146 
147 static void setDebug(int val);
148 
149 static void setEnv(const char *var, const char *val);
150 
151 static void setEnv(const char *var, long val);
152 
153 static void setCache(XrdOucCache *cP);
154 
155 static int Debug;
156 
157 /* There must be one instance of this object per executable image. Typically,
158  this object is declared in main() or at file level. This is necessary to
159  properly do one-time initialization of the static members. When declaring
160  this object, you can pass the following information:
161  maxfd - maximum number of simultaneous files to support (i.e. fdlimit).
162  The value returned by getrlimit() over-rides the passed value
163  unless maxfd is negative. When negative, abs(maxfd) becomes the
164  absolute maximum and shadow file descriptors are not used.
165  maxdir - maximum number of open directories that can be supported. This
166  is independent of maxfd.
167  maxthr - maximum number of threads to use for the callback function.
168 */
169  XrdPosixXrootd(int maxfd=255, int maxdir=255, int maxthr=255);
170  ~XrdPosixXrootd();
171 
172 private:
173 
174 static void initEnv();
175 static void initEnv(char *eData);
176 static void initEnv(XrdOucEnv &, const char *, long long &);
177 static int Fault(XrdPosixFile *fp, int complete=1);
178 static XrdPosixFile *findFP(int fildes, int glk=0);
179 static XrdPosixDir *findDIR(DIR *dirp, int glk=0);
180 static void initStat(struct stat *buf);
181 static void initXdev(dev_t &st_dev, dev_t &st_rdev);
182 static int mapFlags(int flags);
183 static int mapMode(mode_t Mode);
184 
186 static XrdPosixFile **myFiles;
187 static XrdPosixDir **myDirs;
189 static int lastFD;
190 static int highFD;
191 static int baseFD;
192 static int freeFD;
193 static int lastDir;
194 static int highDir;
195 static int devNull;
196 static int pllOpen;
197 static int maxThreads;
198 static int initDone;
199 };
200 #endif
static int baseFD
Definition: XrdPosixXrootd.hh:191
static int Statvfs(const char *path, struct statvfs *buf)
static int Ftruncate(int fildes, off_t offset)
static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt)
static XrdOucCache * myCache
Definition: XrdPosixXrootd.hh:188
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
static const int isStream
Definition: XrdPosixXrootd.hh:79
static int devNull
Definition: XrdPosixXrootd.hh:195
static long Telldir(DIR *dirp)
static long long Getxattr(const char *path, const char *name, void *value, unsigned long long size)
static int highFD
Definition: XrdPosixXrootd.hh:190
static int mapFlags(int flags)
static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset)
static void OpenCB(XrdPosixFile *fp, void *cbArg, int res)
static int maxThreads
Definition: XrdPosixXrootd.hh:197
static ssize_t Write(int fildes, const void *buf, size_t nbyte)
static int Unlink(const char *path)
static int Close(int fildes, int Stream=0)
static XrdPosixDir ** myDirs
Definition: XrdPosixXrootd.hh:187
static int Access(const char *path, int amode)
static int Stat(const char *path, struct stat *buf)
static int highDir
Definition: XrdPosixXrootd.hh:194
static int freeFD
Definition: XrdPosixXrootd.hh:192
static long long QueryOpaque(const char *, char *, int)
static int Fsync(int fildes)
Definition: XrdSysPthread.hh:140
static int Fault(XrdPosixFile *fp, int complete=1)
static void initEnv()
static int mapMode(mode_t Mode)
static int Truncate(const char *path, off_t offset)
static bool myFD(int fd)
Definition: XrdPosixXrootd.hh:137
Definition: XrdOucCache.hh:278
static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
static int lastFD
Definition: XrdPosixXrootd.hh:189
Definition: XrdOucEnv.hh:41
Definition: XrdPosixCallBack.hh:50
static int pllOpen
Definition: XrdPosixXrootd.hh:196
Definition: XrdPosixXrootd.hh:56
static int initDone
Definition: XrdPosixXrootd.hh:198
static bool isXrootdDir(DIR *dirp)
static void initXdev(dev_t &st_dev, dev_t &st_rdev)
static XrdPosixDir * findDIR(DIR *dirp, int glk=0)
static struct dirent * Readdir(DIR *dirp)
static XrdPosixFile ** myFiles
Definition: XrdPosixXrootd.hh:186
static int Statfs(const char *path, struct statfs *buf)
static void setDebug(int val)
static int Fstat(int fildes, struct stat *buf)
static int mapError(int rc)
static int lastDir
Definition: XrdPosixXrootd.hh:193
static XrdPosixFile * findFP(int fildes, int glk=0)
static int QueryChksum(const char *, time_t &, char *, int)
static XrdSysMutex myMutex
Definition: XrdPosixXrootd.hh:185
static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
static int Closedir(DIR *dirp)
static int endPoint(int FD, char *Buff, int Blen)
static void Rewinddir(DIR *dirp)
static struct dirent64 * Readdir64(DIR *dirp)
static int Rename(const char *oldpath, const char *newpath)
static void setCache(XrdOucCache *cP)
static int Rmdir(const char *path)
static ssize_t Read(int fildes, void *buf, size_t nbyte)
static void setEnv(const char *var, const char *val)
static off_t Lseek(int fildes, off_t offset, int whence)
static void initStat(struct stat *buf)
XrdPosixXrootd(int maxfd=255, int maxdir=255, int maxthr=255)
static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt)
static void Seekdir(DIR *dirp, long loc)
static int Mkdir(const char *path, mode_t mode)
static DIR * Opendir(const char *path)
static int Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
static int Debug
Definition: XrdPosixXrootd.hh:155