]> git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-external-jnl.c
hfs-556.41.1.tar.gz
[apple/hfs.git] / tests / cases / test-external-jnl.c
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_IPHONE
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 HOST_IMAGE "/tmp/external-jnl1.sparseimage"
27 #define EXTERNAL_IMAGE "/tmp/external-jnl2.sparseimage"
28
29 TEST(external_jnl)
30
31 int run_external_jnl(__unused test_ctx_t *ctx)
32 {
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,
41 &(disk_image_opts_t){
42 .partition_type = EXTJNL_CONTENT_TYPE_UUID,
43 .size = 8 * 1024 * 1024
44 });
45
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);
52
53 assert(!systemx("/sbin/newfs_hfs", SYSTEMX_QUIET, "-J", "-D", di_ext->disk, di_host->disk, NULL));
54
55 assert(!systemx("/usr/sbin/diskutil", SYSTEMX_QUIET, "mount", di_host->disk, NULL));
56
57 free((char *)di_host->mount_point);
58 di_host->mount_point = NULL;
59
60 struct statfs *mntbuf;
61 int i, n = getmntinfo(&mntbuf, 0);
62 for (i = 0; i < n; ++i) {
63 if (!strcmp(mntbuf[i].f_mntfromname, di_host->disk)) {
64 di_host->mount_point = strdup(mntbuf[i].f_mntonname);
65 break;
66 }
67 }
68
69 assert(i < n);
70
71 char *path;
72 asprintf(&path, "%s/test", di_host->mount_point);
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
82 #endif // !TARGET_OS_IPHONE