]>
Commit | Line | Data |
---|---|---|
558d2836 A |
1 | #include <TargetConditionals.h> |
2 | ||
3 | #if TARGET_OS_EMBEDDED | |
4 | ||
5 | #include <fcntl.h> | |
6 | #include <unistd.h> | |
7 | #include <sys/stat.h> | |
8 | ||
9 | #include "hfs-tests.h" | |
10 | #include "test-utils.h" | |
11 | #include "disk-image.h" | |
12 | ||
13 | TEST(secluded_rename, .run_as_root = true) | |
14 | ||
15 | #define SECLUDE_RENAME 0x00000001 | |
16 | extern int rename_ext(const char *from, const char *to, unsigned int flags); | |
17 | ||
18 | static char *file1, *file2, *file3, *dir1; | |
19 | ||
20 | int run_secluded_rename(__unused test_ctx_t *ctx) | |
21 | { | |
22 | disk_image_t *di = disk_image_get(); | |
23 | asprintf(&file1, "%s/secluded-rename.1", di->mount_point); | |
24 | asprintf(&file2, "%s/secluded-rename.2", di->mount_point); | |
25 | asprintf(&file3, "%s/secluded-rename.3", di->mount_point); | |
26 | asprintf(&dir1, "%s/secluded-rename.dir", di->mount_point); | |
27 | ||
28 | unlink(file1); | |
29 | unlink(file2); | |
30 | unlink(file3); | |
31 | unlink(dir1); | |
32 | ||
33 | int fd = open(file1, O_RDWR | O_CREAT, 0666); | |
34 | ||
35 | assert_with_errno((fd >= 0)); | |
36 | ||
37 | errno = 0; | |
38 | assert_with_errno(rename_ext(file1, file2, SECLUDE_RENAME) == -1 && errno == EBUSY); | |
39 | ||
40 | assert_no_err(close(fd)); | |
41 | ||
42 | fd = open(file1, O_EVTONLY); | |
43 | assert_with_errno(fd >= 0); | |
44 | ||
45 | assert(rename_ext(file1, file2, SECLUDE_RENAME) == -1 && errno == EBUSY); | |
46 | ||
47 | assert_no_err(close(fd)); | |
48 | ||
49 | assert_no_err(rename_ext(file1, file2, SECLUDE_RENAME)); | |
50 | ||
51 | assert_no_err(link(file2, file3)); | |
52 | ||
53 | assert(rename_ext(file2, file1, SECLUDE_RENAME) == -1 && errno == EMLINK); | |
54 | ||
55 | assert_no_err(unlink(file3)); | |
56 | ||
57 | assert_no_err(rename_ext(file2, file1, SECLUDE_RENAME)); | |
58 | ||
59 | assert_no_err(mkdir(dir1, 0777)); | |
60 | ||
61 | assert(rename_ext(dir1, file3, SECLUDE_RENAME) == -1 && errno == EISDIR); | |
62 | ||
63 | return 0; | |
64 | } | |
65 | ||
66 | #endif |