feat(libSceUsbStorage): the no-device path of the USB storage service #8399
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8399"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-20T12:16:55Z.
What
libSceUsbStoragewas 0/21: every export threwNotImplemented_nid_no_patch. Nine of them now implement the no-device path, with prototypes and argument validation following the ABI restored onmain(the firmware-database sweep of 2026-10-21, which matches shadPS4 — the same reference the library's debt file already cites for theRequestMapWSBprototype) and error codes following shadPS4's auto_mounter values; the device-info record follows SharpProspero:sceUsbStorageInit/sceUsbStorageTermaccept every call and keep no state, as shadPS4 does.sceUsbStorageGetDeviceListanswers 0 with an empty list,sceUsbStorageIsExist(the restored three-argument bool form) succeeds and reports non-existence for every device id and directory, andsceUsbStorageGetDeviceInfoanswers0x80f40004(DeviceNotFound) for every device id, after the null-pointer check.sceUsbStorageRequestMapandsceUsbStorageRequestMapWSBanswerDeviceNotFoundfor every device id and leave their outputs untouched.sceUsbStorageGetdentsOpenanswersDeviceNotFound(after the null checks) andsceUsbStorageGetdentsReadanswers0x80f40005(NotSupported) with zero bytes for a descriptor that was never opened.AnyPS5 has no USB mass-storage passthrough, so this is the no-attached-device state a title actually observes here; the model matches the one the merged Hmd2 (no headset) and Mbus (no device) libraries follow. A future passthrough follows shadPS4's virtual-device model at the pinned commit for the filled paths, including its packed dirent, but fills the 0x338-byte device-info record from SharpProspero's layout (recovered from the module's own
sceUsbStorageGetDeviceInfoand checked in #6288 as "volume size at 0x0"), because shadPS4's record starts with a u32 device id at offset 0 where a title reads the volume size, as the debt entry states.Twelve exports keep their markers, each for a reason the debt file records. The six register/unregister callbacks and
sceUsbStorageRequestUnmap/sceUsbStorageGetdentsCloserun their argument validation (a null callback, an event type outside 1 and 2, or a null directory is refused with0x80f40002) and then throw: shadPS4 logs the callbacks as(STUBBED)and returns 0 without storing anything, its unmap keeps no state and its close succeeds only becauseeraseignores a missing key, and a success return without a reference is the pattern #6288 was closed for — the no-device libraries throw on this path (sceMoveClose,sceContentSearchCloseMetadata).sceUsbStorageClearFakeWriteProtection,sceUsbStorageSetFakeMapLockForDebugandsceUsbStorageSetFakeWriteProtectionhave no credible prototypes (names only in the PS5 3.20 export inventory), andsceUsbStorageGetMountPointOfShellCorehas a known prototype but no reference says what a console without a mapped device answers.sceUsbStorageRequestMap's six parameters, the typedUsbStorageCallbackandsceUsbStorageIsExist's bool form follow the restored ABI onmain;sceUsbStorageGetDeviceList'sint32_t*count also follows SharpProspero (whose earlier eight-parameterRequestMapreading carried the trailing reserved pair the restored ABI drops; shadPS4'sRequestMaptakes six and its count isu32*).The library gets a
CMakeLists.txtregistering the newGuestUsbStoragetest (the Hmd2 pattern); the library target builds as before.Tested
Ubuntu (Linux x86-64), GCC,
-std=c++20 -O2 -Wall -Wextra, direct library build ofExport.cpp+GuestUsbStorage(the guest-test pattern of the other libraries; the platform CI relinker build runs on the PR). The author did not compile Windows; a community Windows build of the earlier revision passed (see the comments).guest_usb_storagewalks: init/term (including re-init), the six callback validations with theirInvalidArgumentcases (null callback, event types 0/3/-1, null directory) followed by their marker throws, the no-device answers (GetDeviceList→ empty with the array untouched,GetDeviceInfo→DeviceNotFoundwith the buffer untouched,IsExist→ succeeds withexistscleared on every row), the map requests (outputs untouched by canary),RequestUnmap's null-directory refusal and marker, the getdents family (open →DeviceNotFoundwith outputs untouched, read of an unopened descriptor →NotSupportedwith zero bytes, close → marker), and the four other throwing markers. The callback the test registers is anAPS5_VABIfunction now that the pointer type is restored.Export.cppaborts atsceUsbStorageInit not implemented, so the checks cover the new behaviour, not just the signatures.tools/check_conventions.py --base origin/mainpasses with the title and body below.tools/progress.py: main9be6ccf60= 4405/8805 (50.03%); with this PR = 4414/8805 (50.13%), libSceUsbStorage 0/21 → 9/21; no regressions (compare_progress.py). Re-measured on the ABI-adoption head4d98d9a2cagainst maind6eafa54d: 4834/11181 (43.23%) → 4843/11181 (43.31%), 0/21 → 9/21, no regressions — the count is unchanged by the signature adoption.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T12:17:44Z.
Progress report (
d6eafa5→4d98d9a)📈 System libraries: 43.31% (+0.08%, +9 implemented functions)
✅ 9 implemented
sceUsbStorageGetDeviceInfosceUsbStorageGetDeviceListsceUsbStorageGetdentsOpensceUsbStorageGetdentsReadsceUsbStorageInitsceUsbStorageIsExistsceUsbStorageRequestMapsceUsbStorageRequestMapWSBsceUsbStorageTerm⚪ 2 behaviourally empty (constant return or throw)
sceUsbStorageInitsceUsbStorageTermImported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T20:40:39Z.
1. Callback register/unregister (Export.cpp#L19-L72)
All six calls check their arguments and then return 0 without recording anything. So
sceUsbStorageUnregisterCallback(1, cb)returns 0 for acbthat was never registered, and returns 0 again on a second call.#6288 had the same checks and the same
return 0. It was closed with this comment: "Register/unregister callbacks,RequestMap, and the fake write-protection calls return success without doing anything. Unverified paths must throw (NotImplemented_nid_no_patch)" (comment). This PR fixesRequestMap, the fake calls, the signatures and the missing test from that comment, but not the callbacks.The cited reference does not support the success path either: shadPS4 logs all six as
(STUBBED)(usbstorage.cpp#L110, and L124, L135, L147, L159, L171). The debt file also lists them under Silent stubs while the checklist saysUnblocks: none, and CONTRIBUTING.md allows a silent stub only when it unblocks a title.I suggest keeping the checks and throwing after them until a title needs these calls. The test lines that expect 0 from these calls (43-44, 49-50, 56, 59, 62, 65) would then move to the throwing checks.
2.
sceUsbStorageRequestUnmapandsceUsbStorageGetdentsClose(Export.cpp#L116, Export.cpp#L142)In this model nothing can be mapped or opened. Even so,
sceUsbStorageRequestUnmap(7, "/mnt/usb7")andsceUsbStorageGetdentsClose(1)return 0. MeanwhilesceUsbStorageGetdentsRead(1, ...)on the same never-opened descriptor returns0x80f40005.shadPS4 does not establish these answers:
eraseignores a missing key (L378-L383).The no-device libraries already merged throw in this case.
sceMoveClosethrows for a handle that was never opened (libSceMove/Export.cpp#L71).sceContentSearchCloseMetadatathrows because no metadata id is ever handed out (libSceContentSearch.md#L9).I suggest throwing after the null check in both functions, dropping the two "answers 0" clauses from the debt entry at L16, and updating test lines 104-105 and 126-127.
3. Sources in the debt file (libSceUsbStorage.md#L15)
L15 says the prototypes follow shadPS4 L176-L383, but two of them match SharpProspero and not shadPS4.
sceUsbStorageRequestMaptakes 8 arguments here, as in SharpProspero UsbStorage.cs#L235, while shadPS4's takes 6 (L276-L277).sceUsbStorageGetDeviceListtakesstd::int32_t* count, as in SharpProspero (L233), while shadPS4 hasu32* count(L176).L16 tells a future passthrough to follow shadPS4's 0x338-byte device-info record. That record has
u32 device_idat offset 0 (L33-L35). SharpProspero recovered its layout from the module'ssceUsbStorageGetDeviceInfo, and it has the u64 volume size at offset 0 (L34-L45, L100). #6288 was checked against that layout ("volume size at 0x0"). Filling the record the way shadPS4 does would put a device id where a title reads the volume size.I suggest these changes to the entry:
5dfdb4b0for these two prototypes and for the record layout.device_idat offset 0.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T07:35:22Z.
Windows run of 9e81ae3ff2 merged onto
mainb77bd58806(e6b1b41e3c), the build the description lists as not done. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON.Built
libSceUsbStorageandguest_usb_storage_testswith no errors or warnings;ctest --repeat until-fail:2onguest_usb_storage: passes on both repeats. Not run: the negative control againstmain's library, a title.Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-21T07:44:45Z.
All three points are adopted - thank you for the #6288 archaeology and the SharpProspero cross-check; both changed the PR for the better.
1. Callbacks. Your pattern is in verbatim: the six register/unregister exports keep their argument checks (the
0x80f40002refusals) and throwNotImplemented_nid_no_patchpast them, exactly as #6288's closure comment requires. The test lines you listed (43-44, 49-50, 56, 59, 62, 65) moved to throwing checks, and the exports drop out of the implemented count - the PR is now +9 (0/21 -> 9/21), not +17. The debt entry states the gap first: what a successful registration stores is unverified, shadPS4 logs all six as(STUBBED)and returns 0 without storing anything, and that success-without-a-reference pattern is what #6288 was closed for.2.
RequestUnmapandGetdentsClose. Both now throw after their argument validation, the two "answers 0" clauses are gone from the debt entry, and test lines 104-105 / 126-127 expect the markers. The entry records your reasoning: shadPS4's unmap only logs without state, its close succeeds only becauseeraseignores a missing key, and the no-device libraries throw on this path (sceMoveClose,sceContentSearchCloseMetadata).3. Sources. The debt entry now cites SharpProspero @ 5dfdb4b0 for
sceUsbStorageRequestMap's eight parameters andsceUsbStorageGetDeviceList'sint32_t*count, and for the 0x338-byte device-info record - recovered from the module's ownsceUsbStorageGetDeviceInfoand checked against #6288's "volume size at 0x0" - with the note that shadPS4's record starts with a u32 device id at offset 0, where a title reads the volume size. The remaining prototypes keep the shadPS4 citation, and every entry now states the gap first per CONTRIBUTING.md.The branch is rebased onto current
main9be6ccf60and squashed to a single commit (headb3bca1bc9). Re-measured on that base:main4405/8805 (50.03%) -> with this PR 4414/8805 (50.13%), libSceUsbStorage 0/21 -> 9/21, no regressions. The guest test passes with the new expectations and still aborts onmain'sExport.cppat the first marker.Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-21T07:47:16Z.
Thank you for the Windows run - that closes the "Windows was not compiled" line in the description for the revision you built:
libSceUsbStorageandguest_usb_storage_testsbuilt clean on MinGW-w64 GCC 15.2.0 and passedctest --repeat until-fail:2, merged ontomainb77bd58806.One note for anyone re-running it: the head moved shortly after your run (
b3bca1bc9, rebased onto currentmain9be6ccf60) to adopt nikowolf123's review above - the six register/unregister callbacks,sceUsbStorageRequestUnmapandsceUsbStorageGetdentsClosenow throw their markers past their argument validation instead of returning 0, and the test expectations changed with them (the throwing checks are text matches against the marker message, so they are host-independent; the callback pointer is passed asvoid*and never called, so noAPS5_VABIinvolvement). Your build covers everything that did not change; a re-run againstb3bca1bc9would cover the reworked expectations too, but nothing in the change is Windows-sensitive.Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-21T15:20:48Z.
On the overlap the bot lists: #9137 retypes nine of this library's exports (the six register/unregister callbacks,
GetDeviceInfo,IsExist,RequestMap) but keeps them as markers — no behavioral overlap with the no-device path here. Where its ABI signatures differ from the ones this PR built on, we take the sweep's when it lands:IsExistto the three-argumentboolform,RequestMapto the six-argument form (the PR's eight parameters came from SharpProspero @ 5dfdb4b0 and the declarations already onmain; the sweep and shadPS4 both say six), the callbacks to the typedUsbStorageCallback. Coordination note posted on the sweep: comment.No
Depends onon either side — there is no build-on dependency, and the branch is clean against currentmaincecb540a6with all checks green onb3bca1bc9.Imported from boykopovar/AnyPS5. Originally posted by primesoul-web on 2026-10-22T07:49:50Z.
The ABI sweep reached this library on
main(fix(usbstorage): restore mapping callbacks and system service aliases), and head4d98d9a2cadopts its signatures over the no-device path — exactly the adoption the coordination note on the sweep and the overlap reply above promised: the register/unregister family takes the typedUsbStorageCallback,sceUsbStorageGetDeviceInfotakes the forward-declaredUsbStorageDeviceInfo*,sceUsbStorageIsExisttakes the three-argument bool form (with no device attached it succeeds and reports non-existence —*exists = 0, return true — for every device id and directory), andsceUsbStorageRequestMaptakes the sweep's six parameters, the trailing reserved pair SharpProspero's earlier reading carried being dropped.The argument validation and the no-device answers are unchanged: the six callbacks still refuse a null callback, an event type outside 1 and 2, or a null directory with
0x80f40002and then throw their markers, the map and getdents requests still answer0x80f40004, and nothing is stored. The guest test passes anAPS5_VABIcallback now that the pointer is typed (the #8009 lesson), pins theexistsout-parameter on all threeIsExistrows, and the negative control still aborts onmain's markerExport.cppatsceUsbStorageInit. The debt entry's prototype bullet now cites the restored ABI (with SharpProspero kept forGetDeviceList'sint32_t*count and the reserved-pair history).Re-measured against
maind6eafa54d: 4834/11181 (43.23%) -> 4843/11181 (43.31%), libSceUsbStorage 0/21 -> 9/21, +9, no regressions — the count is unchanged by the signature adoption.git merge-treeagainstmainis clean; conventions all green.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-22T08:21:59Z.
Windows run of
4d98d9a2cd, the signature-adoption update (it already containsmaind6eafa54d0). Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON.Built
libSceUsbStorageandguest_usb_storage_testswith no errors or warnings.ctest --repeat until-fail:2onguest_usb_storage: passes on both repeats. The negative control, which my earlier run left out: withcore/libs/prx/libSceUsbStorage/Export.cpptaken frommainand the rest of this head, the same test aborts withsceUsbStorageInit not implemented(exit code0xc0000409). Not run: a title.