From 5e72905dacdb0f29baf806a0b032dcf718a5572e Mon Sep 17 00:00:00 2001 From: grant Date: Mon, 20 Oct 2003 12:07:23 +0000 Subject: merge some patches from FreeBSD ports. allows this to build on FreeBSD using the ATAPI/CAM subsystem. --- audio/cdparanoia/Makefile | 6 +- audio/cdparanoia/buildlink2.mk | 6 +- audio/cdparanoia/distinfo | 16 ++- audio/cdparanoia/patches/patch-cb | 38 ++++-- audio/cdparanoia/patches/patch-cc | 10 +- audio/cdparanoia/patches/patch-cd | 28 ++-- audio/cdparanoia/patches/patch-ce | 169 +++++++++++++++++++++-- audio/cdparanoia/patches/patch-cf | 233 +++++++++++++++++++++++++++---- audio/cdparanoia/patches/patch-cg | 279 +++++++++++++++++++++++++++++++++----- 9 files changed, 672 insertions(+), 113 deletions(-) (limited to 'audio') diff --git a/audio/cdparanoia/Makefile b/audio/cdparanoia/Makefile index ffcff14924b..68ed302d36e 100644 --- a/audio/cdparanoia/Makefile +++ b/audio/cdparanoia/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.9 2003/07/17 21:22:01 grant Exp $ +# $NetBSD: Makefile,v 1.10 2003/10/20 12:07:23 grant Exp $ # DISTNAME= cdparanoia-III-alpha9.8 @@ -11,7 +11,7 @@ MAINTAINER= tech-pkg@NetBSD.org HOMEPAGE= http://www.xiph.org/paranoia/ COMMENT= CDDA reading utility with extra data verification features -ONLY_FOR_PLATFORM= NetBSD-*-* Linux-*-* +ONLY_FOR_PLATFORM= FreeBSD-*-* NetBSD-*-* Linux-*-* USE_GMAKE= YES USE_LIBTOOL= YES @@ -21,4 +21,6 @@ CONFIGURE_ARGS+= --includedir=${PREFIX}/include/cdparanoia MAKE_ENV+= GCC=yes +LDFLAGS.FreeBSD+= -lcam + .include "../../mk/bsd.pkg.mk" diff --git a/audio/cdparanoia/buildlink2.mk b/audio/cdparanoia/buildlink2.mk index 5f641a0e7f1..824b959bd47 100644 --- a/audio/cdparanoia/buildlink2.mk +++ b/audio/cdparanoia/buildlink2.mk @@ -1,11 +1,11 @@ -# $NetBSD: buildlink2.mk,v 1.3 2003/10/18 11:53:48 grant Exp $ +# $NetBSD: buildlink2.mk,v 1.4 2003/10/20 12:07:23 grant Exp $ .if !defined(CDPARANOIA_BUILDLINK2_MK) CDPARANOIA_BUILDLINK2_MK= # defined .include "../../mk/bsd.prefs.mk" -.if ${OPSYS} == "Linux" || ${OPSYS} == "NetBSD" +.if ${OPSYS} == "FreeBSD" || ${OPSYS} == "NetBSD" || ${OPSYS} == "Linux" BUILDLINK_PACKAGES+= cdparanoia BUILDLINK_DEPENDS.cdparanoia?= cdparanoia>=3.0 BUILDLINK_PKGSRCDIR.cdparanoia?= ../../audio/cdparanoia @@ -19,6 +19,6 @@ BUILDLINK_FILES.cdparanoia+= lib/libcdda_interface.* BUILDLINK_TARGETS+= cdparanoia-buildlink cdparanoia-buildlink: _BUILDLINK_USE -.endif # OPSYS == Linux || NetBSD +.endif # OPSYS == FreeBSD || NetBSD || Linux .endif # CDPARANOIA_BUILDLINK2_MK diff --git a/audio/cdparanoia/distinfo b/audio/cdparanoia/distinfo index fb25f41fc2b..694ec871433 100644 --- a/audio/cdparanoia/distinfo +++ b/audio/cdparanoia/distinfo @@ -1,4 +1,4 @@ -$NetBSD: distinfo,v 1.5 2002/03/04 14:45:12 itohy Exp $ +$NetBSD: distinfo,v 1.6 2003/10/20 12:07:23 grant Exp $ SHA1 (cdparanoia-III-alpha9.8.src.tgz) = 04cc33a7d22d6255f6239e3e74195506b3bdde06 Size (cdparanoia-III-alpha9.8.src.tgz) = 116591 bytes @@ -9,9 +9,11 @@ SHA1 (patch-ad) = 45cb1d2d402f5769447507c8da24e289396021e7 SHA1 (patch-ae) = ea4cbc4a13f36ba4da39bd9a944d4123f132b86e SHA1 (patch-ba) = 05f8efe4f0a2753217d3c1cf1014da64b1d92b73 SHA1 (patch-ca) = 4d7c183aae36fd525a1294be4b6f9a76401c524e -SHA1 (patch-cb) = 9a28bd78dc5df011717da9bb3006f84635c29edb -SHA1 (patch-cc) = 4132884598e845aa9ea0a501dd1635f9030cc104 -SHA1 (patch-cd) = 44b8050dddae449b4e16c5aab9cfcaccb62f9031 -SHA1 (patch-ce) = 83d0f1505bc019b6fb83584ad4f6571fccf3e2a2 -SHA1 (patch-cf) = ca8b2f4d13104ca387fa6205153a41cea405b9f8 -SHA1 (patch-cg) = a113dde9b6b6e1e73dd2a8cbff21318f44085529 +SHA1 (patch-cb) = 00215d433a86a35ae13f2092efefabadc5967bfb +SHA1 (patch-cc) = 6ee7d4842d178491ecf5285c429f932f2f854799 +SHA1 (patch-cd) = a2595237ddbaf35dfc1a5ce0bf7d1fa9244e1d67 +SHA1 (patch-ce) = 813f18a27808234a8a9139f0c53951b5fea83b37 +SHA1 (patch-cf) = ce4dc32047c2e382482a38d05144abefb376a87a +SHA1 (patch-cg) = d57b8019fd14baf0701a9a9f824a4f4bd64ab3ad +SHA1 (patch-ch) = 73c38418cd7ab5fa5a072abfc78479fdd1d87787 +SHA1 (patch-ci) = cff3eaff31ea324d7bde5d0d840df57453085bec diff --git a/audio/cdparanoia/patches/patch-cb b/audio/cdparanoia/patches/patch-cb index 9d01366a378..cc26ae80d7f 100644 --- a/audio/cdparanoia/patches/patch-cb +++ b/audio/cdparanoia/patches/patch-cb @@ -1,7 +1,7 @@ -$NetBSD: patch-cb,v 1.2 2002/03/04 14:45:14 itohy Exp $ +$NetBSD: patch-cb,v 1.3 2003/10/20 12:07:23 grant Exp $ ---- interface/low_interface.h.orig Mon Mar 26 15:12:11 2001 -+++ interface/low_interface.h Mon Mar 4 22:47:22 2002 +--- interface/low_interface.h.orig 2001-03-26 16:12:11.000000000 +1000 ++++ interface/low_interface.h @@ -25,6 +25,7 @@ #include #include @@ -10,17 +10,24 @@ $NetBSD: patch-cb,v 1.2 2002/03/04 14:45:14 itohy Exp $ #include #include -@@ -47,13 +48,24 @@ - +@@ -48,12 +49,32 @@ #include #include -+#endif + ++#elif defined(__FreeBSD__) ++ ++#include ++#include ++ ++#include ++#include ++ ++#elif defined(__NetBSD__) + -+#ifdef __NetBSD__ +#include +#include +#endif - ++ #include "cdda_interface.h" #define MAX_RETRIES 8 @@ -28,10 +35,21 @@ $NetBSD: patch-cb,v 1.2 2002/03/04 14:45:14 itohy Exp $ #define MIN_BIG_BUFF_SIZE 4096 +#ifdef __linux__ #define SG_OFF sizeof(struct sg_header) -+#endif -+#ifdef __NetBSD__ ++#elif defined(__FreeBSD__) ++#define SG_OFF (0) ++#elif defined(__NetBSD__) +#define SG_OFF sizeof(scsireq_t) +#endif #ifndef SG_EMULATED_HOST /* old kernel version; the check for the ioctl is still runtime, this +@@ -64,7 +85,9 @@ + #endif + + extern int cooked_init_drive (cdrom_drive *d); ++#ifndef __FreeBSD__ + extern unsigned char *scsi_inquiry (cdrom_drive *d); ++#endif + extern int scsi_init_drive (cdrom_drive *d); + #ifdef CDDA_TEST + extern int test_init_drive (cdrom_drive *d); diff --git a/audio/cdparanoia/patches/patch-cc b/audio/cdparanoia/patches/patch-cc index 4e2e5f2119a..d5be64a5eba 100644 --- a/audio/cdparanoia/patches/patch-cc +++ b/audio/cdparanoia/patches/patch-cc @@ -1,8 +1,8 @@ -$NetBSD: patch-cc,v 1.2 2000/01/28 07:18:38 rh Exp $ +$NetBSD: patch-cc,v 1.3 2003/10/20 12:07:23 grant Exp $ ---- interface/utils.h.orig Mon Aug 16 00:13:44 1999 -+++ interface/utils.h Fri Jan 28 08:04:27 2000 -@@ -1,4 +1,16 @@ +--- interface/utils.h.orig 2000-04-20 08:41:04.000000000 +1000 ++++ interface/utils.h +@@ -1,4 +1,18 @@ +#ifdef __linux__ #include +#endif @@ -15,6 +15,8 @@ $NetBSD: patch-cc,v 1.2 2000/01/28 07:18:38 rh Exp $ +#include +#endif +#include /* XXX */ ++#elif defined(__FreeBSD__) ++#include +#endif #include #include diff --git a/audio/cdparanoia/patches/patch-cd b/audio/cdparanoia/patches/patch-cd index 535ab0a98a8..fffc512e8e2 100644 --- a/audio/cdparanoia/patches/patch-cd +++ b/audio/cdparanoia/patches/patch-cd @@ -1,8 +1,8 @@ -$NetBSD: patch-cd,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ +$NetBSD: patch-cd,v 1.2 2003/10/20 12:07:23 grant Exp $ ---- interface/common_interface.c.orig Tue Dec 14 13:28:00 1999 -+++ interface/common_interface.c Sat Jan 15 16:55:18 2000 -@@ -13,19 +13,29 @@ +--- interface/common_interface.c.orig 2000-04-20 08:41:04.000000000 +1000 ++++ interface/common_interface.c +@@ -13,19 +13,28 @@ #include "utils.h" #include "smallft.h" @@ -16,8 +16,7 @@ $NetBSD: patch-cd,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ struct cdrom_volctrl volctl; if (ioctl(fd, CDROMVOLREAD, &volctl)) return(1); /* failure */ -+#endif -+#ifdef __NetBSD__ ++#elif defined(__FreeBSD__) || defined(__NetBSD__) + struct ioc_vol volctl; + if (ioctl(fd, CDIOCGETVOL, &volctl)) + return(1); /* failure */ @@ -32,7 +31,7 @@ $NetBSD: patch-cd,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ /* Use the ioctl thingy above ping the cdrom; this will get model info */ char *atapi_drive_info(int fd){ /* Work around the fact that the struct grew without warning in -@@ -46,6 +56,7 @@ +@@ -46,6 +55,7 @@ char *atapi_drive_info(int fd){ free(id); return(ret); } @@ -40,7 +39,7 @@ $NetBSD: patch-cd,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ int data_bigendianp(cdrom_drive *d){ float lsb_votes=0; -@@ -171,7 +182,9 @@ +@@ -171,7 +181,9 @@ int data_bigendianp(cdrom_drive *d){ knows the leasoud/leadin size. */ int FixupTOC(cdrom_drive *d,int tracks){ @@ -50,9 +49,11 @@ $NetBSD: patch-cd,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ int j; /* First off, make sure the 'starting sector' is >=0 */ -@@ -209,13 +222,24 @@ +@@ -208,14 +220,26 @@ int FixupTOC(cdrom_drive *d,int tracks){ + /* For a scsi device, the ioctl must go to the specialized SCSI CDROM device, not the generic device. */ ++#ifndef __FreeBSD__ if (d->ioctl_fd != -1) { +#ifdef __linux__ int result; @@ -76,7 +77,7 @@ $NetBSD: patch-cd,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ /* This is an odd little piece of code --Monty */ -@@ -223,8 +247,8 @@ +@@ -223,14 +247,15 @@ int FixupTOC(cdrom_drive *d,int tracks){ /* adjust end of last audio track to be in the first session */ for (j = tracks-1; j >= 0; j--) { if (j > 0 && !IS_AUDIO(d,j) && IS_AUDIO(d,j-1)) { @@ -87,3 +88,10 @@ $NetBSD: patch-cd,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ break; } } + return 1; + } + } ++#endif + return 0; + } + diff --git a/audio/cdparanoia/patches/patch-ce b/audio/cdparanoia/patches/patch-ce index de11aaf47db..8a84047260b 100644 --- a/audio/cdparanoia/patches/patch-ce +++ b/audio/cdparanoia/patches/patch-ce @@ -1,8 +1,12 @@ -$NetBSD: patch-ce,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ +$NetBSD: patch-ce,v 1.2 2003/10/20 12:07:23 grant Exp $ ---- interface/cooked_interface.c.orig Wed Aug 18 15:54:32 1999 -+++ interface/cooked_interface.c Mon Jan 17 23:43:14 2000 -@@ -13,6 +13,7 @@ +--- interface/cooked_interface.c.orig 2000-04-20 08:41:04.000000000 +1000 ++++ interface/cooked_interface.c +@@ -10,9 +10,11 @@ + #include "common_interface.h" + #include "utils.h" + ++#ifndef __FreeBSD__ static int cooked_readtoc (cdrom_drive *d){ int i; int tracks; @@ -10,7 +14,7 @@ $NetBSD: patch-ce,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ struct cdrom_tochdr hdr; struct cdrom_tocentry entry; -@@ -52,6 +53,45 @@ +@@ -52,6 +54,45 @@ static int cooked_readtoc (cdrom_drive * d->disc_toc[i].dwStartSector = entry.cdte_addr.lba; tracks=hdr.cdth_trk1+1; @@ -56,7 +60,7 @@ $NetBSD: patch-ce,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ d->cd_extra=FixupTOC(d,tracks); return(--tracks); /* without lead-out */ } -@@ -60,10 +100,15 @@ +@@ -60,10 +101,15 @@ static int cooked_readtoc (cdrom_drive * /* Set operating speed */ static int cooked_setspeed(cdrom_drive *d, int speed) { @@ -72,7 +76,7 @@ $NetBSD: patch-ce,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ } -@@ -72,6 +117,7 @@ +@@ -72,6 +118,7 @@ static int cooked_setspeed(cdrom_drive * */ static long cooked_read (cdrom_drive *d, void *p, long begin, long sectors){ @@ -80,7 +84,7 @@ $NetBSD: patch-ce,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ int retry_count,err; struct cdrom_read_audio arg; char *buffer=(char *)p; -@@ -127,6 +173,10 @@ +@@ -127,7 +174,133 @@ static long cooked_read (cdrom_drive *d, } while (err); return(sectors); @@ -88,24 +92,159 @@ $NetBSD: patch-ce,v 1.1.1.1 2000/01/19 08:03:00 itohy Exp $ +#ifdef __NetBSD__ + errx(1, "cooked_read: not implemented"); +#endif ++} ++#elif defined(__FreeBSD__) ++static int ++cooked_readtoc(cdrom_drive *d) ++{ ++ int i; ++ struct ioc_toc_header hdr; ++ struct ioc_read_toc_single_entry entry; ++ ++ if (ioctl(d->ioctl_fd, CDIOREADTOCHEADER, &hdr) == -1) { ++ int ret; ++ ++ if (errno == EPERM) { ++ ret = -102; ++ cderror(d, "102: "); ++ } else { ++ ret = -4; ++ cderror(d, "004: Unable to read table of contents header: "); ++ } ++ cderror(d, strerror(errno)); ++ cderror(d, "\n"); ++ return ret; ++ } ++ ++ entry.address_format = CD_LBA_FORMAT; ++ for (i = hdr.starting_track; i <= hdr.ending_track; ++i) { ++ entry.track = i; ++ ++ if (ioctl(d->ioctl_fd, CDIOREADTOCENTRY, &entry) == -1) { ++ cderror(d, "005: Unable to read table of contents entry\n"); ++ return -5; ++ } ++ ++ d->disc_toc[i - hdr.starting_track].bFlags = entry.entry.control; ++ d->disc_toc[i - hdr.starting_track].bTrack = entry.entry.track; ++ d->disc_toc[i - hdr.starting_track].dwStartSector = be32_to_cpu(entry.entry.addr.lba); ++ } ++ ++ entry.track = 0xaa; /* leadout */ ++ ++ if (ioctl(d->ioctl_fd, CDIOREADTOCENTRY, &entry) == -1) { ++ cderror(d, "005: Unable to read table of contents entry\n"); ++ return -5; ++ } ++ ++ d->disc_toc[i - hdr.starting_track].bFlags = entry.entry.control; ++ d->disc_toc[i - hdr.starting_track].bTrack = entry.entry.track; ++ d->disc_toc[i - hdr.starting_track].dwStartSector = be32_to_cpu(entry.entry.addr.lba); ++ ++ d->cd_extra = FixupTOC(d, hdr.ending_track - hdr.starting_track + 2); /* with TOC */ ++ ++ return hdr.ending_track - hdr.starting_track + 1; ++} ++ ++static int ++cooked_setspeed(cdrom_drive *d, int speed) ++{ ++#ifdef CDRIOCREADSPEED ++ speed *= 177; ++ return ioctl(d->ioctl_fd, CDRIOCREADSPEED, &speed); ++#else ++ return -1; ++#endif ++} ++ ++ ++static long ++cooked_read(cdrom_drive *d, void *p, long begin, long sectors) ++{ ++ int retry_count = 0; ++ struct ioc_read_audio arg; ++ ++ if (sectors > d->nsectors) ++ sectors = d->nsectors; ++ ++ arg.address_format = CD_LBA_FORMAT; ++ arg.address.lba = begin; ++ arg.buffer = p; ++ ++ for (;;) { ++ arg.nframes = sectors; ++ if (ioctl(d->ioctl_fd, CDIOCREADAUDIO, &arg) == -1) { ++ if (!d->error_retry) ++ return -7; ++ ++ switch (errno) { ++ case ENOMEM: ++ if (sectors == 1) { ++ cderror(d, "300: Kernel memory error\n"); ++ return -300; ++ } ++ /* FALLTHROUGH */ ++ default: ++ if (sectors == 1) { ++ if (retry_count > MAX_RETRIES - 1) { ++ char b[256]; ++ snprintf(b, sizeof(b), ++ "010: Unable to access sector %ld; " ++ "skipping...\n", begin); ++ cderror(d, b); ++ return -10; ++ } ++ break; ++ } ++ } ++ ++ if (retry_count > 4 && sectors > 1) ++ sectors = sectors * 3 / 4; ++ ++ ++retry_count; ++ ++ if (retry_count > MAX_RETRIES) { ++ cderror(d, "007: Unknown, unrecoverable error reading data\n"); ++ return -7; ++ } ++ } else ++ break; ++ } ++ ++ return sectors; } ++#endif ++ /* hook */ -@@ -191,6 +241,7 @@ + static int Dummy (cdrom_drive *d,int Switch){ +@@ -191,8 +364,11 @@ static void check_exceptions(cdrom_drive /* set function pointers to use the ioctl routines */ int cooked_init_drive (cdrom_drive *d){ -+#ifdef __linux__ ++#ifdef __NetBSD__ ++ errx(1, "cooked_init_drive: not implemented"); ++#else int ret; - +- ++#ifdef __linux__ switch(d->drive_type){ -@@ -255,5 +306,9 @@ + case MATSUSHITA_CDROM_MAJOR: /* sbpcd 1 */ + case MATSUSHITA_CDROM2_MAJOR: /* sbpcd 2 */ +@@ -243,6 +419,9 @@ int cooked_init_drive (cdrom_drive *d){ + default: + d->nsectors=40; + } ++#elif defined(__FreeBSD__) ++ d->nsectors = 26; /* FreeBSD only supports 64K I/O transfer size */ ++#endif + d->enable_cdda = Dummy; + d->read_audio = cooked_read; + d->set_speed = cooked_setspeed; +@@ -255,5 +434,6 @@ int cooked_init_drive (cdrom_drive *d){ if((ret=verify_read_command(d)))return(ret); d->error_retry=1; return(0); -+#endif -+#ifdef __NetBSD__ -+ errx(1, "cooked_init_drive: not implemented"); +#endif } diff --git a/audio/cdparanoia/patches/patch-cf b/audio/cdparanoia/patches/patch-cf index 2b7d6696217..51bd63d8491 100644 --- a/audio/cdparanoia/patches/patch-cf +++ b/audio/cdparanoia/patches/patch-cf @@ -1,7 +1,7 @@ -$NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ +$NetBSD: patch-cf,v 1.4 2003/10/20 12:07:23 grant Exp $ ---- interface/scan_devices.c.orig Mon Mar 26 14:44:01 2001 -+++ interface/scan_devices.c Mon Mar 4 00:23:01 2002 +--- interface/scan_devices.c.orig 2001-03-26 15:44:01.000000000 +1000 ++++ interface/scan_devices.c @@ -19,6 +19,8 @@ #include "common_interface.h" #include "utils.h" @@ -11,20 +11,39 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ #define MAX_DEV_LEN 20 /* Safe because strings only come from below */ /* must be absolute paths! */ static char *scsi_cdrom_prefixes[]={ -@@ -49,10 +51,12 @@ +@@ -49,10 +51,18 @@ static char *cdrom_devices[]={ "/dev/cm206cd", "/dev/gscd", "/dev/optcd",NULL}; ++#elif defined(__FreeBSD__) ++static char *cdrom_devices[] = { ++ "/dev/cd?c", ++ "/dev/acd?c", ++ "/dev/wcd?c", ++ "/dev/mcd?c", NULL}; +#endif /* Functions here look for a cdrom drive; full init of a drive type happens in interface.c */ -+#ifdef __linux__ ++#if defined(__linux__) || defined(__FreeBSD__) cdrom_drive *cdda_find_a_cdrom(int messagedest,char **messages){ /* Brute force... */ -@@ -98,6 +102,16 @@ +@@ -75,10 +85,12 @@ cdrom_drive *cdda_find_a_cdrom(int messa + if((d=cdda_identify(buffer,messagedest,messages))) + return(d); + idmessage(messagedest,messages,"",NULL); ++#ifdef __linux__ + buffer[pos-(cdrom_devices[i])]=j+97; + if((d=cdda_identify(buffer,messagedest,messages))) + return(d); + idmessage(messagedest,messages,"",NULL); ++#endif + } + }else{ + /* Name. Go for it. */ +@@ -98,6 +110,16 @@ cdrom_drive *cdda_find_a_cdrom(int messa } return(NULL); } @@ -41,7 +60,22 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ cdrom_drive *cdda_identify(const char *device, int messagedest,char **messages){ struct stat st; -@@ -146,6 +160,7 @@ +@@ -117,8 +139,14 @@ cdrom_drive *cdda_identify(const char *d + } + #endif + ++#if defined(__linux__) || defined(__NetBSD__) + d=cdda_identify_cooked(device,messagedest,messages); + if(!d)d=cdda_identify_scsi(device,NULL,messagedest,messages); ++#elif defined(__FreeBSD__) ++ d = cdda_identify_scsi(device, NULL, messagedest, messages); ++ if (d == NULL) ++ d = cdda_identify_cooked(device, messagedest, messages); ++#endif + + #ifdef CDDA_TEST + if(!d)d=cdda_identify_test(device,messagedest,messages); +@@ -146,6 +174,7 @@ char *test_resolve_symlink(const char *f cdrom_drive *cdda_identify_cooked(const char *dev, int messagedest, char **messages){ @@ -49,20 +83,67 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ cdrom_drive *d=NULL; struct stat st; int fd=-1; -@@ -273,6 +288,12 @@ +@@ -273,8 +302,59 @@ cdrom_drive *cdda_identify_cooked(const idmessage(messagedest,messages,"\t\tCDROM sensed: %s\n",description); return(d); -+#endif -+ -+#ifdef __NetBSD__ ++#elif defined(__NetBSD__) + /* no kernel support for CD-DA */ + return NULL; ++#elif defined(__FreeBSD__) ++ cdrom_drive *d; ++ struct stat st; ++ ++ if (stat(dev, &st)) { ++ idperror(messagedest, messages, "\t\tCould not stat %s", dev); ++ return NULL; ++ } ++ ++ if (!S_ISCHR(st.st_mode)) { ++ idmessage(messagedest, messages, "\t\t%s is no block device", dev); ++ return NULL; ++ } ++ ++ if ((d = calloc(1, sizeof(*d))) == NULL) { ++ idperror(messagedest, messages, "\t\tCould not allocate memory", NULL); ++ return NULL; ++ } ++ d->ioctl_fd = -1; ++ ++ if ((d->ioctl_fd = open(dev, O_RDONLY)) == -1) { ++ idperror(messagedest, messages, "\t\tCould not open %s", dev); ++ goto cdda_identify_cooked_fail; ++ } ++ ++ if (ioctl_ping_cdrom(d->ioctl_fd)) { ++ idmessage(messagedest, messages, "\t\tDevice %s is not a CDROM", dev); ++ goto cdda_identify_cooked_fail; ++ } ++ ++ d->drive_model = copystring("Generic cooked ioctl CDROM"); ++ d->interface = COOKED_IOCTL; ++ d->bigendianp = -1; ++ d->nsectors = -1; ++ ++ idmessage(messagedest, messages, "\t\tCDROM sensed: %s\n", d->drive_model); ++ ++ return d; ++ ++cdda_identify_cooked_fail: ++ if (d != NULL) { ++ if (d->ioctl_fd != -1) ++ close(d->ioctl_fd); ++ free(d); ++ } ++ return NULL; +#endif } ++#ifndef __FreeBSD__ struct sg_id { -@@ -289,12 +310,18 @@ + long l1; /* target | lun << 8 | channel << 16 | low_ino << 24 */ + long l2; /* Unique id */ +@@ -289,12 +369,18 @@ typedef struct scsiid{ /* Even *this* isn't as simple as it bloody well should be :-P */ /* SG has an easy interface, but SCSI overall does not */ static int get_scsi_id(int fd, scsiid *id){ @@ -81,7 +162,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ if(ioctl(fd,SCSI_IOCTL_GET_IDLUN,&argid))return(-1); id->bus=argid.l2; /* for now */ id->id=argid.l1&0xff; -@@ -302,6 +329,13 @@ +@@ -302,6 +388,13 @@ static int get_scsi_id(int fd, scsiid *i if(ioctl(fd,SCSI_IOCTL_GET_BUS_NUMBER,&busarg)==0) id->bus=busarg; @@ -95,7 +176,15 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ return(0); } -@@ -401,6 +435,7 @@ +@@ -390,6 +483,7 @@ matchfail: + if(dev!=-1)close(dev); + return(NULL); + } ++#endif + + void strscat(char *a,char *b,int n){ + int i; +@@ -401,6 +495,7 @@ void strscat(char *a,char *b,int n){ strcat(a," "); } @@ -103,15 +192,17 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ /* At this point, we're going to punt compatability before SG2, and allow only SG2 and SG3 */ static int verify_SG_version(cdrom_drive *d,int messagedest, -@@ -430,6 +465,7 @@ +@@ -430,7 +525,9 @@ static int verify_SG_version(cdrom_drive idmessage(messagedest,messages,buffer,""); return(major); } +#endif ++#if defined(__linux__) || defined(__NetBSD__) cdrom_drive *cdda_identify_scsi(const char *generic_device, const char *ioctl_device, int messagedest, -@@ -460,6 +496,7 @@ + char **messages){ +@@ -460,6 +557,7 @@ cdrom_drive *cdda_identify_scsi(const ch generic_device); return(NULL); } @@ -119,7 +210,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ if((int)(g_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){ if((int)(g_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){ idmessage(messagedest,messages,"\t\t%s is not a SCSI device", -@@ -471,6 +508,7 @@ +@@ -471,6 +569,7 @@ cdrom_drive *cdda_identify_scsi(const ch ioctl_device=temp; } } @@ -127,7 +218,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ } if(ioctl_device){ if(stat(ioctl_device,&i_st)){ -@@ -478,6 +516,7 @@ +@@ -478,6 +577,7 @@ cdrom_drive *cdda_identify_scsi(const ch ioctl_device); return(NULL); } @@ -135,7 +226,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ if((int)(i_st.st_rdev>>8)!=SCSI_CDROM_MAJOR){ if((int)(i_st.st_rdev>>8)!=SCSI_GENERIC_MAJOR){ idmessage(messagedest,messages,"\t\t%s is not a SCSI device", -@@ -489,6 +528,7 @@ +@@ -489,6 +589,7 @@ cdrom_drive *cdda_identify_scsi(const ch ioctl_device=temp; } } @@ -143,7 +234,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ } /* we need to resolve any symlinks for the lookup code to work */ -@@ -505,6 +545,7 @@ +@@ -505,6 +606,7 @@ cdrom_drive *cdda_identify_scsi(const ch } if(!generic_device || !ioctl_device){ @@ -151,7 +242,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ if(generic_device){ ioctl_device= scsi_match(generic_device,scsi_cdrom_prefixes, -@@ -520,6 +561,9 @@ +@@ -520,6 +622,9 @@ cdrom_drive *cdda_identify_scsi(const ch if(!generic_device) goto cdda_identify_scsi_fail; } @@ -161,7 +252,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ } idmessage(messagedest,messages,"\t\tgeneric device: %s",generic_device); -@@ -556,6 +600,7 @@ +@@ -556,6 +661,7 @@ cdrom_drive *cdda_identify_scsi(const ch type=(int)(i_st.st_rdev>>8); @@ -169,7 +260,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ if(type==SCSI_CDROM_MAJOR){ if (!S_ISBLK(i_st.st_mode)) { idmessage(messagedest,messages,"\t\tSCSI CDROM device %s not a " -@@ -567,8 +612,10 @@ +@@ -567,8 +673,10 @@ cdrom_drive *cdda_identify_scsi(const ch "major number",ioctl_device); goto cdda_identify_scsi_fail; } @@ -180,7 +271,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ if((int)(g_st.st_rdev>>8)==SCSI_GENERIC_MAJOR){ if (!S_ISCHR(g_st.st_mode)) { idmessage(messagedest,messages,"\t\tGeneric SCSI device %s not a " -@@ -580,6 +627,7 @@ +@@ -580,6 +688,7 @@ cdrom_drive *cdda_identify_scsi(const ch "major number",generic_device); goto cdda_identify_scsi_fail; } @@ -188,7 +279,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ d=calloc(1,sizeof(cdrom_drive)); -@@ -590,6 +638,7 @@ +@@ -590,6 +699,7 @@ cdrom_drive *cdda_identify_scsi(const ch d->bigendianp=-1; /* We don't know yet... */ d->nsectors=-1; @@ -196,7 +287,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ version=verify_SG_version(d,messagedest,messages); switch(version){ case -1:case 0:case 1: -@@ -599,6 +648,9 @@ +@@ -599,6 +709,9 @@ cdrom_drive *cdda_identify_scsi(const ch d->interface=GENERIC_SCSI; break; } @@ -206,7 +297,7 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ /* malloc our big buffer for scsi commands */ d->sg=malloc(MAX_BIG_BUFF_SIZE); -@@ -617,7 +669,16 @@ +@@ -617,7 +730,16 @@ cdrom_drive *cdda_identify_scsi(const ch /* It would seem some TOSHIBA CDROMs gets things wrong */ @@ -224,3 +315,91 @@ $NetBSD: patch-cf,v 1.3 2002/03/04 14:45:14 itohy Exp $ !strncmp (p + 16, "CD-ROM", 6) && p[0] == TYPE_DISK) { p[0] = TYPE_ROM; +@@ -653,6 +775,87 @@ cdda_identify_scsi_fail: + if(g_fd!=-1)close(g_fd); + return(NULL); + } ++#elif defined(__FreeBSD__) ++cdrom_drive *cdda_identify_scsi(const char *device, ++ const char *dummy, ++ int messagedest, ++ char **messages) ++{ ++ char *devname; ++ cdrom_drive *d = NULL; ++ ++ if (device == NULL) { ++ idperror(messagedest, messages, "\t\tNo device specified", NULL); ++ return NULL; ++ } ++ ++ if ((devname = test_resolve_symlink(device, messagedest, messages)) == NULL) ++ return NULL; ++ ++ if ((d = calloc(1, sizeof(*d))) == NULL) { ++ idperror(messagedest, messages, "\t\tCould not allocate memory", NULL); ++ free(devname); ++ return NULL; ++ } ++ ++ if ((d->dev = cam_open_device(devname, O_RDWR)) == NULL) { ++ idperror(messagedest, messages, "\t\tCould not open SCSI device: %s", cam_errbuf); ++ goto cdda_identify_scsi_fail; ++ } ++ ++ if ((d->ccb = cam_getccb(d->dev)) == NULL) { ++ idperror(messagedest, messages, "\t\tCould not allocate ccb", NULL); ++ goto cdda_identify_scsi_fail; ++ } ++ ++ if (strncmp(d->dev->inq_data.vendor, "TOSHIBA", 7) == 0 && ++ strncmp(d->dev->inq_data.product, "CD_ROM", 6) == 0 && ++ SID_TYPE(&d->dev->inq_data) == T_DIRECT) { ++ d->dev->inq_data.device = T_CDROM; ++ d->dev->inq_data.dev_qual2 |= 0x80; ++ } ++ ++ if (SID_TYPE(&d->dev->inq_data) != T_CDROM && ++ SID_TYPE(&d->dev->inq_data) != T_WORM) { ++ idmessage(messagedest, messages, ++ "\t\tDevice is neither a CDROM nor a WORM device\n", NULL); ++ goto cdda_identify_scsi_fail; ++ } ++ ++ d->ioctl_fd = -1; ++ d->bigendianp = -1; ++ d->nsectors = -1; ++ d->lun = d->dev->target_lun; ++ d->interface = GENERIC_SCSI; ++ ++ if ((d->sg_buffer = malloc(MAX_BIG_BUFF_SIZE)) == NULL) { ++ idperror(messagedest, messages, "Could not allocate buffer memory", NULL); ++ goto cdda_identify_scsi_fail; ++ } ++ ++ if ((d->drive_model = calloc(36,1)) == NULL) { ++ } ++ ++ strscat(d->drive_model, d->dev->inq_data.vendor, SID_VENDOR_SIZE); ++ strscat(d->drive_model, d->dev->inq_data.product, SID_PRODUCT_SIZE); ++ strscat(d->drive_model, d->dev->inq_data.revision, SID_REVISION_SIZE); ++ ++ idmessage(messagedest, messages, "\nCDROM model sensed: %s", d->drive_model); ++ ++ return d; ++ ++cdda_identify_scsi_fail: ++ free(devname); ++ if (d) { ++ if (d->ccb) ++ cam_freeccb(d->ccb); ++ if (d->dev) ++ cam_close_device(d->dev); ++ free(d); ++ } ++ return NULL; ++} ++#endif + + #ifdef CDDA_TEST + diff --git a/audio/cdparanoia/patches/patch-cg b/audio/cdparanoia/patches/patch-cg index ac350a0a4d5..83ce8ac3151 100644 --- a/audio/cdparanoia/patches/patch-cg +++ b/audio/cdparanoia/patches/patch-cg @@ -1,16 +1,17 @@ -$NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ +$NetBSD: patch-cg,v 1.7 2003/10/20 12:07:23 grant Exp $ ---- interface/scsi_interface.c.orig Sat Mar 24 10:15:46 2001 -+++ interface/scsi_interface.c Mon Mar 4 00:03:19 2002 -@@ -23,6 +23,7 @@ +--- interface/scsi_interface.c.orig 2001-03-24 12:15:46.000000000 +1100 ++++ interface/scsi_interface.c +@@ -23,6 +23,8 @@ static void tweak_SG_buffer(cdrom_drive int table,reserved; char buffer[256]; ++#ifndef __FreeBSD__ +#ifdef __linux__ /* maximum transfer size? */ if(ioctl(d->cdda_fd,SG_GET_RESERVED_SIZE,&reserved)){ /* Up, guess not. */ -@@ -31,6 +32,10 @@ +@@ -31,6 +33,10 @@ static void tweak_SG_buffer(cdrom_drive } if(ioctl(d->cdda_fd,SG_GET_SG_TABLESIZE,&table))table=1; @@ -21,7 +22,7 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ { int cur; -@@ -53,11 +58,13 @@ +@@ -53,14 +59,24 @@ static void tweak_SG_buffer(cdrom_drive cdmessage(d,buffer); } @@ -31,42 +32,77 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ if(ioctl(d->cdda_fd,SG_SET_COMMAND_Q,&reserved)){ cdmessage(d,"\tCouldn't disable command queue! Continuing anyway...\n"); } +- ++#endif ++#else /* FreeBSD */ ++ d->nsectors = 26; /* FreeBSD only supports 64K I/O transfer size */ ++ d->bigbuff = d->nsectors * CD_FRAMESIZE_RAW; ++ ++ sprintf(buffer,"\tSetting default read size to %d sectors (%d bytes).\n\n", ++ d->nsectors,d->nsectors*CD_FRAMESIZE_RAW); ++ cdmessage(d,buffer); +#endif - } -@@ -65,8 +72,14 @@ ++#ifdef __linux__ + static void reset_scsi(cdrom_drive *d){ int arg; d->enable_cdda(d,0); +@@ -74,6 +90,44 @@ static void reset_scsi(cdrom_drive *d){ + d->enable_cdda(d,1); + } -+#ifdef __linux__ - cdmessage(d,"sending SG SCSI reset... "); - if(ioctl(d->cdda_fd,SG_SCSI_RESET,&arg)) -+#endif -+#ifdef __NetBSD__ ++#elif defined(__NetBSD__) ++static void reset_scsi(cdrom_drive *d){ ++ int arg; ++ d->enable_cdda(d,0); ++ + cdmessage(d,"sending SCSI reset... "); + if(ioctl(d->cdda_fd,CDIOCRESET,&arg)) ++ cdmessage(d,"FAILED: EBUSY\n"); ++ else ++ cdmessage(d,"OK\n"); ++ ++ d->enable_cdda(d,1); ++} ++ ++#elif defined(__FreeBSD__) ++static void reset_scsi(cdrom_drive *d) { ++ d->enable_cdda(d,0); ++ ++ d->ccb->ccb_h.func_code = XPT_RESET_DEV; ++ d->ccb->ccb_h.timeout = 5000; ++ ++ cdmessage(d, "sending SCSI reset... "); ++ if (cam_send_ccb(d->dev, d->ccb)) { ++ cdmessage(d, "error sending XPT_RESET_DEV CCB"); ++ } else { ++ ++ if (((d->ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) || ++ ((d->ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_BDR_SENT)) ++ cdmessage(d,"OK\n"); ++ else ++ cdmessage(d,"FAILED\n"); ++ } ++ ++ d->enable_cdda(d,1); ++} +#endif - cdmessage(d,"FAILED: EBUSY\n"); - else - cdmessage(d,"OK\n"); -@@ -74,6 +87,7 @@ - d->enable_cdda(d,1); - } - ++ +#ifdef __linux__ static void clear_garbage(cdrom_drive *d){ fd_set fdset; struct timeval tv; -@@ -104,6 +118,7 @@ +@@ -104,21 +158,30 @@ static void clear_garbage(cdrom_drive *d flag=1; } } +#endif /* process a complete scsi command. */ ++#ifndef __FreeBSD__ static int handle_scsi_cmd(cdrom_drive *d, -@@ -111,14 +126,21 @@ + unsigned int cmd_len, unsigned int in_size, unsigned int out_size, @@ -89,7 +125,7 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ /* clear out any possibly preexisting garbage */ clear_garbage(d); -@@ -224,11 +246,53 @@ +@@ -224,11 +287,53 @@ static int handle_scsi_cmd(cdrom_drive * if(errno==0)errno=EIO; return(TR_EREAD); } @@ -144,7 +180,7 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ switch(key){ case 0: if(errno==0)errno=EIO; -@@ -266,9 +330,20 @@ +@@ -266,9 +371,20 @@ static int handle_scsi_cmd(cdrom_drive * commands still get through. Perhaps no data comes back even though the target reports success? */ @@ -166,7 +202,91 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ if(d->sg_buffer[i]!=bytefill){ flag=1; break; -@@ -600,6 +675,23 @@ +@@ -284,6 +400,83 @@ static int handle_scsi_cmd(cdrom_drive * + return(0); + } + ++#elif defined(__FreeBSD__) ++static int handle_scsi_cmd(cdrom_drive *d, ++ unsigned int cmd_len, ++ unsigned int out_size, ++ unsigned int in_size, ++ unsigned char bytefill, ++ int bytecheck) { ++ int result; ++ ++ bzero(&d->ccb->csio, sizeof(d->ccb->csio)); ++ ++ memcpy(d->ccb->csio.cdb_io.cdb_bytes, d->sg_buffer, cmd_len); ++ ++ if (bytecheck && out_size == 0) ++ memset(d->sg_buffer, bytefill, in_size); ++ ++ cam_fill_csio(&d->ccb->csio, ++ /* retries */ 0, ++ /* cbfcnp */ NULL, ++ /* flags */ CAM_DEV_QFRZDIS | (out_size ? CAM_DIR_OUT : CAM_DIR_IN), ++ /* tag_action */ MSG_SIMPLE_Q_TAG, ++ /* data_ptr */ out_size ? d->sg_buffer + cmd_len : d->sg_buffer, ++ /* dxfer_len */ out_size ? out_size : in_size, ++ /* sense_len */ SSD_FULL_SIZE, ++ /* cdb_len */ cmd_len, ++ /* timeout */ 60000); /* XXX */ ++ ++ if ((result = cam_send_ccb(d->dev, d->ccb)) < 0 || ++ (d->ccb->ccb_h.status & CAM_STATUS_MASK) == 0 /* hack? */) ++ return TR_EREAD; ++ ++ if ((d->ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP && ++ (d->ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_SCSI_STATUS_ERROR) { ++ fprintf (stderr, "\t\terror returned from SCSI command:\n" ++ "\t\tccb->ccb_h.status == %d\n", d->ccb->ccb_h.status); ++ errno = EIO; ++ return TR_UNKNOWN; ++ } ++ ++ if (d->ccb->csio.dxfer_len != in_size) { ++ errno = EIO; ++ return TR_EREAD; ++ } ++ ++ if (d->ccb->csio.sense_data.error_code & SSD_ERRCODE) { ++ switch (d->ccb->csio.sense_data.flags & SSD_KEY) { ++ case SSD_KEY_NO_SENSE: ++ errno = EIO; ++ return TR_UNKNOWN; ++ case SSD_KEY_RECOVERED_ERROR: ++ break; ++ case SSD_KEY_NOT_READY: ++ errno = EBUSY; ++ return TR_BUSY; ++ case SSD_KEY_MEDIUM_ERROR: ++ errno = EIO; ++ if (d->ccb->csio.sense_data.add_sense_code == 0x0c && ++ d->ccb->csio.sense_data.add_sense_code_qual == 0x09) ++ return TR_STREAMING; ++ else ++ return TR_MEDIUM; ++ case SSD_KEY_HARDWARE_ERROR: ++ errno = EIO; ++ return TR_FAULT; ++ case SSD_KEY_ILLEGAL_REQUEST: ++ errno = EINVAL; ++ return TR_ILLEGAL; ++ default: ++ errno = EIO; ++ return TR_UNKNOWN; ++ } ++ } ++ ++ return 0; ++} ++#endif ++ + /* Group 1 (10b) command */ + + static int mode_sense_atapi(cdrom_drive *d,int size,int page){ +@@ -600,6 +793,23 @@ static int scsi_read_toc2 (cdrom_drive * return(tracks); } @@ -190,7 +310,7 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ /* These do one 'extra' copy in the name of clean code */ static int i_read_28 (cdrom_drive *d, void *p, long begin, long sectors){ -@@ -833,16 +925,29 @@ +@@ -833,30 +1043,59 @@ static long scsi_read_map (cdrom_drive * while(1) { if((err=map(d,(p?buffer:NULL),begin,sectors))){ if(d->report_all){ @@ -204,24 +324,32 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ sprintf(b,"scsi_read error: sector=%ld length=%ld retry=%d\n", begin,sectors,retry_count); ++ fputs(b, stderr); cdmessage(d,b); sprintf(b," Sense key: %x ASC: %x ASCQ: %x\n", +#ifdef __linux__ (int)(sg_hd->sense_buffer[2]&0xf), (int)(sg_hd->sense_buffer[12]), -- (int)(sg_hd->sense_buffer[13])); -+ (int)(sg_hd->sense_buffer[13]) -+#endif -+#ifdef __NetBSD__ + (int)(sg_hd->sense_buffer[13])); ++#elif defined(__FreeBSD__) ++ d->ccb->csio.sense_data.flags & SSD_KEY, ++ d->ccb->csio.sense_data.add_sense_code, ++ d->ccb->csio.sense_data.add_sense_code_qual); ++#elif defined(__NetBSD__) + (int)(sreq->sense[2]&0xf), + (int)(sreq->sense[12]), -+ (int)(sreq->sense[13]) ++ (int)(sreq->sense[13])); +#endif -+ ); ++ fputs(b, stderr); cdmessage(d,b); sprintf(b," Transport error: %s\n",strerror_tr[err]); ++ fputs(b, stderr); cdmessage(d,b); -@@ -852,9 +957,17 @@ + sprintf(b," System error: %s\n",strerror(errno)); ++ fputs(b, stderr); + cdmessage(d,b); + ++#ifndef __FreeBSD__ fprintf(stderr,"scsi_read error: sector=%ld length=%ld retry=%d\n", begin,sectors,retry_count); fprintf(stderr," Sense key: %x ASC: %x ASCQ: %x\n", @@ -239,10 +367,15 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ + ); fprintf(stderr," Transport error: %s\n",strerror_tr[err]); fprintf(stderr," System error: %s\n",strerror(errno)); ++#endif } -@@ -1308,21 +1421,43 @@ + + if(!d->error_retry)return(-7); +@@ -1307,22 +1546,45 @@ static void check_fua_bit(cdrom_drive *d + return; } ++#ifndef __FreeBSD__ static int check_atapi(cdrom_drive *d){ +#ifdef __linux__ int atapiret=-1; @@ -286,7 +419,70 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ d->is_atapi=1; }else{ cdmessage(d,"\tDrive is SCSI\n"); -@@ -1434,7 +1569,7 @@ +@@ -1332,6 +1594,46 @@ static int check_atapi(cdrom_drive *d){ + return(d->is_atapi); + } + } ++#elif defined(__FreeBSD__) ++static int ++check_atapi(cdrom_drive *d) ++{ ++ bzero(&(&d->ccb->ccb_h)[1], sizeof(d->ccb->cpi) - sizeof(d->ccb->ccb_h)); ++ ++ d->ccb->ccb_h.func_code = XPT_PATH_INQ; ++ ++ cdmessage(d, "\nChecking for ATAPICAM...\n"); ++ ++ if (cam_send_ccb(d->dev, d->ccb) < 0) { ++ cderror(d, "\terror sending XPT_PATH_INQ CCB: "); ++ cderror(d, cam_errbuf); ++ cderror(d, "\n"); ++ return -1; ++ } ++ ++ if ((d->ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { ++ cderror(d, "\tXPT_PATH_INQ CCB failed: "); ++ cderror(d, cam_errbuf); ++ cderror(d, "\n"); ++ return -1; ++ } ++ ++ /* ++ * if the bus device name is `ata', we're (obviously) ++ * running ATAPICAM. ++ */ ++ ++ if (strncmp(d->ccb->cpi.dev_name, "ata", 3) == 0) { ++ cdmessage(d, "\tDrive is ATAPI (using ATAPICAM)\n"); ++ d->is_atapi = 1; ++ } else { ++ cdmessage(d, "\tDrive is SCSI\n"); ++ d->is_atapi = 0; ++ } ++ ++ return d->is_atapi; ++} ++#endif + + static int check_mmc(cdrom_drive *d){ + char *b; +@@ -1379,6 +1681,7 @@ static void check_exceptions(cdrom_drive + } + } + ++#ifndef __FreeBSD__ + /* request vendor brand and model */ + unsigned char *scsi_inquiry(cdrom_drive *d){ + memcpy(d->sg_buffer,(char[]){ 0x12,0,0,0,56,0},6); +@@ -1389,6 +1692,7 @@ unsigned char *scsi_inquiry(cdrom_drive + } + return (d->sg_buffer); + } ++#endif + + + int scsi_init_drive(cdrom_drive *d){ +@@ -1434,7 +1738,7 @@ int scsi_init_drive(cdrom_drive *d){ d->read_toc = (!memcmp(d->drive_model, "IMS", 3) && !d->is_atapi) ? scsi_read_toc2 : scsi_read_toc; @@ -295,3 +491,16 @@ $NetBSD: patch-cg,v 1.6 2002/03/04 14:45:14 itohy Exp $ if(!d->is_atapi){ +@@ -1458,8 +1762,12 @@ int scsi_init_drive(cdrom_drive *d){ + check_fua_bit(d); + + d->error_retry=1; ++#ifndef __FreeBSD__ + d->sg=realloc(d->sg,d->nsectors*CD_FRAMESIZE_RAW + SG_OFF + 128); + d->sg_buffer=d->sg+SG_OFF; ++#else ++ d->sg_buffer = realloc(d->sg_buffer, d->nsectors * CD_FRAMESIZE_RAW); ++#endif + d->report_all=1; + return(0); + } -- cgit v1.2.3