1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * COPYRIGHT (c) 2014 |
---|
5 | * Andre Marques <andre.lousa.marques at gmail.com> |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions |
---|
9 | * are met: |
---|
10 | * 1. Redistributions of source code must retain the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer. |
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer in the |
---|
14 | * documentation and/or other materials provided with the distribution. |
---|
15 | * |
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifdef HAVE_CONFIG_H |
---|
30 | #include "config.h" |
---|
31 | #endif |
---|
32 | |
---|
33 | #include "fstest.h" |
---|
34 | #include "fs_config.h" |
---|
35 | #include "fstest_support.h" |
---|
36 | #include <tmacros.h> |
---|
37 | |
---|
38 | #include <sys/stat.h> |
---|
39 | #include <fcntl.h> |
---|
40 | #include <stdio.h> |
---|
41 | #include <string.h> |
---|
42 | #include <unistd.h> |
---|
43 | #include <errno.h> |
---|
44 | #include <limits.h> |
---|
45 | |
---|
46 | const char rtems_test_name[] = "FSRENAME " FILESYSTEM; |
---|
47 | |
---|
48 | static void symbolic_link_test (void) |
---|
49 | { |
---|
50 | int fd; |
---|
51 | int status; |
---|
52 | int rv; |
---|
53 | |
---|
54 | const char *name01 = "name01"; |
---|
55 | const char *name02 = "name02"; |
---|
56 | |
---|
57 | const char *symlink01 = "slink01"; |
---|
58 | const char *symlink02 = "slink02"; |
---|
59 | |
---|
60 | char path01[20]; |
---|
61 | |
---|
62 | mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; |
---|
63 | const char *wd = __func__; |
---|
64 | |
---|
65 | struct stat statbuf; |
---|
66 | |
---|
67 | /* |
---|
68 | * Create a new directory and change the current directory to this |
---|
69 | */ |
---|
70 | |
---|
71 | status = mkdir (wd, mode); |
---|
72 | rtems_test_assert (status == 0); |
---|
73 | status = chdir (wd); |
---|
74 | rtems_test_assert (status == 0); |
---|
75 | |
---|
76 | /* |
---|
77 | * The new argument points to a file and |
---|
78 | * the old argument points to a symbolic link to another file. |
---|
79 | */ |
---|
80 | |
---|
81 | puts ("\nOld is a simbolic link and rename operates on the simbolic link itself\n"); |
---|
82 | |
---|
83 | fd = creat (name01, mode); |
---|
84 | rtems_test_assert (fd >= 0); |
---|
85 | status = close (fd); |
---|
86 | rtems_test_assert (status == 0); |
---|
87 | |
---|
88 | fd = creat (name02, mode); |
---|
89 | rtems_test_assert (fd >= 0); |
---|
90 | status = close (fd); |
---|
91 | rtems_test_assert (status == 0); |
---|
92 | |
---|
93 | status = symlink (name01, symlink01); |
---|
94 | rtems_test_assert (status == 0); |
---|
95 | |
---|
96 | EXPECT_EQUAL (0, rename, symlink01, name02); |
---|
97 | EXPECT_EQUAL (0, lstat, name02, &statbuf); |
---|
98 | |
---|
99 | puts ("Testing if name02 is now a symlink"); |
---|
100 | |
---|
101 | if(S_ISLNK(statbuf.st_mode) != 0) |
---|
102 | FS_PASS (); |
---|
103 | else |
---|
104 | FS_FAIL (); |
---|
105 | |
---|
106 | /* |
---|
107 | * Clear directory |
---|
108 | */ |
---|
109 | |
---|
110 | EXPECT_EQUAL (0, unlink, name01); |
---|
111 | EXPECT_EQUAL (0, unlink, name02); |
---|
112 | EXPECT_EQUAL (-1, unlink, symlink01); |
---|
113 | |
---|
114 | /* |
---|
115 | * The new argument points to a symbolic link to another file and |
---|
116 | * the old argument points to a file. |
---|
117 | */ |
---|
118 | |
---|
119 | puts ("\nNew is a simbolic link and rename operates on the simbolic link itself\n"); |
---|
120 | |
---|
121 | fd = creat (name01, mode); |
---|
122 | rtems_test_assert (fd >= 0); |
---|
123 | status = close (fd); |
---|
124 | rtems_test_assert (status == 0); |
---|
125 | |
---|
126 | fd = creat (name02, mode); |
---|
127 | rtems_test_assert (fd >= 0); |
---|
128 | status = close (fd); |
---|
129 | rtems_test_assert (status == 0); |
---|
130 | |
---|
131 | status = symlink (name01, symlink01); |
---|
132 | rtems_test_assert (status == 0); |
---|
133 | |
---|
134 | EXPECT_EQUAL (0, rename, name02, symlink01); |
---|
135 | EXPECT_EQUAL (0, lstat, symlink01, &statbuf); |
---|
136 | |
---|
137 | puts ("Testing that symlink01 is not a symlink"); |
---|
138 | |
---|
139 | if(S_ISLNK(statbuf.st_mode) == 0) |
---|
140 | FS_PASS (); |
---|
141 | else |
---|
142 | FS_FAIL (); |
---|
143 | |
---|
144 | /* |
---|
145 | * Clear directory |
---|
146 | */ |
---|
147 | |
---|
148 | EXPECT_EQUAL (0, unlink, name01); |
---|
149 | EXPECT_EQUAL (-1, unlink, name02); |
---|
150 | EXPECT_EQUAL (0, unlink, symlink01); |
---|
151 | |
---|
152 | /* |
---|
153 | * The new argument points to a file inside a directory and |
---|
154 | * the old argument points to a file which filepath contains |
---|
155 | * a symbolic link loop. |
---|
156 | */ |
---|
157 | |
---|
158 | puts ("\nTesting with symbolic link loop's\n"); |
---|
159 | |
---|
160 | status = symlink (symlink01, symlink02); |
---|
161 | rtems_test_assert (status == 0); |
---|
162 | |
---|
163 | status = symlink (symlink02, symlink01); |
---|
164 | rtems_test_assert (status == 0); |
---|
165 | |
---|
166 | rv = snprintf (path01, sizeof(path01), "%s/test", symlink01); |
---|
167 | rtems_test_assert (rv < sizeof(path01)); |
---|
168 | EXPECT_ERROR (ELOOP, rename, path01, name01); |
---|
169 | |
---|
170 | rv = snprintf (path01, sizeof(path01), "%s/test", symlink02); |
---|
171 | rtems_test_assert (rv < sizeof(path01)); |
---|
172 | EXPECT_ERROR (ELOOP, rename, path01, name01); |
---|
173 | |
---|
174 | /* |
---|
175 | * Clear directory |
---|
176 | */ |
---|
177 | |
---|
178 | EXPECT_EQUAL (-1, unlink, name01); |
---|
179 | EXPECT_EQUAL (0, unlink, symlink01); |
---|
180 | EXPECT_EQUAL (0, unlink, symlink02); |
---|
181 | |
---|
182 | /* |
---|
183 | * The new argument points to a file, which filepath contains |
---|
184 | * a symbolic link loop, and |
---|
185 | * the old argument points to a file inside a directory |
---|
186 | */ |
---|
187 | |
---|
188 | fd = creat (name01, mode); |
---|
189 | rtems_test_assert (fd >= 0); |
---|
190 | status = close (fd); |
---|
191 | rtems_test_assert (status == 0); |
---|
192 | |
---|
193 | status = symlink (symlink01, symlink02); |
---|
194 | rtems_test_assert (status == 0); |
---|
195 | |
---|
196 | status = symlink (symlink02, symlink01); |
---|
197 | rtems_test_assert (status == 0); |
---|
198 | |
---|
199 | rv = snprintf (path01, sizeof(path01), "%s/test", symlink01); |
---|
200 | rtems_test_assert (rv < sizeof(path01)); |
---|
201 | EXPECT_ERROR (ELOOP, rename, name01, path01); |
---|
202 | |
---|
203 | rv = snprintf (path01, sizeof(path01), "%s/test", symlink02); |
---|
204 | rtems_test_assert (rv < sizeof(path01)); |
---|
205 | EXPECT_ERROR (ELOOP, rename, name01, path01); |
---|
206 | |
---|
207 | /* |
---|
208 | * Clear directory |
---|
209 | */ |
---|
210 | |
---|
211 | EXPECT_EQUAL (0, unlink, name01); |
---|
212 | EXPECT_EQUAL (0, unlink, symlink01); |
---|
213 | EXPECT_EQUAL (0, unlink, symlink02); |
---|
214 | |
---|
215 | /* |
---|
216 | * Go back to parent directory |
---|
217 | */ |
---|
218 | |
---|
219 | status = chdir (".."); |
---|
220 | rtems_test_assert (status == 0); |
---|
221 | |
---|
222 | /* |
---|
223 | * Remove test directory |
---|
224 | */ |
---|
225 | |
---|
226 | status = rmdir (wd); |
---|
227 | rtems_test_assert (status == 0); |
---|
228 | } |
---|
229 | |
---|
230 | static void rename_file_twice_test (void) |
---|
231 | { |
---|
232 | const char *name01 = "name01"; |
---|
233 | const char *name02 = "name02"; |
---|
234 | const char *name03 = "name03"; |
---|
235 | mode_t mode; |
---|
236 | int fd; |
---|
237 | int status; |
---|
238 | |
---|
239 | puts ("\nRename file twice\n"); |
---|
240 | |
---|
241 | mode = S_IRWXU | S_IRWXG | S_IRWXO; |
---|
242 | fd = creat (name01, mode); |
---|
243 | rtems_test_assert (fd >= 0); |
---|
244 | status = close (fd); |
---|
245 | rtems_test_assert (status == 0); |
---|
246 | |
---|
247 | EXPECT_EQUAL (0, rename, name01, name02); |
---|
248 | EXPECT_EQUAL (0, rename, name02, name03); |
---|
249 | |
---|
250 | errno = 0; |
---|
251 | EXPECT_EQUAL (-1, unlink, name01); |
---|
252 | rtems_test_assert (errno == ENOENT); |
---|
253 | EXPECT_EQUAL (-1, unlink, name02); |
---|
254 | rtems_test_assert (errno == ENOENT); |
---|
255 | EXPECT_EQUAL (0, unlink, name03); |
---|
256 | } |
---|
257 | |
---|
258 | static void same_file_test (void) |
---|
259 | { |
---|
260 | int fd; |
---|
261 | int status; |
---|
262 | int rv; |
---|
263 | |
---|
264 | const char *name01 = "name01"; |
---|
265 | const char *name02 = "name02"; |
---|
266 | |
---|
267 | const char *dir01 = "dir01"; |
---|
268 | |
---|
269 | char path01[30]; |
---|
270 | |
---|
271 | mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; |
---|
272 | const char *wd = __func__; |
---|
273 | |
---|
274 | /* |
---|
275 | * Create a new directory and change the current directory to this |
---|
276 | */ |
---|
277 | |
---|
278 | status = mkdir (wd, mode); |
---|
279 | rtems_test_assert (status == 0); |
---|
280 | status = chdir (wd); |
---|
281 | rtems_test_assert (status == 0); |
---|
282 | |
---|
283 | /* |
---|
284 | * The new argument points to a file and |
---|
285 | * the old argument points to the same file on the same directory. |
---|
286 | */ |
---|
287 | |
---|
288 | puts ("\nRename file with itself\n"); |
---|
289 | |
---|
290 | fd = creat (name01, mode); |
---|
291 | rtems_test_assert (fd >= 0); |
---|
292 | status = close (fd); |
---|
293 | rtems_test_assert (status == 0); |
---|
294 | |
---|
295 | EXPECT_EQUAL (0, rename, name01, name01); |
---|
296 | |
---|
297 | /* |
---|
298 | * Clear directory |
---|
299 | */ |
---|
300 | |
---|
301 | EXPECT_EQUAL (0, unlink, name01); |
---|
302 | |
---|
303 | /* |
---|
304 | * The new argument points to a file and |
---|
305 | * the old argument points to the same file from another directory. |
---|
306 | */ |
---|
307 | |
---|
308 | puts ("\nRename file with itself through a hard link in another directory\n"); |
---|
309 | |
---|
310 | fd = creat (name01, mode); |
---|
311 | rtems_test_assert (fd >= 0); |
---|
312 | status = close (fd); |
---|
313 | rtems_test_assert (status == 0); |
---|
314 | |
---|
315 | status = mkdir (dir01, mode); |
---|
316 | rtems_test_assert (status == 0); |
---|
317 | |
---|
318 | rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name02); |
---|
319 | rtems_test_assert (rv < sizeof(path01)); |
---|
320 | status = link (name01, path01); |
---|
321 | rtems_test_assert (status == 0); |
---|
322 | |
---|
323 | EXPECT_EQUAL (0, rename, name01, path01); |
---|
324 | |
---|
325 | /* |
---|
326 | * Clear directory |
---|
327 | */ |
---|
328 | |
---|
329 | EXPECT_EQUAL (0, unlink, name01); |
---|
330 | EXPECT_EQUAL (0, unlink, path01); |
---|
331 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
332 | |
---|
333 | /* |
---|
334 | * Go back to parent directory |
---|
335 | */ |
---|
336 | |
---|
337 | status = chdir (".."); |
---|
338 | rtems_test_assert (status == 0); |
---|
339 | |
---|
340 | /* |
---|
341 | * Remove test directory |
---|
342 | */ |
---|
343 | |
---|
344 | status = rmdir (wd); |
---|
345 | rtems_test_assert (status == 0); |
---|
346 | } |
---|
347 | |
---|
348 | static void directory_test (void) |
---|
349 | { |
---|
350 | int fd; |
---|
351 | int status; |
---|
352 | int rv; |
---|
353 | int i; |
---|
354 | |
---|
355 | const char *name01 = "name01"; |
---|
356 | const char *name02 = "name02"; |
---|
357 | |
---|
358 | const char *dir01 = "dir01"; |
---|
359 | const char *dir02 = "dir02"; |
---|
360 | |
---|
361 | char path01[30]; |
---|
362 | |
---|
363 | char link_name[10]; |
---|
364 | |
---|
365 | mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; |
---|
366 | const char *wd = __func__; |
---|
367 | |
---|
368 | struct stat statbuf; |
---|
369 | |
---|
370 | long LINK_MAX_val; |
---|
371 | |
---|
372 | /* |
---|
373 | * Create a new directory and change the current directory to this |
---|
374 | */ |
---|
375 | |
---|
376 | status = mkdir (wd, mode); |
---|
377 | rtems_test_assert (status == 0); |
---|
378 | status = chdir (wd); |
---|
379 | rtems_test_assert (status == 0); |
---|
380 | |
---|
381 | /* |
---|
382 | * The new argument points to a file and |
---|
383 | * the old argument points to a directory. |
---|
384 | */ |
---|
385 | |
---|
386 | puts ("\nRename directory with file\n"); |
---|
387 | |
---|
388 | fd = creat (name01, mode); |
---|
389 | rtems_test_assert (fd >= 0); |
---|
390 | status = close (fd); |
---|
391 | rtems_test_assert (status == 0); |
---|
392 | |
---|
393 | status = mkdir (dir01, mode); |
---|
394 | rtems_test_assert (status == 0); |
---|
395 | |
---|
396 | EXPECT_ERROR (ENOTDIR, rename, dir01, name01); |
---|
397 | |
---|
398 | /* |
---|
399 | * Clear directory |
---|
400 | */ |
---|
401 | |
---|
402 | EXPECT_EQUAL (0, unlink, name01); |
---|
403 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
404 | |
---|
405 | /* |
---|
406 | * The new argument points to a directory and |
---|
407 | * the old argument points to a file. |
---|
408 | */ |
---|
409 | |
---|
410 | puts ("\nRename file with directory\n"); |
---|
411 | |
---|
412 | fd = creat (name01, mode); |
---|
413 | rtems_test_assert (fd >= 0); |
---|
414 | status = close (fd); |
---|
415 | rtems_test_assert (status == 0); |
---|
416 | |
---|
417 | status = mkdir (dir01, mode); |
---|
418 | rtems_test_assert (status == 0); |
---|
419 | |
---|
420 | EXPECT_ERROR (EISDIR, rename, name01, dir01); |
---|
421 | |
---|
422 | /* |
---|
423 | * Clear directory |
---|
424 | */ |
---|
425 | |
---|
426 | EXPECT_EQUAL (0, unlink, name01); |
---|
427 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
428 | |
---|
429 | /* |
---|
430 | * The new argument points to an empty directory and |
---|
431 | * the old argument points to an ancestor directory of new. |
---|
432 | */ |
---|
433 | |
---|
434 | puts ("\nRename directory with ancestor directory\n"); |
---|
435 | |
---|
436 | status = mkdir (dir02, mode); |
---|
437 | rtems_test_assert (status == 0); |
---|
438 | |
---|
439 | rv = snprintf (path01, sizeof(path01), "%s/%s", dir02, dir01); |
---|
440 | rtems_test_assert (rv < sizeof(path01)); |
---|
441 | status = mkdir (path01, mode); |
---|
442 | rtems_test_assert (status == 0); |
---|
443 | |
---|
444 | EXPECT_ERROR (EINVAL, rename, dir02, path01); |
---|
445 | |
---|
446 | /* |
---|
447 | * Clear directory |
---|
448 | */ |
---|
449 | |
---|
450 | EXPECT_EQUAL (0, rmdir, path01); |
---|
451 | EXPECT_EQUAL (0, rmdir, dir02); |
---|
452 | |
---|
453 | /* |
---|
454 | * The new argument points to an empty directory and |
---|
455 | * the old argument points to a non empty directory. |
---|
456 | */ |
---|
457 | |
---|
458 | puts ("\nRename directory with non empty directory\n"); |
---|
459 | |
---|
460 | status = mkdir (dir01, mode); |
---|
461 | rtems_test_assert (status == 0); |
---|
462 | |
---|
463 | status = mkdir (dir02, mode); |
---|
464 | rtems_test_assert (status == 0); |
---|
465 | |
---|
466 | rv = snprintf (path01, sizeof(path01), "%s/%s", dir02, name02); |
---|
467 | rtems_test_assert (rv < sizeof(path01)); |
---|
468 | fd = creat (path01, mode); |
---|
469 | rtems_test_assert (fd >= 0); |
---|
470 | status = close (fd); |
---|
471 | rtems_test_assert (status == 0); |
---|
472 | |
---|
473 | EXPECT_EQUAL (-1, rename, dir01, dir02); |
---|
474 | |
---|
475 | puts("Testing errno for EEXIST or ENOTEMPTY"); |
---|
476 | |
---|
477 | if(errno == EEXIST || errno == ENOTEMPTY) |
---|
478 | FS_PASS (); |
---|
479 | else |
---|
480 | FS_FAIL (); |
---|
481 | |
---|
482 | /* |
---|
483 | * Clear directory |
---|
484 | */ |
---|
485 | |
---|
486 | EXPECT_EQUAL (0, unlink, path01); |
---|
487 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
488 | EXPECT_EQUAL (0, rmdir, dir02); |
---|
489 | |
---|
490 | /* |
---|
491 | * The new argument points to an empty directory and |
---|
492 | * the old argument points to other empty directory. |
---|
493 | */ |
---|
494 | |
---|
495 | puts ("\nRename empty directory with another empty directory\n"); |
---|
496 | |
---|
497 | status = mkdir (dir01, mode); |
---|
498 | rtems_test_assert (status == 0); |
---|
499 | |
---|
500 | status = mkdir (dir02, mode); |
---|
501 | rtems_test_assert (status == 0); |
---|
502 | |
---|
503 | EXPECT_EQUAL (0, rename, dir01, dir02); |
---|
504 | |
---|
505 | /* |
---|
506 | * Clear directory |
---|
507 | */ |
---|
508 | |
---|
509 | EXPECT_EQUAL (-1, rmdir, dir01); |
---|
510 | EXPECT_EQUAL (0, rmdir, dir02); |
---|
511 | |
---|
512 | /* |
---|
513 | * The new argument points to a non existant directory and |
---|
514 | * the old argument points to an existant directory at LINK_MAX. |
---|
515 | */ |
---|
516 | |
---|
517 | status = mkdir (dir01, mode); |
---|
518 | rtems_test_assert (status == 0); |
---|
519 | |
---|
520 | LINK_MAX_val = pathconf (dir01, _PC_LINK_MAX); |
---|
521 | rtems_test_assert (LINK_MAX_val >= 0); |
---|
522 | |
---|
523 | status = stat (dir01, &statbuf); |
---|
524 | rtems_test_assert (status == 0); |
---|
525 | |
---|
526 | for(i = statbuf.st_nlink; i < LINK_MAX_val; i++) |
---|
527 | { |
---|
528 | rv = snprintf (link_name, sizeof(link_name), "%s/%d", dir01, i); |
---|
529 | rtems_test_assert (rv < sizeof(link_name)); |
---|
530 | |
---|
531 | status = mkdir (link_name, mode); |
---|
532 | rtems_test_assert (status == 0); |
---|
533 | } |
---|
534 | |
---|
535 | status = mkdir (dir02, mode); |
---|
536 | rtems_test_assert (status == 0); |
---|
537 | |
---|
538 | rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, dir01); |
---|
539 | rtems_test_assert (rv < sizeof(path01)); |
---|
540 | EXPECT_ERROR (EMLINK, rename, dir02, path01); |
---|
541 | |
---|
542 | /* |
---|
543 | * Clear directory |
---|
544 | */ |
---|
545 | |
---|
546 | for(i = statbuf.st_nlink; i < LINK_MAX_val; i++) |
---|
547 | { |
---|
548 | rv = snprintf (link_name, sizeof(link_name), "%s/%d", dir01, i); |
---|
549 | rtems_test_assert (rv < sizeof(link_name)); |
---|
550 | |
---|
551 | status = rmdir (link_name); |
---|
552 | rtems_test_assert (status == 0); |
---|
553 | } |
---|
554 | |
---|
555 | EXPECT_EQUAL (-1, rmdir, path01); |
---|
556 | EXPECT_EQUAL (0, rmdir, dir02); |
---|
557 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
558 | |
---|
559 | /* |
---|
560 | * The new argument points to a file and |
---|
561 | * the old argument points to another file on a directory with S_ISVTX. |
---|
562 | */ |
---|
563 | |
---|
564 | puts ("\nRename files within directories protected with S_ISVTX\n"); |
---|
565 | |
---|
566 | status = mkdir (dir01, mode | S_ISVTX); |
---|
567 | rtems_test_assert (status == 0); |
---|
568 | |
---|
569 | rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01); |
---|
570 | rtems_test_assert (rv < sizeof(path01)); |
---|
571 | fd = creat (path01, mode); |
---|
572 | rtems_test_assert (fd >= 0); |
---|
573 | status = close (fd); |
---|
574 | rtems_test_assert (status == 0); |
---|
575 | |
---|
576 | fd = creat (name02, mode); |
---|
577 | rtems_test_assert (fd >= 0); |
---|
578 | status = close (fd); |
---|
579 | rtems_test_assert (status == 0); |
---|
580 | |
---|
581 | status = chown (path01, 65534, -1); |
---|
582 | rtems_test_assert (status == 0); |
---|
583 | |
---|
584 | status = chown (dir01, 65534, -1); |
---|
585 | rtems_test_assert (status == 0); |
---|
586 | |
---|
587 | EXPECT_EQUAL (-1, rename, path01, name02); |
---|
588 | |
---|
589 | puts("Testing errno for EPERM or EACCES"); |
---|
590 | |
---|
591 | if(errno == EPERM || errno == EACCES) |
---|
592 | FS_PASS (); |
---|
593 | else |
---|
594 | FS_FAIL (); |
---|
595 | |
---|
596 | /* |
---|
597 | * Clear directory |
---|
598 | */ |
---|
599 | |
---|
600 | EXPECT_EQUAL (0, unlink, path01); |
---|
601 | EXPECT_EQUAL (0, unlink, name02); |
---|
602 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
603 | |
---|
604 | /* |
---|
605 | * The new argument points to a file on a directory with S_ISVTX and |
---|
606 | * the old argument points to a file outside that directory. |
---|
607 | */ |
---|
608 | |
---|
609 | status = mkdir (dir01, mode | S_ISVTX); |
---|
610 | rtems_test_assert (status == 0); |
---|
611 | |
---|
612 | rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01); |
---|
613 | rtems_test_assert (rv < sizeof(path01)); |
---|
614 | fd = creat (path01, mode); |
---|
615 | rtems_test_assert (fd >= 0); |
---|
616 | status = close (fd); |
---|
617 | rtems_test_assert (status == 0); |
---|
618 | |
---|
619 | fd = creat (name02, mode); |
---|
620 | rtems_test_assert (fd >= 0); |
---|
621 | status = close (fd); |
---|
622 | rtems_test_assert (status == 0); |
---|
623 | |
---|
624 | status = chown (path01, 65534, -1); |
---|
625 | rtems_test_assert (status == 0); |
---|
626 | |
---|
627 | status = chown (dir01, 65534, -1); |
---|
628 | rtems_test_assert (status == 0); |
---|
629 | |
---|
630 | EXPECT_EQUAL (-1, rename, name02, path01); |
---|
631 | |
---|
632 | puts("Testing errno for EPERM or EACCES"); |
---|
633 | |
---|
634 | if(errno == EPERM || errno == EACCES) |
---|
635 | FS_PASS (); |
---|
636 | else |
---|
637 | FS_FAIL (); |
---|
638 | |
---|
639 | /* |
---|
640 | * Clear directory |
---|
641 | */ |
---|
642 | |
---|
643 | EXPECT_EQUAL (0, unlink, path01); |
---|
644 | EXPECT_EQUAL (0, unlink, name02); |
---|
645 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
646 | |
---|
647 | /* |
---|
648 | * Go back to parent directory |
---|
649 | */ |
---|
650 | |
---|
651 | status = chdir (".."); |
---|
652 | rtems_test_assert (status == 0); |
---|
653 | |
---|
654 | /* |
---|
655 | * Remove test directory |
---|
656 | */ |
---|
657 | |
---|
658 | status = rmdir (wd); |
---|
659 | rtems_test_assert (status == 0); |
---|
660 | } |
---|
661 | |
---|
662 | static void arg_test (void) |
---|
663 | { |
---|
664 | int fd; |
---|
665 | int status; |
---|
666 | int rv; |
---|
667 | |
---|
668 | const char *name01 = "name01"; |
---|
669 | const char *name02 = "name02"; |
---|
670 | |
---|
671 | const char *dir01 = "dir01"; |
---|
672 | const char *dir02 = "dir02"; |
---|
673 | |
---|
674 | mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; |
---|
675 | const char *wd = __func__; |
---|
676 | |
---|
677 | char filename[NAME_MAX + 2]; |
---|
678 | char path01[20]; |
---|
679 | |
---|
680 | /* |
---|
681 | * Create a new directory and change the current directory to this |
---|
682 | */ |
---|
683 | |
---|
684 | status = mkdir (wd, mode); |
---|
685 | rtems_test_assert (status == 0); |
---|
686 | status = chdir (wd); |
---|
687 | rtems_test_assert (status == 0); |
---|
688 | |
---|
689 | /* |
---|
690 | * The new argument points to a non existant file and |
---|
691 | * the old argument points to a file. |
---|
692 | */ |
---|
693 | |
---|
694 | puts ("\nRename file with non existant file\n"); |
---|
695 | |
---|
696 | fd = creat (name01, mode); |
---|
697 | rtems_test_assert (fd >= 0); |
---|
698 | status = close (fd); |
---|
699 | rtems_test_assert (status == 0); |
---|
700 | |
---|
701 | EXPECT_EQUAL (0, rename, name01, name02); |
---|
702 | |
---|
703 | /* |
---|
704 | * Clear directory |
---|
705 | */ |
---|
706 | |
---|
707 | EXPECT_EQUAL (-1, unlink, name01); |
---|
708 | EXPECT_EQUAL (0, unlink, name02); |
---|
709 | |
---|
710 | /* |
---|
711 | * The new argument points to a file and |
---|
712 | * the old argument points to a non existant file. |
---|
713 | */ |
---|
714 | |
---|
715 | fd = creat (name01, mode); |
---|
716 | rtems_test_assert (fd >= 0); |
---|
717 | status = close (fd); |
---|
718 | rtems_test_assert (status == 0); |
---|
719 | |
---|
720 | EXPECT_ERROR (ENOENT, rename, name02, name01); |
---|
721 | |
---|
722 | /* |
---|
723 | * Clear directory |
---|
724 | */ |
---|
725 | |
---|
726 | EXPECT_EQUAL (0, unlink, name01); |
---|
727 | EXPECT_EQUAL (-1, unlink, name02); |
---|
728 | |
---|
729 | /* |
---|
730 | * The new argument points to a non existant file and |
---|
731 | * the old argument points to a file where a component of the |
---|
732 | * filepath does not exist. |
---|
733 | */ |
---|
734 | |
---|
735 | puts ("\nRename file with non existant filepath\n"); |
---|
736 | |
---|
737 | status = mkdir (dir01, mode); |
---|
738 | rtems_test_assert (status == 0); |
---|
739 | |
---|
740 | rv = snprintf (path01, sizeof(path01), "%s/%s/%s", dir01, name01, name02); |
---|
741 | rtems_test_assert (rv < sizeof(path01)); |
---|
742 | EXPECT_ERROR (ENOENT, rename, path01, name01); |
---|
743 | |
---|
744 | /* |
---|
745 | * Clear directory |
---|
746 | */ |
---|
747 | |
---|
748 | EXPECT_EQUAL (-1, unlink, name01); |
---|
749 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
750 | |
---|
751 | /* |
---|
752 | * The new argument points to a non existant directory and |
---|
753 | * the old argument points to a directory. |
---|
754 | */ |
---|
755 | |
---|
756 | puts ("\nRename directory with non existant directory\n"); |
---|
757 | |
---|
758 | status = mkdir (dir01, mode); |
---|
759 | rtems_test_assert (status == 0); |
---|
760 | |
---|
761 | EXPECT_EQUAL (0, rename, dir01, dir02); |
---|
762 | |
---|
763 | /* |
---|
764 | * Clear directory |
---|
765 | */ |
---|
766 | |
---|
767 | EXPECT_EQUAL (-1, rmdir, dir01); |
---|
768 | EXPECT_EQUAL (0, rmdir, dir02); |
---|
769 | |
---|
770 | /* |
---|
771 | * The new argument is a name bigger than NAME_MAX and |
---|
772 | * the old argument points to a file. |
---|
773 | */ |
---|
774 | |
---|
775 | puts ("\nRename file with a name size exceeding NAME_MAX\n"); |
---|
776 | |
---|
777 | fd = creat (name01, mode); |
---|
778 | rtems_test_assert (fd >= 0); |
---|
779 | status = close (fd); |
---|
780 | rtems_test_assert (status == 0); |
---|
781 | |
---|
782 | /* Generate string with NAME_MAX + 1 length */ |
---|
783 | memset(filename, 'a', NAME_MAX + 1); |
---|
784 | filename[NAME_MAX + 1] = '\0'; |
---|
785 | |
---|
786 | EXPECT_ERROR (ENAMETOOLONG, rename, name01, filename); |
---|
787 | |
---|
788 | /* |
---|
789 | * Clear directory |
---|
790 | */ |
---|
791 | |
---|
792 | EXPECT_EQUAL (0, unlink, name01); |
---|
793 | EXPECT_EQUAL (-1, unlink, filename); |
---|
794 | |
---|
795 | /* |
---|
796 | * Go back to parent directory |
---|
797 | */ |
---|
798 | |
---|
799 | status = chdir (".."); |
---|
800 | rtems_test_assert (status == 0); |
---|
801 | |
---|
802 | /* |
---|
803 | * Remove test directory |
---|
804 | */ |
---|
805 | |
---|
806 | status = rmdir (wd); |
---|
807 | rtems_test_assert (status == 0); |
---|
808 | } |
---|
809 | |
---|
810 | static void arg_format_test (void) |
---|
811 | { |
---|
812 | int fd; |
---|
813 | int status; |
---|
814 | const char *name01 = "name01"; |
---|
815 | |
---|
816 | const char *dir01 = "dir01"; |
---|
817 | |
---|
818 | mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; |
---|
819 | const char *wd = __func__; |
---|
820 | |
---|
821 | /* |
---|
822 | * Create a new directory and change the current directory to this |
---|
823 | */ |
---|
824 | |
---|
825 | status = mkdir (wd, mode); |
---|
826 | rtems_test_assert (status == 0); |
---|
827 | status = chdir (wd); |
---|
828 | rtems_test_assert (status == 0); |
---|
829 | |
---|
830 | /* |
---|
831 | * The new argument points to a directory and |
---|
832 | * the old argument points to current directory. |
---|
833 | */ |
---|
834 | |
---|
835 | puts ("\nRename directory with current directory\n"); |
---|
836 | |
---|
837 | status = mkdir (dir01, mode); |
---|
838 | rtems_test_assert (status == 0); |
---|
839 | |
---|
840 | EXPECT_EQUAL (-1, rename, "." , dir01); |
---|
841 | |
---|
842 | puts("Testing errno for EINVAL or EBUSY"); |
---|
843 | |
---|
844 | if(errno == EINVAL || errno == EBUSY) |
---|
845 | FS_PASS (); |
---|
846 | else |
---|
847 | FS_FAIL (); |
---|
848 | |
---|
849 | /* |
---|
850 | * The new argument points to current directory and |
---|
851 | * the old argument points to a directory. |
---|
852 | */ |
---|
853 | |
---|
854 | EXPECT_EQUAL (-1, rename, dir01, "."); |
---|
855 | |
---|
856 | puts("Testing errno for EINVAL or EBUSY"); |
---|
857 | |
---|
858 | if(errno == EINVAL || errno == EBUSY) |
---|
859 | FS_PASS (); |
---|
860 | else |
---|
861 | FS_FAIL (); |
---|
862 | |
---|
863 | /* |
---|
864 | * The new argument points to a directory and |
---|
865 | * the old argument points to previous directory. |
---|
866 | */ |
---|
867 | |
---|
868 | puts ("\nRename directory with previous directory\n"); |
---|
869 | |
---|
870 | EXPECT_EQUAL (-1, rename, ".." , dir01); |
---|
871 | |
---|
872 | puts("Testing errno for EINVAL or EBUSY"); |
---|
873 | |
---|
874 | if(errno == EINVAL || errno == EBUSY) |
---|
875 | FS_PASS (); |
---|
876 | else |
---|
877 | FS_FAIL (); |
---|
878 | |
---|
879 | /* |
---|
880 | * The new argument points to previous directory and |
---|
881 | * the old argument points to a directory. |
---|
882 | */ |
---|
883 | |
---|
884 | EXPECT_EQUAL (-1, rename, dir01, ".."); |
---|
885 | |
---|
886 | puts("Testing errno for EINVAL or EBUSY"); |
---|
887 | |
---|
888 | if(errno == EINVAL || errno == EBUSY) |
---|
889 | FS_PASS (); |
---|
890 | else |
---|
891 | FS_FAIL (); |
---|
892 | |
---|
893 | /* |
---|
894 | * Clear directory |
---|
895 | */ |
---|
896 | |
---|
897 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
898 | |
---|
899 | /* |
---|
900 | * The new argument points to a file and |
---|
901 | * the old argument is an empty string. |
---|
902 | */ |
---|
903 | |
---|
904 | puts("\nTesting empty filepaths\n"); |
---|
905 | |
---|
906 | fd = creat (name01, mode); |
---|
907 | rtems_test_assert (fd >= 0); |
---|
908 | status = close (fd); |
---|
909 | rtems_test_assert (status == 0); |
---|
910 | |
---|
911 | EXPECT_ERROR (ENOENT, rename, name01, ""); |
---|
912 | |
---|
913 | /* |
---|
914 | * Clear directory |
---|
915 | */ |
---|
916 | |
---|
917 | EXPECT_EQUAL (0, unlink, name01); |
---|
918 | |
---|
919 | /* |
---|
920 | * The new argument is an empty string and |
---|
921 | * the old argument points to a file. |
---|
922 | */ |
---|
923 | |
---|
924 | fd = creat (name01, mode); |
---|
925 | rtems_test_assert (fd >= 0); |
---|
926 | status = close (fd); |
---|
927 | rtems_test_assert (status == 0); |
---|
928 | |
---|
929 | EXPECT_ERROR (ENOENT, rename, "", name01); |
---|
930 | |
---|
931 | /* |
---|
932 | * Clear directory |
---|
933 | */ |
---|
934 | |
---|
935 | EXPECT_EQUAL (0, unlink, name01); |
---|
936 | |
---|
937 | /* |
---|
938 | * Go back to parent directory |
---|
939 | */ |
---|
940 | |
---|
941 | status = chdir (".."); |
---|
942 | rtems_test_assert (status == 0); |
---|
943 | |
---|
944 | /* |
---|
945 | * Remove test directory |
---|
946 | */ |
---|
947 | |
---|
948 | status = rmdir (wd); |
---|
949 | rtems_test_assert (status == 0); |
---|
950 | } |
---|
951 | |
---|
952 | static void write_permission_test (void) |
---|
953 | { |
---|
954 | int fd; |
---|
955 | int status; |
---|
956 | int rv; |
---|
957 | |
---|
958 | const char *name01 = "name01"; |
---|
959 | const char *name02 = "name02"; |
---|
960 | |
---|
961 | const char *dir01 = "dir01"; |
---|
962 | const char *dir02 = "dir02"; |
---|
963 | |
---|
964 | char path01[20]; |
---|
965 | |
---|
966 | mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; |
---|
967 | mode_t no_write_access = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP |
---|
968 | | S_IROTH | S_IXOTH; |
---|
969 | |
---|
970 | const char *wd = __func__; |
---|
971 | |
---|
972 | /* |
---|
973 | * Create a new directory and change the current directory to this |
---|
974 | */ |
---|
975 | |
---|
976 | status = mkdir (wd, mode); |
---|
977 | rtems_test_assert (status == 0); |
---|
978 | status = chdir (wd); |
---|
979 | rtems_test_assert (status == 0); |
---|
980 | |
---|
981 | /* |
---|
982 | * The new argument points to a file and |
---|
983 | * the old argument points to another file, |
---|
984 | * both inside a directory with no write permission. |
---|
985 | */ |
---|
986 | |
---|
987 | puts ("\nRename two files on a directory with no write permission \n"); |
---|
988 | |
---|
989 | status = mkdir (dir01, mode); |
---|
990 | rtems_test_assert (status == 0); |
---|
991 | |
---|
992 | status = chdir (dir01); |
---|
993 | rtems_test_assert (status == 0); |
---|
994 | |
---|
995 | fd = creat (name01, mode); |
---|
996 | rtems_test_assert (fd >= 0); |
---|
997 | status = close (fd); |
---|
998 | rtems_test_assert (status == 0); |
---|
999 | |
---|
1000 | fd = creat (name02, mode); |
---|
1001 | rtems_test_assert (fd >= 0); |
---|
1002 | status = close (fd); |
---|
1003 | rtems_test_assert (status == 0); |
---|
1004 | |
---|
1005 | status = chmod (".", no_write_access); |
---|
1006 | rtems_test_assert (status == 0); |
---|
1007 | |
---|
1008 | EXPECT_ERROR (EACCES, rename, name01 , name02); |
---|
1009 | |
---|
1010 | status = chdir (".."); |
---|
1011 | rtems_test_assert (status == 0); |
---|
1012 | |
---|
1013 | /* |
---|
1014 | * The new argument points to a file in a directory with no write access and |
---|
1015 | * the old argument points to another file on a directory with write access. |
---|
1016 | */ |
---|
1017 | |
---|
1018 | puts ("\nRename file between two directories, with and without write access\n"); |
---|
1019 | |
---|
1020 | status = mkdir (dir02, mode); |
---|
1021 | rtems_test_assert (status == 0); |
---|
1022 | |
---|
1023 | status = chdir (dir02); |
---|
1024 | rtems_test_assert (status == 0); |
---|
1025 | |
---|
1026 | fd = creat (name01, mode); |
---|
1027 | rtems_test_assert (fd >= 0); |
---|
1028 | status = close (fd); |
---|
1029 | rtems_test_assert (status == 0); |
---|
1030 | |
---|
1031 | rv = snprintf (path01, sizeof(path01), "../%s/%s", dir01, name02); |
---|
1032 | rtems_test_assert (rv < sizeof(path01)); |
---|
1033 | EXPECT_ERROR (EACCES, rename, name01, path01); |
---|
1034 | |
---|
1035 | /* |
---|
1036 | * The new argument points to a file in a directory with write access and |
---|
1037 | * the old argument points to another file on a directory without write access. |
---|
1038 | */ |
---|
1039 | |
---|
1040 | EXPECT_ERROR (EACCES, rename, path01, name01); |
---|
1041 | |
---|
1042 | /* |
---|
1043 | * Clear directory |
---|
1044 | */ |
---|
1045 | |
---|
1046 | EXPECT_EQUAL (0, unlink, name01); |
---|
1047 | |
---|
1048 | rv = snprintf (path01, sizeof(path01), "../%s", dir01); |
---|
1049 | rtems_test_assert (rv < sizeof(path01)); |
---|
1050 | status = chmod (path01, mode); |
---|
1051 | rtems_test_assert (status == 0); |
---|
1052 | |
---|
1053 | rv = snprintf (path01, sizeof(path01), "../%s/%s", dir01, name01); |
---|
1054 | rtems_test_assert (rv < sizeof(path01)); |
---|
1055 | EXPECT_EQUAL (0, unlink, path01); |
---|
1056 | |
---|
1057 | rv = snprintf (path01, sizeof(path01), "../%s/%s", dir01, name02); |
---|
1058 | rtems_test_assert (rv < sizeof(path01)); |
---|
1059 | EXPECT_EQUAL (0, unlink, path01); |
---|
1060 | |
---|
1061 | status = chdir (".."); |
---|
1062 | rtems_test_assert (status == 0); |
---|
1063 | |
---|
1064 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
1065 | EXPECT_EQUAL (0, rmdir, dir02); |
---|
1066 | |
---|
1067 | /* |
---|
1068 | * Go back to parent directory |
---|
1069 | */ |
---|
1070 | |
---|
1071 | status = chdir (".."); |
---|
1072 | rtems_test_assert (status == 0); |
---|
1073 | |
---|
1074 | /* |
---|
1075 | * Remove test directory |
---|
1076 | */ |
---|
1077 | |
---|
1078 | status = rmdir (wd); |
---|
1079 | rtems_test_assert (status == 0); |
---|
1080 | } |
---|
1081 | |
---|
1082 | static void search_permission_test (void) |
---|
1083 | { |
---|
1084 | int fd; |
---|
1085 | int status; |
---|
1086 | int rv; |
---|
1087 | |
---|
1088 | const char *name01 = "name01"; |
---|
1089 | const char *name02 = "name02"; |
---|
1090 | |
---|
1091 | const char *dir01 = "dir01"; |
---|
1092 | const char *dir02 = "dir02"; |
---|
1093 | |
---|
1094 | char path01[20]; |
---|
1095 | char path02[20]; |
---|
1096 | |
---|
1097 | mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; |
---|
1098 | mode_t no_execute_access = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
---|
1099 | | S_IROTH | S_IWOTH; |
---|
1100 | |
---|
1101 | const char *wd = __func__; |
---|
1102 | |
---|
1103 | /* |
---|
1104 | * Create a new directory and change the current directory to this |
---|
1105 | */ |
---|
1106 | |
---|
1107 | status = mkdir (wd, mode); |
---|
1108 | rtems_test_assert (status == 0); |
---|
1109 | status = chdir (wd); |
---|
1110 | rtems_test_assert (status == 0); |
---|
1111 | |
---|
1112 | /* |
---|
1113 | * The new argument points to a file and |
---|
1114 | * the old argument points to another file, |
---|
1115 | * both inside a directory with no execute permission. |
---|
1116 | */ |
---|
1117 | |
---|
1118 | puts ("\nRename two files on a directory with no execute permission \n"); |
---|
1119 | |
---|
1120 | status = mkdir (dir01, mode); |
---|
1121 | rtems_test_assert (status == 0); |
---|
1122 | |
---|
1123 | rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01); |
---|
1124 | rtems_test_assert (rv < sizeof(path01)); |
---|
1125 | fd = creat (path01, mode); |
---|
1126 | rtems_test_assert (fd >= 0); |
---|
1127 | status = close (fd); |
---|
1128 | rtems_test_assert (status == 0); |
---|
1129 | |
---|
1130 | rv = snprintf (path02, sizeof(path02), "%s/%s", dir01, name02); |
---|
1131 | rtems_test_assert (rv < sizeof(path02)); |
---|
1132 | fd = creat (path02, mode); |
---|
1133 | rtems_test_assert (fd >= 0); |
---|
1134 | status = close (fd); |
---|
1135 | rtems_test_assert (status == 0); |
---|
1136 | |
---|
1137 | status = chmod (dir01, no_execute_access); |
---|
1138 | rtems_test_assert (status == 0); |
---|
1139 | |
---|
1140 | EXPECT_ERROR (EACCES, rename, path01 , path02); |
---|
1141 | |
---|
1142 | /* |
---|
1143 | * The new argument points to a file in a directory with no execute access and |
---|
1144 | * the old argument points to another file on a directory with execute access. |
---|
1145 | */ |
---|
1146 | |
---|
1147 | puts ("\nRename file between two directories, with and without execute access\n"); |
---|
1148 | |
---|
1149 | status = mkdir (dir02, mode); |
---|
1150 | rtems_test_assert (status == 0); |
---|
1151 | |
---|
1152 | status = chdir (dir02); |
---|
1153 | rtems_test_assert (status == 0); |
---|
1154 | |
---|
1155 | fd = creat (name01, mode); |
---|
1156 | rtems_test_assert (fd >= 0); |
---|
1157 | status = close (fd); |
---|
1158 | rtems_test_assert (status == 0); |
---|
1159 | |
---|
1160 | status = chdir (".."); |
---|
1161 | rtems_test_assert (status == 0); |
---|
1162 | |
---|
1163 | rv = snprintf (path01, sizeof(path01), "%s/%s", dir02, name01); |
---|
1164 | rtems_test_assert (rv < sizeof(path01)); |
---|
1165 | EXPECT_ERROR (EACCES, rename, path01, path02); |
---|
1166 | |
---|
1167 | /* |
---|
1168 | * The new argument points to a file in a directory with execute access and |
---|
1169 | * the old argument points to another file on a directory without execute access. |
---|
1170 | */ |
---|
1171 | |
---|
1172 | EXPECT_ERROR (EACCES, rename, path02, path01); |
---|
1173 | |
---|
1174 | /* |
---|
1175 | * Clear directory |
---|
1176 | */ |
---|
1177 | |
---|
1178 | EXPECT_EQUAL (0, unlink, path01); |
---|
1179 | |
---|
1180 | status = chmod (dir01, mode); |
---|
1181 | rtems_test_assert (status == 0); |
---|
1182 | |
---|
1183 | rv = snprintf (path01, sizeof(path01), "%s/%s", dir01, name01); |
---|
1184 | rtems_test_assert (rv < sizeof(path01)); |
---|
1185 | EXPECT_EQUAL (0, unlink, path01); |
---|
1186 | EXPECT_EQUAL (0, unlink, path02); |
---|
1187 | EXPECT_EQUAL (0, rmdir, dir01); |
---|
1188 | EXPECT_EQUAL (0, rmdir, dir02); |
---|
1189 | |
---|
1190 | /* |
---|
1191 | * Go back to parent directory |
---|
1192 | */ |
---|
1193 | |
---|
1194 | status = chdir (".."); |
---|
1195 | rtems_test_assert (status == 0); |
---|
1196 | |
---|
1197 | /* |
---|
1198 | * Remove test directory |
---|
1199 | */ |
---|
1200 | |
---|
1201 | status = rmdir (wd); |
---|
1202 | rtems_test_assert (status == 0); |
---|
1203 | } |
---|
1204 | |
---|
1205 | static void filesystem_test (void) |
---|
1206 | { |
---|
1207 | int fd; |
---|
1208 | int status; |
---|
1209 | int rv; |
---|
1210 | |
---|
1211 | const char *name01 = "name01"; |
---|
1212 | const char *name02 = "name02"; |
---|
1213 | |
---|
1214 | char path01[20]; |
---|
1215 | |
---|
1216 | mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; |
---|
1217 | const char *wd = __func__; |
---|
1218 | |
---|
1219 | /* |
---|
1220 | * Create a new directory and change the current directory to this |
---|
1221 | */ |
---|
1222 | |
---|
1223 | status = mkdir (wd, mode); |
---|
1224 | rtems_test_assert (status == 0); |
---|
1225 | status = chdir (wd); |
---|
1226 | rtems_test_assert (status == 0); |
---|
1227 | |
---|
1228 | /* |
---|
1229 | * The new argument points to a file on another instance of the filesystem and |
---|
1230 | * the old argument points to a file on the base filesystem. |
---|
1231 | */ |
---|
1232 | |
---|
1233 | puts ("\nRename files across diferent filesystems\n"); |
---|
1234 | |
---|
1235 | rv = chroot ("/"); |
---|
1236 | rtems_test_assert (rv == 0); |
---|
1237 | |
---|
1238 | fd = creat (name01, mode); |
---|
1239 | rtems_test_assert (fd >= 0); |
---|
1240 | status = close (fd); |
---|
1241 | rtems_test_assert (status == 0); |
---|
1242 | |
---|
1243 | rv = snprintf (path01, sizeof(path01), "%s/%s", BASE_FOR_TEST, name02); |
---|
1244 | rtems_test_assert (rv < sizeof(path01)); |
---|
1245 | EXPECT_ERROR (EXDEV, rename, name01, path01); |
---|
1246 | |
---|
1247 | EXPECT_EQUAL (-1, unlink, path01); |
---|
1248 | EXPECT_EQUAL (0, unlink, name01); |
---|
1249 | |
---|
1250 | rv = chroot (BASE_FOR_TEST); |
---|
1251 | rtems_test_assert (rv == 0); |
---|
1252 | |
---|
1253 | /* |
---|
1254 | * Go back to parent directory |
---|
1255 | */ |
---|
1256 | |
---|
1257 | status = chdir (".."); |
---|
1258 | rtems_test_assert (status == 0); |
---|
1259 | |
---|
1260 | /* |
---|
1261 | * Remove test directory |
---|
1262 | */ |
---|
1263 | |
---|
1264 | status = rmdir (wd); |
---|
1265 | rtems_test_assert (status == 0); |
---|
1266 | } |
---|
1267 | |
---|
1268 | void test (void) |
---|
1269 | { |
---|
1270 | symbolic_link_test (); |
---|
1271 | rename_file_twice_test (); |
---|
1272 | same_file_test (); |
---|
1273 | directory_test (); |
---|
1274 | arg_test (); |
---|
1275 | arg_format_test (); |
---|
1276 | write_permission_test (); |
---|
1277 | search_permission_test (); |
---|
1278 | filesystem_test (); |
---|
1279 | } |
---|