1 #include <TargetConditionals.h>
3 #if !TARGET_OS_EMBEDDED
9 #include <Foundation/Foundation.h>
11 #include "hfs-tests.h"
12 #include "test-utils.h"
14 #include "disk-image.h"
18 static disk_image_t *di;
20 #define DISK_IMAGE "/tmp/hfs_resize.sparseimage"
22 int run_resize(__unused test_ctx_t *ctx)
24 di = disk_image_create(DISK_IMAGE, &(disk_image_opts_t){
25 .size = 100 * 1024 * 1024
30 // Create two fragmented files
31 for (int i = 0; i < 2; ++i) {
33 asprintf(&path, "%s/fragmented-file.%d", di->mount_point, i);
35 fd = open(path, O_RDWR | O_TRUNC | O_CREAT, 0666);
36 assert_with_errno(fd >= 0);
39 * First file we want near the end of the volume. Second file
43 .fst_flags = F_ALLOCATECONTIG | F_ALLOCATEALL,
44 .fst_posmode = F_VOLPOSMODE,
45 .fst_offset = i == 0 ? 80 * 1024 * 1024 : 4096,
50 for (int j = 0; j < 64; ++j) {
52 struct log2phys l2p = {
53 .l2p_contigbytes = 4096,
54 .l2p_devoffset = len - 4096,
57 assert_no_err(fcntl(fd, F_LOG2PHYS_EXT, &l2p));
59 fstore.fst_offset = l2p.l2p_devoffset + 16384;
64 fstore.fst_length = len;
66 assert_no_err(fcntl(fd, F_PREALLOCATE, &fstore));
69 assert_no_err(ftruncate(fd, len));
71 assert_no_err(close(fd));
74 assert(!systemx("/usr/sbin/diskutil", SYSTEMX_QUIET, "resizeVolume", di->mount_point, "40m", NULL));
79 #endif // !TARGET_OS_EMBEDDED