[c712ca]: src / cd-drive.c Maximize Restore History

Download this file

cd-drive.c    313 lines (252 with data), 8.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
$Id: cd-drive.c,v 1.23 2005/04/30 10:05:11 rocky Exp $
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
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>
#include <cdio/scsi_mmc.h>
/* 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:
if (opts.source_image != DRIVER_UNKNOWN) {
report( stderr, "%s: another source type option given before.\n",
program_name );
report( stderr, "%s: give only one source type option.\n",
program_name );
break;
} else {
opts.source_image = DRIVER_DEVICE;
source_name = fillout_device_name(source_name);
break;
}
break;
default:
poptFreeContext(optCon);
return false;
}
}
{
const char *remaining_arg = poptGetArg(optCon);
if ( remaining_arg != NULL) {
if (opts.source_image != DRIVER_UNKNOWN) {
report( stderr, "%s: Source specified in option %s and as %s\n",
program_name, source_name, remaining_arg);
poptFreeContext(optCon);
free(program_name);
exit (EXIT_FAILURE);
}
if (opts.source_image == DRIVER_DEVICE)
source_name = fillout_device_name(remaining_arg);
else
source_name = strdup(remaining_arg);
if ( (poptGetArgs(optCon)) != NULL) {
report( stderr, "%s: Source specified in previously %s and %s\n",
program_name, source_name, remaining_arg);
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);
}
/*! 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");
}
/* 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;
opts.source_image = DRIVER_UNKNOWN;
}
int
main(int argc, const char *argv[])
{
CdIo_t *p_cdio=NULL;
init();
/* Parse our arguments; every option seen by `parse_opt' will
be reflected in `arguments'. */
parse_options(argc, argv);
print_version(program_name, CDIO_VERSION, false, opts.version_only);
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;
p_cdio = cdio_open (NULL, DRIVER_DEVICE);
if (NULL == p_cdio) {
printf("No loaded CD-ROM device accessible.\n");
} else {
default_device = cdio_get_default_device(p_cdio);
printf("The driver selected is %s\n", cdio_get_driver_name(p_cdio));
if (default_device) {
printf("The default device for this driver is %s\n", default_device);
}
free(default_device);
cdio_destroy(p_cdio);
p_cdio=NULL;
printf("\n");
}
}
/* 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++)
if (cdio_have_driver(driver_id)) {
printf(" %-35s\n", cdio_driver_describe(driver_id));
}
printf("\n");
}
if (NULL == source_name) {
/* Print out a list of CD-drives */
char **ppsz_cdrives=NULL, **ppsz_cd;
driver_id_t driver_id = DRIVER_DEVICE;
ppsz_cdrives = cdio_get_devices_ret(&driver_id);
if (NULL != ppsz_cdrives)
for( ppsz_cd = ppsz_cdrives; *ppsz_cd != NULL; ppsz_cd++ ) {
cdio_drive_read_cap_t i_read_cap;
cdio_drive_write_cap_t i_write_cap;
cdio_drive_misc_cap_t i_misc_cap;
cdio_hwinfo_t hwinfo;
CdIo_t *p_cdio = cdio_open(*ppsz_cd, driver_id);
print_mmc_drive_level(p_cdio);
printf("%28s: %s\n", "Drive", *ppsz_cd);
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);
}
printf("\n");
if (p_cdio) cdio_destroy(p_cdio);
}
cdio_free_device_list(ppsz_cdrives);
ppsz_cdrives = NULL;
} else {
/* Print CD-drive info for given source */
cdio_drive_read_cap_t i_read_cap;
cdio_drive_write_cap_t i_write_cap;
cdio_drive_misc_cap_t i_misc_cap;
cdio_hwinfo_t hwinfo;
printf("Drive %s\n", source_name);
p_cdio = cdio_open (source_name, DRIVER_UNKNOWN);
if (p_cdio) {
print_mmc_drive_level(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_dev(source_name, &i_read_cap, &i_write_cap,
&i_misc_cap);
print_drive_capabilities(i_read_cap, i_write_cap, i_misc_cap);
printf("\n");
}
myexit(p_cdio, EXIT_SUCCESS);
/* Not reached:*/
return(EXIT_SUCCESS);
}