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 
13 class XrdSysError;
14 
15 // XrdSysFAttr provides a portable interface to handle extended file attributes
16 //
18 {
19 public:
20 /* AList is a structure which defines attribute names and the associated
21  size of the attributes value. It is used for Free() and List().
22 */
23 struct AList
24  {AList *Next; // -> next element.
25  int Vlen; // The length of the attribute value;
26  int Nlen; // The length of the attribute name that follows.
27  char Name[1]; // Start of the name (size of struct is dynamic)
28  };
29 
30 /* Copy() copies one or more attributes from iPath file to the oPath file.
31  The first form without Aname copies all attributes. The second form
32  copies only the attributes pointed to by Aname.
33  Success: True
34  Failure: False
35 */
36 static int Copy(const char *iPath, int iFD, const char *oPath, int oFD);
37 
38 static int Copy(const char *iPath, int iFD, const char *oPath, int oFD,
39  const char *Aname);
40 
41 /* Del() removes attribute "Aname" from the file identified by "Path" or
42  an opened file referenced by "fd".
43  Success: zero is returned.
44  Failure: -errno is returned. Note that no error is returned should
45  "Aname" not exist.
46 */
47 static int Del(const char *Aname, const char *Path, int fd=-1);
48 
49 /* Free() releases the AList list returned my List(). This method must be
50  used to deallocate the storage as AList is dynamically sized.
51 */
52 static void Free(AList *aPL);
53 
54 /* Get() get the value associated with attribute "Aname" from the file
55  identified by "Path" or an opened file referenced by "fd". The value
56  is placed in the buffer pointed to by "Aval" whose size if "Avsz"
57  bytes. Only up to "Avsz" bytes are returned and no check is made
58  to see if more bytes can be returned. To see how many bytes are
59  occupied by the attribute value, call Get() with "Avsz" set to zero.
60  Success: the number of bytes placed in "Aval" is returned. If
61  "Avsz" is zero, this is how many bytes could have been set.
62  Failure: -errno is returned. Should "Aname" not exist then zero is
63  returned (i.e., no value bytes).
64 */
65 static int Get(const char *Aname, void *Aval, int Avsz,
66  const char *Path, int fd=-1);
67 
68 /* List() returns the list of extended attribute along with the size of each for
69  the file identified by "Path" or an opened file referenced by "fd".
70  The first element of the list is returned in aPL. You must use the
71  class defined Free() method to deallocate the list. If getSZ == True
72  then the size of the attribute value is also returned; otherwise,
73  the size is set to zero and no maximum size can be returned.
74  Success: the length of the lagest attribute value is returned (if
75  getSZ is true; otherwise zero is returned) and
76  *aPL is set to point to the first AList element, if any.
77  Failure: -error is returned and *aPL is set to zero.
78 */
79 static int List(AList **aPL, const char *Path, int fd=-1, int getSz=0);
80 
81 /* Set() sets the value associated with attribute "Aname" for the file
82  identified by "Path" or an opened file referenced by "fd". The value
83  must be in the buffer pointed to by "Aval" and be "Avsz" bytes long.
84  Normally, "Aname" is created if it does not exist or its value is
85  simply replaced. By setting isNew to one, then an error is returned
86  if Aname already exists and it is not replaced.
87  Success: zero is returned.
88  Failure: -errno is returned.
89 */
90 static int Set(const char *Aname, const void *Aval, int Avsz,
91  const char *Path, int fd=-1, int isNew=0);
92 
93 /* Msg() is used to establish the error message object. If it is not
94  established, no messages are produced. It returns the previous setting.
95 */
97  {XrdSysError *orP = Say; Say = erP; return orP;}
98 
99 protected:
100 
101 static int Diagnose(const char *Op, const char *Var, const char *Path, int ec);
102 static AList *getEnt(const char *Path, int fd, const char *Aname,
103  AList *aP, int *msP);
104 
105 static XrdSysError *Say;
106 };
107 #endif