]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-secluded-rename.c
1 #include <TargetConditionals.h>
3 #if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
10 #include "test-utils.h"
11 #include "disk-image.h"
13 TEST(secluded_rename
, .run_as_root
= true)
15 #define SECLUDE_RENAME 0x00000001
16 extern int rename_ext(const char *from
, const char *to
, unsigned int flags
);
18 static char *file1
, *file2
, *file3
, *dir1
;
20 int run_secluded_rename(__unused test_ctx_t
*ctx
)
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
);
33 int fd
= open(file1
, O_RDWR
| O_CREAT
, 0666);
35 assert_with_errno((fd
>= 0));
38 assert_with_errno(rename_ext(file1
, file2
, SECLUDE_RENAME
) == -1 && errno
== EBUSY
);
40 assert_no_err(close(fd
));
42 fd
= open(file1
, O_EVTONLY
);
43 assert_with_errno(fd
>= 0);
45 assert(rename_ext(file1
, file2
, SECLUDE_RENAME
) == -1 && errno
== EBUSY
);
47 assert_no_err(close(fd
));
49 assert_no_err(rename_ext(file1
, file2
, SECLUDE_RENAME
));
51 assert_no_err(link(file2
, file3
));
53 assert(rename_ext(file2
, file1
, SECLUDE_RENAME
) == -1 && errno
== EMLINK
);
55 assert_no_err(unlink(file3
));
57 assert_no_err(rename_ext(file2
, file1
, SECLUDE_RENAME
));
59 assert_no_err(mkdir(dir1
, 0777));
61 assert(rename_ext(dir1
, file3
, SECLUDE_RENAME
) == -1 && errno
== EISDIR
);
66 #endif // (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)