diff --git a/lib/_cdio_freebsd.c b/lib/_cdio_freebsd.c index 3397a98d..7f4634b3 100644 --- a/lib/_cdio_freebsd.c +++ b/lib/_cdio_freebsd.c @@ -1,5 +1,5 @@ /* - $Id: _cdio_freebsd.c,v 1.2 2003/03/29 17:32:00 rocky Exp $ + $Id: _cdio_freebsd.c,v 1.3 2003/03/29 20:28:05 rocky Exp $ Copyright (C) 2003 Rocky Bernstein @@ -26,7 +26,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: _cdio_freebsd.c,v 1.2 2003/03/29 17:32:00 rocky Exp $"; +static const char _rcsid[] = "$Id: _cdio_freebsd.c,v 1.3 2003/03/29 20:28:05 rocky Exp $"; #include "cdio_assert.h" #include "cdio_private.h" @@ -59,7 +59,9 @@ static const char _rcsid[] = "$Id: _cdio_freebsd.c,v 1.2 2003/03/29 17:32:00 roc #define FIRST_TRACK_NUM (_obj->tochdr.starting_track) typedef struct { - int fd; + /* Things common to all drivers like this. + This must be first. */ + generic_img_private_t gen; int ioctls_debugged; /* for debugging */ @@ -70,8 +72,6 @@ typedef struct { char *source_name; - bool init; - /* Track information */ bool toc_init; /* if true, info below is valid. */ struct ioc_toc_header tochdr; @@ -85,39 +85,24 @@ typedef struct { static bool _cdio_init (_img_private_t *_obj) { - if (_obj->init) { + if (_obj->gen.init) { cdio_error ("init called more than once"); return false; } - _obj->fd = open (_obj->source_name, O_RDONLY, 0); + _obj->gen.fd = open (_obj->gen.source_name, O_RDONLY, 0); - if (_obj->fd < 0) + if (_obj->gen.fd < 0) { - cdio_error ("open (%s): %s", _obj->source_name, strerror (errno)); + cdio_error ("open (%s): %s", _obj->gen.source_name, strerror (errno)); return false; } - _obj->init = true; + _obj->gen.init = true; _obj->toc_init = false; return true; } -/*! - Release and free resources associated with cd. - */ -static void -_cdio_free (void *user_data) -{ - _img_private_t *_obj = user_data; - - if (NULL == _obj) return; - free (_obj->source_name); - - if (_obj->fd >= 0) close (_obj->fd); - free (_obj); -} - static int _set_bsize (int fd, unsigned int bsize) { @@ -197,7 +182,7 @@ _read_mode2_sector (void *user_data, void *data, lsn_t lsn, break; case _AM_IOCTL: - if (ioctl (_obj->fd, CDROMREADMODE2, &buf) == -1) + if (ioctl (_obj->gen.fd, CDROMREADMODE2, &buf) == -1) { perror ("ioctl()"); return 1; @@ -258,7 +243,7 @@ _cdio_stat_size (void *user_data) tocent.cdte_track = CDROM_LEADOUT; tocent.cdte_format = CDROM_LBA; - if (ioctl (_obj->fd, CDROMREADTOCENTRY, &tocent) == -1) + if (ioctl (_obj->gen.fd, CDROMREADTOCENTRY, &tocent) == -1) { perror ("ioctl(CDROMREADTOCENTRY)"); exit (EXIT_FAILURE); @@ -282,9 +267,9 @@ _cdio_set_arg (void *user_data, const char key[], const char value[]) if (!value) return -2; - free (_obj->source_name); + free (_obj->gen.source_name); - _obj->source_name = strdup (value); + _obj->gen.source_name = strdup (value); } else if (!strcmp (key, "access-mode")) { @@ -314,7 +299,7 @@ _cdio_read_toc (_img_private_t *_obj) struct ioc_read_toc_entry te; /* read TOC header */ - if ( ioctl(_obj->fd, CDROMREADTOCHDR, &_obj->tochdr) == -1 ) { + if ( ioctl(_obj->gen.fd, CDROMREADTOCHDR, &_obj->tochdr) == -1 ) { cdio_error("error in ioctl(CDROMREADTOCHDR): %s\n", strerror(errno)); return false; } @@ -325,7 +310,7 @@ _cdio_read_toc (_img_private_t *_obj) te.data = _obj->tocent; - if ( ioctl(_obj->fd, CDIOREADTOCENTRYS, &te) == -1 ) { + if ( ioctl(_obj->gen.fd, CDIOREADTOCENTRYS, &te) == -1 ) { cdio_error("%s %d: %s\n", "error in ioctl CDROMREADTOCENTRY for track", i, strerror(errno)); @@ -347,7 +332,7 @@ _cdio_eject_media (void *user_data) { int status; int fd; - if ((fd = open(_obj->source_name, O_RDONLY|O_NONBLOCK)) > -1) { + if ((fd = open(_obj->gen.source_name, O_RDONLY|O_NONBLOCK)) > -1) { ret = 1; if (ioctl(fd, CDIOCALLOW) == -1) { cdio_error("ioctl(fd, CDIOCALLOW) failed: %s\n", strerror(errno)); @@ -357,7 +342,7 @@ _cdio_eject_media (void *user_data) { ret = 0; } close(fd); - _cdio_free((void *) _obj); + _cdio_generic_free((void *) _obj); } return ret; @@ -372,7 +357,7 @@ _cdio_get_arg (void *user_data, const char key[]) _img_private_t *_obj = user_data; if (!strcmp (key, "source")) { - return _obj->source_name; + return _obj->gen.source_name; } else if (!strcmp (key, "access-mode")) { switch (_obj->access_mode) { case _AM_IOCTL: @@ -521,7 +506,7 @@ cdio_open_freebsd (const char *source_name) cdio_funcs _funcs = { .eject_media = _cdio_eject_media, - .free = _cdio_free, + .free = _cdio_generic_free, .get_arg = _cdio_get_arg, .get_default_device = _cdio_get_default_device, .get_first_track_num= _cdio_get_first_track_num, @@ -530,6 +515,8 @@ cdio_open_freebsd (const char *source_name) .get_track_green = _cdio_get_track_green, .get_track_lba = NULL, /* This could be implemented if need be. */ .get_track_msf = _cdio_get_track_msf, + .lseek = cdio_generic_lseek, + .read = cdio_generic_read, .read_mode2_sector = _read_mode2_sector, .read_mode2_sectors = _read_mode2_sectors, .set_arg = _cdio_set_arg, @@ -539,7 +526,7 @@ cdio_open_freebsd (const char *source_name) _data = _cdio_malloc (sizeof (_img_private_t)); _data->access_mode = _AM_READ_CD; _data->init = false; - _data->fd = -1; + _data->gen.fd = -1; _cdio_set_arg(_data, "source", (NULL == source_name) ? DEFAULT_CDIO_DEVICE: source_name); @@ -550,7 +537,7 @@ cdio_open_freebsd (const char *source_name) if (_cdio_init(_data)) return ret; else { - _cdio_free (_data); + _cdio_generic_free (_data); return NULL; } diff --git a/lib/_cdio_sunos.c b/lib/_cdio_sunos.c index 8bc3a233..345116ef 100644 --- a/lib/_cdio_sunos.c +++ b/lib/_cdio_sunos.c @@ -1,5 +1,5 @@ /* - $Id: _cdio_sunos.c,v 1.2 2003/03/29 17:32:00 rocky Exp $ + $Id: _cdio_sunos.c,v 1.3 2003/03/29 20:28:05 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2002,2003 Rocky Bernstein @@ -31,7 +31,7 @@ #ifdef HAVE_SOLARIS_CDROM -static const char _rcsid[] = "$Id: _cdio_sunos.c,v 1.2 2003/03/29 17:32:00 rocky Exp $"; +static const char _rcsid[] = "$Id: _cdio_sunos.c,v 1.3 2003/03/29 20:28:05 rocky Exp $"; #include #include @@ -609,7 +609,7 @@ cdio_open_solaris (const char *source_name) }; _data = _cdio_malloc (sizeof (_img_private_t)); - _data->fd = -1; + _data->gen.fd = -1; _cdio_set_arg(_data, "source", (NULL == source_name) ? DEFAULT_CDIO_DEVICE: source_name);