如何在shell脚本中调用ioctl?
我正在尝试在仅使用 bash 和原始基本实用程序的系统上执行 ioctl 调用。
有没有办法在 shell 脚本中对 /dev 中的特定设备文件执行任意 ioctl 命令(如果参数只是整数),而无需编写 C / perl / python 程序?像这样的东西 “magic_ioctl /dev/console 30 1 2”将调用“ioctl(open("/dev/console"), 30, 1, 2);”。
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);".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正是为此目的编写了 ioctl 工具: https://github.com/jerome -pouiller/ioctl。
目前,无法将多个参数传递给 ioctl 调用。你有一个有用的例子吗?
如果你想调用ioctl(open("/dev/console"), 30, 1);,你可以运行:
但是,对于大多数ioctl,你想要分配一个缓冲区并传递一个指针到 ioctl 调用参数中的该缓冲区。在这种情况下,只需忘记
-v
即可。ioctl
将从标准输入/输出读取/写入缓冲区内容。ioctl
尝试从 ioctl 数字猜测缓冲区大小和方向。最好的是:
ioctl
理解许多(大约 2200 个)ioctl 符号名称。因此你可以调用: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: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:为什么你拒绝 perl/c/python 解决方案?
你可以通过 perl one-liner 来实现这一点,如下所示:
perl -e 需要“sys/ioctl.ph”; ioctl(...);
Why you reject perl/c/python solutions ?
You can made this by perl one-liner like this:
perl -e require "sys/ioctl.ph"; ioctl(...);