XRootD
Loading...
Searching...
No Matches
XrdOssAt.cc File Reference
#include <cerrno>
#include <fcntl.h>
#include <string>
#include <sys/param.h>
#include <sys/stat.h>
#include "XrdOss/XrdOss.hh"
#include "XrdOss/XrdOssApi.hh"
#include "XrdOss/XrdOssAt.hh"
#include "XrdOss/XrdOssCache.hh"
#include "XrdOss/XrdOssError.hh"
#include "XrdOss/XrdOssPath.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysFD.hh"
#include "XrdSys/XrdSysPlatform.hh"
+ Include dependency graph for XrdOssAt.cc:

Go to the source code of this file.

Macros

#define BOILER_PLATE(dfObj, fd)   return -ENOTSUP;
 
#define OPEN_AT(dst, dfd, p, f)
 

Variables

XrdSysError OssEroute
 

Macro Definition Documentation

◆ BOILER_PLATE

#define BOILER_PLATE (   dfObj,
  fd 
)    return -ENOTSUP;

Definition at line 66 of file XrdOssAt.cc.

◆ OPEN_AT

#define OPEN_AT (   dst,
  dfd,
  p,
 
)
Value:
dst = openat(dfd, p, f); \
if (dst >= 0) fcntl(dst, F_SETFD, FD_CLOEXEC);\
else return -errno
int fcntl(int fd, int cmd,...)

Definition at line 76 of file XrdOssAt.cc.

83{
84class openHelper
85 {public:
86 int FD;
87 openHelper() : FD(-1) {}
88 ~openHelper() {if (FD >= 0) close(FD);}
89 };
90}
91
92/******************************************************************************/
93/* O p e n d i r */
94/******************************************************************************/
95
96int XrdOssAt::Opendir(XrdOssDF &atDir, const char *path, XrdOucEnv &env,
97 XrdOssDF *&ossDF)
98{
99 openHelper hOpen;
100 DIR *dirP;
101 int dirFD;
102
103// Standard boilerplate
104//
105 BOILER_PLATE(dirFD, atDir);
106
107// Open the target
108//
109 OPEN_AT(hOpen.FD, dirFD, path, O_RDONLY);
110
111// Create a new dir entry from this FD
112//
113 dirP = fdopendir(hOpen.FD);
114 if (!dirP) return (errno ? -errno : -ENOMSG);
115
116// Finally return a new directory object
117//
118 ossDF = new XrdOssDir(atDir.getTID(), dirP);
119 hOpen.FD = -1;
120 return 0;
121}
122
123/******************************************************************************/
124/* O p e n R O */
125/******************************************************************************/
126
127int XrdOssAt::OpenRO(XrdOssDF &atDir, const char *path, XrdOucEnv &env,
128 XrdOssDF *&ossDF)
129{
130 openHelper hOpen;
131 int dirFD;
132
133// Standard boilerplate
134//
135 BOILER_PLATE(dirFD, atDir);
136
137// Open the target
138//
139 OPEN_AT(hOpen.FD, dirFD, path, O_RDONLY);
140
141// Return a new file object
142//
143 ossDF = new XrdOssFile(atDir.getTID(), hOpen.FD);
144 hOpen.FD = -1;
145 return 0;
146}
147
148/******************************************************************************/
149/* R e m d i r */
150/******************************************************************************/
151
152int XrdOssAt::Remdir(XrdOssDF &atDir, const char *path)
153{
154 int dirFD;
155
156// Standard boilerplate
157//
158 BOILER_PLATE(dirFD, atDir);
159
160// Effect the removal
161//
162 if (unlinkat(dirFD, path, AT_REMOVEDIR)) return -errno;
163
164// All done
165//
166 return 0;
167}
168
169/******************************************************************************/
170/* S t a t */
171/******************************************************************************/
172
173int XrdOssAt::Stat(XrdOssDF &atDir, const char *path, struct stat &buf,
174 int opts)
175{
176 int dirFD;
177
178// Standard boilerplate
179//
180 BOILER_PLATE(dirFD, atDir);
181
182// Do the stat call
183//
184 if (fstatat(dirFD, path, &buf, 0)) return -errno;
185
186// Check if we need to provide dev info
187//
189
190// All done
191//
192 return 0;
193}
194
195/******************************************************************************/
196/* U n l i n k */
197/******************************************************************************/
198
199int XrdOssAt::Unlink(XrdOssDF &atDir, const char *path)
200{
201 struct stat Stat;
202 int dirFD;
203
204// Standard boilerplate
205//
206 BOILER_PLATE(dirFD, atDir);
207
208// This could be a symlink or an actual file but not a directory.
209//
210 if (fstatat(dirFD, path, &Stat, AT_SYMLINK_NOFOLLOW))
211 return (errno == ENOENT ? 0 : -errno);
212 if ((Stat.st_mode & S_IFMT) == S_IFDIR) return -EISDIR;
213
214// If this is not a symlink then we can delete it directly
215//
216 if ((Stat.st_mode & S_IFMT) != S_IFLNK)
217 {if (unlinkat(dirFD, path, 0)) return -errno;
218 if (Stat.st_size)
219 XrdOssCache::Adjust(Stat.st_dev, -Stat.st_size);
220 return 0;
221 }
222
223// Get the target of this link
224//
225 char lnkbuff[MAXPATHLEN+64];
226 int lnklen, retc;
227 if ((lnklen = readlinkat(dirFD, path, lnkbuff, sizeof(lnkbuff)-1)) < 0)
228 return -errno;
229
230// If the underlying file exists, remove it
231//
232 lnkbuff[lnklen] = '\0';
233 if (stat(lnkbuff, &Stat)) Stat.st_size = 0;
234 else if (unlink(lnkbuff) && errno != ENOENT)
235 {retc = -errno;
236 OssEroute.Emsg("Unlink",retc,"unlink symlink target",lnkbuff);
237 return -retc;
238 }
239
240// Adjust the size based on what kind of data cache we are using.
241//
242 if (Stat.st_size)
243 {char *lP = lnkbuff+lnklen-1;
244 if (*lP == XrdOssPath::xChar)
246 XrdOssCache::Adjust(lnkbuff, -Stat.st_size);
247 }
248 else XrdOssCache::Adjust(Stat.st_dev, -Stat.st_size);
249 }
250
251// Effect the removal of the actual symlink
252//
253 if (unlinkat(dirFD, path, 0)) return -errno;
254
255// All done
256//
257 return 0;
258}
struct stat Stat
Definition XrdCks.cc:49
XrdSysError OssEroute
#define BOILER_PLATE(dfObj, fd)
Definition XrdOssAt.cc:66
#define OPEN_AT(dst, dfd, p, f)
Definition XrdOssAt.cc:76
#define close(a)
Definition XrdPosix.hh:48
#define unlink(a)
Definition XrdPosix.hh:113
#define stat(a, b)
Definition XrdPosix.hh:101
struct myOpts opts
int OpenRO(XrdOssDF &atDir, const char *path, XrdOucEnv &env, XrdOssDF *&ossDF)
Definition XrdOssAt.cc:127
int Opendir(XrdOssDF &atDir, const char *path, XrdOucEnv &env, XrdOssDF *&ossDF)
Definition XrdOssAt.cc:96
static const int At_dInfo
Definition XrdOssAt.hh:117
int Unlink(XrdOssDF &atDir, const char *path)
Definition XrdOssAt.cc:199
int Stat(XrdOssDF &atDir, const char *path, struct stat &buf, int opts=0)
Definition XrdOssAt.cc:173
int Remdir(XrdOssDF &atDir, const char *path)
Definition XrdOssAt.cc:152
static void DevInfo(struct stat &buf, bool limits=false)
static void Adjust(dev_t devid, off_t size)
virtual const char * getTID()
Definition XrdOss.hh:434
static void Trim2Base(char *eP)
static const char xChar
Definition XrdOssPath.hh:47
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)

Variable Documentation

◆ OssEroute

XrdSysError OssEroute
extern