1 /******************************************************************************/
3 /* Copyright (c) International Business Machines Corp., 2001 */
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. */
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. */
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19 /******************************************************************************/
21 /******************************************************************************/
23 /* File: check_tray.c */
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 */
30 /* Jan 8 2003 - Created - Manoj Iyer manjo@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 */
36 /******************************************************************************/
40 #include <linux/cdrom.h>
41 #include <sys/ioctl.h>
44 /******************************************************************************/
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. */
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. */
58 /******************************************************************************/
65 if ((fdcdrom
= open("/dev/cdrom", O_RDONLY
|O_NONBLOCK
)) == -1)
68 exit (ioctl(fdcdrom
, CDROM_DRIVE_STATUS
));