2 * Sherlock Library -- Large File Support
4 * (c) 1999--2000 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
7 #ifndef _SHERLOCK_LFS_H
8 #define _SHERLOCK_LFS_H
10 #ifdef SHERLOCK_CONFIG_LFS
12 #ifdef SHERLOCK_CONFIG_LFS_LIBC
15 * Unfortunately, we need to configure this manually since
16 * out-of-the-box glibc 2.1 offers the 64-bit calls, but
17 * converts them to 32-bit syscalls. Damn it!
20 #define sh_open open64
21 #define sh_seek lseek64
22 #define sh_pread pread64
23 #define sh_pwrite pwrite64
24 #define SHERLOCK_HAVE_PREAD
29 * Talk directly with the kernel. The LFS implementations of LFS in Linux 2.2
30 * and 2.4 differ, but fortunately for us only in things like stat64 which
31 * we don't need to use.
35 #if defined(__linux__) && defined(__i386__)
36 #define O_LARGEFILE 0100000
38 #error O_LARGEFILE unknown
43 sh_open(char *name, int flags, int mode)
45 return open(name, flags | O_LARGEFILE, mode);
50 /* A "do it yourself" solution */
52 #include <asm/unistd.h>
55 _syscall5(int, _llseek, int, fd, int, hi, int, lo, loff_t *, result, int, whence);
57 extern inline loff_t sh_seek(int fd, sh_off_t pos, int whence)
62 err = _llseek(fd, pos >> 32, pos, &result, whence);
63 return (err < 0) ? err : result;
67 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
68 /* glibc 2.1 or newer -> has lseek64 */
69 #define sh_seek(f,o,w) lseek64(f,o,w)
71 /* Touching hidden places in glibc */
72 extern loff_t llseek(int fd, loff_t pos, int whence);
73 #define sh_seek(f,o,w) llseek(f,o,w)
78 #endif /* !SHERLOCK_CONFIG_LFS_LIBC */
80 #else /* !SHERLOCK_CONFIG_LFS */
83 #define sh_seek(f,o,w) lseek(f,o,w)
85 #endif /* !SHERLOCK_CONFIG_LFS */
88 * We'd like to use pread/pwrite for our file accesses, but unfortunately it
89 * isn't simple at all since all libc's until glibc 2.1 don't define it.
92 #ifndef SHERLOCK_HAVE_PREAD
95 #define SHERLOCK_HAVE_PREAD
96 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
97 /* glibc 2.1 or newer -> pread/pwrite supported automatically */
98 #ifdef SHERLOCK_CONFIG_LFS
99 /* but have to use the 64-bit versions explicitly */
100 #define sh_pread pread64
101 #define sh_pwrite pwrite64
103 #define sh_pread pread
104 #define sh_pwrite pwrite
106 #elif defined(i386) && defined(__GLIBC__)
107 /* glibc 2.0 on i386 -> call syscalls directly */
108 #include <asm/unistd.h>
109 #include <syscall-list.h>
110 #include <sys/types.h>
113 #define SYS_pread 180
115 static int sh_pread(unsigned int fd, void *buf, size_t size, loff_t where)
116 { return syscall(SYS_pread, fd, buf, size, where); }
118 #define SYS_pwrite 181
120 static int sh_pwrite(unsigned int fd, void *buf, size_t size, loff_t where)
121 { return syscall(SYS_pwrite, fd, buf, size, where); }
123 /* old libc on i386 -> call syscalls directly the old way */
124 #include <asm/unistd.h>
125 static _syscall4(int, pread, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
126 static _syscall4(int, pwrite, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
127 #define sh_pread pread
128 #define sh_pwrite pwrite
130 #undef SHERLOCK_HAVE_PREAD
132 #endif /* __linux__ */
134 #endif /* !SHERLOCK_HAVE_PREAD */
136 #ifndef SHERLOCK_HAVE_PREAD
137 #error pread/pwrite not available, need to work around
140 #endif /* !_SHERLOCK_LFS_H */