Debian Codegraph @

testsuite/systemtap.syscall/statfs.c

raw
1 /* COVERAGE: fstatfs statfs ustat fstatfs64 statfs64 */
2
3 // GLIBC cf2478d53a Deprecate ustat syscall interface
4 #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) && __GLIBC__ <= 2 && __GLIBC_MINOR__ <= 27
5 #define __USTAT_NOT_DEPRECATED
6 #endif
7
8 #define _GNU_SOURCE
9 #define _LARGEFILE64_SOURCE
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <fcntl.h>
13 #include <unistd.h>
14 #ifdef __USTAT_NOT_DEPRECATED
15 #include <ustat.h>
16 #endif
17 #include <sys/vfs.h>
18 #include <sys/syscall.h>
19 #include <sys/statfs.h>
20
21 // glibc mangles some ustat calls, so define our own using syscall().
22 #if defined(__NR_ustat) && defined(__USTAT_NOT_DEPRECATED)
23 static inline int __ustat(dev_t dev, struct ustat *ubuf)
24 {
25 return syscall(__NR_ustat, dev, ubuf);
26 }
27 #endif
28
29 // Here's what the man page says about statfs64()/fstatfs64():
30 //
31 // The original Linux statfs() and fstatfs() system calls were not
32 // designed with extremely large file sizes in mind. Subsequently,
33 // Linux 2.6 added new statfs64() and fstatfs64() system calls that
34 // employ a new structure, statfs64. The new structure contains the
35 // same fields as the original statfs structure, but the sizes of
36 // various fields are increased, to accommodate large file
37 // sizes. The glibc statfs() and fstatfs() wrapper functions
38 // transparently deal with the kernel differences.
39 //
40 // Note that when _LARGEFILE64_SOURCE is defined, there actually *are*
41 // statfs64()/fstatfs64() glibc wrappers, but sometimes glibc still
42 // calls statfs()/fstatfs() anyway. Since we want to explicitly test
43 // statfs64()/fstatfs64(), we'll make our own wrappers. Also note that
44 // our wrappers include the 'sz' parameter, which the glibc wrappers
45 // don't.
46
47 #ifdef __NR_statfs64
48 static inline int __statfs64(const char *path, size_t sz, struct statfs64 *buf)
49 {
50 return syscall(__NR_statfs64, path, sz, buf);
51 }
52 #endif
53
54 #ifdef __NR_fstatfs64
55 static inline int __fstatfs64(int fd, size_t sz, struct statfs64 *buf)
56 {
57 return syscall(__NR_fstatfs64, fd, sz, buf);
58 }
59 #endif
60
61 int main()
62 {
63 int fd;
64 struct stat sbuf;
65 struct statfs buf;
66 struct statfs64 buf64;
67 #if defined(__NR_ustat) && (__USTAT_NOT_DEPRECATED)
68 struct ustat ubuf;
69 #endif
70
71 fd = open("abc", O_WRONLY|O_CREAT, S_IRWXU);
72 fstat(fd, &sbuf);
73
74 // Since ustat() can fail on NFS filesystems, don't check for
75 // success here.
76 #if defined(__NR_ustat) && (__USTAT_NOT_DEPRECATED)
77 ustat(sbuf.st_dev, &ubuf);
78 //staptest// ustat (NNNN, XXXX) = NNNN
79 #endif
80
81 statfs("abc", &buf);
82 //staptest// statfs ("abc", XXXX) = 0
83
84 fstatfs(fd, &buf);
85 //staptest// fstatfs (NNNN, XXXX) = 0
86
87 #ifdef __NR_statfs64
88 __statfs64("abc", sizeof(buf64), &buf64);
89 //staptest// statfs64 ("abc", NNNN, XXXX) = 0
90 #endif
91
92 #ifdef __NR_fstatfs64
93 __fstatfs64(fd, sizeof(buf64), &buf64);
94 //staptest// fstatfs64 (NNNN, NNNN, XXXX) = 0
95 #endif
96
97 /* Limit testing. */
98
99 #if defined(__NR_ustat) && (__USTAT_NOT_DEPRECATED)
100 __ustat(-1, &ubuf);
101 //staptest// ustat (4294967295, XXXX) = NNNN
102
103 ustat(sbuf.st_dev, (struct ustat *)-1);
104 #ifdef __s390__
105 //staptest// ustat (NNNN, 0x[7]?[f]+) = NNNN
106 #else
107 //staptest// ustat (NNNN, 0x[f]+) = NNNN
108 #endif
109 #endif
110
111 statfs((char *)-1, &buf);
112 #ifdef __s390__
113 //staptest// statfs (0x[7]?[f]+, XXXX) = NNNN
114 #else
115 //staptest// statfs (0x[f]+, XXXX) = NNNN
116 #endif
117
118 // The following SEGVs if compiled as a 32-on-64 bit binary on x86_64 in __statfs()))
119 #if __WORDSIZE == 64
120 statfs("abc", (struct statfs *)-1);
121 #ifdef __s390__
122 //staptest// statfs ("abc", 0x[7]?[f]+) = NNNN
123 #else
124 //staptest// statfs ("abc", 0x[f]+) = NNNN
125 #endif
126 #endif
127
128 fstatfs(-1, &buf);
129 //staptest// fstatfs (-1, XXXX) = NNNN
130
131 // The following SEGVs if compiled as a 32-on-64 bit binary on x86_64 in __statfs()))
132 #if __WORDSIZE == 64
133 fstatfs(fd, (struct statfs *)-1);
134 #ifdef __s390__
135 //staptest// fstatfs (NNNN, 0x[7]?[f]+) = NNNN
136 #else
137 //staptest// fstatfs (NNNN, 0x[f]+) = NNNN
138 #endif
139 #endif
140
141 #ifdef __NR_statfs64
142 __statfs64((char *)-1, sizeof(buf64), &buf64);
143 #ifdef __s390__
144 //staptest// statfs64 (0x[7]?[f]+, NNNN, XXXX) = NNNN
145 #else
146 //staptest// statfs64 (0x[f]+, NNNN, XXXX) = NNNN
147 #endif
148
149 __statfs64("abc", (size_t)-1, NULL);
150 #if __WORDSIZE == 64
151 //staptest// statfs64 ("abc", 18446744073709551615, 0x0) = NNNN
152 #else
153 //staptest// statfs64 ("abc", 4294967295, 0x0) = NNNN
154 #endif
155
156 __statfs64("abc", sizeof(buf64), (struct statfs64 *)-1);
157 #ifdef __s390__
158 //staptest// statfs64 ("abc", NNNN, 0x[7]?[f]+) = NNNN
159 #else
160 //staptest// statfs64 ("abc", NNNN, 0x[f]+) = NNNN
161 #endif
162 #endif
163
164 #ifdef __NR_fstatfs64
165 __fstatfs64(-1, sizeof(buf64), &buf64);
166 //staptest// fstatfs64 (-1, NNNN, XXXX) = NNNN
167
168 __fstatfs64(fd, (size_t)-1, NULL);
169 #if __WORDSIZE == 64
170 //staptest// fstatfs64 (NNNN, 18446744073709551615, 0x0) = NNNN
171 #else
172 //staptest// fstatfs64 (NNNN, 4294967295, 0x0) = NNNN
173 #endif
174
175 __fstatfs64(fd, sizeof(buf64), (struct statfs64 *)-1);
176 #ifdef __s390__
177 //staptest// fstatfs64 (NNNN, NNNN, 0x[7]?[f]+) = NNNN
178 #else
179 //staptest// fstatfs64 (NNNN, NNNN, 0x[f]+) = NNNN
180 #endif
181 #endif
182
183 close(fd);
184 return 0;
185 }