4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/types.h>
36 #include "misc_scsi.h"
40 #include "transport.h"
49 get_media_type(target
->d_fd
);
51 /* DVD+RW does not have blanking and can be overwritten */
52 if (device_type
!= DVD_PLUS_W
) {
53 (void) check_device(target
, CHECK_DEVICE_NOT_READY
|
54 CHECK_DEVICE_NOT_WRITABLE
| CHECK_MEDIA_IS_NOT_WRITABLE
|
55 EXIT_IF_CHECK_FAILED
);
57 (void) check_device(target
, CHECK_DEVICE_NOT_READY
|
58 EXIT_IF_CHECK_FAILED
);
62 * Simulation writing can't happen on DVD+RW's
63 * or DVD+R's. According to the MMC spec this
64 * operation is not supported. So we should
65 * bail out if the user tries to do a simulation
68 if (simulation
&& (device_type
== DVD_PLUS_W
||
69 device_type
== DVD_PLUS
)) {
70 err_msg(gettext("Media does not support simulated writing.\n"));
74 write_init(TRACK_MODE_DATA
);
77 h
= open_iso_read_stream(image_file
);
79 h
= open_stdin_read_stream();
83 err_msg(gettext("Cannot open %s: %s\n"),
84 image_file
? image_file
: "stdin", get_err_str());
88 ret
= h
->bstr_size(h
, &size
);
90 if ((str_errno
== STR_ERR_NO_REG_FILE
)) {
93 err_msg(gettext("Cannot stat input file: %s\n"),
98 if ((no_size
== 0) && (size
== 0)) {
99 err_msg(gettext("Input size(0) not valid\n"));
104 struct track_info
*ti
;
107 ti
= (struct track_info
*)my_zalloc(sizeof (*ti
));
108 if (write_mode
== TAO_MODE
)
109 if (!build_track_info(target
, -1, ti
)) {
111 gettext("Unable to find out writable "
115 if (device_type
== CD_RW
) {
116 if ((cap
= get_last_possible_lba(target
)) <= 0) {
117 if ((cap
= read_format_capacity(target
->d_fd
,
119 err_msg(gettext("Unable to determine "
120 "media capacity. Defaulting to "
121 "650 MB (74 minute) disc.\n"));
127 * For DVD drives use read_format_capacity to
128 * find media size, it can be 3.6, 3.9, 4.2,
131 cap
= read_format_capacity(target
->d_fd
,
134 * Sanity check; Default to 4.7 GB if cap unreasonable
136 if (cap
< MAX_CD_BLKS
)
140 if (device_type
== CD_RW
)
141 cap
= (cap
+ 1 - ti
->ti_start_address
) * 2048;
146 err_msg(gettext("Size required (%lld bytes) is greater "
147 "than available space (%lld bytes).\n"), size
, cap
);
151 if (device_type
== DVD_MINUS
) {
152 (void) printf(gettext("Preparing to write DVD\n"));
154 /* streamed file, we dont know the size to reserve */
159 /* DAO requires that we reserve the size to write */
162 "DAO_MODE:reserving track size of = 0x%x\n",
163 (uint32_t)(size
/2048));
165 if (!set_reservation(target
->d_fd
, size
/2048)) {
166 (void) printf(gettext(
167 "Setting reservation failed\n"));
170 } else if (device_type
== DVD_PLUS_W
) {
172 * DVD+RW requires that we format the media before
175 (void) print_n_flush(gettext("Formatting media..."));
176 if (!format_media(target
->d_fd
)) {
177 (void) printf(gettext(
178 "Could not format media\n"));
184 /* poll until format is done */
185 di
= (uchar_t
*)my_zalloc(DISC_INFO_BLOCK_SIZE
);
187 for (counter
= 0; counter
< 200; counter
++) {
189 ret
= read_disc_info(target
->d_fd
, di
);
191 if ((SENSE_KEY(rqbuf
) == 2) &&
193 (void) print_n_flush(".");
201 (void) printf(gettext("done\n"));
208 write_next_track(TRACK_MODE_DATA
, h
);