(root)/
attr-2.5.1/
include/
attributes.h
       1  /*
       2   * Copyright (c) 2001-2002,2004 Silicon Graphics, Inc.
       3   * All Rights Reserved.
       4   *
       5   * This program is free software: you can redistribute it and/or modify it
       6   * under the terms of the GNU Lesser General Public License as published by
       7   * the Free Software Foundation, either version 2.1 of the License, or
       8   * (at your option) any later version.
       9   *
      10   * This program is distributed in the hope that it will be useful,
      11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13   * GNU Lesser General Public License for more details.
      14   *
      15   * You should have received a copy of the GNU Lesser General Public License
      16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17   */
      18  #ifndef __ATTRIBUTES_H__
      19  #define	__ATTRIBUTES_H__
      20  
      21  #ifdef __cplusplus
      22  extern "C" {
      23  #endif
      24  
      25  #include <stdint.h>
      26  
      27  #ifndef ENOATTR
      28  # define ENOATTR ENODATA
      29  #endif
      30  
      31  /*
      32   *	An almost-IRIX-compatible extended attributes API
      33   *	(the IRIX attribute "list" operation is missing, added ATTR_SECURE).
      34   */
      35  
      36  /*
      37   * The maximum size (into the kernel or returned from the kernel) of an
      38   * attribute value or the buffer used for an attr_list() call.  Larger
      39   * sizes will result in an E2BIG return code.
      40   */
      41  #define ATTR_MAX_VALUELEN	(64*1024)	/* max length of a value */
      42  
      43  
      44  /*
      45   * Flags that can be used with any of the simple attribute calls.
      46   * All desired flags should be bit-wise OR'ed together.
      47   */
      48  #define ATTR_DONTFOLLOW	0x0001	/* do not follow symlinks for a pathname */
      49  #define ATTR_ROOT	0x0002	/* use root namespace attributes in op */
      50  #define ATTR_TRUST	0x0004	/* tell server we can be trusted to properly
      51  				   handle extended attributes */
      52  #define ATTR_SECURE	0x0008	/* use security namespace attributes in op */
      53  
      54  /*
      55   * Additional flags that can be used with the set() attribute call.
      56   * All desired flags (from both lists) should be bit-wise OR'ed together.
      57   */
      58  #define ATTR_CREATE	0x0010	/* pure create: fail if attr already exists */
      59  #define ATTR_REPLACE	0x0020	/* pure set: fail if attr does not exist */
      60  
      61  /*
      62   * Define how lists of attribute names are returned to the user from
      63   * the attr_list() call.  A large, 32bit aligned, buffer is passed in
      64   * along with its size.  We put an array of offsets at the top that each
      65   * reference an attrlist_ent_t and pack the attrlist_ent_t's at the bottom.
      66   */
      67  typedef struct attrlist {
      68  	int32_t		al_count;	/* number of entries in attrlist */
      69  	int32_t		al_more;	/* T/F: more attrs (do call again) */
      70  	int32_t		al_offset[1];	/* byte offsets of attrs [var-sized] */
      71  } attrlist_t;
      72  
      73  /*
      74   * Show the interesting info about one attribute.  This is what the
      75   * al_offset[i] entry points to.
      76   */
      77  typedef struct attrlist_ent {	/* data from attr_list() */
      78  	uint32_t	a_valuelen;	/* number bytes in value of attr */
      79  	char		a_name[1];	/* attr name (NULL terminated) */
      80  } attrlist_ent_t;
      81  
      82  /*
      83   * Given a pointer to the (char*) buffer containing the attr_list() result,
      84   * and an index, return a pointer to the indicated attribute in the buffer.
      85   */
      86  #define	ATTR_ENTRY(buffer, index)		\
      87  	((attrlist_ent_t *)			\
      88  	 &((char *)buffer)[ ((attrlist_t *)(buffer))->al_offset[index] ])
      89  
      90  /*
      91   * Implement a "cursor" for use in successive attr_list() calls.
      92   * It provides a way to find the last attribute that was returned in the
      93   * last attr_list() call so that we can get the next one without missing
      94   * any.  This should be zeroed before use and whenever it is desired to
      95   * start over from the beginning of the attribute list.  The only valid
      96   * operation on a cursor is to zero it.
      97   */
      98  typedef struct attrlist_cursor {
      99  	uint32_t	opaque[4];	/* an opaque cookie */
     100  } attrlist_cursor_t;
     101  
     102  /*
     103   * Multi-attribute operation vector.
     104   */
     105  typedef struct attr_multiop {
     106  	int32_t	am_opcode;	/* operation to perform (ATTR_OP_GET, etc.) */
     107  	int32_t	am_error;	/* [out arg] result of this sub-op (an errno) */
     108  	char	*am_attrname;	/* attribute name to work with */
     109  	char	*am_attrvalue;	/* [in/out arg] attribute value (raw bytes) */
     110  	int32_t	am_length;	/* [in/out arg] length of value */
     111  	int32_t	am_flags;	/* flags (bit-wise OR of #defines above) */
     112  } attr_multiop_t;
     113  #define	ATTR_MAX_MULTIOPS	128	/* max number ops in an oplist array */
     114  
     115  /*
     116   * Valid values of am_opcode.
     117   */
     118  #define ATTR_OP_GET	1	/* return the indicated attr's value */
     119  #define ATTR_OP_SET	2	/* set/create the indicated attr/value pair */
     120  #define ATTR_OP_REMOVE	3	/* remove the indicated attr */
     121  
     122  /*
     123   * Get the value of an attribute.
     124   * Valuelength must be set to the maximum size of the value buffer, it will
     125   * be set to the actual number of bytes used in the value buffer upon return.
     126   * The return value is -1 on error (w/errno set appropriately), 0 on success.
     127   */
     128  EXPORT int attr_get (const char *__path, const char *__attrname,
     129  			char *__attrvalue, int *__valuelength, int __flags)
     130  	__attribute__ ((deprecated ("Use getxattr or lgetxattr instead")));
     131  EXPORT int attr_getf (int __fd, const char *__attrname, char *__attrvalue,
     132  			int *__valuelength, int __flags)
     133  	__attribute__ ((deprecated ("Use fgetxattr instead")));
     134  
     135  /*
     136   * Set the value of an attribute, creating the attribute if necessary.
     137   * The return value is -1 on error (w/errno set appropriately), 0 on success.
     138   */
     139  EXPORT int attr_set (const char *__path, const char *__attrname,
     140  			const char *__attrvalue, const int __valuelength,
     141  			int __flags)
     142  	__attribute__ ((deprecated ("Use setxattr or lsetxattr instead")));
     143  EXPORT int attr_setf (int __fd, const char *__attrname,
     144  			const char *__attrvalue, const int __valuelength,
     145  			int __flags)
     146  	__attribute__ ((deprecated ("Use fsetxattr instead")));
     147  
     148  /*
     149   * Remove an attribute.
     150   * The return value is -1 on error (w/errno set appropriately), 0 on success.
     151   */
     152  EXPORT int attr_remove (const char *__path, const char *__attrname,
     153  			int __flags)
     154  	__attribute__ ((deprecated ("Use removexattr or lremovexattr instead")));
     155  EXPORT int attr_removef (int __fd, const char *__attrname, int __flags)
     156  	__attribute__ ((deprecated ("Use fremovexattr instead")));
     157  
     158  /*
     159   * List the names and sizes of the values of all the attributes of an object.
     160   * "Cursor" must be allocated and zeroed before the first call, it is used
     161   * to maintain context between system calls if all the attribute names won't
     162   * fit into the buffer on the first system call.
     163   * The return value is -1 on error (w/errno set appropriately), 0 on success.
     164   */
     165  EXPORT int attr_list(const char *__path, char *__buffer, const int __buffersize,
     166  		int __flags, attrlist_cursor_t *__cursor)
     167  	__attribute__ ((deprecated ("Use listxattr or llistxattr instead")));
     168  EXPORT int attr_listf(int __fd, char *__buffer, const int __buffersize,
     169  		int __flags, attrlist_cursor_t *__cursor)
     170  	__attribute__ ((deprecated ("Use flistxattr instead")));
     171  
     172  /*
     173   * Operate on multiple attributes of the same object simultaneously.
     174   *
     175   * This call will save on system call overhead when many attributes are
     176   * going to be operated on.
     177   *
     178   * The return value is -1 on error (w/errno set appropriately), 0 on success.
     179   * Note that this call will not return -1 as a result of failure of any
     180   * of the sub-operations, their return value is stored in each element
     181   * of the operation array.  This call will return -1 for a failure of the
     182   * call as a whole, eg: if the pathname doesn't exist, or the fd is bad.
     183   *
     184   * The semantics and allowable values for the fields in a attr_multiop_t
     185   * are the same as the semantics and allowable values for the arguments to
     186   * the corresponding "simple" attribute interface.  For example: the args
     187   * to a ATTR_OP_GET are the same as the args to an attr_get() call.
     188   */
     189  EXPORT int attr_multi (const char *__path, attr_multiop_t *__oplist,
     190  			int __count, int __flags)
     191  	__attribute__ ((deprecated ("Use getxattr, setxattr, listxattr, removexattr instead")));
     192  EXPORT int attr_multif (int __fd, attr_multiop_t *__oplist,
     193  			int __count, int __flags)
     194  	__attribute__ ((deprecated ("Use getxattr, setxattr, listxattr, removexattr instead")));
     195  
     196  #ifdef __cplusplus
     197  }
     198  #endif
     199  
     200  #endif	/* __ATTRIBUTES_H__ */