17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
54d218355Szk194757 * Common Development and Distribution License (the "License").
64d218355Szk194757 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*4df0f9a3Sec158148 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #include <string.h>
297c478bd9Sstevel@tonic-gate #include <stdlib.h>
307c478bd9Sstevel@tonic-gate #include <libintl.h>
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include "bstream.h"
337c478bd9Sstevel@tonic-gate #include "trackio.h"
347c478bd9Sstevel@tonic-gate #include "misc_scsi.h"
357c478bd9Sstevel@tonic-gate #include "util.h"
367c478bd9Sstevel@tonic-gate #include "msgs.h"
377c478bd9Sstevel@tonic-gate #include "main.h"
387c478bd9Sstevel@tonic-gate #include "trackio.h"
397c478bd9Sstevel@tonic-gate #include "mmc.h"
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate static bstreamhandle
open_audio(char * fname)427c478bd9Sstevel@tonic-gate open_audio(char *fname)
437c478bd9Sstevel@tonic-gate {
447c478bd9Sstevel@tonic-gate int at;
457c478bd9Sstevel@tonic-gate char *ext;
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate /* No audio type specified, look at extension */
487c478bd9Sstevel@tonic-gate if (audio_type == AUDIO_TYPE_NONE) {
497c478bd9Sstevel@tonic-gate ext = (char *)(strrchr(fname, '.'));
507c478bd9Sstevel@tonic-gate if (ext) {
517c478bd9Sstevel@tonic-gate ext++;
527c478bd9Sstevel@tonic-gate }
537c478bd9Sstevel@tonic-gate if ((ext == NULL) || ((at = get_audio_type(ext)) == -1)) {
547c478bd9Sstevel@tonic-gate err_msg(gettext(
557c478bd9Sstevel@tonic-gate "Cannot understand file extension for %s\n"),
567c478bd9Sstevel@tonic-gate fname);
577c478bd9Sstevel@tonic-gate exit(1);
587c478bd9Sstevel@tonic-gate }
597c478bd9Sstevel@tonic-gate } else {
607c478bd9Sstevel@tonic-gate at = audio_type;
617c478bd9Sstevel@tonic-gate }
627c478bd9Sstevel@tonic-gate if (at == AUDIO_TYPE_SUN)
637c478bd9Sstevel@tonic-gate return (open_au_read_stream(fname));
647c478bd9Sstevel@tonic-gate if (at == AUDIO_TYPE_WAV)
657c478bd9Sstevel@tonic-gate return (open_wav_read_stream(fname));
667c478bd9Sstevel@tonic-gate if (at == AUDIO_TYPE_CDA)
677c478bd9Sstevel@tonic-gate return (open_file_read_stream(fname));
687c478bd9Sstevel@tonic-gate if (at == AUDIO_TYPE_AUR)
697c478bd9Sstevel@tonic-gate return (open_aur_read_stream(fname));
707c478bd9Sstevel@tonic-gate return (NULL);
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate void
write_audio(char ** argv,int start_argc,int argc)747c478bd9Sstevel@tonic-gate write_audio(char **argv, int start_argc, int argc)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate bstreamhandle *h_ptr;
777c478bd9Sstevel@tonic-gate int i, nfiles;
787c478bd9Sstevel@tonic-gate struct track_info *ti;
794d218355Szk194757 uint32_t blks_req, blks_avail;
807c478bd9Sstevel@tonic-gate off_t fsize;
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate /* number of tracks to write */
837c478bd9Sstevel@tonic-gate nfiles = argc - start_argc;
847c478bd9Sstevel@tonic-gate h_ptr = (bstreamhandle *)my_zalloc(nfiles * sizeof (bstreamhandle));
857c478bd9Sstevel@tonic-gate blks_req = 0;
867c478bd9Sstevel@tonic-gate for (i = 0; i < nfiles; i++) {
877c478bd9Sstevel@tonic-gate h_ptr[i] = open_audio(argv[start_argc + i]);
887c478bd9Sstevel@tonic-gate if (h_ptr[i] == NULL) {
897c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot open %s: %s\n"),
907c478bd9Sstevel@tonic-gate argv[start_argc + i], get_err_str());
917c478bd9Sstevel@tonic-gate exit(1);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate (void) (h_ptr[i])->bstr_size(h_ptr[i], &fsize);
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate /* 2352 bytes per block, 75 blocks per second */
967c478bd9Sstevel@tonic-gate blks_req += 150 + fsize/2352; /* 2 sec gap per track */
977c478bd9Sstevel@tonic-gate if (fsize % 2352)
987c478bd9Sstevel@tonic-gate blks_req++;
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate (void) check_device(target, CHECK_DEVICE_NOT_READY |
1017c478bd9Sstevel@tonic-gate CHECK_DEVICE_NOT_WRITABLE | CHECK_MEDIA_IS_NOT_WRITABLE |
1027c478bd9Sstevel@tonic-gate EXIT_IF_CHECK_FAILED);
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate /* Put the device in track-at-once mode */
1057c478bd9Sstevel@tonic-gate write_init(TRACK_MODE_AUDIO);
1066e168402Sarutz ti = (struct track_info *)my_zalloc(sizeof (*ti));
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate /* Build information for next invisible track, -1 */
1097c478bd9Sstevel@tonic-gate if ((build_track_info(target, -1, ti) == 0) ||
1107c478bd9Sstevel@tonic-gate ((ti->ti_flags & TI_NWA_VALID) == 0)) {
1117c478bd9Sstevel@tonic-gate err_msg(gettext(
1127c478bd9Sstevel@tonic-gate "Cannot get writable address for the media.\n"));
1137c478bd9Sstevel@tonic-gate exit(1);
1147c478bd9Sstevel@tonic-gate }
115*4df0f9a3Sec158148 if ((blks_avail = get_last_possible_lba(target)) == 0) {
116*4df0f9a3Sec158148 err_msg(gettext("Unable to determine media capacity. "
117*4df0f9a3Sec158148 "Defaulting to 650 MB (74 minute) disc.\n"));
118*4df0f9a3Sec158148 blks_avail = MAX_CD_BLKS;
119*4df0f9a3Sec158148 } else {
1207c478bd9Sstevel@tonic-gate /* LBA is always one less */
1217c478bd9Sstevel@tonic-gate blks_avail++;
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * Actual number of blocks available based on nwa (next writable
1257c478bd9Sstevel@tonic-gate * address) since there may already be information on the disc.
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate blks_avail -= ti->ti_nwa;
1297c478bd9Sstevel@tonic-gate if (blks_avail < blks_req) {
1307c478bd9Sstevel@tonic-gate err_msg(gettext("Insufficient space on the media.\n"));
1317c478bd9Sstevel@tonic-gate exit(1);
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate for (i = 0; i < nfiles; i++) {
1347c478bd9Sstevel@tonic-gate write_next_track(TRACK_MODE_AUDIO, h_ptr[i]);
1357c478bd9Sstevel@tonic-gate if (simulation && (nfiles != 1)) {
1367c478bd9Sstevel@tonic-gate (void) printf(gettext(
1377c478bd9Sstevel@tonic-gate "Simulation mode : skipping remaining tracks\n"));
1387c478bd9Sstevel@tonic-gate break;
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate for (i = 0; i < nfiles; i++)
1427c478bd9Sstevel@tonic-gate (h_ptr[i])->bstr_close(h_ptr[i]);
1437c478bd9Sstevel@tonic-gate free(ti);
1447c478bd9Sstevel@tonic-gate free(h_ptr);
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate write_fini();
1477c478bd9Sstevel@tonic-gate
1487c478bd9Sstevel@tonic-gate fini_device(target);
1497c478bd9Sstevel@tonic-gate exit(0);
1507c478bd9Sstevel@tonic-gate }
151