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
49
50struct XrdOucIOVec;
51
52class XrdScheduler;
53class XrdOucCache;
54class XrdOucCache2;
55class XrdOucEnv;
56class XrdOucName2Name;
57class XrdSysLogger;
60class XrdPosixFile;
61class XrdPosixInfo;
62
63//-----------------------------------------------------------------------------
65//-----------------------------------------------------------------------------
66
68{
69public:
70friend class XrdPosixConfig;
71
72//-----------------------------------------------------------------------------
74//-----------------------------------------------------------------------------
75
76static int Access(const char *path, int amode);
77
78//-----------------------------------------------------------------------------
80//-----------------------------------------------------------------------------
81
82static int Close(int fildes);
83
84//-----------------------------------------------------------------------------
86//-----------------------------------------------------------------------------
87
88static int Closedir(DIR *dirp);
89
90//-----------------------------------------------------------------------------
99//-----------------------------------------------------------------------------
100
101static int endPoint(int FD, char *Buff, int Blen);
102
103//-----------------------------------------------------------------------------
105//-----------------------------------------------------------------------------
106
107static int Fstat(int fildes, struct stat *buf);
108
109//-----------------------------------------------------------------------------
111//-----------------------------------------------------------------------------
112
113static int Fsync(int fildes);
114
115static void Fsync(int fildes, XrdPosixCallBackIO *cbp); // Async extension!
116
117//-----------------------------------------------------------------------------
119//-----------------------------------------------------------------------------
120
121static int Ftruncate(int fildes, off_t offset);
122
123//-----------------------------------------------------------------------------
141
142static long long Getxattr (const char *path, const char *name,
143 void *value, unsigned long long size);
144
145//-----------------------------------------------------------------------------
147//-----------------------------------------------------------------------------
148
149static off_t Lseek(int fildes, off_t offset, int whence);
150
151//-----------------------------------------------------------------------------
153//-----------------------------------------------------------------------------
154
155static int Mkdir(const char *path, mode_t mode);
156
157//-----------------------------------------------------------------------------
167//-----------------------------------------------------------------------------
168
169static const int isStream = 0x40000000; // Internal for Open oflag
170
171static int Open(const char *path, int oflag, mode_t mode=0,
172 XrdPosixCallBack *cbP=0);
173
174//-----------------------------------------------------------------------------
176//-----------------------------------------------------------------------------
177
178static DIR* Opendir(const char *path);
179
180//-----------------------------------------------------------------------------
182//-----------------------------------------------------------------------------
183
184static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset);
185
186static void Pread(int fildes, void *buf, size_t nbyte, off_t offset,
187 XrdPosixCallBackIO *cbp); // Async extension!
188
189//-----------------------------------------------------------------------------
191//-----------------------------------------------------------------------------
192
193static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
194
195static void Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset,
196 XrdPosixCallBackIO *cbp); // Async extension!
197
198//-----------------------------------------------------------------------------
209//-----------------------------------------------------------------------------
210
211static int QueryChksum(const char *path, time_t &mtime,
212 char *buff, int blen);
213
214//-----------------------------------------------------------------------------
224//-----------------------------------------------------------------------------
225
226static long long QueryOpaque(const char *path, char *buff, int blen);
227
228//-----------------------------------------------------------------------------
230//-----------------------------------------------------------------------------
231
232static ssize_t Read(int fildes, void *buf, size_t nbyte);
233
234//-----------------------------------------------------------------------------
236//-----------------------------------------------------------------------------
237
238static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt);
239
240//-----------------------------------------------------------------------------
244//-----------------------------------------------------------------------------
245
246static struct dirent* Readdir (DIR *dirp);
247static struct dirent64* Readdir64(DIR *dirp);
248
249//-----------------------------------------------------------------------------
253//-----------------------------------------------------------------------------
254
255static int Readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result);
256static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result);
257
258//-----------------------------------------------------------------------------
260//-----------------------------------------------------------------------------
261
262static int Rename(const char *oldpath, const char *newpath);
263
264//-----------------------------------------------------------------------------
266//-----------------------------------------------------------------------------
267
268static void Rewinddir(DIR *dirp);
269
270//-----------------------------------------------------------------------------
272//-----------------------------------------------------------------------------
273
274static int Rmdir(const char *path);
275
276//-----------------------------------------------------------------------------
278//-----------------------------------------------------------------------------
279
280static void Seekdir(DIR *dirp, long loc);
281
282//-----------------------------------------------------------------------------
284//-----------------------------------------------------------------------------
285
286static int Stat(const char *path, struct stat *buf);
287
288//-----------------------------------------------------------------------------
291//-----------------------------------------------------------------------------
292
293static int Statfs(const char *path, struct statfs *buf);
294
295//-----------------------------------------------------------------------------
297//-----------------------------------------------------------------------------
298
299static int Statvfs(const char *path, struct statvfs *buf);
300
301//-----------------------------------------------------------------------------
303//-----------------------------------------------------------------------------
304
305static long Telldir(DIR *dirp);
306
307//-----------------------------------------------------------------------------
309//-----------------------------------------------------------------------------
310
311static int Truncate(const char *path, off_t offset);
312
313//-----------------------------------------------------------------------------
315//-----------------------------------------------------------------------------
316
317static int Unlink(const char *path);
318
319//-----------------------------------------------------------------------------
332//-----------------------------------------------------------------------------
333
334static void VRead(int fildes, const XrdOucIOVec *readV, int n,
335 XrdPosixCallBackIO *cbp); // Async extension!
336
337static ssize_t VRead(int fildes, const XrdOucIOVec *readV, int n);
338
339//-----------------------------------------------------------------------------
341//-----------------------------------------------------------------------------
342
343static ssize_t Write(int fildes, const void *buf, size_t nbyte);
344
345//-----------------------------------------------------------------------------
347//-----------------------------------------------------------------------------
348
349static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt);
350
351//-----------------------------------------------------------------------------
354//-----------------------------------------------------------------------------
355
356inline int fdOrigin() {return baseFD;}
357
358static bool isXrootdDir(DIR *dirp);
359
360static bool myFD(int fd);
361
362/* There must be one instance of this object per executable image. Typically,
363 this object is declared in main() or at file level. This is necessary to
364 properly do one-time initialization of the static members. When declaring
365 this object, you can pass the following information:
366 maxfd - maximum number of simultaneous files and directories to support.
367 The value returned by getrlimit() over-rides the passed value
368 unless maxfd is negative. When negative, abs(maxfd) becomes the
369 absolute maximum and shadow file descriptors are not used.
370 maxdir - Ignored, only here for backward compatability.
371 maxthr - Ignored, only here for backward compatability.
372*/
373 XrdPosixXrootd(int maxfd=255, int maxdir=0, int maxthr=0);
375
376// The following methods were always considered private. They are no longer
377// used and will be removed on the next major release! They are only here for
378// now to keep ABI compatability for the 4.x and prior releases.
379//
380static void setCache(XrdOucCache *cP);
381static void setCache(XrdOucCache2 *cP);
382static void setDebug(int val, bool doDebug=false);
383static void setEnv(const char *kword, int kval);
384static void setIPV4(bool userv4);
385static void setLogger(XrdSysLogger *logP);
386static void setNumCB(int numcb);
387static void setN2N(XrdOucName2Name *pN2N, int opts=0);
388static void setSched(XrdScheduler *sP);
389
390private:
391
392static int Fault(XrdPosixFile *fp, int ecode);
393static void initStat(struct stat *buf);
394static void initXdev(dev_t &st_dev, dev_t &st_rdev);
395
396static int Open(const char *path, int oflag, mode_t mode,
397 XrdPosixCallBack *cbP, XrdPosixInfo *infoP);
399
400static int baseFD;
401static int initDone;
402};
403#endif
#define Info(lvl, where, what)
Definition: XrdClientDebug.hh:52
#define statvfs(a, b)
Definition: XrdPosix.hh:100
#define stat(a, b)
Definition: XrdPosix.hh:96
#define statfs(a, b)
Definition: XrdPosix.hh:98
Definition: XrdOucCache2.hh:197
Definition: XrdOucCache.hh:283
Definition: XrdOucEnv.hh:42
Definition: XrdOucName2Name.hh:49
Definition: XrdPosixCallBack.hh:76
An abstract class to define a callback for Open() call.
Definition: XrdPosixCallBack.hh:52
Definition: XrdPosixConfig.hh:44
Definition: XrdPosixFile.hh:60
POSIX interface to XRootD with some extensions, as noted.
Definition: XrdPosixXrootd.hh:68
static ssize_t Write(int fildes, const void *buf, size_t nbyte)
Write() conforms to POSIX.1-2001 write()
static void setNumCB(int numcb)
static void VRead(int fildes, const XrdOucIOVec *readV, int n, XrdPosixCallBackIO *cbp)
static void Rewinddir(DIR *dirp)
Rewinddir() conforms to POSIX.1-2001 rewinddir()
static int Fstat(int fildes, struct stat *buf)
Fstat() conforms to POSIX.1-2001 fstat()
static int Statvfs(const char *path, struct statvfs *buf)
Statvfs() conforms to POSIX.1-2001 statvfs()
static int QueryChksum(const char *path, time_t &mtime, char *buff, int blen)
static int Open(const char *path, int oflag, mode_t mode, XrdPosixCallBack *cbP, XrdPosixInfo *infoP)
static void setSched(XrdScheduler *sP)
static const int isStream
Definition: XrdPosixXrootd.hh:169
static int Fault(XrdPosixFile *fp, int ecode)
static int Rmdir(const char *path)
Rmdir() conforms to POSIX.1-2001 rmdir()
static int endPoint(int FD, char *Buff, int Blen)
static void initXdev(dev_t &st_dev, dev_t &st_rdev)
static int Readdir64_r(DIR *dirp, struct dirent64 *entry, struct dirent64 **result)
static int baseFD
Definition: XrdPosixXrootd.hh:400
static int Access(const char *path, int amode)
Access() conforms to POSIX.1-2001 access()
static int Fsync(int fildes)
Fsync() conforms to POSIX.1-2001 fsync()
static int Ftruncate(int fildes, off_t offset)
Ftruncate() conforms to POSIX.1-2001 ftruncate()
static int initDone
Definition: XrdPosixXrootd.hh:401
static int Statfs(const char *path, struct statfs *buf)
static void setCache(XrdOucCache *cP)
static struct dirent64 * Readdir64(DIR *dirp)
static ssize_t Writev(int fildes, const struct iovec *iov, int iovcnt)
Writev() conforms to POSIX.1-2001 writev()
static bool myFD(int fd)
static DIR * Opendir(const char *path)
Opendir() conforms to POSIX.1-2001 opendir()
static void Pread(int fildes, void *buf, size_t nbyte, off_t offset, XrdPosixCallBackIO *cbp)
static void setCache(XrdOucCache2 *cP)
static int Mkdir(const char *path, mode_t mode)
Mkdir() conforms to POSIX.1-2001 mkdir()
static int Readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
static int Close(int fildes)
Close() conforms to POSIX.1-2001 close()
static ssize_t Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
Pwrite() conforms to POSIX.1-2001 pwrite()
static bool OpenCache(XrdPosixFile &file, XrdPosixInfo &Info)
static ssize_t Readv(int fildes, const struct iovec *iov, int iovcnt)
Readv() conforms to POSIX.1-2001 readv()
static void initStat(struct stat *buf)
static bool isXrootdDir(DIR *dirp)
static off_t Lseek(int fildes, off_t offset, int whence)
Lseek() conforms to POSIX.1-2001 lseek()
static int Stat(const char *path, struct stat *buf)
Stat() conforms to POSIX.1-2001 stat()
static long long QueryOpaque(const char *path, char *buff, int blen)
static long long Getxattr(const char *path, const char *name, void *value, unsigned long long size)
XrdPosixXrootd(int maxfd=255, int maxdir=0, int maxthr=0)
static void setN2N(XrdOucName2Name *pN2N, int opts=0)
static ssize_t Pread(int fildes, void *buf, size_t nbyte, off_t offset)
Pread() conforms to POSIX.1-2001 pread()
static int Unlink(const char *path)
Unlink() conforms to POSIX.1-2001 unlink()
static long Telldir(DIR *dirp)
Telldir() conforms to POSIX.1-2001 telldir()
static void Pwrite(int fildes, const void *buf, size_t nbyte, off_t offset, XrdPosixCallBackIO *cbp)
static void setIPV4(bool userv4)
static ssize_t Read(int fildes, void *buf, size_t nbyte)
Read() conforms to POSIX.1-2001 read()
static void setEnv(const char *kword, int kval)
static void setLogger(XrdSysLogger *logP)
static void setDebug(int val, bool doDebug=false)
static ssize_t VRead(int fildes, const XrdOucIOVec *readV, int n)
static int Closedir(DIR *dirp)
Closedir() conforms to POSIX.1-2001 closedir()
static int Rename(const char *oldpath, const char *newpath)
Rename() conforms to POSIX.1-2001 rename()
static int Truncate(const char *path, off_t offset)
Telldir() conforms to POSIX.1-2001 telldir()
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
int fdOrigin()
Definition: XrdPosixXrootd.hh:356
static struct dirent * Readdir(DIR *dirp)
static void Seekdir(DIR *dirp, long loc)
Seekdir() conforms to POSIX.1-2001 seekdir()
static void Fsync(int fildes, XrdPosixCallBackIO *cbp)
Definition: XrdScheduler.hh:45
Definition: XrdSysLogger.hh:53
Definition: XrdOucIOVec.hh:41
Definition: XrdPosixInfo.hh:39