]> mj.ucw.cz Git - libucw.git/blob - lib/lfs.h
Split page key to pos and fd. Wastes extra 4 bytes, but simplifies the code a lot.
[libucw.git] / lib / lfs.h
1 /*
2  *      Sherlock Library -- Large File Support
3  *
4  *      (c) 1999 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #ifndef _SHERLOCK_LFS_H
8 #define _SHERLOCK_LFS_H
9
10 #ifdef SHERLOCK_CONFIG_LFS
11
12 #ifndef O_LARGEFILE
13 #if defined(__linux__) && defined(__i386__)
14 #define O_LARGEFILE 0100000
15 #else
16 #error O_LARGEFILE unknown
17 #endif
18 #endif
19
20 #define SHERLOCK_O_LARGEFILE O_LARGEFILE
21
22 #if 0
23
24 /* A "do it yourself" solution */
25
26 #include <asm/unistd.h>
27 #include <errno.h>
28
29 _syscall5(int, _llseek, int, fd, int, hi, int, lo, loff_t *, result, int, whence);
30
31 extern inline loff_t sh_seek(int fd, sh_off_t pos, int whence)
32 {
33   loff_t result;
34   int err;
35
36   err = _llseek(fd, pos >> 32, pos, &result, whence);
37   return (err < 0) ? err : result;
38 }
39 #else
40
41 /* Touching hidden places in glibc */
42 extern loff_t llseek(int fd, loff_t pos, int whence);
43 #define sh_seek(f,o,w) llseek(f,o,w)
44
45 #endif
46
47 #else   /* !SHERLOCK_CONFIG_LFS */
48
49 #define sh_seek(f,o,w) lseek(f,o,w)
50 #define SHERLOCK_O_LARGEFILE 0
51
52 #endif  /* !SHERLOCK_CONFIG_LFS */
53
54 /*
55  *  We'd like to use pread/pwrite for our file accesses, but unfortunately it
56  *  isn't simple at all since all libc's until glibc 2.1 don't define it.
57  */
58
59 #ifdef __linux__
60 #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
61 /* glibc 2.1 or newer -> pread/pwrite supported automatically */
62 #define SHERLOCK_HAVE_PREAD
63 #elif defined(i386) && defined(__GLIBC__)
64 /* glibc 2.0 on i386 -> call syscalls directly */
65 #include <asm/unistd.h>
66 #include <syscall-list.h>
67 #ifndef SYS_pread
68 #define SYS_pread 180
69 #endif
70 static int pread(unsigned int fd, void *buf, size_t size, loff_t where)
71 { return syscall(SYS_pread, fd, buf, size, where); }
72 #ifndef SYS_pwrite
73 #define SYS_pwrite 181
74 #endif
75 static int pwrite(unsigned int fd, void *buf, size_t size, loff_t where)
76 { return syscall(SYS_pwrite, fd, buf, size, where); }
77 #define SHERLOCK_HAVE_PREAD
78 #elif defined(i386)
79 /* old libc on i386 -> call syscalls directly the old way */
80 #include <asm/unistd.h>
81 static _syscall4(int, pread, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
82 static _syscall4(int, pwrite, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
83 #define SHERLOCK_HAVE_PREAD
84 #endif
85 #endif  /* __linux__ */
86
87 #endif  /* !_SHERLOCK_LFS_H */