Commit Graph

27 Commits

Author SHA1 Message Date
Hussein Kadhim 0b1941b313 fix(libkernel): report a stable file identity from stat and fstat on Windows
st_ino was always 0 and st_dev differed between stat (drive number) and
fstat (0), so the usual a.st_dev == b.st_dev && a.st_ino == b.st_ino
identity check gave wrong answers. Read the volume serial, the file index
and the link count from the file handle, which works the same for path and
descriptor lookups.

Fixes #2296
2026-10-10 11:08:09 +02:00
MathiasDevelopes 7810f8464e feat(libkernel): open /dev/random and /dev/urandom for reading
Neither existed under the guest root, so opening them failed and titles
that then read from the descriptor crashed. Opening either for reading
now returns a descriptor whose reads, positioned reads and vector reads
fill the buffer from the host's random device, as
sceRandomGetRandomNumber does. Opening them for writing throws.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 09:12:55 +02:00
Dean 01dc5c14a3
Merge pull request #1764 from Zurisen/fix/flock-nonblocking-contention
fix(libkernel): return EWOULDBLOCK from a contended LOCK_NB flock
2026-10-10 20:08:00 +13:00
Dean 79d1220320
Merge pull request #2342 from AchrafReyani/fix/remove-readonly
fix(libc): remove read-only files on Windows
2026-10-10 20:07:46 +13:00
Adrià 7d94990371
Merge pull request #2300 from AchrafReyani/fix/libkernel-stat-trailing-slash
fix(libkernel): report ENOTDIR from stat for a file with a trailing slash
2026-10-10 08:27:27 +02:00
Zurisen 6d7d4b09e4 test(libkernel): check that a combined flock operation takes an exclusive lock 2026-10-10 07:55:48 +02:00
Zurisen 0f770d2203 fix(libkernel): return EWOULDBLOCK from a contended LOCK_NB flock
flock_nid_postfix threw on every failure, so a LOCK_NB request on a lock
held through another descriptor ended the process. FreeBSD flock(2)
returns -1 with EWOULDBLOCK there. Return guest errno 35 when LOCK_NB is
set and the host reports the lock as held: ERROR_LOCK_VIOLATION on
Windows, EWOULDBLOCK on Linux. Other failures still throw.
2026-10-10 07:55:48 +02:00
Zurisen d2b8e66c09 fix(libkernel): decode flock operations as FreeBSD does
FreeBSD sys_flock takes LOCK_UN over LOCK_EX over LOCK_SH, ignores other
bits and fails with EBADF when none of the three is set. The operation
reached the host unchanged, so malformed operations differed between
hosts: Linux rejects them with EINVAL and the Windows lock tracking threw.
Decode the operation before either host sees it.
2026-10-10 06:49:20 +02:00
Zurisen 6daf7df9ae fix(libkernel): give flock BSD semantics on Windows
flock mapped each call straight onto LockFileEx/UnlockFileEx, whose
byte-range locks stack per handle. LOCK_UN without a lock failed with
ERROR_NOT_LOCKED and aborted the process, a repeated LOCK_EX blocked
forever, converting between shared and exclusive failed, and a repeated
LOCK_SH needed as many unlocks.

Track the one lock each descriptor holds: a repeated mode and LOCK_UN
without a lock succeed, a conversion releases the old lock before taking
the new one, and close forgets the descriptor's lock.
2026-10-10 06:49:20 +02:00
Dean 65bd2f778a
Merge pull request #2289 from AchrafReyani/fix/libkernel-unlink-directory-eperm
fix(libkernel): return EPERM when unlinking a directory
2026-10-10 17:46:40 +13:00
Adrià Franch c1b714f242 test(libkernel): keep the file stat intact for the lstat checks 2026-10-10 06:14:41 +02:00
Achraf Reyani 610ffbbeba fix(libkernel): report ENOTDIR from stat for a file with a trailing slash
On Windows the existence check accepts "file/", then _wstat64 rejects
it and FillFileStat throws, aborting the title. On Linux the host
reports ENOTDIR, which became ENOENT. A trailing slash on something
that is not a directory now returns ENOTDIR on both hosts, as on
FreeBSD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 06:14:41 +02:00
Hannah Lyons 94a33bfa5c fix(libkernel): honour open flags when Windows falls back to a directory descriptor 2026-10-09 21:22:23 -04:00
Adrià 72cf6c3c5a
Merge pull request #1624 from babyhuey/feat/libkernel-lstat
feat(libkernel): implement lstat
2026-10-09 23:52:02 +02:00
Hannah Lyons 903f50a3b4 feat(libkernel): implement lstat 2026-10-09 17:30:43 -04:00
Hannah Lyons 6768210713 feat(libkernel): implement fdatasync 2026-10-09 17:30:24 -04:00
Achraf Reyani 58e18f0828 fix(libc): remove read-only files on Windows
FreeBSD's unlink ignores the file's own permission bits, so remove()
succeeds on a file the guest made read-only with chmod(0400). On Windows
the guest chmod sets FILE_ATTRIBUTE_READONLY, and DeleteFileW then fails
with ERROR_ACCESS_DENIED, which remove() reported as EACCES. Clear the
attribute and retry, restoring it if the retry still fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 00:55:32 +09:00
Achraf Reyani 275163277b fix(libkernel): return EPERM when unlinking a directory
FreeBSD's unlink(2) reports EPERM for a directory, but the host call
returns EACCES on Windows and EISDIR on Linux, so the guest saw a
different error on each host. Check for a directory, not following a
symbolic link, before unlinking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 22:39:50 +09:00
mrk1987 a9d31f3cba fix(libkernel): return POSIX errors from mkdir 2026-10-08 09:20:04 +02:00
kjhq 295780ab20 feat(libkernel): report no write throttling in sceKernelWriteThrottlingStatus
The host has no SSD write budget, so the status reports the largest budget in its first qword and zeroes the rest.
2026-10-08 08:21:23 +02:00
Gjon Gojcevic ccc9e3c6da fix(libkernel): return EBADF from sceKernelClose for a descriptor that is not open 2026-10-07 14:10:53 -04:00
Nicolas Abosch 7789c0a57b feat(libs): implement homebrew libc and kernel runtime exports 2026-10-05 22:40:16 -03:00
Nahuel Genchi ec17b9811c feat(libkernel): implement futimes 2026-10-05 20:47:34 -03:00
Nahuel Genchi eded1e010f feat(libkernel): implement fchmod and sceKernelFchmod 2026-10-05 20:46:34 -03:00
DotDebian 1817d83fec fix(libkernel): return -1 and set errno from the POSIX open, stat, unlink and rmdir
open, _open, stat, unlink and rmdir forwarded the result of their sceKernel
twin, so a failure returned 0x8002xxxx instead of -1 and errno was never set
to the guest error. They now return -1 with errno set to the code carried by
the sce error, and report a null pointer as EFAULT and an empty path as
ENOENT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-02 18:17:12 +02:00
asimplestray a4e755ccb1 feat(kernel): implement file metadata ops and address conversion 2026-09-30 16:51:37 +00:00
SamG-Coder 91bf8e3a7a feat(libc): implement guest file removal and renaming 2026-09-25 06:45:30 +10:00