]>
git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - lib/ext2fs/llseek.c
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 Public
12 #define _LARGEFILE_SOURCE
13 #define _LARGEFILE64_SOURCE
16 #include <sys/types.h>
28 #include "et/com_err.h"
29 #include "ext2fs/ext2_io.h"
33 #if defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE)
35 #define my_llseek lseek64
38 #if defined(HAVE_LLSEEK)
41 #ifndef HAVE_LLSEEK_PROTOTYPE
42 extern long long llseek (int fd
, long long offset
, int origin
);
45 #define my_llseek llseek
47 #else /* ! HAVE_LLSEEK */
49 #if defined(__alpha__) || defined (__ia64__)
53 #else /* !__alpha__ && !__ia64__*/
55 #include <linux/unistd.h>
58 #define __NR__llseek 140
62 static int _llseek (unsigned int, unsigned long,
63 unsigned long, ext2_loff_t
*, unsigned int);
65 static _syscall5(int,_llseek
,unsigned int,fd
,unsigned long,offset_high
,
66 unsigned long, offset_low
,ext2_loff_t
*,result
,
70 static ext2_loff_t
my_llseek (int fd
, ext2_loff_t offset
, int origin
)
76 retval
= _llseek(fd
, ((unsigned long long) offset
) >> 32,
78 retval
= syscall(__NR__llseek
, fd
, (unsigned long long) (offset
>> 32),
80 ((unsigned long long) offset
) & 0xffffffff,
82 return (retval
== -1 ? (ext2_loff_t
) retval
: result
);
85 #endif /* __alpha__ || __ia64__ */
87 #endif /* HAVE_LLSEEK */
88 #endif /* defined(HAVE_LSEEK64) && defined(HAVE_LSEEK64_PROTOTYPE) */
90 ext2_loff_t
ext2fs_llseek (int fd
, ext2_loff_t offset
, int origin
)
93 static int do_compat
= 0;
95 if ((sizeof(off_t
) >= sizeof(ext2_loff_t
)) ||
96 (offset
< ((ext2_loff_t
) 1 << ((sizeof(off_t
)*8) -1))))
97 return lseek(fd
, (off_t
) offset
, origin
);
104 result
= my_llseek (fd
, offset
, origin
);
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 #define EINVAL EXT2_ET_INVALID_ARGUMENT
122 ext2_loff_t
ext2fs_llseek (int fd
, ext2_loff_t offset
, int origin
)
124 if ((sizeof(off_t
) < sizeof(ext2_loff_t
)) &&
125 (offset
>= ((ext2_loff_t
) 1 << ((sizeof(off_t
)*8) -1)))) {
129 return lseek (fd
, (off_t
) offset
, origin
);