X-Git-Url: http://git.thejh.net/?p=moctel.git;a=blobdiff_plain;f=show_ioctl.c;fp=show_ioctl.c;h=e090d9ac0880532c3843080cd14a86335e96d303;hp=0000000000000000000000000000000000000000;hb=b1d5f41202848183d1b6e291afa448c631994d6c;hpb=9ca13033981db455c571e6f54f4ac24938afb94a diff --git a/show_ioctl.c b/show_ioctl.c new file mode 100644 index 0000000..e090d9a --- /dev/null +++ b/show_ioctl.c @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include +#include + +struct fetch_fops_args { + int fd; + uint64_t retp; +}; + +#define MOCTEL_FETCH_FOPS _IOR('m', 1, struct fetch_fops_args) + +struct file_operations { + void *owner; + void *llseek; + void *read; + void *write; + void *aio_read; + void *aio_write; + void *readdir; + void *poll; + void *unlocked_ioctl; + void *compat_ioctl; + void *mmap; + void *open; + void *flush; + void *release; + void *fsync; + void *aio_fsync; + void *fasync; + void *lock; + void *sendpage; + void *get_unmapped_area; + void *check_flags; + void *flock; + void *splice_write; + void *splice_read; + void *setlease; + void *fallocate; +}; + + + +int main(int argc, char **argv) { + if (argc != 2) fputs("Usage: show_ioctl \n", stderr), exit(1); + + char *devname = argv[1]; + int devfd = open(devname, O_RDONLY); + if (devfd == -1) fprintf(stderr, "Can't open %s: %m\n", devname), exit(1); + + int ioctlfd = open("/dev/ioctl_info", O_RDONLY); + if (ioctlfd == -1) fprintf(stderr, "Can't open /dev/ioctl_info: %m\n"), exit(1); + + struct file_operations fops; + struct fetch_fops_args ioctl_args = { + .fd = devfd, + .retp = (uint64_t)&fops + }; + int ret = ioctl(ioctlfd, MOCTEL_FETCH_FOPS, &ioctl_args); + if (ret) fprintf(stderr, "can't perform MOCTEL_FETCH_FOPS: %m\n"), exit(1); + + close(ioctlfd); + close(devfd); + + printf("unlocked_ioctl: %llx\n", (unsigned long long)fops.unlocked_ioctl); + + return 0; +}