2004-04-25 00:46:34 +00:00
|
|
|
/*
|
2005-04-30 09:42:37 +00:00
|
|
|
$Id: cd-drive.c,v 1.20 2005/04/30 09:42:37 rocky Exp $
|
2004-04-25 00:46:34 +00:00
|
|
|
|
2005-01-09 00:10:48 +00:00
|
|
|
Copyright (C) 2004, 2005 Rocky Bernstein <rocky@panix.com>
|
2004-04-25 00:46:34 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Program to show drivers installed and capibilites of CD drives. */
|
|
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_STDIO_H
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <cdio/cdio.h>
|
2004-07-31 07:43:26 +00:00
|
|
|
#include <cdio/scsi_mmc.h>
|
2004-04-25 00:46:34 +00:00
|
|
|
|
|
|
|
|
/* Used by `main' to communicate with `parse_opt'. And global options
|
|
|
|
|
*/
|
|
|
|
|
struct arguments
|
|
|
|
|
{
|
|
|
|
|
uint32_t debug_level;
|
|
|
|
|
int version_only;
|
|
|
|
|
int silent;
|
|
|
|
|
source_image_t source_image;
|
|
|
|
|
} opts;
|
|
|
|
|
|
|
|
|
|
/* Configuration option codes */
|
|
|
|
|
enum {
|
|
|
|
|
OP_SOURCE_DEVICE,
|
|
|
|
|
|
|
|
|
|
/* These are the remaining configuration options */
|
|
|
|
|
OP_VERSION,
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Parse a all options. */
|
|
|
|
|
static bool
|
|
|
|
|
parse_options (int argc, const char *argv[])
|
|
|
|
|
{
|
|
|
|
|
int opt;
|
|
|
|
|
|
|
|
|
|
struct poptOption optionsTable[] = {
|
|
|
|
|
{"debug", 'd', POPT_ARG_INT, &opts.debug_level, 0,
|
|
|
|
|
"Set debugging to LEVEL"},
|
|
|
|
|
|
|
|
|
|
{"cdrom-device", 'i', POPT_ARG_STRING|POPT_ARGFLAG_OPTIONAL,
|
|
|
|
|
&source_name, OP_SOURCE_DEVICE,
|
|
|
|
|
"show only info about CD-ROM device", "DEVICE"},
|
|
|
|
|
|
|
|
|
|
{"quiet", 'q', POPT_ARG_NONE, &opts.silent, 0,
|
|
|
|
|
"Don't produce warning output" },
|
|
|
|
|
|
|
|
|
|
{"version", 'V', POPT_ARG_NONE, &opts.version_only, 0,
|
|
|
|
|
"display version and copyright information and exit"},
|
|
|
|
|
POPT_AUTOHELP {NULL, 0, 0, NULL, 0}
|
|
|
|
|
};
|
|
|
|
|
poptContext optCon = poptGetContext (NULL, argc, argv, optionsTable, 0);
|
|
|
|
|
|
|
|
|
|
program_name = strrchr(argv[0],'/');
|
|
|
|
|
program_name = program_name ? strdup(program_name+1) : strdup(argv[0]);
|
|
|
|
|
|
|
|
|
|
while ((opt = poptGetNextOpt (optCon)) != -1) {
|
|
|
|
|
switch (opt) {
|
|
|
|
|
|
|
|
|
|
case OP_SOURCE_DEVICE:
|
2005-01-09 00:10:48 +00:00
|
|
|
if (opts.source_image != DRIVER_UNKNOWN) {
|
2004-11-04 10:08:23 +00:00
|
|
|
report( stderr, "%s: another source type option given before.\n",
|
|
|
|
|
program_name );
|
|
|
|
|
report( stderr, "%s: give only one source type option.\n",
|
|
|
|
|
program_name );
|
2004-04-25 00:46:34 +00:00
|
|
|
break;
|
|
|
|
|
} else {
|
2005-01-09 00:10:48 +00:00
|
|
|
opts.source_image = DRIVER_DEVICE;
|
2004-04-25 00:46:34 +00:00
|
|
|
source_name = fillout_device_name(source_name);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
const char *remaining_arg = poptGetArg(optCon);
|
|
|
|
|
if ( remaining_arg != NULL) {
|
2005-01-09 00:10:48 +00:00
|
|
|
if (opts.source_image != DRIVER_UNKNOWN) {
|
2004-11-04 10:08:23 +00:00
|
|
|
report( stderr, "%s: Source specified in option %s and as %s\n",
|
|
|
|
|
program_name, source_name, remaining_arg);
|
2004-04-25 00:46:34 +00:00
|
|
|
poptFreeContext(optCon);
|
|
|
|
|
free(program_name);
|
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-09 00:10:48 +00:00
|
|
|
if (opts.source_image == DRIVER_DEVICE)
|
2004-04-25 00:46:34 +00:00
|
|
|
source_name = fillout_device_name(remaining_arg);
|
|
|
|
|
else
|
|
|
|
|
source_name = strdup(remaining_arg);
|
|
|
|
|
|
|
|
|
|
if ( (poptGetArgs(optCon)) != NULL) {
|
2004-11-04 10:08:23 +00:00
|
|
|
report( stderr, "%s: Source specified in previously %s and %s\n",
|
|
|
|
|
program_name, source_name, remaining_arg);
|
2004-04-25 00:46:34 +00:00
|
|
|
poptFreeContext(optCon);
|
|
|
|
|
free(program_name);
|
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
poptFreeContext(optCon);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* CDIO logging routines */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_log_handler (cdio_log_level_t level, const char message[])
|
|
|
|
|
{
|
|
|
|
|
if (level == CDIO_LOG_DEBUG && opts.debug_level < 2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (level == CDIO_LOG_INFO && opts.debug_level < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (level == CDIO_LOG_WARN && opts.silent)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gl_default_cdio_log_handler (level, message);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-30 09:42:37 +00:00
|
|
|
/*! Prints out SCSI-MMC drive features */
|
|
|
|
|
static void
|
|
|
|
|
print_mmc_drive_level(CdIo_t *p_cdio)
|
|
|
|
|
{
|
|
|
|
|
cdio_mmc_level_t mmc_level = mmc_get_drive_mmc_cap(p_cdio);
|
|
|
|
|
|
|
|
|
|
printf( "CD-ROM drive supports " );
|
|
|
|
|
|
|
|
|
|
switch(mmc_level) {
|
|
|
|
|
case CDIO_MMC_LEVEL_WEIRD:
|
|
|
|
|
printf("some nonstandard or degenerate set of MMC\n");
|
|
|
|
|
break;
|
|
|
|
|
case CDIO_MMC_LEVEL_1:
|
|
|
|
|
printf("MMC 1\n");
|
|
|
|
|
break;
|
|
|
|
|
case CDIO_MMC_LEVEL_2:
|
|
|
|
|
printf("MMC 2\n");
|
|
|
|
|
break;
|
|
|
|
|
case CDIO_MMC_LEVEL_3:
|
|
|
|
|
printf("MMC 3\n");
|
|
|
|
|
break;
|
|
|
|
|
case CDIO_MMC_LEVEL_NONE:
|
|
|
|
|
printf("no MMC\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-25 00:46:34 +00:00
|
|
|
/* Initialize global variables. */
|
|
|
|
|
static void
|
|
|
|
|
init(void)
|
|
|
|
|
{
|
|
|
|
|
gl_default_cdio_log_handler = cdio_log_set_handler (_log_handler);
|
|
|
|
|
|
|
|
|
|
/* Default option values. */
|
|
|
|
|
opts.silent = false;
|
|
|
|
|
opts.debug_level = 0;
|
2005-01-09 00:10:48 +00:00
|
|
|
opts.source_image = DRIVER_UNKNOWN;
|
2004-04-25 00:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, const char *argv[])
|
|
|
|
|
{
|
2005-01-02 22:49:31 +00:00
|
|
|
CdIo_t *p_cdio=NULL;
|
2004-04-25 00:46:34 +00:00
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
|
|
|
|
|
/* Parse our arguments; every option seen by `parse_opt' will
|
|
|
|
|
be reflected in `arguments'. */
|
|
|
|
|
parse_options(argc, argv);
|
|
|
|
|
|
2005-01-22 22:21:36 +00:00
|
|
|
print_version(program_name, CDIO_VERSION, false, opts.version_only);
|
2004-04-25 00:46:34 +00:00
|
|
|
|
|
|
|
|
if (opts.debug_level == 3) {
|
|
|
|
|
cdio_loglevel_default = CDIO_LOG_INFO;
|
|
|
|
|
} else if (opts.debug_level >= 4) {
|
|
|
|
|
cdio_loglevel_default = CDIO_LOG_DEBUG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NULL == source_name) {
|
|
|
|
|
char *default_device;
|
|
|
|
|
|
2005-01-09 00:10:48 +00:00
|
|
|
p_cdio = cdio_open (NULL, DRIVER_DEVICE);
|
2004-04-25 00:46:34 +00:00
|
|
|
|
2005-01-09 00:10:48 +00:00
|
|
|
if (NULL == p_cdio) {
|
2005-01-09 17:30:14 +00:00
|
|
|
printf("No loaded CD-ROM device accessible.\n");
|
2005-01-09 00:10:48 +00:00
|
|
|
} else {
|
2004-07-31 07:43:26 +00:00
|
|
|
default_device = cdio_get_default_device(p_cdio);
|
2004-04-25 03:52:37 +00:00
|
|
|
|
2004-07-31 07:43:26 +00:00
|
|
|
printf("The driver selected is %s\n", cdio_get_driver_name(p_cdio));
|
2004-04-25 00:46:34 +00:00
|
|
|
|
2004-04-25 03:52:37 +00:00
|
|
|
if (default_device) {
|
|
|
|
|
printf("The default device for this driver is %s\n", default_device);
|
|
|
|
|
}
|
2004-04-25 00:46:34 +00:00
|
|
|
|
2004-04-25 03:52:37 +00:00
|
|
|
free(default_device);
|
2004-07-31 07:43:26 +00:00
|
|
|
cdio_destroy(p_cdio);
|
|
|
|
|
p_cdio=NULL;
|
2004-04-25 03:52:37 +00:00
|
|
|
printf("\n");
|
|
|
|
|
}
|
2004-04-25 00:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print out a drivers available */
|
|
|
|
|
{
|
|
|
|
|
driver_id_t driver_id;
|
|
|
|
|
|
|
|
|
|
printf("Drivers available...\n");
|
|
|
|
|
for (driver_id=CDIO_MIN_DRIVER; driver_id<=CDIO_MAX_DRIVER; driver_id++)
|
2005-01-13 19:30:24 +00:00
|
|
|
if (cdio_have_driver(driver_id)) {
|
|
|
|
|
printf(" %-35s\n", cdio_driver_describe(driver_id));
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
2004-04-25 00:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (NULL == source_name) {
|
|
|
|
|
/* Print out a list of CD-drives */
|
|
|
|
|
|
2004-07-31 07:43:26 +00:00
|
|
|
char **ppsz_cdrives=NULL, **ppsz_cd;
|
2004-08-27 04:17:08 +00:00
|
|
|
driver_id_t driver_id = DRIVER_DEVICE;
|
2004-04-25 00:46:34 +00:00
|
|
|
|
2004-08-27 04:17:08 +00:00
|
|
|
ppsz_cdrives = cdio_get_devices_ret(&driver_id);
|
2004-07-31 07:43:26 +00:00
|
|
|
if (NULL != ppsz_cdrives)
|
|
|
|
|
for( ppsz_cd = ppsz_cdrives; *ppsz_cd != NULL; ppsz_cd++ ) {
|
2004-07-17 22:16:46 +00:00
|
|
|
cdio_drive_read_cap_t i_read_cap;
|
|
|
|
|
cdio_drive_write_cap_t i_write_cap;
|
|
|
|
|
cdio_drive_misc_cap_t i_misc_cap;
|
2004-08-27 02:50:13 +00:00
|
|
|
cdio_hwinfo_t hwinfo;
|
2005-01-02 22:49:31 +00:00
|
|
|
CdIo_t *p_cdio = cdio_open(*ppsz_cd, driver_id);
|
2004-07-17 22:16:46 +00:00
|
|
|
|
2005-04-30 09:42:37 +00:00
|
|
|
print_mmc_drive_level(p_cdio);
|
|
|
|
|
|
2004-07-31 07:43:26 +00:00
|
|
|
printf("%28s: %s\n", "Drive", *ppsz_cd);
|
2004-11-14 00:03:52 +00:00
|
|
|
|
|
|
|
|
if (p_cdio) {
|
|
|
|
|
if (cdio_get_hwinfo(p_cdio, &hwinfo)) {
|
|
|
|
|
printf("%-28s: %s\n%-28s: %s\n%-28s: %s\n",
|
|
|
|
|
"Vendor" , hwinfo.psz_vendor,
|
|
|
|
|
"Model" , hwinfo.psz_model,
|
|
|
|
|
"Revision", hwinfo.psz_revision);
|
|
|
|
|
}
|
|
|
|
|
print_mmc_drive_features(p_cdio);
|
|
|
|
|
cdio_get_drive_cap(p_cdio, &i_read_cap, &i_write_cap,
|
|
|
|
|
&i_misc_cap);
|
|
|
|
|
print_drive_capabilities(i_read_cap, i_write_cap, i_misc_cap);
|
2004-07-31 07:43:26 +00:00
|
|
|
}
|
2004-04-25 00:46:34 +00:00
|
|
|
printf("\n");
|
2004-07-31 07:43:26 +00:00
|
|
|
if (p_cdio) cdio_destroy(p_cdio);
|
2004-04-25 00:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-31 07:43:26 +00:00
|
|
|
cdio_free_device_list(ppsz_cdrives);
|
|
|
|
|
ppsz_cdrives = NULL;
|
2004-04-25 00:46:34 +00:00
|
|
|
} else {
|
|
|
|
|
/* Print CD-drive info for given source */
|
2004-07-17 22:16:46 +00:00
|
|
|
cdio_drive_read_cap_t i_read_cap;
|
|
|
|
|
cdio_drive_write_cap_t i_write_cap;
|
|
|
|
|
cdio_drive_misc_cap_t i_misc_cap;
|
2004-08-27 02:50:13 +00:00
|
|
|
cdio_hwinfo_t hwinfo;
|
2004-08-07 01:48:36 +00:00
|
|
|
|
2004-04-25 00:46:34 +00:00
|
|
|
|
2004-08-07 01:48:36 +00:00
|
|
|
printf("Drive %s\n", source_name);
|
|
|
|
|
p_cdio = cdio_open (source_name, DRIVER_UNKNOWN);
|
|
|
|
|
if (NULL != p_cdio) {
|
2004-08-27 02:50:13 +00:00
|
|
|
if (cdio_get_hwinfo(p_cdio, &hwinfo)) {
|
2004-08-07 01:48:36 +00:00
|
|
|
printf("%-28s: %s\n%-28s: %s\n%-28s: %s\n",
|
2004-08-27 11:53:38 +00:00
|
|
|
"Vendor" , hwinfo.psz_vendor,
|
|
|
|
|
"Model" , hwinfo.psz_model,
|
|
|
|
|
"Revision", hwinfo.psz_revision);
|
2004-08-07 01:48:36 +00:00
|
|
|
}
|
|
|
|
|
print_mmc_drive_features(p_cdio);
|
|
|
|
|
}
|
2004-07-17 22:16:46 +00:00
|
|
|
cdio_get_drive_cap_dev(source_name, &i_read_cap, &i_write_cap,
|
|
|
|
|
&i_misc_cap);
|
|
|
|
|
print_drive_capabilities(i_read_cap, i_write_cap, i_misc_cap);
|
2004-04-25 00:46:34 +00:00
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-31 07:43:26 +00:00
|
|
|
myexit(p_cdio, EXIT_SUCCESS);
|
2004-04-25 00:46:34 +00:00
|
|
|
/* Not reached:*/
|
|
|
|
|
return(EXIT_SUCCESS);
|
|
|
|
|
}
|