2 Copyright (c) 2000-2012 Craig Condit, Stefan Hülswitt.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
7 1. Redistributions of source code must retain the above copyright notice,
8 this list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright notice,
10 this list of conditions and the following disclaimer in the documentation
11 and/or other materials provided with the distribution.
13 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
14 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
17 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #define _LARGEFILE64_SOURCE
46 extern int virtual, multi;
49 extern struct virt_header *virt_header;
50 extern int virtualMissing;
51 extern char *real_virt_name;
54 static pid_t childpid;
58 /****************************************************************************/
65 if((fd=open64(real_virt_name,O_RDWR|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP| S_IROTH))<0) error("Open failed (new track)");
66 if(write(fd,virt_header,CD_FRAMESIZE)!=CD_FRAMESIZE) error("Write failed (new track)");
69 if(virt_header->tracks>=MAX_VIRT_TRACKS-1) serror("Maximum number of virtual tracks reached");
70 pos=(long long)(virt_header->start[virt_header->tracks]=virt_header->leadout)*CD_FRAMESIZE;
71 virt_header->tracks++;
72 if(lseek64(fd,pos,SEEK_SET)<0) error("Seek failed (new track)");
78 if(pipe(pd)<0) error("Pipe failed (new track)");
79 if((childpid=fork())<0) error("Fork failed (new track)");
80 if(childpid==0) { /* child */
84 start_cdrecord(); /* doesn't returns */
86 close(pd[0]); fd=pd[1];
88 /* debug code; send data to /dev/null. */
90 fprintf(stderr,"DEBUG CODE: NO recording, sending data to /dev/null!\n");
91 if((fd=open("/dev/null",O_WRONLY))<0) error("Open failed (/dev/null)");
93 cd_avail-=padsize*CD_FRAMESIZE;
97 /****************************************************************************/
101 return virt_header->leadout;
104 /****************************************************************************/
108 return virt_header->has_cont;
111 /****************************************************************************/
113 void VprepareDump(void)
115 if((vfd=dup(fd))<0) error("Dup failed");
119 /****************************************************************************/
121 void VvirtRead(void *buf)
123 if(full_read(vfd,buf,CD_FRAMESIZE)!=CD_FRAMESIZE)
124 serror("Unexpected EOF reading data");
127 /****************************************************************************/
129 void VcloseTrack(int cont)
132 if(lseek64(fd,0,SEEK_SET)<0) error("Seek failed (close track)");
133 virt_header->has_cont=cont;
134 if(write(fd,virt_header,CD_FRAMESIZE)!=CD_FRAMESIZE) error("Write failed (close track)");
140 DEBUG("VcloseTrack: waiting for child termination\n");
141 while(wait(0)!=childpid);
144 if(vfd>=0) { close(vfd); vfd=-1; }
147 /****************************************************************************/
149 void Vwrite(const void *buf)
151 if(write(fd,buf,CD_FRAMESIZE)!=CD_FRAMESIZE) error("Write failed");
152 if(virtual) virt_header->leadout++;
153 cd_avail-=CD_FRAMESIZE;