[PATCH] vmsplice: update to iov syscall
[splice.git] / splice.h
1 #ifndef SPLICE_H
2 #define SPLICE_H
3
4 #include <sys/uio.h>
5
6 #if defined(__i386__)
7 #define __NR_splice     313
8 #define __NR_tee        315
9 #define __NR_vmsplice   316
10 #elif defined(__x86_64__)
11 #define __NR_splice     275
12 #define __NR_tee        276
13 #define __NR_vmsplice   278
14 #elif defined(__powerpc__) || defined(__powerpc64__)
15 #define __NR_splice     283
16 #define __NR_tee        284
17 #define __NR_vmsplice   285
18 #elif defined(__ia64__)
19 #define __NR_splice     1297
20 #define __NR_tee        1301
21 #define __NR_vmsplice   1301
22 #else
23 #error unsupported arch
24 #endif
25
26 #ifndef F_SETPSZ
27 #define F_SETPSZ        15
28 #define F_GETPSZ        16
29 #endif
30
31 #define SPLICE_F_MOVE   (0x01)  /* move pages instead of copying */
32 #define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
33                                  /* we may still block on the fd we splice */
34                                  /* from/to, of course */
35 #define SPLICE_F_MORE   (0x04)  /* expect more data */
36
37 static inline int splice(int fdin, loff_t *off_in, int fdout, loff_t *off_out,
38                          size_t len, unsigned long flags)
39 {
40         return syscall(__NR_splice, fdin, off_in, fdout, off_out, len, flags);
41
42 }
43
44 static inline int tee(int fdin, int fdout, size_t len, unsigned int flags)
45 {
46         return syscall(__NR_tee, fdin, fdout, len, flags);
47 }
48
49 static inline int vmsplice(int fd, const struct iovec *iov,
50                            unsigned long nr_segs, unsigned int flags)
51 {
52         return syscall(__NR_vmsplice, fd, iov, nr_segs, flags);
53 }
54
55 #define SPLICE_SIZE     (64*1024)
56
57 #define BUG_ON(c) assert(!(c))
58
59 #define min(x,y) ({ \
60         typeof(x) _x = (x);     \
61         typeof(y) _y = (y);     \
62         (void) (&_x == &_y);            \
63         _x < _y ? _x : _y; })
64
65 #define max(x,y) ({ \
66         typeof(x) _x = (x);     \
67         typeof(y) _y = (y);     \
68         (void) (&_x == &_y);            \
69         _x > _y ? _x : _y; })
70
71 static inline int error(const char *n)
72 {
73         perror(n);
74         return -1;
75 }
76
77 #endif