简体   繁体   中英

How to invoke ioctl in shell script?

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);".

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

Why you reject perl/c/python solutions ? You can made this by perl one-liner like this: perl -e require "sys/ioctl.ph"; ioctl(...); perl -e require "sys/ioctl.ph"; ioctl(...);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM