1 | /* |
---|
2 | * COPYRIGHT (c) 2013 Andrey Mozzhuhin |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.com/license/LICENSE. |
---|
7 | */ |
---|
8 | |
---|
9 | #ifdef HAVE_CONFIG_H |
---|
10 | #include "config.h" |
---|
11 | #endif |
---|
12 | |
---|
13 | #include <sys/statvfs.h> |
---|
14 | #include <string.h> |
---|
15 | #include <fcntl.h> |
---|
16 | |
---|
17 | #include "fstest.h" |
---|
18 | #include "pmacros.h" |
---|
19 | |
---|
20 | static void statvfs_validate(struct statvfs *stat) |
---|
21 | { |
---|
22 | rtems_test_assert(stat->f_bsize > 0); |
---|
23 | rtems_test_assert(stat->f_frsize > 0); |
---|
24 | rtems_test_assert(stat->f_blocks > 0); |
---|
25 | rtems_test_assert(stat->f_bfree <= stat->f_blocks); |
---|
26 | rtems_test_assert(stat->f_bavail <= stat->f_blocks); |
---|
27 | rtems_test_assert(stat->f_ffree <= stat->f_files); |
---|
28 | rtems_test_assert(stat->f_favail <= stat->f_files); |
---|
29 | rtems_test_assert(stat->f_namemax > 0); |
---|
30 | } |
---|
31 | |
---|
32 | static void statvfs_test01(void) |
---|
33 | { |
---|
34 | struct statvfs statbuf1, statbuf2; |
---|
35 | int status; |
---|
36 | int fd; |
---|
37 | ssize_t n; |
---|
38 | const char *databuf = "STATVFS"; |
---|
39 | int datalen = strlen(databuf); |
---|
40 | const char *filename = __func__; |
---|
41 | |
---|
42 | /* |
---|
43 | * Get current filesystem statistics |
---|
44 | */ |
---|
45 | status = statvfs("/", &statbuf1); |
---|
46 | rtems_test_assert(status == 0); |
---|
47 | statvfs_validate(&statbuf1); |
---|
48 | |
---|
49 | /* |
---|
50 | * Create one file |
---|
51 | */ |
---|
52 | fd = open(filename, O_CREAT | O_WRONLY, 0775); |
---|
53 | rtems_test_assert(fd >= 0); |
---|
54 | n = write(fd, databuf, datalen); |
---|
55 | rtems_test_assert(n == datalen); |
---|
56 | status = close(fd); |
---|
57 | rtems_test_assert(status == 0); |
---|
58 | |
---|
59 | /* |
---|
60 | * Get new filesystem statistics |
---|
61 | */ |
---|
62 | status = statvfs("/", &statbuf2); |
---|
63 | rtems_test_assert(status == 0); |
---|
64 | statvfs_validate(&statbuf2); |
---|
65 | |
---|
66 | /* |
---|
67 | * Compare old and new statistics |
---|
68 | */ |
---|
69 | rtems_test_assert(statbuf1.f_bsize == statbuf2.f_bsize); |
---|
70 | rtems_test_assert(statbuf1.f_frsize == statbuf2.f_frsize); |
---|
71 | rtems_test_assert(statbuf1.f_blocks == statbuf2.f_blocks); |
---|
72 | rtems_test_assert(statbuf1.f_bfree >= statbuf2.f_bfree); |
---|
73 | rtems_test_assert(statbuf1.f_bavail >= statbuf2.f_bavail); |
---|
74 | rtems_test_assert(statbuf1.f_ffree >= statbuf2.f_ffree); |
---|
75 | rtems_test_assert(statbuf1.f_favail >= statbuf2.f_favail); |
---|
76 | rtems_test_assert(statbuf1.f_namemax == statbuf2.f_namemax); |
---|
77 | } |
---|
78 | |
---|
79 | /* |
---|
80 | * These tests only get time_t value, and test |
---|
81 | * if they are changed. Thest tests don't check atime |
---|
82 | */ |
---|
83 | void test(void) |
---|
84 | { |
---|
85 | puts( "\n\n*** STATVFS TEST ***"); |
---|
86 | statvfs_test01(); |
---|
87 | puts( "*** END OF STATVFS TEST ***"); |
---|
88 | } |
---|