10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55337Szk194757 * Common Development and Distribution License (the "License").
65337Szk194757 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*7024Sec158148 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <string.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <libintl.h>
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include "bstream.h"
330Sstevel@tonic-gate #include "trackio.h"
340Sstevel@tonic-gate #include "misc_scsi.h"
350Sstevel@tonic-gate #include "util.h"
360Sstevel@tonic-gate #include "msgs.h"
370Sstevel@tonic-gate #include "main.h"
380Sstevel@tonic-gate #include "trackio.h"
390Sstevel@tonic-gate #include "mmc.h"
400Sstevel@tonic-gate
410Sstevel@tonic-gate static bstreamhandle
open_audio(char * fname)420Sstevel@tonic-gate open_audio(char *fname)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate int at;
450Sstevel@tonic-gate char *ext;
460Sstevel@tonic-gate
470Sstevel@tonic-gate /* No audio type specified, look at extension */
480Sstevel@tonic-gate if (audio_type == AUDIO_TYPE_NONE) {
490Sstevel@tonic-gate ext = (char *)(strrchr(fname, '.'));
500Sstevel@tonic-gate if (ext) {
510Sstevel@tonic-gate ext++;
520Sstevel@tonic-gate }
530Sstevel@tonic-gate if ((ext == NULL) || ((at = get_audio_type(ext)) == -1)) {
540Sstevel@tonic-gate err_msg(gettext(
550Sstevel@tonic-gate "Cannot understand file extension for %s\n"),
560Sstevel@tonic-gate fname);
570Sstevel@tonic-gate exit(1);
580Sstevel@tonic-gate }
590Sstevel@tonic-gate } else {
600Sstevel@tonic-gate at = audio_type;
610Sstevel@tonic-gate }
620Sstevel@tonic-gate if (at == AUDIO_TYPE_SUN)
630Sstevel@tonic-gate return (open_au_read_stream(fname));
640Sstevel@tonic-gate if (at == AUDIO_TYPE_WAV)
650Sstevel@tonic-gate return (open_wav_read_stream(fname));
660Sstevel@tonic-gate if (at == AUDIO_TYPE_CDA)
670Sstevel@tonic-gate return (open_file_read_stream(fname));
680Sstevel@tonic-gate if (at == AUDIO_TYPE_AUR)
690Sstevel@tonic-gate return (open_aur_read_stream(fname));
700Sstevel@tonic-gate return (NULL);
710Sstevel@tonic-gate }
720Sstevel@tonic-gate
730Sstevel@tonic-gate void
write_audio(char ** argv,int start_argc,int argc)740Sstevel@tonic-gate write_audio(char **argv, int start_argc, int argc)
750Sstevel@tonic-gate {
760Sstevel@tonic-gate bstreamhandle *h_ptr;
770Sstevel@tonic-gate int i, nfiles;
780Sstevel@tonic-gate struct track_info *ti;
795337Szk194757 uint32_t blks_req, blks_avail;
800Sstevel@tonic-gate off_t fsize;
810Sstevel@tonic-gate
820Sstevel@tonic-gate /* number of tracks to write */
830Sstevel@tonic-gate nfiles = argc - start_argc;
840Sstevel@tonic-gate h_ptr = (bstreamhandle *)my_zalloc(nfiles * sizeof (bstreamhandle));
850Sstevel@tonic-gate blks_req = 0;
860Sstevel@tonic-gate for (i = 0; i < nfiles; i++) {
870Sstevel@tonic-gate h_ptr[i] = open_audio(argv[start_argc + i]);
880Sstevel@tonic-gate if (h_ptr[i] == NULL) {
890Sstevel@tonic-gate err_msg(gettext("Cannot open %s: %s\n"),
900Sstevel@tonic-gate argv[start_argc + i], get_err_str());
910Sstevel@tonic-gate exit(1);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate (void) (h_ptr[i])->bstr_size(h_ptr[i], &fsize);
940Sstevel@tonic-gate
950Sstevel@tonic-gate /* 2352 bytes per block, 75 blocks per second */
960Sstevel@tonic-gate blks_req += 150 + fsize/2352; /* 2 sec gap per track */
970Sstevel@tonic-gate if (fsize % 2352)
980Sstevel@tonic-gate blks_req++;
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate (void) check_device(target, CHECK_DEVICE_NOT_READY |
1010Sstevel@tonic-gate CHECK_DEVICE_NOT_WRITABLE | CHECK_MEDIA_IS_NOT_WRITABLE |
1020Sstevel@tonic-gate EXIT_IF_CHECK_FAILED);
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate /* Put the device in track-at-once mode */
1050Sstevel@tonic-gate write_init(TRACK_MODE_AUDIO);
106178Sarutz ti = (struct track_info *)my_zalloc(sizeof (*ti));
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate /* Build information for next invisible track, -1 */
1090Sstevel@tonic-gate if ((build_track_info(target, -1, ti) == 0) ||
1105337Szk194757 ((ti->ti_flags & TI_NWA_VALID) == 0)) {
1110Sstevel@tonic-gate err_msg(gettext(
1120Sstevel@tonic-gate "Cannot get writable address for the media.\n"));
1130Sstevel@tonic-gate exit(1);
1140Sstevel@tonic-gate }
115*7024Sec158148 if ((blks_avail = get_last_possible_lba(target)) == 0) {
116*7024Sec158148 err_msg(gettext("Unable to determine media capacity. "
117*7024Sec158148 "Defaulting to 650 MB (74 minute) disc.\n"));
118*7024Sec158148 blks_avail = MAX_CD_BLKS;
119*7024Sec158148 } else {
1200Sstevel@tonic-gate /* LBA is always one less */
1210Sstevel@tonic-gate blks_avail++;
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate /*
1240Sstevel@tonic-gate * Actual number of blocks available based on nwa (next writable
1250Sstevel@tonic-gate * address) since there may already be information on the disc.
1260Sstevel@tonic-gate */
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate blks_avail -= ti->ti_nwa;
1290Sstevel@tonic-gate if (blks_avail < blks_req) {
1300Sstevel@tonic-gate err_msg(gettext("Insufficient space on the media.\n"));
1310Sstevel@tonic-gate exit(1);
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate for (i = 0; i < nfiles; i++) {
1340Sstevel@tonic-gate write_next_track(TRACK_MODE_AUDIO, h_ptr[i]);
1350Sstevel@tonic-gate if (simulation && (nfiles != 1)) {
1360Sstevel@tonic-gate (void) printf(gettext(
1370Sstevel@tonic-gate "Simulation mode : skipping remaining tracks\n"));
1380Sstevel@tonic-gate break;
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate for (i = 0; i < nfiles; i++)
1420Sstevel@tonic-gate (h_ptr[i])->bstr_close(h_ptr[i]);
1430Sstevel@tonic-gate free(ti);
1440Sstevel@tonic-gate free(h_ptr);
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate write_fini();
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate fini_device(target);
1490Sstevel@tonic-gate exit(0);
1500Sstevel@tonic-gate }
151