XRootD
Loading...
Searching...
No Matches
XrdPosixMap.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d P o s i x M a p . 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/******************************************************************************/
30
31#include <cerrno>
32#include <sys/stat.h>
33
34#include "XrdOuc/XrdOucECMsg.hh"
37#include "XrdSfs/XrdSfsFlags.hh"
39
40#ifndef EAUTH
41#define EAUTH EBADE
42#endif
43
44#ifndef ENOSR
45#define ENOSR ENOSPC
46#endif
47
48#ifndef ECHRNG
49#define ECHRNG EINVAL
50#endif
51
52/******************************************************************************/
53/* S t a t i c M e m b e r s */
54/******************************************************************************/
55
56bool XrdPosixMap::Debug = false;
57
58/******************************************************************************/
59/* F l a g s 2 M o d e */
60/******************************************************************************/
61
62mode_t XrdPosixMap::Flags2Mode(dev_t *rdv, uint32_t flags)
63{
64 mode_t newflags = 0;
65
66// Map the xroot flags to unix flags
67//
68 if (flags & XrdCl::StatInfo::XBitSet) newflags |= S_IXUSR;
69 if (flags & XrdCl::StatInfo::IsReadable) newflags |= S_IRUSR;
70 if (flags & XrdCl::StatInfo::IsWritable) newflags |= S_IWUSR;
71 if (flags & XrdCl::StatInfo::Other) newflags |= S_IFBLK;
72 else if (flags & XrdCl::StatInfo::IsDir) newflags |= S_IFDIR;
73 else newflags |= S_IFREG;
74 if (flags & XrdCl::StatInfo::POSCPending) newflags |= XRDSFS_POSCPEND;
75 if (rdv)
76 {*rdv = 0;
77 if (flags & XrdCl::StatInfo::Offline) *rdv |= XRDSFS_OFFLINE;
79 }
80
81 return newflags;
82}
83
84/******************************************************************************/
85/* S t a t F i l l */
86/******************************************************************************/
87
89{
90 auto statInfo = dirEnt.GetStatInfo();
91 if (!statInfo) {
92 ecMsg.Set(EIO, "Directory entry is missing expected stat information");
93 return EIO;
94 }
95
96 memset(&buf, '\0', sizeof(buf));
97 buf.st_mode = Flags2Mode(nullptr, statInfo->GetFlags());
98 // Since the UID/GID isn't known by the client, when these are translated by
99 // XrdXrootdProtocol::StatGen back to xroot protocol flags, they will get zero'd
100 // out if only the user access mode is set (e.g., S_IRUSR). Therefor, upgrade the
101 // access mode in the mapping to "other" as well (e.g., S_ROTH). This way, the
102 // computed mode is the same for both the origin and the cache
103 if (buf.st_mode & S_IRUSR) buf.st_mode |= S_IROTH;
104 if (buf.st_mode & S_IWUSR) buf.st_mode |= S_IWOTH;
105 if (buf.st_mode & S_IXUSR) buf.st_mode |= S_IXOTH;
106 buf.st_mtime = static_cast<time_t>(statInfo->GetModTime());
107 buf.st_ctime = buf.st_mtime;
108 buf.st_size = static_cast<size_t>(statInfo->GetSize());
109 buf.st_ino = static_cast<ino_t>(strtoll(statInfo->GetId().c_str(), 0, 10));
110 buf.st_blocks = buf.st_size/512 + buf.st_size%512;
111 // If the device is zero'd out, then the listing later is translated to being offline
112 buf.st_dev = 1;
113
114 if (statInfo->ExtendedFormat())
115 {buf.st_ctime = static_cast<time_t>(statInfo->GetChangeTime());
116 buf.st_atime = static_cast<time_t>(statInfo->GetAccessTime());
117 }
118
119 return 0;
120}
121
122/******************************************************************************/
123/* Private: m a p C o d e */
124/******************************************************************************/
125
126int XrdPosixMap::mapCode(int rc)
127{
128 switch(rc)
129 {case XrdCl::errRetry: return EAGAIN; // Cl:001
130 case XrdCl::errInvalidOp: return EOPNOTSUPP; // Cl:003
131 case XrdCl::errConfig: return ENOEXEC; // Cl:006
132 case XrdCl::errInvalidArgs: return EINVAL; // Cl:009
133 case XrdCl::errInProgress: return EINPROGRESS; // Cl:010
134 case XrdCl::errNotSupported: return ENOTSUP; // Cl:013
135 case XrdCl::errDataError: return EDOM; // Cl:014
136 case XrdCl::errNotImplemented: return ENOSYS; // Cl:015
137 case XrdCl::errNoMoreReplicas: return ENOSR; // Cl:016
138 case XrdCl::errInvalidAddr: return EHOSTUNREACH; // Cl:101
139 case XrdCl::errSocketError: return ENOTSOCK; // Cl:102
140 case XrdCl::errSocketTimeout: return ETIMEDOUT; // Cl:103
141 case XrdCl::errSocketDisconnected: return ENOTCONN; // Cl:104
142 case XrdCl::errStreamDisconnect: return ECONNRESET; // Cl:107
143 case XrdCl::errConnectionError: return ECONNREFUSED; // Cl:108
144 case XrdCl::errInvalidSession: return ECHRNG; // Cl:109
145 case XrdCl::errTlsError: return ENETRESET; // Cl:110
146 case XrdCl::errInvalidMessage: return EPROTO; // Cl:201
147 case XrdCl::errHandShakeFailed: return EPROTO; // Cl:202
148 case XrdCl::errLoginFailed: return ECONNABORTED; // Cl:203
149 case XrdCl::errAuthFailed: return EAUTH; // Cl:204
150 case XrdCl::errQueryNotSupported: return ENOTSUP; // Cl:205
151 case XrdCl::errOperationExpired: return ETIME; // Cl:206
152 case XrdCl::errOperationInterrupted: return EINTR; // Cl:207
153 case XrdCl::errNoMoreFreeSIDs: return ENOSR; // Cl:301
154 case XrdCl::errInvalidRedirectURL: return ESPIPE; // Cl:302
155 case XrdCl::errInvalidResponse: return EBADMSG; // Cl:303
156 case XrdCl::errNotFound: return EIDRM; // Cl:304
157 case XrdCl::errCheckSumError: return EILSEQ; // Cl:305
158 case XrdCl::errRedirectLimit: return ELOOP; // Cl:306
159 default: break;
160 }
161 return ENOMSG;
162}
163
164/******************************************************************************/
165/* M o d e 2 A c c e s s */
166/******************************************************************************/
167
170
171// Map the mode
172//
173 if (mode & S_IRUSR) XMode |= XrdCl::Access::UR;
174 if (mode & S_IWUSR) XMode |= XrdCl::Access::UW;
175 if (mode & S_IXUSR) XMode |= XrdCl::Access::UX;
176 if (mode & S_IRGRP) XMode |= XrdCl::Access::GR;
177 if (mode & S_IWGRP) XMode |= XrdCl::Access::GW;
178 if (mode & S_IXGRP) XMode |= XrdCl::Access::GX;
179 if (mode & S_IROTH) XMode |= XrdCl::Access::OR;
180 if (mode & S_IXOTH) XMode |= XrdCl::Access::OX;
181 return XMode;
182}
183
184/******************************************************************************/
185/* R e s u l t */
186/******************************************************************************/
187
189 XrdOucECMsg& ecMsg, bool retneg1)
190{
191 int eNum;
192
193// If all went well, return success
194//
195 if (Status.IsOK()) return 0;
196
197// If this is an xrootd error then get the xrootd generated error
198//
199 if (Status.code == XrdCl::errErrorResponse)
200 {ecMsg = Status.GetErrorMessage();
201 eNum = XProtocol::toErrno(Status.errNo);
202 } else {
203 ecMsg = Status.ToStr();
204 eNum = (Status.errNo ? Status.errNo : mapCode(Status.code));
205 }
206
207// Trace this if need be (we supress this for as we really need more info to
208// make this messae useful like the opteration and path).
209//
210// if (eNum != ENOENT && !ecMsg.hasMsg() && Debug)
211// std::cerr <<"XrdPosix: " <<eText <<std::endl;
212
213// Return
214//
215 ecMsg = errno = eNum;
216 return (retneg1 ? -1 : -eNum);
217}
#define EAUTH
#define ECHRNG
#define ENOSR
#define stat(a, b)
Definition XrdPosix.hh:101
static const dev_t XRDSFS_HASBKUP
#define XRDSFS_POSCPEND
static const dev_t XRDSFS_OFFLINE
static int toErrno(int xerr)
StatInfo * GetStatInfo()
Get the stat info object.
@ IsReadable
Read access is allowed.
@ IsDir
This is a directory.
@ Other
Neither a file nor a directory.
@ BackUpExists
Back up copy exists.
@ XBitSet
Executable/searchable bit set.
@ Offline
File is not online (ie. on disk)
@ IsWritable
Write access is allowed.
const std::string & GetErrorMessage() const
Get error message.
std::string ToStr() const
Convert to string.
void Set(int ecc, const char *ecm="")
static mode_t Flags2Mode(dev_t *rdv, uint32_t flags)
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)
static XrdCl::Access::Mode Mode2Access(mode_t mode)
const uint16_t errQueryNotSupported
const uint16_t errInvalidAddr
const uint16_t errStreamDisconnect
const uint16_t errRedirectLimit
const uint16_t errErrorResponse
const uint16_t errTlsError
const uint16_t errOperationExpired
const uint16_t errNotImplemented
Operation is not implemented.
const uint16_t errLoginFailed
const uint16_t errNoMoreFreeSIDs
const uint16_t errInProgress
const uint16_t errNotFound
const uint16_t errSocketTimeout
const uint16_t errDataError
data is corrupted
const uint16_t errInvalidOp
const uint16_t errHandShakeFailed
const uint16_t errConfig
System misconfigured.
const uint16_t errInvalidResponse
const uint16_t errInvalidArgs
const uint16_t errInvalidRedirectURL
const uint16_t errConnectionError
const uint16_t errNotSupported
const uint16_t errSocketError
const uint16_t errRetry
Try again for whatever reason.
const uint16_t errCheckSumError
const uint16_t errOperationInterrupted
const uint16_t errNoMoreReplicas
No more replicas to try.
const uint16_t errInvalidSession
const uint16_t errSocketDisconnected
const uint16_t errAuthFailed
const uint16_t errInvalidMessage
@ OX
world executable/browsable
@ UR
owner readable
@ GR
group readable
@ UW
owner writable
@ GX
group executable/browsable
@ GW
group writable
@ UX
owner executable/browsable
@ OR
world readable
uint16_t code
Error type, or additional hints on what to do.
bool IsOK() const
We're fine.
uint32_t errNo
Errno, if any.