Skip to content

Implement posix_getdents - #2677

Open
RajeshRk18 wants to merge 3 commits into
hermit-os:mainfrom
RajeshRk18:feat/posix-getdents
Open

Implement posix_getdents#2677
RajeshRk18 wants to merge 3 commits into
hermit-os:mainfrom
RajeshRk18:feat/posix-getdents

Conversation

@RajeshRk18

@RajeshRk18 RajeshRk18 commented Aug 24, 2026

Copy link
Copy Markdown

Closes #2034.

Adds sys_posix_getdents as specified by POSIX.1-2024 posix_getdents, alongside the existing sys_getdents64.

pub unsafe extern "C" fn sys_posix_getdents(fd: RawFd, buf: *mut PosixDent, nbyte: usize, flags: i32) -> isize

PosixDent matches struct posix_dent { d_ino, d_reclen, d_type, d_name[] } . flags must be 0 for now because POSIX defines no mandatory flags and DT_FORCE_TYPE is optional). Anything else returns EINVAL.

Implementation

  • The entry-serialization logic that was duplicated across mem.rs and virtio_fs.rs is now a single DirentFormat::write_entry, parameterized over the two entry formats. ObjectInterface::getdents takes the requested DirentFormat.
  • The default ObjectInterface::getdents now returns ENOTDIR instead of EINVAL, matching both POSIX and Linux getdents64(2) behavior for non-directory descriptors.

fixes surfaced by the new tests

  • DirectoryReader::getdents was unimplemented!(), so sys_opendir + sys_getdents64 panicked the kernel. It is now implemented.
  • MemDirectory::traverse_readdir never resolved the final path component.readdir("/tmp/gd") listed the contents of /tmp instead of /tmp/gd. Both went unnoticed because nothing exercised the sys_opendir path before.

Tests

New tests/getdents.rs integration test covers both syscalls through both the sys_opendir and O_DIRECTORY paths: entry layout/reclen for both formats, end-of-directory, partial reads with a one-entry buffer, rejected flags, EINVAL for a too-small buffer, and ENOTDIR for a file descriptor.

@RajeshRk18
RajeshRk18 marked this pull request as ready for review August 24, 2026 15:06

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark Results

Details
Benchmark Current: 46d9394 Previous: 2e23902 Performance Ratio
startup_benchmark Build Time 94.26 s 80.34 s 1.17
startup_benchmark File Size 0.79 MB 0.80 MB 0.99
Startup Time - 1 core 0.74 s (±0.02 s) 0.75 s (±0.02 s) 1.00
Startup Time - 2 cores 0.71 s (±0.02 s) 0.74 s (±0.02 s) 0.97
Startup Time - 4 cores 0.73 s (±0.02 s) 0.74 s (±0.02 s) 0.98
multithreaded_benchmark Build Time 92.46 s 82.11 s 1.13
multithreaded_benchmark File Size 0.85 MB 0.86 MB 0.99
Multithreaded Pi Efficiency - 2 Threads 66.32 % (±6.75 %) 85.89 % (±6.61 %) 0.77
Multithreaded Pi Efficiency - 4 Threads 41.31 % (±2.95 %) 43.43 % (±2.56 %) 0.95
Multithreaded Pi Efficiency - 8 Threads 20.18 % (±1.86 %) 25.76 % (±1.53 %) 0.78
micro_benchmarks Build Time 208.11 s 80.40 s 2.59
micro_benchmarks File Size 0.85 MB 0.86 MB 0.99
Scheduling time - 1 thread 153.00 ticks (±29.90 ticks) 62.65 ticks (±4.06 ticks) 2.44
Scheduling time - 2 threads 91.39 ticks (±20.12 ticks) 34.08 ticks (±4.10 ticks) 2.68
Micro - Time for syscall (getpid) 8.88 ticks (±4.23 ticks) 3.45 ticks (±0.58 ticks) 2.57
Memcpy speed - (built_in) block size 4096 59877.27 MByte/s (±41562.35 MByte/s) 82448.38 MByte/s (±56997.13 MByte/s) 0.73
Memcpy speed - (built_in) block size 1048576 13434.84 MByte/s (±10910.96 MByte/s) 30585.98 MByte/s (±24707.84 MByte/s) 0.44
Memcpy speed - (built_in) block size 16777216 11798.34 MByte/s (±9792.61 MByte/s) 26340.06 MByte/s (±21720.96 MByte/s) 0.45
Memset speed - (built_in) block size 4096 59915.04 MByte/s (±41585.96 MByte/s) 82292.76 MByte/s (±56891.50 MByte/s) 0.73
Memset speed - (built_in) block size 1048576 13611.81 MByte/s (±10993.47 MByte/s) 31323.85 MByte/s (±25145.86 MByte/s) 0.43
Memset speed - (built_in) block size 16777216 12125.40 MByte/s (±9983.55 MByte/s) 27104.68 MByte/s (±22209.94 MByte/s) 0.45
Memcpy speed - (rust) block size 4096 52553.64 MByte/s (±37594.71 MByte/s) 74097.96 MByte/s (±51811.44 MByte/s) 0.71
Memcpy speed - (rust) block size 1048576 12911.05 MByte/s (±10507.39 MByte/s) 30361.60 MByte/s (±24602.37 MByte/s) 0.43
Memcpy speed - (rust) block size 16777216 11376.74 MByte/s (±9427.28 MByte/s) 27625.34 MByte/s (±22806.88 MByte/s) 0.41
Memset speed - (rust) block size 4096 53165.76 MByte/s (±37982.54 MByte/s) 74373.47 MByte/s (±51976.48 MByte/s) 0.71
Memset speed - (rust) block size 1048576 13267.58 MByte/s (±10731.59 MByte/s) 31110.89 MByte/s (±25033.24 MByte/s) 0.43
Memset speed - (rust) block size 16777216 11574.57 MByte/s (±9522.20 MByte/s) 28386.93 MByte/s (±23265.03 MByte/s) 0.41
alloc_benchmarks Build Time 211.79 s 74.76 s 2.83
alloc_benchmarks File Size 0.87 MB 0.87 MB 0.99
Allocations - Allocation success 91.38 % 91.31 % 1.00
Allocations - Deallocation success 100.00 % 100.00 % 1
Allocations - Pre-fail Allocations 61.60 % 61.44 % 1.00
Allocations - Average Allocation time 23604.24 Ticks (±1625.42 Ticks) 5860.58 Ticks (±98.43 Ticks) 4.03
Allocations - Average Allocation time (no fail) 24573.12 Ticks (±1902.47 Ticks) 6554.81 Ticks (±92.86 Ticks) 3.75
Allocations - Average Deallocation time 7488.40 Ticks (±1832.12 Ticks) 1805.01 Ticks (±250.35 Ticks) 4.15
mutex_benchmark Build Time 218.56 s 79.82 s 2.74
mutex_benchmark File Size 0.85 MB 0.86 MB 0.99
Mutex Stress Test Average Time per Iteration - 1 Threads 35.46 ns (±7.52 ns) 12.10 ns (±0.41 ns) 2.93
Mutex Stress Test Average Time per Iteration - 2 Threads 31.46 ns (±7.42 ns) 40.26 ns (±1.68 ns) 0.78

This comment was automatically generated by workflow using github-action-benchmark.

Comment thread tests/getdents.rs
@jounathaen

Copy link
Copy Markdown
Member

Overall, looks pretty good to me!

@RajeshRk18
RajeshRk18 requested a review from jounathaen August 27, 2026 10:27

@jounathaen jounathaen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice 👍. (Just the CI doc test needs a little fix)

@RajeshRk18

Copy link
Copy Markdown
Author

Very nice 👍. (Just the CI doc test needs a little fix)

thanks! fixing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement posix_getdents

2 participants