| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * llseek.c -- stub calling the llseek system call |
| 3 | * |
| Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 4 | * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o. |
| Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame] | 5 | * |
| 6 | * %Begin-Header% |
| 7 | * This file may be redistributed under the terms of the GNU Public |
| 8 | * License. |
| 9 | * %End-Header% |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| Theodore Ts'o | 1d2ff46 | 1997-10-19 23:00:21 +0000 | [diff] [blame^] | 12 | #if HAVE_SYS_TYPES_H |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 13 | #include <sys/types.h> |
| Theodore Ts'o | 1d2ff46 | 1997-10-19 23:00:21 +0000 | [diff] [blame^] | 14 | #endif |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 15 | |
| 16 | #include <errno.h> |
| Theodore Ts'o | 3cb6c50 | 1997-08-11 20:29:22 +0000 | [diff] [blame] | 17 | #include <stdlib.h> |
| Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 18 | #if HAVE_UNISTD_H |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 19 | #include <unistd.h> |
| Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 20 | #endif |
| Theodore Ts'o | 3cb6c50 | 1997-08-11 20:29:22 +0000 | [diff] [blame] | 21 | #ifdef __MSDOS__ |
| 22 | #include <io.h> |
| 23 | #endif |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 24 | #include "et/com_err.h" |
| 25 | #include "ext2fs/io.h" |
| 26 | |
| 27 | #ifdef __linux__ |
| 28 | |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 29 | #ifdef HAVE_LLSEEK |
| Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 30 | #if HAVE_UNISTD_H |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 31 | #include <unistd.h> |
| Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 32 | #endif |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 33 | #include <syscall.h> |
| 34 | |
| Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 35 | #if (__GLIBC__ == 2) |
| Theodore Ts'o | bc75f2a | 1997-09-04 00:43:10 +0000 | [diff] [blame] | 36 | ext2_loff_t llseek (int fd, ext2_loff_t offset, int origin); |
| Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | #define my_llseek llseek |
| 40 | |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 41 | #else /* HAVE_LLSEEK */ |
| 42 | |
| 43 | #ifdef __alpha__ |
| 44 | |
| 45 | #define llseek lseek |
| 46 | |
| 47 | #else /* !__alpha__ */ |
| 48 | |
| 49 | #include <linux/unistd.h> |
| 50 | |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 51 | #ifndef __NR__llseek |
| 52 | #define __NR__llseek 140 |
| 53 | #endif |
| 54 | |
| Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 55 | #ifndef __i386__ |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 56 | static int _llseek (unsigned int, unsigned long, |
| 57 | unsigned long, ext2_loff_t *, unsigned int); |
| 58 | |
| 59 | static _syscall5(int,_llseek,unsigned int,fd,unsigned long,offset_high, |
| 60 | unsigned long, offset_low,ext2_loff_t *,result, |
| 61 | unsigned int, origin) |
| Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 62 | #endif |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 63 | |
| Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 64 | static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin) |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 65 | { |
| 66 | ext2_loff_t result; |
| 67 | int retval; |
| 68 | |
| Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 69 | #ifndef __i386__ |
| 70 | retval = _llseek(fd, ((unsigned long long) offset) >> 32, |
| 71 | #else |
| 72 | retval = syscall(__NR__llseek, fd, (unsigned long long) (offset >> 32), |
| 73 | #endif |
| 74 | ((unsigned long long) offset) & 0xffffffff, |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 75 | &result, origin); |
| 76 | return (retval == -1 ? (ext2_loff_t) retval : result); |
| 77 | } |
| 78 | |
| 79 | #endif /* HAVE_LLSEEK */ |
| 80 | |
| 81 | #endif /* __alpha__ */ |
| 82 | |
| Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 83 | ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 84 | { |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 85 | ext2_loff_t result; |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 86 | static int do_compat = 0; |
| 87 | |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 88 | if ((sizeof(off_t) >= sizeof(ext2_loff_t)) || |
| 89 | (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) |
| 90 | return lseek(fd, (off_t) offset, origin); |
| 91 | |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 92 | if (do_compat) { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 93 | errno = EINVAL; |
| 94 | return -1; |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| Theodore Ts'o | 1c27cac | 1997-08-14 17:20:42 +0000 | [diff] [blame] | 97 | result = my_llseek (fd, offset, origin); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 98 | if (result == -1 && errno == ENOSYS) { |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 99 | /* |
| 100 | * Just in case this code runs on top of an old kernel |
| 101 | * which does not support the llseek system call |
| 102 | */ |
| 103 | do_compat++; |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 104 | errno = EINVAL; |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 105 | } |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 106 | return result; |
| 107 | } |
| 108 | |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 109 | #else /* !linux */ |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 110 | |
| Theodore Ts'o | d163b09 | 1997-10-03 17:42:28 +0000 | [diff] [blame] | 111 | ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin) |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 112 | { |
| 113 | if ((sizeof(off_t) < sizeof(ext2_loff_t)) && |
| 114 | (offset >= ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))) { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 115 | errno = EINVAL; |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 116 | return -1; |
| 117 | } |
| 118 | return lseek (fd, (off_t) offset, origin); |
| 119 | } |
| 120 | |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 121 | #endif /* linux */ |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 122 | |
| 123 | |