1 #include <sys/statvfs.h>
14 char *filename
= "statvfs_test_XXXXXX";
17 void create_file(void)
21 ssize_t ntowrite
, nwritten
;
25 if ((fd
= mkstemp(filename
)) < 0) e(1);
29 while (ntowrite
> 0) {
30 if ((nwritten
= write(fd
, p
, ntowrite
)) < 0) e(2);
35 if (close(fd
) < 0) e(3);
38 int main(int argc
, char *argv
[])
41 unsigned long f_bsize
, f_bsize_new
;
42 unsigned long f_frsize
, f_frsize_new
;
43 fsblkcnt_t f_blocks
, f_blocks_new
;
44 fsblkcnt_t f_bfree
, f_bfree_new
;
45 fsblkcnt_t f_bavail
, f_bavail_new
;
46 fsfilcnt_t f_files
, f_files_new
;
47 fsfilcnt_t f_ffree
, f_ffree_new
;
48 fsfilcnt_t f_favail
, f_favail_new
;
49 unsigned long f_fsid
, f_fsid_new
;
50 unsigned long f_flag
, f_flag_new
;
51 unsigned long f_namemax
, f_namemax_new
;
57 for(i
= 0; i
< TRIALS
; i
++) {
58 if (statvfs(".", &stats
) < 0) e(1);
60 f_bsize
= stats
.f_bsize
;
61 f_frsize
= stats
.f_frsize
;
62 f_blocks
= stats
.f_blocks
;
63 f_bfree
= stats
.f_bfree
;
64 f_bavail
= stats
.f_bavail
;
65 f_files
= stats
.f_files
;
66 f_ffree
= stats
.f_ffree
;
67 f_favail
= stats
.f_favail
;
68 f_fsid
= stats
.f_fsid
;
69 f_flag
= stats
.f_flag
;
70 f_namemax
= stats
.f_namemax
;
74 if (statvfs(".", &stats
) < 0) e(2);
75 if (unlink(filename
) < 0) e(3);
77 f_bsize_new
= stats
.f_bsize
;
78 f_frsize_new
= stats
.f_frsize
;
79 f_blocks_new
= stats
.f_blocks
;
80 f_bfree_new
= stats
.f_bfree
;
81 f_bavail_new
= stats
.f_bavail
;
82 f_files_new
= stats
.f_files
;
83 f_ffree_new
= stats
.f_ffree
;
84 f_favail_new
= stats
.f_favail
;
85 f_fsid_new
= stats
.f_fsid
;
86 f_flag_new
= stats
.f_flag
;
87 f_namemax_new
= stats
.f_namemax
;
89 if (!((f_bsize
== f_bsize_new
) &&
90 (f_frsize
== f_frsize_new
) &&
91 (f_blocks
== f_blocks_new
) &&
92 (f_bfree
> f_bfree_new
) &&
93 (f_bavail
> f_bavail_new
) &&
94 (f_files
== f_files_new
) &&
95 (f_ffree
== f_ffree_new
+ 1) &&
96 (f_favail
== f_favail_new
+ 1) &&
97 (f_fsid
== f_fsid_new
) &&
98 (f_flag
== f_flag_new
) &&
99 (f_namemax
== f_namemax_new
))) {