|
|
大家好,我刚学习linux下的编程,用书上的例子实现了一个简单的ioctl的使用——
弹出CD,可是程序运行在ioctl的时候错误,错误信息如下:
[jackk@killua ch05]$ ./cdrom_eject /dev/hda
The file descriptor is 3:
The return value of the ioctl function is -1:
the error message is :Input/output error
程序源码:
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<sys/ioctl.h>
#include<linux/cdrom.h>
#include<unistd.h>
#include<stdio.h>
#include<string.h>
#include<errno.h>
int main( int argc, char* argv[] ){
/*Open a file descriptor to the device specified on the command line.*/
int tmp;
int fd = open ( argv[1], O_RDONLY );
printf( "The file descriptor is %d:\n", fd );
/*Eject the CD-ROM.*/
tmp = ioctl( fd, CDROMEJECT );
printf( "The return value of the ioctl function is %d:\n", tmp );
if( tmp == -1 ){
fprintf( stderr, "the error message is :%s\n", strerror ( errno ) );
}
/*Close the file descriptor. */
close ( fd );
return 0;
} |
|