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 51b01eaa0Szk194757 * Common Development and Distribution License (the "License"). 61b01eaa0Szk194757 * 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*4d218355Szk194757 * Copyright 2007 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 <stdio.h> 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <errno.h> 327c478bd9Sstevel@tonic-gate #include <limits.h> 337c478bd9Sstevel@tonic-gate #include <unistd.h> 347c478bd9Sstevel@tonic-gate #include <libintl.h> 35416baccdSec158148 #include <string.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #include "main.h" 387c478bd9Sstevel@tonic-gate #include "util.h" 397c478bd9Sstevel@tonic-gate #include "misc_scsi.h" 407c478bd9Sstevel@tonic-gate #include "mmc.h" 417c478bd9Sstevel@tonic-gate #include "bstream.h" 427c478bd9Sstevel@tonic-gate #include "device.h" 437c478bd9Sstevel@tonic-gate #include "msgs.h" 447c478bd9Sstevel@tonic-gate #include "transport.h" 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate struct t_data { 477c478bd9Sstevel@tonic-gate bstreamhandle h; 487c478bd9Sstevel@tonic-gate struct track_info ti; 497c478bd9Sstevel@tonic-gate }; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate int read_audio_track(cd_device *dev, struct track_info *ti, bstreamhandle h); 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #define READ_BURST 24 /* < 64K in all cases */ 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * This reads the data off of a cd while updating the progress indicator. 577c478bd9Sstevel@tonic-gate * We want to do this in smaller chunks since some CD drives have 587c478bd9Sstevel@tonic-gate * problems with larger reads. 597c478bd9Sstevel@tonic-gate */ 607c478bd9Sstevel@tonic-gate static int 617c478bd9Sstevel@tonic-gate read_data_track(cd_device *dev, struct track_info *ti, bstreamhandle h) 627c478bd9Sstevel@tonic-gate { 637c478bd9Sstevel@tonic-gate int blksize; 647c478bd9Sstevel@tonic-gate uint32_t blks_read, cblk, read_chunk, read_size; 657c478bd9Sstevel@tonic-gate uchar_t *buf; 667c478bd9Sstevel@tonic-gate int ret, sav; 677c478bd9Sstevel@tonic-gate int link_blks_count; 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate buf = NULL; 707c478bd9Sstevel@tonic-gate ret = 0; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * the last link_blks_count blocks may not exist or be completely 747c478bd9Sstevel@tonic-gate * filled. We need to record the amount to avoid bailing out if 757c478bd9Sstevel@tonic-gate * they cannot be read. 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate if (dev->d_blksize == 512) { 797c478bd9Sstevel@tonic-gate blksize = 512; 807c478bd9Sstevel@tonic-gate link_blks_count = 8; 817c478bd9Sstevel@tonic-gate } else { 827c478bd9Sstevel@tonic-gate blksize = 2048; 837c478bd9Sstevel@tonic-gate link_blks_count = 2; 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate buf = (uchar_t *)my_zalloc(READ_BURST * blksize); 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate print_n_flush(gettext("Reading track %d..."), ti->ti_track_no); 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate if (verbose) 917c478bd9Sstevel@tonic-gate print_n_flush("Track size is %u...", ti->ti_track_size); 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate init_progress(); 947c478bd9Sstevel@tonic-gate cblk = ti->ti_start_address; 957c478bd9Sstevel@tonic-gate blks_read = 0; 967c478bd9Sstevel@tonic-gate while (blks_read < ti->ti_track_size) { 977c478bd9Sstevel@tonic-gate /* Last few are special */ 987c478bd9Sstevel@tonic-gate read_chunk = ti->ti_track_size - blks_read - link_blks_count; 997c478bd9Sstevel@tonic-gate read_chunk = (read_chunk > READ_BURST) ? READ_BURST : 1007c478bd9Sstevel@tonic-gate read_chunk; 1017c478bd9Sstevel@tonic-gate if (read_chunk == 0) { 1027c478bd9Sstevel@tonic-gate /* Time for last link blocks */ 1037c478bd9Sstevel@tonic-gate read_chunk = link_blks_count; 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate read_size = read_chunk * blksize; 1067c478bd9Sstevel@tonic-gate if (read10(dev->d_fd, cblk, read_chunk, buf, read_size)) { 1077c478bd9Sstevel@tonic-gate if (h->bstr_write(h, buf, read_size) != read_size) { 1087c478bd9Sstevel@tonic-gate goto read_data_track_failed; 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate } else { 1117c478bd9Sstevel@tonic-gate if (blks_read != 1127c478bd9Sstevel@tonic-gate (ti->ti_track_size - link_blks_count)) { 1137c478bd9Sstevel@tonic-gate goto read_data_track_failed; 1147c478bd9Sstevel@tonic-gate } else { 1157c478bd9Sstevel@tonic-gate /* Read can fail for last link sectors */ 1167c478bd9Sstevel@tonic-gate errno = 0; 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate } 1197c478bd9Sstevel@tonic-gate blks_read += read_chunk; 1207c478bd9Sstevel@tonic-gate cblk += read_chunk; 1210c83a891Snakanon (void) progress((ti->ti_track_size), blks_read); 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate /* l10n_NOTE : 'done' as in "Reading track 1...done" */ 1247c478bd9Sstevel@tonic-gate (void) str_print(gettext("done.\n"), progress_pos); 1257c478bd9Sstevel@tonic-gate ret = 1; 1267c478bd9Sstevel@tonic-gate read_data_track_failed: 1277c478bd9Sstevel@tonic-gate sav = errno; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate free(buf); 1307c478bd9Sstevel@tonic-gate errno = sav; 1317c478bd9Sstevel@tonic-gate return (ret); 1327c478bd9Sstevel@tonic-gate } 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate static void 1357c478bd9Sstevel@tonic-gate ensure_media_space(uint32_t total_nblks, uchar_t end_tno) 1367c478bd9Sstevel@tonic-gate { 137*4d218355Szk194757 uint32_t nblks_avail; 1387c478bd9Sstevel@tonic-gate uint_t bsize; 1394077f1edSminht uint_t leadin_size = 0; 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 146*4d218355Szk194757 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 */ 153*4d218355Szk194757 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 } 1594077f1edSminht leadin_size = end_tno*300; 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate } else { 1627c478bd9Sstevel@tonic-gate if (device_type == CD_RW) { 1637c478bd9Sstevel@tonic-gate nblks_avail = MAX_CD_BLKS; 1647c478bd9Sstevel@tonic-gate } else { 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * For DVD drives use read_format_capacity as default 1677c478bd9Sstevel@tonic-gate * retrieve the media size, it can be 3.6, 3.9, 4.2, 1687c478bd9Sstevel@tonic-gate * 4.7, or 9.2 GB 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate nblks_avail = 1717c478bd9Sstevel@tonic-gate read_format_capacity(target->d_fd, &bsize); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate /* sanity check. if not reasonable default to 4.7 GB */ 1747c478bd9Sstevel@tonic-gate if (nblks_avail < MAX_CD_BLKS) { 1757c478bd9Sstevel@tonic-gate nblks_avail = MAX_DVD_BLKS; 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate 1804077f1edSminht if ((total_nblks + leadin_size) > nblks_avail) { 1817c478bd9Sstevel@tonic-gate err_msg(gettext("Not enough space on the media.\n")); 1827c478bd9Sstevel@tonic-gate if (debug) { 1837c478bd9Sstevel@tonic-gate (void) printf("Need %u only found %u \n", 1844077f1edSminht (total_nblks + leadin_size), 1857c478bd9Sstevel@tonic-gate (uint32_t)nblks_avail); 1867c478bd9Sstevel@tonic-gate } 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate exit(1); 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * This copies both audio and data CDs. It first reads the TOC of the source CD 1947c478bd9Sstevel@tonic-gate * and creates a temp file with the CD image. After this is completed it creates 1957c478bd9Sstevel@tonic-gate * the target CD using TAO mode. 1967c478bd9Sstevel@tonic-gate */ 1977c478bd9Sstevel@tonic-gate void 1987c478bd9Sstevel@tonic-gate copy_cd(void) 1997c478bd9Sstevel@tonic-gate { 2007c478bd9Sstevel@tonic-gate cd_device *src; 2017c478bd9Sstevel@tonic-gate char *p; 2027c478bd9Sstevel@tonic-gate uchar_t *toc, end_tno; 2037c478bd9Sstevel@tonic-gate int blksize, i; 2047c478bd9Sstevel@tonic-gate int audio_cd, data_cd; 2057c478bd9Sstevel@tonic-gate uint32_t total_nblks; 2067c478bd9Sstevel@tonic-gate int ret; 2077c478bd9Sstevel@tonic-gate struct t_data *tlist; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate print_n_flush(gettext("Analyzing source CD...")); 2107c478bd9Sstevel@tonic-gate (void) check_device(target, 2117c478bd9Sstevel@tonic-gate CHECK_DEVICE_NOT_WRITABLE|EXIT_IF_CHECK_FAILED); 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate /* if source drive is specified on the command line */ 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate if (copy_src) { 2167c478bd9Sstevel@tonic-gate p = my_zalloc(PATH_MAX); 2177c478bd9Sstevel@tonic-gate if (lookup_device(copy_src, p) == 0) { 2187c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot find device %s"), copy_src); 2197c478bd9Sstevel@tonic-gate err_msg(gettext(" or no media in the drive\n")); 2207c478bd9Sstevel@tonic-gate exit(1); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate src = get_device(copy_src, p); 2237c478bd9Sstevel@tonic-gate if (src == NULL) { 2247c478bd9Sstevel@tonic-gate err_msg(gettext("Unable to open %s\n"), copy_src); 2257c478bd9Sstevel@tonic-gate exit(1); 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate free(p); 2287c478bd9Sstevel@tonic-gate } else { 2297c478bd9Sstevel@tonic-gate /* source is same as target drive */ 2307c478bd9Sstevel@tonic-gate src = target; 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate (void) check_device(src, CHECK_TYPE_NOT_CDROM | CHECK_NO_MEDIA | 2347c478bd9Sstevel@tonic-gate CHECK_DEVICE_NOT_READY | EXIT_IF_CHECK_FAILED); 2357c478bd9Sstevel@tonic-gate 23654cafc85Szk194757 /* What type of media are we working with? */ 23754cafc85Szk194757 get_media_type(src->d_fd); 23854cafc85Szk194757 2397c478bd9Sstevel@tonic-gate toc = (uchar_t *)my_zalloc(4); 2407c478bd9Sstevel@tonic-gate if (!read_toc(src->d_fd, 0, 0, 4, toc)) { 2417c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot read table of contents\n")); 2427c478bd9Sstevel@tonic-gate exit(1); 2437c478bd9Sstevel@tonic-gate } 2447c478bd9Sstevel@tonic-gate end_tno = toc[3]; 2457c478bd9Sstevel@tonic-gate free(toc); 2467c478bd9Sstevel@tonic-gate tlist = (struct t_data *)my_zalloc(end_tno * sizeof (struct t_data)); 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate audio_cd = data_cd = 0; 2497c478bd9Sstevel@tonic-gate total_nblks = 0; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate /* build track information so we can copy it over */ 2527c478bd9Sstevel@tonic-gate for (i = 1; i <= end_tno; i++) { 2537c478bd9Sstevel@tonic-gate struct track_info *ti; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate ti = &tlist[i - 1].ti; 2567c478bd9Sstevel@tonic-gate if (!build_track_info(src, i, ti)) { 2577c478bd9Sstevel@tonic-gate err_msg(gettext( 2587c478bd9Sstevel@tonic-gate "Cannot get information for track %d\n"), i); 2597c478bd9Sstevel@tonic-gate exit(1); 2607c478bd9Sstevel@tonic-gate } 2617c478bd9Sstevel@tonic-gate total_nblks += ti->ti_track_size; 2627c478bd9Sstevel@tonic-gate if (ti->ti_track_mode & 4) 2637c478bd9Sstevel@tonic-gate data_cd = 1; 2647c478bd9Sstevel@tonic-gate else 2657c478bd9Sstevel@tonic-gate audio_cd = 1; 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate /* Now some sanity checks on the track information */ 2687c478bd9Sstevel@tonic-gate if ((ti->ti_flags & TI_SESSION_NO_VALID) && 2697c478bd9Sstevel@tonic-gate (ti->ti_session_no != 1)) { 2707c478bd9Sstevel@tonic-gate err_msg( 2717c478bd9Sstevel@tonic-gate gettext("Copying multisession CD is not supported\n")); 2727c478bd9Sstevel@tonic-gate exit(1); 2737c478bd9Sstevel@tonic-gate } 2744077f1edSminht if ((ti->ti_flags & TI_BLANK_TRACK) || 2757c478bd9Sstevel@tonic-gate (ti->ti_flags & TI_DAMAGED_TRACK) || 2767c478bd9Sstevel@tonic-gate (data_cd && audio_cd) || (ti->ti_data_mode == 2)) { 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate err_msg(gettext("CD format is not supported\n")); 2797c478bd9Sstevel@tonic-gate exit(1); 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate if ((ti->ti_flags & TI_NWA_VALID) && 2827c478bd9Sstevel@tonic-gate (ti->ti_nwa != 0xffffffff)) { 2837c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot copy incomplete discs\n")); 2847c478bd9Sstevel@tonic-gate exit(1); 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate /* l10n_NOTE : 'done' as in "Analyzing source CD...done" */ 2887c478bd9Sstevel@tonic-gate (void) printf(gettext("done.\n")); 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate if (data_cd) { 2917c478bd9Sstevel@tonic-gate blksize = 2048; 2927c478bd9Sstevel@tonic-gate } else { 2937c478bd9Sstevel@tonic-gate /* audio cd */ 2947c478bd9Sstevel@tonic-gate blksize = 2352; 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate /* In case of audio CDs, build_track_info() returns 2352 sized nblks */ 2987c478bd9Sstevel@tonic-gate if (src->d_blksize == 512 && data_cd) { 2997c478bd9Sstevel@tonic-gate total_nblks /= 4; 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate (void) printf(gettext("\nCopying %d %s track%s : %ld kbytes\n\n"), 3027c478bd9Sstevel@tonic-gate end_tno, (audio_cd == 1) ? gettext("audio") : gettext("data"), 3037c478bd9Sstevel@tonic-gate (end_tno > 1) ? "s" : "", (long)((total_nblks*blksize)/1024)); 3047c478bd9Sstevel@tonic-gate 305416baccdSec158148 if ((ret = check_avail_temp_space(total_nblks*blksize)) != 0) { 306416baccdSec158148 err_msg(gettext("Cannot use temporary directory : %s\n"), 307416baccdSec158148 strerror(ret)); 308416baccdSec158148 err_msg(gettext("Use -m to specify alternate" 309416baccdSec158148 " temporary directory\n")); 3107c478bd9Sstevel@tonic-gate exit(1); 3117c478bd9Sstevel@tonic-gate } 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate /* 3147c478bd9Sstevel@tonic-gate * If we can check available space on the target media at this 3157c478bd9Sstevel@tonic-gate * Stage, then it is always better. We cannot check DVD+R(W) 3167c478bd9Sstevel@tonic-gate * as this media may be formatted and not blank. 3177c478bd9Sstevel@tonic-gate */ 3187c478bd9Sstevel@tonic-gate if (target && (src != target) && (device_type != DVD_PLUS) && 3197c478bd9Sstevel@tonic-gate (device_type != DVD_PLUS_W) && (!check_device(target, 3207c478bd9Sstevel@tonic-gate CHECK_NO_MEDIA|CHECK_MEDIA_IS_NOT_BLANK))) { 3217c478bd9Sstevel@tonic-gate ensure_media_space(total_nblks, end_tno); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate /* for each track */ 3257c478bd9Sstevel@tonic-gate for (i = 1; i <= end_tno; i++) { 3267c478bd9Sstevel@tonic-gate tlist[i - 1].h = open_temp_file_stream(); 3277c478bd9Sstevel@tonic-gate if (tlist[i - 1].h == NULL) { 3287c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot create temporary file : %s\n"), 3297c478bd9Sstevel@tonic-gate get_err_str()); 3307c478bd9Sstevel@tonic-gate exit(1); 3317c478bd9Sstevel@tonic-gate } 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate if (audio_cd) 3347c478bd9Sstevel@tonic-gate ret = read_audio_track(src, &tlist[i - 1].ti, 3357c478bd9Sstevel@tonic-gate tlist[i - 1].h); 3367c478bd9Sstevel@tonic-gate else 3377c478bd9Sstevel@tonic-gate ret = read_data_track(src, &tlist[i - 1].ti, 3387c478bd9Sstevel@tonic-gate tlist[i - 1].h); 3397c478bd9Sstevel@tonic-gate if (ret == 0) { 3407c478bd9Sstevel@tonic-gate err_msg(gettext("Error reading track %d : %s\n"), i, 3417c478bd9Sstevel@tonic-gate get_err_str()); 3427c478bd9Sstevel@tonic-gate if (debug) 3437c478bd9Sstevel@tonic-gate (void) printf("%x %x %x %x\n", uscsi_status, 3447c478bd9Sstevel@tonic-gate SENSE_KEY(rqbuf), ASC(rqbuf), ASCQ(rqbuf)); 3457c478bd9Sstevel@tonic-gate exit(1); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate } 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate /* 3507c478bd9Sstevel@tonic-gate * We've finished copying the CD. If source and destination are the same 3517c478bd9Sstevel@tonic-gate * or they where not specified then eject the disk and wait for a new 3527c478bd9Sstevel@tonic-gate * disk to be inserted. 35354cafc85Szk194757 * 35454cafc85Szk194757 * Since, DVD+RWs are not blanked just reformated, allow the insertion 35554cafc85Szk194757 * of a DVD+RW to be the only condition necessary to complete copying. 3567c478bd9Sstevel@tonic-gate */ 3577c478bd9Sstevel@tonic-gate 35854cafc85Szk194757 do { 3597c478bd9Sstevel@tonic-gate if (target != NULL) { 3607c478bd9Sstevel@tonic-gate (void) eject_media(target); 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate (void) printf("\n"); 3647c478bd9Sstevel@tonic-gate print_n_flush( 3657c478bd9Sstevel@tonic-gate gettext("Insert a blank media in the drive and press Enter.")); 3667c478bd9Sstevel@tonic-gate (void) fflush(stdin); 3677c478bd9Sstevel@tonic-gate if (target) { 3687c478bd9Sstevel@tonic-gate fini_device(target); 3697c478bd9Sstevel@tonic-gate target = NULL; 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate (void) getchar(); 3727c478bd9Sstevel@tonic-gate (void) sleep(4); 3737c478bd9Sstevel@tonic-gate (void) setup_target(SCAN_WRITERS); 37454cafc85Szk194757 if (target) 37554cafc85Szk194757 get_media_type(target->d_fd); 37654cafc85Szk194757 } while ((target == NULL) || 37754cafc85Szk194757 ((device_type == DVD_PLUS_W)? check_device(target, CHECK_NO_MEDIA): 37854cafc85Szk194757 check_device(target, CHECK_NO_MEDIA|CHECK_MEDIA_IS_NOT_BLANK))); 37954cafc85Szk194757 3807c478bd9Sstevel@tonic-gate (void) printf("\n"); 3817c478bd9Sstevel@tonic-gate (void) setreuid(ruid, 0); 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate if ((device_type != DVD_PLUS) && (device_type != DVD_PLUS_W)) { 3847c478bd9Sstevel@tonic-gate ensure_media_space(total_nblks, end_tno); 3857c478bd9Sstevel@tonic-gate write_init(audio_cd ? TRACK_MODE_AUDIO : TRACK_MODE_DATA); 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate 3881b01eaa0Szk194757 /* 3891b01eaa0Szk194757 * Simulation writing can't happen on DVD+RW's 3901b01eaa0Szk194757 * or DVD+R's. According to the MMC spec this 3911b01eaa0Szk194757 * operation is not supported. So we should 3921b01eaa0Szk194757 * bail out if the user tries to do a simulation 3931b01eaa0Szk194757 * write. 3941b01eaa0Szk194757 */ 3951b01eaa0Szk194757 if (simulation && (device_type == DVD_PLUS_W || 3961b01eaa0Szk194757 device_type == DVD_PLUS)) { 3971b01eaa0Szk194757 err_msg(gettext("Media does not support simulated writing.\n")); 3981b01eaa0Szk194757 exit(1); 3991b01eaa0Szk194757 } 4001b01eaa0Szk194757 4014077f1edSminht if (device_type == DVD_PLUS_W) { 4024077f1edSminht /* 4034077f1edSminht * DVD+RW requires that we format the media before 4044077f1edSminht * writing. 4054077f1edSminht */ 4064077f1edSminht (void) print_n_flush(gettext("Formatting media...")); 4074077f1edSminht if (!format_media(target->d_fd)) { 4084077f1edSminht (void) printf(gettext( 4094077f1edSminht "Could not format media\n")); 4104077f1edSminht exit(1); 4114077f1edSminht } else { 4124077f1edSminht int counter; 4134077f1edSminht uchar_t *di; 4144077f1edSminht 4154077f1edSminht /* poll until format is done */ 4164077f1edSminht di = (uchar_t *)my_zalloc(DISC_INFO_BLOCK_SIZE); 4174077f1edSminht (void) sleep(10); 4184077f1edSminht for (counter = 0; counter < 200; counter++) { 4194077f1edSminht ret = read_disc_info(target->d_fd, di); 4204077f1edSminht if ((SENSE_KEY(rqbuf) == 2) && 4214077f1edSminht (ASC(rqbuf) == 4)) { 4224077f1edSminht (void) print_n_flush("."); 4234077f1edSminht (void) sleep(5); 4244077f1edSminht } else { 4254077f1edSminht break; 4264077f1edSminht } 4274077f1edSminht } 4284077f1edSminht } 4294077f1edSminht } 4304077f1edSminht 4317c478bd9Sstevel@tonic-gate /* for each track */ 4327c478bd9Sstevel@tonic-gate for (i = 0; i < end_tno; i++) { 4337c478bd9Sstevel@tonic-gate /* 4347c478bd9Sstevel@tonic-gate * DVD's dont contain tracks and need to be written in DAO 4357c478bd9Sstevel@tonic-gate * mode. 4367c478bd9Sstevel@tonic-gate */ 4377c478bd9Sstevel@tonic-gate if (device_type != CD_RW) { 4387c478bd9Sstevel@tonic-gate if (end_tno > 1) { 4397c478bd9Sstevel@tonic-gate err_msg(gettext( 4407c478bd9Sstevel@tonic-gate "Media state is not suitable for this" 4417c478bd9Sstevel@tonic-gate " write mode.\n")); 4427c478bd9Sstevel@tonic-gate } 4437c478bd9Sstevel@tonic-gate write_mode = DAO_MODE; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate /* 4467c478bd9Sstevel@tonic-gate * DVD-R(W) and DVD+R needs to have space reserved 4477c478bd9Sstevel@tonic-gate * prior to writing. 4487c478bd9Sstevel@tonic-gate */ 4497c478bd9Sstevel@tonic-gate if ((device_type == DVD_MINUS) || 4507c478bd9Sstevel@tonic-gate (device_type == DVD_PLUS)) { 4517c478bd9Sstevel@tonic-gate if (!set_reservation(target->d_fd, 4527c478bd9Sstevel@tonic-gate total_nblks + 1)) { 4537c478bd9Sstevel@tonic-gate (void) printf(gettext( 4547c478bd9Sstevel@tonic-gate "Setting reservation failed\n")); 4557c478bd9Sstevel@tonic-gate exit(1); 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate write_next_track(audio_cd ? TRACK_MODE_AUDIO : TRACK_MODE_DATA, 4617c478bd9Sstevel@tonic-gate tlist[i].h); 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate /* 4647c478bd9Sstevel@tonic-gate * Running in simulation mode and writing several tracks is 4657c478bd9Sstevel@tonic-gate * useless so bail after the first track is done. 4667c478bd9Sstevel@tonic-gate */ 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate if (simulation && (end_tno != 1)) { 4697c478bd9Sstevel@tonic-gate (void) printf(gettext( 4707c478bd9Sstevel@tonic-gate "Simulation mode : skipping remaining tracks\n")); 4717c478bd9Sstevel@tonic-gate break; 4727c478bd9Sstevel@tonic-gate } 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate write_fini(); 4767c478bd9Sstevel@tonic-gate /* close the temp file handles */ 4777c478bd9Sstevel@tonic-gate for (i = 0; i < end_tno; i++) 4787c478bd9Sstevel@tonic-gate (tlist[i].h)->bstr_close(tlist[i].h); 4797c478bd9Sstevel@tonic-gate free(tlist); 4807c478bd9Sstevel@tonic-gate fini_device(target); 4817c478bd9Sstevel@tonic-gate exit(0); 4827c478bd9Sstevel@tonic-gate } 483