xrootd
XrdSysFAttr.hh
Go to the documentation of this file.
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 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 class XrdSysError;
00034 
00035 // XrdSysFAttr provides a portable interface to handle extended file attributes
00036 //
00037 class XrdSysFAttr
00038 {
00039 public:
00040 /* AList  is a structure which defines attribute names and the associated
00041           size of the attributes value. It is used for Free() and List().
00042 */
00043 struct AList
00044       {AList *Next;    // -> next element.
00045        int    Vlen;    //   The length of the attribute value;
00046        int    Nlen;    //   The length of the attribute name that follows.
00047        char   Name[1]; //   Start of the name (size of struct is dynamic)
00048       };
00049 
00050 /* Copy() copies one or more attributes from iPath file to the oPath file.
00051           The first form without Aname copies all attributes. The second form
00052           copies only the attributes pointed to by Aname.
00053           Success: True
00054           Failure: False
00055 */
00056 static int Copy(const char *iPath, int iFD, const char *oPath, int oFD);
00057 
00058 static int Copy(const char *iPath, int iFD, const char *oPath, int oFD,
00059                 const char *Aname);
00060 
00061 /* Del() removes attribute "Aname" from the file identified by "Path" or
00062          an opened file referenced by "fd".
00063          Success:   zero is returned.
00064          Failure: -errno is returned. Note that no error is returned should
00065                   "Aname" not exist.
00066 */
00067 static int Del(const char *Aname, const char *Path, int fd=-1);
00068 
00069 /* Free() releases the AList list returned my List(). This method must be
00070           used to deallocate the storage as AList is dynamically sized.
00071 */
00072 static void Free(AList *aPL);
00073 
00074 /* Get() get the value associated with attribute "Aname" from the file
00075          identified by "Path" or an opened file referenced by "fd". The value
00076          is placed in the buffer pointed to by "Aval" whose size if "Avsz"
00077          bytes. Only up to "Avsz" bytes are returned and no check is made
00078          to see if more bytes can be returned. To see how many bytes are
00079          occupied by the attribute value, call Get() with "Avsz" set to zero.
00080          Success: the number of bytes placed in "Aval" is returned. If
00081                   "Avsz" is zero, this is how many bytes could have been set.
00082          Failure: -errno is returned. Should "Aname" not exist then zero is
00083                   returned (i.e., no value bytes).
00084 */
00085 static int Get(const char *Aname, void *Aval, int Avsz,
00086                const char *Path,  int fd=-1);
00087 
00088 /* List() returns the list of extended attribute along with the size of each for
00089           the file identified by "Path" or an opened file referenced by "fd".
00090           The first element of the list is returned in aPL. You must use the
00091           class defined Free() method to deallocate the list. If getSZ == True
00092           then the size of the attribute value is also returned; otherwise,
00093           the size is set to zero and no maximum size can be returned.
00094           Success: the length of the lagest attribute value is returned (if
00095                    getSZ is true; otherwise zero is returned) and
00096                    *aPL is set to point to the first AList element, if any.
00097           Failure: -error is returned and *aPL is set to zero.
00098 */
00099 static int List(AList **aPL, const char *Path, int fd=-1, int getSz=0);
00100 
00101 /* Set() sets the value associated with attribute "Aname" for the file
00102          identified by "Path" or an opened file referenced by "fd". The value
00103          must be in the buffer pointed to by "Aval" and be "Avsz" bytes long.
00104          Normally, "Aname" is created if it does not exist or its value is
00105          simply replaced. By setting isNew to one, then an error is returned
00106          if Aname already exists and it is not replaced.
00107          Success:   zero is returned.
00108          Failure: -errno is returned.
00109 */
00110 static int Set(const char *Aname, const void *Aval, int Avsz,
00111                const char *Path,  int fd=-1,  int isNew=0);
00112 
00113 /* Msg() is used to establish the error message object. If it is not
00114    established, no messages are produced. It returns the previous setting.
00115 */
00116 static XrdSysError *Msg(XrdSysError *erP)
00117                        {XrdSysError *orP = Say; Say = erP; return orP;}
00118 
00119 protected:
00120 
00121 static int Diagnose(const char *Op, const char *Var, const char *Path, int ec);
00122 static AList *getEnt(const char *Path,  int fd, const char *Aname,
00123                      AList *aP, int *msP);
00124 
00125 static XrdSysError *Say;
00126 };
00127 #endif