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
8 * GNU Lesser General Public License.
12 #define _LARGEFILE_SOURCE
13 #define _LARGEFILE64_SOURCE
16 #include <sys/types.h>
33 #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
35 #define my_llseek lseek64
37 #elif defined(HAVE_LLSEEK)
40 #ifndef HAVE_LLSEEK_PROTOTYPE
41 extern long long llseek(int fd, long long offset, int origin);
44 #define my_llseek llseek
46 #else /* ! HAVE_LLSEEK */
48 #if defined(__alpha__) || defined(__ia64__)
52 #else /* !__alpha__ && !__ia64__*/
54 #include <linux/unistd.h>
57 #define __NR__llseek 140
61 static int _llseek(unsigned int, unsigned long, unsigned long,
62 blkid_loff_t *, unsigned int);
64 static _syscall5(int, _llseek, unsigned int, fd, unsigned long, offset_high,
65 unsigned long, offset_low, blkid_loff_t *, result,
69 static blkid_loff_t my_llseek(int fd, blkid_loff_t offset, int origin)
75 retval = _llseek(fd, ((unsigned long long) offset) >> 32,
76 ((unsigned long long)offset) & 0xffffffff,
79 retval = syscall(__NR__llseek, fd, ((unsigned long long) offset) >> 32,
80 ((unsigned long long)offset) & 0xffffffff,
83 return (retval == -1 ? (blkid_loff_t) retval : result);
86 #endif /* __alpha__ || __ia64__ */
88 #endif /* HAVE_LLSEEK */
90 blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence)
93 static int do_compat = 0;
95 if ((sizeof(off_t) >= sizeof(blkid_loff_t)) ||
96 (offset < ((blkid_loff_t) 1 << ((sizeof(off_t)*8) -1))))
97 return lseek(fd, (off_t) offset, whence);
104 result = my_llseek(fd, offset, whence);
105 if (result == -1 && errno == ENOSYS) {
107 * Just in case this code runs on top of an old kernel
108 * which does not support the llseek system call
119 #ifdef EXT2_ET_INVALID_ARGUMENT
120 #define EOVERFLOW EXT2_ET_INVALID_ARGUMENT
122 #define EOVERFLOW 112
126 blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int origin)
128 if ((sizeof(off_t) < sizeof(blkid_loff_t)) &&
129 (offset >= ((blkid_loff_t) 1 << ((sizeof(off_t)*8) - 1)))) {
133 return lseek(fd, (off_t) offset, origin);