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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 230c83a891Snakanon * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <stdlib.h> 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <errno.h> 337c478bd9Sstevel@tonic-gate #include <limits.h> 347c478bd9Sstevel@tonic-gate #include <unistd.h> 357c478bd9Sstevel@tonic-gate #include <libintl.h> 36*416baccdSec158148 #include <string.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #include "main.h" 397c478bd9Sstevel@tonic-gate #include "util.h" 407c478bd9Sstevel@tonic-gate #include "misc_scsi.h" 417c478bd9Sstevel@tonic-gate #include "mmc.h" 427c478bd9Sstevel@tonic-gate #include "bstream.h" 437c478bd9Sstevel@tonic-gate #include "device.h" 447c478bd9Sstevel@tonic-gate #include "msgs.h" 457c478bd9Sstevel@tonic-gate #include "transport.h" 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate struct t_data { 487c478bd9Sstevel@tonic-gate bstreamhandle h; 497c478bd9Sstevel@tonic-gate struct track_info ti; 507c478bd9Sstevel@tonic-gate }; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate int read_audio_track(cd_device *dev, struct track_info *ti, bstreamhandle h); 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #define READ_BURST 24 /* < 64K in all cases */ 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* 577c478bd9Sstevel@tonic-gate * This reads the data off of a cd while updating the progress indicator. 587c478bd9Sstevel@tonic-gate * We want to do this in smaller chunks since some CD drives have 597c478bd9Sstevel@tonic-gate * problems with larger reads. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate static int 627c478bd9Sstevel@tonic-gate read_data_track(cd_device *dev, struct track_info *ti, bstreamhandle h) 637c478bd9Sstevel@tonic-gate { 647c478bd9Sstevel@tonic-gate int blksize; 657c478bd9Sstevel@tonic-gate uint32_t blks_read, cblk, read_chunk, read_size; 667c478bd9Sstevel@tonic-gate uchar_t *buf; 677c478bd9Sstevel@tonic-gate int ret, sav; 687c478bd9Sstevel@tonic-gate int link_blks_count; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate buf = NULL; 717c478bd9Sstevel@tonic-gate ret = 0; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * the last link_blks_count blocks may not exist or be completely 757c478bd9Sstevel@tonic-gate * filled. We need to record the amount to avoid bailing out if 767c478bd9Sstevel@tonic-gate * they cannot be read. 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate if (dev->d_blksize == 512) { 807c478bd9Sstevel@tonic-gate blksize = 512; 817c478bd9Sstevel@tonic-gate link_blks_count = 8; 827c478bd9Sstevel@tonic-gate } else { 837c478bd9Sstevel@tonic-gate blksize = 2048; 847c478bd9Sstevel@tonic-gate link_blks_count = 2; 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate buf = (uchar_t *)my_zalloc(READ_BURST * blksize); 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate print_n_flush(gettext("Reading track %d..."), ti->ti_track_no); 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate if (verbose) 927c478bd9Sstevel@tonic-gate print_n_flush("Track size is %u...", ti->ti_track_size); 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate init_progress(); 957c478bd9Sstevel@tonic-gate cblk = ti->ti_start_address; 967c478bd9Sstevel@tonic-gate blks_read = 0; 977c478bd9Sstevel@tonic-gate while (blks_read < ti->ti_track_size) { 987c478bd9Sstevel@tonic-gate /* Last few are special */ 997c478bd9Sstevel@tonic-gate read_chunk = ti->ti_track_size - blks_read - link_blks_count; 1007c478bd9Sstevel@tonic-gate read_chunk = (read_chunk > READ_BURST) ? READ_BURST : 1017c478bd9Sstevel@tonic-gate read_chunk; 1027c478bd9Sstevel@tonic-gate if (read_chunk == 0) { 1037c478bd9Sstevel@tonic-gate /* Time for last link blocks */ 1047c478bd9Sstevel@tonic-gate read_chunk = link_blks_count; 1057c478bd9Sstevel@tonic-gate } 1067c478bd9Sstevel@tonic-gate read_size = read_chunk * blksize; 1077c478bd9Sstevel@tonic-gate if (read10(dev->d_fd, cblk, read_chunk, buf, read_size)) { 1087c478bd9Sstevel@tonic-gate if (h->bstr_write(h, buf, read_size) != read_size) { 1097c478bd9Sstevel@tonic-gate goto read_data_track_failed; 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate } else { 1127c478bd9Sstevel@tonic-gate if (blks_read != 1137c478bd9Sstevel@tonic-gate (ti->ti_track_size - link_blks_count)) { 1147c478bd9Sstevel@tonic-gate goto read_data_track_failed; 1157c478bd9Sstevel@tonic-gate } else { 1167c478bd9Sstevel@tonic-gate /* Read can fail for last link sectors */ 1177c478bd9Sstevel@tonic-gate errno = 0; 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate } 1207c478bd9Sstevel@tonic-gate blks_read += read_chunk; 1217c478bd9Sstevel@tonic-gate cblk += read_chunk; 1220c83a891Snakanon (void) progress((ti->ti_track_size), blks_read); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate /* l10n_NOTE : 'done' as in "Reading track 1...done" */ 1257c478bd9Sstevel@tonic-gate (void) str_print(gettext("done.\n"), progress_pos); 1267c478bd9Sstevel@tonic-gate ret = 1; 1277c478bd9Sstevel@tonic-gate read_data_track_failed: 1287c478bd9Sstevel@tonic-gate sav = errno; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate free(buf); 1317c478bd9Sstevel@tonic-gate errno = sav; 1327c478bd9Sstevel@tonic-gate return (ret); 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate static void 1367c478bd9Sstevel@tonic-gate ensure_media_space(uint32_t total_nblks, uchar_t end_tno) 1377c478bd9Sstevel@tonic-gate { 1387c478bd9Sstevel@tonic-gate off_t nblks_avail; 1397c478bd9Sstevel@tonic-gate uint_t bsize; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate get_media_type(target->d_fd); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate if (use_media_stated_capacity) { 1447c478bd9Sstevel@tonic-gate nblks_avail = get_last_possible_lba(target); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate if (nblks_avail <= 0) { 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate /* most newer drives use READ FORMAT CAPACITY */ 1497c478bd9Sstevel@tonic-gate nblks_avail = read_format_capacity(target->d_fd, 1507c478bd9Sstevel@tonic-gate &bsize); 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* if both methods fail no choice but to bail out */ 1537c478bd9Sstevel@tonic-gate if (nblks_avail <= 0) { 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate err_msg(gettext( 1567c478bd9Sstevel@tonic-gate "Cannot find out media capacity.\n")); 1577c478bd9Sstevel@tonic-gate exit(1); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate } else { 1617c478bd9Sstevel@tonic-gate if (device_type == CD_RW) { 1627c478bd9Sstevel@tonic-gate nblks_avail = MAX_CD_BLKS; 1637c478bd9Sstevel@tonic-gate } else { 1647c478bd9Sstevel@tonic-gate /* 1657c478bd9Sstevel@tonic-gate * For DVD drives use read_format_capacity as default 1667c478bd9Sstevel@tonic-gate * retrieve the media size, it can be 3.6, 3.9, 4.2, 1677c478bd9Sstevel@tonic-gate * 4.7, or 9.2 GB 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate nblks_avail = 1707c478bd9Sstevel@tonic-gate read_format_capacity(target->d_fd, &bsize); 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate /* sanity check. if not reasonable default to 4.7 GB */ 1737c478bd9Sstevel@tonic-gate if (nblks_avail < MAX_CD_BLKS) { 1747c478bd9Sstevel@tonic-gate nblks_avail = MAX_DVD_BLKS; 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate if ((total_nblks + end_tno*300) > nblks_avail) { 1807c478bd9Sstevel@tonic-gate err_msg(gettext("Not enough space on the media.\n")); 1817c478bd9Sstevel@tonic-gate if (debug) { 1827c478bd9Sstevel@tonic-gate (void) printf("Need %u only found %u \n", 1837c478bd9Sstevel@tonic-gate (total_nblks + end_tno*300), 1847c478bd9Sstevel@tonic-gate (uint32_t)nblks_avail); 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate exit(1); 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * This copies both audio and data CDs. It first reads the TOC of the source CD 1937c478bd9Sstevel@tonic-gate * and creates a temp file with the CD image. After this is completed it creates 1947c478bd9Sstevel@tonic-gate * the target CD using TAO mode. 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate void 1977c478bd9Sstevel@tonic-gate copy_cd(void) 1987c478bd9Sstevel@tonic-gate { 1997c478bd9Sstevel@tonic-gate cd_device *src; 2007c478bd9Sstevel@tonic-gate char *p; 2017c478bd9Sstevel@tonic-gate uchar_t *toc, end_tno; 2027c478bd9Sstevel@tonic-gate int blksize, i; 2037c478bd9Sstevel@tonic-gate int audio_cd, data_cd; 2047c478bd9Sstevel@tonic-gate uint32_t total_nblks; 2057c478bd9Sstevel@tonic-gate int ret; 2067c478bd9Sstevel@tonic-gate struct t_data *tlist; 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate print_n_flush(gettext("Analyzing source CD...")); 2097c478bd9Sstevel@tonic-gate (void) check_device(target, 2107c478bd9Sstevel@tonic-gate CHECK_DEVICE_NOT_WRITABLE|EXIT_IF_CHECK_FAILED); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate /* if source drive is specified on the command line */ 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate if (copy_src) { 2157c478bd9Sstevel@tonic-gate p = my_zalloc(PATH_MAX); 2167c478bd9Sstevel@tonic-gate if (lookup_device(copy_src, p) == 0) { 2177c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot find device %s"), copy_src); 2187c478bd9Sstevel@tonic-gate err_msg(gettext(" or no media in the drive\n")); 2197c478bd9Sstevel@tonic-gate exit(1); 2207c478bd9Sstevel@tonic-gate } 2217c478bd9Sstevel@tonic-gate src = get_device(copy_src, p); 2227c478bd9Sstevel@tonic-gate if (src == NULL) { 2237c478bd9Sstevel@tonic-gate err_msg(gettext("Unable to open %s\n"), copy_src); 2247c478bd9Sstevel@tonic-gate exit(1); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate free(p); 2277c478bd9Sstevel@tonic-gate } else { 2287c478bd9Sstevel@tonic-gate /* source is same as target drive */ 2297c478bd9Sstevel@tonic-gate src = target; 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate (void) check_device(src, CHECK_TYPE_NOT_CDROM | CHECK_NO_MEDIA | 2337c478bd9Sstevel@tonic-gate CHECK_DEVICE_NOT_READY | EXIT_IF_CHECK_FAILED); 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate toc = (uchar_t *)my_zalloc(4); 2367c478bd9Sstevel@tonic-gate if (!read_toc(src->d_fd, 0, 0, 4, toc)) { 2377c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot read table of contents\n")); 2387c478bd9Sstevel@tonic-gate exit(1); 2397c478bd9Sstevel@tonic-gate } 2407c478bd9Sstevel@tonic-gate end_tno = toc[3]; 2417c478bd9Sstevel@tonic-gate free(toc); 2427c478bd9Sstevel@tonic-gate tlist = (struct t_data *)my_zalloc(end_tno * sizeof (struct t_data)); 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate audio_cd = data_cd = 0; 2457c478bd9Sstevel@tonic-gate total_nblks = 0; 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* build track information so we can copy it over */ 2487c478bd9Sstevel@tonic-gate for (i = 1; i <= end_tno; i++) { 2497c478bd9Sstevel@tonic-gate struct track_info *ti; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate ti = &tlist[i - 1].ti; 2527c478bd9Sstevel@tonic-gate if (!build_track_info(src, i, ti)) { 2537c478bd9Sstevel@tonic-gate err_msg(gettext( 2547c478bd9Sstevel@tonic-gate "Cannot get information for track %d\n"), i); 2557c478bd9Sstevel@tonic-gate exit(1); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate total_nblks += ti->ti_track_size; 2587c478bd9Sstevel@tonic-gate if (ti->ti_track_mode & 4) 2597c478bd9Sstevel@tonic-gate data_cd = 1; 2607c478bd9Sstevel@tonic-gate else 2617c478bd9Sstevel@tonic-gate audio_cd = 1; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate /* Now some sanity checks on the track information */ 2647c478bd9Sstevel@tonic-gate if ((ti->ti_flags & TI_SESSION_NO_VALID) && 2657c478bd9Sstevel@tonic-gate (ti->ti_session_no != 1)) { 2667c478bd9Sstevel@tonic-gate err_msg( 2677c478bd9Sstevel@tonic-gate gettext("Copying multisession CD is not supported\n")); 2687c478bd9Sstevel@tonic-gate exit(1); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate if ((ti->ti_flags & TI_PACKET_MODE) || 2717c478bd9Sstevel@tonic-gate (ti->ti_flags & TI_BLANK_TRACK) || 2727c478bd9Sstevel@tonic-gate (ti->ti_flags & TI_DAMAGED_TRACK) || 2737c478bd9Sstevel@tonic-gate (data_cd && audio_cd) || (ti->ti_data_mode == 2)) { 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate err_msg(gettext("CD format is not supported\n")); 2767c478bd9Sstevel@tonic-gate exit(1); 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate if ((ti->ti_flags & TI_NWA_VALID) && 2797c478bd9Sstevel@tonic-gate (ti->ti_nwa != 0xffffffff)) { 2807c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot copy incomplete discs\n")); 2817c478bd9Sstevel@tonic-gate exit(1); 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate /* l10n_NOTE : 'done' as in "Analyzing source CD...done" */ 2857c478bd9Sstevel@tonic-gate (void) printf(gettext("done.\n")); 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate if (data_cd) { 2887c478bd9Sstevel@tonic-gate blksize = 2048; 2897c478bd9Sstevel@tonic-gate } else { 2907c478bd9Sstevel@tonic-gate /* audio cd */ 2917c478bd9Sstevel@tonic-gate blksize = 2352; 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate /* In case of audio CDs, build_track_info() returns 2352 sized nblks */ 2957c478bd9Sstevel@tonic-gate if (src->d_blksize == 512 && data_cd) { 2967c478bd9Sstevel@tonic-gate total_nblks /= 4; 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate (void) printf(gettext("\nCopying %d %s track%s : %ld kbytes\n\n"), 2997c478bd9Sstevel@tonic-gate end_tno, (audio_cd == 1) ? gettext("audio") : gettext("data"), 3007c478bd9Sstevel@tonic-gate (end_tno > 1) ? "s" : "", (long)((total_nblks*blksize)/1024)); 3017c478bd9Sstevel@tonic-gate 302*416baccdSec158148 if ((ret = check_avail_temp_space(total_nblks*blksize)) != 0) { 303*416baccdSec158148 err_msg(gettext("Cannot use temporary directory : %s\n"), 304*416baccdSec158148 strerror(ret)); 305*416baccdSec158148 err_msg(gettext("Use -m to specify alternate" 306*416baccdSec158148 " temporary directory\n")); 3077c478bd9Sstevel@tonic-gate exit(1); 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate /* 3117c478bd9Sstevel@tonic-gate * If we can check available space on the target media at this 3127c478bd9Sstevel@tonic-gate * Stage, then it is always better. We cannot check DVD+R(W) 3137c478bd9Sstevel@tonic-gate * as this media may be formatted and not blank. 3147c478bd9Sstevel@tonic-gate */ 3157c478bd9Sstevel@tonic-gate if (target && (src != target) && (device_type != DVD_PLUS) && 3167c478bd9Sstevel@tonic-gate (device_type != DVD_PLUS_W) && (!check_device(target, 3177c478bd9Sstevel@tonic-gate CHECK_NO_MEDIA|CHECK_MEDIA_IS_NOT_BLANK))) { 3187c478bd9Sstevel@tonic-gate ensure_media_space(total_nblks, end_tno); 3197c478bd9Sstevel@tonic-gate } 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate /* for each track */ 3227c478bd9Sstevel@tonic-gate for (i = 1; i <= end_tno; i++) { 3237c478bd9Sstevel@tonic-gate tlist[i - 1].h = open_temp_file_stream(); 3247c478bd9Sstevel@tonic-gate if (tlist[i - 1].h == NULL) { 3257c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot create temporary file : %s\n"), 3267c478bd9Sstevel@tonic-gate get_err_str()); 3277c478bd9Sstevel@tonic-gate exit(1); 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate if (audio_cd) 3317c478bd9Sstevel@tonic-gate ret = read_audio_track(src, &tlist[i - 1].ti, 3327c478bd9Sstevel@tonic-gate tlist[i - 1].h); 3337c478bd9Sstevel@tonic-gate else 3347c478bd9Sstevel@tonic-gate ret = read_data_track(src, &tlist[i - 1].ti, 3357c478bd9Sstevel@tonic-gate tlist[i - 1].h); 3367c478bd9Sstevel@tonic-gate if (ret == 0) { 3377c478bd9Sstevel@tonic-gate err_msg(gettext("Error reading track %d : %s\n"), i, 3387c478bd9Sstevel@tonic-gate get_err_str()); 3397c478bd9Sstevel@tonic-gate if (debug) 3407c478bd9Sstevel@tonic-gate (void) printf("%x %x %x %x\n", uscsi_status, 3417c478bd9Sstevel@tonic-gate SENSE_KEY(rqbuf), ASC(rqbuf), ASCQ(rqbuf)); 3427c478bd9Sstevel@tonic-gate exit(1); 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate /* 3477c478bd9Sstevel@tonic-gate * We've finished copying the CD. If source and destination are the same 3487c478bd9Sstevel@tonic-gate * or they where not specified then eject the disk and wait for a new 3497c478bd9Sstevel@tonic-gate * disk to be inserted. 3507c478bd9Sstevel@tonic-gate */ 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate while ((target == NULL) || 3537c478bd9Sstevel@tonic-gate check_device(target, CHECK_NO_MEDIA|CHECK_MEDIA_IS_NOT_BLANK)) { 3547c478bd9Sstevel@tonic-gate if (target != NULL) { 3557c478bd9Sstevel@tonic-gate (void) eject_media(target); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate (void) printf("\n"); 3597c478bd9Sstevel@tonic-gate print_n_flush( 3607c478bd9Sstevel@tonic-gate gettext("Insert a blank media in the drive and press Enter.")); 3617c478bd9Sstevel@tonic-gate (void) fflush(stdin); 3627c478bd9Sstevel@tonic-gate if (target) { 3637c478bd9Sstevel@tonic-gate fini_device(target); 3647c478bd9Sstevel@tonic-gate target = NULL; 3657c478bd9Sstevel@tonic-gate } 3667c478bd9Sstevel@tonic-gate (void) getchar(); 3677c478bd9Sstevel@tonic-gate (void) sleep(4); 3687c478bd9Sstevel@tonic-gate (void) setup_target(SCAN_WRITERS); 3697c478bd9Sstevel@tonic-gate } 3707c478bd9Sstevel@tonic-gate (void) printf("\n"); 3717c478bd9Sstevel@tonic-gate (void) setreuid(ruid, 0); 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate if ((device_type != DVD_PLUS) && (device_type != DVD_PLUS_W)) { 3747c478bd9Sstevel@tonic-gate ensure_media_space(total_nblks, end_tno); 3757c478bd9Sstevel@tonic-gate write_init(audio_cd ? TRACK_MODE_AUDIO : TRACK_MODE_DATA); 3767c478bd9Sstevel@tonic-gate } 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate /* for each track */ 3797c478bd9Sstevel@tonic-gate for (i = 0; i < end_tno; i++) { 3807c478bd9Sstevel@tonic-gate /* 3817c478bd9Sstevel@tonic-gate * DVD's dont contain tracks and need to be written in DAO 3827c478bd9Sstevel@tonic-gate * mode. 3837c478bd9Sstevel@tonic-gate */ 3847c478bd9Sstevel@tonic-gate if (device_type != CD_RW) { 3857c478bd9Sstevel@tonic-gate if (end_tno > 1) { 3867c478bd9Sstevel@tonic-gate err_msg(gettext( 3877c478bd9Sstevel@tonic-gate "Media state is not suitable for this" 3887c478bd9Sstevel@tonic-gate " write mode.\n")); 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate write_mode = DAO_MODE; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate /* 3937c478bd9Sstevel@tonic-gate * DVD-R(W) and DVD+R needs to have space reserved 3947c478bd9Sstevel@tonic-gate * prior to writing. 3957c478bd9Sstevel@tonic-gate */ 3967c478bd9Sstevel@tonic-gate if ((device_type == DVD_MINUS) || 3977c478bd9Sstevel@tonic-gate (device_type == DVD_PLUS)) { 3987c478bd9Sstevel@tonic-gate if (!set_reservation(target->d_fd, 3997c478bd9Sstevel@tonic-gate total_nblks + 1)) { 4007c478bd9Sstevel@tonic-gate (void) printf(gettext( 4017c478bd9Sstevel@tonic-gate "Setting reservation failed\n")); 4027c478bd9Sstevel@tonic-gate exit(1); 4037c478bd9Sstevel@tonic-gate } 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate write_next_track(audio_cd ? TRACK_MODE_AUDIO : TRACK_MODE_DATA, 4087c478bd9Sstevel@tonic-gate tlist[i].h); 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate /* 4117c478bd9Sstevel@tonic-gate * Running in simulation mode and writing several tracks is 4127c478bd9Sstevel@tonic-gate * useless so bail after the first track is done. 4137c478bd9Sstevel@tonic-gate */ 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate if (simulation && (end_tno != 1)) { 4167c478bd9Sstevel@tonic-gate (void) printf(gettext( 4177c478bd9Sstevel@tonic-gate "Simulation mode : skipping remaining tracks\n")); 4187c478bd9Sstevel@tonic-gate break; 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate write_fini(); 4237c478bd9Sstevel@tonic-gate /* close the temp file handles */ 4247c478bd9Sstevel@tonic-gate for (i = 0; i < end_tno; i++) 4257c478bd9Sstevel@tonic-gate (tlist[i].h)->bstr_close(tlist[i].h); 4267c478bd9Sstevel@tonic-gate free(tlist); 4277c478bd9Sstevel@tonic-gate fini_device(target); 4287c478bd9Sstevel@tonic-gate exit(0); 4297c478bd9Sstevel@tonic-gate } 430