File: statfs.c

package info (click to toggle)
systemtap 3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 32,860 kB
  • ctags: 12,513
  • sloc: cpp: 58,610; ansic: 58,189; exp: 37,322; sh: 10,633; xml: 7,771; perl: 2,252; python: 2,066; tcl: 1,305; makefile: 969; lisp: 105; java: 100; awk: 94; asm: 91; sed: 16
file content (172 lines) | stat: -rw-r--r-- 4,578 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* COVERAGE: fstatfs statfs ustat fstatfs64 statfs64 */

#define _GNU_SOURCE
#define _LARGEFILE64_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <ustat.h>
#include <sys/vfs.h>
#include <sys/syscall.h>
#include <sys/statfs.h>

// glibc mangles some ustat calls, so define our own using syscall().
#if defined(__NR_ustat)
static inline int __ustat(dev_t dev, struct ustat *ubuf)
{
    return syscall(__NR_ustat, dev, ubuf);
}
#endif

// Here's what the man page says about statfs64()/fstatfs64():
//
//   The original Linux statfs() and fstatfs() system calls were not
//   designed with extremely large file sizes in mind. Subsequently,
//   Linux 2.6 added new statfs64() and fstatfs64() system calls that
//   employ a new structure, statfs64. The new structure contains the
//   same fields as the original statfs structure, but the sizes of
//   various fields are increased, to accommodate large file
//   sizes. The glibc statfs() and fstatfs() wrapper functions
//   transparently deal with the kernel differences.
//
// Note that when _LARGEFILE64_SOURCE is defined, there actually *are*
// statfs64()/fstatfs64() glibc wrappers, but sometimes glibc still
// calls statfs()/fstatfs() anyway. Since we want to explicitly test
// statfs64()/fstatfs64(), we'll make our own wrappers. Also note that
// our wrappers include the 'sz' parameter, which the glibc wrappers
// don't.

#ifdef __NR_statfs64
static inline int __statfs64(const char *path, size_t sz, struct statfs64 *buf)
{
    return syscall(__NR_statfs64, path, sz, buf);
}
#endif

#ifdef __NR_fstatfs64
static inline int __fstatfs64(int fd, size_t sz, struct statfs64 *buf)
{
    return syscall(__NR_fstatfs64, fd, sz, buf);
}
#endif

int main()
{
    int fd;
    struct stat sbuf;
    struct statfs buf;
    struct statfs64 buf64;
#ifdef __NR_ustat
    struct ustat ubuf;
#endif

    fd = open("abc", O_WRONLY|O_CREAT, S_IRWXU);
    fstat(fd, &sbuf);

    // Since ustat() can fail on NFS filesystems, don't check for
    // success here.
#ifdef __NR_ustat
    ustat(sbuf.st_dev, &ubuf);
    //staptest// ustat (NNNN, XXXX) = NNNN
#endif

    statfs("abc", &buf);
    //staptest// statfs ("abc", XXXX) = 0

    fstatfs(fd, &buf);
    //staptest// fstatfs (NNNN, XXXX) = 0

#ifdef __NR_statfs64
    __statfs64("abc", sizeof(buf64), &buf64);
    //staptest// statfs64 ("abc", NNNN, XXXX) = 0
#endif

#ifdef __NR_fstatfs64
    __fstatfs64(fd, sizeof(buf64), &buf64);
    //staptest// fstatfs64 (NNNN, NNNN, XXXX) = 0
#endif

    /* Limit testing. */

#ifdef __NR_ustat
    __ustat(-1, &ubuf);
    //staptest// ustat (4294967295, XXXX) = NNNN

    ustat(sbuf.st_dev, (struct ustat *)-1);
#ifdef __s390__
    //staptest// ustat (NNNN, 0x[7]?[f]+) = NNNN
#else
    //staptest// ustat (NNNN, 0x[f]+) = NNNN
#endif
#endif

    statfs((char *)-1, &buf);
#ifdef __s390__
    //staptest// statfs (0x[7]?[f]+, XXXX) = NNNN
#else
    //staptest// statfs (0x[f]+, XXXX) = NNNN
#endif

    statfs("abc", (struct statfs *)-1);
#ifdef __s390__
    //staptest// statfs ("abc", 0x[7]?[f]+) = NNNN
#else
    //staptest// statfs ("abc", 0x[f]+) = NNNN
#endif

    fstatfs(-1, &buf);
    //staptest// fstatfs (-1, XXXX) = NNNN

    fstatfs(fd, (struct statfs *)-1);
#ifdef __s390__
    //staptest// fstatfs (NNNN, 0x[7]?[f]+) = NNNN
#else
    //staptest// fstatfs (NNNN, 0x[f]+) = NNNN
#endif

#ifdef __NR_statfs64
    __statfs64((char *)-1, sizeof(buf64), &buf64);
#ifdef __s390__
    //staptest// statfs64 (0x[7]?[f]+, NNNN, XXXX) = NNNN
#else
    //staptest// statfs64 (0x[f]+, NNNN, XXXX) = NNNN
#endif

    __statfs64("abc", (size_t)-1, NULL);
#if __WORDSIZE == 64
    //staptest// statfs64 ("abc", 18446744073709551615, 0x0) = NNNN
#else
    //staptest// statfs64 ("abc", 4294967295, 0x0) = NNNN
#endif

    __statfs64("abc", sizeof(buf64), (struct statfs64 *)-1);
#ifdef __s390__
    //staptest// statfs64 ("abc", NNNN, 0x[7]?[f]+) = NNNN
#else
    //staptest// statfs64 ("abc", NNNN, 0x[f]+) = NNNN
#endif
#endif

#ifdef __NR_fstatfs64
    __fstatfs64(-1, sizeof(buf64), &buf64);
    //staptest// fstatfs64 (-1, NNNN, XXXX) = NNNN

    __fstatfs64(fd, (size_t)-1, NULL);
#if __WORDSIZE == 64
    //staptest// fstatfs64 (NNNN, 18446744073709551615, 0x0) = NNNN
#else
    //staptest// fstatfs64 (NNNN, 4294967295, 0x0) = NNNN
#endif

    __fstatfs64(fd, sizeof(buf64), (struct statfs64 *)-1);
#ifdef __s390__
    //staptest// fstatfs64 (NNNN, NNNN, 0x[7]?[f]+) = NNNN
#else
    //staptest// fstatfs64 (NNNN, NNNN, 0x[f]+) = NNNN
#endif
#endif

    close(fd);
    return 0;
}