Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:43

0001 #ifndef __XRDSYSXATTR_HH__
0002 #define __XRDSYSXATTR_HH__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                        X r d S y s X A t t r . h h                         */
0006 /*                                                                            */
0007 /* (c) 2014 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*                            All Rights Reserved                             */
0009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0011 /*                                                                            */
0012 /* This file is part of the XRootD software suite.                            */
0013 /*                                                                            */
0014 /* XRootD is free software: you can redistribute it and/or modify it under    */
0015 /* the terms of the GNU Lesser General Public License as published by the     */
0016 /* Free Software Foundation, either version 3 of the License, or (at your     */
0017 /* option) any later version.                                                 */
0018 /*                                                                            */
0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0022 /* License for more details.                                                  */
0023 /*                                                                            */
0024 /* You should have received a copy of the GNU Lesser General Public License   */
0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0027 /*                                                                            */
0028 /* The copyright holder's institutional names and contributor's names may not */
0029 /* be used to endorse or promote products derived from this software without  */
0030 /* specific prior written permission of the institution or contributor.       */
0031 /******************************************************************************/
0032 
0033 //------------------------------------------------------------------------------
0034 //! This pure abstract class defines the extended attribute interface and is
0035 //! used by extended attribute plugin writers to implement extended attribute
0036 //! handling. The plugin is loaded via the ofs.xattrlib directive.
0037 //------------------------------------------------------------------------------
0038 
0039 class XrdOucEnv;
0040 class XrdSysError;
0041 
0042 class XrdSysXAttr
0043 {
0044 public:
0045 //------------------------------------------------------------------------------
0046 //! Definition of a structure to hold an attribute name and the size of the
0047 //! name as well as the size of its associated value. The structure is a list
0048 //! and is used as an argument to Free() and is returned by List(). The size of
0049 //! the struct is dynamic and should be sized to hold all of the information.
0050 //------------------------------------------------------------------------------
0051 
0052 struct AList
0053       {AList *Next;    //!< -> next element.
0054        int    Vlen;    //!<   The length of the attribute value;
0055        int    Nlen;    //!<   The length of the attribute name that follows.
0056        char   Name[1]; //!<   Start of the name (size of struct is dynamic)
0057       };
0058 
0059 //------------------------------------------------------------------------------
0060 //! Copy one or all extended attributes from one file to another (a default
0061 //! implementation is supplied).
0062 //!
0063 //! @param  iPath  -> Path of the file whose attribute(s) are to be copied.
0064 //! @param  iFD       If >=0 is the file descriptor of the opened source file.
0065 //! @param  oPath  -> Path of the file to receive the extended attribute(s).
0066 //!                   Duplicate attributes are replaced.
0067 //! @param  oFD       If >=0 is the file descriptor of the opened target file.
0068 //! @param  Aname  -> if nil, the all of the attributes of the source file are
0069 //!                   copied. Otherwise, only the attribute name pointed to by
0070 //!                   Aname is copied. If Aname does not exist or extended
0071 //!                   attributes are not supported, the operation succeeds by
0072 //!                   copying nothing.
0073 //!
0074 //! @return =0     Attribute(s) successfully copied, did not exist, or extended
0075 //!                attributes are not supported for source or target.
0076 //! @return <0     Attribute(s) not copied, the return value is -errno that
0077 //!                describes the reason for the failure.
0078 //------------------------------------------------------------------------------
0079 
0080 virtual int  Copy(const char *iPath, int iFD, const char *oPath, int oFD,
0081                   const char *Aname=0);
0082 
0083 //------------------------------------------------------------------------------
0084 //! Remove an extended attribute.
0085 //!
0086 //! @param  Aname  -> The attribute name.
0087 //! @param  Path   -> Path of the file whose attribute is to be removed.
0088 //! @param  fd        If >=0 is the file descriptor of the opened subject file.
0089 //!
0090 //! @return =0     Attribute was successfully removed.
0091 //! @return <0     Attribute was not removed or does not exist. The return value
0092 //!                is -errno that describes the reason for the failure.
0093 //------------------------------------------------------------------------------
0094 
0095 virtual int  Del(const char *Aname, const char *Path, int fd=-1) = 0;
0096 
0097 //------------------------------------------------------------------------------
0098 //! Release storage occupied by the Alist structure returned by List().
0099 //!
0100 //! @param  aPL    -> The first element of the AList structure.
0101 //------------------------------------------------------------------------------
0102 
0103 virtual void Free(AList *aPL) = 0;
0104 
0105 //------------------------------------------------------------------------------
0106 //! Get an attribute value and its size.
0107 //!
0108 //! @param  Aname  -> The attribute name.
0109 //! @param  Aval   -> Buffer to receive the attribute value.
0110 //! @param  Avsz      Length of the buffer in bytes. Only up to this number of
0111 //!                   bytes should be returned. However, should Avsz be zero
0112 //!                   the the size of the attribute value should be returned
0113 //!                   and the Aval argument should be ignored.
0114 //! @param  Path   -> Path of the file whose attribute is to be fetched.
0115 //! @param  fd     -> If >=0 is the file descriptor of the opened subject file.
0116 //!
0117 //! @return >0     The number of bytes placed in Aval. However, if avsz is zero
0118 //!                then the value is the actual size of the attribute value.
0119 //! @return =0     The attribute exists but has no associated value.
0120 //! @return <0     The attribute value could not be returned. The returned
0121 //!                value is -errno describing the reason.
0122 //------------------------------------------------------------------------------
0123 
0124 virtual int  Get(const char *Aname, void *Aval, int Avsz,
0125                  const char *Path,  int fd=-1) = 0;
0126 
0127 //------------------------------------------------------------------------------
0128 //! Get all of the attributes associated with a file.
0129 //!
0130 //! @param  aPL    -> the pointer to hold the first element of AList. The
0131 //!                   storage occupied by the returned AList must be released
0132 //!                   by calling Free().
0133 //! @param  Path   -> Path of the file whose attributes are t be returned.
0134 //! @param  fd     -> If >=0 is the file descriptor of the opened subject file.
0135 //! @param  getSz     When != 0 then the size of the maximum attribute value
0136 //!                   should be returned. Otherwise, upon success 0 is returned.
0137 //!
0138 //! @return >0     Attributes were returned and aPL points to the first
0139 //!                attribute value.  The returned value is the largest size
0140 //!                of an attribute value encountered (getSz != 0).
0141 //! @return =0     Attributes were returned and aPL points to the first
0142 //!                attribute value (getSz == 0).
0143 //! @return <0     The attribute values could not be returned. The returned
0144 //!                value is -errno describing the reason.
0145 //------------------------------------------------------------------------------
0146 
0147 virtual int  List(AList **aPL, const char *Path, int fd=-1, int getSz=0) = 0;
0148 
0149 //------------------------------------------------------------------------------
0150 //! Set an attribute.
0151 //!
0152 //! @param  Aname  -> The attribute name.
0153 //! @param  Aval   -> Buffer holding the attribute value.
0154 //! @param  Avsz      Length of the buffer in bytes. This is the length of the
0155 //!                   attribute value which may contain binary data.
0156 //! @param  Path   -> Path of the file whose attribute is to be set.
0157 //! @param  fd     -> If >=0 is the file descriptor of the opened subject file.
0158 //! @param  isNew     When !0 then the attribute must not exist (i.e. new).
0159 //!                   Otherwise, if it does exist, the value is replaced. In
0160 //!                   either case, if it does not exist it should be created.
0161 //!
0162 //! @return =0     The attribute was successfully set.
0163 //! @return <0     The attribute values could not be set. The returned
0164 //!                value is -errno describing the reason.
0165 //------------------------------------------------------------------------------
0166 
0167 virtual int  Set(const char *Aname, const void *Aval, int Avsz,
0168                  const char *Path,  int fd=-1,  int isNew=0) = 0;
0169 
0170 //------------------------------------------------------------------------------
0171 //! Establish the error message routing. Unless it's established, no messages
0172 //! should be produced. A default implementation is supplied.
0173 //!
0174 //! @param  errP   -> Pointer to the error message object. If it is a nil
0175 //!                   pointer, no error messages should be produced.
0176 //!
0177 //! @return The previous setting.
0178 //------------------------------------------------------------------------------
0179 
0180 virtual XrdSysError *SetMsgRoute(XrdSysError *errP);
0181 
0182 //------------------------------------------------------------------------------
0183 //! Constructor and Destructor
0184 //------------------------------------------------------------------------------
0185 
0186          XrdSysXAttr() : Say(0) {}
0187 virtual ~XrdSysXAttr() {}
0188 
0189 protected:
0190 
0191 XrdSysError *Say;
0192 };
0193 
0194 /******************************************************************************/
0195 /*       X r d S y s X A t t r   O b j e c t   I n s t a n t i a t o r        */
0196 /******************************************************************************/
0197   
0198 //------------------------------------------------------------------------------
0199 //! Get an instance of a configured XrdSysXAttr object.
0200 //!
0201 //! @param  errP       -> Error message object for error messages.
0202 //! @param  config_fn  -> The name of the config file.
0203 //! @param  parms      -> Any parameters specified on the ofs.xattrlib
0204 //!                       directive. If there are no parameters parms may be 0.
0205 //!
0206 //! @return Success:   -> an instance of the XrdSysXattr object to be used.
0207 //!         Failure:      Null pointer which causes initialization to fail.
0208 //!
0209 //! The object creation function must be declared as an extern "C" function
0210 //! in the plug-in shared library as follows:
0211 //------------------------------------------------------------------------------
0212 
0213 typedef XrdSysXAttr *(*XrdSysGetXAttrObject_t)(XrdSysError  *errP,
0214                                                const char   *config_fn,
0215                                                const char   *parms);
0216 /*!
0217 extern "C" XrdSysXAttr *XrdSysGetXAttrObject(XrdSysError  *errP,
0218                                              const char   *config_fn,
0219                                              const char   *parms);
0220 */
0221 
0222 //------------------------------------------------------------------------------
0223 //! Add an instance of a configured XrdSysXAttr object, wrapping previous one.
0224 //!
0225 //! @param  errP       -> Error message object for error messages.
0226 //! @param  config_fn  -> The name of the config file.
0227 //! @param  parms      -> Any parameters specified on the ofs.xattrlib
0228 //!                       directive. If there are no parameters parms may be 0.
0229 //! @param  envP       -> To environmental information (may be nil).
0230 //! @param  attrP      -> the current attribue object that should be wraped by
0231 //!                       this object.
0232 //!
0233 //! @return Success:   -> an instance of the XrdSysXattr object to be used.
0234 //!         Failure:      Null pointer which causes initialization to fail.
0235 //!
0236 //! The object creation function must be declared as an extern "C" function
0237 //! in the plug-in shared library as follows:
0238 //------------------------------------------------------------------------------
0239 
0240 typedef XrdSysXAttr *(*XrdSysAddXAttrObject_t)(XrdSysError  *errP,
0241                                                const char   *config_fn,
0242                                                const char   *parms,
0243                                                XrdOucEnv    *envP,
0244                                                XrdSysXAttr  *attrP);
0245 /*!
0246     extern "C" XrdSysXAttr *XrdSysAddXAttrObject(XrdSysError  *errP,
0247                                                  const char   *config_fn,
0248                                                  const char   *parms,
0249                                                  XrdOucEnv    *envP,
0250                                                  XrdSysXAttr  *attrP);
0251 */
0252 //------------------------------------------------------------------------------
0253 //! Declare compilation version.
0254 //!
0255 //! Additionally, you *should* declare the xrootd version you used to compile
0256 //! your plug-in. Declare it as:
0257 //------------------------------------------------------------------------------
0258 
0259 /*! #include "XrdVersion.hh"
0260     XrdVERSIONINFO(XrdSysGetXAttrObject,<name>);
0261 
0262     where <name> is a 1- to 15-character unquoted name identifying your plugin.
0263 */
0264 
0265 /******************************************************************************/
0266 /*           X r d S y s X A t t r   I m p l e m e n t a t i o n s            */
0267 /******************************************************************************/
0268 
0269 //------------------------------------------------------------------------------
0270 //! Access the native implementation in libXrdUtils.so:
0271 //!
0272 //! extern XrdSysXAttr  XrdSysXAttrNative;
0273 //------------------------------------------------------------------------------
0274 
0275 //------------------------------------------------------------------------------
0276 //! Access the active implementation in libXrdUtils.so:
0277 //!
0278 //! extern XrdSysXAttr *XrdSysXAttrActive;
0279 //!
0280 //! The active implementatiuon is the one being used. This may be a pointer to
0281 //! the native implementation or to a specified plugin loaded by the OFS layer.
0282 //------------------------------------------------------------------------------
0283 #endif