xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 struct XrdOucIOVec;
51 
52 class XrdPosixCallBack;
53 class XrdPosixCallBackIO;
54 class XrdPosixFile;
55 class XrdPosixInfo;
56 class XrdPosixAdmin;
57 
58 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 
63 {
64 public:
65 friend class XrdPosixConfig;
66 friend class XrdPosixExtra;
67 
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 
72 static int Access(const char *path, int amode);
73 
74 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
77 
78 static int Close(int fildes);
79 
80 //-----------------------------------------------------------------------------
82 //-----------------------------------------------------------------------------
83 
84 static int Closedir(DIR *dirp);
85 
86 //-----------------------------------------------------------------------------
95 //-----------------------------------------------------------------------------
96 
97 static int endPoint(int FD, char *Buff, int Blen);
98 
99 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
102 
103 static int Fstat(int fildes, struct stat *buf);
104 
105 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
108 
109 static int Fsync(int fildes);
110 
111 static void Fsync(int fildes, XrdPosixCallBackIO *cbp); // Async extension!
112 
113 //-----------------------------------------------------------------------------
115 //-----------------------------------------------------------------------------
116 
117 static int Ftruncate(int fildes, off_t offset);
118 
119 //-----------------------------------------------------------------------------
137 
138 static long long Getxattr (const char *path, const char *name,
139  void *value, unsigned long long size);
140 
141 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
144 
145 static off_t Lseek(int fildes, off_t offset, int whence);
146 
147 //-----------------------------------------------------------------------------
149 //-----------------------------------------------------------------------------
150 
151 static int Mkdir(const char *path, mode_t mode);
152 
153 //-----------------------------------------------------------------------------
163 //-----------------------------------------------------------------------------
164 
165 static const int isStream = 0x40000000; // Internal for Open oflag
166 
167 static int Open(const char *path, int oflag, mode_t mode=0,
168  XrdPosixCallBack *cbP=0);
169 
170 //-----------------------------------------------------------------------------
172 //-----------------------------------------------------------------------------
173 
174 static DIR* Opendir(const char *path);
175 
176 //-----------------------------------------------------------------------------
178 //-----------------------------------------------------------------------------
179 
180 static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset);
181 
182 static void Pread(int fildes, void *buf, size_t nbyte, off_t offset,
183  XrdPosixCallBackIO *cbp); // Async extension!
184 
185 //-----------------------------------------------------------------------------
187 //-----------------------------------------------------------------------------
188 
189 static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
190 
191 static void Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset,
192  XrdPosixCallBackIO *cbp); // Async extension!
193 
194 //-----------------------------------------------------------------------------
205 //-----------------------------------------------------------------------------
206 
207 static int QueryChksum(const char *path, time_t &mtime,
208  char *buff, int blen);
209 
210 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------
221 
222 static long long QueryOpaque(const char *path, char *buff, int blen);
223 
224 //-----------------------------------------------------------------------------
226 //-----------------------------------------------------------------------------
227 
228 static ssize_t Read(int fildes, void *buf, size_t nbyte);
229 
230 //-----------------------------------------------------------------------------
232 //-----------------------------------------------------------------------------
233 
234 static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt);
235 
236 //-----------------------------------------------------------------------------
240 //-----------------------------------------------------------------------------
241 
242 static struct dirent* Readdir (DIR *dirp);
243 static struct dirent64* Readdir64(DIR *dirp);
244 
245 //-----------------------------------------------------------------------------
249 //-----------------------------------------------------------------------------
250 
251 static int Readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result);
252 static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result);
253 
254 //-----------------------------------------------------------------------------
256 //-----------------------------------------------------------------------------
257 
258 static int Rename(const char *oldpath, const char *newpath);
259 
260 //-----------------------------------------------------------------------------
262 //-----------------------------------------------------------------------------
263 
264 static void Rewinddir(DIR *dirp);
265 
266 //-----------------------------------------------------------------------------
268 //-----------------------------------------------------------------------------
269 
270 static int Rmdir(const char *path);
271 
272 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
275 
276 static void Seekdir(DIR *dirp, long loc);
277 
278 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
281 
282 static int Stat(const char *path, struct stat *buf);
283 
284 //-----------------------------------------------------------------------------
287 //-----------------------------------------------------------------------------
288 
289 static int Statfs(const char *path, struct statfs *buf);
290 
291 //-----------------------------------------------------------------------------
293 //-----------------------------------------------------------------------------
294 
295 static int Statvfs(const char *path, struct statvfs *buf);
296 
297 //-----------------------------------------------------------------------------
299 //-----------------------------------------------------------------------------
300 
301 static long Telldir(DIR *dirp);
302 
303 //-----------------------------------------------------------------------------
305 //-----------------------------------------------------------------------------
306 
307 static int Truncate(const char *path, off_t offset);
308 
309 //-----------------------------------------------------------------------------
311 //-----------------------------------------------------------------------------
312 
313 static int Unlink(const char *path);
314 
315 //-----------------------------------------------------------------------------
328 //-----------------------------------------------------------------------------
329 
330 static void VRead(int fildes, const XrdOucIOVec *readV, int n,
331  XrdPosixCallBackIO *cbp); // Async extension!
332 
333 static ssize_t VRead(int fildes, const XrdOucIOVec *readV, int n);
334 
335 //-----------------------------------------------------------------------------
337 //-----------------------------------------------------------------------------
338 
339 static ssize_t Write(int fildes, const void *buf, size_t nbyte);
340 
341 //-----------------------------------------------------------------------------
343 //-----------------------------------------------------------------------------
344 
345 static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt);
346 
347 //-----------------------------------------------------------------------------
350 //-----------------------------------------------------------------------------
351 
352 inline int fdOrigin() {return baseFD;}
353 
354 static bool isXrootdDir(DIR *dirp);
355 
356 static bool myFD(int fd);
357 
358 /* There must be one instance of this object per executable image. Typically,
359  this object is declared in main() or at file level. This is necessary to
360  properly do one-time initialization of the static members. When declaring
361  this object, you can pass the following information:
362  maxfd - maximum number of simultaneous files and directories to support.
363  The value returned by getrlimit() over-rides the passed value
364  unless maxfd is negative. When negative, abs(maxfd) becomes the
365  absolute maximum and shadow file descriptors are not used.
366  maxdir - Ignored, only here for backward compatibility.
367  maxthr - Ignored, only here for backward compatibility.
368 */
369  XrdPosixXrootd(int maxfd=255, int maxdir=0, int maxthr=0);
370  ~XrdPosixXrootd();
371 
372 private:
373 
374 static int Fault(XrdPosixFile *fp, int ecode);
375 
376 static int Open(const char *path, int oflag, mode_t mode,
377  XrdPosixCallBack *cbP, XrdPosixInfo *infoP);
378 static bool OpenCache(XrdPosixFile &file, XrdPosixInfo &Info);
379 
380 // functions that will be used when XrdEC is invoked
381 static int EcRename(const char*, const char*, XrdPosixAdmin*);
382 static int EcStat(const char*, struct stat*, XrdPosixAdmin*);
383 static int EcUnlink(const char*, XrdPosixAdmin*);
384 
385 static int baseFD;
386 static int initDone;
387 };
388 #endif
static int baseFD
Definition: XrdPosixXrootd.hh:385
static int Statvfs(const char *path, struct statvfs *buf)
Statvfs() conforms to POSIX.1-2001 statvfs()
static int Ftruncate(int fildes, off_t offset)
Ftruncate() conforms to POSIX.1-2001 ftruncate()
static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt)
Readv() conforms to POSIX.1-2001 readv()
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
static const int isStream
Definition: XrdPosixXrootd.hh:165
static long Telldir(DIR *dirp)
Telldir() conforms to POSIX.1-2001 telldir()
static long long Getxattr(const char *path, const char *name, void *value, unsigned long long size)
Definition: XrdPosixFile.hh:57
#define statfs(a, b)
Definition: XrdPosix.hh:98
int fdOrigin()
Definition: XrdPosixXrootd.hh:352
static long long QueryOpaque(const char *path, char *buff, int blen)
static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset)
Pread() conforms to POSIX.1-2001 pread()
static int EcStat(const char *, struct stat *, XrdPosixAdmin *)
static int EcUnlink(const char *, XrdPosixAdmin *)
static ssize_t Write(int fildes, const void *buf, size_t nbyte)
Write() conforms to POSIX.1-2001 write()
static int Unlink(const char *path)
Unlink() conforms to POSIX.1-2001 unlink()
static int Access(const char *path, int amode)
Access() conforms to POSIX.1-2001 access()
XrdPosixXrootd(int maxfd=255, int maxdir=0, int maxthr=0)
static int Stat(const char *path, struct stat *buf)
Stat() conforms to POSIX.1-2001 stat()
static int Fsync(int fildes)
Fsync() conforms to POSIX.1-2001 fsync()
static bool OpenCache(XrdPosixFile &file, XrdPosixInfo &Info)
static int EcRename(const char *, const char *, XrdPosixAdmin *)
Definition: XrdOucIOVec.hh:65
static int Truncate(const char *path, off_t offset)
Telldir() conforms to POSIX.1-2001 telldir()
static bool myFD(int fd)
static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
Pwrite() conforms to POSIX.1-2001 pwrite()
An abstract class to define a callback for Open() call.
Definition: XrdPosixCallBack.hh:51
Definition: XrdOucIOVec.hh:40
static int Close(int fildes)
Close() conforms to POSIX.1-2001 close()
static int Fault(XrdPosixFile *fp, int ecode)
static int QueryChksum(const char *path, time_t &mtime, char *buff, int blen)
POSIX interface to XRootD with some extensions, as noted.
Definition: XrdPosixXrootd.hh:62
static int initDone
Definition: XrdPosixXrootd.hh:386
static bool isXrootdDir(DIR *dirp)
Extended POSIX interface to XRootD.
Definition: XrdPosixExtra.hh:46
static struct dirent * Readdir(DIR *dirp)
static int Statfs(const char *path, struct statfs *buf)
static void VRead(int fildes, const XrdOucIOVec *readV, int n, XrdPosixCallBackIO *cbp)
Definition: XrdPosixConfig.hh:46
static int Fstat(int fildes, struct stat *buf)
Fstat() conforms to POSIX.1-2001 fstat()
#define stat(a, b)
Definition: XrdPosix.hh:96
static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
static int Closedir(DIR *dirp)
Closedir() conforms to POSIX.1-2001 closedir()
static int endPoint(int FD, char *Buff, int Blen)
static void Rewinddir(DIR *dirp)
Rewinddir() conforms to POSIX.1-2001 rewinddir()
static struct dirent64 * Readdir64(DIR *dirp)
static int Rename(const char *oldpath, const char *newpath)
Rename() conforms to POSIX.1-2001 rename()
Definition: XrdPosixInfo.hh:39
Definition: XrdMacaroonsHandler.hh:18
static int Rmdir(const char *path)
Rmdir() conforms to POSIX.1-2001 rmdir()
Definition: XrdPosixCallBack.hh:75
#define statvfs(a, b)
Definition: XrdPosix.hh:100
static ssize_t Read(int fildes, void *buf, size_t nbyte)
Read() conforms to POSIX.1-2001 read()
static off_t Lseek(int fildes, off_t offset, int whence)
Lseek() conforms to POSIX.1-2001 lseek()
Definition: XrdPosixAdmin.hh:46
static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt)
Writev() conforms to POSIX.1-2001 writev()
static void Seekdir(DIR *dirp, long loc)
Seekdir() conforms to POSIX.1-2001 seekdir()
static int Mkdir(const char *path, mode_t mode)
Mkdir() conforms to POSIX.1-2001 mkdir()
static DIR * Opendir(const char *path)
Opendir() conforms to POSIX.1-2001 opendir()
static int Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)