/* * cdcheck - check CDROM/DVD status * * Returns 0 if there is a disc in the drive or 1 (drive not ready), * 2 (tray open), 3 (no disc), 4 (no info), 10 (error) * * Copyright (C) 2005 Schlomo Schapiro [GSS] * * Licensed under the GNU GPL http://www.gnu.org/copyleft/gpl.html * * Versions: * 2005-08-04 GSS Initial release * * Installation: * Compile with "gcc -o cdcheck cdcheck.c" and copy to your favourite bin path, * e.g. /usr/bin */ #include #include #include #include int main(int argc,char **argv) { int cdrom; /* CDROM device file descriptor */ int status; if (argc <2 ) { printf("cdcheck /dev/cdrom-device\nreturn 0 if there is a disc inserted\nCopyright (C) 2005 Schlomo Schapiro\nRead the source for more information\n"); exit(9); } if ((cdrom = open(argv[1],O_RDONLY | O_NONBLOCK)) < 0) { perror("open"); exit(1); } status=ioctl(cdrom,CDROM_DRIVE_STATUS); close(cdrom); if (status<0) { perror("ioctl CDROM_DRIVE_STATUS"); exit(10); } exit(4-status); /* 4=disc in should result in a true return code */ }