4 ms·
What comes closest is scandir [1], which gives you an iterator of direntries, and can be used to avoid lstat syscalls for each file. Otherwise you can open a d
by stabbles 9mo ago
What comes closest is scandir [1], which gives you an iterator of direntries, and can be used to avoid lstat syscalls for each file.
Otherwise you can open a dir and pass its fd to openat together with a relative path to a file, to reduce the kernel overhead of resolving absolute paths for each file.
[1] https://man7.org/linux/man-pages/man3/scandir.3.html https://man7.org/linux/man-pages/man3/scandir.3.html
- zokier 9mo agoin what way does scandir avoid stat syscalls?
- stabbles 9mo agoBecause you get an iterator over `struct dirent`, which includes `d_type` for popular filesystems. Notice that this avoids `lstat` calls; for symlinks you may still need to do a stat call if you want to stat the target.
- direwolf20 9mo agoThis is a (3) man page which means it's not a syscall. Have you checked it doesn't call lstat on each file?
- stabbles 9mo agoFair, https://www.man7.org/linux/man-pages/man2/getdents64.2.html https://www.man7.org/linux/man-pages/man2/getdents64.2.html is a better link. You'd have to call lstat when d_type is DT_UNKNOWN