Debian Codegraph @

testsuite/systemtap.syscall/copy_file_range.c

raw
1 /* COVERAGE: copy_file_range */
2 #define _GNU_SOURCE
3 #include <fcntl.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <sys/stat.h>
7 #include <sys/syscall.h>
8 #include <unistd.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <sys/types.h>
12 #include <limits.h>
13
14 // We'd like to use the gilbc wrapper here, but it only exists in
15 // glibc 2.27+. When it does exist, we use our own wrapper.
16 #if defined(SYS_copy_file_range) && !__GLIBC_PREREQ(2, 27)
17 static loff_t
18 copy_file_range(int fd_in, loff_t *off_in, int fd_out,
19 loff_t *off_out, size_t len, unsigned int flags)
20 {
21 return syscall(SYS_copy_file_range, fd_in, off_in, fd_out,
22 off_out, len, flags);
23 }
24 #endif
25
26 int main ()
27 {
28 #ifdef SYS_copy_file_range
29 int fd_in, fd_out;
30 loff_t off_in, off_out;
31 char buf[] = "Hello world abcdefghijklmnopqrstuvwxyz 01234567890123456789";
32 loff_t buf_size = sizeof(buf) - 1;
33
34 /* Create a file with something in it. */
35 fd_in = open("foobar", O_WRONLY|O_CREAT, 0666);
36 write(fd_in, buf, buf_size);
37 fsync(fd_in);
38 close(fd_in);
39
40 fd_in = open("foobar", O_RDONLY);
41 fd_out = open("foobar2", O_WRONLY|O_CREAT, 0666);
42
43 /* Copy 'foobar' to 'foobar2'. */
44 off_in = off_out = 0;
45 copy_file_range(fd_in, &off_in, fd_out, &off_out, buf_size, 0);
46 //staptest// copy_file_range (NNNN, XXXX, NNNN, XXXX, 59, 0x0) = 59
47
48 /* Test variations of the copy_file range to make sure that the
49 * syscall tapset prints out the correct values. */
50 copy_file_range(-1, &off_in, fd_out, &off_out, buf_size, 0);
51 //staptest// copy_file_range (-1, XXXX, NNNN, XXXX, 59, 0x0) = -NNNN
52
53 copy_file_range(fd_in, (loff_t*)-1, fd_out, &off_out, buf_size, 0);
54 #ifdef __s390__
55 //staptest// copy_file_range (NNNN, 0x[7]?[f]+, NNNN, XXXX, 59, 0x0) = -NNNN
56 #else
57 //staptest// copy_file_range (NNNN, 0x[f]+, NNNN, XXXX, 59, 0x0) = -NNNN
58 #endif
59
60 copy_file_range(fd_in, &off_in, -1, &off_out, buf_size, 0);
61 //staptest// copy_file_range (NNNN, XXXX, -1, XXXX, 59, 0x0) = -NNNN
62
63 copy_file_range(fd_in, &off_in, fd_out, (loff_t*)-1, buf_size, 0);
64 #ifdef __s390__
65 //staptest// copy_file_range (NNNN, XXXX, NNNN, 0x[7]?[f]+, 59, 0x0) = -NNNN
66 #else
67 //staptest// copy_file_range (NNNN, XXXX, NNNN, 0x[f]+, 59, 0x0) = -NNNN
68 #endif
69
70 copy_file_range(fd_in, &off_in, fd_out, &off_out, -1L, 0);
71 #if __WORDSIZE == 64
72 //staptest// copy_file_range (NNNN, XXXX, NNNN, XXXX, 18446744073709551615, 0x0) = NNNN
73 #else
74 //staptest// copy_file_range (NNNN, XXXX, NNNN, XXXX, 4294967295, 0x0) = NNNN
75 #endif
76
77 /* Note: flags is unused and should be set to 0, otherwise an
78 * error occurs. This may change if the syscall is developed. */
79 copy_file_range(fd_in, &off_in, fd_out, &off_out, buf_size, -1);
80 //staptest// copy_file_range (NNNN, XXXX, NNNN, XXXX, 59, 0xffffffff) = NNNN
81
82 close(fd_out);
83 close(fd_in);
84 unlink("foobar");
85 unlink("foobar2");
86 #endif
87
88 return 0;
89 }