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.org/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 <fcntl.h> |
---|
23 | #include <errno.h> |
---|
24 | #include <unistd.h> |
---|
25 | #include <stdio.h> |
---|
26 | |
---|
27 | #include <rtems/libio.h> |
---|
28 | #include <rtems/rtems-rfs-format.h> |
---|
29 | #include <rtems/ramdisk.h> |
---|
30 | |
---|
31 | const char rtems_test_name[] = "FSROFS 1"; |
---|
32 | |
---|
33 | static const rtems_rfs_format_config rfs_config; |
---|
34 | |
---|
35 | static const char rda [] = "/dev/rda"; |
---|
36 | |
---|
37 | static const char mnt [] = "/mnt"; |
---|
38 | |
---|
39 | static const char file [] = "/mnt/file"; |
---|
40 | |
---|
41 | static const char not_exist [] = "/mnt/not_exist"; |
---|
42 | |
---|
43 | static void test_mount(bool writeable) |
---|
44 | { |
---|
45 | int rv; |
---|
46 | const void *data = NULL; |
---|
47 | |
---|
48 | rv = mount( |
---|
49 | rda, |
---|
50 | mnt, |
---|
51 | RTEMS_FILESYSTEM_TYPE_RFS, |
---|
52 | writeable ? RTEMS_FILESYSTEM_READ_WRITE : 0, |
---|
53 | data |
---|
54 | ); |
---|
55 | rtems_test_assert(rv == 0); |
---|
56 | } |
---|
57 | |
---|
58 | static void test_create_file_system(void) |
---|
59 | { |
---|
60 | int rv; |
---|
61 | |
---|
62 | rv = mkdir(mnt, S_IRWXU | S_IRWXG | S_IRWXO); |
---|
63 | rtems_test_assert(rv == 0); |
---|
64 | |
---|
65 | rv = rtems_rfs_format(rda, &rfs_config); |
---|
66 | rtems_test_assert(rv == 0); |
---|
67 | |
---|
68 | test_mount(true); |
---|
69 | |
---|
70 | rv = mknod(file, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0); |
---|
71 | rtems_test_assert(rv == 0); |
---|
72 | |
---|
73 | rv = unmount(mnt); |
---|
74 | rtems_test_assert(rv == 0); |
---|
75 | } |
---|
76 | |
---|
77 | static void test_rofs(void) |
---|
78 | { |
---|
79 | int rv; |
---|
80 | int fd; |
---|
81 | char buf [1]; |
---|
82 | ssize_t n; |
---|
83 | |
---|
84 | test_mount(false); |
---|
85 | |
---|
86 | fd = open(file, O_RDONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); |
---|
87 | rtems_test_assert(fd >= 0); |
---|
88 | |
---|
89 | n = read(fd, buf, sizeof(buf)); |
---|
90 | rtems_test_assert(n == 0); |
---|
91 | |
---|
92 | errno = 0; |
---|
93 | n = write(fd, buf, sizeof(buf)); |
---|
94 | rtems_test_assert(n == -1); |
---|
95 | rtems_test_assert(errno == EBADF); |
---|
96 | |
---|
97 | errno = 0; |
---|
98 | rv = ftruncate(fd, 0); |
---|
99 | rtems_test_assert(rv == -1); |
---|
100 | rtems_test_assert(errno == EINVAL); |
---|
101 | |
---|
102 | errno = 0; |
---|
103 | rv = fchmod(fd, 0); |
---|
104 | rtems_test_assert(rv == -1); |
---|
105 | rtems_test_assert(errno == EROFS); |
---|
106 | |
---|
107 | errno = 0; |
---|
108 | rv = fchown(fd, 0, 0); |
---|
109 | rtems_test_assert(rv == -1); |
---|
110 | rtems_test_assert(errno == EROFS); |
---|
111 | |
---|
112 | rv = close(fd); |
---|
113 | rtems_test_assert(rv == 0); |
---|
114 | |
---|
115 | errno = 0; |
---|
116 | fd = open(not_exist, O_RDONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); |
---|
117 | rtems_test_assert(fd == -1); |
---|
118 | rtems_test_assert(errno == EROFS); |
---|
119 | |
---|
120 | errno = 0; |
---|
121 | rv = mknod(not_exist, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0); |
---|
122 | rtems_test_assert(rv == -1); |
---|
123 | rtems_test_assert(errno == EROFS); |
---|
124 | |
---|
125 | errno = 0; |
---|
126 | rv = mkdir(not_exist, S_IRWXU | S_IRWXG | S_IRWXO); |
---|
127 | rtems_test_assert(rv == -1); |
---|
128 | rtems_test_assert(errno == EROFS); |
---|
129 | |
---|
130 | errno = 0; |
---|
131 | rv = rename(file, not_exist); |
---|
132 | rtems_test_assert(rv == -1); |
---|
133 | rtems_test_assert(errno == EROFS); |
---|
134 | |
---|
135 | errno = 0; |
---|
136 | rv = link(file, not_exist); |
---|
137 | rtems_test_assert(rv == -1); |
---|
138 | rtems_test_assert(errno == EROFS); |
---|
139 | |
---|
140 | errno = 0; |
---|
141 | rv = unlink(file); |
---|
142 | rtems_test_assert(rv == -1); |
---|
143 | rtems_test_assert(errno == EROFS); |
---|
144 | |
---|
145 | errno = 0; |
---|
146 | rv = symlink(file, not_exist); |
---|
147 | rtems_test_assert(rv == -1); |
---|
148 | rtems_test_assert(errno == EROFS); |
---|
149 | |
---|
150 | rv = unmount(mnt); |
---|
151 | rtems_test_assert(rv == 0); |
---|
152 | } |
---|
153 | |
---|
154 | static void Init(rtems_task_argument arg) |
---|
155 | { |
---|
156 | TEST_BEGIN(): |
---|
157 | |
---|
158 | test_create_file_system(); |
---|
159 | test_rofs(); |
---|
160 | |
---|
161 | TEST_END(): |
---|
162 | rtems_test_exit(0); |
---|
163 | } |
---|
164 | |
---|
165 | rtems_ramdisk_config rtems_ramdisk_configuration [] = { |
---|
166 | { .block_size = 512, .block_num = 1024 } |
---|
167 | }; |
---|
168 | |
---|
169 | size_t rtems_ramdisk_configuration_size = 1; |
---|
170 | |
---|
171 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
172 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
173 | #define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY |
---|
174 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK |
---|
175 | |
---|
176 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5 |
---|
177 | |
---|
178 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
179 | #define CONFIGURE_FILESYSTEM_RFS |
---|
180 | |
---|
181 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
182 | |
---|
183 | #define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024) |
---|
184 | |
---|
185 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
186 | |
---|
187 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
188 | |
---|
189 | #define CONFIGURE_INIT |
---|
190 | |
---|
191 | #include <rtems/confdefs.h> |
---|