XRootD
XrdPosixDir Class Reference

#include <XrdPosixDir.hh>

+ Inheritance diagram for XrdPosixDir:
+ Collaboration diagram for XrdPosixDir:

Public Member Functions

 XrdPosixDir (const char *path)
 
 ~XrdPosixDir ()
 
long getEntries ()
 
long getOffset ()
 
dirent64 * nextEntry (dirent64 *dp=0)
 
DIR * Open ()
 
void rewind ()
 
void setOffset (long offset)
 
int StatRet (struct stat *buf)
 
int Status ()
 
bool Unread ()
 
virtual bool Who (XrdPosixDir **dirP)
 
bool Who (XrdPosixDir **dirP)
 
virtual bool Who (XrdPosixFile **fileP)
 
- Public Member Functions inherited from XrdPosixObject
 XrdPosixObject ()
 
virtual ~XrdPosixObject ()
 
bool AssignFD (bool isStream=false)
 
int FDNum ()
 
XrdOucECMsggetECMsg ()
 
void Lock (bool wr=true)
 
void Ref ()
 
int Refs ()
 
void UnLock ()
 
void unRef ()
 
virtual bool Who (XrdPosixFile **fileP)
 

Static Public Member Functions

static int dirNo (DIR *dirP)
 
- Static Public Member Functions inherited from XrdPosixObject
static bool CanStream ()
 
static XrdPosixDirDir (int fildes, bool glk=false)
 
static XrdPosixFileFile (int fildes, bool glk=false)
 
static int Init (int numfd)
 
static void Release (XrdPosixObject *oP, bool needlk=true)
 
static XrdPosixDirReleaseDir (int fildes)
 
static XrdPosixFileReleaseFile (int fildes)
 
static void Shutdown ()
 
static bool Valid (int fd)
 

Static Public Attributes

static const size_t maxDlen = 256
 

Additional Inherited Members

- Public Attributes inherited from XrdPosixObject
XrdOucECMsg ecMsg
 
- Protected Attributes inherited from XrdPosixObject
int fdNum
 
XrdSysRWLock objMutex
 
int refCnt
 
XrdSysRecMutex updMutex
 

Detailed Description

Definition at line 49 of file XrdPosixDir.hh.

Constructor & Destructor Documentation

◆ XrdPosixDir()

XrdPosixDir::XrdPosixDir ( const char *  path)
inline

Definition at line 52 of file XrdPosixDir.hh.

53  : DAdmin(path,ecMsg), myDirVec(0), myDirEnt(0),
54  myBuf(nullptr), nxtEnt(0), numEnt(0), eNum(0)
55  {}
XrdOucECMsg ecMsg

◆ ~XrdPosixDir()

XrdPosixDir::~XrdPosixDir ( )
inline

Definition at line 57 of file XrdPosixDir.hh.

57  {delete myDirVec;
58  if (myDirEnt) free(myDirEnt);
59  }

Member Function Documentation

◆ dirNo()

static int XrdPosixDir::dirNo ( DIR *  dirP)
inlinestatic

Definition at line 61 of file XrdPosixDir.hh.

61 {return *(int *)dirP;}

Referenced by XrdPosixXrootd::Closedir(), XrdPosixXrootd::isXrootdDir(), XrdPosixXrootd::QueryError(), XrdPosixXrootd::Readdir64(), XrdPosixXrootd::Readdir64_r(), XrdPosixXrootd::Rewinddir(), XrdPosixXrootd::Seekdir(), XrdPosixXrootd::StatRet(), and XrdPosixXrootd::Telldir().

+ Here is the caller graph for this function:

◆ getEntries()

long XrdPosixDir::getEntries ( )
inline

Definition at line 63 of file XrdPosixDir.hh.

63 { return numEnt;}

Referenced by XrdPosixXrootd::Seekdir().

+ Here is the caller graph for this function:

◆ getOffset()

long XrdPosixDir::getOffset ( )
inline

Definition at line 65 of file XrdPosixDir.hh.

65 { return nxtEnt; }

Referenced by XrdPosixXrootd::Telldir().

+ Here is the caller graph for this function:

◆ nextEntry()

dirent64 * XrdPosixDir::nextEntry ( dirent64 *  dp = 0)

Definition at line 48 of file XrdPosixDir.cc.

49 {
51  const char *d_name;
52  const int dirhdrln = dp->d_name - (char *)dp;
53  size_t d_nlen;
54 
55 // Reread the directory if we need to (rewind forces this)
56 //
57  if (!myDirVec && !Open()) {eNum = errno; return 0;} // Open() sets ecMsg
58 
59 // Check if dir is empty or all entries have been read
60 //
61  if (nxtEnt >= numEnt) {eNum = 0; return 0;}
62 
63 // Get information about the next entry
64 //
65  dirEnt = myDirVec->At(nxtEnt);
66  d_name = dirEnt->GetName().c_str();
67  d_nlen = dirEnt->GetName().length();
68 
69 // Create a directory entry
70 //
71  if (!dp) dp = myDirEnt;
72  if (d_nlen > maxDlen) d_nlen = maxDlen;
73 #ifndef __solaris__
74  dp->d_type = DT_UNKNOWN;
75 #endif
76 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
77  dp->d_fileno = nxtEnt;
78  dp->d_namlen = d_nlen;
79 #else
80  dp->d_ino = nxtEnt+1;
81  dp->d_off = nxtEnt;
82 #endif
83  dp->d_reclen = d_nlen + dirhdrln;
84  strncpy(dp->d_name, d_name, d_nlen);
85  dp->d_name[d_nlen] = '\0';
86 
87  // Note we fail if the stat info is needed but not available
88  int rc;
89  if (myBuf && (rc = XrdPosixMap::Entry2Buf(*dirEnt, *myBuf)))
90  {eNum = rc;
91  ecMsg.SetErrno(eNum);
92  dp = nullptr;
93  }
94  nxtEnt++;
95  return dp;
96 }
const std::string & GetName() const
Get file name.
ListEntry * At(uint32_t index)
Get an entry at given index.
int SetErrno(int ecc, int retval=-1, const char *alt=0)
Definition: XrdOucECMsg.cc:144
DIR * Open()
Definition: XrdPosixDir.cc:111
static const size_t maxDlen
Definition: XrdPosixDir.hh:90
static int Entry2Buf(const XrdCl::DirectoryList::ListEntry &dirEnt, struct stat &buf)
Definition: XrdPosixMap.cc:88

References XrdCl::DirectoryList::At(), XrdPosixObject::ecMsg, XrdPosixMap::Entry2Buf(), XrdCl::DirectoryList::ListEntry::GetName(), maxDlen, Open(), and XrdOucECMsg::SetErrno().

Referenced by XrdPosixXrootd::Readdir64(), and XrdPosixXrootd::Readdir64_r().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Open()

DIR * XrdPosixDir::Open ( )

Definition at line 111 of file XrdPosixDir.cc.

112 {
113  static const size_t dEntSize = sizeof(dirent64) + maxDlen + 1;
114  int rc;
115 
116 // Allocate a local dirent. Note that we get additional padding because on
117 // some system the dirent structure does not include the name buffer
118 //
119  if (!myDirEnt && !(myDirEnt = (dirent64 *)malloc(dEntSize)))
120  {ecMsg.SetErrno(ENOMEM);
121  return (DIR*)0;
122  }
123 
124 // Get the directory list
125 //
126  rc = XrdPosixMap::Result(DAdmin.Xrd.DirList(DAdmin.Url.GetPathWithParams(),
128  myDirVec, (uint16_t)0),ecMsg);
129 
130 // If we failed, return a zero pointer ote that Result() set errno for us
131 //
132  if (rc) return (DIR *)0;
133 
134 // Finish up
135 //
136  numEnt = myDirVec->GetSize();
137  return (DIR *)&fdNum;
138 }
uint32_t GetSize() const
Get the size of the listing.
XRootDStatus DirList(const std::string &path, DirListFlags::Flags flags, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
std::string GetPathWithParams() const
Get the path with params.
Definition: XrdClURL.cc:318
XrdCl::FileSystem Xrd
XrdCl::URL Url
static int Result(const XrdCl::XRootDStatus &Status, XrdOucECMsg &ecMsg, bool retneg1=false)
Definition: XrdPosixMap.cc:185
XrdCl::DirListFlags::Flags dlFlag
Definition: XrdPosixDir.cc:41

References XrdCl::FileSystem::DirList(), XrdPosixGlobals::dlFlag, XrdPosixObject::ecMsg, XrdPosixObject::fdNum, XrdCl::URL::GetPathWithParams(), XrdCl::DirectoryList::GetSize(), maxDlen, XrdPosixMap::Result(), XrdOucECMsg::SetErrno(), XrdPosixAdmin::Url, and XrdPosixAdmin::Xrd.

Referenced by nextEntry(), XrdPosixXrootd::Opendir(), and XrdPosixXrootd::Seekdir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rewind()

void XrdPosixDir::rewind ( )
inline

Definition at line 78 of file XrdPosixDir.hh.

79  nxtEnt = 0; delete myDirVec; myDirVec = 0;
80  objMutex.UnLock();
81  }
XrdSysRWLock objMutex

References XrdPosixObject::objMutex, XrdSysRWLock::UnLock(), and XrdSysRWLock::WriteLock().

Referenced by XrdPosixXrootd::Rewinddir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setOffset()

void XrdPosixDir::setOffset ( long  offset)
inline

Definition at line 67 of file XrdPosixDir.hh.

67 { nxtEnt = offset; }

Referenced by XrdPosixXrootd::Seekdir().

+ Here is the caller graph for this function:

◆ StatRet()

int XrdPosixDir::StatRet ( struct stat buf)

Definition at line 101 of file XrdPosixDir.cc.

102 {
103  myBuf = buf;
104  return 0;
105 }

◆ Status()

int XrdPosixDir::Status ( )
inline

Definition at line 82 of file XrdPosixDir.hh.

82 {return eNum;}

Referenced by XrdPosixXrootd::Readdir64(), and XrdPosixXrootd::Readdir64_r().

+ Here is the caller graph for this function:

◆ Unread()

bool XrdPosixDir::Unread ( )
inline

Definition at line 84 of file XrdPosixDir.hh.

84 {return myDirVec == 0;}

Referenced by XrdPosixXrootd::Seekdir().

+ Here is the caller graph for this function:

◆ Who() [1/3]

virtual bool XrdPosixObject::Who
inline

Definition at line 89 of file XrdPosixObject.hh.

89 {return false;}

◆ Who() [2/3]

bool XrdPosixDir::Who ( XrdPosixDir **  dirP)
inlinevirtual

Reimplemented from XrdPosixObject.

Definition at line 88 of file XrdPosixDir.hh.

88 {*dirP = this; return true;}

◆ Who() [3/3]

virtual bool XrdPosixObject::Who
inline

Definition at line 91 of file XrdPosixObject.hh.

91 {return false;}

Member Data Documentation

◆ maxDlen

const size_t XrdPosixDir::maxDlen = 256
static

Definition at line 90 of file XrdPosixDir.hh.

Referenced by nextEntry(), and Open().


The documentation for this class was generated from the following files: