shadPS4/src/core/libraries
Stephen Miller d8204641fa
libkernel: Filesystem code cleanup (#2554)
* sceKernelOpen: Clean up flag handling

* sceKernelOpen: fix params

Based on decompilation, the second parameter of _open should be flags.
Additionally swaps the return and parameter types to align with our current standards.

* sceKernelOpen: Fix errors

Based on POSIX spec, if part of the path is missing, ENOENT is the correct return.
Additionally, decompilation suggests that open sets errno too.

* Fix exports

Fixes function exports to align with what they should be, based on what I've seen from decompilation and our module generator.

* Proper errno behavior on open

Since sceKernelOpen calls posix_open, errno should be set during this process.
Simplest way to handle that is to move the actual open code to posix_open and adjust error cases accordingly.

* Reorganize open calls, add error log

* Improve close

Removes the EPERM return, as it makes no sense, and swaps sceKernelClose with posix_close to properly emulate errno behavior.

* Fix log on close

* posix_open fixups

* Readd hack in posix_close

It's either this, or removing LLE DiscMap.
Or shadow implements posix sockets.

* Missing exports

Commented out while I gradually work through them all

* Remaining placeholder exports

* Swap some stuff around

I see nothing that suggests "open" only takes two parameters, so this should be completely safe.
It's also more accurate to how these are handled in libkernel, and means I won't need to reorganize anything for readv and writev.

* Update file_system.cpp

* Implement write and posix_write

* Oops

* Implement posix_readv and sceKernelReadv

Also fixes error behavior on readv, as that function shouldn't be returning any kernel error codes.

* Move sceKernelUnlink

Will deal with this one later, was just annoyed by how it's location doesn't align with the export order.

* Cleanup readv

* Implement posix_writev and sceKernelWritev

Also fixes error behavior on writev, since it shouldn't ever return kernel errors (since our device files return those)

* More cleanup on older functions

* Swap around sceKernelLseek and posix_lseek

This ensures that these have the correct error behavior, and makes their behavior align with the updated implementations for earlier functions.

* Update file_system.cpp

* Implement read

Also fixes error behavior

* Swap sceKernelMkdir and posix_mkdir

Fixes errno behavior on kernel calls, also fixed some incorrect error returns.

* Fix errno behavior on sceKernelRmdir

Also reduces function logging to bring it closer to the level of logging seen in other filesystem functions.

* Slight clean up of sceKernelStat

Fixes error behavior and changes some of the old data types.

* Refactor fstat

Fixes errno behavior, implements fstat, and shifts exports around based on file position.
Might reorganize function locations later though.

* Implement posix_ftruncate

Implements posix_ftruncate and fixes errno behavior for sceKernelFtruncate

* Add missing error conversions for more device functions

* Implement posix_rename, fix sceKernelRename errno behavior

* Add posix_preadv and posix_pread

Also fixes some incorrect error returns, fixes errno behavior, and removes an unnecessary hack.

* Fix compile

* Implement posix_getdents, getdirentries, and posix_getdirentries

Also fixes errno behavior for the kernel variants of these functions.

* Fix errno behavior of sceKernelFsync

* Implement posix_pwrite and posix_unlink

Also fixes errno behavior in related functions.

* Update file_system.cpp

* Remove SetPosixErrno

Ideally, we've handled all possible error conditions before calling these functions, so treat errors in platform-specific code as IO errors and return POSIX_EIO instead.

* Update header exports

Not sure where these get used, but might as well keep them consistent with the rest of this.

* Check if file exists before calling platform-specific code

Bloodborne checks if a file doesn't exist using open, checking if it specifically failed with error code ENOENT. To avoid working with platform-specific errnos, add a proper error return for if the file doesn't exist.
Fixes a regression in Bloodborne.

* Clang

Out of all the changes, this is apparently the only thing Clang-Format doesn't like.
I'm honestly surprised.

* Improve error checks on posix_unlink

Just because a file isn't opened doesn't mean the file doesn't exist.
Fixes the error returned if host_path.empty(), and removes the error return for when GetFile fails.

* Fix the Bloodborne fix

* Limit exports to tested functions

* More confirmed working exports

* Remaining stuff my games can test

* FS exports from firmware tests

* Bring back missing exports from main

I don't have any bootable things that call these, but since they were working well enough on main, they should be fine to readd.

* Add export for posix_pread

Spotted in Dreams a while back, might as well add it.

* Revert "Remove SetPosixErrno"

This reverts commit bdfc0c246c.

* Revert SetPosixErrno changes

shadow's using it for posix sockets, so significant modifications would introduce unnecessary merge conflicts.

* Update comment

* Add EACCES errno to SetPosixErrno

Seen in Gravity Rush.
Also reorganizes the switch case based on the posix errno value, since ordering by errno makes no sense on some OSes.

* More export fixups

Missed these during my initial pass through FS stuff because they were in kernel.cpp for some reason.

* Symbols from FS tests

Tested by messing around with firmware elfs, these atleast don't cause any crashes.

* Remove inaccurate error behavior

Seek can have offsets past the end of a file.
Also add logging for two valid whence values that are unsupported on Windows.
I'll need to verify that SEEK_HOLE and SEEK_DATA correspond to 3 and 4 respectively, I've yet to check source to verify.

* Fix error log

Oops

* Clang

Clang

* Remove close hack

Since LLE libSceDiscMap is no longer a concern, this hack shouldn't be needed.
Since sockets are still stubbed, and close can be used on sockets, I've added a warning log just in case this still occurs in some titles.

* Change SetPosixErrno unreachable to warning

I changed it to an unreachable in an earlier commit to make testing easier.
At this point, having an unreachable for this seems unnecessary, so change it to a warning instead.

* Remove Bloodborne hack

Games should be able to unlink files that aren't opened file descriptors. As far as I've tested, this doesn't break Bloodborne.
2025-03-26 18:03:35 +02:00
..
ajm Avoid processing job buffers before codec initialization (#2507) 2025-02-23 06:47:44 +03:00
app_content change sizeof to TmpMount.size (#2523) 2025-02-24 12:44:22 +02:00
audio audioout: Add error returns when not initialized. (#2309) 2025-02-01 10:52:40 +02:00
audio3d texture_cache: Improve support for stencil reads (#1758) 2024-12-13 18:28:19 +02:00
avplayer fix: fix #1457 again by moving av_err2str to a common header (#1688) 2024-12-08 00:52:03 +02:00
disc_map HLE discmap (#2686) 2025-03-25 23:54:32 +02:00
fiber libraries/fiber: print fiber ctx size on stack overflow 2025-01-24 19:37:34 +01:00
game_live_streaming Network libs fixes , stubs and more (#1324) 2024-10-11 10:37:36 +03:00
gnmdriver Properly implement sceVideoOutGetBufferLabelAddress (#2642) 2025-03-12 20:36:01 +02:00
hmd libSceHmd Stubs (#2355) 2025-02-05 17:24:53 +02:00
ime fix for ime (#2475) 2025-03-01 20:02:29 +02:00
jpeg Support for Vulkan 1.4 (#1665) 2024-12-07 19:41:41 +02:00
kernel libkernel: Filesystem code cleanup (#2554) 2025-03-26 18:03:35 +02:00
libc_internal libcInternal HLE fixes (#2491) 2025-02-22 10:56:35 +02:00
libpng hot-fix: debug build fixed 2024-12-01 15:46:08 +01:00
mouse dummy sceMouse module and change sceMouseRead to debug to reduce spam (#2074) 2025-01-06 18:45:53 +02:00
move libraries: Add libSceMove HLE skeleton (#1945) 2024-12-28 12:58:37 +02:00
network [Lib] libsceHttp (#2576) 2025-03-02 23:09:38 +02:00
ngs2 core: Library cleanup (#1631) 2024-11-30 22:37:36 +02:00
np_common Implement sceNpCmp functions (#2114) 2025-01-11 17:58:07 +01:00
np_manager Additional libSceNpManager functions and cleanup (#2195) 2025-01-19 19:12:42 -08:00
np_party stubbed webbrowserdialog,npparty (#2234) 2025-01-24 19:22:06 +02:00
np_score Reorganization of includes (Part 2) 2024-08-30 15:48:21 +02:00
np_trophy load trophy from .wav (#2603) 2025-03-06 16:20:55 +02:00
np_web_api Add libSceNpWebApi (#2150) 2025-01-15 13:19:41 +02:00
pad Fix SDL gyro and acceleration sensor handling (#2532) 2025-02-24 22:38:06 +02:00
playgo video_core: Various small improvements and bug fixes (#2525) 2025-02-24 14:31:12 +02:00
random core: Library cleanup (#1631) 2024-11-30 22:37:36 +02:00
razor_cpu libraries: Add libSceRazorCpu HLE skeleton. (#1624) 2024-11-30 11:30:22 +02:00
remote_play Network libs fixes , stubs and more (#1324) 2024-10-11 10:37:36 +03:00
rtc core: Library cleanup (#1631) 2024-11-30 22:37:36 +02:00
save_data language fix (#2421) 2025-02-13 20:01:35 +02:00
screenshot Reorganization of includes (Part 2) 2024-08-30 15:48:21 +02:00
share_play Network libs fixes , stubs and more (#1324) 2024-10-11 10:37:36 +03:00
system Handle error behavior in sceSysmoduleGetModuleInfoForUnwind stub (#2629) 2025-03-09 23:17:33 +02:00
usbd Reduce USBD Log Spamming (#2019) 2025-01-02 17:37:19 +02:00
videodec hotfix: Raise videodec memory back up to 16MB. 2025-01-29 01:32:12 -08:00
videoout Reset previous buffer label instead of current one (#2663) 2025-03-23 00:27:57 +02:00
web_browser_dialog stubbed webbrowserdialog,npparty (#2234) 2025-01-24 19:22:06 +02:00
zlib libraries: Implement libSceZlib. (#2256) 2025-01-28 18:48:19 +02:00
error_codes.h core: Library cleanup (#1631) 2024-11-30 22:37:36 +02:00
libs.cpp HLE discmap (#2686) 2025-03-25 23:54:32 +02:00
libs.h kernel: Rewrite pthread emulation (#1440) 2024-11-21 22:59:38 +02:00