]>
Commit | Line | Data |
---|---|---|
558d2836 A |
1 | // |
2 | // external-jnl.c | |
3 | // hfs | |
4 | // | |
5 | // Created by Chris Suter on 8/11/15. | |
6 | // | |
7 | // | |
8 | ||
9 | #include <TargetConditionals.h> | |
10 | ||
11 | #if !TARGET_OS_EMBEDDED | |
12 | ||
13 | #include <stdio.h> | |
14 | #include <sys/mount.h> | |
15 | #include <unistd.h> | |
16 | #include <stdlib.h> | |
17 | #include <string.h> | |
18 | #include <fcntl.h> | |
19 | ||
20 | #include "hfs-tests.h" | |
21 | #include "disk-image.h" | |
22 | #include "systemx.h" | |
23 | #include "../core/hfs_format.h" | |
24 | #include "test-utils.h" | |
25 | ||
26 | #define DISK_IMAGE_1 "/tmp/external-jnl1.sparseimage" | |
27 | #define DISK_IMAGE_2 "/tmp/external-jnl2.sparseimage" | |
28 | ||
29 | TEST(external_jnl) | |
30 | ||
31 | int run_external_jnl(__unused test_ctx_t *ctx) | |
32 | { | |
33 | unlink(DISK_IMAGE_1); | |
34 | unlink(DISK_IMAGE_2); | |
35 | ||
36 | disk_image_t *di1 = disk_image_create(DISK_IMAGE_1, | |
37 | &(disk_image_opts_t){ | |
38 | .size = 64 * 1024 * 1024 | |
39 | }); | |
40 | disk_image_t *di2 | |
41 | = disk_image_create(DISK_IMAGE_2, | |
42 | &(disk_image_opts_t){ | |
43 | .partition_type = EXTJNL_CONTENT_TYPE_UUID, | |
44 | .size = 8 * 1024 * 1024 | |
45 | }); | |
46 | ||
47 | unmount(di1->mount_point, 0); | |
48 | ||
49 | assert(!systemx("/sbin/newfs_hfs", SYSTEMX_QUIET, "-J", "-D", di2->disk, di1->disk, NULL)); | |
50 | ||
51 | assert(!systemx("/usr/sbin/diskutil", SYSTEMX_QUIET, "mount", di1->disk, NULL)); | |
52 | ||
53 | free((char *)di1->mount_point); | |
54 | di1->mount_point = NULL; | |
55 | ||
56 | struct statfs *mntbuf; | |
57 | int i, n = getmntinfo(&mntbuf, 0); | |
58 | for (i = 0; i < n; ++i) { | |
59 | if (!strcmp(mntbuf[i].f_mntfromname, di1->disk)) { | |
60 | di1->mount_point = strdup(mntbuf[i].f_mntonname); | |
61 | break; | |
62 | } | |
63 | } | |
64 | ||
65 | assert(i < n); | |
66 | ||
67 | char *path; | |
68 | asprintf(&path, "%s/test", di1->mount_point); | |
69 | int fd = open(path, O_RDWR | O_CREAT, 0666); | |
70 | assert_with_errno(fd >= 0); | |
71 | assert_no_err(close(fd)); | |
72 | assert_no_err(unlink(path)); | |
73 | free(path); | |
74 | ||
75 | return 0; | |
76 | } | |
77 | ||
78 | #endif |