1 /*
2 Copyright (C) 2003, 2004, 2006, 2008, 2009, 2012
3 Rocky Bernstein <rocky@gnu.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /* Simple program to show drivers installed and what the default
20 CD-ROM drive is and what CD drives are available. */
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #define __CDIO_CONFIG_H__ 1
24 #endif
25
26 #ifdef HAVE_STDIO_H
27 #include <stdio.h>
28 #endif
29 #ifdef HAVE_STDLIB_H
30 #include <stdlib.h>
31 #endif
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
34 #endif
35
36 #include <cdio/cdio.h>
37 #include <cdio/cd_types.h>
38 #include <cdio/logging.h>
39
40 static void
log_handler(cdio_log_level_t level,const char message[])41 log_handler (cdio_log_level_t level, const char message[])
42 {
43 switch(level) {
44 case CDIO_LOG_DEBUG:
45 case CDIO_LOG_INFO:
46 return;
47 default:
48 printf("cdio %d message: %s\n", level, message);
49 }
50 }
51
52 static void
print_drive_class(const char * psz_msg,cdio_fs_anal_t bitmask,bool b_any)53 print_drive_class(const char *psz_msg, cdio_fs_anal_t bitmask, bool b_any) {
54 char **ppsz_cd_drives=NULL, **c;
55
56 printf("-- %s...\n", psz_msg);
57 ppsz_cd_drives = cdio_get_devices_with_cap(NULL, bitmask, b_any);
58 if (NULL != ppsz_cd_drives)
59 for( c = ppsz_cd_drives; *c != NULL; c++ ) {
60 printf("-- Drive %s\n", *c);
61 }
62
63 cdio_free_device_list(ppsz_cd_drives);
64 printf("-----\n");
65 }
66
67 int
main(int argc,const char * argv[])68 main(int argc, const char *argv[])
69 {
70 char **ppsz_cd_drives=NULL, **c;
71
72 cdio_log_set_handler (log_handler);
73
74 /* Print out a list of CD-drives */
75 ppsz_cd_drives = cdio_get_devices(DRIVER_DEVICE);
76 if (NULL != ppsz_cd_drives)
77 for( c = ppsz_cd_drives; *c != NULL; c++ ) {
78 printf("-- Drive %s\n", *c);
79 }
80
81 cdio_free_device_list(ppsz_cd_drives);
82 ppsz_cd_drives = NULL;
83
84 printf("-----\n");
85
86 /* Print out a list of CD-drives the harder way. */
87 print_drive_class("-- All CD-ROM drives (again)", CDIO_FS_MATCH_ALL, false);
88 print_drive_class("-- CD-ROM drives with a CD-DA loaded...",
89 CDIO_FS_AUDIO, false);
90 print_drive_class("-- CD-ROM drives with some sort of ISO 9660 filesystem...",
91 CDIO_FS_ANAL_ISO9660_ANY, true);
92 print_drive_class("-- (S)VCD drives...", CDIO_FS_ANAL_VCD_ANY, true);
93 return 0;
94
95 }
96