New ATAPI burner utility. Replaces wormcontrol.

This commit is contained in:
Søren Schmidt 2000-01-06 22:46:20 +00:00
parent 0a3f3aa25c
commit 191ba01f6a
5 changed files with 389 additions and 5 deletions

72
sys/sys/cdrio.h Normal file
View File

@ -0,0 +1,72 @@
/*-
* Copyright (c) 2000 Søren Schmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _SYS_CDRIO_H_
#define _SYS_CDRIO_H_
#include <sys/ioccom.h>
struct cdr_track {
int track_type; /* type of this track */
#define CDR_DB_RAW 0x0 /* 2352 bytes of raw data */
#define CDR_DB_RAW_PQ 0x1 /* 2368 bytes raw data + P/Q subchan */
#define CDR_DB_RAW_PW 0x2 /* 2448 bytes raw data + P-W subchan */
#define CDR_DB_RAW_PW_R 0x3 /* 2448 bytes raw data + P-W raw sub */
#define CDR_DB_RES_4 0x4 /* reserved */
#define CDR_DB_RES_5 0x5 /* reserved */
#define CDR_DB_RES_6 0x6 /* reserved */
#define CDR_DB_VS_7 0x7 /* vendor specific */
#define CDR_DB_ROM_MODE1 0x8 /* 2048 bytes Mode 1 (ISO/IEC 10149) */
#define CDR_DB_ROM_MODE2 0x9 /* 2336 bytes Mode 2 (ISO/IEC 10149) */
#define CDR_DB_XA_MODE1 0xa /* 2048 bytes Mode 1 (CD-ROM XA 1) */
#define CDR_DB_XA_MODE2_F1 0xb /* 2056 bytes Mode 2 (CD-ROM XA 1) */
#define CDR_DB_XA_MODE2_F2 0xc /* 2324 bytes Mode 2 (CD-ROM XA 2) */
#define CDR_DB_XA_MODE2_MIX 0xd /* 2332 bytes Mode 2 (CD-ROM XA 1/2) */
#define CDR_DB_RES_14 0xe /* reserved */
#define CDR_DB_VS_15 0xf /* vendor specific */
int preemp; /* preemphasis if audio track*/
int test_write; /* use test writes, laser turned off */
};
#define CDRIOCBLANK _IOW('c', 100, int)
#define CDRIOCNEXTWRITEABLEADDR _IOR('c', 101, int)
#define CDRIOCOPENDISK _IO('c', 102)
#define CDRIOCCLOSEDISK _IO('c', 103)
#define CDRIOCOPENTRACK _IOW('c', 104, struct cdr_track)
#define CDRIOCCLOSETRACK _IO('c', 105)
#define CDRIOCWRITESPEED _IOW('c', 106, int)
#define CDRIOCGETBLOCKSIZE _IOR('c', 107, int)
#define CDRIOCSETBLOCKSIZE _IOW('c', 108, int)
#endif /* !_SYS_CDRIO_H_ */

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 1999 Søren Schmidt
* Copyright (c) 1999,2000 Søren Schmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -28,6 +28,9 @@
* $FreeBSD$
*/
#ifndef _SYS_DVDIO_H_
#define _SYS_DVDIO_H_
struct dvd_layer {
u_int8_t book_type :4;
u_int8_t book_version :4;
@ -70,10 +73,6 @@ struct dvd_authinfo {
u_char keychal[10];
};
#define DVDIOCREPORTKEY _IOWR('c', 32, struct dvd_authinfo)
#define DVDIOCSENDKEY _IOWR('c', 33, struct dvd_authinfo)
#define DVDIOCREADSTRUCTURE _IOWR('c', 34, struct dvd_struct)
#define DVD_STRUCT_PHYSICAL 0x00
#define DVD_STRUCT_COPYRIGHT 0x01
#define DVD_STRUCT_DISCKEY 0x02
@ -101,3 +100,9 @@ struct dvd_authinfo {
#define DVD_SEND_CHALLENGE 1
#define DVD_SEND_KEY2 3
#define DVD_SEND_RPC 6
#define DVDIOCREPORTKEY _IOWR('c', 200, struct dvd_authinfo)
#define DVDIOCSENDKEY _IOWR('c', 201, struct dvd_authinfo)
#define DVDIOCREADSTRUCTURE _IOWR('c', 202, struct dvd_struct)
#endif _SYS_DVDIO_H_

6
usr.sbin/burncd/Makefile Normal file
View File

@ -0,0 +1,6 @@
$FreeBSD$
PROG= burncd
MAN8= burncd.8
.include <bsd.prog.mk>

111
usr.sbin/burncd/burncd.8 Normal file
View File

@ -0,0 +1,111 @@
.\"
.\" Copyright (c) 2000 Søren Schmidt
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer,
.\" without modification, immediately at the beginning of the file.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. The name of the author may not be used to endorse or promote products
.\" derived from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd January 6, 2000
.Os
.Dt BURNCD 8
.Sh NAME
.Nm burncd
.Nd control the ATAPI CD-R/RW driver
.Sh SYNOPSIS
.Nm burncd
.Op Fl f Ar device
.Op Fl s Ar speed
.Op Fl e
.Op Fl p
.Op Fl q
.Ar [command]
.Ar [command filename...]
.Sh DESCRIPTION
The
.Nm
utility is used to burn CD-R/RW media using the ATAPI cd driver.
.Pp
Available options and operands:
.Pp
.Bl -tag -width XXXXXXXXXXXX
.It Fl f Ar device
set the device to use for the burning process.
.It Fl s Ar speed
set the speed of the burner device, typically 1, 2 or 4. Defaults to 1.
.It Fl e
eject the CD-R/RW when done.
.It Fl p
use preemphasis on audio tracks.
.It Fl q
quiet, dont print progress messages.
.El
.Pp
.Ar command
may be one of:
.Pp
.Bl -tag -width XXXXXXXXXXXX
.It Ar blank
Blank a CD-RW medium. This uses the fast blanking method, so data are not physically overwritten, only those areas that make the media appear blank for further usage.
.It Ar fixate
Fixate the medium so that the TOC is generated and the media can be used in an ordinary CD drive. The driver defaults to creating multisession media. Should be the last command to
.Nm
as the program exits when this has been done.
.It Ar raw | audio
Set the write mode to produce audio (raw mode) tracks for the following images on the command line.
.It Ar data | mode1
Set the write mode to produce data (mode1) tracks for the following image files
on the command line.
.It Ar filename
All other arguments are treated as filenames of images to write to the media.
.El
.Pp
Files whose length are not a multiple of the current media blocksize are quietly zero padded to fit the blocksize requirement.
.Pp
.Sh EXAMPLES
The typical usage for burning a data CD-R:
.Bd -literal
# burncd -f /dev/acd0c data file1 fixate
.Pp
The typical usage for burning an audio CD-R:
.Bd -literal
# burncd -f /dev/acd0c audio file1 file2 file3 fixate
.Pp
The typical usage for burning a mixed mode CD-R:
.Bd -literal
# burncd -f /dev/acd0c data file1 audio file2 file3 fixate
.Pp
.Sh BUGS
Probably, please report when found.
.Sh HISTORY
.Nm burncd
is currently under development. The
.Nm
command appeared in
.Fx 4.0 .
.Sh AUTHORS
The program has been contributed by
.ie t S/oren Schmidt,
.el Søren Schmidt,
Denmark.

190
usr.sbin/burncd/burncd.c Normal file
View File

@ -0,0 +1,190 @@
/*-
* Copyright (c) 2000 Søren Schmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* without modification, immediately at the beginning of the file.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <sysexits.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/cdio.h>
#include <sys/cdrio.h>
#define BLOCKS 32
static int fd, saved_block_size;
void cleanup(int);
int
main(int argc, char **argv)
{
int ch, speed = 1, preemp = 0, test_write = 0, eject = 0, quiet = 0;
char *devname = "/dev/acd0c";
char buf[2352*BLOCKS];
int arg, file, addr, count;
int block_size, cdopen = 0, size, tot_size = 0;
struct cdr_track track;
while ((ch = getopt(argc, argv, "ef:pqs:")) != -1) {
switch (ch) {
case 'e':
eject = 1;
break;
case 'f':
devname = optarg;
break;
case 'p':
preemp = 1;
break;
case 'q':
quiet = 1;
break;
case 's':
speed = atoi(optarg);
break;
case 't':
test_write = 1;
break;
default:
}
}
argc -= optind;
argv += optind;
if ((fd = open(devname, O_RDWR, 0)) < 0)
err(EX_NOINPUT, "open(%s)", devname);
if (ioctl(fd, CDRIOCWRITESPEED, &speed) < 0)
err(EX_IOERR, "ioctl(CDRIOCWRITESPEED)");
if (ioctl(fd, CDRIOCGETBLOCKSIZE, &saved_block_size) < 0)
err(EX_IOERR, "ioctl(CDRIOCGETBLOCKSIZE)");
err_set_exit(cleanup);
for (arg = 0; arg < argc; arg++) {
if (!strcmp(argv[arg], "blank")) {
if (!quiet)
fprintf(stderr, "blanking CD, please wait..\n");
if (ioctl(fd, CDRIOCBLANK) < 0)
err(EX_IOERR, "ioctl(CDRIOCBLANK)");
continue;
}
if (!strcmp(argv[arg], "fixate")) {
if (!quiet)
fprintf(stderr, "fixating CD, please wait..\n");
if (ioctl(fd, CDRIOCCLOSEDISK) < 0)
err(EX_IOERR, "ioctl(CDRIOCCLOSEDISK)");
break;
}
if (!strcmp(argv[arg], "audio") || !strcmp(argv[arg], "raw")) {
track.test_write = test_write;
track.track_type = CDR_DB_RAW;
track.preemp = preemp;
block_size = 2352;
continue;
}
if (!strcmp(argv[arg], "data") || !strcmp(argv[arg], "mode1")) {
track.test_write = test_write;
track.track_type = CDR_DB_ROM_MODE1;
track.preemp = 0;
block_size = 2048;
continue;
}
if ((file = open(argv[arg], O_RDONLY, 0)) < 0) {
err(EX_NOINPUT, "open(%s)", argv[arg]);
}
if (!cdopen) {
if (ioctl(fd, CDRIOCOPENDISK) < 0)
err(EX_IOERR, "ioctl(CDRIOCOPENDISK)");
cdopen = 1;
}
if (ioctl(fd, CDRIOCOPENTRACK, &track) < 0)
err(EX_IOERR, "ioctl(CDRIOCOPENTRACK)");
if (ioctl(fd, CDRIOCNEXTWRITEABLEADDR, &addr) < 0)
err(EX_IOERR, "ioctl(CDRIOCNEXTWRITEABLEADDR)");
if (!quiet) {
fprintf(stderr, "next writeable LBA %d\n", addr);
fprintf(stderr, "writing from file %s\n", argv[arg]);
}
lseek(fd, 0, SEEK_SET);
size = 0;
while ((count = read(file, buf, block_size * BLOCKS)) > 0) {
if (count % block_size) {
/* pad file to % block_size */
bzero(&buf[count], block_size * BLOCKS - count);
count = ((count / block_size) + 1) * block_size;
}
if (write(fd, buf, count) != count) {
int res;
fprintf(stderr, "\nonly wrote %d of %d bytes\n",
res, count);
break;
}
size += count;
tot_size += count;
if (!quiet)
fprintf(stderr, "written this track %d KB"
" total %d KB\r",
size/1024, tot_size/1024);
}
if (!quiet)
fprintf(stderr, "\n");
close(file);
if (ioctl(fd, CDRIOCCLOSETRACK) < 0)
err(EX_IOERR, "ioctl(CDRIOCCLOSETRACK)");
}
if (ioctl(fd, CDRIOCGETBLOCKSIZE, &saved_block_size) < 0)
err(EX_IOERR, "ioctl(CDRIOCGETBLOCKSIZE)");
if (eject)
if (ioctl(fd, CDIOCEJECT) < 0)
err(EX_IOERR, "ioctl(CDIOCEJECT)");
close(fd);
}
void cleanup(int dummy)
{
if (ioctl(fd, CDRIOCGETBLOCKSIZE, &saved_block_size) < 0)
err(EX_IOERR, "ioctl(CDRIOCGETBLOCKSIZE)");
}