xrootd
XrdSysFAttr.hh
Go to the documentation of this file.
1 #ifndef __XRDSYSFATTR_HH__
2 #define __XRDSYSFATTR_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d S y s F A t t r . h h */
6 /* */
7 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 class XrdSysError;
34 
35 // XrdSysFAttr provides a portable interface to handle extended file attributes
36 //
38 {
39 public:
40 /* AList is a structure which defines attribute names and the associated
41  size of the attributes value. It is used for Free() and List().
42 */
43 struct AList
44  {AList *Next; // -> next element.
45  int Vlen; // The length of the attribute value;
46  int Nlen; // The length of the attribute name that follows.
47  char Name[1]; // Start of the name (size of struct is dynamic)
48  };
49 
50 /* Copy() copies one or more attributes from iPath file to the oPath file.
51  The first form without Aname copies all attributes. The second form
52  copies only the attributes pointed to by Aname.
53  Success: True
54  Failure: False
55 */
56 static int Copy(const char *iPath, int iFD, const char *oPath, int oFD);
57 
58 static int Copy(const char *iPath, int iFD, const char *oPath, int oFD,
59  const char *Aname);
60 
61 /* Del() removes attribute "Aname" from the file identified by "Path" or
62  an opened file referenced by "fd".
63  Success: zero is returned.
64  Failure: -errno is returned. Note that no error is returned should
65  "Aname" not exist.
66 */
67 static int Del(const char *Aname, const char *Path, int fd=-1);
68 
69 /* Free() releases the AList list returned my List(). This method must be
70  used to deallocate the storage as AList is dynamically sized.
71 */
72 static void Free(AList *aPL);
73 
74 /* Get() get the value associated with attribute "Aname" from the file
75  identified by "Path" or an opened file referenced by "fd". The value
76  is placed in the buffer pointed to by "Aval" whose size if "Avsz"
77  bytes. Only up to "Avsz" bytes are returned and no check is made
78  to see if more bytes can be returned. To see how many bytes are
79  occupied by the attribute value, call Get() with "Avsz" set to zero.
80  Success: the number of bytes placed in "Aval" is returned. If
81  "Avsz" is zero, this is how many bytes could have been set.
82  Failure: -errno is returned. Should "Aname" not exist then zero is
83  returned (i.e., no value bytes).
84 */
85 static int Get(const char *Aname, void *Aval, int Avsz,
86  const char *Path, int fd=-1);
87 
88 /* List() returns the list of extended attribute along with the size of each for
89  the file identified by "Path" or an opened file referenced by "fd".
90  The first element of the list is returned in aPL. You must use the
91  class defined Free() method to deallocate the list. If getSZ == True
92  then the size of the attribute value is also returned; otherwise,
93  the size is set to zero and no maximum size can be returned.
94  Success: the length of the lagest attribute value is returned (if
95  getSZ is true; otherwise zero is returned) and
96  *aPL is set to point to the first AList element, if any.
97  Failure: -error is returned and *aPL is set to zero.
98 */
99 static int List(AList **aPL, const char *Path, int fd=-1, int getSz=0);
100 
101 /* Set() sets the value associated with attribute "Aname" for the file
102  identified by "Path" or an opened file referenced by "fd". The value
103  must be in the buffer pointed to by "Aval" and be "Avsz" bytes long.
104  Normally, "Aname" is created if it does not exist or its value is
105  simply replaced. By setting isNew to one, then an error is returned
106  if Aname already exists and it is not replaced.
107  Success: zero is returned.
108  Failure: -errno is returned.
109 */
110 static int Set(const char *Aname, const void *Aval, int Avsz,
111  const char *Path, int fd=-1, int isNew=0);
112 
113 /* Msg() is used to establish the error message object. If it is not
114  established, no messages are produced. It returns the previous setting.
115 */
117  {XrdSysError *orP = Say; Say = erP; return orP;}
118 
119 protected:
120 
121 static int Diagnose(const char *Op, const char *Var, const char *Path, int ec);
122 static AList *getEnt(const char *Path, int fd, const char *Aname,
123  AList *aP, int *msP);
124 
125 static XrdSysError *Say;
126 };
127 #endif