Repository navigation
Conversation
uyjulian
reviewed
Nov 14, 2026
| res = fdinfo->ops->lseek64(fdinfo->userdata, offset, whence); | ||
| // Not every device supports 64-bit seeking (iomanX only supports it on IOP_DT_FSEXT devices), | ||
| // so fall back to the 32-bit callback if the 64-bit one fails. | ||
| if (res >= 0 || fdinfo->ops->lseek == NULL) |
Member
There was a problem hiding this comment.
It would be better to fall back to 32-bit callback only if res is equal to -EUNSUP. Otherwise it will eat errors returned by lseek64
Contributor
Author
There was a problem hiding this comment.
Good catch, thanks — fixed to fall back to the 32-bit callback only on -EUNSUP, so real lseek64 errors propagate instead of being masked. Re-tested on hardware (PSX via ps2link): lseek past 2 GiB on a host: file still returns -1/EOVERFLOW.
off_t is 64 bits, but _lseek() always called the lseek callback, which takes an int offset and returns an int. fseeko()/lseek() on files larger than 2 GiB (exFAT, HDD) therefore truncated the offset silently: a seek to 4 GiB + 100 ends at 100. Positions from 2 GiB on came back negative and were treated as errors. Use the lseek64 callback when the descriptor has one. Not every device supports 64-bit seeking (iomanX only supports it on IOP_DT_FSEXT devices) and returns -EUNSUP for those; fall back to the 32-bit callback only then, so real lseek64 errors are not masked. Before using the 32-bit callback, reject offsets outside the int range with EOVERFLOW instead of truncating them. Tested on hardware (PSX DESR, ps2link): lseek past 2 GiB on a host: file returns -1/EOVERFLOW. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
kaisa847
force-pushed
the
fix/libcglue-lseek64
branch
from
November 14, 2026 08:04
c47a25f to
d9b1640
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_lseek()inee/libcglue/src/glue.ctakes a 64-bitoff_tbut only ever calls the device's 32-bitlseekcallback, which takes anint. The offset is silently truncated: a seek to 4 GiB + 100 lands at 100, and offsets between 2 GiB and 4 GiB come back negative and look like errors. This breaksfseeko/lseekon files larger than 2 GiB (exFAT, HDD). The installed code compiles the truncation assll a1, a1, 0.Fix
lseek64callback when it exists, and fall back to the 32-bitlseekonly when 64-bit seeking is not supported (iomanX offers it only onIOP_DT_FSEXTdevices).intrange withEOVERFLOWinstead of truncating it.Testing
Tested on real hardware: a PSX DESR-5100 (PS2-based), with a test program started via ps2link. The program opens a file over
host:through the standard C library (which uses the fio/ioman path, whose device has nolseek64) and seeks to 4 GiB + 100.lseekreturns0x00000064(the offset truncated to 100),errno0, and a following read returns the byte at offset 100.lseekreturns -1 witherrno == EOVERFLOW.(The 64-bit
lseek64path is not exercised by this test, since thehost:device is a legacy fio device without a 64-bit callback.)🤖 Generated with Claude Code