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 51 of file XrdPosixDir.hh.

Constructor & Destructor Documentation

◆ XrdPosixDir()

XrdPosixDir::XrdPosixDir ( const char *  path)
inline

Definition at line 54 of file XrdPosixDir.hh.

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

◆ ~XrdPosixDir()

XrdPosixDir::~XrdPosixDir ( )
inline

Definition at line 59 of file XrdPosixDir.hh.

59  {delete myDirVec;
60  if (myDirEnt) free(myDirEnt);
61  }

Member Function Documentation

◆ dirNo()

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

Definition at line 63 of file XrdPosixDir.hh.

63 {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 65 of file XrdPosixDir.hh.

65 { return numEnt;}

Referenced by XrdPosixXrootd::Seekdir().

+ Here is the caller graph for this function:

◆ getOffset()

long XrdPosixDir::getOffset ( )
inline

Definition at line 67 of file XrdPosixDir.hh.

67 { 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, ecMsg)))
90  {eNum = rc;
91  dp = nullptr;
92  }
93  nxtEnt++;
94  return dp;
95 }
const std::string & GetName() const
Get file name.
ListEntry * At(uint32_t index)
Get an entry at given index.
DIR * Open()
Definition: XrdPosixDir.cc:110
static const size_t maxDlen
Definition: XrdPosixDir.hh:92
static int Entry2Buf(const XrdCl::DirectoryList::ListEntry &dirEnt, struct stat &buf, XrdOucECMsg &ecMsg)
Definition: XrdPosixMap.cc:88

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

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 110 of file XrdPosixDir.cc.

111 {
112  static const size_t dEntSize = sizeof(dirent64) + maxDlen + 1;
113  int rc;
114 
115 // Allocate a local dirent. Note that we get additional padding because on
116 // some system the dirent structure does not include the name buffer
117 //
118  if (!myDirEnt && !(myDirEnt = (dirent64 *)malloc(dEntSize)))
119  {ecMsg.SetErrno(ENOMEM);
120  return (DIR*)0;
121  }
122 
123 // Get the directory list
124 //
125  rc = XrdPosixMap::Result(DAdmin.Xrd.DirList(DAdmin.Url.GetPathWithParams(),
127  myDirVec, (uint16_t)0),ecMsg);
128 
129 // If we failed, return a zero pointer ote that Result() set errno for us
130 //
131  if (rc) return (DIR *)0;
132 
133 // Finish up
134 //
135  numEnt = myDirVec->GetSize();
136  return (DIR *)&fdNum;
137 }
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
int SetErrno(int ecc, int ret=-1, const char *alt=0)
Definition: XrdOucECMsg.cc:152
XrdCl::FileSystem Xrd
XrdCl::URL Url
static int Result(const XrdCl::XRootDStatus &Status, XrdOucECMsg &ecMsg, bool retneg1=false)
Definition: XrdPosixMap.cc:188
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 80 of file XrdPosixDir.hh.

81  nxtEnt = 0; delete myDirVec; myDirVec = 0;
82  objMutex.UnLock();
83  }
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 69 of file XrdPosixDir.hh.

69 { nxtEnt = offset; }

Referenced by XrdPosixXrootd::Seekdir().

+ Here is the caller graph for this function:

◆ StatRet()

int XrdPosixDir::StatRet ( struct stat buf)

Definition at line 100 of file XrdPosixDir.cc.

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

◆ Status()

int XrdPosixDir::Status ( )
inline

Definition at line 84 of file XrdPosixDir.hh.

84 {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 86 of file XrdPosixDir.hh.

86 {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 90 of file XrdPosixDir.hh.

90 {*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 92 of file XrdPosixDir.hh.

Referenced by nextEntry(), and Open().


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