]> git.saurik.com Git - apple/xnu.git/blame - tests/xnu_quick_test_entitled.c
xnu-6153.101.6.tar.gz
[apple/xnu.git] / tests / xnu_quick_test_entitled.c
CommitLineData
d9a64523
A
1#include <darwintest.h>
2
3#include <fcntl.h>
4#include <stdlib.h>
5#include <unistd.h>
6#include <sys/types.h>
7#include <sys/sysctl.h>
8#include <sys/disk.h>
9#include <sys/ioctl.h>
10#include <sys/mount.h>
11
cb323159 12#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
d9a64523
A
13#include <sys/csr.h>
14#endif
15
cb323159
A
16T_GLOBAL_META(
17 T_META_NAMESPACE("xnu.quicktest"),
18 T_META_CHECK_LEAKS(false),
19 T_META_RUN_CONCURRENTLY(true)
20 );
d9a64523
A
21
22
23/* **************************************************************************************************************
24 * Test ioctl system calls.
25 * **************************************************************************************************************
26 */
27T_DECL(ioctl, "Sanity check of ioctl by exercising DKIOCGETBLOCKCOUNT and DKIOCGETBLOCKSIZE",
0a7de745 28 T_META_ASROOT(true))
d9a64523 29{
0a7de745
A
30 int my_err;
31 int my_fd = -1;
32 struct statfs * my_infop;
33 char * my_ptr;
34 int my_blksize;
35 long long my_block_count;
36 char my_name[MAXPATHLEN];
d9a64523 37
cb323159 38#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
d9a64523
A
39 /*
40 * this test won't be able to open the root disk device unless CSR is
41 * disabled or in AppleInternal mode
42 */
43 if (csr_check( CSR_ALLOW_UNRESTRICTED_FS ) &&
0a7de745 44 csr_check( CSR_ALLOW_APPLE_INTERNAL )) {
d9a64523
A
45 T_SKIP("System Integrity Protection is enabled");
46 }
47#endif
48
49 T_SETUPBEGIN;
50
51 T_WITH_ERRNO;
52 T_ASSERT_GT(getmntinfo( &my_infop, MNT_NOWAIT ), 0, "getmntinfo");
53
54 /* make this a raw device */
0a7de745
A
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));
d9a64523
A
60 my_ptr[1] = 'r';
61 }
62 }
63
64 T_ASSERT_POSIX_SUCCESS(my_fd = open( &my_name[0], O_RDONLY ), "open");
65
66 T_SETUPEND;
67
68 /* obtain the size of the media (in blocks) */
69 T_EXPECT_POSIX_SUCCESS(my_err = ioctl( my_fd, DKIOCGETBLOCKCOUNT, &my_block_count ),
0a7de745 70 "ioctl DKIOCGETBLOCKCOUNT");
d9a64523
A
71
72 /* obtain the block size of the media */
73 T_EXPECT_POSIX_SUCCESS(my_err = ioctl( my_fd, DKIOCGETBLOCKSIZE, &my_blksize ),
0a7de745 74 "ioctl DKIOCGETBLOCKSIZE");
d9a64523
A
75
76 T_LOG( "my_block_count %qd my_blksize %d \n", my_block_count, my_blksize );
77
78 if (my_err != -1) {
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);
82 }
83
84 close( my_fd );
85}