aboutsummaryrefslogtreecommitdiff
path: root/sysutils/cdrtools/files/patch-cdda2wav::ioctl.c
blob: 1c13170bf8b4a1d979691f3d167b06a8d81bc8bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--- cdda2wav/ioctl.c	Sat Dec 27 17:29:28 2003
+++ cdda2wav/ioctl.c	Sun Jan 18 01:36:36 2004
@@ -59,10 +59,14 @@
 #include <cdrecord.h>
 
 #if defined (HAVE_IOCTL_INTERFACE)
-#if	!defined	sun	&& !defined	__sun
+#if  !defined(sun) && !defined(__sun) && !(__FreeBSD_version >= 501112)
 static struct cdrom_read_audio arg;
 #endif
 
+#if defined(__FreeBSD__) && __FreeBSD_version >= 400014
+static unsigned sector_size = CD_FRAMESIZE;
+#endif
+
 static int err;
 
 static void EnableCdda_cooked __PR((SCSI *scgp, int fAudioMode, unsigned uSectorsize));
@@ -72,13 +76,23 @@
 	int fAudioMode;
 	unsigned uSectorsize;
 {
+#if	defined(__FreeBSD__) && __FreeBSD_version >= 400014
+	if (scgp && scgp->verbose)
+		fprintf(stderr, "EnableCdda_cooked (CDRIOCSETBLOCKSIZE)...\n");
+
+	if (fAudioMode) {
+		if (ioctl(global.cooked_fd, CDRIOCGETBLOCKSIZE, &sector_size) ==-1)
+			sector_size = CD_FRAMESIZE;
+        	ioctl(global.cooked_fd, CDRIOCSETBLOCKSIZE, &uSectorsize);
+	} else
+        	ioctl(global.cooked_fd, CDRIOCSETBLOCKSIZE, &sector_size);
+#elif	defined	CDIOCSETCDDA
 	if (scgp && scgp->verbose) {
 		fprintf(stderr, "EnableCdda_cooked (CDIOCSETCDDA)...\n");
 		if (uSectorsize != CD_FRAMESIZE_RAW)
 			fprintf(stderr, "non audio sector size is ignored.\n");
 	}
 
-#if	defined	CDIOCSETCDDA
 	ioctl(global.cooked_fd, CDIOCSETCDDA, &fAudioMode);
 #else
 	fprintf(stderr, "EnableCdda_cooked (CDIOCSETCDDA) is not available...\n");
@@ -197,6 +211,10 @@
       /* trash the cache */
 
 #if	defined __FreeBSD__
+#if	__FreeBSD_version >= 501112
+      pread(global.cooked_fd, (void *) &p[0], 3*CD_FRAMESIZE_RAW,
+          find_an_off_sector(lSector, SectorBurstVal)*CD_FRAMESIZE_RAW);
+#else
       static struct cdrom_read_audio arg2;
 
       arg2.address.lba = find_an_off_sector(lSector, SectorBurstVal);
@@ -206,6 +224,7 @@
 
       ioctl(global.cooked_fd, CDROMREADAUDIO, &arg2);
 #endif
+#endif
 #if	defined __linux__
       static struct cdrom_read_audio arg2;
 
@@ -267,6 +286,17 @@
 
 /* read 2352 bytes audio data */
 #if	defined __FreeBSD__
+#if	__FreeBSD_version >= 501112
+    if (x && x->verbose) {
+	fprintf(stderr, "ReadCdRom_cooked (pread)...\n");
+    }
+
+  do {
+    err = 0;
+    if (pread(global.cooked_fd, (void *) &p[0], SectorBurstVal*CD_FRAMESIZE_RAW,
+	lSector*CD_FRAMESIZE_RAW) == -1)
+		err = -1;
+#else
   arg.address.lba = lSector;
   arg.addr_format = CDROM_LBA;
   arg.nframes = SectorBurstVal;
@@ -278,6 +308,7 @@
 
   do {
     err = ioctl(global.cooked_fd, CDROMREADAUDIO, &arg);
+#endif
 #endif
 #if	defined __linux__
   arg.addr.lba = lSector;