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*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 <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 { 1374d218355Szk194757 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 143*4df0f9a3Sec158148 if (device_type == CD_RW) { 1447c478bd9Sstevel@tonic-gate nblks_avail = get_last_possible_lba(target); 1457c478bd9Sstevel@tonic-gate 1464d218355Szk194757 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 152*4df0f9a3Sec158148 /* if both methods fail, fall back on defaults */ 1534d218355Szk194757 if (nblks_avail == 0) { 154*4df0f9a3Sec158148 err_msg(gettext("Unable to determine media " 155*4df0f9a3Sec158148 "capacity. Defaulting to 650 MB (74 minute)" 156*4df0f9a3Sec158148 " disc.\n")); 157*4df0f9a3Sec158148 nblks_avail = MAX_CD_BLKS; 1587c478bd9Sstevel@tonic-gate } 1594077f1edSminht leadin_size = end_tno*300; 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate } else { 1627c478bd9Sstevel@tonic-gate /* 1637c478bd9Sstevel@tonic-gate * For DVD drives use read_format_capacity as default 1647c478bd9Sstevel@tonic-gate * retrieve the media size, it can be 3.6, 3.9, 4.2, 1657c478bd9Sstevel@tonic-gate * 4.7, or 9.2 GB 1667c478bd9Sstevel@tonic-gate */ 167*4df0f9a3Sec158148 nblks_avail = read_format_capacity(target->d_fd, &bsize); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate /* sanity check. if not reasonable default to 4.7 GB */ 1707c478bd9Sstevel@tonic-gate if (nblks_avail < MAX_CD_BLKS) { 1717c478bd9Sstevel@tonic-gate nblks_avail = MAX_DVD_BLKS; 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate 1754077f1edSminht if ((total_nblks + leadin_size) > nblks_avail) { 1767c478bd9Sstevel@tonic-gate err_msg(gettext("Not enough space on the media.\n")); 1777c478bd9Sstevel@tonic-gate if (debug) { 1787c478bd9Sstevel@tonic-gate (void) printf("Need %u only found %u \n", 1794077f1edSminht (total_nblks + leadin_size), 1807c478bd9Sstevel@tonic-gate (uint32_t)nblks_avail); 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate exit(1); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate /* 1887c478bd9Sstevel@tonic-gate * This copies both audio and data CDs. It first reads the TOC of the source CD 1897c478bd9Sstevel@tonic-gate * and creates a temp file with the CD image. After this is completed it creates 1907c478bd9Sstevel@tonic-gate * the target CD using TAO mode. 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate void 1937c478bd9Sstevel@tonic-gate copy_cd(void) 1947c478bd9Sstevel@tonic-gate { 1957c478bd9Sstevel@tonic-gate cd_device *src; 1967c478bd9Sstevel@tonic-gate char *p; 1977c478bd9Sstevel@tonic-gate uchar_t *toc, end_tno; 1987c478bd9Sstevel@tonic-gate int blksize, i; 1997c478bd9Sstevel@tonic-gate int audio_cd, data_cd; 2007c478bd9Sstevel@tonic-gate uint32_t total_nblks; 2017c478bd9Sstevel@tonic-gate int ret; 2027c478bd9Sstevel@tonic-gate struct t_data *tlist; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate print_n_flush(gettext("Analyzing source CD...")); 2057c478bd9Sstevel@tonic-gate (void) check_device(target, 2067c478bd9Sstevel@tonic-gate CHECK_DEVICE_NOT_WRITABLE|EXIT_IF_CHECK_FAILED); 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* if source drive is specified on the command line */ 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate if (copy_src) { 2117c478bd9Sstevel@tonic-gate p = my_zalloc(PATH_MAX); 2127c478bd9Sstevel@tonic-gate if (lookup_device(copy_src, p) == 0) { 2137c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot find device %s"), copy_src); 2147c478bd9Sstevel@tonic-gate err_msg(gettext(" or no media in the drive\n")); 2157c478bd9Sstevel@tonic-gate exit(1); 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate src = get_device(copy_src, p); 2187c478bd9Sstevel@tonic-gate if (src == NULL) { 2197c478bd9Sstevel@tonic-gate err_msg(gettext("Unable to open %s\n"), copy_src); 2207c478bd9Sstevel@tonic-gate exit(1); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate free(p); 2237c478bd9Sstevel@tonic-gate } else { 2247c478bd9Sstevel@tonic-gate /* source is same as target drive */ 2257c478bd9Sstevel@tonic-gate src = target; 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate (void) check_device(src, CHECK_TYPE_NOT_CDROM | CHECK_NO_MEDIA | 2297c478bd9Sstevel@tonic-gate CHECK_DEVICE_NOT_READY | EXIT_IF_CHECK_FAILED); 2307c478bd9Sstevel@tonic-gate 23154cafc85Szk194757 /* What type of media are we working with? */ 23254cafc85Szk194757 get_media_type(src->d_fd); 23354cafc85Szk194757 2347c478bd9Sstevel@tonic-gate toc = (uchar_t *)my_zalloc(4); 2357c478bd9Sstevel@tonic-gate if (!read_toc(src->d_fd, 0, 0, 4, toc)) { 2367c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot read table of contents\n")); 2377c478bd9Sstevel@tonic-gate exit(1); 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate end_tno = toc[3]; 2407c478bd9Sstevel@tonic-gate free(toc); 2417c478bd9Sstevel@tonic-gate tlist = (struct t_data *)my_zalloc(end_tno * sizeof (struct t_data)); 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate audio_cd = data_cd = 0; 2447c478bd9Sstevel@tonic-gate total_nblks = 0; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* build track information so we can copy it over */ 2477c478bd9Sstevel@tonic-gate for (i = 1; i <= end_tno; i++) { 2487c478bd9Sstevel@tonic-gate struct track_info *ti; 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate ti = &tlist[i - 1].ti; 2517c478bd9Sstevel@tonic-gate if (!build_track_info(src, i, ti)) { 2527c478bd9Sstevel@tonic-gate err_msg(gettext( 2537c478bd9Sstevel@tonic-gate "Cannot get information for track %d\n"), i); 2547c478bd9Sstevel@tonic-gate exit(1); 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate total_nblks += ti->ti_track_size; 2577c478bd9Sstevel@tonic-gate if (ti->ti_track_mode & 4) 2587c478bd9Sstevel@tonic-gate data_cd = 1; 2597c478bd9Sstevel@tonic-gate else 2607c478bd9Sstevel@tonic-gate audio_cd = 1; 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate /* Now some sanity checks on the track information */ 2637c478bd9Sstevel@tonic-gate if ((ti->ti_flags & TI_SESSION_NO_VALID) && 2647c478bd9Sstevel@tonic-gate (ti->ti_session_no != 1)) { 2657c478bd9Sstevel@tonic-gate err_msg( 2667c478bd9Sstevel@tonic-gate gettext("Copying multisession CD is not supported\n")); 2677c478bd9Sstevel@tonic-gate exit(1); 2687c478bd9Sstevel@tonic-gate } 2694077f1edSminht if ((ti->ti_flags & TI_BLANK_TRACK) || 2707c478bd9Sstevel@tonic-gate (ti->ti_flags & TI_DAMAGED_TRACK) || 2717c478bd9Sstevel@tonic-gate (data_cd && audio_cd) || (ti->ti_data_mode == 2)) { 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate err_msg(gettext("CD format is not supported\n")); 2747c478bd9Sstevel@tonic-gate exit(1); 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate if ((ti->ti_flags & TI_NWA_VALID) && 2777c478bd9Sstevel@tonic-gate (ti->ti_nwa != 0xffffffff)) { 2787c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot copy incomplete discs\n")); 2797c478bd9Sstevel@tonic-gate exit(1); 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate /* l10n_NOTE : 'done' as in "Analyzing source CD...done" */ 2837c478bd9Sstevel@tonic-gate (void) printf(gettext("done.\n")); 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate if (data_cd) { 2867c478bd9Sstevel@tonic-gate blksize = 2048; 2877c478bd9Sstevel@tonic-gate } else { 2887c478bd9Sstevel@tonic-gate /* audio cd */ 2897c478bd9Sstevel@tonic-gate blksize = 2352; 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate /* In case of audio CDs, build_track_info() returns 2352 sized nblks */ 2937c478bd9Sstevel@tonic-gate if (src->d_blksize == 512 && data_cd) { 2947c478bd9Sstevel@tonic-gate total_nblks /= 4; 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate (void) printf(gettext("\nCopying %d %s track%s : %ld kbytes\n\n"), 2977c478bd9Sstevel@tonic-gate end_tno, (audio_cd == 1) ? gettext("audio") : gettext("data"), 2987c478bd9Sstevel@tonic-gate (end_tno > 1) ? "s" : "", (long)((total_nblks*blksize)/1024)); 2997c478bd9Sstevel@tonic-gate 300416baccdSec158148 if ((ret = check_avail_temp_space(total_nblks*blksize)) != 0) { 301416baccdSec158148 err_msg(gettext("Cannot use temporary directory : %s\n"), 302416baccdSec158148 strerror(ret)); 303416baccdSec158148 err_msg(gettext("Use -m to specify alternate" 304416baccdSec158148 " temporary directory\n")); 3057c478bd9Sstevel@tonic-gate exit(1); 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate /* 3097c478bd9Sstevel@tonic-gate * If we can check available space on the target media at this 3107c478bd9Sstevel@tonic-gate * Stage, then it is always better. We cannot check DVD+R(W) 3117c478bd9Sstevel@tonic-gate * as this media may be formatted and not blank. 3127c478bd9Sstevel@tonic-gate */ 3137c478bd9Sstevel@tonic-gate if (target && (src != target) && (device_type != DVD_PLUS) && 3147c478bd9Sstevel@tonic-gate (device_type != DVD_PLUS_W) && (!check_device(target, 3157c478bd9Sstevel@tonic-gate CHECK_NO_MEDIA|CHECK_MEDIA_IS_NOT_BLANK))) { 3167c478bd9Sstevel@tonic-gate ensure_media_space(total_nblks, end_tno); 3177c478bd9Sstevel@tonic-gate } 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate /* for each track */ 3207c478bd9Sstevel@tonic-gate for (i = 1; i <= end_tno; i++) { 3217c478bd9Sstevel@tonic-gate tlist[i - 1].h = open_temp_file_stream(); 3227c478bd9Sstevel@tonic-gate if (tlist[i - 1].h == NULL) { 3237c478bd9Sstevel@tonic-gate err_msg(gettext("Cannot create temporary file : %s\n"), 3247c478bd9Sstevel@tonic-gate get_err_str()); 3257c478bd9Sstevel@tonic-gate exit(1); 3267c478bd9Sstevel@tonic-gate } 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate if (audio_cd) 3297c478bd9Sstevel@tonic-gate ret = read_audio_track(src, &tlist[i - 1].ti, 3307c478bd9Sstevel@tonic-gate tlist[i - 1].h); 3317c478bd9Sstevel@tonic-gate else 3327c478bd9Sstevel@tonic-gate ret = read_data_track(src, &tlist[i - 1].ti, 3337c478bd9Sstevel@tonic-gate tlist[i - 1].h); 3347c478bd9Sstevel@tonic-gate if (ret == 0) { 3357c478bd9Sstevel@tonic-gate err_msg(gettext("Error reading track %d : %s\n"), i, 3367c478bd9Sstevel@tonic-gate get_err_str()); 3377c478bd9Sstevel@tonic-gate if (debug) 3387c478bd9Sstevel@tonic-gate (void) printf("%x %x %x %x\n", uscsi_status, 3397c478bd9Sstevel@tonic-gate SENSE_KEY(rqbuf), ASC(rqbuf), ASCQ(rqbuf)); 3407c478bd9Sstevel@tonic-gate exit(1); 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate } 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate /* 3457c478bd9Sstevel@tonic-gate * We've finished copying the CD. If source and destination are the same 3467c478bd9Sstevel@tonic-gate * or they where not specified then eject the disk and wait for a new 3477c478bd9Sstevel@tonic-gate * disk to be inserted. 34854cafc85Szk194757 * 34954cafc85Szk194757 * Since, DVD+RWs are not blanked just reformated, allow the insertion 35054cafc85Szk194757 * of a DVD+RW to be the only condition necessary to complete copying. 3517c478bd9Sstevel@tonic-gate */ 3527c478bd9Sstevel@tonic-gate 35354cafc85Szk194757 do { 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); 36954cafc85Szk194757 if (target) 37054cafc85Szk194757 get_media_type(target->d_fd); 37154cafc85Szk194757 } while ((target == NULL) || 37254cafc85Szk194757 ((device_type == DVD_PLUS_W)? check_device(target, CHECK_NO_MEDIA): 37354cafc85Szk194757 check_device(target, CHECK_NO_MEDIA|CHECK_MEDIA_IS_NOT_BLANK))); 37454cafc85Szk194757 3757c478bd9Sstevel@tonic-gate (void) printf("\n"); 3767c478bd9Sstevel@tonic-gate (void) setreuid(ruid, 0); 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate if ((device_type != DVD_PLUS) && (device_type != DVD_PLUS_W)) { 3797c478bd9Sstevel@tonic-gate ensure_media_space(total_nblks, end_tno); 3807c478bd9Sstevel@tonic-gate write_init(audio_cd ? TRACK_MODE_AUDIO : TRACK_MODE_DATA); 3817c478bd9Sstevel@tonic-gate } 3827c478bd9Sstevel@tonic-gate 3831b01eaa0Szk194757 /* 3841b01eaa0Szk194757 * Simulation writing can't happen on DVD+RW's 3851b01eaa0Szk194757 * or DVD+R's. According to the MMC spec this 3861b01eaa0Szk194757 * operation is not supported. So we should 3871b01eaa0Szk194757 * bail out if the user tries to do a simulation 3881b01eaa0Szk194757 * write. 3891b01eaa0Szk194757 */ 3901b01eaa0Szk194757 if (simulation && (device_type == DVD_PLUS_W || 3911b01eaa0Szk194757 device_type == DVD_PLUS)) { 3921b01eaa0Szk194757 err_msg(gettext("Media does not support simulated writing.\n")); 3931b01eaa0Szk194757 exit(1); 3941b01eaa0Szk194757 } 3951b01eaa0Szk194757 3964077f1edSminht if (device_type == DVD_PLUS_W) { 3974077f1edSminht /* 3984077f1edSminht * DVD+RW requires that we format the media before 3994077f1edSminht * writing. 4004077f1edSminht */ 4014077f1edSminht (void) print_n_flush(gettext("Formatting media...")); 4024077f1edSminht if (!format_media(target->d_fd)) { 4034077f1edSminht (void) printf(gettext( 4044077f1edSminht "Could not format media\n")); 4054077f1edSminht exit(1); 4064077f1edSminht } else { 4074077f1edSminht int counter; 4084077f1edSminht uchar_t *di; 4094077f1edSminht 4104077f1edSminht /* poll until format is done */ 4114077f1edSminht di = (uchar_t *)my_zalloc(DISC_INFO_BLOCK_SIZE); 4124077f1edSminht (void) sleep(10); 4134077f1edSminht for (counter = 0; counter < 200; counter++) { 4144077f1edSminht ret = read_disc_info(target->d_fd, di); 4154077f1edSminht if ((SENSE_KEY(rqbuf) == 2) && 4164077f1edSminht (ASC(rqbuf) == 4)) { 4174077f1edSminht (void) print_n_flush("."); 4184077f1edSminht (void) sleep(5); 4194077f1edSminht } else { 4204077f1edSminht break; 4214077f1edSminht } 4224077f1edSminht } 4234077f1edSminht } 4244077f1edSminht } 4254077f1edSminht 4267c478bd9Sstevel@tonic-gate /* for each track */ 4277c478bd9Sstevel@tonic-gate for (i = 0; i < end_tno; i++) { 4287c478bd9Sstevel@tonic-gate /* 4297c478bd9Sstevel@tonic-gate * DVD's dont contain tracks and need to be written in DAO 4307c478bd9Sstevel@tonic-gate * mode. 4317c478bd9Sstevel@tonic-gate */ 4327c478bd9Sstevel@tonic-gate if (device_type != CD_RW) { 4337c478bd9Sstevel@tonic-gate if (end_tno > 1) { 4347c478bd9Sstevel@tonic-gate err_msg(gettext( 4357c478bd9Sstevel@tonic-gate "Media state is not suitable for this" 4367c478bd9Sstevel@tonic-gate " write mode.\n")); 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate write_mode = DAO_MODE; 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate /* 4417c478bd9Sstevel@tonic-gate * DVD-R(W) and DVD+R needs to have space reserved 4427c478bd9Sstevel@tonic-gate * prior to writing. 4437c478bd9Sstevel@tonic-gate */ 4447c478bd9Sstevel@tonic-gate if ((device_type == DVD_MINUS) || 4457c478bd9Sstevel@tonic-gate (device_type == DVD_PLUS)) { 4467c478bd9Sstevel@tonic-gate if (!set_reservation(target->d_fd, 4477c478bd9Sstevel@tonic-gate total_nblks + 1)) { 4487c478bd9Sstevel@tonic-gate (void) printf(gettext( 4497c478bd9Sstevel@tonic-gate "Setting reservation failed\n")); 4507c478bd9Sstevel@tonic-gate exit(1); 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate } 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate write_next_track(audio_cd ? TRACK_MODE_AUDIO : TRACK_MODE_DATA, 4567c478bd9Sstevel@tonic-gate tlist[i].h); 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate /* 4597c478bd9Sstevel@tonic-gate * Running in simulation mode and writing several tracks is 4607c478bd9Sstevel@tonic-gate * useless so bail after the first track is done. 4617c478bd9Sstevel@tonic-gate */ 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate if (simulation && (end_tno != 1)) { 4647c478bd9Sstevel@tonic-gate (void) printf(gettext( 4657c478bd9Sstevel@tonic-gate "Simulation mode : skipping remaining tracks\n")); 4667c478bd9Sstevel@tonic-gate break; 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate } 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate write_fini(); 4717c478bd9Sstevel@tonic-gate /* close the temp file handles */ 4727c478bd9Sstevel@tonic-gate for (i = 0; i < end_tno; i++) 4737c478bd9Sstevel@tonic-gate (tlist[i].h)->bstr_close(tlist[i].h); 4747c478bd9Sstevel@tonic-gate free(tlist); 4757c478bd9Sstevel@tonic-gate fini_device(target); 4767c478bd9Sstevel@tonic-gate exit(0); 4777c478bd9Sstevel@tonic-gate } 478