1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <libintl.h>
#include <unistd.h>
#include "msgs.h"
#include "mmc.h"
#include "util.h"
#include "transport.h"
#include "main.h"
#include "misc_scsi.h"
/*
* This is called recursively once, if an ALL blank succeeds but the
* media is not blank we call blank() again to perform a fast blank.
* This is a workaround for some drives such as older Toshiba DVD-RW
* which has this problem with ALL blanking.
*/
void
blank(void)
{
int type, invalid;
int count, ret;
uchar_t *di, *buf;
int immediate, err;
int silent_pass = 0;
/*
* silent_pass is set to 1 whenever we do not want to print
* information messages. This is the case where blank() function
* is called within the blank() function or the blank() function
* is called from other functions within cdrw to blank the media
* as part of other operations (clearing ghost TOC, closing the media
* after a write operation, etc). In all those cases we need not print
* or duplicate information messages. We should also return from the
* blank() function to the calling function in those cases.
*/
int ignore_error = 0;
/*
* ignore_error is set to 1 whenever we do not want to report any
* error messages to the user and make things transparent to the
* user (For eg: Clearing ghost TOC during write simulation).
*/
invalid = 0;
err = 0;
(void) check_device(target, CHECK_TYPE_NOT_CDROM | CHECK_NO_MEDIA |
EXIT_IF_CHECK_FAILED);
(void) check_device(target, CHECK_DEVICE_NOT_READY |
CHECK_DEVICE_NOT_WRITABLE | EXIT_IF_CHECK_FAILED);
if (blanking_type == NULL) {
invalid = 1;
}
get_media_type(target->d_fd);
if (strcmp(blanking_type, "all") == 0) {
/* erase the whole disk */
type = ALL;
} else if (strcmp(blanking_type, "session") == 0) {
/* only erase the last session */
type = SESSION;
} else if (strcmp(blanking_type, "fast") == 0) {
/* quick blank the TOC on the media */
type = FAST;
} else if (strcmp(blanking_type, "leadout") == 0) {
/* erase the track tail to unclose the media */
type = LEADOUT;
silent_pass = 1;
} else if (strcmp(blanking_type, "clear") == 0) {
/*
* used for drives where "all" blanking fails,
* if it fails we follow up with a quick erase of TOC.
* This is only called from within this function to do
* a second blanking pass.
*/
type = CLEAR;
silent_pass = 1;
} else if (strcmp(blanking_type, "clear_ghost") == 0) {
/*
* used for drives in simulation mode to blank ghost
* TOC after simulation write is complete.
*/
type = CLEAR;
silent_pass = 1;
ignore_error = 1;
} else {
/* invalid blank type was passed on the command line */
invalid = 1;
}
if (invalid) {
err_msg(gettext("Invalid blanking type specified\n"));
exit(1);
}
/*
* many DVD+RW drives do not allow blanking the media, it is also
* not included in the spec, we would just reformat the media prior
* to writing. This is not the equivelent to blanking as the media
* contains a TOC when formatted.
*/
if (device_type == DVD_PLUS_W) {
if (ignore_error)
return;
err_msg(gettext("Blanking cannot be done on DVD+RW media\n"));
exit(1);
}
if ((target->d_inq[2] & 7) != 0) {
/* SCSI device */
immediate = 0;
} else {
/* non-SCSI (e.g ATAPI) device */
immediate = 1;
}
/* we are doing a second pass. We don't want to re-print messsages */
if (!silent_pass)
print_n_flush(gettext("Initializing device..."));
/* Make sure that test write is off */
buf = (uchar_t *)my_zalloc(64);
/* get mode page for test writing if it fails we cannot turn it off */
if (!get_mode_page(target->d_fd, 5, 0, 64, buf)) {
if (ignore_error)
return;
err_msg(gettext("Device not supported\n"));
exit(1);
}
buf[2] &= 0xef;
/* turn laser on */
if (!set_mode_page(target->d_fd, buf)) {
if (ignore_error)
return;
err_msg(gettext("Unable to configure device\n"));
exit(1);
}
free(buf);
/* we are doing a second pass. We don't want to re-print messsages */
if (!silent_pass) {
/* l10n_NOTE : 'done' as in "Initializing device...done" */
(void) printf(gettext("done.\n"));
print_n_flush(gettext(
"Blanking the media (Can take several minutes)..."));
}
if (!blank_disc(target->d_fd, type, immediate)) {
if (ignore_error)
return;
err_msg(gettext("Blank command failed\n"));
if (debug)
(void) printf("%x %x %x %x\n", uscsi_status,
SENSE_KEY(rqbuf), ASC(rqbuf), ASCQ(rqbuf));
goto blank_failed;
}
/* Allow the blanking to start */
(void) sleep(10);
/*
* set ATAPI devices to immediately return from the command and poll
* so that we don't hog the channel.
*/
if (immediate) {
di = (uchar_t *)my_zalloc(DISC_INFO_BLOCK_SIZE);
/* Blanking should not take more than 75 minutes */
for (count = 0; count < (16*60); count++) {
ret = read_disc_info(target->d_fd, di);
if (ret != 0)
break;
if (uscsi_status != 2)
err = 1;
/* not ready but not becoming ready */
if (SENSE_KEY(rqbuf) == 2) {
if (ASC(rqbuf) != 4)
err = 1;
/* illegal mode for this track */
} else if (SENSE_KEY(rqbuf) == 5) {
if (ASC(rqbuf) != 0x64)
err = 1;
} else {
err = 1;
}
if (err == 1) {
if (ignore_error)
break;
err_msg(gettext("Blanking operation failed\n"));
if (debug) {
(void) printf("%x %x %x %x\n",
uscsi_status, SENSE_KEY(rqbuf),
ASC(rqbuf), ASCQ(rqbuf));
}
free(di);
goto blank_failed;
}
(void) sleep(5);
}
free(di);
if (count == (16*60)) {
if (!silent_pass) {
(void) printf(gettext(
"Blank command timed out.\n"));
}
goto blank_failed;
}
}
/* we are doing a second pass. We don't want to re-print messsages */
if (!silent_pass) {
/* l10n_NOTE : 'done' as in "Erasing track 1...done" */
(void) printf(gettext("done.\n"));
}
/*
* some cruft left from all blanking, this has been seen on some
* newer drives including Toshiba SD-6112 DVD-RW and Sony 510A.
* we will do a second pass with a recursive call to blank the
* lead-in.
*/
if (type == ALL) {
if (check_device(target, CHECK_MEDIA_IS_NOT_BLANK)) {
blanking_type = "clear";
blank();
if (silent_pass)
return;
exit(0);
}
}
/*
* We erased part of the leadout for the media to unclose
* the disk, we still need to generate an appendable leadout
* so that the next track can be written. so do not eject or exit.
*/
if (silent_pass)
return;
if (vol_running)
(void) eject_media(target);
exit(0);
blank_failed:
if ((type != ALL) && !silent_pass) {
(void) printf("Try using blanking type 'all'\n");
}
if (silent_pass)
return;
if (vol_running)
(void) eject_media(target);
exit(1);
}
|