$NetBSD: patch-cd,v 1.7 2018/09/27 15:29:06 triaxx Exp $ Support for Sun and several BSD. --- interface/common_interface.c.orig 2008-08-21 16:08:54.000000000 +0000 +++ interface/common_interface.c @@ -9,26 +9,50 @@ ******************************************************************/ #include +#if defined(__APPLE__) && defined(__MACH__) +#include +#include +#include +#include +#include +#endif #include "low_interface.h" #include "utils.h" #include "smallft.h" +#ifdef __linux__ #include +#endif + +#ifdef __sun +#include +#endif /* Test for presence of a cdrom by pinging with the 'CDROMVOLREAD' ioctl() */ /* Also test using CDROM_GET_CAPABILITY (if available) as some newer DVDROMs will reject CDROMVOLREAD ioctl for god-knows-what reason */ int ioctl_ping_cdrom(int fd){ +#ifdef __linux__ struct cdrom_volctrl volctl; if (ioctl(fd, CDROMVOLREAD, &volctl) && ioctl(fd, CDROM_GET_CAPABILITY, NULL)<0) return(1); /* failure */ +#elif defined(__sun) + struct cdrom_volctrl volctl; + if (ioctl(fd, CDROMVOLCTRL, &volctl)) + return(1); /* failure */ +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) + struct ioc_vol volctl; + if (ioctl(fd, CDIOCGETVOL, &volctl)) + return(1); /* failure */ +#endif return(0); /* success! */ } +#ifdef __linux__ /* 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 @@ -49,6 +73,7 @@ char *atapi_drive_info(int fd){ free(id); return(ret); } +#endif int data_bigendianp(cdrom_drive *d){ float lsb_votes=0; @@ -174,9 +199,12 @@ int data_bigendianp(cdrom_drive *d){ knows the leadout/leadin size. */ int FixupTOC(cdrom_drive *d,int tracks){ +#ifdef __linux__ struct cdrom_multisession ms_str; +#endif int j; +#if !(defined(__APPLE__) && defined(__MACH__)) /* First off, make sure the 'starting sector' is >=0 */ for(j=0;jioctl_fd != -1) { +#ifdef __linux__ int result; ms_str.addr_format = CDROM_LBA; result = ioctl(d->ioctl_fd, CDROMMULTISESSION, &ms_str); if (result == -1) return -1; +# define ms_addr (ms_str.addr.lba) +#endif + +#if defined(__NetBSD__) || defined(__sun) + int ms_addr; + + ms_addr = 0; /* last session */ +#ifdef __NetBSD__ + if (ioctl(d->ioctl_fd, CDIOREADMSADDR, &ms_addr) == -1) +#else + if (ioctl(d->ioctl_fd, CDROMREADOFFSET, &ms_addr) == -1) +#endif + return -1; +#endif - if (ms_str.addr.lba > 100) { + if (ms_addr > 100) { /* This is an odd little piece of code --Monty */ @@ -226,15 +270,17 @@ 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)) { - if ((d->disc_toc[j].dwStartSector > ms_str.addr.lba - 11400) && - (ms_str.addr.lba - 11400 > d->disc_toc[j-1].dwStartSector)) - d->disc_toc[j].dwStartSector = ms_str.addr.lba - 11400; + if ((d->disc_toc[j].dwStartSector > ms_addr - 11400) && + (ms_addr - 11400 > d->disc_toc[j-1].dwStartSector)) + d->disc_toc[j].dwStartSector = ms_addr - 11400; break; } } return 1; } } +#endif +#endif return 0; }