]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-external-jnl.c
5 // Created by Chris Suter on 8/11/15.
9 #include <TargetConditionals.h>
14 #include <sys/mount.h>
20 #include "hfs-tests.h"
21 #include "disk-image.h"
23 #include "../core/hfs_format.h"
24 #include "test-utils.h"
26 #define HOST_IMAGE "/tmp/external-jnl1.sparseimage"
27 #define EXTERNAL_IMAGE "/tmp/external-jnl2.sparseimage"
31 int run_external_jnl(__unused test_ctx_t
*ctx
)
34 unlink(EXTERNAL_IMAGE
);
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.
40 disk_image_t
*di_ext
= disk_image_create(EXTERNAL_IMAGE
,
42 .partition_type
= EXTJNL_CONTENT_TYPE_UUID
,
43 .size
= 8 * 1024 * 1024
46 disk_image_t
*di_host
= disk_image_create(HOST_IMAGE
,
48 .size
= 64 * 1024 * 1024
51 unmount(di_host
->mount_point
, 0);
53 assert(!systemx("/sbin/newfs_hfs", SYSTEMX_QUIET
, "-J", "-D", di_ext
->disk
, di_host
->disk
, NULL
));
55 assert(!systemx("/usr/sbin/diskutil", SYSTEMX_QUIET
, "mount", di_host
->disk
, NULL
));
57 free((char *)di_host
->mount_point
);
58 di_host
->mount_point
= NULL
;
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
);
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
));
82 #endif // !TARGET_OS_IPHONE