1 #include <darwintest.h>
7 #include <sys/sysctl.h>
10 #include <sys/mount.h>
12 #if !TARGET_OS_EMBEDDED
16 T_GLOBAL_META (T_META_NAMESPACE("xnu.quicktest"), T_META_CHECK_LEAKS(false));
19 /* **************************************************************************************************************
20 * Test ioctl system calls.
21 * **************************************************************************************************************
23 T_DECL(ioctl
, "Sanity check of ioctl by exercising DKIOCGETBLOCKCOUNT and DKIOCGETBLOCKSIZE",
28 struct statfs
* my_infop
;
31 long long my_block_count
;
32 char my_name
[ MAXPATHLEN
];
34 #if !TARGET_OS_EMBEDDED
36 * this test won't be able to open the root disk device unless CSR is
37 * disabled or in AppleInternal mode
39 if (csr_check( CSR_ALLOW_UNRESTRICTED_FS
) &&
40 csr_check( CSR_ALLOW_APPLE_INTERNAL
) ) {
41 T_SKIP("System Integrity Protection is enabled");
48 T_ASSERT_GT(getmntinfo( &my_infop
, MNT_NOWAIT
), 0, "getmntinfo");
50 /* make this a raw device */
51 strlcpy( &my_name
[0], &my_infop
->f_mntfromname
[0], sizeof(my_name
) );
52 if ( (my_ptr
= strrchr( &my_name
[0], '/' )) != 0 ) {
53 if ( my_ptr
[1] != 'r' ) {
54 my_ptr
[ strlen( my_ptr
) ] = 0x00;
55 memmove( &my_ptr
[2], &my_ptr
[1], (strlen( &my_ptr
[1] ) + 1) );
60 T_ASSERT_POSIX_SUCCESS(my_fd
= open( &my_name
[0], O_RDONLY
), "open");
64 /* obtain the size of the media (in blocks) */
65 T_EXPECT_POSIX_SUCCESS(my_err
= ioctl( my_fd
, DKIOCGETBLOCKCOUNT
, &my_block_count
),
66 "ioctl DKIOCGETBLOCKCOUNT");
68 /* obtain the block size of the media */
69 T_EXPECT_POSIX_SUCCESS(my_err
= ioctl( my_fd
, DKIOCGETBLOCKSIZE
, &my_blksize
),
70 "ioctl DKIOCGETBLOCKSIZE");
72 T_LOG( "my_block_count %qd my_blksize %d \n", my_block_count
, my_blksize
);
75 /* make sure the returned data looks somewhat valid */
76 T_EXPECT_GE(my_blksize
, 0, NULL
);
77 T_EXPECT_LE(my_blksize
, 1024 * 1000, NULL
);