Add interface to eject CD-ROM by device name.

eject.c: new routine to test/show this.
example/*.c iso2.cpp: Note in comment allowance of an optional argument.
This commit is contained in:
rocky
2005-11-07 07:44:00 +00:00
parent 2f8e8b9529
commit 6f81e9252b
9 changed files with 133 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
$Id: iso2.cpp,v 1.4 2005/10/30 14:25:46 rocky Exp $
$Id: iso2.cpp,v 1.5 2005/11/07 07:44:00 rocky Exp $
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -21,6 +21,10 @@
/* Simple program to show using libiso9660 to extract a file from a
cue/bin CD-IMAGE.
If a single argument is given, it is used as the CUE file of a CD image
to use. Otherwise a compiled-in default image name (that
comes with the libcdio distribution) will be used.
This program can be compiled with either a C or C++ compiler. In
the distribution we prefer C++ just to make sure we haven't broken
things on the C++ side.

78
example/eject.c Normal file
View File

@@ -0,0 +1,78 @@
/*
$Id: eject.c,v 1.1 2005/11/07 07:44:00 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.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
*/
/* Simple program to eject a CD-ROM drive door and then close it again.
If a single argument is given, it is used as the CD-ROM device to
eject/close. Otherwise a CD-ROM drive will be scanned for.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <cdio/cdio.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif
int
main(int argc, const char *argv[])
{
driver_return_code_t ret;
driver_id_t driver_id = DRIVER_DEVICE;
char *psz_drive = NULL;
if (argc > 1)
psz_drive = strdup(argv[1]);
if (!psz_drive) {
psz_drive = cdio_get_default_device_driver(&driver_id);
if (!psz_drive) {
printf("Can't find a CD-ROM to eject\n");
exit(1);
}
}
ret = cdio_eject_media_drive(psz_drive);
switch(ret) {
case DRIVER_OP_UNSUPPORTED:
printf("Eject not supported for %s.\n", psz_drive);
break;
case DRIVER_OP_SUCCESS:
printf("CD-ROM drive %s ejected.\n", psz_drive);
break;
default:
printf("Eject of CD-ROM drive %s failed.\n", psz_drive);
break;
}
if (DRIVER_OP_SUCCESS == cdio_close_tray(psz_drive, &driver_id)) {
printf("Closed tray of CD-ROM drive %s.\n", psz_drive);
} else {
printf("Closing tray of CD-ROM drive %s failed.\n", psz_drive);
}
free(psz_drive);
return 0;
}

View File

@@ -1,5 +1,5 @@
/*
$Id: iso1.c,v 1.4 2005/02/03 07:32:32 rocky Exp $
$Id: iso1.c,v 1.5 2005/11/07 07:44:00 rocky Exp $
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -20,6 +20,10 @@
/* Simple program to show using libiso9660 to list files in a directory of
an ISO-9660 image.
If a single argument is given, it is used as the ISO 9660 image to
use in the listing. Otherwise a compiled-in default ISO 9660 image
name (that comes with the libcdio distribution) will be used.
*/
/* This is the ISO 9660 image. */

View File

@@ -1,5 +1,5 @@
/*
$Id: iso2.c,v 1.9 2005/10/30 14:26:11 rocky Exp $
$Id: iso2.c,v 1.10 2005/11/07 07:44:00 rocky Exp $
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -19,7 +19,11 @@
*/
/* Simple program to show using libiso9660 to extract a file from a
cue/bin CD-IMAGE.
CUE/BIN CD image.
If a single argument is given, it is used as the CUE file of a CD image
to use. Otherwise a compiled-in default image name (that
comes with the libcdio distribution) will be used.
This program can be compiled with either a C or C++ compiler. In
the distribution we prefer C++ just to make sure we haven't broken

View File

@@ -1,7 +1,7 @@
/*
$Id: iso3.c,v 1.4 2005/02/19 11:42:18 rocky Exp $
$Id: iso3.c,v 1.5 2005/11/07 07:44:00 rocky Exp $
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.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
@@ -20,6 +20,10 @@
/* Simple program to show using libiso9660 to extract a file from an
ISO-9660 image.
If a single argument is given, it is used as the ISO 9660 image to
use in the extraction. Otherwise a compiled in default ISO 9660 image
name (that comes with the libcdio distribution) will be used.
*/
/* This is the ISO 9660 image. */

View File

@@ -1,5 +1,5 @@
/*
$Id: isofuzzy.c,v 1.1 2005/02/09 02:50:47 rocky Exp $
$Id: isofuzzy.c,v 1.2 2005/11/07 07:44:00 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -19,6 +19,10 @@
*/
/* Program to show using libiso9660 with fuzzy search to get file info.
If a single argument is given, it is used as the ISO 9660 image.
Otherwise we use a compiled-in default ISO 9660 image
name.
*/
/* This is the BIN we think there is an ISO 9660 image inside of. */

View File

@@ -1,5 +1,5 @@
/* -*- c -*-
$Id: cdio.h,v 1.80 2005/02/10 01:59:05 rocky Exp $
$Id: cdio.h,v 1.81 2005/11/07 07:44:00 rocky Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>
@@ -50,7 +50,7 @@
extern "C" {
#endif /* __cplusplus */
/* For compatability. */
/* For compatibility. */
#define CdIo CdIo_t
/** This is an opaque structure for the CD object. */

View File

@@ -1,5 +1,5 @@
/* -*- c -*-
$Id: device.h,v 1.24 2005/11/06 22:50:37 rocky Exp $
$Id: device.h,v 1.25 2005/11/07 07:44:00 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -237,6 +237,13 @@ extern "C" {
*/
driver_return_code_t cdio_eject_media (CdIo_t **p_cdio);
/*!
Eject media in CD drive if there is a routine to do so.
@param psz_drive the name of the device to be acted upon.
*/
driver_return_code_t cdio_eject_media_drive (const char *psz_drive);
/*!
Free device list returned by cdio_get_devices or
cdio_get_devices_with_cap.

View File

@@ -1,5 +1,5 @@
/*
$Id: device.c,v 1.27 2005/04/11 01:03:46 rocky Exp $
$Id: device.c,v 1.28 2005/11/07 07:44:00 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -345,7 +345,6 @@ cdio_close_tray (const char *psz_drive, /*in/out*/ driver_id_t
driver_return_code_t
cdio_eject_media (CdIo_t **pp_cdio)
{
if ((pp_cdio == NULL) || (*pp_cdio == NULL)) return DRIVER_OP_UNINIT;
if ((*pp_cdio)->op.eject_media) {
@@ -362,6 +361,23 @@ cdio_eject_media (CdIo_t **pp_cdio)
}
}
/*!
Eject media in CD drive if there is a routine to do so. If you want
to scan for any CD-ROM and eject that, pass NULL for psz_drive.
@param psz_drive the CD object to be acted upon.
*/
driver_return_code_t
cdio_eject_media_drive (const char *psz_drive)
{
CdIo_t *p_cdio = cdio_open (psz_drive, DRIVER_DEVICE);
if (p_cdio) {
return cdio_eject_media(&p_cdio);
} else {
return DRIVER_OP_UNINIT;
}
}
/*!
Free device list returned by cdio_get_devices or
cdio_get_devices_with_cap.