/[debburn]/cdrkit/trunk/cdrecord/clone.c
ViewVC logotype

Contents of /cdrkit/trunk/cdrecord/clone.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Fri Aug 18 17:34:13 2006 UTC (6 years, 9 months ago) by blade
Original Path: nonameyet/trunk/cdrecord/clone.c
File MIME type: text/plain
File size: 6229 byte(s)
Imported the resorted version a08
1 /* @(#)clone.c 1.7 04/03/02 Copyright 2001-2004 J. Schilling */
2 #ifndef lint
3 static char sccsid[] =
4 "@(#)clone.c 1.7 04/03/02 Copyright 2001-2004 J. Schilling";
5 #endif
6 /*
7 * Clone Subchannel processing
8 *
9 * Copyright (c) 2001-2004 J. Schilling
10 */
11 /*
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * this program; see the file COPYING. If not, write to the Free Software
23 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 */
25
26 #include <mconfig.h>
27 #include <stdio.h>
28 #include <fctldefs.h>
29 #include <strdefs.h>
30 #include <unixstd.h>
31 #include <standard.h>
32 #include <btorder.h>
33 #include <utypes.h>
34 #include <schily.h>
35
36 #include <scg/scgcmd.h>
37 #include <scg/scsitransp.h>
38
39 #include "cdrecord.h"
40 #include "crc16.h"
41
42 #include <scg/scsireg.h>
43 #include "scsimmc.h"
44
45 /*#define SAO_RAW*/
46
47 EXPORT void clone_toc __PR((track_t *trackp));
48 EXPORT void clone_tracktype __PR((track_t *trackp));
49
50 extern int lverbose;
51 extern int xdebug;
52
53 extern Uchar _subq[110][12];
54 extern int _nsubh;
55
56
57 LOCAL int ctrl_first;
58 LOCAL int ctrl_last;
59 LOCAL int sectype_first;
60 LOCAL int sectype_last;
61 LOCAL int disktype;
62 LOCAL long loutstart;
63
64 /*
65 * Read Clone TOC description from full toc file.
66 */
67 EXPORT void
68 clone_toc(trackp)
69 track_t *trackp;
70 {
71 char filename[1024];
72 msf_t m;
73 msf_t mr;
74 struct tocheader *tp;
75 struct ftrackdesc *fp;
76 int f;
77 char buf[2048];
78 int amt;
79 int len;
80 int i;
81 int j;
82 int ctrladr;
83 Uint first = 100;
84 Uint last = 0;
85
86 len = strlen(trackp[1].filename);
87 if (len > (sizeof (filename)-5)) {
88 len = sizeof (filename)-5;
89 }
90 js_snprintf(filename, sizeof (filename), "%.*s.toc", len, trackp[1].filename);
91
92 f = open(filename, O_RDONLY|O_BINARY);
93 if (f < 0)
94 comerr("Cannot open '%s'.\n", filename);
95 amt = read(f, buf, sizeof (buf));
96
97 if (amt == sizeof (buf))
98 comerrno(EX_BAD, "TOC too large.\n");
99 close(f);
100 tp = (struct tocheader *)buf;
101 len = a_to_u_2_byte(tp->len) + sizeof (struct tocheader)-2;
102
103 if (xdebug) {
104 printf("Read %d bytes TOC len: %d first session: %d last session: %d\n",
105 amt, len, tp->first, tp->last);
106 }
107
108 fp = (struct ftrackdesc *)&buf[4];
109
110 for (i = 4, j = 0; i < len; i += 11) {
111 fp = (struct ftrackdesc *)&buf[i];
112 if (xdebug)
113 scg_prbytes("FT", (Uchar *)&buf[i], 11);
114 if (fp->sess_number != 1)
115 comerrno(EX_BAD, "Can only copy session # 1.\n");
116
117 if (fp->adr == 1) {
118 if (fp->point < first) {
119 first = fp->point;
120 ctrl_first = fp->control;
121 }
122 if (fp->point <= 99 && fp->point > last) {
123 last = fp->point;
124 ctrl_last = fp->control;
125 }
126 }
127 if (fp->adr != 1) {
128 switch (fp->point) {
129
130 case 0xB0:
131 case 0xC0:
132 case 0xC1:
133 break;
134 default:
135 continue;
136 }
137 }
138 m.msf_min = fp->amin;
139 m.msf_sec = fp->asec;
140 m.msf_frame = fp->aframe;
141
142 mr.msf_min = fp->pmin;
143 mr.msf_sec = fp->psec;
144 mr.msf_frame = fp->pframe;
145
146 if (fp->point == 0xA0) {
147 disktype = mr.msf_sec;
148 mr.msf_sec = from_bcd(mr.msf_sec); /* convert to BCD */
149 }
150
151 if (fp->point == 0xA2)
152 loutstart = msf_to_lba(fp->pmin, fp->psec, fp->pframe, TRUE);
153 ctrladr = fp->control << 4;
154 ctrladr |= fp->adr;
155
156 filltpoint(_subq[j], ctrladr, fp->point, &mr);
157 fillttime(_subq[j], &m);
158 _subq[j][6] = fp->res7;
159 if (fp->point == 0xC0 || fp->point == 0xC1) {
160 _subq[j][3] = m.msf_min;
161 _subq[j][4] = m.msf_sec;
162 _subq[j][5] = m.msf_frame;
163 }
164 if (fp->point == 0xC1) {
165 _subq[j][7] = mr.msf_min;
166 _subq[j][8] = mr.msf_sec;
167 _subq[j][9] = mr.msf_frame;
168 }
169 if (xdebug)
170 scg_prbytes("TOC ", _subq[j], 12);
171 j++;
172 }
173 _nsubh = j;
174 if (xdebug) {
175 printf("nsubheader %d lout: %ld track 1 secs: %ld\n", j, loutstart, trackp[1].tracksecs);
176 printf("first %u last %u ctrl first: %X ctrl last %X\n", first, last, ctrl_first, ctrl_last);
177 }
178 if (trackp->tracks != 1)
179 comerrno(EX_BAD, "Clone writing currently supports only one file argument.\n");
180 if (loutstart > trackp[1].tracksecs)
181 comerrno(EX_BAD, "Clone writing TOC length %ld does not match track length %ld\n",
182 loutstart, trackp[1].tracksecs);
183
184 if (amt > len) {
185 sectype_first = buf[len];
186 sectype_last = buf[len+1];
187 if (xdebug) {
188 printf("sectype first: %X sectype last %X\n",
189 sectype_first, sectype_last);
190 }
191 }
192 }
193
194
195 /*
196 * Set tracktypes for track 0 (lead-in) & track AA (lead-out)
197 *
198 * Control 0 = audio
199 * Control 1 = audio preemp
200 * Control 2 = audio copy
201 * Control 3 = audio copy preemp
202 * Control 4 = data
203 * Control 5 = packet data
204 */
205 EXPORT void
206 clone_tracktype(trackp)
207 track_t *trackp;
208 {
209 int tracks = trackp->tracks;
210 int sectype;
211
212 sectype = SECT_ROM;
213 if ((ctrl_first & TM_DATA) == 0) {
214 sectype = SECT_AUDIO;
215
216 if ((ctrl_first & TM_PREEM) != 0) {
217 trackp[0].flags |= TI_PREEMP;
218 } else {
219 trackp[0].flags &= ~TI_PREEMP;
220 sectype |= ST_PREEMPMASK;
221 }
222 if ((ctrl_first & TM_ALLOW_COPY) != 0) {
223 trackp[0].flags |= TI_COPY;
224 } else {
225 trackp[0].flags &= ~TI_COPY;
226 }
227 /* XXX ??? flags |= TI_SCMS; */
228 } else {
229 if ((ctrl_first & TM_INCREMENTAL) != 0) {
230 trackp[0].flags |= TI_PACKET;
231 } else {
232 trackp[0].flags &= ~TI_PACKET;
233 }
234 if (sectype_first != 0)
235 sectype = sectype_first;
236 }
237 trackp[0].sectype = sectype;
238
239 sectype = SECT_ROM;
240
241 if ((ctrl_last & TM_DATA) == 0) {
242 sectype = SECT_AUDIO;
243
244 if ((ctrl_last & TM_PREEM) != 0) {
245 trackp[tracks+1].flags |= TI_PREEMP;
246 } else {
247 trackp[tracks+1].flags &= ~TI_PREEMP;
248 sectype |= ST_PREEMPMASK;
249 }
250 if ((ctrl_last & TM_ALLOW_COPY) != 0) {
251 trackp[tracks+1].flags |= TI_COPY;
252 } else {
253 trackp[tracks+1].flags &= ~TI_COPY;
254 }
255 /* XXX ??? flags |= TI_SCMS; */
256 } else {
257 if ((ctrl_first & TM_INCREMENTAL) != 0) {
258 trackp[0].flags |= TI_PACKET;
259 } else {
260 trackp[0].flags &= ~TI_PACKET;
261 if (sectype_last != 0)
262 sectype = sectype_last;
263 }
264 }
265 trackp[tracks+1].sectype = sectype;
266 }

  ViewVC Help
Powered by ViewVC 1.1.5