]>
Commit | Line | Data |
---|---|---|
558d2836 A |
1 | // |
2 | // test-sparse-dev.c | |
3 | // hfs | |
4 | // | |
5 | // Created by Chris Suter on 8/14/15. | |
6 | // | |
7 | // | |
8 | ||
9 | #include <TargetConditionals.h> | |
10 | ||
11 | #if !TARGET_OS_EMBEDDED | |
12 | ||
13 | #include <sys/mount.h> | |
14 | #include <sys/fcntl.h> | |
15 | #include <unistd.h> | |
16 | ||
17 | #include "hfs-tests.h" | |
18 | #include "disk-image.h" | |
19 | #include "test-utils.h" | |
20 | ||
21 | TEST(sparse_dev) | |
22 | ||
23 | int run_sparse_dev(__unused test_ctx_t *ctx) | |
24 | { | |
25 | disk_image_t *di = disk_image_create("/tmp/sparse-dev.sparseimage", | |
26 | &(disk_image_opts_t) { | |
27 | .size = 64 * 1024 * 1024 | |
28 | }); | |
29 | ||
30 | char *path; | |
31 | asprintf(&path, "%s/child.sparseimage", di->mount_point); | |
32 | ||
33 | disk_image_t *child = disk_image_create(path, | |
34 | &(disk_image_opts_t) { | |
35 | .size = 256 * 1024 * 1024 | |
36 | }); | |
37 | ||
38 | free(path); | |
39 | ||
40 | asprintf(&path, "%s/test.file", child->mount_point); | |
41 | ||
42 | int fd = open(path, O_CREAT | O_RDWR, 0777); | |
43 | assert_with_errno(fd >= 0); | |
44 | ||
45 | assert(ftruncate(fd, 128 * 1024 * 1024) == -1 && errno == ENOSPC); | |
46 | ||
47 | struct statfs sfs; | |
48 | assert_no_err(statfs(child->mount_point, &sfs)); | |
49 | ||
50 | assert(sfs.f_bfree * sfs.f_bsize < 64 * 1024 * 1024); | |
51 | ||
52 | return 0; | |
53 | } | |
54 | ||
55 | #endif // !TARGET_OS_EMBEDDED |