1 /* Begin C code. Put this in a file called cdstatus.c and do "gcc -o
2 * cdstatus cdstatus.c" . No error checking, no looping, no
3 * documentation, if it breaks, you get to keep both pieces. */
12 #include <linux/types.h>
13 #include <linux/cdrom.h>
15 int main(int argc
, char **argv
) {
17 /* ioctl() needs a 3rd arg but it doesn't really use it here. */
22 fprintf(stderr
,"Usage: cdstatus <CD-ROM device name>\n");
26 fd
=open(argv
[1], O_RDONLY
| O_NONBLOCK
); /* need NONBLOCK! */
28 snprintf(buff
,64,"%s cannot be opened\n",argv
[1]);
32 status
=ioctl(fd
,CDROM_DRIVE_STATUS
,buff
);
41 printf("No disc is in the drive.");
45 printf("Tray is open, or tray is closed and no CD is present.");
48 case CDS_DRIVE_NOT_READY
:
49 printf("Drive is not ready.");
53 printf("A disc is in the drive.");
57 printf("Um, we shouldn't be here!");