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 <string>
35 #include <dirent.h>
36 #include <unistd.h>
37 #include <sys/stat.h>
38 #include <sys/statvfs.h>
39 #include <sys/types.h>
40 
41 #if defined(__APPLE__) || defined(__FreeBSD__)
42 #include <sys/param.h>
43 #include <sys/mount.h>
44 #else
45 #include <sys/statfs.h>
46 #endif
47 
49 #include "XrdSys/XrdSysPthread.hh"
50 
51 struct XrdOucIOVec;
52 
53 class XrdPosixCallBack;
54 class XrdPosixCallBackIO;
55 class XrdPosixFile;
56 struct XrdPosixInfo;
57 class XrdPosixAdmin;
58 
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
62 
64 {
65 public:
66 friend class XrdPosixConfig;
67 friend class XrdPosixExtra;
68 
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
72 
73 static int Access(const char *path, int amode);
74 
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
78 
79 static int Close(int fildes);
80 
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
84 
85 static int Closedir(DIR *dirp);
86 
87 //-----------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------
97 
98 static int endPoint(int FD, char *Buff, int Blen);
99 
100 
101 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
114 
115 enum class Fcop { QFInfo };
116 
117 static int Fcntl(int fildes, Fcop op, const std::string& args,
118  std::string& resp);
119 
120 //-----------------------------------------------------------------------------
122 //-----------------------------------------------------------------------------
123 
124 static int Fstat(int fildes, struct stat *buf);
125 
126 //-----------------------------------------------------------------------------
128 //-----------------------------------------------------------------------------
129 
130 static int Fsync(int fildes);
131 
132 static void Fsync(int fildes, XrdPosixCallBackIO *cbp); // Async extension!
133 
134 //-----------------------------------------------------------------------------
136 //-----------------------------------------------------------------------------
137 
138 static int Ftruncate(int fildes, off_t offset);
139 
140 //-----------------------------------------------------------------------------
158 
159 static long long Getxattr (const char *path, const char *name,
160  void *value, unsigned long long size);
161 
162 //-----------------------------------------------------------------------------
164 //-----------------------------------------------------------------------------
165 
166 static off_t Lseek(int fildes, off_t offset, int whence);
167 
168 //-----------------------------------------------------------------------------
170 //-----------------------------------------------------------------------------
171 
172 static int Mkdir(const char *path, mode_t mode);
173 
174 //-----------------------------------------------------------------------------
184 //-----------------------------------------------------------------------------
185 
186 static const int isStream = 0x40000000; // Internal for Open oflag
187 
188 static int Open(const char *path, int oflag, mode_t mode=0,
189  XrdPosixCallBack *cbP=0);
190 
191 //-----------------------------------------------------------------------------
193 //-----------------------------------------------------------------------------
194 
195 static DIR* Opendir(const char *path);
196 
197 //-----------------------------------------------------------------------------
199 //-----------------------------------------------------------------------------
200 
201 static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset);
202 
203 static void Pread(int fildes, void *buf, size_t nbyte, off_t offset,
204  XrdPosixCallBackIO *cbp); // Async extension!
205 
206 //-----------------------------------------------------------------------------
208 //-----------------------------------------------------------------------------
209 
210 static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
211 
212 static void Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset,
213  XrdPosixCallBackIO *cbp); // Async extension!
214 
215 //-----------------------------------------------------------------------------
226 //-----------------------------------------------------------------------------
227 
228 static int QueryChksum(const char *path, time_t &mtime,
229  char *buff, int blen);
230 
231 //-----------------------------------------------------------------------------
246 //-----------------------------------------------------------------------------
247 
248 static int QueryError(std::string& emsg, int fd=-1, bool reset=true);
249 
250 static int QueryError(std::string& emsg, DIR* dirP, bool reset=true);
251 
252 //-----------------------------------------------------------------------------
262 //-----------------------------------------------------------------------------
263 
264 static long long QueryOpaque(const char *path, char *buff, int blen);
265 
266 //-----------------------------------------------------------------------------
268 //-----------------------------------------------------------------------------
269 
270 static ssize_t Read(int fildes, void *buf, size_t nbyte);
271 
272 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
275 
276 static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt);
277 
278 //-----------------------------------------------------------------------------
282 //-----------------------------------------------------------------------------
283 
284 static struct dirent* Readdir (DIR *dirp);
285 static struct dirent64* Readdir64(DIR *dirp);
286 
287 //-----------------------------------------------------------------------------
291 //-----------------------------------------------------------------------------
292 
293 static int Readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result);
294 static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result);
295 
296 //-----------------------------------------------------------------------------
298 //-----------------------------------------------------------------------------
299 
300 static int Rename(const char *oldpath, const char *newpath);
301 
302 //-----------------------------------------------------------------------------
304 //-----------------------------------------------------------------------------
305 
306 static void Rewinddir(DIR *dirp);
307 
308 //-----------------------------------------------------------------------------
310 //-----------------------------------------------------------------------------
311 
312 static int Rmdir(const char *path);
313 
314 //-----------------------------------------------------------------------------
316 //-----------------------------------------------------------------------------
317 
318 static void Seekdir(DIR *dirp, long loc);
319 
320 //-----------------------------------------------------------------------------
322 //-----------------------------------------------------------------------------
323 
324 static int Stat(const char *path, struct stat *buf);
325 
326 //-----------------------------------------------------------------------------
329 //-----------------------------------------------------------------------------
330 
331 static int Statfs(const char *path, struct statfs *buf);
332 
333 //-----------------------------------------------------------------------------
335 //-----------------------------------------------------------------------------
336 
337 static int Statvfs(const char *path, struct statvfs *buf);
338 
339 //-----------------------------------------------------------------------------
341 //-----------------------------------------------------------------------------
342 
343 static long Telldir(DIR *dirp);
344 
345 //-----------------------------------------------------------------------------
347 //-----------------------------------------------------------------------------
348 
349 static int Truncate(const char *path, off_t offset);
350 
351 //-----------------------------------------------------------------------------
353 //-----------------------------------------------------------------------------
354 
355 static int Unlink(const char *path);
356 
357 //-----------------------------------------------------------------------------
367 //-----------------------------------------------------------------------------
368 
369 static void VRead(int fildes, const XrdOucIOVec *readV, int n,
370  XrdPosixCallBackIO *cbp); // Async extension!
371 
372 static ssize_t VRead(int fildes, const XrdOucIOVec *readV, int n);
373 
374 //-----------------------------------------------------------------------------
376 //-----------------------------------------------------------------------------
377 
378 static ssize_t Write(int fildes, const void *buf, size_t nbyte);
379 
380 //-----------------------------------------------------------------------------
382 //-----------------------------------------------------------------------------
383 
384 static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt);
385 
386 //-----------------------------------------------------------------------------
389 //-----------------------------------------------------------------------------
390 
391 inline int fdOrigin() {return baseFD;}
392 
393 static bool isXrootdDir(DIR *dirp);
394 
395 static bool myFD(int fd);
396 
397 // The XRootD client will fetch the information needed for a full `stat` call
398 // as part of the directory listing. By calling this function from XrdPss
399 // layer, we enable the use of the `autoStat` functionality, which avoids
400 // having to call `stat` for each entry in the directory listing.
401 //
402 // On error, returns errno; on success, returns 0 and stores the buffer
403 // internally; on subsequent Readdir calls, the `buf` contents are filled in
404 // as if one called `fstatat` on it.
405 //
406 // Note that this matches other XrdPosixXrootd methods in returning errno on
407 // failure; this differs from the similar XrdOss method which returns -errno.
408 static int StatRet(DIR *dirp, struct stat *buf);
409 
410 /* There must be one instance of this object per executable image. Typically,
411  this object is declared in main() or at file level. This is necessary to
412  properly do one-time initialization of the static members. When declaring
413  this object, you can pass the following information:
414  maxfd - maximum number of simultaneous files and directories to support.
415  The value returned by getrlimit() over-rides the passed value
416  unless maxfd is negative. When negative, abs(maxfd) becomes the
417  absolute maximum and shadow file descriptors are not used.
418  maxdir - Ignored, only here for backward compatibility.
419  maxthr - Ignored, only here for backward compatibility.
420 */
421  XrdPosixXrootd(int maxfd=255, int maxdir=0, int maxthr=0);
422  ~XrdPosixXrootd();
423 
424 private:
425 
426 static int Fault(XrdPosixFile *fp, int ecode, const char *msg=0);
427 
428 static int Open(const char *path, int oflag, mode_t mode,
429  XrdPosixCallBack *cbP, XrdPosixInfo *infoP);
430 static bool OpenCache(XrdPosixFile &file, XrdPosixInfo &Info);
431 
432 // functions that will be used when XrdEC is invoked
433 static int EcRename(const char*, const char*, XrdPosixAdmin&);
434 static int EcStat(const char*, struct stat*, XrdPosixAdmin&);
435 static int EcUnlink(const char*, XrdPosixAdmin&);
436 
437 static int baseFD;
438 static int initDone;
439 };
440 #endif
#define statvfs(a, b)
Definition: XrdPosix.hh:135
#define stat(a, b)
Definition: XrdPosix.hh:105
#define statfs(a, b)
Definition: XrdPosix.hh:111
int emsg(int rc, char *msg)
An abstract class to define a callback for Open() call.
Extended POSIX interface to XRootD.
POSIX interface to XRootD with some extensions, as noted.
static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt)
Readv() conforms to POSIX.1-2001 readv()
static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset)
Pread() conforms to POSIX.1-2001 pread()
static int Closedir(DIR *dirp)
Closedir() conforms to POSIX.1-2001 closedir()
static void Seekdir(DIR *dirp, long loc)
Seekdir() conforms to POSIX.1-2001 seekdir()
static const int isStream
static int Stat(const char *path, struct stat *buf)
Stat() conforms to POSIX.1-2001 stat()
static int QueryChksum(const char *path, time_t &mtime, char *buff, int blen)
static int Mkdir(const char *path, mode_t mode)
Mkdir() conforms to POSIX.1-2001 mkdir()
static int Unlink(const char *path)
Unlink() conforms to POSIX.1-2001 unlink()
static int Rmdir(const char *path)
Rmdir() conforms to POSIX.1-2001 rmdir()
static void Rewinddir(DIR *dirp)
Rewinddir() conforms to POSIX.1-2001 rewinddir()
static void VRead(int fildes, const XrdOucIOVec *readV, int n, XrdPosixCallBackIO *cbp)
static int Rename(const char *oldpath, const char *newpath)
Rename() conforms to POSIX.1-2001 rename()
static int Close(int fildes)
Close() conforms to POSIX.1-2001 close()
static int Statvfs(const char *path, struct statvfs *buf)
Statvfs() conforms to POSIX.1-2001 statvfs()
static int Fcntl(int fildes, Fcop op, const std::string &args, std::string &resp)
static int endPoint(int FD, char *Buff, int Blen)
static ssize_t Write(int fildes, const void *buf, size_t nbyte)
Write() conforms to POSIX.1-2001 write()
static struct dirent * Readdir(DIR *dirp)
static int Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt)
Writev() conforms to POSIX.1-2001 writev()
static int QueryError(std::string &emsg, int fd=-1, bool reset=true)
static struct dirent64 * Readdir64(DIR *dirp)
XrdPosixXrootd(int maxfd=255, int maxdir=0, int maxthr=0)
static bool myFD(int fd)
static int Ftruncate(int fildes, off_t offset)
Ftruncate() conforms to POSIX.1-2001 ftruncate()
static long Telldir(DIR *dirp)
Telldir() conforms to POSIX.1-2001 telldir()
static bool isXrootdDir(DIR *dirp)
static int Access(const char *path, int amode)
Access() conforms to POSIX.1-2001 access()
static DIR * Opendir(const char *path)
Opendir() conforms to POSIX.1-2001 opendir()
static int Fsync(int fildes)
Fsync() conforms to POSIX.1-2001 fsync()
static int StatRet(DIR *dirp, struct stat *buf)
static long long Getxattr(const char *path, const char *name, void *value, unsigned long long size)
static long long QueryOpaque(const char *path, char *buff, int blen)
static int Statfs(const char *path, struct statfs *buf)
static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
static ssize_t Read(int fildes, void *buf, size_t nbyte)
Read() conforms to POSIX.1-2001 read()
static int Fstat(int fildes, struct stat *buf)
Fstat() conforms to POSIX.1-2001 fstat()
static off_t Lseek(int fildes, off_t offset, int whence)
Lseek() conforms to POSIX.1-2001 lseek()
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
Pwrite() conforms to POSIX.1-2001 pwrite()
static int Truncate(const char *path, off_t offset)
Telldir() conforms to POSIX.1-2001 telldir()