From b6a67c8d94088dae280cc7e3aec4b83e2af000af Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 23 Apr 2004 01:01:35 +0000 Subject: [PATCH] image/common.c, Makefile.am: common image routines. src/cd-info.c, *.right: Now show file images under "drive capability" bincue.c/nrg.c: report file image "drive capability" --- example/sample2.c | 4 +- lib/Makefile.am | 3 +- lib/_cdio_linux.c | 14 +++-- lib/image/bincue.c | 86 +++------------------------- lib/image/common.c | 103 ++++++++++++++++++++++++++++++++++ lib/image/nrg.c | 60 +++----------------- src/cd-info.c | 24 +++++++- test/cdda.right | 1 + test/check_opts0.right | 1 + test/check_opts1.right | 1 + test/check_opts2.right | 1 + test/check_opts3.right | 1 + test/check_opts4.right | 1 + test/check_opts5.right | 1 + test/check_opts6.right | 1 + test/check_opts7.right | 1 + test/isofs-m1.right | 1 + test/monvoisin.right | 1 + test/svcd_ogt_test_ntsc.right | 1 + test/svcdgs.right | 1 + test/vcd_demo.right | 1 + test/videocd.right | 1 + 22 files changed, 173 insertions(+), 136 deletions(-) create mode 100644 lib/image/common.c diff --git a/example/sample2.c b/example/sample2.c index 3d68cba2..b647d36d 100644 --- a/example/sample2.c +++ b/example/sample2.c @@ -1,5 +1,5 @@ /* - $Id: sample2.c,v 1.5 2004/04/22 03:24:38 rocky Exp $ + $Id: sample2.c,v 1.6 2004/04/23 01:01:35 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein @@ -53,7 +53,7 @@ main(int argc, const char *argv[]) } else if (CDIO_DRIVE_UNKNOWN == i_drive_cap) { printf("Can't determine drive properties\n"); } else if (CDIO_DRIVE_FILE == i_drive_cap) { - printf("Can't determine drive properties\n"); + printf("Disc-image file\n"); } else { if (i_drive_cap & CDIO_DRIVE_CD_R) printf("Drive can read CD-ROM\n"); diff --git a/lib/Makefile.am b/lib/Makefile.am index 1519f839..2378ba41 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.30 2004/03/20 22:49:33 rocky Exp $ +# $Id: Makefile.am,v 1.31 2004/04/23 01:01:36 rocky Exp $ # # Copyright (C) 2003, 2004 Rocky Bernstein # @@ -69,6 +69,7 @@ libcdio_sources = \ ds.c \ ds.h \ image/bincue.c \ + image/common.c \ image/nrg.c \ logging.c \ MSWindows/aspi32.c \ diff --git a/lib/_cdio_linux.c b/lib/_cdio_linux.c index 2160465b..9528efad 100644 --- a/lib/_cdio_linux.c +++ b/lib/_cdio_linux.c @@ -1,5 +1,5 @@ /* - $Id: _cdio_linux.c,v 1.33 2004/04/22 03:24:38 rocky Exp $ + $Id: _cdio_linux.c,v 1.34 2004/04/23 01:01:36 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2002, 2003, 2004 Rocky Bernstein @@ -27,7 +27,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: _cdio_linux.c,v 1.33 2004/04/22 03:24:38 rocky Exp $"; +static const char _rcsid[] = "$Id: _cdio_linux.c,v 1.34 2004/04/23 01:01:36 rocky Exp $"; #include @@ -1109,8 +1109,14 @@ cdio_open_linux (const char *orig_source_name) if (NULL == source_name) return NULL; _cdio_set_arg(_data, "source", source_name); free(source_name); - } else - _cdio_set_arg(_data, "source", orig_source_name); + } else { + if (cdio_is_device_generic(orig_source_name)) + _cdio_set_arg(_data, "source", orig_source_name); + else { + cdio_info ("source %s is a not a device", orig_source_name); + return NULL; + } + } ret = cdio_new (_data, &_funcs); if (ret == NULL) return NULL; diff --git a/lib/image/bincue.c b/lib/image/bincue.c index 063f0581..6f4319b3 100644 --- a/lib/image/bincue.c +++ b/lib/image/bincue.c @@ -1,5 +1,5 @@ /* - $Id: bincue.c,v 1.9 2004/03/22 01:01:50 rocky Exp $ + $Id: bincue.c,v 1.10 2004/04/23 01:01:37 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2002, 2003, 2004 Rocky Bernstein @@ -24,7 +24,7 @@ (*.cue). */ -static const char _rcsid[] = "$Id: bincue.c,v 1.9 2004/03/22 01:01:50 rocky Exp $"; +static const char _rcsid[] = "$Id: bincue.c,v 1.10 2004/04/23 01:01:37 rocky Exp $"; #include "cdio_assert.h" #include "cdio_private.h" @@ -104,6 +104,8 @@ typedef struct { static bool _cdio_image_read_cue (_img_private_t *_obj); static uint32_t _cdio_stat_size (void *env); +#include "image/common.c" + /*! Initialize image structures. */ @@ -740,53 +742,6 @@ cdio_get_default_device_bincue(void) return drive; } -/*! - Return the number of of the first track. - CDIO_INVALID_TRACK is returned on error. -*/ -static track_t -_cdio_get_first_track_num(void *env) -{ - _img_private_t *_obj = env; - - _cdio_init (_obj); - - return _obj->first_track_num; -} - -/*! - Return the media catalog number (MCN) from the CD or NULL if there - is none or we don't have the ability to get it. - - Note: string is malloc'd so caller has to free() the returned - string when done with it. - */ -static char * -_cdio_get_mcn(void *env) -{ - _img_private_t *_obj = env; - - _cdio_init (_obj); - - if (NULL == _obj->mcn) return NULL; - return strdup(_obj->mcn); -} - -/*! - Return the number of tracks in the current medium. - If no cuesheet is available, We fake it an just say there's - one big track. - CDIO_INVALID_TRACK is returned on error. -*/ -static track_t -_cdio_get_num_tracks(void *env) -{ - _img_private_t *_obj = env; - _cdio_init (_obj); - - return _obj->have_cue && _obj->total_tracks > 0 ? _obj->total_tracks : 1; -} - /*! Return the number of tracks in the current medium. CDIO_INVALID_TRACK is returned on error. @@ -846,30 +801,6 @@ _cdio_get_track_lba(void *env, track_t track_num) return CDIO_INVALID_LBA; } -/*! - Return the starting MSF (minutes/secs/frames) for the track number - track_num in obj. Tracks numbers start at 1. - The "leadout" track is specified either by - using track_num LEADOUT_TRACK or the total tracks+1. - -*/ -static bool -_cdio_get_track_msf(void *env, track_t track_num, msf_t *msf) -{ - _img_private_t *_obj = env; - _cdio_init (_obj); - - if (NULL == msf) return false; - - if (track_num == CDIO_CDROM_LEADOUT_TRACK) track_num = _obj->total_tracks+1; - - if (track_num <= _obj->total_tracks+1 && track_num != 0) { - *msf = _obj->tocent[track_num-1].start_msf; - return true; - } else - return false; -} - /*! Return corresponding BIN file if cue_name is a cue file or NULL if not a CUE file. @@ -964,13 +895,14 @@ cdio_open_cue (const char *cue_name) .free = _cdio_bincue_destroy, .get_arg = _cdio_get_arg, .get_default_device = cdio_get_default_device_bincue, - .get_first_track_num= _cdio_get_first_track_num, - .get_mcn = _cdio_get_mcn, - .get_num_tracks = _cdio_get_num_tracks, + .get_drive_cap = _cdio_image_get_drive_cap, + .get_first_track_num= _cdio_image_get_first_track_num, + .get_mcn = _cdio_image_get_mcn, + .get_num_tracks = _cdio_image_get_num_tracks, .get_track_format = _cdio_get_track_format, .get_track_green = _cdio_get_track_green, .get_track_lba = _cdio_get_track_lba, - .get_track_msf = _cdio_get_track_msf, + .get_track_msf = _cdio_image_get_track_msf, .lseek = _cdio_lseek, .read = _cdio_read, .read_audio_sectors = _cdio_read_audio_sectors, diff --git a/lib/image/common.c b/lib/image/common.c new file mode 100644 index 00000000..5fdb32b2 --- /dev/null +++ b/lib/image/common.c @@ -0,0 +1,103 @@ +/* + $Id: common.c,v 1.1 2004/04/23 01:01:37 rocky Exp $ + + Copyright (C) 2004 Rocky Bernstein + + 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 +*/ + +/* Common image routines. */ + +/*! + Return the the kind of drive capabilities of device. + + Note: string is malloc'd so caller should free() then returned + string when done with it. + + */ +static cdio_drive_cap_t +_cdio_image_get_drive_cap (const void *env) { + const _img_private_t *_obj = env; + + if (_obj->gen.fd < 0 ) + return CDIO_DRIVE_UNKNOWN; + else + return CDIO_DRIVE_FILE; + +} + +/*! + Return the media catalog number (MCN) from the CD or NULL if there + is none or we don't have the ability to get it. + + Note: string is malloc'd so caller has to free() the returned + string when done with it. + */ +static char * +_cdio_image_get_mcn(void *env) +{ + _img_private_t *_obj = env; + + if (NULL == _obj->mcn) return NULL; + return strdup(_obj->mcn); +} + +/*! + Return the starting MSF (minutes/secs/frames) for the track number + track_num in obj. Tracks numbers start at 1. + The "leadout" track is specified either by + using track_num LEADOUT_TRACK or the total tracks+1. + +*/ +static bool +_cdio_image_get_track_msf(void *env, track_t track_num, msf_t *msf) +{ + _img_private_t *_obj = env; + + if (NULL == msf) return false; + + if (track_num == CDIO_CDROM_LEADOUT_TRACK) track_num = _obj->total_tracks+1; + + if (track_num <= _obj->total_tracks+1 && track_num != 0) { + *msf = _obj->tocent[track_num-1].start_msf; + return true; + } else + return false; +} + +/*! + Return the number of of the first track. + CDIO_INVALID_TRACK is returned on error. +*/ +static track_t +_cdio_image_get_first_track_num(void *env) +{ + _img_private_t *_obj = env; + + return _obj->first_track_num; +} + +/*! + Return the number of tracks. We fake it an just say there's + one big track. +*/ +static track_t +_cdio_image_get_num_tracks(void *env) +{ + _img_private_t *_obj = env; + + return _obj->total_tracks; +} + diff --git a/lib/image/nrg.c b/lib/image/nrg.c index 9339b160..b4ec5004 100644 --- a/lib/image/nrg.c +++ b/lib/image/nrg.c @@ -1,5 +1,5 @@ /* - $Id: nrg.c,v 1.4 2004/03/20 22:46:57 rocky Exp $ + $Id: nrg.c,v 1.5 2004/04/23 01:01:37 rocky Exp $ Copyright (C) 2001, 2003 Herbert Valerio Riedel Copyright (C) 2003, 2004 Rocky Bernstein @@ -48,7 +48,7 @@ #include "cdio_private.h" #include "_cdio_stdio.h" -static const char _rcsid[] = "$Id: nrg.c,v 1.4 2004/03/20 22:46:57 rocky Exp $"; +static const char _rcsid[] = "$Id: nrg.c,v 1.5 2004/04/23 01:01:37 rocky Exp $"; /* structures used */ @@ -177,6 +177,8 @@ typedef struct { static bool _cdio_parse_nero_footer (_img_private_t *_obj); static uint32_t _cdio_stat_size (void *env); +#include "image/common.c" + /* Updates internal track TOC, so we can later simulate ioctl(CDROMREADTOCENTRY). */ @@ -1074,30 +1076,6 @@ cdio_get_default_device_nrg(void) return drive; } -/*! - Return the number of of the first track. - CDIO_INVALID_TRACK is returned on error. -*/ -static track_t -_cdio_get_first_track_num(void *env) -{ - _img_private_t *_obj = env; - - return _obj->first_track_num; -} - -/*! - Return the number of tracks. We fake it an just say there's - one big track. -*/ -static track_t -_cdio_get_num_tracks(void *env) -{ - _img_private_t *_obj = env; - - return _obj->total_tracks; -} - /*! Return the number of tracks in the current medium. CDIO_INVALID_TRACK is returned on error. @@ -1144,28 +1122,6 @@ _cdio_get_track_green(void *env, track_t track_num) return _obj->tocent[track_num-1].track_green; } -/*! - Return the starting MSF (minutes/secs/frames) for the track number - track_num in obj. Tracks numbers start at 1. - The "leadout" track is specified either by - using track_num LEADOUT_TRACK or the total tracks+1. -*/ -static bool -_cdio_get_track_msf(void *env, track_t track_num, msf_t *msf) -{ - _img_private_t *_obj = env; - - if (NULL == msf) return 1; - - if (track_num == CDIO_CDROM_LEADOUT_TRACK) track_num = _obj->total_tracks+1; - - if (track_num <= _obj->total_tracks+1 && track_num != 0) { - *msf = _obj->tocent[track_num-1].start_msf; - return true; - } else - return false; -} - CdIo * cdio_open_nrg (const char *source_name) { @@ -1178,12 +1134,14 @@ cdio_open_nrg (const char *source_name) .get_arg = _cdio_get_arg, .get_devices = cdio_get_devices_nrg, .get_default_device = cdio_get_default_device_nrg, - .get_first_track_num= _cdio_get_first_track_num, - .get_num_tracks = _cdio_get_num_tracks, + .get_drive_cap = _cdio_image_get_drive_cap, + .get_first_track_num= _cdio_image_get_first_track_num, + .get_mcn = _cdio_image_get_mcn, + .get_num_tracks = _cdio_image_get_num_tracks, .get_track_format = _cdio_get_track_format, .get_track_green = _cdio_get_track_green, .get_track_lba = NULL, /* Will use generic routine via msf */ - .get_track_msf = _cdio_get_track_msf, + .get_track_msf = _cdio_image_get_track_msf, .lseek = _cdio_lseek, .read = _cdio_read, .read_audio_sectors = _cdio_read_audio_sectors, diff --git a/src/cd-info.c b/src/cd-info.c index 24f54339..ff32e369 100644 --- a/src/cd-info.c +++ b/src/cd-info.c @@ -1,5 +1,5 @@ /* - $Id: cd-info.c,v 1.52 2004/04/21 09:23:38 rocky Exp $ + $Id: cd-info.c,v 1.53 2004/04/23 01:01:37 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein Copyright (C) 1996, 1997, 1998 Gerd Knorr @@ -829,6 +829,28 @@ main(int argc, const char *argv[]) printf("CD driver name: %s\n", cdio_get_driver_name(cdio)); } + { + cdio_drive_cap_t i_drive_cap = cdio_get_drive_cap(source_name); + if (CDIO_DRIVE_ERROR == i_drive_cap) { + printf("Error in getting drive properties\n"); + } else if (CDIO_DRIVE_UNKNOWN == i_drive_cap) { + printf("Can't determine drive properties\n"); + } else if (CDIO_DRIVE_FILE == i_drive_cap) { + printf("Disc-image file\n"); + } else { + if (i_drive_cap & CDIO_DRIVE_CD_R) + printf("Drive can read CD-ROM\n"); + if (i_drive_cap & CDIO_DRIVE_CD_RW) + printf("Drive can write CD-ROM\n"); + if (i_drive_cap & CDIO_DRIVE_DVD) + printf("Drive can read DVD\n"); + if (i_drive_cap & CDIO_DRIVE_DVD_R) + printf("Drive can write DVD-R\n"); + if (i_drive_cap & CDIO_DRIVE_DVD_RAM) + printf("Drive can write DVD-RAM\n"); + } + } + if (opts.list_drives) { char ** device_list = cdio_get_devices(DRIVER_DEVICE); char ** d = device_list; diff --git a/test/cdda.right b/test/cdda.right index a8172c89..d2a9cc2b 100644 --- a/test/cdda.right +++ b/test/cdda.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 1) #: MSF LSN Type Green? diff --git a/test/check_opts0.right b/test/check_opts0.right index 0c16b82e..27a24859 100644 --- a/test/check_opts0.right +++ b/test/check_opts0.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file Media Catalog Number (MCN): 0000010271955 __________________________________ CD Analysis Report diff --git a/test/check_opts1.right b/test/check_opts1.right index 0c16b82e..27a24859 100644 --- a/test/check_opts1.right +++ b/test/check_opts1.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file Media Catalog Number (MCN): 0000010271955 __________________________________ CD Analysis Report diff --git a/test/check_opts2.right b/test/check_opts2.right index ee529fe9..eb6a09b6 100644 --- a/test/check_opts2.right +++ b/test/check_opts2.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 1) #: MSF LSN Type Green? diff --git a/test/check_opts3.right b/test/check_opts3.right index ee529fe9..eb6a09b6 100644 --- a/test/check_opts3.right +++ b/test/check_opts3.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 1) #: MSF LSN Type Green? diff --git a/test/check_opts4.right b/test/check_opts4.right index b9f8060c..3983760c 100644 --- a/test/check_opts4.right +++ b/test/check_opts4.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 1) #: MSF LSN Type Green? diff --git a/test/check_opts5.right b/test/check_opts5.right index b9f8060c..3983760c 100644 --- a/test/check_opts5.right +++ b/test/check_opts5.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 1) #: MSF LSN Type Green? diff --git a/test/check_opts6.right b/test/check_opts6.right index b9f8060c..3983760c 100644 --- a/test/check_opts6.right +++ b/test/check_opts6.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 1) #: MSF LSN Type Green? diff --git a/test/check_opts7.right b/test/check_opts7.right index b9f8060c..3983760c 100644 --- a/test/check_opts7.right +++ b/test/check_opts7.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 1) #: MSF LSN Type Green? diff --git a/test/isofs-m1.right b/test/isofs-m1.right index 1698f9c9..194006e0 100644 --- a/test/isofs-m1.right +++ b/test/isofs-m1.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 1) #: MSF LSN Type Green? diff --git a/test/monvoisin.right b/test/monvoisin.right index bc91c8f2..60181314 100644 --- a/test/monvoisin.right +++ b/test/monvoisin.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 2) #: MSF LSN Type Green? diff --git a/test/svcd_ogt_test_ntsc.right b/test/svcd_ogt_test_ntsc.right index 6961f669..aa44f4b1 100644 --- a/test/svcd_ogt_test_ntsc.right +++ b/test/svcd_ogt_test_ntsc.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 2) #: MSF LSN Type Green? diff --git a/test/svcdgs.right b/test/svcdgs.right index 4ddf20ce..327d282c 100644 --- a/test/svcdgs.right +++ b/test/svcdgs.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 2) #: MSF LSN Type Green? diff --git a/test/vcd_demo.right b/test/vcd_demo.right index e0f7b374..28bf5f39 100644 --- a/test/vcd_demo.right +++ b/test/vcd_demo.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 3) #: MSF LSN Type Green? diff --git a/test/videocd.right b/test/videocd.right index 4c2c6d55..3f1800da 100644 --- a/test/videocd.right +++ b/test/videocd.right @@ -1,6 +1,7 @@ This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +Disc-image file __________________________________ CD-ROM Track List (1 - 5) #: MSF LSN Type Green?