Test driver for fsetxattr and fgetxattr. */
| 175 | |
| 176 | /* Test driver for fsetxattr and fgetxattr. */ |
| 177 | static int test_fxattr(void) |
| 178 | { |
| 179 | int rc = 0; |
| 180 | size_t value_len; |
| 181 | struct io_uring ring; |
| 182 | char value[XATTR_SIZE]; |
| 183 | |
| 184 | /* Init io-uring queue. */ |
| 185 | int ret = io_uring_queue_init(QUEUE_DEPTH, &ring, 0); |
| 186 | if (ret) { |
| 187 | fprintf(stderr, "child: ring setup failed: %d\n", ret); |
| 188 | return -1; |
| 189 | } |
| 190 | |
| 191 | /* Create the test file. */ |
| 192 | int fd = open(FILENAME, O_CREAT | O_RDWR, 0644); |
| 193 | if (fd < 0) { |
| 194 | fprintf(stderr, "Error: cannot open file: ret=%d\n", fd); |
| 195 | return -1; |
| 196 | } |
| 197 | |
| 198 | /* Test writing attributes. */ |
| 199 | if (io_uring_fsetxattr(&ring, fd, KEY1, VALUE1, strlen(VALUE1), 0) < 0) { |
| 200 | if (no_xattr) { |
| 201 | fprintf(stdout, "No xattr support, skipping\n"); |
| 202 | goto Exit; |
| 203 | } |
| 204 | fprintf(stderr, "Error fsetxattr cannot write key1\n"); |
| 205 | rc = -1; |
| 206 | goto Exit; |
| 207 | } |
| 208 | |
| 209 | if (io_uring_fsetxattr(&ring, fd, KEY2, VALUE2, strlen(VALUE2), 0) < 0) { |
| 210 | fprintf(stderr, "Error fsetxattr cannot write key1\n"); |
| 211 | rc = -1; |
| 212 | goto Exit; |
| 213 | } |
| 214 | |
| 215 | /* Test reading attributes. */ |
| 216 | value_len = io_uring_fgetxattr(&ring, fd, KEY1, value, XATTR_SIZE); |
| 217 | if (value_len != strlen(VALUE1) || strncmp(value, VALUE1, value_len)) { |
| 218 | fprintf(stderr, "Error: fgetxattr expected value: %s, returned value: %s\n", VALUE1, value); |
| 219 | rc = -1; |
| 220 | goto Exit; |
| 221 | } |
| 222 | |
| 223 | value_len = io_uring_fgetxattr(&ring, fd, KEY2, value, XATTR_SIZE); |
| 224 | if (value_len != strlen(VALUE2) || strncmp(value, VALUE2, value_len)) { |
| 225 | fprintf(stderr, "Error: fgetxattr expected value: %s, returned value: %s\n", VALUE2, value); |
| 226 | rc = -1; |
| 227 | goto Exit; |
| 228 | } |
| 229 | |
| 230 | /* Cleanup. */ |
| 231 | Exit: |
| 232 | close(fd); |
| 233 | unlink(FILENAME); |
| 234 |
no test coverage detected