I'm trying to execute an ioctl call on a system with only bash and primitive base utilities.
Is there any way to execute arbitrary ioctl command (if the params are simply integers) to a specific device file in /dev in shell script, without writing C / perl / python programs? Something like "magic_ioctl /dev/console 30 1 2" which would calls "ioctl(open("/dev/console"), 30, 1, 2);".
The ioctl() function manipulates the underlying device parameters of special files. In particular, many operating characteristics of character special files (e.g. terminals) may be controlled with ioctl() requests. The argument d must be an open file descriptor. The second argument is a device-dependent request code.
I wrote ioctl
tool exactly for this purpose: https://github.com/jerome-pouiller/ioctl.
Currently, it is not possible to pass multiple argument to ioctl call. Have you an example where it would be usefull?
If you want to call ioctl(open("/dev/console"), 30, 1);
, you can run:
ioctl /dev/console 30 -v 1
However, for most ioctl, you want to allocate a buffer and pass a pointer to this buffer in argument to ioctl call. In this case, just forget -v
. ioctl
will read/write buffer content from/to standard input/output. ioctl
try to guess buffer size and direction from ioctl number.
The best is: ioctl
understand many (around 2200) ioctl symbolic names. Thus you can call:
ioctl /dev/video0 VIDIOC_QUERYCAP > video_caps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With