/* makedvdpluswork.c: A program for dealing with pesky DVD drives that * have "random" compatability with DVD+R(W) media. * Copyright (C) 2006 Segin <segin2005@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */#if defined(__AS386_16__) && !defined(__FORCE_ELKS_ANYWAYS__)# error Not for ELKS/MS-DOS.#endif#define _BITS_PTHREADTYPES_H 1#include <stdio.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <sys/types.h>#include <fcntl.h>#include <errno.h>#if !defined(__BCC__) # include <linux/cdrom.h>#endif#if !defined(CDROMEJECT)# define CDROMEJECT 0x5309 /* Ejects the cdrom media */#endif#if !defined(CDROMCLOSETRAY)# define CDROMCLOSETRAY 0x5319#endif#if !defined(CDROM_DRIVE_STATUS)# define CDROM_DRIVE_STATUS 0x5326#endif#if !defined(CDS_NO_INFO)# define CDS_NO_INFO 0 /* if not implemented */#endif#if !defined(CDS_NO_DISC)# define CDS_NO_DISC 1#endif#if !defined(CDS_TRAY_OPEN)# define CDS_TRAY_OPEN 2#endif#if !defined(CDS_DRIVE_NOT_READY)# define CDS_DRIVE_NOT_READY 3#endif#if !defined(CDS_DISC_OK)# define CDS_DISC_OK 4#endifint main(int argc, char **argv){ int fd, x, y=0, ret, is_read; char *tmp, *tmp2, *src; if (argc == 1) { src = "/dev/dvd"; y = 1; goto startloop; } else { src = argv[1]; } for(x=0; x<argc-1; x++) { src = argv[x+1];startloop: fd = open(src, O_RDONLY | O_NONBLOCK); if (fd == -1) { perror(src); goto endloop; } /* Don't ask why the 0s are there... * The ioctl failed before I added them, so... * I'll keep them. */ while(is_read != 1) { ret = ioctl(fd,CDROM_DRIVE_STATUS,0,0,0); if (ret == CDS_TRAY_OPEN) { printf("Closing tray...\n"); ret = ioctl(fd, CDROMCLOSETRAY, 0, 0); if (ret == -1) perror("CDROMEJECT"); } if (ret == -1) perror(src); while(ioctl(fd,CDROM_DRIVE_STATUS,0,0,0) == CDS_DRIVE_NOT_READY); ret = ioctl(fd,CDROM_DRIVE_STATUS,0,0,0); if (ret == CDS_NO_DISC) { printf("Disk read failed, ejecting...\n"); ret = ioctl(fd, CDROMEJECT, 0, 0); if (ret == -1) perror(src); } if (ret == CDS_DISC_OK) { printf("Disk read, moving on...\n"); is_read = 1; } if (ret == -1) perror(src); }endloop: { if (y == 1) goto afterloop; } }afterloop: { }}