]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-dprotect.c
1 #include <TargetConditionals.h>
16 #include <sys/param.h>
17 #include <sys/mount.h>
19 #include "hfs-tests.h"
20 #include "test-utils.h"
21 #include "disk-image.h"
23 TEST(dprotect
, .run_as_root
= true)
25 #define TEST_FILE "/tmp/dprotect.data"
27 int run_dprotect(__unused test_ctx_t
*ctx
)
29 // The root file system needs to be HFS
32 assert(statfs("/tmp", &sfs
) == 0);
33 if (strcmp(sfs
.f_fstypename
, "hfs")) {
34 printf("dprotect needs hfs as root file system - skipping.\n");
39 int fd
= open_dprotected_np(TEST_FILE
, O_RDWR
| O_CREAT
,
41 assert_with_errno(fd
>= 0);
43 char *ones
= valloc(4096), *buf
= valloc(16384);
45 memset(ones
, 0xff, 4096);
46 memset(buf
, 0xff, 4096);
48 check_io(write(fd
, buf
, 4096), 4096);
50 assert_no_err(fsync(fd
));
52 assert_no_err(close(fd
));
54 fd
= open_dprotected_np(TEST_FILE
, O_RDONLY
, 0, O_DP_GETRAWENCRYPTED
);
57 check_io(pread(fd
, buf
, 4096, 0), 4096);
59 if (!memcmp(ones
, buf
, 4096))
60 assert_fail("data should be encrypted (make sure the volume you're running on has content protection enabled)");
62 assert_no_err(unlink(TEST_FILE
));