Skip to content

Commit

Permalink
lib/ext2fs: llseek: simplify linux section
Browse files Browse the repository at this point in the history
On 32-bit musl systems, off_t is always 8 bytes regardless of
_FILE_OFFSET_BITS. The previous code did not cover this case.

The previous #ifdef logic was rather confusing, so I reworked it into a
more understandable form.

Bug: https://bugs.gentoo.org/908892
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
Closes: #150
Signed-off-by: Sam James <sam@gentoo.org>
Link: https://lore.kernel.org/r/20231107233323.2013334-2-sam@gentoo.org
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
floppym authored and tytso committed Apr 4, 2024
1 parent fed000a commit 24181bb
Showing 1 changed file with 15 additions and 52 deletions.
67 changes: 15 additions & 52 deletions lib/ext2fs/llseek.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,68 +35,32 @@

#ifdef __linux__

#if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)

#define my_llseek lseek64

#else
#if defined(HAVE_LLSEEK)
#include <sys/syscall.h>

#ifndef HAVE_LLSEEK_PROTOTYPE
extern long long llseek (int fd, long long offset, int origin);
#endif

#define my_llseek llseek

#else /* ! HAVE_LLSEEK */

#if SIZEOF_LONG == SIZEOF_LONG_LONG || _FILE_OFFSET_BITS+0 == 64

#define my_llseek lseek

#else /* SIZEOF_LONG != SIZEOF_LONG_LONG */

#include <linux/unistd.h>

#ifndef __NR__llseek
#define __NR__llseek 140
#endif

#ifndef __i386__
static int _llseek (unsigned int, unsigned long,
unsigned long, ext2_loff_t *, unsigned int);

static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high,
unsigned long, offset_low,ext2_loff_t *,result,
unsigned int, origin);
#endif

static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin)
{
ext2_loff_t result;
#if SIZEOF_OFF_T >= 8
return lseek(fd, offset, origin);
#elif HAVE_LSEEK64_PROTOTYPE
return lseek64(fd, offset, origin);
#elif HAVE_LLSEEK_PROTOTYPE
return llseek(fd, offset, origin);
#elif defined(__NR__llseek)
loff_t result;
int retval;

#ifndef __i386__
retval = _llseek(fd, ((unsigned long long) offset) >> 32,
retval = syscall(__NR__llseek, fd,
(unsigned long)(offset >> 32),
(unsigned long)(offset & 0xffffffff),
&result, origin);
return (retval == -1 ? retval : result);
#else
retval = syscall(__NR__llseek, fd, (unsigned long long) (offset >> 32),
errno = ENOSYS;
return -1;
#endif
((unsigned long long) offset) & 0xffffffff,
&result, origin);
return (retval == -1 ? (ext2_loff_t) retval : result);
}

#endif /* SIZE_LONG == SIZEOF_LONG_LONG */

#endif /* HAVE_LLSEEK */
#endif /* defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) */

ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
{
#if SIZEOF_OFF_T >= SIZEOF_LONG_LONG
return my_llseek (fd, offset, origin);
#else
ext2_loff_t result;
static int do_compat = 0;

Expand All @@ -117,7 +81,6 @@ ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
return -1;
}
return result;
#endif
}

#else /* !linux */
Expand Down

0 comments on commit 24181bb

Please sign in to comment.