XRootD
XrdPosixDir.hh
Go to the documentation of this file.
1 #ifndef __XRDPOSIXDIR_H__
2 #define __XRDPOSIXDIR_H__
3 /******************************************************************************/
4 /* */
5 /* X r d P o s i x D i r . h h */
6 /* */
7 /* (c) 2013 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 
36 #if defined(__APPLE__) || defined(__FreeBSD__)
37 #if !defined(dirent64)
38 #define dirent64 dirent
39 #endif
40 #endif
41 
42 #include <unistd.h>
43 #include <sys/stat.h>
44 #include <sys/types.h>
45 
48 
50 {
51 public:
52  XrdPosixDir(const char *path)
53  : DAdmin(path,ecMsg), myDirVec(0), myDirEnt(0),
54  myBuf(nullptr), nxtEnt(0), numEnt(0), eNum(0)
55  {}
56 
57  ~XrdPosixDir() {delete myDirVec;
58  if (myDirEnt) free(myDirEnt);
59  }
60 
61 static int dirNo(DIR *dirP) {return *(int *)dirP;}
62 
63  long getEntries() { return numEnt;}
64 
65  long getOffset() { return nxtEnt; }
66 
67  void setOffset(long offset) { nxtEnt = offset; }
68 
69  dirent64 *nextEntry(dirent64 *dp=0);
70 
71  DIR *Open();
72 
73  // Return the stat info corresponding to the current directory entry
74  // On error, returns -errno; otherwise, returns 0 and stores a reference
75  // to buf internally
76  int StatRet(struct stat *buf);
77 
79  nxtEnt = 0; delete myDirVec; myDirVec = 0;
80  objMutex.UnLock();
81  }
82  int Status() {return eNum;}
83 
84  bool Unread() {return myDirVec == 0;}
85 
86  using XrdPosixObject::Who;
87 
88  bool Who(XrdPosixDir **dirP) {*dirP = this; return true;}
89 
90 static const size_t maxDlen = 256;
91 
92 private:
93  XrdPosixAdmin DAdmin;
94  XrdCl::DirectoryList *myDirVec;
95  dirent64 *myDirEnt;
96  struct stat *myBuf;
97  uint32_t nxtEnt;
98  uint32_t numEnt;
99  int eNum;
100 };
101 #endif
int stat(const char *path, struct stat *buf)
XrdPosixDir(const char *path)
Definition: XrdPosixDir.hh:52
int StatRet(struct stat *buf)
Definition: XrdPosixDir.cc:101
static int dirNo(DIR *dirP)
Definition: XrdPosixDir.hh:61
void rewind()
Definition: XrdPosixDir.hh:78
long getOffset()
Definition: XrdPosixDir.hh:65
DIR * Open()
Definition: XrdPosixDir.cc:111
bool Unread()
Definition: XrdPosixDir.hh:84
dirent64 * nextEntry(dirent64 *dp=0)
Definition: XrdPosixDir.cc:48
void setOffset(long offset)
Definition: XrdPosixDir.hh:67
int Status()
Definition: XrdPosixDir.hh:82
long getEntries()
Definition: XrdPosixDir.hh:63
static const size_t maxDlen
Definition: XrdPosixDir.hh:90
bool Who(XrdPosixDir **dirP)
Definition: XrdPosixDir.hh:88
XrdSysRWLock objMutex
virtual bool Who(XrdPosixDir **dirP)
XrdOucECMsg ecMsg