2 * Sherlock Library -- Large File Support
4 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
7 #ifndef _SHERLOCK_LFS_H
8 #define _SHERLOCK_LFS_H
13 #ifdef SHERLOCK_CONFIG_LFS
15 #ifdef SHERLOCK_CONFIG_LFS_LIBC
18 * Unfortunately, we need to configure this manually since
19 * out-of-the-box glibc 2.1 offers the 64-bit calls, but
20 * converts them to 32-bit syscalls. Damn it!
23 #define sh_open open64
24 #define sh_seek lseek64
25 #define sh_pread pread64
26 #define sh_pwrite pwrite64
27 #define SHERLOCK_HAVE_PREAD
32 * Talk directly with the kernel. The LFS implementations of LFS in Linux 2.2
33 * and 2.4 differ, but fortunately for us only in things like stat64 which
34 * we don't need to use.
38 #if defined(__linux__) && defined(__i386__)
39 #define O_LARGEFILE 0100000
41 #error O_LARGEFILE unknown
46 sh_open(char *name, int flags, int mode)
48 return open(name, flags | O_LARGEFILE, mode);
53 /* A "do it yourself" solution */
55 #include <asm/unistd.h>
58 _syscall5(int, _llseek, int, fd, int, hi, int, lo, loff_t *, result, int, whence);
60 static inline loff_t sh_seek(int fd, sh_off_t pos, int whence)
65 err = _llseek(fd, pos >> 32, pos, &result, whence);
66 return (err < 0) ? err : result;
70 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
71 /* glibc 2.1 or newer -> has lseek64 */
72 #define sh_seek(f,o,w) lseek64(f,o,w)
74 /* Touching hidden places in glibc */
75 extern loff_t llseek(int fd, loff_t pos, int whence);
76 #define sh_seek(f,o,w) llseek(f,o,w)
81 #endif /* !SHERLOCK_CONFIG_LFS_LIBC */
83 #else /* !SHERLOCK_CONFIG_LFS */
86 #define sh_seek(f,o,w) lseek(f,o,w)
88 #endif /* !SHERLOCK_CONFIG_LFS */
91 * We'd like to use pread/pwrite for our file accesses, but unfortunately it
92 * isn't simple at all since all libc's until glibc 2.1 don't define it.
95 #ifndef SHERLOCK_HAVE_PREAD
98 #define SHERLOCK_HAVE_PREAD
99 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
100 /* glibc 2.1 or newer -> pread/pwrite supported automatically */
101 #ifdef SHERLOCK_CONFIG_LFS
102 /* but have to use the 64-bit versions explicitly */
103 #define sh_pread pread64
104 #define sh_pwrite pwrite64
106 #define sh_pread pread
107 #define sh_pwrite pwrite
109 #elif defined(i386) && defined(__GLIBC__)
110 /* glibc 2.0 on i386 -> call syscalls directly */
111 #include <asm/unistd.h>
112 #include <syscall-list.h>
113 #include <sys/types.h>
116 #define SYS_pread 180
118 static int sh_pread(unsigned int fd, void *buf, size_t size, loff_t where)
119 { return syscall(SYS_pread, fd, buf, size, where); }
121 #define SYS_pwrite 181
123 static int sh_pwrite(unsigned int fd, void *buf, size_t size, loff_t where)
124 { return syscall(SYS_pwrite, fd, buf, size, where); }
126 /* old libc on i386 -> call syscalls directly the old way */
127 #include <asm/unistd.h>
129 static _syscall4(int, pread, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
130 static _syscall4(int, pwrite, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
131 #define sh_pread pread
132 #define sh_pwrite pwrite
134 #undef SHERLOCK_HAVE_PREAD
136 #endif /* __linux__ */
138 #endif /* !SHERLOCK_HAVE_PREAD */
140 #endif /* !_SHERLOCK_LFS_H */