原型
ioctl是input output control的简写,标识输入输出控制,ioctl函数通过对文件描述符的发送命令来控制设备。
ioctl函数通过对文件描述符发送特定的命令来控制文件描述符所代表的设备。
1 2 3 4 5 6 7 8
|
int ioctl(int d, int request, ...);
|
使用参考
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| #include <Linux/cdrom.h> #include <stdio.h> #include <fcntl.h>
int main() { int fd = open("/dev/cdrom", O_RDONLY); # 打开CDROM设备文件 if(fd < 0){ printf("打开CDROM失败\n"); return -1; }
if(!ioctl(fd, CDROMEJECT, NULL)){ printf("成功弹出CDROM\n"); } else { printf("弹出CDROM失败\n"); }
close(fd); return 0; }
|