clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name registry.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -fcoverage-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -resource-dir /usr/bin/../lib/clang/22 -include /__w/nvme-cli/nvme-cli/.build-ci/nvme-config.h -I libnvme/src/libnvme3.so.1.0.0.p -I libnvme/src -I ../libnvme/src -I ccan -I ../ccan -I . -I .. -I shared -I ../shared -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -U NDEBUG -internal-isystem /usr/bin/../lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=gnu99 -ferror-limit 19 -fvisibility=hidden -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-opt-analyze-headers -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /__w/nvme-cli/nvme-cli/.build-ci/scan-results/2026-08-08-045408-589-1 -x c ../libnvme/src/nvme/registry.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #include <dirent.h> |
| 10 | #include <errno.h> |
| 11 | #include <fcntl.h> |
| 12 | #include <limits.h> |
| 13 | #include <stdbool.h> |
| 14 | #include <stdio.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <string.h> |
| 17 | #include <sys/stat.h> |
| 18 | #include <sys/types.h> |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | #include <compiler-attributes.h> |
| 22 | #include <fs-util.h> |
| 23 | #include <io-util.h> |
| 24 | |
| 25 | #include "cleanup.h" |
| 26 | #include "private.h" |
| 27 | #include "private-fabrics.h" |
| 28 | #include "registry.h" |
| 29 | |
| 30 | #define REGISTRY_DIR_DEFAULT RUNDIR "/nvme/registry" |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | static const char *registry_dir(struct libnvme_global_ctx *ctx) |
| 41 | { |
| 42 | static const char *cache; |
| 43 | static char buf[PATH_MAX]; |
| 44 | int n; |
| 45 | |
| 46 | if (cache) |
| 47 | return cache; |
| 48 | if (!ctx->test_base_dir) { |
| 49 | cache = REGISTRY_DIR_DEFAULT; |
| 50 | return cache; |
| 51 | } |
| 52 | |
| 53 | n = snprintf(buf, sizeof(buf), "%s/registry", ctx->test_base_dir); |
| 54 | cache = (n > 0 && (size_t)n < sizeof(buf)) ? buf : REGISTRY_DIR_DEFAULT; |
| 55 | return cache; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | static char *registry_path(struct libnvme_global_ctx *ctx, const char *device, |
| 64 | const char *attr) |
| 65 | { |
| 66 | char *path = NULL; |
| 67 | int n; |
| 68 | |
| 69 | if (attr) |
| 70 | n = asprintf(&path, "%s/%s/%s", registry_dir(ctx), |
| 71 | device, attr); |
| 72 | else |
| 73 | n = asprintf(&path, "%s/%s", registry_dir(ctx), device); |
| 74 | return n < 0 ? NULL : path; |
| 75 | } |
| 76 | |
| 77 | static int ensure_device_dir(struct libnvme_global_ctx *ctx, const char *device) |
| 78 | { |
| 79 | __cleanup_free char *path = NULL; |
| 80 | int ret; |
| 81 | |
| 82 | ret = shr_mkdir_p(registry_dir(ctx), 0755); |
| 83 | if (ret) |
| 84 | return ret; |
| 85 | |
| 86 | path = registry_path(ctx, device, NULL); |
| 87 | if (!path) |
| 88 | return -ENOMEM; |
| 89 | |
| 90 | |
| 91 | if (mkdir(path, 0755) < 0 && errno != EEXIST) |
| 92 | return -errno; |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static bool valid_device(const char *device) |
| 97 | { |
| 98 | const char *p; |
| 99 | |
| 100 | if (!device || strncmp(device, "nvme", 4) != 0) |
| 101 | return false; |
| 102 | p = device + 4; |
| 103 | if (!*p) |
| 104 | return false; |
| 105 | for (; *p; p++) { |
| 106 | if (*p < '0' || *p > '9') |
| 107 | return false; |
| 108 | } |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | static bool valid_attr(const char *attr) |
| 113 | { |
| 114 | const char *p; |
| 115 | |
| 116 | if (!attr || !*attr) |
| 117 | return false; |
| 118 | for (p = attr; *p; p++) { |
| 119 | if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') || |
| 120 | (*p >= '0' && *p <= '9') || *p == '_' || *p == '-') |
| 121 | continue; |
| 122 | return false; |
| 123 | } |
| 124 | return true; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | static ssize_t read_full(int fd, char *buf, size_t count) |
| 132 | { |
| 133 | size_t off = 0; |
| 134 | |
| 135 | while (off < count) { |
| 136 | ssize_t r = read(fd, buf + off, count - off); |
| 137 | |
| 138 | if (r < 0) { |
| 139 | if (errno == EINTR) |
| 140 | continue; |
| 141 | return -errno; |
| 142 | } |
| 143 | if (r == 0) |
| 144 | break; |
| 145 | off += r; |
| 146 | } |
| 147 | return off; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | static int read_attr_fd(int fd, char **out) |
| 157 | { |
| 158 | struct stat st; |
| 159 | char *val; |
| 160 | ssize_t n; |
| 161 | |
| 162 | if (fstat(fd, &st) < 0) |
| 163 | return -errno; |
| 164 | if (st.st_size == 0) |
| 165 | return -ENOENT; |
| 166 | |
| 167 | val = malloc(st.st_size + 1); |
| 168 | if (!val) |
| 169 | return -ENOMEM; |
| 170 | |
| 171 | n = read_full(fd, val, st.st_size); |
| 172 | if (n < 0) { |
| 173 | free(val); |
| 174 | return n; |
| 175 | } |
| 176 | |
| 177 | while (n > 0 && (val[n - 1] == '\n' || val[n - 1] == '\r')) |
| 178 | n--; |
| 179 | val[n] = '\0'; |
| 180 | *out = val; |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | static int write_attr_atomic(int dir_fd, const char *dir_path, |
| 201 | const char *attr, const char *value) |
| 202 | { |
| 203 | __cleanup_free char *tmp_path = NULL; |
| 204 | __cleanup_free char *final_path = NULL; |
| 205 | int fd, ret; |
| 206 | |
| 207 | if (!valid_attr(attr)) |
| 208 | return -EINVAL; |
| 209 | |
| 210 | if (!value) { |
| 211 | if (unlinkat(dir_fd, attr, 0) < 0 && errno != ENOENT) |
| 212 | return -errno; |
| 213 | fsync(dir_fd); |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | if (asprintf(&final_path, "%s/%s", dir_path, attr) < 0) |
| 218 | return -ENOMEM; |
| 219 | if (asprintf(&tmp_path, "%s/%s.tmp.XXXXXX", dir_path, attr) < 0) |
| 220 | return -ENOMEM; |
| 221 | |
| 222 | fd = shr_mkstemp(tmp_path); |
| 223 | if (fd < 0) |
| 224 | return fd; |
| 225 | |
| 226 | |
| 227 | if (fchmod(fd, 0644) < 0) { |
| 228 | ret = -errno; |
| 229 | goto err; |
| 230 | } |
| 231 | |
| 232 | ret = shr_write_all(fd, value, strlen(value)); |
| 233 | if (ret) |
| 234 | goto err; |
| 235 | ret = shr_write_all(fd, "\n", 1); |
| 236 | if (ret) |
| 237 | goto err; |
| 238 | close(fd); |
| 239 | |
| 240 | if (rename(tmp_path, final_path) < 0) { |
| 241 | ret = -errno; |
| 242 | unlink(tmp_path); |
| 243 | return ret; |
| 244 | } |
| 245 | |
| 246 | |
| 247 | fsync(dir_fd); |
| 248 | return 0; |
| 249 | |
| 250 | err: |
| 251 | close(fd); |
| 252 | unlink(tmp_path); |
| 253 | return ret; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | static int write_device_attr(struct libnvme_global_ctx *ctx, const char *device, |
| 261 | const char *attr, const char *value) |
| 262 | { |
| 263 | __cleanup_free char *dir_path = NULL; |
| 264 | int dir_fd, ret; |
| 265 | |
| 266 | ret = ensure_device_dir(ctx, device); |
| 267 | if (ret) |
| 268 | return ret; |
| 269 | |
| 270 | dir_path = registry_path(ctx, device, NULL); |
| 271 | if (!dir_path) |
| 272 | return -ENOMEM; |
| 273 | |
| 274 | dir_fd = open(dir_path, O_RDONLY | O_DIRECTORY | O_CLOEXEC); |
| 275 | if (dir_fd < 0) |
| 276 | return -errno; |
| 277 | |
| 278 | ret = write_attr_atomic(dir_fd, dir_path, attr, value); |
| 279 | close(dir_fd); |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | static char *read_uevent_seqnum(void) |
| 293 | { |
| 294 | char buf[32]; |
| 295 | ssize_t n; |
| 296 | int fd; |
| 297 | |
| 298 | fd = open("/sys/kernel/uevent_seqnum", O_RDONLY | O_CLOEXEC); |
| 299 | if (fd < 0) |
| 300 | return NULL; |
| 301 | n = read_full(fd, buf, sizeof(buf) - 1); |
| 302 | close(fd); |
| 303 | if (n <= 0) |
| 304 | return NULL; |
| 305 | |
| 306 | |
| 307 | while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) |
| 308 | n--; |
| 309 | if (n == 0) |
| 310 | return NULL; |
| 311 | buf[n] = '\0'; |
| 312 | |
| 313 | return strdup(buf); |
| 314 | } |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | static int delete_dir(const char *path) |
| 322 | { |
| 323 | struct dirent *de; |
| 324 | int dir_fd, ret = 0; |
| 325 | DIR *d; |
| 326 | |
| 327 | d = opendir(path); |
| 14 | | Assuming that 'opendir' is successful | |
|
| 328 | if (!d) |
| |
| 329 | return -errno; |
| 330 | |
| 331 | dir_fd = dirfd(d); |
| 16 | | Assuming that 'dirfd' fails | |
|
| 17 | | Value assigned to 'dir_fd' | |
|
| 332 | while ((de = readdir(d)) != NULL) { |
| 18 | | Assuming the condition is true | |
|
| 19 | | Loop condition is true. Entering loop body | |
|
| 333 | if (de->d_name[0] == '.') |
| 20 | | Assuming the condition is false | |
|
| 334 | continue; |
| 335 | if (unlinkat(dir_fd, de->d_name, 0) < 0 && errno != ENOENT) |
| 21 | | The 1st argument to 'unlinkat' is -1 but should be a valid file descriptor or AT_FDCWD |
|
| 336 | ret = -errno; |
| 337 | } |
| 338 | closedir(d); |
| 339 | |
| 340 | if (ret) |
| 341 | return ret; |
| 342 | |
| 343 | if (rmdir(path) < 0 && errno != ENOENT) |
| 344 | return -errno; |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | static int delete_dir_atomic(struct libnvme_global_ctx *ctx, const char *path) |
| 359 | { |
| 360 | __cleanup_free char *trash = NULL; |
| 361 | |
| 362 | if (asprintf(&trash, "%s/.trash.XXXXXX", registry_dir(ctx)) < 0) |
| 8 | | Assuming the condition is false | |
|
| |
| 363 | return -ENOMEM; |
| 364 | if (!mkdtemp(trash)) |
| |
| 365 | return -errno; |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | if (rename(path, trash) < 0) { |
| 11 | | Assuming the condition is false | |
|
| |
| 374 | int ret = -errno; |
| 375 | |
| 376 | rmdir(trash); |
| 377 | return ret; |
| 378 | } |
| 379 | return delete_dir(trash); |
| |
| 380 | } |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | int libnvmf_registry_create_instance(struct libnvme_global_ctx *ctx, |
| 396 | int instance, const char *owner) |
| 397 | { |
| 398 | __cleanup_free char *tmp_dir = NULL; |
| 399 | __cleanup_free char *final_path = NULL; |
| 400 | __cleanup_free char *seqnum = NULL; |
| 401 | char device[32]; |
| 402 | int dir_fd, ret; |
| 403 | |
| 404 | snprintf(device, sizeof(device), "nvme%d", instance); |
| 405 | |
| 406 | final_path = registry_path(ctx, device, NULL); |
| 407 | if (!final_path) |
| 408 | return -ENOMEM; |
| 409 | |
| 410 | |
| 411 | ret = shr_mkdir_p(registry_dir(ctx), 0755); |
| 412 | if (ret) |
| 413 | return ret; |
| 414 | |
| 415 | if (asprintf(&tmp_dir, "%s/.%s.tmp.XXXXXX", |
| 416 | registry_dir(ctx), device) < 0) |
| 417 | return -ENOMEM; |
| 418 | if (!mkdtemp(tmp_dir)) |
| 419 | return -errno; |
| 420 | |
| 421 | |
| 422 | if (chmod(tmp_dir, 0755) < 0) { |
| 423 | ret = -errno; |
| 424 | goto err; |
| 425 | } |
| 426 | |
| 427 | dir_fd = open(tmp_dir, O_RDONLY | O_DIRECTORY | O_CLOEXEC); |
| 428 | if (dir_fd < 0) { |
| 429 | ret = -errno; |
| 430 | goto err; |
| 431 | } |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | seqnum = read_uevent_seqnum(); |
| 440 | if (seqnum) |
| 441 | write_attr_atomic(dir_fd, tmp_dir, "seqnum", seqnum); |
| 442 | |
| 443 | ret = write_attr_atomic(dir_fd, tmp_dir, "owner", owner); |
| 444 | close(dir_fd); |
| 445 | if (ret) |
| 446 | goto err; |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | delete_dir_atomic(ctx, final_path); |
| 454 | if (rename(tmp_dir, final_path) < 0) { |
| 455 | ret = -errno; |
| 456 | goto err; |
| 457 | } |
| 458 | return 0; |
| 459 | |
| 460 | err: |
| 461 | delete_dir(tmp_dir); |
| 462 | return ret; |
| 463 | } |
| 464 | |
| 465 | int libnvmf_registry_delete_instance(struct libnvme_global_ctx *ctx, |
| 466 | int instance) |
| 467 | { |
| 468 | char device[32]; |
| 469 | int ret; |
| 470 | |
| 471 | snprintf(device, sizeof(device), "nvme%d", instance); |
| 472 | ret = libnvmf_registry_delete(ctx, device); |
| 1 | Calling 'libnvmf_registry_delete' | |
|
| 473 | return (ret == -ENOENT) ? 0 : ret; |
| 474 | } |
| 475 | |
| 476 | __shr_public int libnvmf_registry_retrieve(struct libnvme_global_ctx *ctx, |
| 477 | const char *device, |
| 478 | const char *attr, char **value) |
| 479 | { |
| 480 | __cleanup_free char *path = NULL; |
| 481 | int fd, ret; |
| 482 | |
| 483 | if (!ctx) |
| 484 | return -EINVAL; |
| 485 | if (!device || !attr || !value) |
| 486 | return -EINVAL; |
| 487 | if (!valid_device(device)) |
| 488 | return -EINVAL; |
| 489 | |
| 490 | path = registry_path(ctx, device, attr); |
| 491 | if (!path) |
| 492 | return -ENOMEM; |
| 493 | |
| 494 | fd = open(path, O_RDONLY | O_CLOEXEC); |
| 495 | if (fd < 0) |
| 496 | return -errno; |
| 497 | |
| 498 | ret = read_attr_fd(fd, value); |
| 499 | close(fd); |
| 500 | return ret; |
| 501 | } |
| 502 | |
| 503 | __shr_public int libnvmf_registry_attr_equal(struct libnvme_global_ctx *ctx, |
| 504 | const char *device, |
| 505 | const char *attr, |
| 506 | const char *value) |
| 507 | { |
| 508 | char *stored = NULL; |
| 509 | int rc; |
| 510 | |
| 511 | if (!ctx) |
| 512 | return -EINVAL; |
| 513 | |
| 514 | rc = libnvmf_registry_retrieve(ctx, device, attr, &stored); |
| 515 | if (rc < 0 && rc != -ENOENT) |
| 516 | return rc; |
| 517 | if (!stored) |
| 518 | rc = value ? 1 : 0; |
| 519 | else |
| 520 | rc = (value && !strcmp(stored, value)) ? 0 : 1; |
| 521 | free(stored); |
| 522 | return rc; |
| 523 | } |
| 524 | |
| 525 | __shr_public int libnvmf_registry_update(struct libnvme_global_ctx *ctx, |
| 526 | const char *device, |
| 527 | const char *attr, const char *value) |
| 528 | { |
| 529 | if (!ctx) |
| 530 | return -EINVAL; |
| 531 | if (!device || !valid_device(device)) |
| 532 | return -EINVAL; |
| 533 | |
| 534 | return write_device_attr(ctx, device, attr, value); |
| 535 | } |
| 536 | |
| 537 | __shr_public int libnvmf_registry_delete(struct libnvme_global_ctx *ctx, |
| 538 | const char *device) |
| 539 | { |
| 540 | __cleanup_free char *path = NULL; |
| 541 | |
| 542 | if (!ctx) |
| 2 | | Assuming 'ctx' is non-null | |
|
| 543 | return -EINVAL; |
| 544 | if (!device || !valid_device(device)) |
| 3 | | Assuming the condition is false | |
|
| |
| 545 | return -EINVAL; |
| 546 | |
| 547 | path = registry_path(ctx, device, NULL); |
| 548 | if (!path) |
| 5 | | Assuming 'path' is non-null | |
|
| |
| 549 | return -ENOMEM; |
| 550 | |
| 551 | return delete_dir_atomic(ctx, path); |
| 7 | | Calling 'delete_dir_atomic' | |
|
| 552 | } |
| 553 | |
| 554 | __shr_public int libnvmf_registry_device_for_each( |
| 555 | struct libnvme_global_ctx *ctx, |
| 556 | void (*callback)(const char *device, void *user_data), |
| 557 | void *user_data) |
| 558 | { |
| 559 | char dev_path[NAME_MAX + 6]; |
| 560 | struct dirent *de; |
| 561 | DIR *d; |
| 562 | |
| 563 | if (!ctx) |
| 564 | return -EINVAL; |
| 565 | if (!callback) |
| 566 | return -EINVAL; |
| 567 | |
| 568 | d = opendir(registry_dir(ctx)); |
| 569 | if (!d) { |
| 570 | if (errno == ENOENT) |
| 571 | return 0; |
| 572 | return -errno; |
| 573 | } |
| 574 | |
| 575 | while ((de = readdir(d)) != NULL) { |
| 576 | if (de->d_name[0] == '.') |
| 577 | continue; |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | if (de->d_type != DT_DIR) { |
| 584 | struct stat st; |
| 585 | |
| 586 | if (de->d_type != DT_UNKNOWN) |
| 587 | continue; |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | if (fstatat(dirfd(d), de->d_name, &st, 0) < 0 || |
| 594 | !S_ISDIR(st.st_mode)) |
| 595 | continue; |
| 596 | } |
| 597 | |
| 598 | |
| 599 | snprintf(dev_path, sizeof(dev_path), "/dev/%s", de->d_name); |
| 600 | if (access(dev_path, F_OK) != 0) |
| 601 | continue; |
| 602 | |
| 603 | callback(de->d_name, user_data); |
| 604 | } |
| 605 | closedir(d); |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | __shr_public int libnvmf_registry_attr_for_each( |
| 610 | struct libnvme_global_ctx *ctx, |
| 611 | const char *device, |
| 612 | void (*callback)(const char *attr, const char *value, |
| 613 | void *user_data), |
| 614 | void *user_data) |
| 615 | { |
| 616 | __cleanup_free char *dir_path = NULL; |
| 617 | struct dirent *de; |
| 618 | int dir_fd; |
| 619 | DIR *d; |
| 620 | |
| 621 | if (!ctx) |
| 622 | return -EINVAL; |
| 623 | if (!device || !callback) |
| 624 | return -EINVAL; |
| 625 | if (!valid_device(device)) |
| 626 | return -EINVAL; |
| 627 | |
| 628 | dir_path = registry_path(ctx, device, NULL); |
| 629 | if (!dir_path) |
| 630 | return -ENOMEM; |
| 631 | |
| 632 | d = opendir(dir_path); |
| 633 | if (!d) |
| 634 | return -errno; |
| 635 | |
| 636 | dir_fd = dirfd(d); |
| 637 | while ((de = readdir(d)) != NULL) { |
| 638 | __cleanup_free char *val = NULL; |
| 639 | int fd, rc; |
| 640 | |
| 641 | if (de->d_name[0] == '.') |
| 642 | continue; |
| 643 | |
| 644 | if (strstr(de->d_name, ".tmp.")) |
| 645 | continue; |
| 646 | |
| 647 | fd = openat(dir_fd, de->d_name, O_RDONLY | O_CLOEXEC); |
| 648 | if (fd < 0) |
| 649 | continue; |
| 650 | |
| 651 | rc = read_attr_fd(fd, &val); |
| 652 | close(fd); |
| 653 | if (rc == 0) |
| 654 | callback(de->d_name, val, user_data); |
| 655 | } |
| 656 | closedir(d); |
| 657 | return 0; |
| 658 | } |