简体   繁体   English

如何在shell脚本中调用ioctl?

[英]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. 我正在尝试在只有bash和原始基础实用程序的系统上执行ioctl调用。

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? 有没有办法在shell脚本中的/ dev中执行任意ioctl命令(如果params只是整数),而不编写C / perl / python程序? Something like "magic_ioctl /dev/console 30 1 2" which would calls "ioctl(open("/dev/console"), 30, 1, 2);". 像“magic_ioctl / dev / console 30 1 2”这样的东西会调用“ioctl(open(”/ dev / console“),30,1,2);”。

I wrote ioctl tool exactly for this purpose: https://github.com/jerome-pouiller/ioctl . 我正是为此目的编写了ioctl工具: https//github.com/jerome-pouiller/ioctl

Currently, it is not possible to pass multiple argument to ioctl call. 目前,不可能将多个参数传递给ioctl调用。 Have you an example where it would be usefull? 你有一个例子,它会有用吗?

If you want to call ioctl(open("/dev/console"), 30, 1); 如果你想调用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. 但是,对于大多数ioctl,您希望分配一个缓冲区并在ioctl调用的参数中将指针传递给此缓冲区。 In this case, just forget -v . 在这种情况下,只需忘记-v ioctl will read/write buffer content from/to standard input/output. ioctl将从/向标准输入/输出读/写缓冲区内容。 ioctl try to guess buffer size and direction from ioctl number. ioctl尝试从ioctl数字猜测缓冲区大小和方向。

The best is: ioctl understand many (around 2200) ioctl symbolic names. 最好的是: ioctl了解许多(约2200个)ioctl符号名称。 Thus you can call: 因此你可以打电话:

ioctl /dev/video0 VIDIOC_QUERYCAP > video_caps

Why you reject perl/c/python solutions ? 为什么拒绝perl / c / python解决方案? You can made this by perl one-liner like this: perl -e require "sys/ioctl.ph"; ioctl(...); 你可以用perl one-liner这样做: perl -e require "sys/ioctl.ph"; ioctl(...); perl -e require "sys/ioctl.ph"; ioctl(...);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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