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"
34 #include "misc_scsi.h"
42 open_audio(char *fname
)
47 /* No audio type specified, look at extension */
48 if (audio_type
== AUDIO_TYPE_NONE
) {
49 ext
= (char *)(strrchr(fname
, '.'));
53 if ((ext
== NULL
) || ((at
= get_audio_type(ext
)) == -1)) {
55 "Cannot understand file extension for %s\n"),
62 if (at
== AUDIO_TYPE_SUN
)
63 return (open_au_read_stream(fname
));
64 if (at
== AUDIO_TYPE_WAV
)
65 return (open_wav_read_stream(fname
));
66 if (at
== AUDIO_TYPE_CDA
)
67 return (open_file_read_stream(fname
));
68 if (at
== AUDIO_TYPE_AUR
)
69 return (open_aur_read_stream(fname
));
74 write_audio(char **argv
, int start_argc
, int argc
)
78 struct track_info
*ti
;
79 uint32_t blks_req
, blks_avail
;
82 /* number of tracks to write */
83 nfiles
= argc
- start_argc
;
84 h_ptr
= (bstreamhandle
*)my_zalloc(nfiles
* sizeof (bstreamhandle
));
86 for (i
= 0; i
< nfiles
; i
++) {
87 h_ptr
[i
] = open_audio(argv
[start_argc
+ i
]);
88 if (h_ptr
[i
] == NULL
) {
89 err_msg(gettext("Cannot open %s: %s\n"),
90 argv
[start_argc
+ i
], get_err_str());
93 (void) (h_ptr
[i
])->bstr_size(h_ptr
[i
], &fsize
);
95 /* 2352 bytes per block, 75 blocks per second */
96 blks_req
+= 150 + fsize
/2352; /* 2 sec gap per track */
100 (void) check_device(target
, CHECK_DEVICE_NOT_READY
|
101 CHECK_DEVICE_NOT_WRITABLE
| CHECK_MEDIA_IS_NOT_WRITABLE
|
102 EXIT_IF_CHECK_FAILED
);
104 /* Put the device in track-at-once mode */
105 write_init(TRACK_MODE_AUDIO
);
106 ti
= (struct track_info
*)my_zalloc(sizeof (*ti
));
108 /* Build information for next invisible track, -1 */
109 if ((build_track_info(target
, -1, ti
) == 0) ||
110 ((ti
->ti_flags
& TI_NWA_VALID
) == 0)) {
112 "Cannot get writable address for the media.\n"));
115 if ((blks_avail
= get_last_possible_lba(target
)) == 0) {
116 err_msg(gettext("Unable to determine media capacity. "
117 "Defaulting to 650 MB (74 minute) disc.\n"));
118 blks_avail
= MAX_CD_BLKS
;
120 /* LBA is always one less */
124 * Actual number of blocks available based on nwa (next writable
125 * address) since there may already be information on the disc.
128 blks_avail
-= ti
->ti_nwa
;
129 if (blks_avail
< blks_req
) {
130 err_msg(gettext("Insufficient space on the media.\n"));
133 for (i
= 0; i
< nfiles
; i
++) {
134 write_next_track(TRACK_MODE_AUDIO
, h_ptr
[i
]);
135 if (simulation
&& (nfiles
!= 1)) {
136 (void) printf(gettext(
137 "Simulation mode : skipping remaining tracks\n"));
141 for (i
= 0; i
< nfiles
; i
++)
142 (h_ptr
[i
])->bstr_close(h_ptr
[i
]);