Print this page
6581 cmd/format should be able label virtio BLKDEV drives
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/format/menu_command.c
+++ new/usr/src/cmd/format/menu_command.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright 2012 Milan Jurik. All rights reserved.
24 24 * Copyright 2014 Toomas Soome <tsoome@me.com>
25 25 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
26 + * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
26 27 */
27 28
28 29 /*
29 30 * This file contains functions that implement the command menu commands.
30 31 */
31 32
32 33 #include "global.h"
33 34 #include <time.h>
34 35 #include <sys/time.h>
35 36 #include <sys/resource.h>
36 37 #include <sys/wait.h>
37 38 #include <strings.h>
38 39 #include <signal.h>
39 40 #include <stdlib.h>
40 41 #include <string.h>
41 42
42 43 #if defined(sparc)
43 44 #include <sys/hdio.h>
44 45 #endif /* defined(sparc) */
45 46
46 47 #include "main.h"
47 48 #include "analyze.h"
48 49 #include "menu.h"
49 50 #include "menu_command.h"
50 51 #include "menu_defect.h"
51 52 #include "menu_partition.h"
52 53 #include "param.h"
53 54 #include "misc.h"
54 55 #include "label.h"
55 56 #include "startup.h"
56 57 #include "partition.h"
57 58 #include "prompts.h"
58 59 #include "checkdev.h"
59 60 #include "io.h"
60 61 #include "ctlr_scsi.h"
61 62 #include "auto_sense.h"
62 63 #include "modify_partition.h"
63 64
64 65
65 66 extern struct menu_item menu_partition[];
66 67 extern struct menu_item menu_analyze[];
67 68 extern struct menu_item menu_defect[];
68 69
69 70 /*
70 71 * Choices for the p_tag vtoc field
71 72 */
72 73 slist_t ptag_choices[] = {
73 74 { "unassigned", "", V_UNASSIGNED },
74 75 { "boot", "", V_BOOT },
75 76 { "root", "", V_ROOT },
76 77 { "swap", "", V_SWAP },
77 78 { "usr", "", V_USR },
78 79 { "backup", "", V_BACKUP },
79 80 { "stand", "", V_STAND },
80 81 { "var", "", V_VAR },
81 82 { "home", "", V_HOME },
82 83 { "alternates", "", V_ALTSCTR },
83 84 { "reserved", "", V_RESERVED },
84 85 { "system", "", V_SYSTEM },
85 86 { "BIOS_boot", "", V_BIOS_BOOT },
86 87 { NULL }
87 88 };
88 89
89 90
90 91 /*
91 92 * Choices for the p_flag vtoc field
92 93 */
93 94 slist_t pflag_choices[] = {
94 95 { "wm", "read-write, mountable", 0 },
95 96 { "wu", "read-write, unmountable", V_UNMNT },
96 97 { "rm", "read-only, mountable", V_RONLY },
97 98 { "ru", "read-only, unmountable", V_RONLY|V_UNMNT },
98 99 { NULL }
99 100 };
100 101
101 102
102 103 /*
103 104 * This routine implements the 'disk' command. It allows the user to
104 105 * select a disk to be current. The list of choices is the list of
105 106 * disks that were found at startup time.
106 107 */
107 108 int
108 109 c_disk()
109 110 {
110 111 struct disk_info *disk;
111 112 u_ioparam_t ioparam;
112 113 int i;
113 114 int ndisks = 0;
114 115 int blind_select = 0;
115 116 int deflt;
116 117 int index;
117 118 int *defltptr = NULL;
118 119 int more = 0;
119 120 int more_quit = 0;
120 121 int one_line = 0;
121 122 int tty_lines;
122 123
123 124 /*
124 125 * This buffer holds the check() prompt that verifies we've got the right
125 126 * disk when performing a blind selection. The size should be sufficient
126 127 * to hold the prompt string, plus 256 characters for the disk name -
127 128 * way more than should ever be necessary. See the #define in misc.h.
128 129 */
129 130 char chk_buf[BLIND_SELECT_VER_PROMPT];
130 131
131 132 if (istokenpresent()) {
132 133 /*
133 134 * disk number to be selected is already in the
134 135 * input stream .
135 136 */
136 137 TOKEN token, cleantoken;
137 138
138 139 /*
139 140 * Get the disk number the user has given.
140 141 */
141 142 i = 0;
142 143 for (disk = disk_list; disk != NULL; disk = disk->disk_next) {
143 144 i++;
144 145 }
145 146
146 147 ioparam.io_bounds.lower = 0;
147 148 ioparam.io_bounds.upper = i - 1;
148 149 (void) gettoken(token);
149 150 clean_token(cleantoken, token);
150 151
151 152 /*
152 153 * Convert the token into an integer.
153 154 */
154 155 if (geti(cleantoken, &index, (int *)NULL))
155 156 return (0);
156 157
157 158 /*
158 159 * Check to be sure it is within the legal bounds.
159 160 */
160 161 if ((index < 0) || (index >= i)) {
161 162 err_print("`%d' is out of range.\n", index);
162 163 return (0);
163 164 }
164 165 goto checkdisk;
165 166 }
166 167
167 168 fmt_print("\n\nAVAILABLE DISK SELECTIONS:\n");
168 169
169 170 i = 0;
170 171 if ((option_f == (char *)NULL) && isatty(0) == 1 && isatty(1) == 1) {
171 172 /*
172 173 * We have a real terminal for std input and output, enable
173 174 * more style of output for disk selection list.
174 175 */
175 176 more = 1;
176 177 tty_lines = get_tty_lines();
177 178 enter_critical();
178 179 echo_off();
179 180 charmode_on();
180 181 exit_critical();
181 182 }
182 183
183 184 /*
184 185 * Loop through the list of found disks.
185 186 */
186 187 for (disk = disk_list; disk != NULL; disk = disk->disk_next) {
187 188 /*
188 189 * If using more output, account 2 lines for each disk.
189 190 */
190 191 if (more && !more_quit && i && (one_line ||
191 192 ((2 * i + 1) % (tty_lines - 2) <= 1))) {
192 193 int c;
193 194
194 195 /*
195 196 * Get the next character.
196 197 */
197 198 fmt_print("- hit space for more or s to select - ");
198 199 c = getchar();
199 200 fmt_print("\015");
200 201 one_line = 0;
201 202 /*
202 203 * Handle display one line command
203 204 * (return key)
204 205 */
205 206 if (c == '\012') {
206 207 one_line++;
207 208 }
208 209 /* Handle Quit command */
209 210 if (c == 'q') {
210 211 fmt_print(
211 212 " \015");
212 213 more_quit++;
213 214 }
214 215 /* Handle ^D command */
215 216 if (c == '\004')
216 217 fullabort();
217 218 /* or get on with the show */
218 219 if (c == 's' || c == 'S') {
219 220 fmt_print("%80s\n", " ");
220 221 break;
221 222 }
222 223 }
223 224 /*
224 225 * If this is the current disk, mark it as
225 226 * the default.
226 227 */
227 228 if (cur_disk == disk) {
228 229 deflt = i;
229 230 defltptr = &deflt;
230 231 }
231 232 if (!more || !more_quit)
232 233 pr_diskline(disk, i);
233 234 i++;
234 235 }
235 236 if (more) {
236 237 enter_critical();
237 238 charmode_off();
238 239 echo_on();
239 240 exit_critical();
240 241 }
241 242
242 243 /*
243 244 * Determine total number of disks, and ask the user which disk he
244 245 * would like to make current.
245 246 */
246 247
247 248 for (disk = disk_list; disk != NULL; disk = disk->disk_next) {
248 249 ndisks++;
249 250 }
250 251
251 252 ioparam.io_bounds.lower = 0;
252 253 ioparam.io_bounds.upper = ndisks - 1;
253 254 index = input(FIO_INT, "Specify disk (enter its number)", ':',
254 255 &ioparam, defltptr, DATA_INPUT);
255 256
256 257 if (index >= i) {
257 258 blind_select = 1;
258 259 }
259 260
260 261 /*
261 262 * Find the disk chosen. Search through controllers/disks
262 263 * in the same original order, so we match what the user
263 264 * chose.
264 265 */
265 266 checkdisk:
266 267 i = 0;
267 268 for (disk = disk_list; disk != NULL; disk = disk->disk_next) {
268 269 if (i == index)
269 270 goto found;
270 271 i++;
271 272 }
272 273 /*
273 274 * Should never happen.
274 275 */
275 276 impossible("no disk found");
276 277
277 278 found:
278 279 if (blind_select) {
279 280 (void) snprintf(chk_buf, sizeof (chk_buf),
280 281 "Disk %s selected - is this the desired disk? ", disk->disk_name);
281 282 if (check(chk_buf)) {
282 283 return (-1);
283 284 }
284 285 }
285 286
286 287 /*
287 288 * Update the state. We lock out interrupts so the state can't
288 289 * get half-updated.
289 290 */
290 291
291 292 enter_critical();
292 293 init_globals(disk);
293 294 exit_critical();
294 295
295 296 /*
296 297 * If type unknown and interactive, ask user to specify type.
297 298 * Also, set partition table (best guess) too.
298 299 */
299 300 if (!option_f && ncyl == 0 && nhead == 0 && nsect == 0 &&
300 301 (disk->label_type != L_TYPE_EFI)) {
301 302 (void) c_type();
302 303 }
303 304
304 305 /*
305 306 * Get the Solaris Fdisk Partition information
306 307 */
307 308 if (nhead != 0 && nsect != 0)
308 309 (void) copy_solaris_part(&cur_disk->fdisk_part);
309 310
310 311 if ((cur_disk->label_type == L_TYPE_EFI) &&
311 312 (cur_disk->disk_parts->etoc->efi_flags &
312 313 EFI_GPT_PRIMARY_CORRUPT)) {
313 314 err_print("Reading the primary EFI GPT label ");
314 315 err_print("failed. Using backup label.\n");
315 316 err_print("Use the 'backup' command to restore ");
316 317 err_print("the primary label.\n");
317 318 }
318 319
319 320 #if defined(_SUNOS_VTOC_16)
320 321 /*
321 322 * If there is no fdisk solaris partition.
322 323 */
323 324 if (cur_disk->fdisk_part.numsect == 0) {
324 325 err_print("No Solaris fdisk partition found.\n");
325 326 goto exit;
326 327 }
327 328 #endif /* defined(_SUNOS_VTOC_16) */
328 329
329 330 /*
330 331 * If the label of the disk is marked dirty,
331 332 * see if they'd like to label the disk now.
332 333 */
333 334 if (cur_disk->disk_flags & DSK_LABEL_DIRTY) {
334 335 if (check("Disk not labeled. Label it now") == 0) {
335 336 if (write_label()) {
336 337 err_print("Write label failed\n");
337 338 } else {
338 339 cur_disk->disk_flags &= ~DSK_LABEL_DIRTY;
339 340 }
340 341 }
341 342 }
342 343 exit:
343 344 return (0);
344 345 }
345 346
346 347 /*
347 348 * This routine implements the 'type' command. It allows the user to
348 349 * specify the type of the current disk. It should be necessary only
349 350 * if the disk was not labelled or was somehow labelled incorrectly.
350 351 * The list of legal types for the disk comes from information that was
351 352 * in the data file.
352 353 */
353 354 int
354 355 c_type()
355 356 {
356 357 struct disk_type *type, *tptr, *oldtype;
357 358 u_ioparam_t ioparam;
358 359 int i, index, deflt, *defltptr = NULL;
359 360 struct disk_type disk_type;
360 361 struct disk_type *d = &disk_type;
361 362 int first_disk;
362 363 int auto_conf_choice;
363 364 int other_choice;
364 365 struct dk_label label;
365 366 struct efi_info efi_info;
366 367 uint64_t maxLBA;
367 368 char volname[LEN_DKL_VVOL];
368 369 int volinit = 0;
369 370
370 371 /*
371 372 * There must be a current disk.
372 373 */
373 374 if (cur_disk == NULL) {
374 375 err_print("Current Disk is not set.\n");
375 376 return (-1);
376 377 }
377 378 oldtype = cur_disk->disk_type;
378 379 type = cur_ctype->ctype_dlist;
379 380 /*
380 381 * Print out the list of choices.
381 382 */
382 383 fmt_print("\n\nAVAILABLE DRIVE TYPES:\n");
383 384 first_disk = 0;
384 385 if (cur_ctype->ctype_ctype == DKC_SCSI_CCS) {
385 386 auto_conf_choice = 0;
386 387 fmt_print(" %d. Auto configure\n", first_disk++);
387 388 } else {
388 389 auto_conf_choice = -1;
389 390 }
390 391
391 392 i = first_disk;
392 393 for (tptr = type; tptr != NULL; tptr = tptr->dtype_next) {
393 394 /*
394 395 * If we pass the current type, mark it to be the default.
395 396 */
396 397 if (cur_dtype == tptr) {
397 398 deflt = i;
398 399 defltptr = &deflt;
399 400 }
400 401 if (cur_disk->label_type == L_TYPE_EFI) {
401 402 continue;
402 403 }
403 404 if (tptr->dtype_asciilabel)
404 405 fmt_print(" %d. %s\n", i++,
405 406 tptr->dtype_asciilabel);
406 407 }
407 408 other_choice = i;
408 409 fmt_print(" %d. other\n", i);
409 410 ioparam.io_bounds.lower = 0;
410 411 ioparam.io_bounds.upper = i;
411 412 /*
412 413 * Ask the user which type the disk is.
413 414 */
414 415 index = input(FIO_INT, "Specify disk type (enter its number)", ':',
415 416 &ioparam, defltptr, DATA_INPUT);
416 417 /*
417 418 * Find the type s/he chose.
418 419 */
419 420 if (index == auto_conf_choice) {
420 421 float scaled;
421 422 diskaddr_t nblks;
422 423 int nparts;
423 424
424 425 /*
425 426 * User chose "auto configure".
426 427 */
427 428 (void) strcpy(x86_devname, cur_disk->disk_name);
428 429 switch (cur_disk->label_type) {
429 430 case L_TYPE_SOLARIS:
430 431 if ((tptr = auto_sense(cur_file, 1, &label)) == NULL) {
431 432 err_print("Auto configure failed\n");
432 433 return (-1);
433 434 }
434 435 fmt_print("%s: configured with capacity of ",
435 436 cur_disk->disk_name);
436 437 nblks = (diskaddr_t)tptr->dtype_ncyl *
437 438 tptr->dtype_nhead * tptr->dtype_nsect;
438 439 scaled = bn2mb(nblks);
439 440 if (scaled > 1024.0) {
440 441 fmt_print("%1.2fGB\n", scaled/1024.0);
441 442 } else {
442 443 fmt_print("%1.2fMB\n", scaled);
443 444 }
444 445 fmt_print("<%s cyl %d alt %d hd %d sec %d>\n",
445 446 tptr->dtype_asciilabel, tptr->dtype_ncyl,
446 447 tptr->dtype_acyl, tptr->dtype_nhead,
447 448 tptr->dtype_nsect);
448 449 break;
449 450 case L_TYPE_EFI:
450 451 if ((tptr = auto_efi_sense(cur_file, &efi_info))
451 452 == NULL) {
452 453 err_print("Auto configure failed\n");
453 454 return (-1);
454 455 }
455 456 fmt_print("%s: configured with capacity of ",
456 457 cur_disk->disk_name);
457 458 scaled = bn2mb(efi_info.capacity);
458 459 if (scaled > 1024.0) {
459 460 fmt_print("%1.2fGB\n", scaled/1024.0);
460 461 } else {
461 462 fmt_print("%1.2fMB\n", scaled);
462 463 }
463 464 cur_blksz = efi_info.e_parts->efi_lbasize;
464 465 print_efi_string(efi_info.vendor, efi_info.product,
465 466 efi_info.revision, efi_info.capacity);
466 467 fmt_print("\n");
467 468 for (nparts = 0; nparts < cur_parts->etoc->efi_nparts;
468 469 nparts++) {
469 470 if (cur_parts->etoc->efi_parts[nparts].p_tag ==
470 471 V_RESERVED) {
471 472 if (cur_parts->etoc->efi_parts[nparts].
472 473 p_name) {
473 474 (void) strcpy(volname,
474 475 cur_parts->etoc->efi_parts
475 476 [nparts].p_name);
476 477 volinit = 1;
477 478 }
478 479 break;
479 480 }
480 481 }
481 482 enter_critical();
482 483 if (delete_disk_type(cur_disk->disk_type) != 0) {
483 484 fmt_print("Autoconfiguration failed.\n");
484 485 return (-1);
485 486 }
486 487 cur_disk->disk_type = tptr;
487 488 cur_disk->disk_parts = tptr->dtype_plist;
488 489 init_globals(cur_disk);
489 490 exit_critical();
490 491 if (volinit) {
491 492 for (nparts = 0; nparts <
492 493 cur_parts->etoc->efi_nparts; nparts++) {
493 494 if (cur_parts->etoc->efi_parts[nparts].p_tag ==
494 495 V_RESERVED) {
495 496 (void) strcpy(
496 497 cur_parts->etoc->efi_parts[nparts].p_name,
497 498 volname);
498 499 (void) strlcpy(cur_disk->v_volume, volname,
499 500 LEN_DKL_VVOL);
500 501 break;
501 502 }
502 503 }
503 504 }
504 505 return (0);
505 506 default:
506 507 /* Should never happen */
507 508 return (-1);
508 509 }
509 510 } else if ((index == other_choice) && (cur_label == L_TYPE_SOLARIS)) {
510 511 /*
511 512 * User chose "other".
512 513 * Get the standard information on the new type.
513 514 * Put all information in a tmp structure, in
514 515 * case user aborts.
515 516 */
516 517 bzero((char *)d, sizeof (struct disk_type));
517 518
518 519 d->dtype_ncyl = get_ncyl();
519 520 d->dtype_acyl = get_acyl(d->dtype_ncyl);
520 521 d->dtype_pcyl = get_pcyl(d->dtype_ncyl, d->dtype_acyl);
521 522 d->dtype_nhead = get_nhead();
522 523 d->dtype_phead = get_phead(d->dtype_nhead, &d->dtype_options);
523 524 d->dtype_nsect = get_nsect();
524 525 d->dtype_psect = get_psect(&d->dtype_options);
525 526 d->dtype_bpt = get_bpt(d->dtype_nsect, &d->dtype_options);
526 527 d->dtype_rpm = get_rpm();
527 528 d->dtype_fmt_time = get_fmt_time(&d->dtype_options);
528 529 d->dtype_cyl_skew = get_cyl_skew(&d->dtype_options);
529 530 d->dtype_trk_skew = get_trk_skew(&d->dtype_options);
530 531 d->dtype_trks_zone = get_trks_zone(&d->dtype_options);
531 532 d->dtype_atrks = get_atrks(&d->dtype_options);
532 533 d->dtype_asect = get_asect(&d->dtype_options);
533 534 d->dtype_cache = get_cache(&d->dtype_options);
534 535 d->dtype_threshold = get_threshold(&d->dtype_options);
535 536 d->dtype_prefetch_min = get_min_prefetch(&d->dtype_options);
536 537 d->dtype_prefetch_max = get_max_prefetch(d->dtype_prefetch_min,
537 538 &d->dtype_options);
538 539 d->dtype_bps = get_bps();
539 540 #if defined(sparc)
540 541 d->dtype_dr_type = 0;
541 542 #endif /* defined(sparc) */
542 543
543 544 d->dtype_asciilabel = get_asciilabel();
544 545 /*
545 546 * Add the new type to the list of possible types for
546 547 * this controller. We lock out interrupts so the lists
547 548 * can't get munged. We put off actually allocating the
548 549 * structure till here in case the user wanted to
549 550 * interrupt while still inputting information.
550 551 */
551 552 enter_critical();
552 553 tptr = (struct disk_type *)zalloc(sizeof (struct disk_type));
553 554 if (type == NULL)
554 555 cur_ctype->ctype_dlist = tptr;
555 556 else {
556 557 while (type->dtype_next != NULL)
557 558 type = type->dtype_next;
558 559 type->dtype_next = tptr;
559 560 }
560 561 bcopy((char *)d, (char *)tptr, sizeof (disk_type));
561 562 tptr->dtype_next = NULL;
562 563 /*
563 564 * the new disk type does not have any defined
564 565 * partition table . Hence copy the current partition
565 566 * table if possible else create a default
566 567 * paritition table.
567 568 */
568 569 new_partitiontable(tptr, oldtype);
569 570 } else if ((index == other_choice) && (cur_label == L_TYPE_EFI)) {
570 571 maxLBA = get_mlba();
571 572 cur_parts->etoc->efi_last_lba = maxLBA;
572 573 cur_parts->etoc->efi_last_u_lba = maxLBA - 34;
573 574 for (i = 0; i < cur_parts->etoc->efi_nparts; i++) {
574 575 cur_parts->etoc->efi_parts[i].p_start = 0;
575 576 cur_parts->etoc->efi_parts[i].p_size = 0;
576 577 cur_parts->etoc->efi_parts[i].p_tag = V_UNASSIGNED;
577 578 }
578 579 cur_parts->etoc->efi_parts[8].p_start =
579 580 maxLBA - 34 - (1024 * 16);
580 581 cur_parts->etoc->efi_parts[8].p_size = (1024 * 16);
581 582 cur_parts->etoc->efi_parts[8].p_tag = V_RESERVED;
582 583 if (write_label()) {
583 584 err_print("Write label failed\n");
584 585 } else {
585 586 cur_disk->disk_flags &= ~DSK_LABEL_DIRTY;
586 587 }
587 588 return (0);
588 589 } else {
589 590 /*
590 591 * User picked an existing disk type.
591 592 */
592 593 i = first_disk;
593 594 tptr = type;
594 595 while (i < index) {
595 596 if (tptr->dtype_asciilabel) {
596 597 i++;
597 598 }
598 599 tptr = tptr->dtype_next;
599 600 }
600 601 if ((tptr->dtype_asciilabel == NULL) &&
601 602 (tptr->dtype_next != NULL)) {
602 603 while (tptr->dtype_asciilabel == NULL) {
603 604 tptr = tptr->dtype_next;
604 605 }
605 606 }
606 607 }
607 608 /*
608 609 * Check for mounted file systems in the format zone.
609 610 * One potential problem with this would be that check()
610 611 * always returns 'yes' when running out of a file. However,
611 612 * it is actually ok because we don't let the program get
612 613 * started if there are mounted file systems and we are
613 614 * running from a file.
614 615 */
615 616 if ((tptr != oldtype) &&
616 617 checkmount((diskaddr_t)-1, (diskaddr_t)-1)) {
617 618 err_print(
618 619 "Cannot set disk type while it has mounted "
619 620 "partitions.\n\n");
620 621 return (-1);
621 622 }
622 623 /*
623 624 * check for partitions being used for swapping in format zone
624 625 */
625 626 if ((tptr != oldtype) &&
626 627 checkswap((diskaddr_t)-1, (diskaddr_t)-1)) {
627 628 err_print("Cannot set disk type while its partition are "
628 629 "currently being used for swapping.\n");
629 630 return (-1);
630 631 }
631 632
632 633 /*
633 634 * Check for partitions being used in SVM, VxVM or LU devices
634 635 */
635 636
636 637 if ((tptr != oldtype) &&
637 638 checkdevinuse(cur_disk->disk_name, (diskaddr_t)-1,
638 639 (diskaddr_t)-1, 0, 0)) {
639 640 err_print("Cannot set disk type while its "
640 641 "partitions are currently in use.\n");
641 642 return (-1);
642 643 }
643 644 /*
644 645 * If the type selected is different from the previous type,
645 646 * mark the disk as not labelled and reload the current
646 647 * partition info. This is not essential but probably the
647 648 * right thing to do, since the size of the disk has probably
648 649 * changed.
649 650 */
650 651 enter_critical();
651 652 if (tptr != oldtype) {
652 653 cur_disk->disk_type = tptr;
653 654 cur_disk->disk_parts = NULL;
654 655 cur_disk->disk_flags &= ~DSK_LABEL;
655 656 }
656 657 /*
657 658 * Initialize the state of the current disk.
658 659 */
659 660 init_globals(cur_disk);
660 661 (void) get_partition();
661 662 exit_critical();
662 663
663 664 /*
664 665 * If the label of the disk is marked dirty,
665 666 * see if they'd like to label the disk now.
666 667 */
667 668 if (cur_disk->disk_flags & DSK_LABEL_DIRTY) {
668 669 if (check("Disk not labeled. Label it now") == 0) {
669 670 if (write_label()) {
670 671 err_print("Write label failed\n");
671 672 } else {
672 673 cur_disk->disk_flags &= ~DSK_LABEL_DIRTY;
673 674 }
674 675 }
675 676 }
676 677
677 678 return (0);
678 679 }
679 680
680 681 /*
681 682 * This routine implements the 'partition' command. It simply runs
682 683 * the partition menu.
683 684 */
684 685 int
685 686 c_partition()
686 687 {
687 688
688 689 /*
689 690 * There must be a current disk type and a current disk
690 691 */
691 692 if (cur_dtype == NULL) {
692 693 err_print("Current Disk Type is not set.\n");
693 694 return (-1);
694 695 }
695 696 /*
696 697 * Check for a valid fdisk table entry for Solaris
697 698 */
698 699 if (!good_fdisk()) {
699 700 return (-1);
700 701 }
701 702
702 703 cur_menu++;
703 704 last_menu = cur_menu;
704 705
705 706 #ifdef not
706 707 /*
707 708 * If there is no current partition table, make one. This is
708 709 * so the commands within the menu never have to check for
709 710 * a non-existent table.
710 711 */
711 712 if (cur_parts == NULL)
712 713 err_print("making partition.\n");
713 714 make_partition();
714 715 #endif /* not */
715 716
716 717 /*
717 718 * Run the menu.
718 719 */
719 720 run_menu(menu_partition, "PARTITION", "partition", 0);
720 721 cur_menu--;
721 722 return (0);
722 723 }
723 724
724 725 /*
725 726 * This routine implements the 'current' command. It describes the
726 727 * current disk.
727 728 */
728 729 int
729 730 c_current()
730 731 {
731 732
732 733 /*
733 734 * If there is no current disk, say so. Note that this is
734 735 * not an error since it is a legitimate response to the inquiry.
735 736 */
736 737 if (cur_disk == NULL) {
737 738 fmt_print("No Current Disk.\n");
738 739 return (0);
739 740 }
740 741 /*
741 742 * Print out the info we have on the current disk.
742 743 */
743 744 fmt_print("Current Disk = %s", cur_disk->disk_name);
744 745 if (chk_volname(cur_disk)) {
745 746 fmt_print(": ");
746 747 print_volname(cur_disk);
747 748 }
748 749 fmt_print("\n");
749 750 if (cur_disk->devfs_name != NULL) {
750 751 if (cur_dtype == NULL) {
751 752 fmt_print("<type unknown>\n");
752 753 } else if (cur_label == L_TYPE_SOLARIS) {
753 754 fmt_print("<%s cyl %d alt %d hd %d sec %d>\n",
754 755 cur_dtype->dtype_asciilabel, ncyl,
755 756 acyl, nhead, nsect);
756 757 } else if (cur_label == L_TYPE_EFI) {
757 758 print_efi_string(cur_dtype->vendor,
758 759 cur_dtype->product, cur_dtype->revision,
759 760 cur_dtype->capacity);
760 761 fmt_print("\n");
761 762 }
762 763 fmt_print("%s\n", cur_disk->devfs_name);
763 764 } else {
764 765 fmt_print("%s%d: <", cur_ctlr->ctlr_dname,
765 766 cur_disk->disk_dkinfo.dki_unit);
766 767 if (cur_dtype == NULL) {
767 768 fmt_print("type unknown");
768 769 } else if (cur_label == L_TYPE_SOLARIS) {
769 770 fmt_print("%s cyl %d alt %d hd %d sec %d",
770 771 cur_dtype->dtype_asciilabel, ncyl,
771 772 acyl, nhead, nsect);
772 773 } else if (cur_label == L_TYPE_EFI) {
773 774 print_efi_string(cur_dtype->vendor,
774 775 cur_dtype->product, cur_dtype->revision,
775 776 cur_dtype->capacity);
776 777 fmt_print("\n");
777 778 }
778 779 fmt_print(">\n");
779 780 }
780 781 fmt_print("\n");
781 782 return (0);
782 783 }
783 784 /*
784 785 * This routine implements the 'format' command. It allows the user
785 786 * to format and verify any portion of the disk.
786 787 */
787 788 int
788 789 c_format()
789 790 {
790 791 diskaddr_t start, end;
791 792 time_t clock;
792 793 int format_time, format_tracks, format_cyls;
793 794 int format_interval;
794 795 diskaddr_t deflt;
795 796 int status;
796 797 u_ioparam_t ioparam;
797 798 struct scsi_inquiry *inq;
798 799 char rawbuf[MAX_MODE_SENSE_SIZE];
799 800 struct scsi_capacity_16 capacity;
800 801 struct vpd_hdr *vpdhdr;
801 802 uint8_t protect;
802 803 uint8_t pagecode;
803 804 uint8_t spt;
804 805 uint8_t p_type;
805 806 uint8_t prot_flag[NUM_PROT_TYPE] = {1, 0, 0, 0};
806 807 int i;
807 808 char *prot_descriptor[NUM_PROT_TYPE] = {
808 809 "Protection Information is disabled.",
809 810 "Protection Information is enabled.",
810 811 "Protection Information is enabled.",
811 812 "Protection Information is enabled.", };
812 813
813 814 /*
814 815 * There must be a current disk type and a current disk
815 816 */
816 817 if (cur_dtype == NULL) {
817 818 err_print("Current Disk Type is not set.\n");
818 819 return (-1);
819 820 }
820 821
821 822 /*
822 823 * There must be a format routine in cur_ops structure to have
823 824 * this routine work.
824 825 */
825 826 if (cur_ops->op_format == NULL) {
826 827 err_print(
827 828 "Cannot format this drive. Please use your Manufacturer supplied formatting "
828 829 "utility.\n");
829 830 return (-1);
830 831 }
831 832
832 833 /*
833 834 * There must be a current defect list. Except for
834 835 * unformatted SCSI disks. For them the defect list
835 836 * can only be retrieved after formatting the disk.
836 837 */
837 838 if ((cur_ctype->ctype_flags & CF_SCSI) && !EMBEDDED_SCSI &&
838 839 (cur_ctype->ctype_flags & CF_DEFECTS) &&
839 840 ! (cur_flags & DISK_FORMATTED)) {
840 841 cur_list.flags |= LIST_RELOAD;
841 842
842 843 } else if (cur_list.list == NULL && !EMBEDDED_SCSI) {
843 844 err_print("Current Defect List must be initialized.\n");
844 845 return (-1);
845 846 }
846 847 /*
847 848 * Ask for the bounds of the format. We always use the whole
848 849 * disk as the default, since that is the most likely case.
849 850 * Note, for disks which must be formatted accross the whole disk,
850 851 * don't bother the user.
851 852 */
852 853 ioparam.io_bounds.lower = start = 0;
853 854 if (cur_label == L_TYPE_SOLARIS) {
854 855 if (cur_ctype->ctype_flags & CF_SCSI) {
855 856 ioparam.io_bounds.upper = end = datasects() - 1;
856 857 } else {
857 858 ioparam.io_bounds.upper = end = physsects() - 1;
858 859 }
859 860 } else {
860 861 ioparam.io_bounds.upper = end = cur_parts->etoc->efi_last_lba;
861 862 }
862 863
863 864 if (! (cur_ctlr->ctlr_flags & DKI_FMTVOL)) {
864 865 deflt = ioparam.io_bounds.lower;
865 866 start = input(FIO_BN,
866 867 "Enter starting block number", ':',
867 868 &ioparam, (int *)&deflt, DATA_INPUT);
868 869 ioparam.io_bounds.lower = start;
869 870 deflt = ioparam.io_bounds.upper;
870 871 end = input(FIO_BN,
871 872 "Enter ending block number", ':',
872 873 &ioparam, (int *)&deflt, DATA_INPUT);
873 874 }
874 875 /*
875 876 * Some disks can format tracks. Make sure the whole track is
876 877 * specified for them.
877 878 */
878 879 if (cur_ctlr->ctlr_flags & DKI_FMTTRK) {
879 880 if (bn2s(start) != 0 ||
880 881 bn2s(end) != sectors(bn2h(end)) - 1) {
881 882 err_print("Controller requires formatting of ");
882 883 err_print("entire tracks.\n");
883 884 return (-1);
884 885 }
885 886 }
886 887 /*
887 888 * Check for mounted file systems in the format zone, and if we
888 889 * find any, make sure they are really serious. One potential
889 890 * problem with this would be that check() always returns 'yes'
890 891 * when running out of a file. However, it is actually ok
891 892 * because we don't let the program get started if there are
892 893 * mounted file systems and we are running from a file.
893 894 */
894 895 if (checkmount(start, end)) {
895 896 err_print(
896 897 "Cannot format disk while it has mounted partitions.\n\n");
897 898 return (-1);
898 899 }
899 900 /*
900 901 * check for partitions being used for swapping in format zone
901 902 */
902 903 if (checkswap(start, end)) {
903 904 err_print("Cannot format disk while its partition are \
904 905 currently being used for swapping.\n");
905 906 return (-1);
906 907 }
907 908 /*
908 909 * Check for partitions being used in SVM, VxVM or LU devices
909 910 * in this format zone
910 911 */
911 912 if (checkdevinuse(cur_disk->disk_name, start, end, 0, 0)) {
912 913 err_print("Cannot format disk while its partitions "
913 914 "are currently in use.\n");
914 915 return (-1);
915 916 }
916 917
917 918 if (cur_disk->disk_lbasize != DEV_BSIZE) {
918 919 fmt_print("Current disk sector size is %d Byte, format\n"
919 920 "will change the sector size to 512 Byte. ",
920 921 cur_disk->disk_lbasize);
921 922 if (check("Continue")) {
922 923 return (-1);
923 924 }
924 925 }
925 926
926 927 /*
927 928 * set the default protection type
928 929 */
929 930 prot_type = PROT_TYPE_0;
930 931
931 932 /*
932 933 * Check if the protect information of this disk is enabled
933 934 */
934 935 if (uscsi_inquiry(cur_file, rawbuf, sizeof (rawbuf))) {
935 936 err_print("Inquiry failed\n");
936 937 return (-1);
937 938 }
938 939 inq = (struct scsi_inquiry *)rawbuf;
939 940 protect = inq->inq_protect;
940 941 if (protect == 0) {
941 942 fmt_print("The protection information is not enabled\n");
942 943 fmt_print(
943 944 "The disk will be formatted with protection type 0\n");
944 945 } else {
945 946 (void) memset(rawbuf, 0, MAX_MODE_SENSE_SIZE);
946 947 if (uscsi_inquiry_page_86h(cur_file, rawbuf, sizeof (rawbuf))) {
947 948 err_print("Inquiry with page 86h failed\n");
948 949 return (-1);
949 950 }
950 951 vpdhdr = (struct vpd_hdr *)rawbuf;
951 952 pagecode = vpdhdr->page_code;
952 953 if (pagecode != 0x86) {
953 954 err_print("Inquiry with page 86h failed\n");
954 955 return (-1);
955 956 }
956 957 spt = (rawbuf[4] << 2) >> 5;
957 958 fmt_print("This disk can support protection types:\n");
958 959
959 960 switch (spt) {
960 961 case 0:
961 962 prot_flag[1] = 1;
962 963 break;
963 964 case 1:
964 965 prot_flag[1] = 1;
965 966 prot_flag[2] = 1;
966 967 break;
967 968 case 2:
968 969 prot_flag[2] = 1;
969 970 break;
970 971 case 3:
971 972 prot_flag[1] = 1;
972 973 prot_flag[3] = 1;
973 974 break;
974 975 case 4:
975 976 prot_flag[3] = 1;
976 977 break;
977 978 case 5:
978 979 prot_flag[2] = 1;
979 980 prot_flag[3] = 1;
980 981 break;
981 982 case 7:
982 983 prot_flag[1] = 1;
983 984 prot_flag[2] = 1;
984 985 prot_flag[3] = 1;
985 986 break;
986 987 default:
987 988 err_print(
988 989 "Invalid supported protection types\n");
989 990 return (-1);
990 991 }
991 992 for (i = 0; i < NUM_PROT_TYPE; i++) {
992 993 if (prot_flag[i] == 1) {
993 994 fmt_print("[%d] TYPE_%d : ", i, i);
994 995 fmt_print("%s\n", prot_descriptor[i]);
995 996 }
996 997 }
997 998
998 999 /*
999 1000 * Get the current protection type
1000 1001 */
1001 1002 if (uscsi_read_capacity_16(cur_file, &capacity)) {
1002 1003 err_print("Read capacity_16 failed\n");
1003 1004 return (-1);
1004 1005 }
1005 1006 p_type = get_cur_protection_type(&capacity);
1006 1007 fmt_print("\nThe disk is currently formatted with TYPE_%d.\n",
1007 1008 p_type);
1008 1009
1009 1010 /*
1010 1011 * Ask user what protection type to use
1011 1012 */
1012 1013 ioparam.io_bounds.lower = PROT_TYPE_0;
1013 1014 ioparam.io_bounds.upper = PROT_TYPE_3;
1014 1015 prot_type = input(FIO_INT, "Specify the New Protection Type",
1015 1016 ':', &ioparam, NULL, DATA_INPUT);
1016 1017 /*
1017 1018 * if get a unsupported protection type, then use the
1018 1019 * current type: p_type.
1019 1020 */
1020 1021 if (prot_flag[prot_type] == 0) {
1021 1022 fmt_print("Unsupported protection type.\n");
1022 1023 prot_type = p_type;
1023 1024 }
1024 1025 fmt_print("The disk will be formatted to type %d\n", prot_type);
1025 1026 }
1026 1027
1027 1028 if (SCSI && (format_time = scsi_format_time()) > 0) {
1028 1029 fmt_print(
1029 1030 "\nReady to format. Formatting cannot be interrupted\n"
1030 1031 "and takes %d minutes (estimated). ", format_time);
1031 1032
1032 1033 } else if (cur_dtype->dtype_options & SUP_FMTTIME) {
1033 1034 /*
1034 1035 * Formatting time is (2 * time of 1 spin * number of
1035 1036 * tracks) + (step rate * number of cylinders) rounded
1036 1037 * up to the nearest minute. Note, a 10% fudge factor
1037 1038 * is thrown in for insurance.
1038 1039 */
1039 1040 if (cur_dtype->dtype_fmt_time == 0)
1040 1041 cur_dtype->dtype_fmt_time = 2;
1041 1042
1042 1043 format_tracks = ((end-start) / cur_dtype->dtype_nsect) + 1;
1043 1044 format_cyls = format_tracks / cur_dtype->dtype_nhead;
1044 1045 format_tracks = format_tracks * cur_dtype->dtype_fmt_time;
1045 1046
1046 1047 /*
1047 1048 * ms.
1048 1049 */
1049 1050 format_time = ((60000 / cur_dtype->dtype_rpm) +1) *
1050 1051 format_tracks + format_cyls * 7;
1051 1052 /*
1052 1053 * 20% done tick (sec)
1053 1054 */
1054 1055 format_interval = format_time / 5000;
1055 1056 /*
1056 1057 * min.
1057 1058 */
1058 1059 format_time = (format_time + 59999) / 60000;
1059 1060
1060 1061 /*
1061 1062 * Check format time values and make adjustments
1062 1063 * to prevent sleeping too long (forever?) or
1063 1064 * too short.
1064 1065 */
1065 1066 if (format_time <= 1) {
1066 1067 /*
1067 1068 * Format time is less than 1 min..
1068 1069 */
1069 1070 format_time = 1;
1070 1071 }
1071 1072
1072 1073 if (format_interval < 11) {
1073 1074 /* Format time is less than 1 minute. */
1074 1075 if (format_interval < 2)
1075 1076 format_interval = 2; /* failsafe */
1076 1077 format_interval = 10;
1077 1078 } else {
1078 1079 /* Format time is greater than 1 minute. */
1079 1080 format_interval -= 10;
1080 1081 }
1081 1082
1082 1083 fmt_print(
1083 1084 "Ready to format. Formatting cannot be interrupted\n"
1084 1085 "and takes %d minutes (estimated). ", format_time);
1085 1086 } else {
1086 1087 fmt_print(
1087 1088 "Ready to format. Formatting cannot be interrupted.\n");
1088 1089 }
1089 1090 if (check("Continue")) {
1090 1091 return (-1);
1091 1092 }
1092 1093
1093 1094 /*
1094 1095 * Print the time so that the user will know when format started.
1095 1096 * Lock out interrupts. This could be a problem, since it could
1096 1097 * cause the user to sit for quite awhile with no control, but we
1097 1098 * don't have any other good way of keeping his gun from going off.
1098 1099 */
1099 1100 clock = time((time_t *)0);
1100 1101 fmt_print("Beginning format. The current time is %s\n",
1101 1102 ctime(&clock));
1102 1103 enter_critical();
1103 1104 /*
1104 1105 * Mark the defect list dirty so it will be rewritten when we are
1105 1106 * done. It is possible to qualify this so it doesn't always
1106 1107 * get rewritten, but it's not worth the trouble.
1107 1108 * Note: no defect lists for embedded scsi drives.
1108 1109 */
1109 1110 if (!EMBEDDED_SCSI) {
1110 1111 cur_list.flags |= LIST_DIRTY;
1111 1112 }
1112 1113 /*
1113 1114 * If we are formatting over any of the labels, mark the label
1114 1115 * dirty so it will be rewritten.
1115 1116 */
1116 1117 if (cur_disk->label_type == L_TYPE_SOLARIS) {
1117 1118 if (start < totalsects() && end >= datasects()) {
1118 1119 if (cur_disk->disk_flags & DSK_LABEL)
1119 1120 cur_flags |= LABEL_DIRTY;
1120 1121 }
1121 1122 } else if (cur_disk->label_type == L_TYPE_EFI) {
1122 1123 if (start < 34) {
1123 1124 if (cur_disk->disk_flags & DSK_LABEL)
1124 1125 cur_flags |= LABEL_DIRTY;
1125 1126 }
1126 1127 }
1127 1128 if (start == 0) {
1128 1129 cur_flags |= LABEL_DIRTY;
1129 1130 }
1130 1131 /*
1131 1132 * Do the format. bugid 1009138 removed the use of fork to
1132 1133 * background the format and print a tick.
1133 1134 */
1134 1135
1135 1136 status = (*cur_ops->op_format)(start, end, &cur_list);
1136 1137 if (status) {
1137 1138 exit_critical();
1138 1139 err_print("failed\n");
1139 1140 return (-1);
1140 1141 }
1141 1142 fmt_print("done\n");
1142 1143 if (option_msg && diag_msg) {
1143 1144 clock = time((time_t *)0);
1144 1145 fmt_print("The current time is %s\n", ctime(&clock));
1145 1146 }
1146 1147 cur_flags |= DISK_FORMATTED;
1147 1148 /*
1148 1149 * If the defect list or label is dirty, write them out again.
1149 1150 * Note, for SCSI we have to wait til now to load defect list
1150 1151 * since we can't access it until after formatting a virgin disk.
1151 1152 */
1152 1153 /* enter_critical(); */
1153 1154 if (cur_list.flags & LIST_RELOAD) {
1154 1155 assert(!EMBEDDED_SCSI);
1155 1156 if (*cur_ops->op_ex_man == NULL ||
1156 1157 (*cur_ops->op_ex_man)(&cur_list)) {
1157 1158 err_print("Warning: unable to reload defect list\n");
1158 1159 cur_list.flags &= ~LIST_DIRTY;
1159 1160 return (-1);
1160 1161 }
1161 1162 cur_list.flags |= LIST_DIRTY;
1162 1163 }
1163 1164
1164 1165 if (cur_list.flags & LIST_DIRTY) {
1165 1166 assert(!EMBEDDED_SCSI);
1166 1167 write_deflist(&cur_list);
1167 1168 cur_list.flags = 0;
1168 1169 }
1169 1170 if (cur_flags & LABEL_DIRTY) {
1170 1171 (void) write_label();
1171 1172 cur_flags &= ~LABEL_DIRTY;
1172 1173 }
1173 1174 /*
1174 1175 * Come up for air, since the verify step does not need to
1175 1176 * be atomic (it does it's own lockouts when necessary).
1176 1177 */
1177 1178 exit_critical();
1178 1179 /*
1179 1180 * If we are supposed to verify, we do the 'write' test over
1180 1181 * the format zone. The rest of the analysis parameters are
1181 1182 * left the way they were.
1182 1183 */
1183 1184 if (scan_auto) {
1184 1185 scan_entire = 0;
1185 1186 scan_lower = start;
1186 1187 scan_upper = end;
1187 1188 fmt_print("\nVerifying media...");
1188 1189 status = do_scan(SCAN_PATTERN, F_SILENT);
1189 1190 }
1190 1191 /*
1191 1192 * If the defect list or label is dirty, write them out again.
1192 1193 */
1193 1194 if (cur_list.flags & LIST_DIRTY) {
1194 1195 assert(!EMBEDDED_SCSI);
1195 1196 cur_list.flags = 0;
1196 1197 write_deflist(&cur_list);
1197 1198 }
1198 1199 if (cur_flags & LABEL_DIRTY) {
1199 1200 cur_flags &= ~LABEL_DIRTY;
1200 1201 (void) write_label();
1201 1202 }
1202 1203 return (status);
1203 1204 }
1204 1205
1205 1206 /*
1206 1207 * This routine implements the 'repair' command. It allows the user
1207 1208 * to reallocate sectors on the disk that have gone bad.
1208 1209 */
1209 1210 int
1210 1211 c_repair()
1211 1212 {
1212 1213 diskaddr_t bn;
1213 1214 int status;
1214 1215 u_ioparam_t ioparam;
1215 1216 char *buf;
1216 1217 int buf_is_good;
1217 1218 int block_has_error;
1218 1219 int i;
1219 1220
1220 1221 /*
1221 1222 * There must be a current disk type (and therefore a current disk).
1222 1223 */
1223 1224 if (cur_dtype == NULL) {
1224 1225 err_print("Current Disk Type is not set.\n");
1225 1226 return (-1);
1226 1227 }
1227 1228 /*
1228 1229 * The current disk must be formatted for repair to work.
1229 1230 */
1230 1231 if (!(cur_flags & DISK_FORMATTED)) {
1231 1232 err_print("Current Disk is unformatted.\n");
1232 1233 return (-1);
1233 1234 }
1234 1235 /*
1235 1236 * Check for a valid fdisk table entry for Solaris
1236 1237 */
1237 1238 if (!good_fdisk()) {
1238 1239 return (-1);
1239 1240 }
1240 1241 /*
1241 1242 * Repair is an optional command for controllers, so it may
1242 1243 * not be supported.
1243 1244 */
1244 1245 if (cur_ops->op_repair == NULL) {
1245 1246 err_print("Controller does not support repairing.\n");
1246 1247 err_print("or disk supports automatic defect management.\n");
1247 1248 return (-1);
1248 1249 }
1249 1250 /*
1250 1251 * There must be a defect list for non-embedded scsi devices,
1251 1252 * since we will add to it.
1252 1253 */
1253 1254 if (!EMBEDDED_SCSI && cur_list.list == NULL) {
1254 1255 err_print("Current Defect List must be initialized.\n");
1255 1256 return (-1);
1256 1257 }
1257 1258 /*
1258 1259 * Ask the user which sector has gone bad.
1259 1260 */
1260 1261 ioparam.io_bounds.lower = 0;
1261 1262 if (cur_disk->label_type == L_TYPE_SOLARIS) {
1262 1263 ioparam.io_bounds.upper = physsects() - 1;
1263 1264 } else {
1264 1265 ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba;
1265 1266 }
1266 1267 bn = input(FIO_BN,
1267 1268 "Enter absolute block number of defect", ':',
1268 1269 &ioparam, (int *)NULL, DATA_INPUT);
1269 1270 /*
1270 1271 * Check to see if there is a mounted file system over the
1271 1272 * specified sector. If there is, make sure the user is
1272 1273 * really serious.
1273 1274 */
1274 1275 if (checkmount(bn, bn)) {
1275 1276 if (check("Repair is in a mounted partition, continue"))
1276 1277 return (-1);
1277 1278 }
1278 1279 /*
1279 1280 * check for partitions being used for swapping in format zone
1280 1281 */
1281 1282 if (checkswap(bn, bn)) {
1282 1283 if (check("Repair is in a partition which is currently \
1283 1284 being used for swapping.\ncontinue"))
1284 1285 return (-1);
1285 1286 }
1286 1287
1287 1288 if (checkdevinuse(cur_disk->disk_name, bn, bn, 0, 0)) {
1288 1289 if (check("Repair is in a partition which is currently "
1289 1290 "in use.\ncontinue"))
1290 1291 return (-1);
1291 1292 }
1292 1293
1293 1294 buf = zalloc((cur_disk->disk_lbasize == 0) ?
1294 1295 SECSIZE : cur_disk->disk_lbasize);
1295 1296
1296 1297 /*
1297 1298 * Try to read the sector before repairing it. If we can
1298 1299 * get good data out of it, we can write that data back
1299 1300 * after the repair. If the sector looks ok, ask the
1300 1301 * user to confirm the repair, since it doesn't appear
1301 1302 * necessary. Try reading the block several times to
1302 1303 * see if we can read it consistently.
1303 1304 *
1304 1305 * First, let's see if the block appears to have problems...
1305 1306 */
1306 1307 block_has_error = 1;
1307 1308 for (i = 0; i < 5; i++) {
1308 1309 status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, bn,
1309 1310 1, buf, (F_SILENT | F_ALLERRS), NULL);
1310 1311 if (status)
1311 1312 break; /* one of the tries failed */
1312 1313 }
1313 1314 if (status == 0) {
1314 1315 block_has_error = 0;
1315 1316 if (check("\
1316 1317 This block doesn't appear to be bad. Repair it anyway")) {
1317 1318 free(buf);
1318 1319 return (0);
1319 1320 }
1320 1321 }
1321 1322 /*
1322 1323 * Last chance...
1323 1324 */
1324 1325 if (check("Ready to repair defect, continue")) {
1325 1326 free(buf);
1326 1327 return (-1);
1327 1328 }
1328 1329 /*
1329 1330 * We're committed to repairing it. Try to get any good
1330 1331 * data out of the block if possible. Note that we do
1331 1332 * not set the F_ALLERRS flag.
1332 1333 */
1333 1334 buf_is_good = 0;
1334 1335 for (i = 0; i < 5; i++) {
1335 1336 status = (*cur_ops->op_rdwr)(DIR_READ, cur_file, bn,
1336 1337 1, buf, F_SILENT, NULL);
1337 1338 if (status == 0) {
1338 1339 buf_is_good = 1;
1339 1340 break;
1340 1341 }
1341 1342 }
1342 1343 /*
1343 1344 * Lock out interrupts so the disk can't get out of sync with
1344 1345 * the defect list.
1345 1346 */
1346 1347 enter_critical();
1347 1348
1348 1349 fmt_print("Repairing ");
1349 1350 if (block_has_error) {
1350 1351 fmt_print("%s error on ", buf_is_good ? "soft" : "hard");
1351 1352 }
1352 1353 fmt_print("block %llu (", bn);
1353 1354 pr_dblock(fmt_print, bn);
1354 1355 fmt_print(")...");
1355 1356 /*
1356 1357 * Do the repair.
1357 1358 */
1358 1359 status = (*cur_ops->op_repair)(bn, F_NORMAL);
1359 1360 if (status) {
1360 1361 fmt_print("failed.\n\n");
1361 1362 } else {
1362 1363 /*
1363 1364 * The repair worked. Write the old data to the new
1364 1365 * block if we were able to read it, otherwise
1365 1366 * zero out the new block. If it looks like the
1366 1367 * new block is bad, let the user know that, too.
1367 1368 * Should we attempt auto-repair in this case?
1368 1369 */
1369 1370 fmt_print("ok.\n");
1370 1371 if (!buf_is_good) {
1371 1372 bzero(buf, cur_disk->disk_lbasize);
1372 1373 }
1373 1374 status = (*cur_ops->op_rdwr)(DIR_WRITE, cur_file, bn,
1374 1375 1, buf, (F_SILENT | F_ALLERRS), NULL);
1375 1376 if (status == 0) {
1376 1377 status = (*cur_ops->op_rdwr)(DIR_READ, cur_file,
1377 1378 bn, 1, buf, (F_SILENT | F_ALLERRS), NULL);
1378 1379 }
1379 1380 if (status) {
1380 1381 fmt_print("The new block %llu (", bn);
1381 1382 pr_dblock(fmt_print, bn);
1382 1383 fmt_print(") also appears defective.\n");
1383 1384 }
1384 1385 fmt_print("\n");
1385 1386 /*
1386 1387 * Add the bad sector to the defect list, write out
1387 1388 * the defect list, and kill off the working list so
1388 1389 * it will get synced up with the current defect list
1389 1390 * next time we need it.
1390 1391 *
1391 1392 * For embedded scsi, we don't require a defect list.
1392 1393 * However, if we have one, add the defect if the
1393 1394 * list includes the grown list. If not, kill it
1394 1395 * to force a resync if we need the list later.
1395 1396 */
1396 1397 if (EMBEDDED_SCSI) {
1397 1398 if (cur_list.list != NULL) {
1398 1399 if (cur_list.flags & LIST_PGLIST) {
1399 1400 add_ldef(bn, &cur_list);
1400 1401 } else {
1401 1402 kill_deflist(&cur_list);
1402 1403 }
1403 1404 }
1404 1405 } else if (cur_ctype->ctype_flags & CF_WLIST) {
1405 1406 kill_deflist(&cur_list);
1406 1407 if (*cur_ops->op_ex_cur != NULL) {
1407 1408 (*cur_ops->op_ex_cur)(&cur_list);
1408 1409 fmt_print("Current list updated\n");
1409 1410 }
1410 1411 } else {
1411 1412 add_ldef(bn, &cur_list);
1412 1413 write_deflist(&cur_list);
1413 1414 }
1414 1415 kill_deflist(&work_list);
1415 1416 }
1416 1417 exit_critical();
1417 1418 free(buf);
1418 1419
1419 1420 /*
1420 1421 * Return status.
1421 1422 */
1422 1423 return (status);
1423 1424 }
1424 1425
1425 1426 /*
1426 1427 * This routine implements the 'show' command. It translates a disk
1427 1428 * block given in any format into decimal, hexadecimal, and
1428 1429 * cylinder/head/sector format.
1429 1430 */
1430 1431 int
1431 1432 c_show()
1432 1433 {
1433 1434 u_ioparam_t ioparam;
1434 1435 diskaddr_t bn;
1435 1436
1436 1437 /*
1437 1438 * There must be a current disk type, so we will know the geometry.
1438 1439 */
1439 1440 if (cur_dtype == NULL) {
1440 1441 err_print("Current Disk Type is not set.\n");
1441 1442 return (-1);
1442 1443 }
1443 1444 /*
1444 1445 * Ask the user for a disk block.
1445 1446 */
1446 1447 ioparam.io_bounds.lower = 0;
1447 1448 if (cur_disk->label_type == L_TYPE_SOLARIS) {
1448 1449 ioparam.io_bounds.upper = physsects() - 1;
1449 1450 } else {
1450 1451 ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba;
1451 1452 }
1452 1453 bn = input(FIO_BN, "Enter a disk block", ':',
1453 1454 &ioparam, (int *)NULL, DATA_INPUT);
1454 1455 /*
1455 1456 * Echo it back.
1456 1457 */
1457 1458 fmt_print("Disk block = %lld = 0x%llx = (", bn, bn);
1458 1459 pr_dblock(fmt_print, bn);
1459 1460 fmt_print(")\n\n");
1460 1461 return (0);
1461 1462 }
1462 1463
1463 1464 /*
1464 1465 * This routine implements the 'label' command. It writes the
1465 1466 * primary and backup labels onto the current disk.
1466 1467 */
1467 1468 int
1468 1469 c_label()
1469 1470 {
1470 1471 int status;
1471 1472 int deflt, *defltptr = NULL;
1472 1473
1473 1474 /*
1474 1475 * There must be a current disk type (and therefore a current disk).
1475 1476 */
1476 1477 if (cur_dtype == NULL) {
1477 1478 err_print("Current Disk Type is not set.\n");
1478 1479 return (-1);
1479 1480 }
1480 1481 /*
1481 1482 * The current disk must be formatted to label it.
1482 1483 */
1483 1484 if (!(cur_flags & DISK_FORMATTED)) {
1484 1485 err_print("Current Disk is unformatted.\n");
1485 1486 return (-1);
1486 1487 }
1487 1488 /*
1488 1489 * Check for a valid fdisk table entry for Solaris
1489 1490 */
1490 1491 if (!good_fdisk()) {
1491 1492 return (-1);
1492 1493 }
1493 1494 /*
1494 1495 * Check to see if there are any mounted file systems anywhere
1495 1496 * on the current disk. If so, refuse to label the disk, but
1496 1497 * only if the partitions would change for the mounted partitions.
1497 1498 *
1498 1499 */
1499 1500 if (checkmount((diskaddr_t)-1, (diskaddr_t)-1)) {
1500 1501 /* Bleagh, too descriptive */
1501 1502 if (check_label_with_mount()) {
1502 1503 err_print("Cannot label disk while it has "
1503 1504 "mounted partitions.\n\n");
1504 1505 return (-1);
1505 1506 }
1506 1507 }
1507 1508
1508 1509 /*
1509 1510 * check to see if there any partitions being used for swapping
1510 1511 * on the current disk. If so, refuse to label the disk, but
1511 1512 * only if the partitions would change for the mounted partitions.
1512 1513 */
1513 1514 if (checkswap((diskaddr_t)-1, (diskaddr_t)-1)) {
1514 1515 if (check_label_with_swap()) {
1515 1516 err_print("Cannot label disk while its "
1516 1517 "partitions are currently being used for "
1517 1518 "swapping.\n");
1518 1519 return (-1);
1519 1520 }
1520 1521 }
1521 1522
1522 1523 /*
1523 1524 * Check to see if any partitions used for svm, vxvm or live upgrade
1524 1525 * are on the disk. If so, refuse to label the disk, but only
1525 1526 * if we are trying to shrink a partition in use.
1526 1527 */
1527 1528 if (checkdevinuse(cur_disk->disk_name, (diskaddr_t)-1,
1528 1529 (diskaddr_t)-1, 0, 1)) {
1529 1530 err_print("Cannot label disk when "
1530 1531 "partitions are in use as described.\n");
1531 1532 return (-1);
1532 1533 }
1533 1534
1534 1535 /*
1535 1536 * If there is not a current partition map, warn the user we
1536 1537 * are going to use the default. The default is the first
1537 1538 * partition map we encountered in the data file. If there is
1538 1539 * no default we give up.
1539 1540 */
1540 1541 if (cur_parts == NULL) {
1541 1542 fmt_print("Current Partition Table is not set, "
1542 1543 "using default.\n");
1543 1544 cur_disk->disk_parts = cur_parts = cur_dtype->dtype_plist;
1544 1545 if (cur_parts == NULL) {
1545 1546 err_print("No default available, cannot label.\n");
1546 1547 return (-1);
1547 1548 }
1548 1549 }
1549 1550 /*
1550 1551 * If expert (-e) mode, then ask user if they wish
1551 1552 * to change the current solaris label into an EFI one
1552 1553 */
1553 1554 if (expert_mode) {
1554 1555 #if defined(_SUNOS_VTOC_8)
1555 1556 int i;
1556 1557 #endif
1557 1558 int choice;
1558 1559 u_ioparam_t ioparam;
1559 1560 struct extvtoc vtoc;
1560 1561 struct dk_label label;
1561 1562 struct dk_gpt *vtoc64;
1562 1563 struct efi_info efinfo;
1563 1564 struct disk_type *dptr;
1564 1565
1565 1566 /* Ask user what label to use */
1566 1567 fmt_print("[0] SMI Label\n");
1567 1568 fmt_print("[1] EFI Label\n");
1568 1569 ioparam.io_bounds.lower = 0;
1569 1570 ioparam.io_bounds.upper = 1;
1570 1571 if ((cur_label == L_TYPE_SOLARIS) &&
1571 1572 (cur_disk->fdisk_part.systid != EFI_PMBR))
1572 1573 deflt = L_TYPE_SOLARIS;
1573 1574 else
1574 1575 deflt = L_TYPE_EFI;
1575 1576 defltptr = &deflt;
1576 1577 choice = input(FIO_INT, "Specify Label type", ':',
1577 1578 &ioparam, defltptr, DATA_INPUT);
1578 1579 if ((choice == L_TYPE_SOLARIS) &&
1579 1580 (cur_label == L_TYPE_SOLARIS) &&
1580 1581 (cur_disk->fdisk_part.systid != EFI_PMBR)) {
1581 1582 goto expert_end;
1582 1583 } else if ((choice == L_TYPE_EFI) &&
1583 1584 (cur_label == L_TYPE_EFI)) {
1584 1585 goto expert_end;
1585 1586 }
1586 1587 switch (choice) {
1587 1588 case L_TYPE_SOLARIS:
1588 1589 /*
1589 1590 * EFI label to SMI label
1590 1591 */
1591 1592 if (cur_dtype->capacity > INFINITY) {
1592 1593 fmt_print("Warning: SMI labels only support up to "
1593 1594 "2 TB.\n");
1594 1595 }
1595 1596
1596 1597 if (cur_disk->fdisk_part.systid == EFI_PMBR) {
1597 1598 fmt_print("Warning: This disk has an EFI label. "
1598 1599 "Changing to SMI label will erase all\n"
1599 1600 "current partitions.\n");
1600 1601 if (check("Continue"))
1601 1602 return (-1);
1602 1603 #if defined(_FIRMWARE_NEEDS_FDISK)
1603 1604 fmt_print("You must use fdisk to delete the current "
1604 1605 "EFI partition and create a new\n"
1605 1606 "Solaris partition before you can convert the "
1606 1607 "label.\n");
1607 1608 return (-1);
1608 1609 #endif
1609 1610 }
1610 1611
1611 1612 #if defined(_FIRMWARE_NEEDS_FDISK)
1612 1613 if (!(((cur_disk->fdisk_part.systid != SUNIXOS) ||
1613 1614 (cur_disk->fdisk_part.systid != SUNIXOS2)) &&
↓ open down ↓ |
1578 lines elided |
↑ open up ↑ |
1614 1615 (cur_disk->fdisk_part.numsect > 0))) {
1615 1616 fmt_print("You must use fdisk to create a Solaris "
1616 1617 "partition before you can convert the label.\n");
1617 1618 return (-1);
1618 1619 }
1619 1620 #endif
1620 1621
1621 1622 (void) memset((char *)&label, 0, sizeof (struct dk_label));
1622 1623
1623 1624 (void) strcpy(x86_devname, cur_disk->disk_name);
1624 - if (cur_ctype->ctype_ctype == DKC_DIRECT)
1625 + if (cur_ctype->ctype_ctype == DKC_DIRECT ||
1626 + cur_ctype->ctype_ctype == DKC_BLKDEV)
1625 1627 dptr = auto_direct_get_geom_label(cur_file, &label);
1626 1628 else
1627 1629 dptr = auto_sense(cur_file, 1, &label);
1628 1630 if (dptr == NULL) {
1629 1631 fmt_print("Autoconfiguration failed.\n");
1630 1632 return (-1);
1631 1633 }
1632 1634
1633 1635 pcyl = label.dkl_pcyl;
1634 1636 ncyl = label.dkl_ncyl;
1635 1637 acyl = label.dkl_acyl;
1636 1638 nhead = label.dkl_nhead;
1637 1639 nsect = label.dkl_nsect;
1638 1640
1639 1641 if (delete_disk_type(cur_disk->disk_type) == 0) {
1640 1642 cur_label = L_TYPE_SOLARIS;
1641 1643 cur_disk->label_type = L_TYPE_SOLARIS;
1642 1644 cur_disk->disk_type = dptr;
1643 1645 cur_disk->disk_parts = dptr->dtype_plist;
1644 1646 cur_dtype = dptr;
1645 1647 cur_parts = dptr->dtype_plist;
1646 1648
1647 1649 if (status = write_label())
1648 1650 err_print("Label failed.\n");
1649 1651 else
1650 1652 cur_disk->disk_flags &= ~DSK_LABEL_DIRTY;
1651 1653
1652 1654 return (status);
1653 1655 } else {
1654 1656 err_print("Label failed.\n");
1655 1657 return (-1);
1656 1658 }
1657 1659
1658 1660
1659 1661 case L_TYPE_EFI:
1660 1662 /*
1661 1663 * SMI label to EFI label
1662 1664 */
1663 1665
1664 1666 if ((cur_disk->fdisk_part.systid == SUNIXOS) ||
1665 1667 (cur_disk->fdisk_part.systid == SUNIXOS2)) {
1666 1668 fmt_print("Warning: This disk has an SMI label. "
1667 1669 "Changing to EFI label will erase all\ncurrent "
1668 1670 "partitions.\n");
1669 1671 if (check("Continue")) {
1670 1672 return (-1);
1671 1673 }
1672 1674 }
1673 1675
1674 1676 if (get_disk_info(cur_file, &efinfo, cur_disk) != 0) {
1675 1677 return (-1);
1676 1678 }
1677 1679 (void) memset((char *)&label, 0, sizeof (struct dk_label));
1678 1680 label.dkl_pcyl = pcyl;
1679 1681 label.dkl_ncyl = ncyl;
1680 1682 label.dkl_acyl = acyl;
1681 1683 #if defined(_SUNOS_VTOC_16)
1682 1684 label.dkl_bcyl = bcyl;
1683 1685 #endif /* defined(_SUNOC_VTOC_16) */
1684 1686 label.dkl_nhead = nhead;
1685 1687 label.dkl_nsect = nsect;
1686 1688 #if defined(_SUNOS_VTOC_8)
1687 1689 for (i = 0; i < NDKMAP; i++) {
1688 1690 label.dkl_map[i] = cur_parts->pinfo_map[i];
1689 1691 }
1690 1692 #endif /* defined(_SUNOS_VTOC_8) */
1691 1693 label.dkl_magic = DKL_MAGIC;
1692 1694 label.dkl_vtoc = cur_parts->vtoc;
1693 1695 if (label_to_vtoc(&vtoc, &label) == -1) {
1694 1696 return (-1);
1695 1697 }
1696 1698 if (SMI_vtoc_to_EFI(cur_file, &vtoc64) == -1) {
1697 1699 return (-1);
1698 1700 }
1699 1701 if (efi_write(cur_file, vtoc64) != 0) {
1700 1702 err_check(vtoc64);
1701 1703 err_print("Warning: error writing EFI.\n");
1702 1704 return (-1);
1703 1705 } else {
1704 1706 cur_disk->disk_flags &= ~DSK_LABEL_DIRTY;
1705 1707 }
1706 1708 /*
1707 1709 * copy over the EFI vtoc onto the SMI vtoc and return
1708 1710 * okay.
1709 1711 */
1710 1712 dptr = auto_efi_sense(cur_file, &efinfo);
1711 1713 if (dptr == NULL) {
1712 1714 fmt_print("Autoconfiguration failed.\n");
1713 1715 return (-1);
1714 1716 }
1715 1717
1716 1718 cur_label = L_TYPE_EFI;
1717 1719 cur_disk->label_type = L_TYPE_EFI;
1718 1720 cur_disk->disk_type = dptr;
1719 1721 cur_disk->disk_parts = dptr->dtype_plist;
1720 1722 cur_dtype = dptr;
1721 1723 cur_parts = dptr->dtype_plist;
1722 1724 cur_parts->etoc = vtoc64;
1723 1725
1724 1726 ncyl = pcyl = nsect = psect = acyl = phead = 0;
1725 1727
1726 1728 /*
1727 1729 * Get the Solais Fdisk Partition information.
1728 1730 */
1729 1731 (void) copy_solaris_part(&cur_disk->fdisk_part);
1730 1732
1731 1733 return (0);
1732 1734 }
1733 1735 }
1734 1736
1735 1737 expert_end:
1736 1738 /*
1737 1739 * Make sure the user is serious.
1738 1740 */
1739 1741 if (check("Ready to label disk, continue")) {
1740 1742 return (-1);
1741 1743 }
1742 1744 /*
1743 1745 * Write the labels out (this will also notify unix) and
1744 1746 * return status.
1745 1747 */
1746 1748 fmt_print("\n");
1747 1749 if (status = write_label())
1748 1750 err_print("Label failed.\n");
1749 1751 return (status);
1750 1752 }
1751 1753
1752 1754 /*
1753 1755 * This routine implements the 'analyze' command. It simply runs
1754 1756 * the analyze menu.
1755 1757 */
1756 1758 int
1757 1759 c_analyze()
1758 1760 {
1759 1761
1760 1762 /*
1761 1763 * There must be a current disk type (and therefor a current disk).
1762 1764 */
1763 1765 if (cur_dtype == NULL) {
1764 1766 err_print("Current Disk Type is not set.\n");
1765 1767 return (-1);
1766 1768 }
1767 1769 cur_menu++;
1768 1770 last_menu = cur_menu;
1769 1771
1770 1772 /*
1771 1773 * Run the menu.
1772 1774 */
1773 1775 run_menu(menu_analyze, "ANALYZE", "analyze", 0);
1774 1776 cur_menu--;
1775 1777 return (0);
1776 1778 }
1777 1779
1778 1780 /*
1779 1781 * This routine implements the 'defect' command. It simply runs
1780 1782 * the defect menu.
1781 1783 */
1782 1784 int
1783 1785 c_defect()
1784 1786 {
1785 1787 int i;
1786 1788
1787 1789 /*
1788 1790 * There must be a current disk type (and therefor a current disk).
1789 1791 */
1790 1792 if (cur_dtype == NULL) {
1791 1793 err_print("Current Disk Type is not set.\n");
1792 1794 return (-1);
1793 1795 }
1794 1796
1795 1797 /*
1796 1798 * Check for the defect management and list management ops and
1797 1799 * display appropriate message.
1798 1800 */
1799 1801 if ((cur_ops->op_ex_man == NULL) && (cur_ops->op_ex_cur == NULL) &&
1800 1802 (cur_ops->op_create == NULL) && (cur_ops->op_wr_cur == NULL)) {
1801 1803 err_print("Controller does not support defect management\n");
1802 1804 err_print("or disk supports automatic defect management.\n");
1803 1805 return (-1);
1804 1806 }
1805 1807 cur_menu++;
1806 1808 last_menu = cur_menu;
1807 1809
1808 1810 /*
1809 1811 * Lock out interrupt while we manipulate the defect lists.
1810 1812 */
1811 1813 enter_critical();
1812 1814 /*
1813 1815 * If the working list is null but there is a current list,
1814 1816 * update the working list to be a copy of the current list.
1815 1817 */
1816 1818 if ((work_list.list == NULL) && (cur_list.list != NULL)) {
1817 1819 work_list.header = cur_list.header;
1818 1820 work_list.list = (struct defect_entry *)zalloc(
1819 1821 deflist_size(cur_blksz, work_list.header.count) *
1820 1822 cur_blksz);
1821 1823 for (i = 0; i < work_list.header.count; i++)
1822 1824 *(work_list.list + i) = *(cur_list.list + i);
1823 1825 work_list.flags = cur_list.flags & LIST_PGLIST;
1824 1826 }
1825 1827 exit_critical();
1826 1828 /*
1827 1829 * Run the menu.
1828 1830 */
1829 1831 run_menu(menu_defect, "DEFECT", "defect", 0);
1830 1832 cur_menu--;
1831 1833
1832 1834 /*
1833 1835 * If the user has modified the working list but not committed
1834 1836 * it, warn him that he is probably making a mistake.
1835 1837 */
1836 1838 if (work_list.flags & LIST_DIRTY) {
1837 1839 if (!EMBEDDED_SCSI) {
1838 1840 err_print(
1839 1841 "Warning: working defect list modified; but not committed.\n");
1840 1842 if (!check(
1841 1843 "Do you wish to commit changes to current defect list"))
1842 1844 (void) do_commit();
1843 1845 }
1844 1846 }
1845 1847 return (0);
1846 1848 }
1847 1849
1848 1850 /*
1849 1851 * This routine implements the 'backup' command. It allows the user
1850 1852 * to search for backup labels on the current disk. This is useful
1851 1853 * if the primary label was lost and the user wishes to recover the
1852 1854 * partition information for the disk. The disk is relabeled and
1853 1855 * the current defect list is written out if a backup label is found.
1854 1856 */
1855 1857 int
1856 1858 c_backup()
1857 1859 {
1858 1860 struct dk_label label;
1859 1861 struct disk_type *dtype;
1860 1862 struct partition_info *parts, *plist;
1861 1863 diskaddr_t bn;
1862 1864 int sec, head, i;
1863 1865 char *buf;
1864 1866
1865 1867 /*
1866 1868 * There must be a current disk type (and therefore a current disk).
1867 1869 */
1868 1870 if (cur_dtype == NULL) {
1869 1871 err_print("Current Disk Type is not set.\n");
1870 1872 return (-1);
1871 1873 }
1872 1874 /*
1873 1875 * The disk must be formatted to read backup labels.
1874 1876 */
1875 1877 if (!(cur_flags & DISK_FORMATTED)) {
1876 1878 err_print("Current Disk is unformatted.\n");
1877 1879 return (-1);
1878 1880 }
1879 1881 /*
1880 1882 * Check for a valid fdisk table entry for Solaris
1881 1883 */
1882 1884 if (!good_fdisk()) {
1883 1885 return (-1);
1884 1886 }
1885 1887 /*
1886 1888 * If we found a primary label on this disk, make sure
1887 1889 * the user is serious.
1888 1890 */
1889 1891 if (cur_disk->label_type == L_TYPE_EFI) {
1890 1892 if (((cur_disk->disk_parts->etoc->efi_flags &
1891 1893 EFI_GPT_PRIMARY_CORRUPT) == 0) &&
1892 1894 check("Disk has a primary label, still continue"))
1893 1895 return (-1);
1894 1896 fmt_print("Restoring primary label.\n");
1895 1897 if (write_label()) {
1896 1898 err_print("Failed\n");
1897 1899 return (-1);
1898 1900 }
1899 1901 return (0);
1900 1902 } else if (((cur_disk->disk_flags & (DSK_LABEL | DSK_LABEL_DIRTY)) ==
1901 1903 DSK_LABEL) &&
1902 1904 (check("Disk has a primary label, still continue"))) {
1903 1905 return (-1);
1904 1906 }
1905 1907
1906 1908 buf = zalloc(cur_blksz);
1907 1909 fmt_print("Searching for backup labels...");
1908 1910 (void) fflush(stdout);
1909 1911
1910 1912 /*
1911 1913 * Some disks have the backup labels in a strange place.
1912 1914 */
1913 1915 if (cur_ctype->ctype_flags & CF_BLABEL)
1914 1916 head = 2;
1915 1917 else
1916 1918 head = nhead - 1;
1917 1919 /*
1918 1920 * Loop through each copy of the backup label.
1919 1921 */
1920 1922 for (sec = 1; ((sec < BAD_LISTCNT * 2 + 1) && (sec < nsect));
1921 1923 sec += 2) {
1922 1924 bn = chs2bn(ncyl + acyl - 1, head, sec) + solaris_offset;
1923 1925 /*
1924 1926 * Attempt to read it.
1925 1927 */
1926 1928 if ((*cur_ops->op_rdwr)(DIR_READ, cur_file, bn,
1927 1929 1, buf, F_NORMAL, NULL)) {
1928 1930 continue;
1929 1931 }
1930 1932
1931 1933 (void *) memcpy((char *)&label, buf, sizeof (struct dk_label));
1932 1934
1933 1935 /*
1934 1936 * Verify that it is a reasonable label.
1935 1937 */
1936 1938 if (!checklabel(&label))
1937 1939 continue;
1938 1940 if (trim_id(label.dkl_asciilabel))
1939 1941 continue;
1940 1942 /*
1941 1943 * Lock out interrupts while we manipulate lists.
1942 1944 */
1943 1945 enter_critical();
1944 1946 fmt_print("found.\n");
1945 1947 /*
1946 1948 * Find out which disk type the backup label claims.
1947 1949 */
1948 1950 for (dtype = cur_ctype->ctype_dlist; dtype != NULL;
1949 1951 dtype = dtype->dtype_next)
1950 1952 if (dtype_match(&label, dtype))
1951 1953 break;
1952 1954 /*
1953 1955 * If it disagrees with our current type, something
1954 1956 * real bad is happening.
1955 1957 */
1956 1958 if (dtype != cur_dtype) {
1957 1959 if (dtype == NULL) {
1958 1960 fmt_print("\
1959 1961 Unknown disk type in backup label\n");
1960 1962 exit_critical();
1961 1963 free(buf);
1962 1964 return (-1);
1963 1965 }
1964 1966 fmt_print("Backup label claims different type:\n");
1965 1967 fmt_print(" <%s cyl %d alt %d hd %d sec %d>\n",
1966 1968 label.dkl_asciilabel, label.dkl_ncyl,
1967 1969 label.dkl_acyl, label.dkl_nhead,
1968 1970 label.dkl_nsect);
1969 1971 if (check("Continue")) {
1970 1972 exit_critical();
1971 1973 free(buf);
1972 1974 return (-1);
1973 1975 }
1974 1976 cur_dtype = dtype;
1975 1977 }
1976 1978 /*
1977 1979 * Try to match the partition map with a known map.
1978 1980 */
1979 1981 for (parts = dtype->dtype_plist; parts != NULL;
1980 1982 parts = parts->pinfo_next)
1981 1983 if (parts_match(&label, parts))
1982 1984 break;
1983 1985 /*
1984 1986 * If we couldn't match it, allocate space for a new one,
1985 1987 * fill in the info, and add it to the list. The name
1986 1988 * for the new map is derived from the disk name.
1987 1989 */
1988 1990 if (parts == NULL) {
1989 1991 parts = (struct partition_info *)
1990 1992 zalloc(sizeof (struct partition_info));
1991 1993 plist = dtype->dtype_plist;
1992 1994 if (plist == NULL)
1993 1995 dtype->dtype_plist = parts;
1994 1996 else {
1995 1997 while (plist->pinfo_next != NULL)
1996 1998 plist = plist->pinfo_next;
1997 1999 plist->pinfo_next = parts;
1998 2000 }
1999 2001 parts->pinfo_name = alloc_string("original");
2000 2002 for (i = 0; i < NDKMAP; i++)
2001 2003
2002 2004 #if defined(_SUNOS_VTOC_8)
2003 2005 parts->pinfo_map[i] = label.dkl_map[i];
2004 2006
2005 2007 #elif defined(_SUNOS_VTOC_16)
2006 2008 parts->pinfo_map[i].dkl_cylno =
2007 2009 label.dkl_vtoc.v_part[i].p_start / spc();
2008 2010 parts->pinfo_map[i].dkl_nblk =
2009 2011 label.dkl_vtoc.v_part[i].p_size;
2010 2012 #else
2011 2013 #error No VTOC layout defined.
2012 2014 #endif /* defined(_SUNOS_VTOC_8) */
2013 2015 parts->vtoc = label.dkl_vtoc;
2014 2016 }
2015 2017 /*
2016 2018 * We now have a partition map. Make it the current map.
2017 2019 */
2018 2020 cur_disk->disk_parts = cur_parts = parts;
2019 2021 exit_critical();
2020 2022 /*
2021 2023 * Rewrite the labels and defect lists, as appropriate.
2022 2024 */
2023 2025 if (EMBEDDED_SCSI) {
2024 2026 fmt_print("Restoring primary label.\n");
2025 2027 if (write_label()) {
2026 2028 free(buf);
2027 2029 return (-1);
2028 2030 }
2029 2031 } else {
2030 2032 fmt_print("Restoring primary label and defect list.\n");
2031 2033 if (write_label()) {
2032 2034 free(buf);
2033 2035 return (-1);
2034 2036 }
2035 2037 if (cur_list.list != NULL)
2036 2038 write_deflist(&cur_list);
2037 2039 }
2038 2040 fmt_print("\n");
2039 2041 free(buf);
2040 2042 return (0);
2041 2043 }
2042 2044 /*
2043 2045 * If we didn't find any backup labels, say so.
2044 2046 */
2045 2047 fmt_print("not found.\n\n");
2046 2048 free(buf);
2047 2049 return (0);
2048 2050 }
2049 2051
2050 2052 /*
2051 2053 * This routine is called by c_verify() for an EFI labeled disk
2052 2054 */
2053 2055 static int
2054 2056 c_verify_efi()
2055 2057 {
2056 2058 struct efi_info efi_info;
2057 2059 struct partition_info tmp_pinfo;
2058 2060 int status;
2059 2061
2060 2062 status = read_efi_label(cur_file, &efi_info, cur_disk);
2061 2063 if (status != 0) {
2062 2064 err_print("Warning: Could not read label.\n");
2063 2065 return (-1);
2064 2066 }
2065 2067 if (cur_parts->etoc->efi_flags & EFI_GPT_PRIMARY_CORRUPT) {
2066 2068 err_print("Reading the primary EFI GPT label ");
2067 2069 err_print("failed. Using backup label.\n");
2068 2070 err_print("Use the 'backup' command to restore ");
2069 2071 err_print("the primary label.\n");
2070 2072 }
2071 2073 tmp_pinfo.etoc = efi_info.e_parts;
2072 2074 fmt_print("\n");
2073 2075 if (cur_parts->etoc->efi_parts[8].p_name) {
2074 2076 fmt_print("Volume name = <%8s>\n",
2075 2077 cur_parts->etoc->efi_parts[8].p_name);
2076 2078 } else {
2077 2079 fmt_print("Volume name = < >\n");
2078 2080 }
2079 2081 fmt_print("ascii name = ");
2080 2082 print_efi_string(efi_info.vendor, efi_info.product,
2081 2083 efi_info.revision, efi_info.capacity);
2082 2084 fmt_print("\n");
2083 2085
2084 2086 fmt_print("bytes/sector = %d\n", cur_blksz);
2085 2087 fmt_print("sectors = %llu\n", cur_parts->etoc->efi_last_lba);
2086 2088 fmt_print("accessible sectors = %llu\n",
2087 2089 cur_parts->etoc->efi_last_u_lba);
2088 2090
2089 2091 print_map(&tmp_pinfo);
2090 2092
2091 2093 free(efi_info.vendor);
2092 2094 free(efi_info.product);
2093 2095 free(efi_info.revision);
2094 2096 return (0);
2095 2097 }
2096 2098
2097 2099 /*
2098 2100 * This routine implements the 'verify' command. It allows the user
2099 2101 * to read the labels on the current disk.
2100 2102 */
2101 2103 int
2102 2104 c_verify()
2103 2105 {
2104 2106 struct dk_label p_label, b_label, *label;
2105 2107 struct partition_info tmp_pinfo;
2106 2108 diskaddr_t bn;
2107 2109 int sec, head, i, status;
2108 2110 int p_label_bad = 0;
2109 2111 int b_label_bad = 0;
2110 2112 int p_label_found = 0;
2111 2113 int b_label_found = 0;
2112 2114 char id_str[128];
2113 2115 char *buf;
2114 2116
2115 2117 /*
2116 2118 * There must be a current disk type (and therefore a current disk).
2117 2119 */
2118 2120 if (cur_dtype == NULL) {
2119 2121 err_print("Current Disk Type is not set.\n");
2120 2122 return (-1);
2121 2123 }
2122 2124 /*
2123 2125 * The disk must be formatted to read labels.
2124 2126 */
2125 2127 if (!(cur_flags & DISK_FORMATTED)) {
2126 2128 err_print("Current Disk is unformatted.\n");
2127 2129 return (-1);
2128 2130 }
2129 2131 /*
2130 2132 * Check for a valid fdisk table entry for Solaris
2131 2133 */
2132 2134 if (!good_fdisk()) {
2133 2135 return (-1);
2134 2136 }
2135 2137 /*
2136 2138 * Branch off here if the disk is EFI labelled.
2137 2139 */
2138 2140 if (cur_label == L_TYPE_EFI) {
2139 2141 return (c_verify_efi());
2140 2142 }
2141 2143 /*
2142 2144 * Attempt to read the primary label.
2143 2145 */
2144 2146 status = read_label(cur_file, &p_label);
2145 2147 if (status == -1) {
2146 2148 err_print("Warning: Could not read primary label.\n");
2147 2149 p_label_bad = 1;
2148 2150 } else {
2149 2151 /*
2150 2152 * Verify that it is a reasonable label.
2151 2153 */
2152 2154 /*
2153 2155 * Save complete ascii string for printing later.
2154 2156 */
2155 2157 (void) strncpy(id_str, p_label.dkl_asciilabel, 128);
2156 2158
2157 2159 if ((!checklabel((struct dk_label *)&p_label)) ||
2158 2160 (trim_id(p_label.dkl_asciilabel))) {
2159 2161 err_print("\
2160 2162 Warning: Primary label appears to be corrupt.\n");
2161 2163 p_label_bad = 1;
2162 2164 } else {
2163 2165 p_label_found = 1;
2164 2166 /*
2165 2167 * Make sure it matches current label
2166 2168 */
2167 2169 if ((!dtype_match(&p_label, cur_dtype)) ||
2168 2170 (!parts_match(&p_label, cur_parts))) {
2169 2171 err_print("\
2170 2172 Warning: Primary label on disk appears to be different from\ncurrent label.\n");
2171 2173 p_label_bad = 1;
2172 2174 }
2173 2175 }
2174 2176 }
2175 2177
2176 2178 /*
2177 2179 * Read backup labels.
2178 2180 * Some disks have the backup labels in a strange place.
2179 2181 */
2180 2182 if (cur_ctype->ctype_flags & CF_BLABEL)
2181 2183 head = 2;
2182 2184 else
2183 2185 head = nhead - 1;
2184 2186
2185 2187 buf = zalloc(cur_blksz);
2186 2188 /*
2187 2189 * Loop through each copy of the backup label.
2188 2190 */
2189 2191 for (sec = 1; ((sec < BAD_LISTCNT * 2 + 1) && (sec < nsect));
2190 2192 sec += 2) {
2191 2193 bn = chs2bn(ncyl + acyl - 1, head, sec) + solaris_offset;
2192 2194 /*
2193 2195 * Attempt to read it.
2194 2196 */
2195 2197 if ((*cur_ops->op_rdwr)(DIR_READ, cur_file, bn,
2196 2198 1, buf, F_NORMAL, NULL))
2197 2199 continue;
2198 2200
2199 2201 (void *) memcpy((char *)&b_label, buf,
2200 2202 sizeof (struct dk_label));
2201 2203
2202 2204 /*
2203 2205 * Verify that it is a reasonable label.
2204 2206 */
2205 2207 if (!checklabel(&b_label))
2206 2208 continue;
2207 2209
2208 2210 /*
2209 2211 * Save complete label only if no primary label exists
2210 2212 */
2211 2213 if (!p_label_found)
2212 2214 (void) strncpy(id_str, b_label.dkl_asciilabel, 128);
2213 2215
2214 2216 if (trim_id(b_label.dkl_asciilabel))
2215 2217 continue;
2216 2218 b_label_found = 1;
2217 2219 /*
2218 2220 * Compare against primary label
2219 2221 */
2220 2222 if (p_label_found) {
2221 2223 if ((strcmp(b_label.dkl_asciilabel,
2222 2224 p_label.dkl_asciilabel) != 0) ||
2223 2225 (b_label.dkl_ncyl != p_label.dkl_ncyl) ||
2224 2226 (b_label.dkl_acyl != p_label.dkl_acyl) ||
2225 2227 (b_label.dkl_nhead != p_label.dkl_nhead) ||
2226 2228 (b_label.dkl_nsect != p_label.dkl_nsect)) {
2227 2229 b_label_bad = 1;
2228 2230 } else {
2229 2231 for (i = 0; i < NDKMAP; i++) {
2230 2232 #if defined(_SUNOS_VTOC_8)
2231 2233 if ((b_label.dkl_map[i].dkl_cylno !=
2232 2234 p_label.dkl_map[i].dkl_cylno) ||
2233 2235 (b_label.dkl_map[i].dkl_nblk !=
2234 2236 p_label.dkl_map[i].dkl_nblk)) {
2235 2237 b_label_bad = 1;
2236 2238 break;
2237 2239 }
2238 2240
2239 2241 #elif defined(_SUNOS_VTOC_16)
2240 2242 if ((b_label.dkl_vtoc.v_part[i].p_tag !=
2241 2243 p_label.dkl_vtoc.v_part[i].p_tag) ||
2242 2244 (b_label.dkl_vtoc.v_part[i].p_flag
2243 2245 != p_label.dkl_vtoc.v_part[i].
2244 2246 p_flag) ||
2245 2247 (b_label.dkl_vtoc.v_part[i].p_start
2246 2248 != p_label.dkl_vtoc.v_part[i].
2247 2249 p_start) ||
2248 2250 (b_label.dkl_vtoc.v_part[i].p_size
2249 2251 != p_label.dkl_vtoc.v_part[i].
2250 2252 p_size)) {
2251 2253 b_label_bad = 1;
2252 2254 break;
2253 2255 }
2254 2256 #else
2255 2257 #error No VTOC layout defined.
2256 2258 #endif /* defined(_SUNOS_VTOC_8) */
2257 2259 }
2258 2260 }
2259 2261 }
2260 2262 if (b_label_bad)
2261 2263 err_print(
2262 2264 "Warning: Primary and backup labels do not match.\n");
2263 2265 break;
2264 2266 }
2265 2267 /*
2266 2268 * If we didn't find any backup labels, say so.
2267 2269 */
2268 2270 if (!b_label_found)
2269 2271 err_print("Warning: Could not read backup labels.\n");
2270 2272
2271 2273 if ((!b_label_found) || (p_label_bad) || (b_label_bad))
2272 2274 err_print("\n\
2273 2275 Warning: Check the current partitioning and 'label' the disk or use the\n\
2274 2276 \t 'backup' command.\n");
2275 2277
2276 2278 /*
2277 2279 * Print label information.
2278 2280 */
2279 2281 if (p_label_found) {
2280 2282 fmt_print("\nPrimary label contents:\n");
2281 2283 label = &p_label;
2282 2284 } else if (b_label_found) {
2283 2285 fmt_print("\nBackup label contents:\n");
2284 2286 label = &b_label;
2285 2287 } else {
2286 2288 free(buf);
2287 2289 return (0);
2288 2290 }
2289 2291
2290 2292 /*
2291 2293 * Must put info into partition_info struct for
2292 2294 * for print routine.
2293 2295 */
2294 2296 bzero(&tmp_pinfo, sizeof (struct partition_info));
2295 2297 for (i = 0; i < NDKMAP; i++) {
2296 2298
2297 2299 #if defined(_SUNOS_VTOC_8)
2298 2300 tmp_pinfo.pinfo_map[i] = label->dkl_map[i];
2299 2301
2300 2302 #elif defined(_SUNOS_VTOC_16)
2301 2303 tmp_pinfo.pinfo_map[i].dkl_cylno =
2302 2304 label->dkl_vtoc.v_part[i].p_start / spc();
2303 2305 tmp_pinfo.pinfo_map[i].dkl_nblk =
2304 2306 label->dkl_vtoc.v_part[i].p_size;
2305 2307 #else
2306 2308 #error No VTOC layout defined.
2307 2309 #endif /* defined(_SUNOS_VTOC_8) */
2308 2310 }
2309 2311 tmp_pinfo.vtoc = label->dkl_vtoc;
2310 2312
2311 2313 fmt_print("\n");
2312 2314 fmt_print("Volume name = <%8s>\n", label->dkl_vtoc.v_volume);
2313 2315 fmt_print("ascii name = <%s>\n", id_str);
2314 2316 fmt_print("pcyl = %4d\n", label->dkl_pcyl);
2315 2317 fmt_print("ncyl = %4d\n", label->dkl_ncyl);
2316 2318 fmt_print("acyl = %4d\n", label->dkl_acyl);
2317 2319
2318 2320 #if defined(_SUNOS_VTOC_16)
2319 2321 fmt_print("bcyl = %4d\n", label->dkl_bcyl);
2320 2322 #endif /* defined(_SUNOS_VTOC_16) */
2321 2323
2322 2324 fmt_print("nhead = %4d\n", label->dkl_nhead);
2323 2325 fmt_print("nsect = %4d\n", label->dkl_nsect);
2324 2326
2325 2327 print_map(&tmp_pinfo);
2326 2328 free(buf);
2327 2329 return (0);
2328 2330 }
2329 2331
2330 2332
2331 2333 /*
2332 2334 * This command implements the inquiry command, for embedded SCSI
2333 2335 * disks only, which issues a SCSI inquiry command, and
2334 2336 * displays the resulting vendor, product id and revision level.
2335 2337 */
2336 2338 int
2337 2339 c_inquiry()
2338 2340 {
2339 2341 char inqbuf[255];
2340 2342 struct scsi_inquiry *inq;
2341 2343
2342 2344 assert(SCSI);
2343 2345
2344 2346 inq = (struct scsi_inquiry *)inqbuf;
2345 2347
2346 2348 if (uscsi_inquiry(cur_file, inqbuf, sizeof (inqbuf))) {
2347 2349 err_print("Failed\n");
2348 2350 return (-1);
2349 2351 } else {
2350 2352 fmt_print("Vendor: ");
2351 2353 print_buf(inq->inq_vid, sizeof (inq->inq_vid));
2352 2354 fmt_print("\nProduct: ");
2353 2355 print_buf(inq->inq_pid, sizeof (inq->inq_pid));
2354 2356 fmt_print("\nRevision: ");
2355 2357 print_buf(inq->inq_revision, sizeof (inq->inq_revision));
2356 2358 fmt_print("\n");
2357 2359 }
2358 2360
2359 2361 return (0);
2360 2362 }
2361 2363
2362 2364
2363 2365 /*
2364 2366 * This routine allows the user to set the 8-character
2365 2367 * volume name in the vtoc. It then writes both the
2366 2368 * primary and backup labels onto the current disk.
2367 2369 */
2368 2370 int
2369 2371 c_volname()
2370 2372 {
2371 2373 int status;
2372 2374 char *prompt;
2373 2375 union {
2374 2376 int xfoo;
2375 2377 char defvolname[LEN_DKL_VVOL+1];
2376 2378 } x;
2377 2379 char s1[MAXPATHLEN], nclean[MAXPATHLEN];
2378 2380 char *volname;
2379 2381
2380 2382
2381 2383 /*
2382 2384 * There must be a current disk type (and therefore a current disk).
2383 2385 */
2384 2386 if (cur_dtype == NULL) {
2385 2387 err_print("Current Disk Type is not set.\n");
2386 2388 return (-1);
2387 2389 }
2388 2390 /*
2389 2391 * The current disk must be formatted to label it.
2390 2392 */
2391 2393 if (!(cur_flags & DISK_FORMATTED)) {
2392 2394 err_print("Current Disk is unformatted.\n");
2393 2395 return (-1);
2394 2396 }
2395 2397 /*
2396 2398 * Check for a valid fdisk table entry for Solaris
2397 2399 */
2398 2400 if (!good_fdisk()) {
2399 2401 return (-1);
2400 2402 }
2401 2403 /*
2402 2404 * The current disk must be formatted to label it.
2403 2405 */
2404 2406 if (cur_parts == NULL) {
2405 2407 err_print(
2406 2408 "Please select a partition map for the disk first.\n");
2407 2409 return (-1);
2408 2410 }
2409 2411
2410 2412 /*
2411 2413 * Check to see if there are any mounted file systems anywhere
2412 2414 * on the current disk. If so, refuse to label the disk, but
2413 2415 * only if the partitions would change for the mounted partitions.
2414 2416 *
2415 2417 */
2416 2418 if (checkmount((diskaddr_t)-1, (diskaddr_t)-1)) {
2417 2419 /* Bleagh, too descriptive */
2418 2420 if (check_label_with_mount()) {
2419 2421 err_print(
2420 2422 "Cannot label disk while it has mounted partitions.\n\n");
2421 2423 return (-1);
2422 2424 }
2423 2425 }
2424 2426
2425 2427 /*
2426 2428 * Check to see if there are partitions being used for swapping
2427 2429 * on the current disk. If so, refuse to label the disk, but
2428 2430 * only if the partitions would change for the swap partitions.
2429 2431 *
2430 2432 */
2431 2433 if (checkswap((diskaddr_t)-1, (diskaddr_t)-1)) {
2432 2434 /* Bleagh, too descriptive */
2433 2435 if (check_label_with_swap()) {
2434 2436 err_print(
2435 2437 "Cannot label disk while its partitions are currently \
2436 2438 being used for swapping.\n\n");
2437 2439 return (-1);
2438 2440 }
2439 2441 }
2440 2442
2441 2443 /*
2442 2444 * Check to see if any partitions used for svm, vxvm, ZFS zpool
2443 2445 * or live upgrade are on the disk. If so, refuse to label the
2444 2446 * disk, but only if we are trying to shrink a partition in
2445 2447 * use.
2446 2448 */
2447 2449 if (checkdevinuse(cur_disk->disk_name, (diskaddr_t)-1,
2448 2450 (diskaddr_t)-1, 0, 1)) {
2449 2451 err_print("Cannot label disk while its partitions "
2450 2452 "are in use as described.\n");
2451 2453 return (-1);
2452 2454 }
2453 2455
2454 2456 /*
2455 2457 * Prompt for the disk volume name.
2456 2458 */
2457 2459 prompt = "Enter 8-character volume name (remember quotes)";
2458 2460 bzero(x.defvolname, LEN_DKL_VVOL+1);
2459 2461 bcopy(cur_disk->v_volume, x.defvolname, LEN_DKL_VVOL);
2460 2462 /*
2461 2463 * Get the input using "get_inputline" since
2462 2464 * input would never return null string.
2463 2465 */
2464 2466 fmt_print("%s[\"%s\"]:", prompt, x.defvolname);
2465 2467
2466 2468 /*
2467 2469 * Get input from the user.
2468 2470 */
2469 2471 get_inputline(nclean, MAXPATHLEN);
2470 2472 clean_token(s1, nclean);
2471 2473 /*
2472 2474 * check for return.
2473 2475 */
2474 2476 if (s1[0] == 0) {
2475 2477 volname = x.defvolname;
2476 2478 } else {
2477 2479 /*
2478 2480 * remove the " mark from volname.
2479 2481 */
2480 2482 if (s1[0] == '"') {
2481 2483 int i = 1;
2482 2484 volname = &s1[1];
2483 2485 while (s1[i] != '"' && s1[i] != '\0')
2484 2486 i++;
2485 2487 s1[i] = '\0';
2486 2488 clean_token(nclean, volname);
2487 2489 volname = nclean;
2488 2490 } else {
2489 2491 (void) sscanf(&s1[0], "%1024s", nclean);
2490 2492 volname = nclean;
2491 2493 };
2492 2494 }
2493 2495 /*
2494 2496 * Make sure the user is serious.
2495 2497 */
2496 2498 if (check("Ready to label disk, continue")) {
2497 2499 fmt_print("\n");
2498 2500 return (-1);
2499 2501 }
2500 2502 /*
2501 2503 * Use the volume name chosen above
2502 2504 */
2503 2505 bzero(cur_disk->v_volume, LEN_DKL_VVOL);
2504 2506 bcopy(volname, cur_disk->v_volume, min((int)strlen(volname),
2505 2507 LEN_DKL_VVOL));
2506 2508 if (cur_label == L_TYPE_EFI) {
2507 2509 bzero(cur_parts->etoc->efi_parts[8].p_name, LEN_DKL_VVOL);
2508 2510 bcopy(volname, cur_parts->etoc->efi_parts[8].p_name,
2509 2511 LEN_DKL_VVOL);
2510 2512 }
2511 2513 /*
2512 2514 * Write the labels out (this will also notify unix) and
2513 2515 * return status.
2514 2516 */
2515 2517 fmt_print("\n");
2516 2518 if (status = write_label())
2517 2519 err_print("Label failed.\n");
2518 2520 return (status);
2519 2521 }
↓ open down ↓ |
885 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX