XRootD
XrdSysFAttr.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d S y s F A t t r . c c */
4 /* */
5 /* (c) 2014 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 <cstdio>
33 #include <cstdlib>
34 
35 #include "XrdSys/XrdSysError.hh"
36 #include "XrdSys/XrdSysFAttr.hh"
37 
38 /******************************************************************************/
39 /* P l a t f o r m D e p e n d e n c i e s */
40 /******************************************************************************/
41 
42 #ifndef ENOATTR
43 #define ENOATTR ENODATA
44 #endif
45 
46 /******************************************************************************/
47 /* S t a t i c O b j e c t s */
48 /******************************************************************************/
49 
50 namespace
51 {
52 XrdSysFAttr dfltXAttr;
53 }
54 
55 // The following global symbol always points to the native implementation
56 //
58 
59 // The following global symbol always points to the active implementation
60 //
62 
63 XrdSysXAttr *XrdSysFAttr::Xat = &dfltXAttr;
64 
65 /******************************************************************************/
66 /* X r d S y s F A t t r I m p l e m e n t a t i o n */
67 /******************************************************************************/
68 
69 #if defined(__FreeBSD__)
71 #elif defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
73 #elif defined(__APPLE__)
75 #elif defined(__solaris__)
77 #else
78 int XrdSysFAttr::Del(const char *Aname, const char *Path, int fd)
79  {return -ENOTSUP;}
80 int XrdSysFAttr::List(AList **aPL, const char *Path, int fd, int getSz)
81  {return -ENOTSUP;}
82 int XrdSysFAttr::Get(const char *Aname, void *Aval, int Avsz,
83  const char *Path, int fd)
84  {return -ENOTSUP;}
85 int XrdSysFAttr::Set(const char *Aname, const void *Aval, int Avsz,
86  const char *Path, int fd, int isNew)
87  {return -ENOTSUP;}
88 #endif
89 
90 /******************************************************************************/
91 /* D i a g n o s e */
92 /******************************************************************************/
93 
94 int XrdSysFAttr::Diagnose(const char *Op, const char *Var,
95  const char *Path, int ec)
96 {
97  char buff[512];
98 
99 // Screen out common case
100 //
101  if (ec == ENOATTR || ec == ENOENT) return -ec;
102 
103 // Format message insert and print if we can actually say anything
104 //
105  if (Say)
106  {snprintf(buff, sizeof(buff), "%s attr %s from", Op, Var);
107  Say->Emsg("FAttr", ec, buff, Path);
108  }
109 
110 // Return negative code
111 //
112  return -ec;
113 }
114 
115 /******************************************************************************/
116 /* F r e e */
117 /******************************************************************************/
118 
119 void XrdSysFAttr::Free(XrdSysFAttr::AList *aLP)
120 {
121  AList *aNP;
122 
123 // Free all the structs using free as they were allocated using malloc()
124 //
125  while(aLP) {aNP = aLP->Next; free(aLP); aLP = aNP;}
126 }
127 
128 /******************************************************************************/
129 /* g e t E n t */
130 /******************************************************************************/
131 
132 XrdSysFAttr::AList *XrdSysFAttr::getEnt(const char *Path, int fd,
133  const char *Aname,
134  XrdSysFAttr::AList *aP, int *msP)
135 {
136  AList *aNew;
137  int sz = 0, n = strlen(Aname);
138 
139 // Get the data size of this attribute if so wanted
140 //
141  if (!n || (msP && (sz = Get(Aname, 0, 0, Path, fd)) < 0)) return 0;
142 
143 // Allocate a new dynamic struct
144 //
145  if (!(aNew = (AList *)malloc(sizeof(AList) + n))) return 0;
146 
147 // Initialize the structure
148 //
149  aNew->Next = aP;
150  aNew->Vlen = sz;
151  aNew->Nlen = n;
152  strcpy(aNew->Name, Aname); // Gauranteed to fit
153 
154 // All done
155 //
156  if (msP && *msP < sz) *msP = sz;
157  return aNew;
158 }
159 
160 /******************************************************************************/
161 /* S e t P l u g i n */
162 /******************************************************************************/
163 
164 void XrdSysFAttr::SetPlugin(XrdSysXAttr *xaP, bool push)
165 {
166  if (!push && Xat && Xat != &dfltXAttr) delete Xat;
167  XrdSysXAttrActive = Xat = xaP;
168 }
XrdOucString Path
#define ENOATTR
Definition: XrdSysFAttr.cc:43
XrdSysXAttr & XrdSysXAttrNative
Definition: XrdSysFAttr.cc:57
XrdSysXAttr * XrdSysXAttrActive
Definition: XrdSysFAttr.cc:61
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
static void SetPlugin(XrdSysXAttr *xaP, bool push=false)
Definition: XrdSysFAttr.cc:164
static XrdSysXAttr * Xat
Definition: XrdSysFAttr.hh:51
int Vlen
The length of the attribute value;.
Definition: XrdSysXAttr.hh:54
XrdSysError * Say
Definition: XrdSysXAttr.hh:191
AList * Next
-> next element.
Definition: XrdSysXAttr.hh:53