You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, Hermit's getdents64 is not stateful. This means that when reading a directory, the caller needs to provide a buffer that is large enough to hold all directory members. A buffer that can only hold a few members returns EINVAL.
Instead, getdents64 should be stateful. This means that when reading a directory, it is fine if the caller provides a buffer that can only hold a few members of the directory. getdents64 is then called again and again to return the next members until it returns 0 (end of directory). Only if the buffer is too small to hold the next member, EINVAL is returned.
The issue has been worked around in rust-std by growing the buffer until it is big enough to hold all directory members. This is not ideal for performance, since we eagerly copy all the directory members instead of copying lazily while iterating over ReadDir. This is also not ideal for memory consumption, since the buffer we allocate can grow arbitrarily large instead of staying constant.
The state should be exposed by and resettable via lseek (which is used in newlib's seekdir and rewinddir).
Just thinking out loud: An alternative approach might be to keep it stateless in the kernel and pass the starting position for reading to the systemcall as well. The newlib would then keep track of the state. (We never claimed that our syscall interface is POSIX compatible, after all)
Activity
jounathaen commentedon May 21, 2025
Just thinking out loud: An alternative approach might be to keep it stateless in the kernel and pass the starting position for reading to the systemcall as well. The newlib would then keep track of the state. (We never claimed that our syscall interface is POSIX compatible, after all)