Ask the kernel for a whole directory at once
getattrlistbulk returns names, sizes, dates, flags and link counts for a batch of entries in one call. A pool of work-stealing threads decodes each 128 KiB buffer with bounds checks and memcpy, because 8-byte fields sit on 4-byte boundaries.
macOS gives / and /System/Volumes/Data the same device ID, so comparing st_dev would count your files twice. Three checks keep a scan on its volume:
- Mount status of each entry, from
ATTR_DIR_MOUNTSTATUS - Mount table, looked up before a directory is opened
- Device ID of every entry in the batch
- 0length4
- 4returned_attrs20
- 24error4
- 28name_ref8
- 36devid4
- 40objtype4
- 44modtime16
- 60flags4
- 64fileid8
- 72linkcount4
- 76allocsize8
- 84datalength8
92 bytes, then the name. allocsize comes before datalength: the kernel packs by bit value.
