1 #include <darwintest.h>
7 #include <sys/sysctl.h>
10 #include <sys/mount.h>
12 #if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
17 T_META_NAMESPACE("xnu.quicktest"),
18 T_META_CHECK_LEAKS(false),
19 T_META_RUN_CONCURRENTLY(true)
23 /* **************************************************************************************************************
24 * Test ioctl system calls.
25 * **************************************************************************************************************
27 T_DECL(ioctl
, "Sanity check of ioctl by exercising DKIOCGETBLOCKCOUNT and DKIOCGETBLOCKSIZE",
32 struct statfs
* my_infop
;
35 long long my_block_count
;
36 char my_name
[MAXPATHLEN
];
38 #if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
40 * this test won't be able to open the root disk device unless CSR is
41 * disabled or in AppleInternal mode
43 if (csr_check( CSR_ALLOW_UNRESTRICTED_FS
) &&
44 csr_check( CSR_ALLOW_APPLE_INTERNAL
)) {
45 T_SKIP("System Integrity Protection is enabled");
52 T_ASSERT_GT(getmntinfo( &my_infop
, MNT_NOWAIT
), 0, "getmntinfo");
54 /* make this a raw device */
55 strlcpy( &my_name
[0], &my_infop
->f_mntfromname
[0], sizeof(my_name
));
56 if ((my_ptr
= strrchr( &my_name
[0], '/' )) != 0) {
57 if (my_ptr
[1] != 'r') {
58 my_ptr
[strlen( my_ptr
)] = 0x00;
59 memmove( &my_ptr
[2], &my_ptr
[1], (strlen( &my_ptr
[1] ) + 1));
64 T_ASSERT_POSIX_SUCCESS(my_fd
= open( &my_name
[0], O_RDONLY
), "open");
68 /* obtain the size of the media (in blocks) */
69 T_EXPECT_POSIX_SUCCESS(my_err
= ioctl( my_fd
, DKIOCGETBLOCKCOUNT
, &my_block_count
),
70 "ioctl DKIOCGETBLOCKCOUNT");
72 /* obtain the block size of the media */
73 T_EXPECT_POSIX_SUCCESS(my_err
= ioctl( my_fd
, DKIOCGETBLOCKSIZE
, &my_blksize
),
74 "ioctl DKIOCGETBLOCKSIZE");
76 T_LOG( "my_block_count %qd my_blksize %d \n", my_block_count
, my_blksize
);
79 /* make sure the returned data looks somewhat valid */
80 T_EXPECT_GE(my_blksize
, 0, NULL
);
81 T_EXPECT_LE(my_blksize
, 1024 * 1000, NULL
);