XRootD
Loading...
Searching...
No Matches
XrdOssArcDir.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d O s s A r c D i r . c c */
4/* */
5/* (c) 2025 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/******************************************************************************/
30
31#include <fcntl.h>
32#include <unistd.h>
33#include <sys/stat.h>
34#include <sys/types.h>
35
40
41#include "XrdOuc/XrdOucEnv.hh"
42#include "XrdOuc/XrdOucECMsg.hh"
43
44#include "XrdSys/XrdSysError.hh"
45#include "XrdSys/XrdSysFD.hh"
47
48/******************************************************************************/
49/* G l o b a l O b j e c t s */
50/******************************************************************************/
51
52namespace XrdOssArcGlobals
53{
54extern XrdSysError Elog;
55
56extern XrdSysTrace ArcTrace;
57
58extern thread_local XrdOucECMsg ecMsg;
59}
60using namespace XrdOssArcGlobals;
61
62#define Neg(x) (x > 0 ? -x : x)
63
64/******************************************************************************/
65/* D e s t r u c t o r */
66/******************************************************************************/
67
69{ delete ossDF;
70 if (zFile) delete zFile;
71}
72
73/******************************************************************************/
74/* C l o s e */
75/******************************************************************************/
76
77int XrdOssArcDir::Close(long long *retsz)
78{
79 int rc;
80
81// Issue close to possible zipfile appendage and delete it. The underlying
82// oss did not open the file, so we do not issue a close to that.
83//
84 if (zFile)
85 {rc = zFile->Close();
86 if (retsz) *retsz = 0;
87 delete zFile;
88 zFile = 0;
89 } else rc = ossDF->Close(retsz);
90
91// All done
92//
93 return rc;
94}
95
96/******************************************************************************/
97/* g e t E r r M s g */
98/******************************************************************************/
99
100bool XrdOssArcDir::getErrMsg(std::string& eText)
101{
102// Return any extened error mesage associated with this thread
103//
104 if (ecMsg.hasMsg())
105 {std::string xMsg;
106 if (ossDF->getErrMsg(xMsg))
107 {ecMsg.Append();
108 ecMsg.Msg("oss", xMsg.c_str());
109 }
110 ecMsg.Get(eText);
111 return true;
112 }
113 return ossDF->getErrMsg(eText);
114}
115
116/******************************************************************************/
117/* O p e n d i r */
118/******************************************************************************/
119
120int XrdOssArcDir::Opendir(const char *path, XrdOucEnv &env)
121{
122 TraceInfo("Opendir", ossDF->getTID());
123 int rc, arcFD;
124
125// Construct a minimal information object
126//
127 XrdOssArcCompose dsInfo(path, 0, rc, false);
128
129// If this is not out path, forward it along
130//
131 if (rc == EDOM) return ossDF->Opendir(path, env);
132
133// We don't support directory listings for backup paths
134//
135 if (dsInfo.didType == XrdOssArcCompose::isBKP) return EPERM;
136
137// Whether this is a request for an archve or a file in the archive, we
138// need to bring the archive file online. We do this first.
139//
140 char arcPath[MAXPATHLEN];
141 if ((rc = dsInfo.ArcPath(arcPath, sizeof(arcPath), true)))
142 {Elog.Emsg("opendir", rc, "instantiate path", arcPath);
143 return -rc;
144 }
145
146// Open the directory
147//
148 DEBUG("Dir="<<arcPath);
149 if ((arcFD = XrdSysFD_Open(arcPath, O_RDONLY)) < 0)
150 {rc = errno;
151 Elog.Emsg("opendir", rc, "open directory", arcPath);
152 return -rc;
153 }
154
155// We now promote the newly opened directory to the wrapped directory
156// object as it will handle all of the directory methods. We just do the open
157// to bypass all of the name2name mapping.
158//
159 rc = ossDF->Fctl(XrdOssDF::Fctl_setFD,sizeof(int),(const char*)&arcFD);
160 if (rc)
161 {Elog.Emsg("opendir", rc, "promote open of", arcPath);
162 close(arcFD);
163 return Neg(rc);
164 }
165
166// All done
167//
168 return XrdOssOK;
169}
#define DEBUG(x)
#define TraceInfo(x, y)
#define Neg(x)
Definition XrdOssArc.cc:78
#define XrdOssOK
Definition XrdOss.hh:54
#define close(a)
Definition XrdPosix.hh:48
int ArcPath(char *buff, int blen, bool addafn=false)
int Close(long long *retsz=0) override
bool getErrMsg(std::string &eText) override
int Opendir(const char *path, XrdOucEnv &env) override
virtual ~XrdOssArcDir()
static const int Fctl_setFD
Definition XrdOss.hh:460
XrdSysTrace ArcTrace("OssArc")
XrdSysError Elog(0, "OssArc_")