1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #pragma once
30 
31 /**
32  * @file sys/xattr.h
33  * @brief Extended attribute functions.
34  */
35 
36 #include <linux/xattr.h>
37 #include <sys/cdefs.h>
38 #include <sys/types.h>
39 
40 __BEGIN_DECLS
41 
42 /**
43  * [fsetxattr(2)](http://man7.org/linux/man-pages/man2/fsetxattr.2.html)
44  * sets an extended attribute on the file referred to by the given file
45  * descriptor.
46  *
47  * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`.
48  *
49  * Returns 0 on success and returns -1 and sets `errno` on failure.
50  */
51 int fsetxattr(int __fd, const char* __name, const void* __value, size_t __size, int __flags);
52 
53 /**
54  * [setxattr(2)](http://man7.org/linux/man-pages/man2/setxattr.2.html)
55  * sets an extended attribute on the file referred to by the given path.
56  *
57  * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`.
58  *
59  * Returns 0 on success and returns -1 and sets `errno` on failure.
60  */
61 int setxattr(const char* __path, const char* __name, const void* __value, size_t __size, int __flags);
62 
63 /**
64  * [lsetxattr(2)](http://man7.org/linux/man-pages/man2/lsetxattr.2.html)
65  * sets an extended attribute on the file referred to by the given path, which
66  * is the link itself rather than its target in the case of a symbolic link.
67  *
68  * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`.
69  *
70  * Returns 0 on success and returns -1 and sets `errno` on failure.
71  */
72 int lsetxattr(const char* __path, const char* __name, const void* __value, size_t __size, int __flags);
73 
74 /**
75  * [fgetxattr(2)](http://man7.org/linux/man-pages/man2/fgetxattr.2.html)
76  * gets an extended attribute on the file referred to by the given file
77  * descriptor.
78  *
79  * Returns the non-negative length of the value on success, or
80  * returns -1 and sets `errno` on failure.
81  */
82 ssize_t fgetxattr(int __fd, const char* __name, void* __value, size_t __size);
83 
84 /**
85  * [getxattr(2)](http://man7.org/linux/man-pages/man2/getxattr.2.html)
86  * gets an extended attribute on the file referred to by the given path.
87  *
88  * Returns the non-negative length of the value on success, or
89  * returns -1 and sets `errno` on failure.
90  */
91 ssize_t getxattr(const char* __path, const char* __name, void* __value, size_t __size);
92 
93 /**
94  * [lgetxattr(2)](http://man7.org/linux/man-pages/man2/lgetxattr.2.html)
95  * gets an extended attribute on the file referred to by the given path, which
96  * is the link itself rather than its target in the case of a symbolic link.
97  *
98  * Returns the non-negative length of the value on success, or
99  * returns -1 and sets `errno` on failure.
100  */
101 ssize_t lgetxattr(const char* __path, const char* __name, void* __value, size_t __size);
102 
103 /**
104  * [flistxattr(2)](http://man7.org/linux/man-pages/man2/flistxattr.2.html)
105  * lists the extended attributes on the file referred to by the given file
106  * descriptor.
107  *
108  * Returns the non-negative length of the list on success, or
109  * returns -1 and sets `errno` on failure.
110  */
111 ssize_t flistxattr(int __fd, char* __list, size_t __size);
112 
113 /**
114  * [listxattr(2)](http://man7.org/linux/man-pages/man2/listxattr.2.html)
115  * lists the extended attributes on the file referred to by the given path.
116  *
117  * Returns the non-negative length of the list on success, or
118  * returns -1 and sets `errno` on failure.
119  */
120 ssize_t listxattr(const char* __path, char* __list, size_t __size);
121 
122 /**
123  * [llistxattr(2)](http://man7.org/linux/man-pages/man2/llistxattr.2.html)
124  * lists the extended attributes on the file referred to by the given path, which
125  * is the link itself rather than its target in the case of a symbolic link.
126  *
127  * Returns the non-negative length of the list on success, or
128  * returns -1 and sets `errno` on failure.
129  */
130 ssize_t llistxattr(const char* __path, char* __list, size_t __size);
131 
132 /**
133  * [fremovexattr(2)](http://man7.org/linux/man-pages/man2/fremovexattr.2.html)
134  * removes an extended attribute on the file referred to by the given file
135  * descriptor.
136  *
137  * Returns 0 on success and returns -1 and sets `errno` on failure.
138  */
139 int fremovexattr(int __fd, const char* __name);
140 
141 /**
142  * [lremovexattr(2)](http://man7.org/linux/man-pages/man2/lremovexattr.2.html)
143  * removes an extended attribute on the file referred to by the given path, which
144  * is the link itself rather than its target in the case of a symbolic link.
145  *
146  * Returns 0 on success and returns -1 and sets `errno` on failure.
147  */
148 int lremovexattr(const char* __path, const char* __name);
149 
150 /**
151  * [removexattr(2)](http://man7.org/linux/man-pages/man2/removexattr.2.html)
152  * removes an extended attribute on the file referred to by the given path.
153  *
154  * Returns 0 on success and returns -1 and sets `errno` on failure.
155  */
156 int removexattr(const char* __path, const char* __name);
157 
158 __END_DECLS
159