source: rtems/testsuites/fstests/fsnofs01/init.c @ a7d1992c

Last change on this file since a7d1992c was da154e14, checked in by Sebastian Huber <sebastian.huber@…>, on 05/14/12 at 14:55:41

Filesystem: Move operations to mount table entry

The scope of the file system operations is the file system instance.
The scope of the file system node handlers is the file location. The
benefit of moving the operations to the mount table entry is a size
reduction of the file location (rtems_filesystem_location_info_t). The
code size is slightly increased due to additional load instructions.

Restructure rtems_filesystem_mount_table_entry_t to improve cache
efficiency.

  • Property mode set to 100644
File size: 9.9 KB
Line 
1/*
2 * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Obere Lagerstr. 30
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.com/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include "tmacros.h"
20
21#include <sys/stat.h>
22#include <sys/statvfs.h>
23#include <errno.h>
24#include <fcntl.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <utime.h>
28
29#include <rtems/libio_.h>
30
31static int node_count(const rtems_chain_control *chain)
32{
33  int count = 0;
34  const rtems_chain_node *current = rtems_chain_immutable_first(chain);
35  const rtems_chain_node *tail = rtems_chain_immutable_tail(chain);
36
37  while (current != tail) {
38    ++count;
39
40    current = rtems_chain_immutable_next(current);
41  }
42
43  return count;
44}
45
46static void rtems_test_assert_equal_to_null_loc(
47  const rtems_filesystem_location_info_t *local_loc
48)
49{
50  rtems_filesystem_global_location_t *null_loc =
51    &rtems_filesystem_global_location_null;
52
53  rtems_test_assert(null_loc->location.node_access == local_loc->node_access);
54  rtems_test_assert(null_loc->location.node_access_2 == local_loc->node_access_2);
55  rtems_test_assert(null_loc->location.handlers == local_loc->handlers);
56  rtems_test_assert(null_loc->location.mt_entry == local_loc->mt_entry);
57}
58
59static void test_initial_values(void)
60{
61  rtems_filesystem_global_location_t *null_loc =
62    &rtems_filesystem_global_location_null;
63  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
64  rtems_chain_control *loc_chain = &null_mt->location_chain;
65  rtems_chain_node *loc_node = &null_loc->location.mt_entry_node;
66
67  rtems_test_assert(node_count(loc_chain) == 1);
68  rtems_test_assert(rtems_chain_previous(loc_node) == rtems_chain_head(loc_chain));
69  rtems_test_assert(rtems_chain_next(loc_node) == rtems_chain_tail(loc_chain));
70  rtems_test_assert(null_mt->mt_point_node == null_loc);
71  rtems_test_assert(null_mt->mt_fs_root == null_loc);
72  rtems_test_assert(!null_mt->mounted);
73  rtems_test_assert(!null_mt->writeable);
74  rtems_test_assert(null_loc->reference_count == 4);
75}
76
77static void test_location_obtain(void)
78{
79  rtems_filesystem_global_location_t *global_loc = NULL;
80  rtems_filesystem_global_location_t *null_loc =
81    rtems_filesystem_global_location_obtain(&global_loc);
82  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
83  rtems_chain_control *loc_chain = &null_mt->location_chain;
84
85  rtems_test_assert(node_count(loc_chain) == 1);
86  rtems_test_assert(null_loc->reference_count == 5);
87
88  rtems_filesystem_global_location_release(null_loc);
89
90  rtems_test_assert(node_count(loc_chain) == 1);
91  rtems_test_assert(null_loc->reference_count == 4);
92}
93
94static void test_null_location_obtain(void)
95{
96  rtems_filesystem_global_location_t *null_loc =
97    rtems_filesystem_global_location_obtain_null();
98  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
99  rtems_chain_control *loc_chain = &null_mt->location_chain;
100
101  rtems_test_assert(node_count(loc_chain) == 1);
102  rtems_test_assert(null_loc->reference_count == 5);
103
104  rtems_filesystem_global_location_release(null_loc);
105
106  rtems_test_assert(node_count(loc_chain) == 1);
107  rtems_test_assert(null_loc->reference_count == 4);
108}
109
110static void test_null_location_replace(void)
111{
112  rtems_filesystem_global_location_t *null_loc =
113    &rtems_filesystem_global_location_null;
114  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
115  rtems_chain_control *loc_chain = &null_mt->location_chain;
116  rtems_filesystem_location_info_t local_loc;
117
118  rtems_test_assert(node_count(loc_chain) == 1);
119  rtems_test_assert(null_loc->reference_count == 4);
120  rtems_test_assert(rtems_filesystem_global_location_is_null(null_loc));
121
122  rtems_filesystem_location_copy(&local_loc, &null_loc->location);
123
124  rtems_test_assert(node_count(loc_chain) == 2);
125  rtems_test_assert(null_loc->reference_count == 4);
126
127  rtems_filesystem_location_detach(&local_loc);
128
129  rtems_test_assert(node_count(loc_chain) == 2);
130  rtems_test_assert(null_loc->reference_count == 4);
131  rtems_test_assert(rtems_filesystem_location_is_null(&local_loc));
132  rtems_test_assert_equal_to_null_loc(&local_loc);
133
134  rtems_filesystem_location_free(&local_loc);
135
136  rtems_test_assert(node_count(loc_chain) == 1);
137  rtems_test_assert(null_loc->reference_count == 4);
138}
139
140static void test_null_location_get_and_replace(void)
141{
142  rtems_filesystem_global_location_t *null_loc =
143    &rtems_filesystem_global_location_null;
144  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
145  rtems_chain_control *loc_chain = &null_mt->location_chain;
146  rtems_filesystem_location_info_t local_loc_0;
147  rtems_filesystem_location_info_t local_loc_1;
148
149  rtems_test_assert(node_count(loc_chain) == 1);
150  rtems_test_assert(null_loc->reference_count == 4);
151
152  rtems_filesystem_location_copy(&local_loc_0, &null_loc->location);
153
154  rtems_test_assert(node_count(loc_chain) == 2);
155  rtems_test_assert(null_loc->reference_count == 4);
156  rtems_test_assert_equal_to_null_loc(&local_loc_0);
157
158  rtems_filesystem_location_copy_and_detach(&local_loc_1, &local_loc_0);
159
160  rtems_test_assert(node_count(loc_chain) == 3);
161  rtems_test_assert(null_loc->reference_count == 4);
162  rtems_test_assert_equal_to_null_loc(&local_loc_0);
163  rtems_test_assert_equal_to_null_loc(&local_loc_1);
164
165  rtems_filesystem_location_free(&local_loc_0);
166
167  rtems_test_assert(node_count(loc_chain) == 2);
168  rtems_test_assert(null_loc->reference_count == 4);
169  rtems_test_assert_equal_to_null_loc(&local_loc_1);
170
171  rtems_filesystem_location_free(&local_loc_1);
172
173  rtems_test_assert(node_count(loc_chain) == 1);
174  rtems_test_assert(null_loc->reference_count == 4);
175}
176
177static void test_path_ops(void)
178{
179  int rv = 0;
180  long lrv = 0;
181  struct stat st;
182  struct statvfs stvfs;
183  char buf [32];
184  ssize_t n = 0;
185  const char *path = "/";
186  const struct utimbuf times;
187
188  errno = 0;
189  rv = open(path, O_RDONLY);
190  rtems_test_assert(rv == -1);
191  rtems_test_assert(errno == ENXIO);
192
193  errno = 0;
194  rv = chdir(path);
195  rtems_test_assert(rv == -1);
196  rtems_test_assert(errno == ENXIO);
197
198  errno = 0;
199  rv = chroot(path);
200  rtems_test_assert(rv == -1);
201  rtems_test_assert(errno == ENXIO);
202
203  errno = 0;
204  rv = mknod(path, S_IFREG, 0);
205  rtems_test_assert(rv == -1);
206  rtems_test_assert(errno == ENXIO);
207
208  errno = 0;
209  rv = mkdir(path, 0);
210  rtems_test_assert(rv == -1);
211  rtems_test_assert(errno == ENXIO);
212
213  errno = 0;
214  rv = mkfifo(path, 0);
215  rtems_test_assert(rv == -1);
216  rtems_test_assert(errno == ENXIO);
217
218  errno = 0;
219  rv = stat(path, &st);
220  rtems_test_assert(rv == -1);
221  rtems_test_assert(errno == ENXIO);
222
223  errno = 0;
224  rv = lstat(path, &st);
225  rtems_test_assert(rv == -1);
226  rtems_test_assert(errno == ENXIO);
227
228  errno = 0;
229  rv = statvfs(path, &stvfs);
230  rtems_test_assert(rv == -1);
231  rtems_test_assert(errno == ENXIO);
232
233  errno = 0;
234  n = readlink(path, buf, sizeof(buf));
235  rtems_test_assert(n == -1);
236  rtems_test_assert(errno == ENXIO);
237
238  errno = 0;
239  rv = chmod(path, 0);
240  rtems_test_assert(rv == -1);
241  rtems_test_assert(errno == ENXIO);
242
243  errno = 0;
244  rv = chown(path, 0, 0);
245  rtems_test_assert(rv == -1);
246  rtems_test_assert(errno == ENXIO);
247
248  errno = 0;
249  rv = lchown(path, 0, 0);
250  rtems_test_assert(rv == -1);
251  rtems_test_assert(errno == ENXIO);
252
253  errno = 0;
254  rv = rmdir(path);
255  rtems_test_assert(rv == -1);
256  rtems_test_assert(errno == ENXIO);
257
258  errno = 0;
259  rv = unlink(path);
260  rtems_test_assert(rv == -1);
261  rtems_test_assert(errno == ENXIO);
262
263  errno = 0;
264  rv = truncate(path, 0);
265  rtems_test_assert(rv == -1);
266  rtems_test_assert(errno == ENXIO);
267
268  errno = 0;
269  rv = access(path, 0);
270  rtems_test_assert(rv == -1);
271  rtems_test_assert(errno == ENXIO);
272
273  errno = 0;
274  lrv = pathconf(path, _PC_LINK_MAX);
275  rtems_test_assert(lrv == -1);
276  rtems_test_assert(errno == ENXIO);
277
278  errno = 0;
279  rv = link(path, path);
280  rtems_test_assert(rv == -1);
281  rtems_test_assert(errno == ENXIO);
282
283  errno = 0;
284  rv = symlink(path, path);
285  rtems_test_assert(rv == -1);
286  rtems_test_assert(errno == ENXIO);
287
288  errno = 0;
289  rv = rename(path, path);
290  rtems_test_assert(rv == -1);
291  rtems_test_assert(errno == ENXIO);
292
293  errno = 0;
294  rv = utime(path, &times);
295  rtems_test_assert(rv == -1);
296  rtems_test_assert(errno == ENXIO);
297}
298
299static void test_user_env(void)
300{
301  rtems_status_code sc = RTEMS_SUCCESSFUL;
302  rtems_filesystem_global_location_t *null_loc =
303    &rtems_filesystem_global_location_null;
304  rtems_filesystem_mount_table_entry_t *null_mt = null_loc->location.mt_entry;
305  rtems_chain_control *loc_chain = &null_mt->location_chain;
306
307  rtems_test_assert(node_count(loc_chain) == 1);
308  rtems_test_assert(null_loc->reference_count == 4);
309
310  sc = rtems_libio_set_private_env();
311  rtems_test_assert(sc == RTEMS_UNSATISFIED);
312
313  rtems_test_assert(node_count(loc_chain) == 1);
314  rtems_test_assert(null_loc->reference_count == 4);
315
316  sc = rtems_libio_share_private_env(RTEMS_SELF);
317  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
318
319  rtems_test_assert(node_count(loc_chain) == 1);
320  rtems_test_assert(null_loc->reference_count == 4);
321
322  sc = rtems_libio_share_private_env(rtems_task_self());
323  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
324
325  rtems_test_assert(node_count(loc_chain) == 1);
326  rtems_test_assert(null_loc->reference_count == 4);
327
328  rtems_libio_use_global_env();
329
330  rtems_test_assert(node_count(loc_chain) == 1);
331  rtems_test_assert(null_loc->reference_count == 4);
332}
333
334static void Init(rtems_task_argument arg)
335{
336  printk("\n\n*** TEST FSNOFS 1 ***\n");
337
338  rtems_libio_init();
339
340  test_initial_values();
341  test_location_obtain();
342  test_null_location_obtain();
343  test_null_location_replace();
344  test_null_location_get_and_replace();
345  test_path_ops();
346  test_user_env();
347
348  printk("*** END OF TEST FSNOFS 1 ***\n");
349
350  exit(0);
351}
352
353#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
354
355#define CONFIGURE_APPLICATION_DISABLE_FILESYSTEM
356
357#define CONFIGURE_MAXIMUM_TASKS 1
358
359#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
360
361#define CONFIGURE_INIT
362
363#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.