libkernel: mkdir and rmdir return ENOENT instead of ENOTDIR on Windows when a path component is a regular file #3097
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 husseinkad on 2026-10-10T22:07:24Z.
What
On Windows,
mkdir_nid_postfix,sceKernelMkdir,rmdir_nid_postfixandsceKernelRmdir(core/libs/prx/libkernel/File/src/Stdio.cpp) with a regular file as a path component returnENOENT(or a raw Windows code that maps toEIO):mkdir("file/child"),mkdir("file/child/leaf"),rmdir("file/child"). FreeBSD returnsENOTDIR: mkdir(2) "[ENOTDIR] A component of the path prefix is not a directory", rmdir(2) "[ENOTDIR] A component of the path is not a directory". Linux hosts already returnENOTDIRthere. The same defect likely affects the other path-taking calls (#2300 fixed it forstatwith a trailing slash); this issue is about mkdir and rmdir only.Reproduce
Windows 11, WinLibs GCC 15.2.0 r7,
mainat the time of writing: create a regular filef, callmkdir_nid_postfix("f/child", 0700):-1witherrno2 (FreeBSD: 20).sceKernelMkdirandsceKernelRmdirreturn0x80020002(or anEIOcode) where the console gives0x80020014.Fix
A tested fix is on my fork:
husseinkad:fix/kernel-mkdir-enotdir(two commits onmain; PR #2707, closed by the intake check). A helperHasNonDirectoryPrefixwalks up to the nearest existing ancestor and reports whether it is not a directory (a trailing separator is ignored); it runs only on the failure path, and the four functions returnENOTDIRwhen it is true (errnois captured before the helper runs;_wmkdir'sEINVALfor names likefile/a:b/xis translated too). Along the waysceKernelMkdir("new/")stops failing withENOENTwhilemkdir("new/")succeeds (the parent was taken from the path with its trailing separator, which is the related #2743), so both strip it. Not covered:mkdir("file/")still reportsEEXIST, and a path component longer than the limit is notENAMETOOLONG.guest_filesystemgains the file-prefix anda:bcases for all four functions,dir/missing/leaf(staysENOENT),rmdir("missing/")and trailing-separator mkdir; it fails without the change. A guest-API probe of 124 paths x 4 functions (496 comparisons) againstmain'sStdio.cppbuilt into a secondlibkernel.prx: 371 identical, 104 changedENOENT/EINVALtoENOTDIRand all of them have a regular file as a prefix (junctions, case differences, non-ASCII names,NUL/x, 400 nested components, a file under a read-only directory), 20 are the trailing-separatorsceKernelMkdirforms, none changed from success to failure; a 3-thread create/delete race against a flipping ancestor showed no hang or staleerrno. Linux not run.AI-assisted: yes.