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