2 * Copyright (c) 2014 Apple, Inc. All rights reserved.
4 * Test HFS fsinfo fsctls
7 #include <TargetConditionals.h>
11 #include <sys/ioctl.h>
12 #include <sys/ioccom.h>
13 #include <sys/param.h>
14 #include <sys/mount.h>
19 #include <sys/errno.h>
23 #include <hfs/hfs_fsctl.h>
25 #include "hfs-tests.h"
26 #include "test-utils.h"
29 TEST(fsinfo_cprotect
, .run_as_root
= true)
33 #define TEST_DIR "/tmp"
35 static hfs_fsinfo fsinfo
;
41 } __attribute__((aligned(4), packed
)) attrs
;
43 static void test_fsinfo_file_cprotect_count(void)
47 void *buf
= malloc(1 KB
);
48 unsigned class_B_count
= 0;
52 bzero(&fsinfo
, sizeof(fsinfo
));
53 fsinfo
.header
.version
= HFS_FSINFO_VERSION
;
54 fsinfo
.header
.request_type
= HFS_FSINFO_FILE_CPROTECT_COUNT
;
55 assert_no_err(fsctl(TEST_DIR
, HFSIOC_GET_FSINFO
, &fsinfo
, 0));
56 class_B_count
= fsinfo
.cprotect
.class_B
;
58 for (i
= 0; i
< 10; i
++)
60 asprintf(&path
[i
], "%s/fsinfo_test.data.%u", TEST_DIR
, getpid());
62 assert_with_errno((fd
= open(path
[i
], O_RDWR
| O_TRUNC
| O_CREAT
, 0666)) >= 0);
64 buf
= malloc(buf_size
);
65 memset(buf
, 0x83, buf_size
);
67 assert_no_err(fcntl(fd
, F_SETPROTECTIONCLASS
, 2));
69 struct attrlist attrlist
= {
70 .bitmapcount
= ATTR_BIT_MAP_COUNT
,
71 .commonattr
= ATTR_CMN_FILEID
| ATTR_CMN_DATA_PROTECT_FLAGS
,
74 assert_no_err(fgetattrlist(fd
, &attrlist
, &attrs
, sizeof(attrs
), 0));
75 assert((attrs
.dp_flags
& 0x1f) == 2);
78 assert_no_err(fsctl(TEST_DIR
, HFSIOC_GET_FSINFO
, &fsinfo
, 0));
81 for (i
= 0; i
< 10; i
++)
84 assert(fsinfo
.cprotect
.class_B
>= (class_B_count
+ 5));
88 int run_fsinfo_cprotect(__unused test_ctx_t
*ctx
)
90 // The root file system needs to be HFS
93 assert(statfs("/tmp", &sfs
) == 0);
94 if (strcmp(sfs
.f_fstypename
, "hfs")) {
95 printf("fsinfo_cprotect needs hfs as root file system - skipping.\n");
99 test_fsinfo_file_cprotect_count();
104 #endif // TARGET_OS_EMBEDDED