2 * llseek.c -- stub calling the llseek system call
4 * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
12 #ifndef _LARGEFILE_SOURCE
13 #define _LARGEFILE_SOURCE
15 #ifndef _LARGEFILE64_SOURCE
16 #define _LARGEFILE64_SOURCE
21 #include <sys/types.h>
33 #include "et/com_err.h"
34 #include "ext2fs/ext2_io.h"
38 #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
40 #define my_llseek lseek64
43 #if defined(HAVE_LLSEEK)
44 #include <sys/syscall.h>
46 #ifndef HAVE_LLSEEK_PROTOTYPE
47 extern long long llseek (int fd, long long offset, int origin);
50 #define my_llseek llseek
52 #else /* ! HAVE_LLSEEK */
54 #if SIZEOF_LONG == SIZEOF_LONG_LONG || _FILE_OFFSET_BITS+0 == 64
56 #define my_llseek lseek
58 #else /* SIZEOF_LONG != SIZEOF_LONG_LONG */
60 #include <linux/unistd.h>
63 #define __NR__llseek 140
67 static int _llseek (unsigned int, unsigned long,
68 unsigned long, ext2_loff_t *, unsigned int);
70 static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high,
71 unsigned long, offset_low,ext2_loff_t *,result,
72 unsigned int, origin);
75 static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin)
81 retval = _llseek(fd, ((unsigned long long) offset) >> 32,
83 retval = syscall(__NR__llseek, fd, (unsigned long long) (offset >> 32),
85 ((unsigned long long) offset) & 0xffffffff,
87 return (retval == -1 ? (ext2_loff_t) retval : result);
90 #endif /* SIZE_LONG == SIZEOF_LONG_LONG */
92 #endif /* HAVE_LLSEEK */
93 #endif /* defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) */
95 ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
97 #if SIZEOF_OFF_T >= SIZEOF_LONG_LONG
98 return my_llseek (fd, offset, origin);
101 static int do_compat = 0;
106 result = my_llseek (fd, offset, origin);
107 if (result == -1 && errno == ENOSYS) {
109 * Just in case this code runs on top of an old kernel
110 * which does not support the llseek system call
114 if (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))
115 return lseek(fd, (off_t) offset, origin);
126 #define EINVAL EXT2_ET_INVALID_ARGUMENT
129 ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
131 #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
132 return lseek64 (fd, offset, origin);
134 if ((sizeof(off_t) < sizeof(ext2_loff_t)) &&
135 (offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) {
139 return lseek (fd, (off_t) offset, origin);