libkernel_sys: fchdir on a pipe or socket fails with ENOTDIR, where FreeBSD fails with EINVAL; fix branch ready #9130

Closed
opened 2026-10-21 12:47:37 +00:00 by xXPBSXx · 1 comment
xXPBSXx commented 2026-10-21 12:47:37 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T12:47:37Z.


fchdir(fd) on a pipe end or a socket returns ENOTDIR. FreeBSD 11.4's sys_fchdir resolves the descriptor with getvnode, which fails with EINVAL for a descriptor that has no vnode; only a vnode that is not a directory (a regular file) reaches change_dir and gets ENOTDIR. A caller that tells "not a directory" from "not a file descriptor of that kind" by the error sees the wrong one.

Cause. fchdir_nid_postfix passes the ENOTDIR of GetDirectoryDescriptorPath_nid_no_patch straight through for every descriptor that is not a directory.

Observed on main 865166414f, Windows 10 (10.0.19045), WinLibs GCC 15.2.0 r7, Release (probe, other rows for comparison):

call main on Windows FreeBSD 11.4 source
fchdir(-1) -1, EBADF (9) EBADF
fchdir(regular file) -1, ENOTDIR (20) ENOTDIR
fchdir(pipe read end) -1, ENOTDIR (20) EINVAL (22)
fchdir(socket) -1, ENOTDIR (20) EINVAL (22)

I have not found a title that stops on this.

Fix. xXPBSXx:fix/fchdir-non-vnode (c8edf9477d, one commit on main 865166414f, three files, +15/-1). When the lookup fails with ENOTDIR and the descriptor is neither a vnode (File::IsVnode) nor the random device, fchdir returns EINVAL; the debt entry records the three errors. guest_kernel_sys gets pipe and socket cases: it fails without the change (exit code 0xc0000409 on Windows, 3 of 3; Subprocess aborted on Linux) and passes with it (Windows 3 of 3, Linux 3 of 3); the filesystem, rename, dup and directory tests pass (12 of 12 on Windows).

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5960775186 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9130). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T12:47:37Z. --- `fchdir(fd)` on a pipe end or a socket returns `ENOTDIR`. FreeBSD 11.4's [`sys_fchdir`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/vfs_syscalls.c#L693-L723) resolves the descriptor with [`getvnode`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/vfs_syscalls.c#L3850-L3877), which fails with `EINVAL` for a descriptor that has no vnode; only a vnode that is not a directory (a regular file) reaches `change_dir` and gets `ENOTDIR`. A caller that tells "not a directory" from "not a file descriptor of that kind" by the error sees the wrong one. **Cause.** [`fchdir_nid_postfix`](https://github.com/boykopovar/AnyPS5/blob/865166414f/core/libs/prx/libkernel_sys/Export.cpp#L358-L368) passes the `ENOTDIR` of `GetDirectoryDescriptorPath_nid_no_patch` straight through for every descriptor that is not a directory. Observed on `main` 865166414f, Windows 10 (10.0.19045), WinLibs GCC 15.2.0 r7, Release (probe, other rows for comparison): | call | main on Windows | FreeBSD 11.4 source | |---|---|---| | `fchdir(-1)` | -1, EBADF (9) | EBADF | | `fchdir(regular file)` | -1, ENOTDIR (20) | ENOTDIR | | `fchdir(pipe read end)` | -1, ENOTDIR (20) | EINVAL (22) | | `fchdir(socket)` | -1, ENOTDIR (20) | EINVAL (22) | I have not found a title that stops on this. **Fix.** [`xXPBSXx:fix/fchdir-non-vnode`](https://github.com/boykopovar/AnyPS5/compare/main...xXPBSXx:AnyPS5:fix/fchdir-non-vnode) (c8edf9477d, one commit on `main` 865166414f, three files, +15/-1). When the lookup fails with `ENOTDIR` and the descriptor is neither a vnode (`File::IsVnode`) nor the random device, `fchdir` returns `EINVAL`; the debt entry records the three errors. `guest_kernel_sys` gets pipe and socket cases: it fails without the change (exit code 0xc0000409 on Windows, 3 of 3; `Subprocess aborted` on Linux) and passes with it (Windows 3 of 3, Linux 3 of 3); the filesystem, rename, dup and directory tests pass (12 of 12 on Windows). AI-assisted (Claude Code).
MarcZX10 commented 2026-10-21 22:47:21 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T22:47:21Z.


PR #9131 now carries the reported fix, and the current diff limits EINVAL to descriptors without vnode, character-device or random-device status. I left a focused test note there: its /dev/random case is covered by the explicit random-device exception, so an ordinary character device (/dev/null or NUL) would better pin the preservation of ENOTDIR that this issue identified.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328247861 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/9130#issuecomment-6328247861). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T22:47:21Z. --- PR #9131 now carries the reported fix, and the current diff limits `EINVAL` to descriptors without vnode, character-device or random-device status. I left a focused test note there: its `/dev/random` case is covered by the explicit random-device exception, so an ordinary character device (`/dev/null` or `NUL`) would better pin the preservation of `ENOTDIR` that this issue identified.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#9130
No description provided.