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/* Private: m a p C o d e */
86/******************************************************************************/
87
88int XrdPosixMap::mapCode(int rc)
89{
90 switch(rc)
91 {case XrdCl::errRetry: return EAGAIN; // Cl:001
92 case XrdCl::errInvalidOp: return EOPNOTSUPP; // Cl:003
93 case XrdCl::errConfig: return ENOEXEC; // Cl:006
94 case XrdCl::errInvalidArgs: return EINVAL; // Cl:009
95 case XrdCl::errInProgress: return EINPROGRESS; // Cl:010
96 case XrdCl::errNotSupported: return ENOTSUP; // Cl:013
97 case XrdCl::errDataError: return EDOM; // Cl:014
98 case XrdCl::errNotImplemented: return ENOSYS; // Cl:015
99 case XrdCl::errNoMoreReplicas: return ENOSR; // Cl:016
100 case XrdCl::errInvalidAddr: return EHOSTUNREACH; // Cl:101
101 case XrdCl::errSocketError: return ENOTSOCK; // Cl:102
102 case XrdCl::errSocketTimeout: return ETIMEDOUT; // Cl:103
103 case XrdCl::errSocketDisconnected: return ENOTCONN; // Cl:104
104 case XrdCl::errStreamDisconnect: return ECONNRESET; // Cl:107
105 case XrdCl::errConnectionError: return ECONNREFUSED; // Cl:108
106 case XrdCl::errInvalidSession: return ECHRNG; // Cl:109
107 case XrdCl::errTlsError: return ENETRESET; // Cl:110
108 case XrdCl::errInvalidMessage: return EPROTO; // Cl:201
109 case XrdCl::errHandShakeFailed: return EPROTO; // Cl:202
110 case XrdCl::errLoginFailed: return ECONNABORTED; // Cl:203
111 case XrdCl::errAuthFailed: return EAUTH; // Cl:204
112 case XrdCl::errQueryNotSupported: return ENOTSUP; // Cl:205
113 case XrdCl::errOperationExpired: return ESTALE; // Cl:206
114 case XrdCl::errOperationInterrupted: return EINTR; // Cl:207
115 case XrdCl::errNoMoreFreeSIDs: return ENOSR; // Cl:301
116 case XrdCl::errInvalidRedirectURL: return ESPIPE; // Cl:302
117 case XrdCl::errInvalidResponse: return EBADMSG; // Cl:303
118 case XrdCl::errNotFound: return EIDRM; // Cl:304
119 case XrdCl::errCheckSumError: return EILSEQ; // Cl:305
120 case XrdCl::errRedirectLimit: return ELOOP; // Cl:306
121 default: break;
122 }
123 return ENOMSG;
124}
125
126/******************************************************************************/
127/* M o d e 2 A c c e s s */
128/******************************************************************************/
129
132
133// Map the mode
134//
135 if (mode & S_IRUSR) XMode |= XrdCl::Access::UR;
136 if (mode & S_IWUSR) XMode |= XrdCl::Access::UW;
137 if (mode & S_IXUSR) XMode |= XrdCl::Access::UX;
138 if (mode & S_IRGRP) XMode |= XrdCl::Access::GR;
139 if (mode & S_IWGRP) XMode |= XrdCl::Access::GW;
140 if (mode & S_IXGRP) XMode |= XrdCl::Access::GX;
141 if (mode & S_IROTH) XMode |= XrdCl::Access::OR;
142 if (mode & S_IXOTH) XMode |= XrdCl::Access::OX;
143 return XMode;
144}
145
146/******************************************************************************/
147/* R e s u l t */
148/******************************************************************************/
149
151 XrdOucECMsg& ecMsg, bool retneg1)
152{
153 int eNum;
154
155// If all went well, return success
156//
157 if (Status.IsOK()) return 0;
158
159// If this is an xrootd error then get the xrootd generated error
160//
161 if (Status.code == XrdCl::errErrorResponse)
162 {ecMsg = Status.GetErrorMessage();
163 eNum = XProtocol::toErrno(Status.errNo);
164 } else {
165 ecMsg = Status.ToStr();
166 eNum = (Status.errNo ? Status.errNo : mapCode(Status.code));
167 }
168
169// Trace this if need be (we supress this for as we really need more info to
170// make this messae useful like the opteration and path).
171//
172// if (eNum != ENOENT && !ecMsg.hasMsg() && Debug)
173// std::cerr <<"XrdPosix: " <<eText <<std::endl;
174
175// Return
176//
177 ecMsg = errno = eNum;
178 return (retneg1 ? -1 : -eNum);
179}
#define EAUTH
#define ECHRNG
#define ENOSR
static const dev_t XRDSFS_HASBKUP
#define XRDSFS_POSCPEND
static const dev_t XRDSFS_OFFLINE
static int toErrno(int xerr)
@ 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.
static mode_t Flags2Mode(dev_t *rdv, uint32_t flags)
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.