1f08c3bdfSopenharmony_ci/******************************************************************************/ 2f08c3bdfSopenharmony_ci/* */ 3f08c3bdfSopenharmony_ci/* Copyright (c) International Business Machines Corp., 2001 */ 4f08c3bdfSopenharmony_ci/* Jan 8 2003 - Created - Manoj Iyer manjo@mail.utexas.edu */ 5f08c3bdfSopenharmony_ci/* */ 6f08c3bdfSopenharmony_ci/* This program is free software; you can redistribute it and/or modify */ 7f08c3bdfSopenharmony_ci/* it under the terms of the GNU General Public License as published by */ 8f08c3bdfSopenharmony_ci/* the Free Software Foundation; either version 2 of the License, or */ 9f08c3bdfSopenharmony_ci/* (at your option) any later version. */ 10f08c3bdfSopenharmony_ci/* */ 11f08c3bdfSopenharmony_ci/* This program is distributed in the hope that it will be useful, but */ 12f08c3bdfSopenharmony_ci/* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY */ 13f08c3bdfSopenharmony_ci/* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License */ 14f08c3bdfSopenharmony_ci/* for more details. */ 15f08c3bdfSopenharmony_ci/* */ 16f08c3bdfSopenharmony_ci/* You should have received a copy of the GNU General Public License */ 17f08c3bdfSopenharmony_ci/* along with this program; if not, write to the Free Software Foundation, */ 18f08c3bdfSopenharmony_ci/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ 19f08c3bdfSopenharmony_ci/******************************************************************************/ 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci/* 22f08c3bdfSopenharmony_ci * 23f08c3bdfSopenharmony_ci * Description: This program checks the status of the cdrom drive, it will 24f08c3bdfSopenharmony_ci * return the status as to if the cdrom device is open or is 25f08c3bdfSopenharmony_ci * ready for use. 26f08c3bdfSopenharmony_ci */ 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_ci#include <sys/stat.h> 29f08c3bdfSopenharmony_ci#include <fcntl.h> 30f08c3bdfSopenharmony_ci#include <linux/cdrom.h> 31f08c3bdfSopenharmony_ci#include <sys/ioctl.h> 32f08c3bdfSopenharmony_ci#include <stdlib.h> 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci/* 35f08c3bdfSopenharmony_ci * Exit Vaules: 36f08c3bdfSopenharmony_ci * 0 - No information. 37f08c3bdfSopenharmony_ci * 1 - No disk in the drive. 38f08c3bdfSopenharmony_ci * 2 - CD tray is open. 39f08c3bdfSopenharmony_ci * 3 - CD drive not ready. 40f08c3bdfSopenharmony_ci * 4 - CD disk in drive & drive closed. 41f08c3bdfSopenharmony_ci */ 42f08c3bdfSopenharmony_ciint main(int argc, char *argv[]) 43f08c3bdfSopenharmony_ci{ 44f08c3bdfSopenharmony_ci int fd; 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci if (argc != 2) 47f08c3bdfSopenharmony_ci exit(-1); 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ci if ((fd = open(argv[1], O_RDONLY | O_NONBLOCK)) == -1) 50f08c3bdfSopenharmony_ci exit(-2); 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_ci exit(ioctl(fd, CDROM_DRIVE_STATUS)); 53f08c3bdfSopenharmony_ci} 54