1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2011. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifdef HAVE_CONFIG_H |
---|
11 | #include "config.h" |
---|
12 | #endif |
---|
13 | |
---|
14 | #include <unistd.h> |
---|
15 | #include <fcntl.h> |
---|
16 | #include <limits.h> |
---|
17 | #include <stdio.h> |
---|
18 | #include <unistd.h> |
---|
19 | #include <errno.h> |
---|
20 | #include <sys/stat.h> |
---|
21 | #include <time.h> |
---|
22 | #include <stdint.h> |
---|
23 | #include <math.h> |
---|
24 | |
---|
25 | #include "fstest.h" |
---|
26 | #include "fs_config.h" |
---|
27 | #include "pmacros.h" |
---|
28 | |
---|
29 | const char rtems_test_name[] = "FSLINK " FILESYSTEM; |
---|
30 | |
---|
31 | /* |
---|
32 | * Test if the successful call works as expect |
---|
33 | */ |
---|
34 | static void link_test01 (void) |
---|
35 | { |
---|
36 | char *name0 = "t0"; |
---|
37 | char *name1 = "t1"; |
---|
38 | char *name2 = "t2"; |
---|
39 | |
---|
40 | |
---|
41 | int status; |
---|
42 | int fd; |
---|
43 | |
---|
44 | mode_t mode = 0644; |
---|
45 | struct stat statbuf; |
---|
46 | |
---|
47 | |
---|
48 | puts ("link creates hardlinks"); |
---|
49 | fd = creat (name0, mode); |
---|
50 | status = close (fd); |
---|
51 | rtems_test_assert (status == 0); |
---|
52 | |
---|
53 | status = stat (name0, &statbuf); |
---|
54 | rtems_test_assert (status == 0); |
---|
55 | rtems_test_assert (statbuf.st_nlink == 1); |
---|
56 | |
---|
57 | puts ("test if the stat is the same"); |
---|
58 | status = link (name0, name1); |
---|
59 | rtems_test_assert (status == 0); |
---|
60 | |
---|
61 | status = stat (name0, &statbuf); |
---|
62 | rtems_test_assert (status == 0); |
---|
63 | |
---|
64 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
65 | rtems_test_assert (statbuf.st_nlink == 2); |
---|
66 | |
---|
67 | status = stat (name1, &statbuf); |
---|
68 | rtems_test_assert (status == 0); |
---|
69 | |
---|
70 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
71 | rtems_test_assert (statbuf.st_nlink == 2); |
---|
72 | |
---|
73 | /* |
---|
74 | * link the file and check the nlink |
---|
75 | */ |
---|
76 | status = link (name1, name2); |
---|
77 | rtems_test_assert (status == 0); |
---|
78 | |
---|
79 | status = stat (name0, &statbuf); |
---|
80 | rtems_test_assert (status == 0); |
---|
81 | |
---|
82 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
83 | rtems_test_assert (statbuf.st_nlink == 3); |
---|
84 | |
---|
85 | status = stat (name1, &statbuf); |
---|
86 | rtems_test_assert (status == 0); |
---|
87 | |
---|
88 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
89 | rtems_test_assert (statbuf.st_nlink == 3); |
---|
90 | |
---|
91 | status = stat (name2, &statbuf); |
---|
92 | rtems_test_assert (status == 0); |
---|
93 | |
---|
94 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
95 | rtems_test_assert (statbuf.st_nlink == 3); |
---|
96 | |
---|
97 | /* |
---|
98 | * call chmod and chown and test. |
---|
99 | */ |
---|
100 | puts ("chmod and chown"); |
---|
101 | |
---|
102 | chown (name1, 65534, 65533); |
---|
103 | |
---|
104 | status = stat (name0, &statbuf); |
---|
105 | rtems_test_assert (status == 0); |
---|
106 | |
---|
107 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
108 | rtems_test_assert (statbuf.st_nlink == 3); |
---|
109 | rtems_test_assert (statbuf.st_uid = 65534); |
---|
110 | rtems_test_assert (statbuf.st_gid = 65533); |
---|
111 | |
---|
112 | status = stat (name1, &statbuf); |
---|
113 | rtems_test_assert (status == 0); |
---|
114 | |
---|
115 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
116 | rtems_test_assert (statbuf.st_nlink == 3); |
---|
117 | rtems_test_assert (statbuf.st_uid = 65534); |
---|
118 | rtems_test_assert (statbuf.st_gid = 65533); |
---|
119 | |
---|
120 | status = stat (name2, &statbuf); |
---|
121 | rtems_test_assert (status == 0); |
---|
122 | |
---|
123 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
124 | rtems_test_assert (statbuf.st_nlink == 3); |
---|
125 | rtems_test_assert (statbuf.st_uid = 65534); |
---|
126 | rtems_test_assert (statbuf.st_gid = 65533); |
---|
127 | |
---|
128 | /* |
---|
129 | * |
---|
130 | * unlink then test if the nlink changes |
---|
131 | */ |
---|
132 | puts ("unlink then stat the file "); |
---|
133 | |
---|
134 | status = unlink (name0); |
---|
135 | rtems_test_assert (status == 0); |
---|
136 | |
---|
137 | status = stat (name0, &statbuf); |
---|
138 | rtems_test_assert (status == -1); |
---|
139 | rtems_test_assert (errno = ENOENT); |
---|
140 | |
---|
141 | status = stat (name1, &statbuf); |
---|
142 | rtems_test_assert (status == 0); |
---|
143 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
144 | rtems_test_assert (statbuf.st_nlink == 2); |
---|
145 | |
---|
146 | status = stat (name2, &statbuf); |
---|
147 | rtems_test_assert (status == 0); |
---|
148 | rtems_test_assert (S_ISREG (statbuf.st_mode)); |
---|
149 | rtems_test_assert (statbuf.st_nlink == 2); |
---|
150 | |
---|
151 | status = unlink (name1); |
---|
152 | rtems_test_assert (status == 0); |
---|
153 | |
---|
154 | status = unlink (name2); |
---|
155 | rtems_test_assert (status == 0); |
---|
156 | |
---|
157 | } |
---|
158 | |
---|
159 | void test (void) |
---|
160 | { |
---|
161 | link_test01 (); |
---|
162 | } |
---|