blob: 745f50c12ae86c873a5af74a98e8a0155d91106f [file] [log] [blame]
Stephen Smalley5eb686d2012-01-13 07:45:16 -05001/*
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 */
Elliott Hughes5470c182016-07-22 11:36:17 -070028
Elliott Hughesb361e682019-11-01 16:47:46 -070029#pragma once
30
31/**
32 * @file sys/xattr.h
33 * @brief Extended attribute functions.
34 */
Stephen Smalley5eb686d2012-01-13 07:45:16 -050035
Elliott Hughes5470c182016-07-22 11:36:17 -070036#include <linux/xattr.h>
Elliott Hughes203e13d2016-07-22 14:56:18 -070037#include <sys/cdefs.h>
Stephen Smalley5eb686d2012-01-13 07:45:16 -050038#include <sys/types.h>
39
40__BEGIN_DECLS
41
Elliott Hughesb361e682019-11-01 16:47:46 -070042/**
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 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +000047 * A `size` of 0 can be used to set an empty value, in which case `value` is
48 * ignored and may be null. Setting an xattr to an empty value is not the same
49 * as removing an xattr; see removexattr() for the latter operation.
50 *
Elliott Hughesb361e682019-11-01 16:47:46 -070051 * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`.
52 *
53 * Returns 0 on success and returns -1 and sets `errno` on failure.
54 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +000055int fsetxattr(int __fd, const char* _Nonnull __name, const void* _Nullable __value, size_t __size, int __flags);
Stephen Smalley5eb686d2012-01-13 07:45:16 -050056
Elliott Hughesb361e682019-11-01 16:47:46 -070057/**
58 * [setxattr(2)](http://man7.org/linux/man-pages/man2/setxattr.2.html)
59 * sets an extended attribute on the file referred to by the given path.
60 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +000061 * A `size` of 0 can be used to set an empty value, in which case `value` is
62 * ignored and may be null. Setting an xattr to an empty value is not the same
63 * as removing an xattr; see removexattr() for the latter operation.
64 *
Elliott Hughesb361e682019-11-01 16:47:46 -070065 * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`.
66 *
67 * Returns 0 on success and returns -1 and sets `errno` on failure.
68 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +000069int setxattr(const char* _Nonnull __path, const char* _Nonnull __name, const void* _Nullable __value, size_t __size, int __flags);
Stephen Smalley5eb686d2012-01-13 07:45:16 -050070
Elliott Hughesb361e682019-11-01 16:47:46 -070071/**
72 * [lsetxattr(2)](http://man7.org/linux/man-pages/man2/lsetxattr.2.html)
73 * sets an extended attribute on the file referred to by the given path, which
74 * is the link itself rather than its target in the case of a symbolic link.
75 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +000076 * A `size` of 0 can be used to set an empty value, in which case `value` is
77 * ignored and may be null. Setting an xattr to an empty value is not the same
78 * as removing an xattr; see removexattr() for the latter operation.
79 *
Elliott Hughesb361e682019-11-01 16:47:46 -070080 * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`.
81 *
82 * Returns 0 on success and returns -1 and sets `errno` on failure.
83 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +000084int lsetxattr(const char* _Nonnull __path, const char* _Nonnull __name, const void* _Nullable __value, size_t __size, int __flags);
Stephen Smalley5eb686d2012-01-13 07:45:16 -050085
Elliott Hughesb361e682019-11-01 16:47:46 -070086/**
87 * [fgetxattr(2)](http://man7.org/linux/man-pages/man2/fgetxattr.2.html)
88 * gets an extended attribute on the file referred to by the given file
89 * descriptor.
90 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +000091 * A `size` of 0 can be used to query the current length, in which case `value` is ignored and may be null.
92 *
Elliott Hughesb361e682019-11-01 16:47:46 -070093 * Returns the non-negative length of the value on success, or
94 * returns -1 and sets `errno` on failure.
95 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +000096ssize_t fgetxattr(int __fd, const char* _Nonnull __name, void* _Nullable __value, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -070097
98/**
99 * [getxattr(2)](http://man7.org/linux/man-pages/man2/getxattr.2.html)
100 * gets an extended attribute on the file referred to by the given path.
101 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000102 * A `size` of 0 can be used to query the current length, in which case `value` is ignored and may be null.
103 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700104 * Returns the non-negative length of the value on success, or
105 * returns -1 and sets `errno` on failure.
106 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000107ssize_t getxattr(const char* _Nonnull __path, const char* _Nonnull __name, void* _Nullable __value, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700108
109/**
110 * [lgetxattr(2)](http://man7.org/linux/man-pages/man2/lgetxattr.2.html)
111 * gets an extended attribute on the file referred to by the given path, which
112 * is the link itself rather than its target in the case of a symbolic link.
113 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000114 * A `size` of 0 can be used to query the current length, in which case `value` is ignored and may be null.
115 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700116 * Returns the non-negative length of the value on success, or
117 * returns -1 and sets `errno` on failure.
118 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000119ssize_t lgetxattr(const char* _Nonnull __path, const char* _Nonnull __name, void* _Nullable __value, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700120
121/**
122 * [flistxattr(2)](http://man7.org/linux/man-pages/man2/flistxattr.2.html)
123 * lists the extended attributes on the file referred to by the given file
124 * descriptor.
125 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000126 * A `size` of 0 can be used to query the current length, in which case `list` is ignored and may be null.
127 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700128 * Returns the non-negative length of the list on success, or
129 * returns -1 and sets `errno` on failure.
130 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000131ssize_t flistxattr(int __fd, char* _Nullable __list, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700132
133/**
134 * [listxattr(2)](http://man7.org/linux/man-pages/man2/listxattr.2.html)
135 * lists the extended attributes on the file referred to by the given path.
136 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000137 * A `size` of 0 can be used to query the current length, in which case `list` is ignored and may be null.
138 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700139 * Returns the non-negative length of the list on success, or
140 * returns -1 and sets `errno` on failure.
141 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000142ssize_t listxattr(const char* _Nonnull __path, char* _Nullable __list, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700143
144/**
145 * [llistxattr(2)](http://man7.org/linux/man-pages/man2/llistxattr.2.html)
146 * lists the extended attributes on the file referred to by the given path, which
147 * is the link itself rather than its target in the case of a symbolic link.
148 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000149 * A `size` of 0 can be used to query the current length, in which case `list` is ignored and may be null.
150 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700151 * Returns the non-negative length of the list on success, or
152 * returns -1 and sets `errno` on failure.
153 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000154ssize_t llistxattr(const char* _Nonnull __path, char* _Nullable __list, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700155
156/**
157 * [fremovexattr(2)](http://man7.org/linux/man-pages/man2/fremovexattr.2.html)
158 * removes an extended attribute on the file referred to by the given file
159 * descriptor.
160 *
161 * Returns 0 on success and returns -1 and sets `errno` on failure.
162 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000163int fremovexattr(int __fd, const char* _Nonnull __name);
Elliott Hughesb361e682019-11-01 16:47:46 -0700164
165/**
166 * [lremovexattr(2)](http://man7.org/linux/man-pages/man2/lremovexattr.2.html)
167 * removes an extended attribute on the file referred to by the given path, which
168 * is the link itself rather than its target in the case of a symbolic link.
169 *
170 * Returns 0 on success and returns -1 and sets `errno` on failure.
171 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000172int lremovexattr(const char* _Nonnull __path, const char* _Nonnull __name);
Elliott Hughesb361e682019-11-01 16:47:46 -0700173
174/**
175 * [removexattr(2)](http://man7.org/linux/man-pages/man2/removexattr.2.html)
176 * removes an extended attribute on the file referred to by the given path.
177 *
178 * Returns 0 on success and returns -1 and sets `errno` on failure.
179 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000180int removexattr(const char* _Nonnull __path, const char* _Nonnull __name);
Stephen Smalley5eb686d2012-01-13 07:45:16 -0500181
182__END_DECLS