Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke ioctl in shell script?

Tags:

bash

shell

ioctl

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

like image 744
Hung-Te Lin Avatar asked Nov 10 '11 15:11

Hung-Te Lin


People also ask

What are ioctl commands?

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.


1 Answers

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 
like image 127
Jérôme Pouiller Avatar answered Oct 05 '22 16:10

Jérôme Pouiller