Skip to content

Fix HostFS directory leaks, dangling symlinks and DREAD replies - #72

Open
fjtrujy wants to merge 1 commit into
masterfrom
fix/usb-hostfs-long-uptime
Open

fjtrujy wants to merge 1 commit into
masterfrom
fix/usb-hostfs-long-uptime

Conversation

@fjtrujy

@fjtrujy fjtrujy commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Scope

This PR now contains only the HostFS directory fixes, independently reviewable and mergeable into master:

  • Return HOSTFS_CMD_DREAD rather than HOSTFS_CMD_READ in a DREAD response.
  • Free scandir() entries on successful directory enumeration (not just on errors), preventing allocation leaks during repeated directory opens.
  • Use lstat() so dangling symbolic links remain visible as directory entries.
  • Clear the directory pointer after freeing it on an error path.
  • Add one native C regression test covering the DREAD wire response, dangling symlinks, and repeated open/close cycles.

Fixes #57.

Verification

  • make -C tests test — passed on macOS.
  • HOSTFS_TEST_ITERATIONS=5000 make -C tests test — passed.
  • make -C usbhostfs_pc -j4 — passed with only the pre-existing unrelated newpathlen warning.
  • git diff --check — passed.

Other independent fixes split out of the original PR

The original combined PR commit (b45ad24) was preserved in a local backup branch before narrowing this PR. All four independent patches together reproduce the exact same Git tree as the original combined PR.

Out of scope

The intermittent multi-hour USB/pspsh hang is tracked separately in #74. Neither this directory PR nor the three extracted fixes alone claims to resolve the root cause. Experimental wake-recovery work is not part of these PRs.

@sharkwouter sharkwouter 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.

Could you still clean up the commit history and the files in this one still? It still looks a bit unfinished.

@fjtrujy
fjtrujy force-pushed the fix/usb-hostfs-long-uptime branch from bd032c4 to b45ad24 Compare October 24, 2026 10:26
@fjtrujy fjtrujy changed the title Improve USB HostFS reconnect resilience and fix directory leaks Fix USB HostFS error handling and directory bugs Oct 24, 2026
@fjtrujy

fjtrujy commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

@sharkwouter Thanks for the review. I've cleaned this up and force-pushed the rewritten branch (b45ad24):

  • Squashed the four incremental/WIP commits into one focused commit, rebased on the updated master.
  • Reduced the diff from 8 files (~688 additions) to 4 files (176 additions, 33 deletions): the PSP/PC HostFS fixes plus one native-C directory/DREAD regression test.
  • Removed the long investigation report, mock pspsh, and standalone hardware smoke-test sources from this PR. The original work is preserved locally, and the long-uptime investigation is tracked in PSPLinkUSB / pspsh stops responding after many hours of mostly idle USB connection #74 rather than mixed into this patch.
  • Updated the PR title and description to specify the verified fixes and explicitly state that the overnight hang is not resolved by this PR.
  • Verified the focused C test, PSP kernel module and host binary builds, and git diff --check. CI is running again on the rewritten head (Linux/macOS/Docker already green at time of writing).

Would you mind taking another look at the revised, smaller diff? Thanks!

@fjtrujy
fjtrujy requested a review from sharkwouter October 24, 2026 10:33
Free scandir results after successful enumerations, preserve dangling symbolic links via lstat, clear released directory pointers, and return the correct HostFS DREAD reply command. Add a native C regression test for enumeration, replies and repeated open/close. Fixes #57.
@fjtrujy
fjtrujy force-pushed the fix/usb-hostfs-long-uptime branch from b45ad24 to c231b89 Compare October 26, 2026 09:03
@fjtrujy fjtrujy changed the title Fix USB HostFS error handling and directory bugs Fix HostFS directory leaks, dangling symlinks and DREAD replies Oct 26, 2026
@fjtrujy

fjtrujy commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

I've split this PR into four independently reviewable changes, preserving this PR's original discussion and reviews:

The original combined commit b45ad24 is backed up locally. I verified that applying the four standalone patches to the same master commit gives the exact same Git tree as b45ad24; nothing was dropped.

The extracted PSP PRs build independently with the PSP toolchain; the Mac host PR and the directory-only PR also build, and the directory regression test passes at 5,000 iterations.

Thanks for reviewing the smaller, independently mergeable changes. The unrelated long-idle investigation stays in #74.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A broken symlink will make ls fail in pspsh

2 participants