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