xrootd
|
00001 #ifndef __XRDSYSFATTR_HH__ 00002 #define __XRDSYSFATTR_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d S y s F A t t r . h h */ 00006 /* */ 00007 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* All Rights Reserved */ 00009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 class XrdSysError; 00014 00015 // XrdSysFAttr provides a portable interface to handle extended file attributes 00016 // 00017 class XrdSysFAttr 00018 { 00019 public: 00020 /* AList is a structure which defines attribute names and the associated 00021 size of the attributes value. It is used for Free() and List(). 00022 */ 00023 struct AList 00024 {AList *Next; // -> next element. 00025 int Vlen; // The length of the attribute value; 00026 int Nlen; // The length of the attribute name that follows. 00027 char Name[1]; // Start of the name (size of struct is dynamic) 00028 }; 00029 00030 /* Copy() copies one or more attributes from iPath file to the oPath file. 00031 The first form without Aname copies all attributes. The second form 00032 copies only the attributes pointed to by Aname. 00033 Success: True 00034 Failure: False 00035 */ 00036 static int Copy(const char *iPath, int iFD, const char *oPath, int oFD); 00037 00038 static int Copy(const char *iPath, int iFD, const char *oPath, int oFD, 00039 const char *Aname); 00040 00041 /* Del() removes attribute "Aname" from the file identified by "Path" or 00042 an opened file referenced by "fd". 00043 Success: zero is returned. 00044 Failure: -errno is returned. Note that no error is returned should 00045 "Aname" not exist. 00046 */ 00047 static int Del(const char *Aname, const char *Path, int fd=-1); 00048 00049 /* Free() releases the AList list returned my List(). This method must be 00050 used to deallocate the storage as AList is dynamically sized. 00051 */ 00052 static void Free(AList *aPL); 00053 00054 /* Get() get the value associated with attribute "Aname" from the file 00055 identified by "Path" or an opened file referenced by "fd". The value 00056 is placed in the buffer pointed to by "Aval" whose size if "Avsz" 00057 bytes. Only up to "Avsz" bytes are returned and no check is made 00058 to see if more bytes can be returned. To see how many bytes are 00059 occupied by the attribute value, call Get() with "Avsz" set to zero. 00060 Success: the number of bytes placed in "Aval" is returned. If 00061 "Avsz" is zero, this is how many bytes could have been set. 00062 Failure: -errno is returned. Should "Aname" not exist then zero is 00063 returned (i.e., no value bytes). 00064 */ 00065 static int Get(const char *Aname, void *Aval, int Avsz, 00066 const char *Path, int fd=-1); 00067 00068 /* List() returns the list of extended attribute along with the size of each for 00069 the file identified by "Path" or an opened file referenced by "fd". 00070 The first element of the list is returned in aPL. You must use the 00071 class defined Free() method to deallocate the list. If getSZ == True 00072 then the size of the attribute value is also returned; otherwise, 00073 the size is set to zero and no maximum size can be returned. 00074 Success: the length of the lagest attribute value is returned (if 00075 getSZ is true; otherwise zero is returned) and 00076 *aPL is set to point to the first AList element, if any. 00077 Failure: -error is returned and *aPL is set to zero. 00078 */ 00079 static int List(AList **aPL, const char *Path, int fd=-1, int getSz=0); 00080 00081 /* Set() sets the value associated with attribute "Aname" for the file 00082 identified by "Path" or an opened file referenced by "fd". The value 00083 must be in the buffer pointed to by "Aval" and be "Avsz" bytes long. 00084 Normally, "Aname" is created if it does not exist or its value is 00085 simply replaced. By setting isNew to one, then an error is returned 00086 if Aname already exists and it is not replaced. 00087 Success: zero is returned. 00088 Failure: -errno is returned. 00089 */ 00090 static int Set(const char *Aname, const void *Aval, int Avsz, 00091 const char *Path, int fd=-1, int isNew=0); 00092 00093 /* Msg() is used to establish the error message object. If it is not 00094 established, no messages are produced. It returns the previous setting. 00095 */ 00096 static XrdSysError *Msg(XrdSysError *erP) 00097 {XrdSysError *orP = Say; Say = erP; return orP;} 00098 00099 protected: 00100 00101 static int Diagnose(const char *Op, const char *Var, const char *Path, int ec); 00102 static AList *getEnt(const char *Path, int fd, const char *Aname, 00103 AList *aP, int *msP); 00104 00105 static XrdSysError *Say; 00106 }; 00107 #endif