]>
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 | ||
de8ee011 | 11 | #if !TARGET_OS_IPHONE |
558d2836 A |
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 | ||
927b7b56 A |
26 | #define HOST_IMAGE "/tmp/external-jnl1.sparseimage" |
27 | #define EXTERNAL_IMAGE "/tmp/external-jnl2.sparseimage" | |
558d2836 A |
28 | |
29 | TEST(external_jnl) | |
30 | ||
31 | int run_external_jnl(__unused test_ctx_t *ctx) | |
32 | { | |
927b7b56 A |
33 | unlink(HOST_IMAGE); |
34 | unlink(EXTERNAL_IMAGE); | |
35 | ||
36 | /* Since disk image cleanup occurs on a stack, create the external | |
37 | * journal partition first so that the cleanup of the host image | |
38 | * prevents a resource busy error during the journal partition ejection. | |
39 | */ | |
40 | disk_image_t *di_ext = disk_image_create(EXTERNAL_IMAGE, | |
558d2836 A |
41 | &(disk_image_opts_t){ |
42 | .partition_type = EXTJNL_CONTENT_TYPE_UUID, | |
43 | .size = 8 * 1024 * 1024 | |
44 | }); | |
45 | ||
927b7b56 A |
46 | disk_image_t *di_host = disk_image_create(HOST_IMAGE, |
47 | &(disk_image_opts_t){ | |
48 | .size = 64 * 1024 * 1024 | |
49 | }); | |
50 | ||
51 | unmount(di_host->mount_point, 0); | |
558d2836 | 52 | |
927b7b56 | 53 | assert(!systemx("/sbin/newfs_hfs", SYSTEMX_QUIET, "-J", "-D", di_ext->disk, di_host->disk, NULL)); |
558d2836 | 54 | |
927b7b56 | 55 | assert(!systemx("/usr/sbin/diskutil", SYSTEMX_QUIET, "mount", di_host->disk, NULL)); |
558d2836 | 56 | |
927b7b56 A |
57 | free((char *)di_host->mount_point); |
58 | di_host->mount_point = NULL; | |
558d2836 A |
59 | |
60 | struct statfs *mntbuf; | |
61 | int i, n = getmntinfo(&mntbuf, 0); | |
62 | for (i = 0; i < n; ++i) { | |
927b7b56 A |
63 | if (!strcmp(mntbuf[i].f_mntfromname, di_host->disk)) { |
64 | di_host->mount_point = strdup(mntbuf[i].f_mntonname); | |
558d2836 A |
65 | break; |
66 | } | |
67 | } | |
68 | ||
69 | assert(i < n); | |
70 | ||
71 | char *path; | |
927b7b56 | 72 | asprintf(&path, "%s/test", di_host->mount_point); |
558d2836 A |
73 | int fd = open(path, O_RDWR | O_CREAT, 0666); |
74 | assert_with_errno(fd >= 0); | |
75 | assert_no_err(close(fd)); | |
76 | assert_no_err(unlink(path)); | |
77 | free(path); | |
78 | ||
79 | return 0; | |
80 | } | |
81 | ||
de8ee011 | 82 | #endif // !TARGET_OS_IPHONE |