pkgsrc - initial commit
[pkgsrc.git] / audio / cdparanoia / patches / patch-cd
1 $NetBSD: patch-cd,v 1.5 2009/08/09 16:00:53 drochner Exp $
2
3 --- interface/common_interface.c.orig   2008-08-21 18:08:54.000000000 +0200
4 +++ interface/common_interface.c
5 @@ -9,26 +9,42 @@
6   ******************************************************************/
7  
8  #include <math.h>
9 +#if defined(__APPLE__) && defined(__MACH__)
10 +#include <sys/syslimits.h>
11 +#include <assert.h>
12 +#include <stdlib.h>
13 +#include <paths.h>
14 +#include <fcntl.h>
15 +#endif
16  #include "low_interface.h"
17  #include "utils.h"
18  #include "smallft.h"
19  
20 +#ifdef __linux__
21  #include <linux/hdreg.h>
22 +#endif
23  
24  /* Test for presence of a cdrom by pinging with the 'CDROMVOLREAD' ioctl() */
25  /* Also test using CDROM_GET_CAPABILITY (if available) as some newer DVDROMs will
26     reject CDROMVOLREAD ioctl for god-knows-what reason */
27  int ioctl_ping_cdrom(int fd){
28 +#ifdef __linux__
29    struct cdrom_volctrl volctl;
30    if (ioctl(fd, CDROMVOLREAD, &volctl) &&
31        ioctl(fd, CDROM_GET_CAPABILITY, NULL)<0)
32      return(1); /* failure */
33 +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
34 +  struct ioc_vol volctl;
35 +  if (ioctl(fd, CDIOCGETVOL, &volctl)) 
36 +    return(1); /* failure */
37 +#endif
38  
39    return(0);
40    /* success! */
41  }
42  
43  
44 +#ifdef __linux__
45  /* Use the ioctl thingy above ping the cdrom; this will get model info */
46  char *atapi_drive_info(int fd){
47    /* Work around the fact that the struct grew without warning in
48 @@ -49,6 +65,7 @@ char *atapi_drive_info(int fd){
49    free(id);
50    return(ret);
51  }
52 +#endif
53  
54  int data_bigendianp(cdrom_drive *d){
55    float lsb_votes=0;
56 @@ -174,9 +191,12 @@ int data_bigendianp(cdrom_drive *d){
57     knows the leadout/leadin size. */
58  
59  int FixupTOC(cdrom_drive *d,int tracks){
60 +#ifdef __linux__
61    struct cdrom_multisession ms_str;
62 +#endif
63    int j;
64    
65 +#if !(defined(__APPLE__) && defined(__MACH__))
66    /* First off, make sure the 'starting sector' is >=0 */
67    
68    for(j=0;j<tracks;j++){
69 @@ -211,14 +231,26 @@ int FixupTOC(cdrom_drive *d,int tracks){
70    /* For a scsi device, the ioctl must go to the specialized SCSI
71       CDROM device, not the generic device. */
72  
73 +#if !defined(__FreeBSD__) && !defined(__DragonFly__)
74    if (d->ioctl_fd != -1) {
75 +#ifdef __linux__
76      int result;
77  
78      ms_str.addr_format = CDROM_LBA;
79      result = ioctl(d->ioctl_fd, CDROMMULTISESSION, &ms_str);
80      if (result == -1) return -1;
81 +# define ms_addr       (ms_str.addr.lba)
82 +#endif
83 +
84 +#ifdef __NetBSD__
85 +    int ms_addr;
86 +
87 +    ms_addr = 0;       /* last session */
88 +    if (ioctl(d->ioctl_fd, CDIOREADMSADDR, &ms_addr) == -1)
89 +      return -1;
90 +#endif
91  
92 -    if (ms_str.addr.lba > 100) {
93 +    if (ms_addr > 100) {
94  
95        /* This is an odd little piece of code --Monty */
96  
97 @@ -226,15 +258,17 @@ int FixupTOC(cdrom_drive *d,int tracks){
98        /* adjust end of last audio track to be in the first session */
99        for (j = tracks-1; j >= 0; j--) {
100         if (j > 0 && !IS_AUDIO(d,j) && IS_AUDIO(d,j-1)) {
101 -         if ((d->disc_toc[j].dwStartSector > ms_str.addr.lba - 11400) &&
102 -             (ms_str.addr.lba - 11400 > d->disc_toc[j-1].dwStartSector))
103 -           d->disc_toc[j].dwStartSector = ms_str.addr.lba - 11400;
104 +         if ((d->disc_toc[j].dwStartSector > ms_addr - 11400) &&
105 +             (ms_addr - 11400 > d->disc_toc[j-1].dwStartSector))
106 +           d->disc_toc[j].dwStartSector = ms_addr - 11400;
107           break;
108         }
109        }
110        return 1;
111      }
112    }
113 +#endif
114 +#endif
115    return 0;
116  }
117