XRootD
Loading...
Searching...
No Matches
XrdPosixDir.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d P o s i x D i r . c c */
4/* */
5/* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/* Modified by Frank Winklmeier to add the full Posix file system definition. */
30/******************************************************************************/
31
34
35/******************************************************************************/
36/* G l o b a l s */
37/******************************************************************************/
38
39namespace XrdPosixGlobals
40{
42};
43
44/******************************************************************************/
45/* n e x t E n t r y */
46/******************************************************************************/
47
48dirent64 *XrdPosixDir::nextEntry(dirent64 *dp)
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}
96
97/******************************************************************************/
98/* S t a t R e t */
99/******************************************************************************/
101{
102 myBuf = buf;
103 return 0;
104}
105
106/******************************************************************************/
107/* O p e n */
108/******************************************************************************/
109
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//
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}
#define stat(a, b)
Definition XrdPosix.hh:101
const std::string & GetName() const
Get file name.
uint32_t GetSize() const
Get the size of the listing.
ListEntry * At(uint32_t index)
Get an entry at given index.
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)
XrdCl::FileSystem Xrd
XrdCl::URL Url
int StatRet(struct stat *buf)
dirent64 * nextEntry(dirent64 *dp=0)
static const size_t maxDlen
static int Entry2Buf(const XrdCl::DirectoryList::ListEntry &dirEnt, struct stat &buf, XrdOucECMsg &ecMsg)
static int Result(const XrdCl::XRootDStatus &Status, XrdOucECMsg &ecMsg, bool retneg1=false)
XrdOucECMsg ecMsg
XrdCl::DirListFlags::Flags dlFlag