feat(libSceUsbStorage): pass the host's USB FAT and exFAT volumes through #11046

Merged
simnJS merged 6 commits from upstream-pr/11046 into main 2026-10-27 07:27:15 +00:00
simnJS commented 2026-10-25 15:05:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-10-25T15:05:41Z.


What

libSceUsbStorage can pass the host's USB drives through instead of always answering "no device".

  • Switch: the passthrough is off unless APS5_USB_STORAGE_PASSTHROUGH is set (documented in docs/dev/ENVIRONMENT.md). Unset, no host volume is scanned or exposed and the guest sees no USB storage, as on main.

  • Devices: the FAT and exFAT volumes the host has mounted from USB mass-storage devices. Linux reads /proc/self/mountinfo and keeps whole-file-system vfat/msdos/exfat mounts whose sysfs block device has a USB interface of class 08 among its ancestors. Windows keeps the FAT/FAT32/exFAT drive letters whose storage descriptor reports BusTypeUsb, and reads VID/PID/revision through SetupAPI and CfgMgr. macOS lists none.

  • Lifecycle: sceUsbStorageInit builds the list and starts a service thread (scePthreadCreate) that rescans once a second; sceUsbStorageTerm joins it and frees the list, as the debt entry asked. A volume keeps the lowest free of eight ids while it stays mounted, and /mnt/usb<id> resolves to it through a libc path alias.

  • Callbacks: sceUsbStorageRegisterCallback/Unregister deliver SharpProspero's recovered 16-byte event (1 mount, 2 unmount, device id, flags) to the callbacks of that event type.

  • Device info: the 0x338-byte record (SharpProspero layout, shadPS4 ids/lengths/flag bits) with the file-system capacity, SCSI inquiry vendor/product, USB serial and flags (read-only, FAT, exFAT).

  • Paths and scans: GetMountPointOfShellCore, IsExist, RequestMap/RequestMapWSB/RequestUnmap and the getdents scan follow shadPS4's virtual-device model for the filled paths, as the debt entry asked.

  • Unknown answers: these still throw or keep the marker. They include a non-null Init attribute, nonzero map flags or volume size, a second map of a directory, unmapping something not mapped, closing a scan that is not open, and the map-available/unavailable callbacks. docs/dev/debt/libSceUsbStorage.md is rewritten around what is still unverified.

Tested

  • Linux (Ubuntu 24.04, GCC 13.3, full build with BUILD_TESTING=ON): ctest -R '^guest_usb_storage$' passes, five runs in a row, about 3 s each.
    • The test builds a fake sysfs tree and mountinfo.
    • Listed: the USB FAT volume, with the right ids, strings, flags and capacity.
    • Excluded: a SATA vfat, a USB ext4 and a bind mount of a subdirectory.
    • Checked: maps and unmaps, the getdents layout and its end, and path resolution through /mnt/usb0.
    • Hotplug: mount and unmount events arrive from the service thread with their user data, and ids are kept and reused.
  • Also on Linux: public_headers*, conventions_*, test_registration, env_reference, progress_* pass. cmake --build build --target libs succeeds. python3 tools/check_conventions.py --base upstream/main passes.
  • Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release: ctest -R '^guest_usb_storage$' passes, ten runs in a row, about 10 s each.
    • The injected-volume cases run, including the switch-off case: with volumes injected and the switch unset, nothing is listed at sceUsbStorageInit or after a rescan, no mount event arrives, device 0 has no info and cannot be mapped, and /mnt/usb0 does not reach the volume. Without the check in ScanHostVolumes it fails.
    • The fake-sysfs case is skipped, because directory symbolic links need Developer Mode or elevation there. The SetupAPI/CfgMgr enumerator has not run against a real drive.
  • No physical USB drive was tested; the machine had no USB access.
  • tools/pr_overlap.py could not run, because gh is not authenticated here. The merge refs of the 1303 open pull requests show none touching libSceUsbStorage or libSceAutoMounterClient.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5005884306 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11046). Originally posted by [simnJS](https://github.com/simnJS) on 2026-10-25T15:05:41Z. --- ### What libSceUsbStorage can pass the host's USB drives through instead of always answering "no device". - **Switch**: the passthrough is off unless `APS5_USB_STORAGE_PASSTHROUGH` is set (documented in `docs/dev/ENVIRONMENT.md`). Unset, no host volume is scanned or exposed and the guest sees no USB storage, as on `main`. - **Devices**: the FAT and exFAT volumes the host has mounted from USB mass-storage devices. Linux reads `/proc/self/mountinfo` and keeps whole-file-system `vfat`/`msdos`/`exfat` mounts whose sysfs block device has a USB interface of class 08 among its ancestors. Windows keeps the FAT/FAT32/exFAT drive letters whose storage descriptor reports `BusTypeUsb`, and reads VID/PID/revision through SetupAPI and CfgMgr. macOS lists none. - **Lifecycle**: `sceUsbStorageInit` builds the list and starts a service thread (`scePthreadCreate`) that rescans once a second; `sceUsbStorageTerm` joins it and frees the list, as the debt entry asked. A volume keeps the lowest free of eight ids while it stays mounted, and `/mnt/usb<id>` resolves to it through a libc path alias. - **Callbacks**: `sceUsbStorageRegisterCallback`/`Unregister` deliver SharpProspero's recovered 16-byte event (1 mount, 2 unmount, device id, flags) to the callbacks of that event type. - **Device info**: the 0x338-byte record (SharpProspero layout, shadPS4 ids/lengths/flag bits) with the file-system capacity, SCSI inquiry vendor/product, USB serial and flags (read-only, FAT, exFAT). - **Paths and scans**: `GetMountPointOfShellCore`, `IsExist`, `RequestMap`/`RequestMapWSB`/`RequestUnmap` and the getdents scan follow shadPS4's virtual-device model for the filled paths, as the debt entry asked. - **Unknown answers**: these still throw or keep the marker. They include a non-null `Init` attribute, nonzero map flags or volume size, a second map of a directory, unmapping something not mapped, closing a scan that is not open, and the map-available/unavailable callbacks. `docs/dev/debt/libSceUsbStorage.md` is rewritten around what is still unverified. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - Linux (Ubuntu 24.04, GCC 13.3, full build with `BUILD_TESTING=ON`): `ctest -R '^guest_usb_storage$'` passes, five runs in a row, about 3 s each. - The test builds a fake sysfs tree and mountinfo. - Listed: the USB FAT volume, with the right ids, strings, flags and capacity. - Excluded: a SATA `vfat`, a USB `ext4` and a bind mount of a subdirectory. - Checked: maps and unmaps, the getdents layout and its end, and path resolution through `/mnt/usb0`. - Hotplug: mount and unmount events arrive from the service thread with their user data, and ids are kept and reused. - Also on Linux: `public_headers*`, `conventions_*`, `test_registration`, `env_reference`, `progress_*` pass. `cmake --build build --target libs` succeeds. `python3 tools/check_conventions.py --base upstream/main` passes. - Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release: `ctest -R '^guest_usb_storage$'` passes, ten runs in a row, about 10 s each. - The injected-volume cases run, including the switch-off case: with volumes injected and the switch unset, nothing is listed at `sceUsbStorageInit` or after a rescan, no mount event arrives, device 0 has no info and cannot be mapped, and `/mnt/usb0` does not reach the volume. Without the check in `ScanHostVolumes` it fails. - The fake-sysfs case is skipped, because directory symbolic links need Developer Mode or elevation there. The SetupAPI/CfgMgr enumerator has not run against a real drive. - No physical USB drive was tested; the machine had no USB access. - `tools/pr_overlap.py` could not run, because `gh` is not authenticated here. The merge refs of the 1303 open pull requests show none touching `libSceUsbStorage` or `libSceAutoMounterClient`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 15:16:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:16:26Z.

Review: CHANGES_REQUESTED


On Windows, RelativeDirectory accepts a drive-qualified value such as C:/Windows because it only rejects backslashes and dot components. Map then constructs a filesystem path from that string and appends it to the selected volume root. A Windows filesystem path with a different root name replaces the left-hand path during operator/=, so is_directory can check C:/Windows instead of the USB volume. If that directory exists, the request succeeds but returns a path under /mnt/usbN that does not refer to the directory that was checked. A drive-relative value such as C:Windows can also carry a root name. Please reject root names and root directories before joining, or build the host path from validated relative components, and add Windows regression coverage for a different-drive path.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643825353 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11046#pullrequestreview-5643825353). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T15:16:26Z. **Review:** CHANGES_REQUESTED --- On Windows, RelativeDirectory accepts a drive-qualified value such as C:/Windows because it only rejects backslashes and dot components. Map then constructs a filesystem path from that string and appends it to the selected volume root. A Windows filesystem path with a different root name replaces the left-hand path during operator/=, so is_directory can check C:/Windows instead of the USB volume. If that directory exists, the request succeeds but returns a path under /mnt/usbN that does not refer to the directory that was checked. A drive-relative value such as C:Windows can also carry a root name. Please reject root names and root directories before joining, or build the host path from validated relative components, and add Windows regression coverage for a different-drive path.
MarcZX10 commented 2026-10-25 15:28:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:28:35Z.

Review: DISMISSED


The Windows root-path escape I reported on the previous head is fixed in 4de4eeff2e46d057c9a442046f6b2bbec213f773: DirectoryNames rejects a root path before joining validated components, and the tests cover both C:/Windows and C:Windows. I rechecked that change and found no remaining instance of that escape. The new Windows host-volume enumerator in HostVolumesWindows.cpp is still only cross-compiled according to the PR report; the hosted Windows product test is skipped by path policy. Please run guest_usb_storage on Windows and report whether the synthetic-volume cases execute or are skipped, since that is the only runtime coverage for this PR’s Windows-specific discovery and path behavior. I am keeping the review request open pending that result.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643864728 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11046#pullrequestreview-5643864728). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T15:28:35Z. **Review:** DISMISSED --- The Windows root-path escape I reported on the previous head is fixed in `4de4eeff2e46d057c9a442046f6b2bbec213f773`: `DirectoryNames` rejects a root path before joining validated components, and the tests cover both `C:/Windows` and `C:Windows`. I rechecked that change and found no remaining instance of that escape. The new Windows host-volume enumerator in `HostVolumesWindows.cpp` is still only cross-compiled according to the PR report; the hosted Windows product test is skipped by path policy. Please run `guest_usb_storage` on Windows and report whether the synthetic-volume cases execute or are skipped, since that is the only runtime coverage for this PR’s Windows-specific discovery and path behavior. I am keeping the review request open pending that result.
Sign in to join this conversation.
No reviewers
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!11046
No description provided.