blob: ebe4eb86bf3816282679244439bb37adf647b30b [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 Hughes203e13d2016-07-22 14:56:18 -070036#include <sys/cdefs.h>
Elliott Hughes414dd2d2024-10-16 14:48:30 +000037
38#include <linux/xattr.h>
Stephen Smalley5eb686d2012-01-13 07:45:16 -050039#include <sys/types.h>
40
41__BEGIN_DECLS
42
Elliott Hughesb361e682019-11-01 16:47:46 -070043/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000044 * [fsetxattr(2)](https://man7.org/linux/man-pages/man2/fsetxattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -070045 * sets an extended attribute on the file referred to by the given file
46 * descriptor.
47 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +000048 * A `size` of 0 can be used to set an empty value, in which case `value` is
49 * ignored and may be null. Setting an xattr to an empty value is not the same
50 * as removing an xattr; see removexattr() for the latter operation.
51 *
Elliott Hughesb361e682019-11-01 16:47:46 -070052 * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`.
53 *
54 * Returns 0 on success and returns -1 and sets `errno` on failure.
55 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +000056int fsetxattr(int __fd, const char* _Nonnull __name, const void* _Nullable __value, size_t __size, int __flags);
Stephen Smalley5eb686d2012-01-13 07:45:16 -050057
Elliott Hughesb361e682019-11-01 16:47:46 -070058/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000059 * [setxattr(2)](https://man7.org/linux/man-pages/man2/setxattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -070060 * sets an extended attribute on the file referred to by the given path.
61 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +000062 * A `size` of 0 can be used to set an empty value, in which case `value` is
63 * ignored and may be null. Setting an xattr to an empty value is not the same
64 * as removing an xattr; see removexattr() for the latter operation.
65 *
Elliott Hughesb361e682019-11-01 16:47:46 -070066 * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`.
67 *
68 * Returns 0 on success and returns -1 and sets `errno` on failure.
69 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +000070int 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 -050071
Elliott Hughesb361e682019-11-01 16:47:46 -070072/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000073 * [lsetxattr(2)](https://man7.org/linux/man-pages/man2/lsetxattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -070074 * sets an extended attribute on the file referred to by the given path, which
75 * is the link itself rather than its target in the case of a symbolic link.
76 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +000077 * A `size` of 0 can be used to set an empty value, in which case `value` is
78 * ignored and may be null. Setting an xattr to an empty value is not the same
79 * as removing an xattr; see removexattr() for the latter operation.
80 *
Elliott Hughesb361e682019-11-01 16:47:46 -070081 * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`.
82 *
83 * Returns 0 on success and returns -1 and sets `errno` on failure.
84 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +000085int 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 -050086
Elliott Hughesb361e682019-11-01 16:47:46 -070087/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +000088 * [fgetxattr(2)](https://man7.org/linux/man-pages/man2/fgetxattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -070089 * gets an extended attribute on the file referred to by the given file
90 * descriptor.
91 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +000092 * A `size` of 0 can be used to query the current length, in which case `value` is ignored and may be null.
93 *
Elliott Hughesb361e682019-11-01 16:47:46 -070094 * Returns the non-negative length of the value on success, or
95 * returns -1 and sets `errno` on failure.
96 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +000097ssize_t fgetxattr(int __fd, const char* _Nonnull __name, void* _Nullable __value, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -070098
99/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000100 * [getxattr(2)](https://man7.org/linux/man-pages/man2/getxattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -0700101 * gets an extended attribute on the file referred to by the given path.
102 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000103 * A `size` of 0 can be used to query the current length, in which case `value` is ignored and may be null.
104 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700105 * Returns the non-negative length of the value on success, or
106 * returns -1 and sets `errno` on failure.
107 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000108ssize_t getxattr(const char* _Nonnull __path, const char* _Nonnull __name, void* _Nullable __value, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700109
110/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000111 * [lgetxattr(2)](https://man7.org/linux/man-pages/man2/lgetxattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -0700112 * gets an extended attribute on the file referred to by the given path, which
113 * is the link itself rather than its target in the case of a symbolic link.
114 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000115 * A `size` of 0 can be used to query the current length, in which case `value` is ignored and may be null.
116 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700117 * Returns the non-negative length of the value on success, or
118 * returns -1 and sets `errno` on failure.
119 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000120ssize_t lgetxattr(const char* _Nonnull __path, const char* _Nonnull __name, void* _Nullable __value, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700121
122/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000123 * [flistxattr(2)](https://man7.org/linux/man-pages/man2/flistxattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -0700124 * lists the extended attributes on the file referred to by the given file
125 * descriptor.
126 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000127 * A `size` of 0 can be used to query the current length, in which case `list` is ignored and may be null.
128 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700129 * Returns the non-negative length of the list on success, or
130 * returns -1 and sets `errno` on failure.
131 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000132ssize_t flistxattr(int __fd, char* _Nullable __list, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700133
134/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000135 * [listxattr(2)](https://man7.org/linux/man-pages/man2/listxattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -0700136 * lists the extended attributes on the file referred to by the given path.
137 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000138 * A `size` of 0 can be used to query the current length, in which case `list` is ignored and may be null.
139 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700140 * Returns the non-negative length of the list on success, or
141 * returns -1 and sets `errno` on failure.
142 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000143ssize_t listxattr(const char* _Nonnull __path, char* _Nullable __list, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700144
145/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000146 * [llistxattr(2)](https://man7.org/linux/man-pages/man2/llistxattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -0700147 * lists the extended attributes on the file referred to by the given path, which
148 * is the link itself rather than its target in the case of a symbolic link.
149 *
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000150 * A `size` of 0 can be used to query the current length, in which case `list` is ignored and may be null.
151 *
Elliott Hughesb361e682019-11-01 16:47:46 -0700152 * Returns the non-negative length of the list on success, or
153 * returns -1 and sets `errno` on failure.
154 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000155ssize_t llistxattr(const char* _Nonnull __path, char* _Nullable __list, size_t __size);
Elliott Hughesb361e682019-11-01 16:47:46 -0700156
157/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000158 * [fremovexattr(2)](https://man7.org/linux/man-pages/man2/fremovexattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -0700159 * removes an extended attribute on the file referred to by the given file
160 * descriptor.
161 *
162 * Returns 0 on success and returns -1 and sets `errno` on failure.
163 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000164int fremovexattr(int __fd, const char* _Nonnull __name);
Elliott Hughesb361e682019-11-01 16:47:46 -0700165
166/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000167 * [lremovexattr(2)](https://man7.org/linux/man-pages/man2/lremovexattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -0700168 * removes an extended attribute on the file referred to by the given path, which
169 * is the link itself rather than its target in the case of a symbolic link.
170 *
171 * Returns 0 on success and returns -1 and sets `errno` on failure.
172 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000173int lremovexattr(const char* _Nonnull __path, const char* _Nonnull __name);
Elliott Hughesb361e682019-11-01 16:47:46 -0700174
175/**
Elliott Hughesbbd39aa2024-08-13 20:59:16 +0000176 * [removexattr(2)](https://man7.org/linux/man-pages/man2/removexattr.2.html)
Elliott Hughesb361e682019-11-01 16:47:46 -0700177 * removes an extended attribute on the file referred to by the given path.
178 *
179 * Returns 0 on success and returns -1 and sets `errno` on failure.
180 */
zijunzhao9f6b4ca2023-05-20 01:16:32 +0000181int removexattr(const char* _Nonnull __path, const char* _Nonnull __name);
Stephen Smalley5eb686d2012-01-13 07:45:16 -0500182
183__END_DECLS