38

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

Hung-Te Lin
  • 381
  • 1
  • 3
  • 3
  • you could see whether your driver has a sysfs interface. – sehe Nov 10 '11 at 16:03
  • 1
    Seems like you could write a trivial C program to do this. – sorpigal Nov 21 '11 at 16:11
  • 12
    Being able to issue `ioctl` calls in, for example, init scripts on embedded devices (no perl/python), without having to deal with cross-compilation/deployment of a C program (just one line in the script!) would be really handy. Did you manage to get any further with this? – Anthony Feb 24 '15 at 02:29

2 Answers2

13

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
Jérôme Pouiller
  • 9,249
  • 5
  • 39
  • 47
7

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

Sergey Beduev
  • 352
  • 2
  • 15