1 /* trinity ioctl() support routines */
10 #include "utils.h" // ARRAY_SIZE
12 #define IOCTL_GROUPS_MAX 48
14 static const struct ioctl_group
*grps
[IOCTL_GROUPS_MAX
];
17 void register_ioctl_group(const struct ioctl_group
*grp
)
19 /* group could be empty e.g. if everything is ifdeffed out */
20 if (grp
->ioctls_cnt
== 0)
23 if (grps_cnt
== ARRAY_SIZE(grps
)) {
24 outputerr("WARNING: please grow IOCTL_GROUPS_MAX.\n");
33 const struct ioctl_group
*find_ioctl_group(int fd
)
40 if (fstat(fd
, &stbuf
) < 0)
43 if (stbuf
.st_rdev
== 0)
46 devname
= map_dev(stbuf
.st_rdev
, stbuf
.st_mode
);
50 for (i
=0; i
< grps_cnt
; ++i
) {
51 if (grps
[i
]->fd_test
) {
52 if (grps
[i
]->fd_test(fd
, &stbuf
) == 0)
58 switch (grps
[i
]->devtype
) {
60 /* fall through. misc devices are char devices. */
62 if (!S_ISCHR(stbuf
.st_mode
))
66 if (!S_ISBLK(stbuf
.st_mode
))
72 for (j
=0; j
< grps
[i
]->devs_cnt
; ++j
)
73 if (strcmp(devname
, grps
[i
]->devs
[j
]) == 0)
80 const struct ioctl_group
*get_random_ioctl_group(void)
85 return grps
[rand() % grps_cnt
];
88 void pick_random_ioctl(const struct ioctl_group
*grp
, int childno
)
92 ioctlnr
= rand() % grp
->ioctls_cnt
;
94 shm
->a2
[childno
] = grp
->ioctls
[ioctlnr
].request
;
97 void dump_ioctls(void)
102 for (i
=0; i
< grps_cnt
; ++i
) {
104 outputerr("- %s:\n", grps
[i
]->name
);
105 else if (grps
[i
]->devtype
) {
106 if (grps
[i
]->devtype
== DEV_MISC
)
107 outputerr("- misc devices");
108 else if (grps
[i
]->devtype
== DEV_CHAR
)
109 outputerr("- char devices");
110 else if (grps
[i
]->devtype
== DEV_BLOCK
)
111 outputerr("- block devices");
112 for (j
=0; j
< grps
[i
]->devs_cnt
; ++j
)
118 outputerr("- <unknown>:\n");
120 for (j
=0; j
< grps
[i
]->ioctls_cnt
; ++j
) {
121 outputerr(" - 0x%08x : %s\n",
122 grps
[i
]->ioctls
[j
].request
,
123 grps
[i
]->ioctls
[j
].name
? : "");