blob: 02e0ede8706168f3ea822f264a8c5e74019d3547 [file] [log] [blame]
Theodore Ts'of3db3561997-04-26 13:34:30 +00001/*
2 * llseek.c -- stub calling the llseek system call
3 *
4 * Copyright (C) 1994 Remy Card. This file may be redistributed
5 * under the terms of the GNU Public License.
6 */
7
8#include <sys/types.h>
9
10#include <errno.h>
11#include <unistd.h>
Theodore Ts'of3db3561997-04-26 13:34:30 +000012#include "et/com_err.h"
13#include "ext2fs/io.h"
14
15#ifdef __linux__
16
Theodore Ts'o50e1e101997-04-26 13:58:21 +000017#ifdef HAVE_LLSEEK
18#include <unistd.h>
19#include <syscall.h>
20
21#else /* HAVE_LLSEEK */
22
23#ifdef __alpha__
24
25#define llseek lseek
26
27#else /* !__alpha__ */
28
29#include <linux/unistd.h>
30
Theodore Ts'of3db3561997-04-26 13:34:30 +000031#ifndef __NR__llseek
32#define __NR__llseek 140
33#endif
34
35static int _llseek (unsigned int, unsigned long,
36 unsigned long, ext2_loff_t *, unsigned int);
37
38static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high,
39 unsigned long, offset_low,ext2_loff_t *,result,
40 unsigned int, origin)
41
Theodore Ts'o50e1e101997-04-26 13:58:21 +000042static ext2_loff_t llseek (unsigned int fd, ext2_loff_t offset,
43 unsigned int origin)
44{
45 ext2_loff_t result;
46 int retval;
47
48 retval = _llseek (fd, ((unsigned long long) offset) >> 32,
49 ((unsigned long long) offset) & 0xffffffff,
50 &result, origin);
51 return (retval == -1 ? (ext2_loff_t) retval : result);
52}
53
54#endif /* HAVE_LLSEEK */
55
56#endif /* __alpha__ */
57
Theodore Ts'of3db3561997-04-26 13:34:30 +000058ext2_loff_t ext2_llseek (unsigned int fd, ext2_loff_t offset,
59 unsigned int origin)
60{
Theodore Ts'of3db3561997-04-26 13:34:30 +000061 ext2_loff_t result;
Theodore Ts'of3db3561997-04-26 13:34:30 +000062 static int do_compat = 0;
63
Theodore Ts'o50e1e101997-04-26 13:58:21 +000064 if ((sizeof(off_t) >= sizeof(ext2_loff_t)) ||
65 (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1))))
66 return lseek(fd, (off_t) offset, origin);
67
Theodore Ts'of3db3561997-04-26 13:34:30 +000068 if (do_compat) {
Theodore Ts'o50e1e101997-04-26 13:58:21 +000069 errno = EINVAL;
70 return -1;
Theodore Ts'of3db3561997-04-26 13:34:30 +000071 }
72
Theodore Ts'o50e1e101997-04-26 13:58:21 +000073 result = llseek (fd, offset, origin);
74 if (result == -1 && errno == ENOSYS) {
Theodore Ts'of3db3561997-04-26 13:34:30 +000075 /*
76 * Just in case this code runs on top of an old kernel
77 * which does not support the llseek system call
78 */
79 do_compat++;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000080 errno = EINVAL;
Theodore Ts'of3db3561997-04-26 13:34:30 +000081 }
Theodore Ts'of3db3561997-04-26 13:34:30 +000082 return result;
83}
84
Theodore Ts'o50e1e101997-04-26 13:58:21 +000085#else /* !linux */
Theodore Ts'of3db3561997-04-26 13:34:30 +000086
87ext2_loff_t ext2_llseek (unsigned int fd, ext2_loff_t offset,
88 unsigned int origin)
89{
90 if ((sizeof(off_t) < sizeof(ext2_loff_t)) &&
91 (offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) {
Theodore Ts'o50e1e101997-04-26 13:58:21 +000092 errno = EINVAL;
Theodore Ts'of3db3561997-04-26 13:34:30 +000093 return -1;
94 }
95 return lseek (fd, (off_t) offset, origin);
96}
97
Theodore Ts'o50e1e101997-04-26 13:58:21 +000098#endif /* linux */
Theodore Ts'of3db3561997-04-26 13:34:30 +000099
100