]> git.saurik.com Git - apple/hfs.git/blob - tests/cases/test_disklevel.c
hfs-407.1.3.tar.gz
[apple/hfs.git] / tests / cases / test_disklevel.c
1 #include <fcntl.h>
2 #include <sys/attr.h>
3 #include <unistd.h>
4 #include <sys/stat.h>
5
6 #include "hfs-tests.h"
7 #include "test-utils.h"
8 #include "../core/hfs_fsctl.h"
9 #include "disk-image.h"
10
11 TEST(disklevel)
12
13 int run_disklevel(__unused test_ctx_t *ctx)
14 {
15 disk_image_t *di = disk_image_get();
16 const char *test_hfs_volume = di->mount_point;
17 uint32_t very_low_disk = 0, low_disk = 0, near_low_disk = 0, desired_disk = 0;
18
19 // Make sure initial values are sane.
20 assert_no_err(fsctl(test_hfs_volume, HFSIOC_GET_VERY_LOW_DISK, &very_low_disk, 0));
21 assert_no_err(fsctl(test_hfs_volume, HFSIOC_GET_LOW_DISK, &low_disk, 0));
22 assert_no_err(fsctl(test_hfs_volume, APFSIOC_GET_NEAR_LOW_DISK, &near_low_disk, 0));
23 assert_no_err(fsctl(test_hfs_volume, HFSIOC_GET_DESIRED_DISK, &desired_disk, 0));
24 assert(very_low_disk > 0);
25 assert(very_low_disk < low_disk);
26 assert(low_disk < near_low_disk);
27 assert(near_low_disk < desired_disk);
28
29 very_low_disk = 1;
30 low_disk = 2;
31 near_low_disk = 3;
32 desired_disk = 4;
33 // Re-assign the values to new legal values and make sure they are preserved.
34 assert_no_err(fsctl(test_hfs_volume, HFSIOC_SET_VERY_LOW_DISK, &very_low_disk, 0));
35 assert_no_err(fsctl(test_hfs_volume, HFSIOC_SET_LOW_DISK, &low_disk, 0));
36 assert_no_err(fsctl(test_hfs_volume, APFSIOC_SET_NEAR_LOW_DISK, &near_low_disk, 0));
37 assert_no_err(fsctl(test_hfs_volume, HFSIOC_SET_DESIRED_DISK, &desired_disk, 0));
38
39 assert_no_err(fsctl(test_hfs_volume, HFSIOC_GET_VERY_LOW_DISK, &very_low_disk, 0));
40 assert_no_err(fsctl(test_hfs_volume, HFSIOC_GET_LOW_DISK, &low_disk, 0));
41 assert_no_err(fsctl(test_hfs_volume, APFSIOC_GET_NEAR_LOW_DISK, &near_low_disk, 0));
42 assert_no_err(fsctl(test_hfs_volume, HFSIOC_GET_DESIRED_DISK, &desired_disk, 0));
43 assert_equal(very_low_disk, 1, "%d");
44 assert_equal(low_disk, 2, "%d");
45 assert_equal(near_low_disk, 3, "%d");
46 assert_equal(desired_disk, 4, "%d");
47
48 // Now, attempt to reassign the levels to illegal values and make sure they don't lose their previous value.
49 very_low_disk = 4;
50 low_disk = 1;
51 near_low_disk = 2;
52 desired_disk = 0;
53 assert(fsctl(test_hfs_volume, HFSIOC_SET_VERY_LOW_DISK, &very_low_disk, 0) < 0);
54 assert(fsctl(test_hfs_volume, HFSIOC_SET_LOW_DISK, &low_disk, 0) < 0);
55 assert(fsctl(test_hfs_volume, APFSIOC_SET_NEAR_LOW_DISK, &near_low_disk, 0) < 0);
56 assert(fsctl(test_hfs_volume, HFSIOC_SET_DESIRED_DISK, &desired_disk, 0) < 0);
57
58 assert_no_err(fsctl(test_hfs_volume, HFSIOC_GET_VERY_LOW_DISK, &very_low_disk, 0));
59 assert_no_err(fsctl(test_hfs_volume, HFSIOC_GET_LOW_DISK, &low_disk, 0));
60 assert_no_err(fsctl(test_hfs_volume, APFSIOC_GET_NEAR_LOW_DISK, &near_low_disk, 0));
61 assert_no_err(fsctl(test_hfs_volume, HFSIOC_GET_DESIRED_DISK, &desired_disk, 0));
62 assert_equal(very_low_disk, 1, "%d");
63 assert_equal(low_disk, 2, "%d");
64 assert_equal(near_low_disk, 3, "%d");
65 assert_equal(desired_disk, 4, "%d");
66
67 return 0;
68 }