]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-raw-dev-unaligned.c
10 #include "hfs-tests.h"
11 #include "test-utils.h"
12 #include "disk-image.h"
14 TEST(raw_dev_unaligned
, .run_as_root
= 1);
16 int run_raw_dev_unaligned(__unused test_ctx_t
*ctx
)
20 assert(statfs("/tmp", &sfs
) == 0);
21 if (strcmp(sfs
.f_fstypename
, "hfs")) {
22 printf("raw_dev_aligned needs hfs as root file system - skipping.\n");
26 int fd
= open("/tmp/raw-dev-unaligned", O_CREAT
| O_RDWR
| O_TRUNC
, 0666);
28 assert_with_errno(fd
>= 0);
30 assert_no_err(ftruncate(fd
, 4096));
32 assert_no_err(fcntl(fd
, F_FULLFSYNC
));
34 struct log2phys l2p
= {};
36 assert_no_err(fcntl(fd
, F_LOG2PHYS_EXT
, &l2p
));
38 assert(!strncmp(sfs
.f_mntfromname
, "/dev/disk", 9));
41 asprintf(&rdev
, "/dev/rdisk%s", sfs
.f_mntfromname
+ 9);
44 assert_with_errno((raw_fd
= open(rdev
, O_RDWR
)) >= 0);
46 void *buf
= malloc(16384);
48 off_t offset
= l2p
.l2p_devoffset
;
51 char *p
= (char *)((((uintptr_t)buf
+ 64) & ~63) + 8);
57 check_io(pread(raw_fd
, p
, bs
, offset
), bs
);
60 check_io(pwrite(fd
, &fd
, 4, 0), 4);
62 assert_no_err(fcntl(fd
, F_FULLFSYNC
));
64 char *state
= malloc(bs
);
67 * Make sure it changed on the raw device so we know we've got the
68 * correct location. We can't actually check the contents because
69 * it's encrypted on iOS.
71 check_io(pread(raw_fd
, state
, bs
, offset
), bs
);
73 assert(memcmp(state
, p
, bs
));
75 assert_no_err(close(fd
));
77 for (int i
= 0; i
< 3000; ++i
) {
78 for (unsigned i
= 0; i
< bs
; ++i
)
81 check_io(pwrite(raw_fd
, p
, bs
, offset
), bs
);
82 check_io(pread(raw_fd
, p
, bs
, offset
), bs
);
83 assert(!memcmp(p
, state
, bs
));
87 assert_no_err(close(raw_fd
));
88 assert_no_err(unlink("/tmp/raw-dev-unaligned"));