1 /******************************************************************************/ 2 /* */ 3 /* Copyright (c) International Business Machines Corp., 2001 */ 4 /* */ 5 /* This program is free software; you can redistribute it and/or modify */ 6 /* it under the terms of the GNU General Public License as published by */ 7 /* the Free Software Foundation; either version 2 of the License, or */ 8 /* (at your option) any later version. */ 9 /* */ 10 /* This program is distributed in the hope that it will be useful, but */ 11 /* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY */ 12 /* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License */ 13 /* for more details. */ 14 /* */ 15 /* You should have received a copy of the GNU General Public License */ 16 /* along with this program; if not, write to the Free Software */ 17 /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ 18 /* */ 19 /******************************************************************************/ 20 21 /******************************************************************************/ 22 /* */ 23 /* File: check_tray.c */ 24 /* */ 25 /* Description: This program checks the status of the cdrom drive, it will */ 26 /* return the status as to if the cdrom device is open or is */ 27 /* ready for use. */ 28 /* */ 29 /* History: */ 30 /* Jan 8 2003 - Created - Manoj Iyer manjo (at) mail.utexas.edu */ 31 /* - Note: In the 2.4.19 kenrel ioctl() & this so this program */ 32 /* '2' even when there is no cdrom in the drive. This might be */ 33 /* a kbug. So value 1 is not used in the script to check if */ 34 /* drive is empty. */ 35 /* */ 36 /******************************************************************************/ 37 38 #include <sys/stat.h> 39 #include <fcntl.h> 40 #include <linux/cdrom.h> 41 #include <sys/ioctl.h> 42 #include <stdlib.h> 43 44 /******************************************************************************/ 45 /* */ 46 /* Function: main */ 47 /* */ 48 /* Description: This function opens the cdrom device, and checks the status */ 49 /* of the drive. Note drop the cdrom inside the cd drive for */ 50 /* this program to work usefully. */ 51 /* */ 52 /* Exit Vaules: 0 - No information. */ 53 /* 1 - No disk in the drive. */ 54 /* 2 - CD tray is open. */ 55 /* 3 - CD drive not ready. */ 56 /* 4 - CD disk in drive & drive closed. */ 57 /* */ 58 /******************************************************************************/ 59 60 int main() 61 { 62 int fdcdrom = -1; 63 64 if ((fdcdrom = open("/dev/cdrom", O_RDONLY | O_NONBLOCK)) == -1) 65 exit(-2); 66 67 exit(ioctl(fdcdrom, CDROM_DRIVE_STATUS)); 68 } 69