XRootD
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"
35 #include "XProtocol/XProtocol.hh"
36 #include "XrdPosix/XrdPosixMap.hh"
37 #include "XrdSfs/XrdSfsFlags.hh"
38 #include "XrdSys/XrdSysHeaders.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 
56 bool XrdPosixMap::Debug = false;
57 
58 /******************************************************************************/
59 /* F l a g s 2 M o d e */
60 /******************************************************************************/
61 
62 mode_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;
78  if (flags & XrdCl::StatInfo::BackUpExists) *rdv |= XRDSFS_HASBKUP;
79  }
80 
81  return newflags;
82 }
83 
84 /******************************************************************************/
85 /* Private: m a p C o d e */
86 /******************************************************************************/
87 
88 int 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
Definition: XProtocol.hh:1350
#define ECHRNG
Definition: XrdPosixMap.cc:49
#define ENOSR
Definition: XrdPosixMap.cc:45
static const dev_t XRDSFS_HASBKUP
Definition: XrdSfsFlags.hh:102
#define XRDSFS_POSCPEND
Definition: XrdSfsFlags.hh:89
static const dev_t XRDSFS_OFFLINE
Definition: XrdSfsFlags.hh:100
static int toErrno(int xerr)
Definition: XProtocol.hh:1408
@ 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)
Definition: XrdPosixMap.cc:62
static int Result(const XrdCl::XRootDStatus &Status, XrdOucECMsg &ecMsg, bool retneg1=false)
Definition: XrdPosixMap.cc:150
static XrdCl::Access::Mode Mode2Access(mode_t mode)
Definition: XrdPosixMap.cc:130
const uint16_t errQueryNotSupported
Definition: XrdClStatus.hh:89
const uint16_t errInvalidAddr
Definition: XrdClStatus.hh:71
const uint16_t errStreamDisconnect
Definition: XrdClStatus.hh:77
const uint16_t errRedirectLimit
Definition: XrdClStatus.hh:102
const uint16_t errErrorResponse
Definition: XrdClStatus.hh:105
const uint16_t errTlsError
Definition: XrdClStatus.hh:80
const uint16_t errOperationExpired
Definition: XrdClStatus.hh:90
const uint16_t errNotImplemented
Operation is not implemented.
Definition: XrdClStatus.hh:64
const uint16_t errLoginFailed
Definition: XrdClStatus.hh:87
const uint16_t errNoMoreFreeSIDs
Definition: XrdClStatus.hh:97
const uint16_t errInProgress
Definition: XrdClStatus.hh:59
const uint16_t errNotFound
Definition: XrdClStatus.hh:100
const uint16_t errSocketTimeout
Definition: XrdClStatus.hh:73
const uint16_t errDataError
data is corrupted
Definition: XrdClStatus.hh:63
const uint16_t errInvalidOp
Definition: XrdClStatus.hh:51
const uint16_t errHandShakeFailed
Definition: XrdClStatus.hh:86
const uint16_t errConfig
System misconfigured.
Definition: XrdClStatus.hh:55
const uint16_t errInvalidResponse
Definition: XrdClStatus.hh:99
const uint16_t errInvalidArgs
Definition: XrdClStatus.hh:58
const uint16_t errInvalidRedirectURL
Definition: XrdClStatus.hh:98
const uint16_t errConnectionError
Definition: XrdClStatus.hh:78
const uint16_t errNotSupported
Definition: XrdClStatus.hh:62
const uint16_t errSocketError
Definition: XrdClStatus.hh:72
const uint16_t errRetry
Try again for whatever reason.
Definition: XrdClStatus.hh:49
const uint16_t errCheckSumError
Definition: XrdClStatus.hh:101
const uint16_t errOperationInterrupted
Definition: XrdClStatus.hh:91
const uint16_t errNoMoreReplicas
No more replicas to try.
Definition: XrdClStatus.hh:65
const uint16_t errInvalidSession
Definition: XrdClStatus.hh:79
const uint16_t errSocketDisconnected
Definition: XrdClStatus.hh:74
const uint16_t errAuthFailed
Definition: XrdClStatus.hh:88
const uint16_t errInvalidMessage
Definition: XrdClStatus.hh:85
thread_local XrdOucECMsg ecMsg
Mode
Access mode.
@ 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.
Definition: XrdClStatus.hh:147
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124
uint32_t errNo
Errno, if any.
Definition: XrdClStatus.hh:148