]> git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-defrag.c
hfs-522.0.9.tar.gz
[apple/hfs.git] / tests / cases / test-defrag.c
1 /*
2 * Copyright (c) 2016 Apple, Inc. All rights reserved.
3 *
4 * Test HFS defrag fsctls
5 */
6
7 #include <sys/ioctl.h>
8 #include <sys/ioccom.h>
9 #include <sys/param.h>
10 #include <sys/mount.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/errno.h>
16 #include <spawn.h>
17 #include <sys/stat.h>
18 #include <fcntl.h>
19
20 #include "../../core/hfs_fsctl.h"
21 #include "hfs-tests.h"
22 #include "test-utils.h"
23 #include "systemx.h"
24 #include "disk-image.h"
25
26 TEST(defrag, .run_as_root = true)
27
28 int run_defrag(__unused test_ctx_t *ctx)
29 {
30
31 // The root file system needs to be HFS
32 struct statfs sfs;
33
34 assert(statfs("/tmp", &sfs) == 0);
35 if (strcmp(sfs.f_fstypename, "hfs")) {
36 printf("test-defrag needs hfs as root file system - skipping.\n");
37 return 0;
38 }
39
40 /* These two should pass */
41 uint32_t enable_defrag = 1;
42 assert_no_err(fsctl("/tmp", HFSIOC_FORCE_ENABLE_DEFRAG, &enable_defrag, 0));
43
44 uint32_t max_file_size = 50 * 1024 * 1024;
45 assert_no_err(fsctl("/tmp", HFSIOC_SET_MAX_DEFRAG_SIZE, &max_file_size, 0));
46
47 /* This should fail */
48 max_file_size = 500 * 1024 * 1024;
49 int err = fsctl("/tmp", HFSIOC_SET_MAX_DEFRAG_SIZE, &max_file_size, 0);
50 if (err == 0){
51 abort();
52 }
53
54 return 0;
55 }