Debian Codegraph @

testsuite/systemtap.syscall/fallocate.c

raw
1 /* COVERAGE: fallocate */
2
3 #define _GNU_SOURCE
4 #define _LARGEFILE64_SOURCE
5 #define _FILE_OFFSET_BITS 64
6 #include <fcntl.h>
7 #include <linux/falloc.h>
8 #include <unistd.h>
9 #include <sys/syscall.h>
10
11
12 // We'd like to use the gilbc wrapper here, but it only exists in
13 // glibc 2.10+. When it does exist, we want to be sure to use the
14 // 64-bit version.
15 #ifdef __NR_fallocate
16 static inline int __fallocate(int fd, int mode, off64_t offset, off64_t len)
17 {
18 #if __GLIBC_PREREQ(2, 10)
19 #ifdef __USE_LARGEFILE64
20 return fallocate64(fd, mode, offset, len);
21 #else
22 return fallocate(fd, mode, offset, len);
23 #endif
24 #else
25 #if defined(__powerpc__) && !defined(__powerpc64__)
26 /* ppc (not ppc64) has the 64-bit arguments broken up. */
27 return syscall(__NR_fallocate, fd, mode,
28 (unsigned int)(offset >> 32), (unsigned int)offset,
29 (unsigned int)(len >> 32), (unsigned int)len);
30 #else
31 return syscall(__NR_fallocate, fd, mode, offset, len);
32 #endif
33 #endif
34 }
35 #endif
36
37 int main()
38 {
39 #ifdef __NR_fallocate
40 int fd;
41
42 fd = open("foo", O_RDWR | O_CREAT, 0700);
43
44 __fallocate(fd, 0, 0LL, 4096LL);
45 //staptest// fallocate (NNNN, 0x0, 0x0, 4096) = NNNN
46
47 #ifdef FALLOC_FL_KEEP_SIZE
48 __fallocate(fd, FALLOC_FL_KEEP_SIZE, 0LL, 8192LL);
49 //staptest// fallocate (NNNN, FALLOC_FL_KEEP_SIZE, 0x0, 8192) = NNNN
50 #endif
51
52 close(fd);
53 //staptest// close (NNNN) = 0
54
55 /* Limit testing. */
56 __fallocate(-1, 0, 0LL, 0LL);
57 //staptest// fallocate (-1, 0x0, 0x0, 0) = NNNN
58
59 __fallocate(fd, -1, 0LL, 0LL);
60 //staptest// fallocate (NNNN, FALLOC_[^ ]+|XXXX, 0x0, 0) = NNNN
61
62 __fallocate(fd, 0, -1LL, 0LL);
63 //staptest// fallocate (NNNN, 0x0, 0xffffffffffffffff, 0) = NNNN
64
65 __fallocate(fd, 0, 0xdeadbeef12345678LL, 0LL);
66 //staptest// fallocate (NNNN, 0x0, 0xdeadbeef12345678, 0) = NNNN
67
68 __fallocate(fd, 0, 0LL, -1LL);
69 //staptest// fallocate (NNNN, 0x0, 0x0, 18446744073709551615) = NNNN
70
71 __fallocate(fd, 0, 0LL, 0xdeadbeef12345678LL);
72 //staptest// fallocate (NNNN, 0x0, 0x0, 16045690981402826360) = NNNN
73 #endif
74
75 return 0;
76 }