Stephen Smalley | 5eb686d | 2012-01-13 07:45:16 -0500 | [diff] [blame] | 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 | */ |
Elliott Hughes | 5470c18 | 2016-07-22 11:36:17 -0700 | [diff] [blame] | 28 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 29 | #pragma once |
| 30 | |
| 31 | /** |
| 32 | * @file sys/xattr.h |
| 33 | * @brief Extended attribute functions. |
| 34 | */ |
Stephen Smalley | 5eb686d | 2012-01-13 07:45:16 -0500 | [diff] [blame] | 35 | |
Elliott Hughes | 203e13d | 2016-07-22 14:56:18 -0700 | [diff] [blame] | 36 | #include <sys/cdefs.h> |
Elliott Hughes | 414dd2d | 2024-10-16 14:48:30 +0000 | [diff] [blame] | 37 | |
| 38 | #include <linux/xattr.h> |
Stephen Smalley | 5eb686d | 2012-01-13 07:45:16 -0500 | [diff] [blame] | 39 | #include <sys/types.h> |
| 40 | |
| 41 | __BEGIN_DECLS |
| 42 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 43 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 44 | * [fsetxattr(2)](https://man7.org/linux/man-pages/man2/fsetxattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 45 | * sets an extended attribute on the file referred to by the given file |
| 46 | * descriptor. |
| 47 | * |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 48 | * 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 Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 52 | * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`. |
| 53 | * |
| 54 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 55 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 56 | int fsetxattr(int __fd, const char* _Nonnull __name, const void* _Nullable __value, size_t __size, int __flags); |
Stephen Smalley | 5eb686d | 2012-01-13 07:45:16 -0500 | [diff] [blame] | 57 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 58 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 59 | * [setxattr(2)](https://man7.org/linux/man-pages/man2/setxattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 60 | * sets an extended attribute on the file referred to by the given path. |
| 61 | * |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 62 | * 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 Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 66 | * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`. |
| 67 | * |
| 68 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 69 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 70 | int setxattr(const char* _Nonnull __path, const char* _Nonnull __name, const void* _Nullable __value, size_t __size, int __flags); |
Stephen Smalley | 5eb686d | 2012-01-13 07:45:16 -0500 | [diff] [blame] | 71 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 72 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 73 | * [lsetxattr(2)](https://man7.org/linux/man-pages/man2/lsetxattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 74 | * 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 | * |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 77 | * 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 Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 81 | * Valid flags are `XATTR_CREATE` and `XATTR_REPLACE`. |
| 82 | * |
| 83 | * Returns 0 on success and returns -1 and sets `errno` on failure. |
| 84 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 85 | int lsetxattr(const char* _Nonnull __path, const char* _Nonnull __name, const void* _Nullable __value, size_t __size, int __flags); |
Stephen Smalley | 5eb686d | 2012-01-13 07:45:16 -0500 | [diff] [blame] | 86 | |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 87 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 88 | * [fgetxattr(2)](https://man7.org/linux/man-pages/man2/fgetxattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 89 | * gets an extended attribute on the file referred to by the given file |
| 90 | * descriptor. |
| 91 | * |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 92 | * A `size` of 0 can be used to query the current length, in which case `value` is ignored and may be null. |
| 93 | * |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 94 | * Returns the non-negative length of the value on success, or |
| 95 | * returns -1 and sets `errno` on failure. |
| 96 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 97 | ssize_t fgetxattr(int __fd, const char* _Nonnull __name, void* _Nullable __value, size_t __size); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 98 | |
| 99 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 100 | * [getxattr(2)](https://man7.org/linux/man-pages/man2/getxattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 101 | * gets an extended attribute on the file referred to by the given path. |
| 102 | * |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 103 | * A `size` of 0 can be used to query the current length, in which case `value` is ignored and may be null. |
| 104 | * |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 105 | * Returns the non-negative length of the value on success, or |
| 106 | * returns -1 and sets `errno` on failure. |
| 107 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 108 | ssize_t getxattr(const char* _Nonnull __path, const char* _Nonnull __name, void* _Nullable __value, size_t __size); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 111 | * [lgetxattr(2)](https://man7.org/linux/man-pages/man2/lgetxattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 112 | * 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 | * |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 115 | * A `size` of 0 can be used to query the current length, in which case `value` is ignored and may be null. |
| 116 | * |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 117 | * Returns the non-negative length of the value on success, or |
| 118 | * returns -1 and sets `errno` on failure. |
| 119 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 120 | ssize_t lgetxattr(const char* _Nonnull __path, const char* _Nonnull __name, void* _Nullable __value, size_t __size); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 123 | * [flistxattr(2)](https://man7.org/linux/man-pages/man2/flistxattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 124 | * lists the extended attributes on the file referred to by the given file |
| 125 | * descriptor. |
| 126 | * |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 127 | * A `size` of 0 can be used to query the current length, in which case `list` is ignored and may be null. |
| 128 | * |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 129 | * Returns the non-negative length of the list on success, or |
| 130 | * returns -1 and sets `errno` on failure. |
| 131 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 132 | ssize_t flistxattr(int __fd, char* _Nullable __list, size_t __size); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 133 | |
| 134 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 135 | * [listxattr(2)](https://man7.org/linux/man-pages/man2/listxattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 136 | * lists the extended attributes on the file referred to by the given path. |
| 137 | * |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 138 | * A `size` of 0 can be used to query the current length, in which case `list` is ignored and may be null. |
| 139 | * |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 140 | * Returns the non-negative length of the list on success, or |
| 141 | * returns -1 and sets `errno` on failure. |
| 142 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 143 | ssize_t listxattr(const char* _Nonnull __path, char* _Nullable __list, size_t __size); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 146 | * [llistxattr(2)](https://man7.org/linux/man-pages/man2/llistxattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 147 | * 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 | * |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 150 | * A `size` of 0 can be used to query the current length, in which case `list` is ignored and may be null. |
| 151 | * |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 152 | * Returns the non-negative length of the list on success, or |
| 153 | * returns -1 and sets `errno` on failure. |
| 154 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 155 | ssize_t llistxattr(const char* _Nonnull __path, char* _Nullable __list, size_t __size); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 158 | * [fremovexattr(2)](https://man7.org/linux/man-pages/man2/fremovexattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 159 | * 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 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 164 | int fremovexattr(int __fd, const char* _Nonnull __name); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 165 | |
| 166 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 167 | * [lremovexattr(2)](https://man7.org/linux/man-pages/man2/lremovexattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 168 | * 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 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 173 | int lremovexattr(const char* _Nonnull __path, const char* _Nonnull __name); |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 174 | |
| 175 | /** |
Elliott Hughes | bbd39aa | 2024-08-13 20:59:16 +0000 | [diff] [blame] | 176 | * [removexattr(2)](https://man7.org/linux/man-pages/man2/removexattr.2.html) |
Elliott Hughes | b361e68 | 2019-11-01 16:47:46 -0700 | [diff] [blame] | 177 | * 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 | */ |
zijunzhao | 9f6b4ca | 2023-05-20 01:16:32 +0000 | [diff] [blame] | 181 | int removexattr(const char* _Nonnull __path, const char* _Nonnull __name); |
Stephen Smalley | 5eb686d | 2012-01-13 07:45:16 -0500 | [diff] [blame] | 182 | |
| 183 | __END_DECLS |