xref: /titanic_52/usr/src/cmd/format/menu_defect.c (revision 65908c77dfc02644236ba18bffe67b5ed6f23135)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5342440ecSPrasad Singamsetty  * Common Development and Distribution License (the "License").
6342440ecSPrasad Singamsetty  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*65908c77Syu, larry liu - Sun Microsystems - Beijing China  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * This file contains functions to implement the defect menu commands.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate #include "global.h"
307c478bd9Sstevel@tonic-gate #include <unistd.h>
317c478bd9Sstevel@tonic-gate #include <string.h>
327c478bd9Sstevel@tonic-gate #include "misc.h"
337c478bd9Sstevel@tonic-gate #include "menu_defect.h"
347c478bd9Sstevel@tonic-gate #include "param.h"
357c478bd9Sstevel@tonic-gate #include "ctlr_scsi.h"
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * This is the working defect list.  All the commands here operate on
397c478bd9Sstevel@tonic-gate  * the working list, except for 'commit'.  This way the user can
407c478bd9Sstevel@tonic-gate  * change his mind at any time without having mangled the current defect
417c478bd9Sstevel@tonic-gate  * list.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate struct	defect_list work_list;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #ifdef __STDC__
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /* Function prototypes for ANSI C Compilers */
487c478bd9Sstevel@tonic-gate static int	commit_list(void);
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /* Function prototypes for non-ANSI C Compilers */
537c478bd9Sstevel@tonic-gate static int	commit_list();
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * This routine implements the 'restore' command.  It sets the working
597c478bd9Sstevel@tonic-gate  * list equal to the current list.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate int
627c478bd9Sstevel@tonic-gate d_restore()
637c478bd9Sstevel@tonic-gate {
647c478bd9Sstevel@tonic-gate 	int	i;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	assert(!EMBEDDED_SCSI);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 	/*
697c478bd9Sstevel@tonic-gate 	 * If the working list has not been modified, there's nothing to do.
707c478bd9Sstevel@tonic-gate 	 */
717c478bd9Sstevel@tonic-gate 	if (!(work_list.flags & LIST_DIRTY)) {
727c478bd9Sstevel@tonic-gate 		err_print("working list was not modified.\n");
737c478bd9Sstevel@tonic-gate 		return (0);
747c478bd9Sstevel@tonic-gate 	}
757c478bd9Sstevel@tonic-gate 	/*
767c478bd9Sstevel@tonic-gate 	 * Make sure the user is serious.
777c478bd9Sstevel@tonic-gate 	 */
787c478bd9Sstevel@tonic-gate 	if (check("Ready to update working list, continue"))
797c478bd9Sstevel@tonic-gate 		return (-1);
807c478bd9Sstevel@tonic-gate 	/*
817c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so the lists can't get mangled.
827c478bd9Sstevel@tonic-gate 	 */
837c478bd9Sstevel@tonic-gate 	enter_critical();
847c478bd9Sstevel@tonic-gate 	/*
857c478bd9Sstevel@tonic-gate 	 * Kill off the old working list.
867c478bd9Sstevel@tonic-gate 	 */
877c478bd9Sstevel@tonic-gate 	kill_deflist(&work_list);
887c478bd9Sstevel@tonic-gate 	/*
897c478bd9Sstevel@tonic-gate 	 * If the current isn't null, set the working list to be a
907c478bd9Sstevel@tonic-gate 	 * copy of it.
917c478bd9Sstevel@tonic-gate 	 */
927c478bd9Sstevel@tonic-gate 	if (cur_list.list != NULL) {
937c478bd9Sstevel@tonic-gate 		work_list.header = cur_list.header;
947c478bd9Sstevel@tonic-gate 		work_list.list = (struct defect_entry *)zalloc(
95*65908c77Syu, larry liu - Sun Microsystems - Beijing China 		    deflist_size(cur_blksz, work_list.header.count) *
96*65908c77Syu, larry liu - Sun Microsystems - Beijing China 		    cur_blksz);
977c478bd9Sstevel@tonic-gate 		for (i = 0; i < work_list.header.count; i++)
987c478bd9Sstevel@tonic-gate 			*(work_list.list + i) = *(cur_list.list + i);
997c478bd9Sstevel@tonic-gate 	}
1007c478bd9Sstevel@tonic-gate 	/*
1017c478bd9Sstevel@tonic-gate 	 * Initialize the flags since they are now in sync.
1027c478bd9Sstevel@tonic-gate 	 */
1037c478bd9Sstevel@tonic-gate 	work_list.flags = 0;
1047c478bd9Sstevel@tonic-gate 	if (work_list.list == NULL)
1057c478bd9Sstevel@tonic-gate 		fmt_print("working list set to null.\n\n");
1067c478bd9Sstevel@tonic-gate 	else
1077c478bd9Sstevel@tonic-gate 		fmt_print("working list updated, total of %d defects.\n\n",
1087c478bd9Sstevel@tonic-gate 		    work_list.header.count);
1097c478bd9Sstevel@tonic-gate 	exit_critical();
1107c478bd9Sstevel@tonic-gate 	return (0);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * This routine implements the 'original' command.  It extracts the
1157c478bd9Sstevel@tonic-gate  * manufacturer's defect list from the current disk.
1167c478bd9Sstevel@tonic-gate  */
1177c478bd9Sstevel@tonic-gate int
1187c478bd9Sstevel@tonic-gate d_original()
1197c478bd9Sstevel@tonic-gate {
1207c478bd9Sstevel@tonic-gate 	int	status;
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	/*
1247c478bd9Sstevel@tonic-gate 	 * If the controller does not support the extraction, we're out
1257c478bd9Sstevel@tonic-gate 	 * of luck.
1267c478bd9Sstevel@tonic-gate 	 */
1277c478bd9Sstevel@tonic-gate 	if (cur_ops->op_ex_man == NULL) {
1287c478bd9Sstevel@tonic-gate 		err_print("Controller does not support extracting ");
1297c478bd9Sstevel@tonic-gate 		err_print("manufacturer's defect list.\n");
1307c478bd9Sstevel@tonic-gate 		return (-1);
1317c478bd9Sstevel@tonic-gate 	}
1327c478bd9Sstevel@tonic-gate 	/*
1337c478bd9Sstevel@tonic-gate 	 * Make sure the user is serious.  Note, for SCSI disks
1347c478bd9Sstevel@tonic-gate 	 * since this is instantaneous, we will just do it and
1357c478bd9Sstevel@tonic-gate 	 * not ask for confirmation.
1367c478bd9Sstevel@tonic-gate 	 */
1377c478bd9Sstevel@tonic-gate 	if (!(cur_ctype->ctype_flags & CF_CONFIRM) &&
1387c478bd9Sstevel@tonic-gate 	    check(
1397c478bd9Sstevel@tonic-gate "Ready to update working list. This cannot be interrupted\n\
1407c478bd9Sstevel@tonic-gate and may take a long while. Continue"))
1417c478bd9Sstevel@tonic-gate 		return (-1);
1427c478bd9Sstevel@tonic-gate 	/*
1437c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so we don't get half the list.
1447c478bd9Sstevel@tonic-gate 	 */
1457c478bd9Sstevel@tonic-gate 	enter_critical();
1467c478bd9Sstevel@tonic-gate 	/*
1477c478bd9Sstevel@tonic-gate 	 * Kill off the working list.
1487c478bd9Sstevel@tonic-gate 	 */
1497c478bd9Sstevel@tonic-gate 	kill_deflist(&work_list);
1507c478bd9Sstevel@tonic-gate 	fmt_print("Extracting manufacturer's defect list...");
1517c478bd9Sstevel@tonic-gate 	/*
1527c478bd9Sstevel@tonic-gate 	 * Do the extraction.
1537c478bd9Sstevel@tonic-gate 	 */
1547c478bd9Sstevel@tonic-gate 	status = (*cur_ops->op_ex_man)(&work_list);
1557c478bd9Sstevel@tonic-gate 	if (status)
1567c478bd9Sstevel@tonic-gate 		fmt_print("Extraction failed.\n\n");
1577c478bd9Sstevel@tonic-gate 	else {
1587c478bd9Sstevel@tonic-gate 		fmt_print("Extraction complete.\n");
1597c478bd9Sstevel@tonic-gate 		fmt_print("Working list updated, total of %d defects.\n\n",
1607c478bd9Sstevel@tonic-gate 		    work_list.header.count);
1617c478bd9Sstevel@tonic-gate 	}
1627c478bd9Sstevel@tonic-gate 	/*
1637c478bd9Sstevel@tonic-gate 	 * Mark the working list dirty since we modified it.
1647c478bd9Sstevel@tonic-gate 	 */
1657c478bd9Sstevel@tonic-gate 	work_list.flags |= LIST_DIRTY;
1667c478bd9Sstevel@tonic-gate 	exit_critical();
1677c478bd9Sstevel@tonic-gate 	/*
1687c478bd9Sstevel@tonic-gate 	 * Return status.
1697c478bd9Sstevel@tonic-gate 	 */
1707c478bd9Sstevel@tonic-gate 	return (status);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate  * This routine implements the 'extract' command.  It extracts the
1757c478bd9Sstevel@tonic-gate  * entire defect list from the current disk.
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate int
1787c478bd9Sstevel@tonic-gate d_extract()
1797c478bd9Sstevel@tonic-gate {
1807c478bd9Sstevel@tonic-gate 	int	status;
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	/*
1837c478bd9Sstevel@tonic-gate 	 * If the controller does not support the extraction, we are out
1847c478bd9Sstevel@tonic-gate 	 * of luck.
1857c478bd9Sstevel@tonic-gate 	 */
1867c478bd9Sstevel@tonic-gate 	if (cur_ops->op_ex_cur == NULL) {
1877c478bd9Sstevel@tonic-gate 		err_print("Controller does not support extracting ");
1887c478bd9Sstevel@tonic-gate 		err_print("current defect list.\n");
1897c478bd9Sstevel@tonic-gate 		return (-1);
1907c478bd9Sstevel@tonic-gate 	}
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	/*
1937c478bd9Sstevel@tonic-gate 	 * If disk is unformatted, you really shouldn't do this.
1947c478bd9Sstevel@tonic-gate 	 * However, ask user to be sure.
1957c478bd9Sstevel@tonic-gate 	 */
1967c478bd9Sstevel@tonic-gate 	if (! (cur_flags & DISK_FORMATTED) &&
1977c478bd9Sstevel@tonic-gate 	    (check(
1987c478bd9Sstevel@tonic-gate "Cannot extract defect list from an unformatted disk. Continue")))
1997c478bd9Sstevel@tonic-gate 		return (-1);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	/*
2027c478bd9Sstevel@tonic-gate 	 * If this takes a long time, let's ask the user if he
2037c478bd9Sstevel@tonic-gate 	 * doesn't mind waiting.  Note, for SCSI disks
2047c478bd9Sstevel@tonic-gate 	 * this operation is instantaneous so we won't ask for
2057c478bd9Sstevel@tonic-gate 	 * for confirmation.
2067c478bd9Sstevel@tonic-gate 	 */
2077c478bd9Sstevel@tonic-gate 	if (! (cur_ctype->ctype_flags & CF_CONFIRM) &&
2087c478bd9Sstevel@tonic-gate 	    check(
2097c478bd9Sstevel@tonic-gate "Ready to extract working list. This cannot be interrupted\n\
2107c478bd9Sstevel@tonic-gate and may take a long while. Continue"))
2117c478bd9Sstevel@tonic-gate 		return (-1);
2127c478bd9Sstevel@tonic-gate 	/*
2137c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so we don't get half the list and
2147c478bd9Sstevel@tonic-gate 	 * Kill off the working list.
2157c478bd9Sstevel@tonic-gate 	 */
2167c478bd9Sstevel@tonic-gate 	enter_critical();
2177c478bd9Sstevel@tonic-gate 	kill_deflist(&work_list);
2187c478bd9Sstevel@tonic-gate 	fmt_print("Extracting defect list...");
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	/*
2217c478bd9Sstevel@tonic-gate 	 * Do the extraction.
2227c478bd9Sstevel@tonic-gate 	 */
2237c478bd9Sstevel@tonic-gate 	status = (*cur_ops->op_ex_cur)(&work_list);
2247c478bd9Sstevel@tonic-gate 	if (status) {
2257c478bd9Sstevel@tonic-gate 		if (!EMBEDDED_SCSI) {
2267c478bd9Sstevel@tonic-gate 			if (cur_flags & DISK_FORMATTED)
2277c478bd9Sstevel@tonic-gate 				read_list(&work_list);
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 			if (work_list.list != NULL) {
2307c478bd9Sstevel@tonic-gate 				status = 0;
2317c478bd9Sstevel@tonic-gate 				fmt_print("Extraction complete.\n");
2327c478bd9Sstevel@tonic-gate 				fmt_print(
2337c478bd9Sstevel@tonic-gate "Working list updated, total of %d defects.\n\n",
2347c478bd9Sstevel@tonic-gate 				    work_list.header.count);
2357c478bd9Sstevel@tonic-gate 			} else {
2367c478bd9Sstevel@tonic-gate 				fmt_print("Extraction failed.\n\n");
2377c478bd9Sstevel@tonic-gate 			}
2387c478bd9Sstevel@tonic-gate 		} else {
2397c478bd9Sstevel@tonic-gate 			fmt_print("Extraction failed.\n\n");
2407c478bd9Sstevel@tonic-gate 		}
2417c478bd9Sstevel@tonic-gate 	} else {
2427c478bd9Sstevel@tonic-gate 		fmt_print("Extraction complete.\n");
2437c478bd9Sstevel@tonic-gate 		fmt_print("Working list updated, total of %d defects.\n\n",
2447c478bd9Sstevel@tonic-gate 		    work_list.header.count);
2457c478bd9Sstevel@tonic-gate 	}
2467c478bd9Sstevel@tonic-gate 	/*
2477c478bd9Sstevel@tonic-gate 	 * Mark the working list dirty since we modified it.
2487c478bd9Sstevel@tonic-gate 	 */
2497c478bd9Sstevel@tonic-gate 	work_list.flags |= LIST_DIRTY;
2507c478bd9Sstevel@tonic-gate 	exit_critical();
2517c478bd9Sstevel@tonic-gate 	/*
2527c478bd9Sstevel@tonic-gate 	 * Return status.
2537c478bd9Sstevel@tonic-gate 	 */
2547c478bd9Sstevel@tonic-gate 	return (status);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate  * This routine implements the 'add' command.  It allows the user to
2597c478bd9Sstevel@tonic-gate  * enter the working defect list manually.  It loops infinitely until
2607c478bd9Sstevel@tonic-gate  * the user breaks out with a ctrl-C.
2617c478bd9Sstevel@tonic-gate  */
2627c478bd9Sstevel@tonic-gate int
2637c478bd9Sstevel@tonic-gate d_add()
2647c478bd9Sstevel@tonic-gate {
265342440ecSPrasad Singamsetty 	int			type, deflt, index;
266342440ecSPrasad Singamsetty 	diskaddr_t		bn;
2677c478bd9Sstevel@tonic-gate 	u_ioparam_t		ioparam;
2687c478bd9Sstevel@tonic-gate 	struct defect_entry	def;
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	assert(!EMBEDDED_SCSI);
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	/*
2737c478bd9Sstevel@tonic-gate 	 * Ask the user which mode of input he'd like to use.
2747c478bd9Sstevel@tonic-gate 	 */
2757c478bd9Sstevel@tonic-gate 	fmt_print("        0. bytes-from-index\n");
2767c478bd9Sstevel@tonic-gate 	fmt_print("        1. logical block\n");
2777c478bd9Sstevel@tonic-gate 	deflt = 0;
2787c478bd9Sstevel@tonic-gate 	ioparam.io_bounds.lower = 0;
2797c478bd9Sstevel@tonic-gate 	ioparam.io_bounds.upper = 1;
2807c478bd9Sstevel@tonic-gate 	type = input(FIO_INT, "Select input format (enter its number)", ':',
2817c478bd9Sstevel@tonic-gate 	    &ioparam, &deflt, DATA_INPUT);
2827c478bd9Sstevel@tonic-gate 	fmt_print("\nEnter Control-C to terminate.\n");
2837c478bd9Sstevel@tonic-gate loop:
2847c478bd9Sstevel@tonic-gate 	if (type) {
2857c478bd9Sstevel@tonic-gate 		/*
2867c478bd9Sstevel@tonic-gate 		 * Mode selected is logical block.  Input the defective block
2877c478bd9Sstevel@tonic-gate 		 * and fill in the defect entry with the info.
2887c478bd9Sstevel@tonic-gate 		 */
2897c478bd9Sstevel@tonic-gate 		def.bfi = def.nbits = UNKNOWN;
2907c478bd9Sstevel@tonic-gate 		ioparam.io_bounds.lower = 0;
2917c478bd9Sstevel@tonic-gate 		if (cur_disk->label_type == L_TYPE_SOLARIS) {
2927c478bd9Sstevel@tonic-gate 			ioparam.io_bounds.upper = physsects() - 1;
2937c478bd9Sstevel@tonic-gate 		} else {
2947c478bd9Sstevel@tonic-gate 			ioparam.io_bounds.upper = cur_parts->etoc->efi_last_lba;
2957c478bd9Sstevel@tonic-gate 		}
2967c478bd9Sstevel@tonic-gate 		bn = input(FIO_BN, "Enter defective block number", ':',
2977c478bd9Sstevel@tonic-gate 		    &ioparam, (int *)NULL, DATA_INPUT);
2987c478bd9Sstevel@tonic-gate 		def.cyl = bn2c(bn);
2997c478bd9Sstevel@tonic-gate 		def.head = bn2h(bn);
3007c478bd9Sstevel@tonic-gate 		def.sect = bn2s(bn);
3017c478bd9Sstevel@tonic-gate 	} else {
3027c478bd9Sstevel@tonic-gate 		/*
3037c478bd9Sstevel@tonic-gate 		 * Mode selected is bytes-from-index.  Input the information
3047c478bd9Sstevel@tonic-gate 		 * about the defect and fill in the defect entry.
3057c478bd9Sstevel@tonic-gate 		 */
3067c478bd9Sstevel@tonic-gate 		def.sect = UNKNOWN;
3077c478bd9Sstevel@tonic-gate 		ioparam.io_bounds.lower = 0;
3087c478bd9Sstevel@tonic-gate 		ioparam.io_bounds.upper = pcyl - 1;
3097c478bd9Sstevel@tonic-gate 		def.cyl = input(FIO_INT,
3107c478bd9Sstevel@tonic-gate 		    "Enter defect's cylinder number", ':',
3117c478bd9Sstevel@tonic-gate 		    &ioparam, (int *)NULL, DATA_INPUT);
3127c478bd9Sstevel@tonic-gate 		ioparam.io_bounds.upper = nhead - 1;
3137c478bd9Sstevel@tonic-gate 		def.head = input(FIO_INT, "Enter defect's head number",
3147c478bd9Sstevel@tonic-gate 		    ':', &ioparam, (int *)NULL, DATA_INPUT);
3157c478bd9Sstevel@tonic-gate 		ioparam.io_bounds.upper = cur_dtype->dtype_bpt - 1;
3167c478bd9Sstevel@tonic-gate 		def.bfi = input(FIO_INT, "Enter defect's bytes-from-index",
3177c478bd9Sstevel@tonic-gate 		    ':', &ioparam, (int *)NULL, DATA_INPUT);
3187c478bd9Sstevel@tonic-gate 		ioparam.io_bounds.lower = -1;
3197c478bd9Sstevel@tonic-gate 		ioparam.io_bounds.upper = (cur_dtype->dtype_bpt - def.bfi) * 8;
3207c478bd9Sstevel@tonic-gate 		if (ioparam.io_bounds.upper >= 32 * 1024)
3217c478bd9Sstevel@tonic-gate 			ioparam.io_bounds.upper = 32 * 1024 - 1;
3227c478bd9Sstevel@tonic-gate 		/*
3237c478bd9Sstevel@tonic-gate 		 * Note: a length of -1 means the length is not known.  We
3247c478bd9Sstevel@tonic-gate 		 * make this the default value.
3257c478bd9Sstevel@tonic-gate 		 */
3267c478bd9Sstevel@tonic-gate 		deflt = -1;
3277c478bd9Sstevel@tonic-gate 		def.nbits = input(FIO_INT, "Enter defect's length (in bits)",
3287c478bd9Sstevel@tonic-gate 		    ':', &ioparam, &deflt, DATA_INPUT);
3297c478bd9Sstevel@tonic-gate 	}
3307c478bd9Sstevel@tonic-gate 	/*
3317c478bd9Sstevel@tonic-gate 	 * Calculate where in the defect list this defect belongs
3327c478bd9Sstevel@tonic-gate 	 * and print it out.
3337c478bd9Sstevel@tonic-gate 	 */
3347c478bd9Sstevel@tonic-gate 	index = sort_defect(&def, &work_list);
3357c478bd9Sstevel@tonic-gate 	fmt_print(DEF_PRINTHEADER);
3367c478bd9Sstevel@tonic-gate 	pr_defect(&def, index);
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	/*
3397c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so lists don't get mangled.
3407c478bd9Sstevel@tonic-gate 	 * Also, mark the working list dirty since we are modifying it.
3417c478bd9Sstevel@tonic-gate 	 */
3427c478bd9Sstevel@tonic-gate 	enter_critical();
3437c478bd9Sstevel@tonic-gate 	work_list.flags |= LIST_DIRTY;
3447c478bd9Sstevel@tonic-gate 	/*
3457c478bd9Sstevel@tonic-gate 	 * If the list is null, create it with zero length.  This is
3467c478bd9Sstevel@tonic-gate 	 * necessary because the routines to add a defect to the list
3477c478bd9Sstevel@tonic-gate 	 * assume the list is initialized.
3487c478bd9Sstevel@tonic-gate 	 */
3497c478bd9Sstevel@tonic-gate 	if (work_list.list == NULL) {
3507c478bd9Sstevel@tonic-gate 		work_list.header.magicno = (uint_t)DEFECT_MAGIC;
3517c478bd9Sstevel@tonic-gate 		work_list.header.count = 0;
3527c478bd9Sstevel@tonic-gate 		work_list.list = (struct defect_entry *)zalloc(
353*65908c77Syu, larry liu - Sun Microsystems - Beijing China 		    deflist_size(cur_blksz, 0) * cur_blksz);
3547c478bd9Sstevel@tonic-gate 	}
3557c478bd9Sstevel@tonic-gate 	/*
3567c478bd9Sstevel@tonic-gate 	 * Add the defect to the working list.
3577c478bd9Sstevel@tonic-gate 	 */
3587c478bd9Sstevel@tonic-gate 	add_def(&def, &work_list, index);
3597c478bd9Sstevel@tonic-gate 	fmt_print("defect number %d added.\n\n", index + 1);
3607c478bd9Sstevel@tonic-gate 	exit_critical();
3617c478bd9Sstevel@tonic-gate 	/*
3627c478bd9Sstevel@tonic-gate 	 * Loop back for the next defect.
3637c478bd9Sstevel@tonic-gate 	 */
3647c478bd9Sstevel@tonic-gate 	goto loop;
3657c478bd9Sstevel@tonic-gate 	/*NOTREACHED*/
3667c478bd9Sstevel@tonic-gate #ifdef	lint
3677c478bd9Sstevel@tonic-gate 	return (0);
3687c478bd9Sstevel@tonic-gate #endif
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate /*
3727c478bd9Sstevel@tonic-gate  * This routine implements the 'delete' command.  It allows the user
3737c478bd9Sstevel@tonic-gate  * to manually delete a defect from the working list.
3747c478bd9Sstevel@tonic-gate  */
3757c478bd9Sstevel@tonic-gate int
3767c478bd9Sstevel@tonic-gate d_delete()
3777c478bd9Sstevel@tonic-gate {
3787c478bd9Sstevel@tonic-gate 	int		i, count, num;
3797c478bd9Sstevel@tonic-gate 	u_ioparam_t	ioparam;
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate 	assert(!EMBEDDED_SCSI);
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 	/*
3847c478bd9Sstevel@tonic-gate 	 * If the working list is null or zero length, there's nothing
3857c478bd9Sstevel@tonic-gate 	 * to delete.
3867c478bd9Sstevel@tonic-gate 	 */
3877c478bd9Sstevel@tonic-gate 	count = work_list.header.count;
3887c478bd9Sstevel@tonic-gate 	if (work_list.list == NULL || count == 0) {
3897c478bd9Sstevel@tonic-gate 		err_print("No defects to delete.\n");
3907c478bd9Sstevel@tonic-gate 		return (-1);
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate 	/*
3937c478bd9Sstevel@tonic-gate 	 * Ask the user which defect should be deleted. Bounds are off by
3947c478bd9Sstevel@tonic-gate 	 * one because user sees a one-relative list.
3957c478bd9Sstevel@tonic-gate 	 */
3967c478bd9Sstevel@tonic-gate 	ioparam.io_bounds.lower = 1;
3977c478bd9Sstevel@tonic-gate 	ioparam.io_bounds.upper = count;
3987c478bd9Sstevel@tonic-gate 	num = input(FIO_INT, "Specify defect to be deleted (enter its number)",
3997c478bd9Sstevel@tonic-gate 	    ':', &ioparam, (int *)NULL, DATA_INPUT);
4007c478bd9Sstevel@tonic-gate 	/*
4017c478bd9Sstevel@tonic-gate 	 *
4027c478bd9Sstevel@tonic-gate 	 * The user thinks it's one relative but it's not really.
4037c478bd9Sstevel@tonic-gate 	 */
4047c478bd9Sstevel@tonic-gate 	--num;
4057c478bd9Sstevel@tonic-gate 	/*
4067c478bd9Sstevel@tonic-gate 	 * Print the defect selected and ask the user for confirmation.
4077c478bd9Sstevel@tonic-gate 	 */
4087c478bd9Sstevel@tonic-gate 	fmt_print(DEF_PRINTHEADER);
4097c478bd9Sstevel@tonic-gate 	pr_defect(work_list.list + num, num);
4107c478bd9Sstevel@tonic-gate 	/*
4117c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so the lists don't get mangled.
4127c478bd9Sstevel@tonic-gate 	 */
4137c478bd9Sstevel@tonic-gate 	enter_critical();
4147c478bd9Sstevel@tonic-gate 	/*
4157c478bd9Sstevel@tonic-gate 	 * Move down all the defects beyond the one deleted so the defect
4167c478bd9Sstevel@tonic-gate 	 * list is still fully populated.
4177c478bd9Sstevel@tonic-gate 	 */
4187c478bd9Sstevel@tonic-gate 	for (i = num; i < count - 1; i++)
4197c478bd9Sstevel@tonic-gate 		*(work_list.list + i) = *(work_list.list + i + 1);
4207c478bd9Sstevel@tonic-gate 	/*
4217c478bd9Sstevel@tonic-gate 	 * If the size of the list in sectors has changed, reallocate
4227c478bd9Sstevel@tonic-gate 	 * the list to shrink it appropriately.
4237c478bd9Sstevel@tonic-gate 	 */
424*65908c77Syu, larry liu - Sun Microsystems - Beijing China 	if (deflist_size(cur_blksz, count - 1) <
425*65908c77Syu, larry liu - Sun Microsystems - Beijing China 	    deflist_size(cur_blksz, count))
4267c478bd9Sstevel@tonic-gate 		work_list.list = (struct defect_entry *)rezalloc(
427*65908c77Syu, larry liu - Sun Microsystems - Beijing China 		    (void *)work_list.list,
428*65908c77Syu, larry liu - Sun Microsystems - Beijing China 		    deflist_size(cur_blksz, count - 1) * cur_blksz);
4297c478bd9Sstevel@tonic-gate 	/*
4307c478bd9Sstevel@tonic-gate 	 * Decrement the defect count.
4317c478bd9Sstevel@tonic-gate 	 */
4327c478bd9Sstevel@tonic-gate 	work_list.header.count--;
4337c478bd9Sstevel@tonic-gate 	/*
4347c478bd9Sstevel@tonic-gate 	 * Recalculate the list's checksum.
4357c478bd9Sstevel@tonic-gate 	 */
4367c478bd9Sstevel@tonic-gate 	(void) checkdefsum(&work_list, CK_MAKESUM);
4377c478bd9Sstevel@tonic-gate 	/*
4387c478bd9Sstevel@tonic-gate 	 * Mark the working list dirty since we modified it.
4397c478bd9Sstevel@tonic-gate 	 */
4407c478bd9Sstevel@tonic-gate 	work_list.flags |= LIST_DIRTY;
4417c478bd9Sstevel@tonic-gate 	fmt_print("defect number %d deleted.\n\n", ++num);
4427c478bd9Sstevel@tonic-gate 	exit_critical();
4437c478bd9Sstevel@tonic-gate 	return (0);
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate /*
4477c478bd9Sstevel@tonic-gate  * This routine implements the 'print' command.  It prints the working
4487c478bd9Sstevel@tonic-gate  * defect list out in human-readable format.
4497c478bd9Sstevel@tonic-gate  */
4507c478bd9Sstevel@tonic-gate int
4517c478bd9Sstevel@tonic-gate d_print()
4527c478bd9Sstevel@tonic-gate {
4537c478bd9Sstevel@tonic-gate 	int	i, nomore = 0;
4547c478bd9Sstevel@tonic-gate 	int	c, one_line = 0;
4557c478bd9Sstevel@tonic-gate 	int	tty_lines = get_tty_lines();
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 	/*
4587c478bd9Sstevel@tonic-gate 	 * If the working list is null, there's nothing to print.
4597c478bd9Sstevel@tonic-gate 	 */
4607c478bd9Sstevel@tonic-gate 	if (work_list.list == NULL) {
4617c478bd9Sstevel@tonic-gate 		if (EMBEDDED_SCSI)
4627c478bd9Sstevel@tonic-gate 			err_print(
4637c478bd9Sstevel@tonic-gate "No list defined,extract primary or grown or both defects list first.\n");
4647c478bd9Sstevel@tonic-gate 		else
4657c478bd9Sstevel@tonic-gate 			err_print("No working list defined.\n");
4667c478bd9Sstevel@tonic-gate 		return (-1);
4677c478bd9Sstevel@tonic-gate 	}
4687c478bd9Sstevel@tonic-gate 	/*
4697c478bd9Sstevel@tonic-gate 	 * If we're running from a file, don't use the paging scheme.
4707c478bd9Sstevel@tonic-gate 	 * If we are running interactive, turn off echoing.
4717c478bd9Sstevel@tonic-gate 	 */
4727c478bd9Sstevel@tonic-gate 	if (option_f || (!isatty(0)) || (!isatty(1)))
4737c478bd9Sstevel@tonic-gate 		nomore++;
4747c478bd9Sstevel@tonic-gate 	else {
4757c478bd9Sstevel@tonic-gate 		enter_critical();
4767c478bd9Sstevel@tonic-gate 		echo_off();
4777c478bd9Sstevel@tonic-gate 		charmode_on();
4787c478bd9Sstevel@tonic-gate 		exit_critical();
4797c478bd9Sstevel@tonic-gate 	}
4807c478bd9Sstevel@tonic-gate 	/* Print out the banner. */
4817c478bd9Sstevel@tonic-gate 	if (work_list.header.count != 0)
4827c478bd9Sstevel@tonic-gate 		fmt_print(DEF_PRINTHEADER);
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 	/*
4857c478bd9Sstevel@tonic-gate 	 * Loop through the each defect in the working list.
4867c478bd9Sstevel@tonic-gate 	 */
4877c478bd9Sstevel@tonic-gate 	for (i = 0; i < work_list.header.count; i++) {
4887c478bd9Sstevel@tonic-gate 		/*
4897c478bd9Sstevel@tonic-gate 		 * If we are paging and hit the end of a page, wait for
4907c478bd9Sstevel@tonic-gate 		 * the user to hit either space-bar, "q", or return
4917c478bd9Sstevel@tonic-gate 		 * before going on.
4927c478bd9Sstevel@tonic-gate 		 */
4937c478bd9Sstevel@tonic-gate 		if (one_line ||
4947c478bd9Sstevel@tonic-gate 		    (!nomore && ((i + 1) % (tty_lines - 1) == 0))) {
4957c478bd9Sstevel@tonic-gate 			/*
4967c478bd9Sstevel@tonic-gate 			 * Get the next character.
4977c478bd9Sstevel@tonic-gate 			 */
4987c478bd9Sstevel@tonic-gate 			fmt_print("- hit space for more - ");
4997c478bd9Sstevel@tonic-gate 			c = getchar();
5007c478bd9Sstevel@tonic-gate 			fmt_print("\015");
5017c478bd9Sstevel@tonic-gate 			one_line = 0;
5027c478bd9Sstevel@tonic-gate 			/* Handle display one line command (return key) */
5037c478bd9Sstevel@tonic-gate 			if (c == '\012') {
5047c478bd9Sstevel@tonic-gate 				one_line++;
5057c478bd9Sstevel@tonic-gate 			}
5067c478bd9Sstevel@tonic-gate 			/* Handle Quit command */
5077c478bd9Sstevel@tonic-gate 			if (c == 'q') {
5087c478bd9Sstevel@tonic-gate 				fmt_print("                       \015");
5097c478bd9Sstevel@tonic-gate 				goto PRINT_EXIT;
5107c478bd9Sstevel@tonic-gate 			}
5117c478bd9Sstevel@tonic-gate 			/* Handle ^D */
5127c478bd9Sstevel@tonic-gate 			if (c == '\004')
5137c478bd9Sstevel@tonic-gate 				fullabort();
5147c478bd9Sstevel@tonic-gate 		}
5157c478bd9Sstevel@tonic-gate 		/*
5167c478bd9Sstevel@tonic-gate 		 * Print the defect.
5177c478bd9Sstevel@tonic-gate 		 */
5187c478bd9Sstevel@tonic-gate 		pr_defect(work_list.list + i, i);
5197c478bd9Sstevel@tonic-gate 	}
5207c478bd9Sstevel@tonic-gate 	fmt_print("total of %d defects.\n\n", i);
5217c478bd9Sstevel@tonic-gate 	/*
5227c478bd9Sstevel@tonic-gate 	 * If we were doing paging, turn echoing back on.
5237c478bd9Sstevel@tonic-gate 	 */
5247c478bd9Sstevel@tonic-gate PRINT_EXIT:
5257c478bd9Sstevel@tonic-gate 	if (!nomore) {
5267c478bd9Sstevel@tonic-gate 		enter_critical();
5277c478bd9Sstevel@tonic-gate 		charmode_off();
5287c478bd9Sstevel@tonic-gate 		echo_on();
5297c478bd9Sstevel@tonic-gate 		exit_critical();
5307c478bd9Sstevel@tonic-gate 	}
5317c478bd9Sstevel@tonic-gate 	return (0);
5327c478bd9Sstevel@tonic-gate }
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate /*
5357c478bd9Sstevel@tonic-gate  * This routine implements the 'dump' command.  It writes the working
5367c478bd9Sstevel@tonic-gate  * defect list to a file.
5377c478bd9Sstevel@tonic-gate  */
5387c478bd9Sstevel@tonic-gate int
5397c478bd9Sstevel@tonic-gate d_dump()
5407c478bd9Sstevel@tonic-gate {
5417c478bd9Sstevel@tonic-gate 	int	i, status = 0;
5427c478bd9Sstevel@tonic-gate 	char	*str;
5437c478bd9Sstevel@tonic-gate 	FILE	*fptr;
5447c478bd9Sstevel@tonic-gate 	struct	defect_entry *dptr;
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	/*
5477c478bd9Sstevel@tonic-gate 	 * If the working list is null, there's nothing to do.
5487c478bd9Sstevel@tonic-gate 	 */
5497c478bd9Sstevel@tonic-gate 	if (work_list.list == NULL) {
5507c478bd9Sstevel@tonic-gate 		if (EMBEDDED_SCSI)
5517c478bd9Sstevel@tonic-gate 			err_print(
5527c478bd9Sstevel@tonic-gate "No list defined,extract primary or grown or both defects list first.\n");
5537c478bd9Sstevel@tonic-gate 		else
5547c478bd9Sstevel@tonic-gate 			err_print("No working list defined.\n");
5557c478bd9Sstevel@tonic-gate 		return (-1);
5567c478bd9Sstevel@tonic-gate 	}
5577c478bd9Sstevel@tonic-gate 	/*
5587c478bd9Sstevel@tonic-gate 	 * Ask the user for the name of the defect file.  Note that the
5597c478bd9Sstevel@tonic-gate 	 * input will be in malloc'd space since we are inputting
5607c478bd9Sstevel@tonic-gate 	 * type OSTR.
5617c478bd9Sstevel@tonic-gate 	 */
562052b6e8aSbg159949 	str = (char *)(uintptr_t)input(FIO_OSTR, "Enter name of defect file",
563052b6e8aSbg159949 	    ':', (u_ioparam_t *)NULL, (int *)NULL, DATA_INPUT);
5647c478bd9Sstevel@tonic-gate 	/*
5657c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so the file doesn't get half written.
5667c478bd9Sstevel@tonic-gate 	 */
5677c478bd9Sstevel@tonic-gate 	enter_critical();
5687c478bd9Sstevel@tonic-gate 	/*
5697c478bd9Sstevel@tonic-gate 	 * Open the file for writing.
5707c478bd9Sstevel@tonic-gate 	 */
5717c478bd9Sstevel@tonic-gate 	if ((fptr = fopen(str, "w+")) == NULL) {
5727c478bd9Sstevel@tonic-gate 		err_print("unable to open defect file.\n");
5737c478bd9Sstevel@tonic-gate 		status = -1;
5747c478bd9Sstevel@tonic-gate 		goto out;
5757c478bd9Sstevel@tonic-gate 	}
5767c478bd9Sstevel@tonic-gate 	/*
5777c478bd9Sstevel@tonic-gate 	 * Print a header containing the magic number, count, and checksum.
5787c478bd9Sstevel@tonic-gate 	 */
5797c478bd9Sstevel@tonic-gate 	(void) fprintf(fptr, "0x%08x%8d  0x%08x\n",
5807c478bd9Sstevel@tonic-gate 	    work_list.header.magicno,
5817c478bd9Sstevel@tonic-gate 	    work_list.header.count, work_list.header.cksum);
5827c478bd9Sstevel@tonic-gate 	/*
5837c478bd9Sstevel@tonic-gate 	 * Loop through each defect in the working list.  Write the
5847c478bd9Sstevel@tonic-gate 	 * defect info to the defect file.
5857c478bd9Sstevel@tonic-gate 	 */
5867c478bd9Sstevel@tonic-gate 	for (i = 0; i < work_list.header.count; i++) {
5877c478bd9Sstevel@tonic-gate 		dptr = work_list.list + i;
5887c478bd9Sstevel@tonic-gate 		(void) fprintf(fptr, "%4d%8d%7d%8d%8d%8d\n",
5897c478bd9Sstevel@tonic-gate 		    i+1, dptr->cyl, dptr->head,
5907c478bd9Sstevel@tonic-gate 		    dptr->bfi, dptr->nbits, dptr->sect);
5917c478bd9Sstevel@tonic-gate 	}
5927c478bd9Sstevel@tonic-gate 	fmt_print("defect file updated, total of %d defects.\n", i);
5937c478bd9Sstevel@tonic-gate 	/*
5947c478bd9Sstevel@tonic-gate 	 * Close the defect file.
5957c478bd9Sstevel@tonic-gate 	 */
5967c478bd9Sstevel@tonic-gate 	(void) fclose(fptr);
5977c478bd9Sstevel@tonic-gate out:
5987c478bd9Sstevel@tonic-gate 	/*
5997c478bd9Sstevel@tonic-gate 	 * Destroy the string used for the file name.
6007c478bd9Sstevel@tonic-gate 	 */
6017c478bd9Sstevel@tonic-gate 	destroy_data(str);
6027c478bd9Sstevel@tonic-gate 	exit_critical();
6037c478bd9Sstevel@tonic-gate 	fmt_print("\n");
6047c478bd9Sstevel@tonic-gate 	return (status);
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate /*
6087c478bd9Sstevel@tonic-gate  * This routine implements the 'load' command.  It reads the working
6097c478bd9Sstevel@tonic-gate  * list in from a file.
6107c478bd9Sstevel@tonic-gate  */
6117c478bd9Sstevel@tonic-gate int
6127c478bd9Sstevel@tonic-gate d_load()
6137c478bd9Sstevel@tonic-gate {
6147c478bd9Sstevel@tonic-gate 	int	i, items, status = 0, count, cksum;
6157c478bd9Sstevel@tonic-gate 	uint_t	magicno;
6167c478bd9Sstevel@tonic-gate 	char	*str;
6177c478bd9Sstevel@tonic-gate 	TOKEN	filename;
6187c478bd9Sstevel@tonic-gate 	FILE	*fptr;
6197c478bd9Sstevel@tonic-gate 	struct	defect_entry *dptr;
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 	assert(!EMBEDDED_SCSI);
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 	/*
6247c478bd9Sstevel@tonic-gate 	 * Ask the user for the name of the defect file.  Note that the
6257c478bd9Sstevel@tonic-gate 	 * input will be malloc'd space since we inputted type OSTR.
6267c478bd9Sstevel@tonic-gate 	 */
627052b6e8aSbg159949 	str = (char *)(uintptr_t)input(FIO_OSTR, "Enter name of defect file",
628052b6e8aSbg159949 	    ':', (u_ioparam_t *)NULL, (int *)NULL, DATA_INPUT);
6297c478bd9Sstevel@tonic-gate 	/*
6307c478bd9Sstevel@tonic-gate 	 * Copy the file name into local space then destroy the string
6317c478bd9Sstevel@tonic-gate 	 * it came in.  This is simply a precaution against later having
6327c478bd9Sstevel@tonic-gate 	 * to remember to destroy this space.
6337c478bd9Sstevel@tonic-gate 	 */
6347c478bd9Sstevel@tonic-gate 	enter_critical();
6357c478bd9Sstevel@tonic-gate 	(void) strcpy(filename, str);
6367c478bd9Sstevel@tonic-gate 	destroy_data(str);
6377c478bd9Sstevel@tonic-gate 	exit_critical();
6387c478bd9Sstevel@tonic-gate 	/*
6397c478bd9Sstevel@tonic-gate 	 * See if the defect file is accessable.  If not, we can't load
6407c478bd9Sstevel@tonic-gate 	 * from it.  We do this here just so we can get out before asking
6417c478bd9Sstevel@tonic-gate 	 * the user for confirmation.
6427c478bd9Sstevel@tonic-gate 	 */
6437c478bd9Sstevel@tonic-gate 	status = access(filename, 4);
6447c478bd9Sstevel@tonic-gate 	if (status) {
6457c478bd9Sstevel@tonic-gate 		err_print("defect file not accessable.\n");
6467c478bd9Sstevel@tonic-gate 		return (-1);
6477c478bd9Sstevel@tonic-gate 	}
6487c478bd9Sstevel@tonic-gate 	/*
6497c478bd9Sstevel@tonic-gate 	 * Make sure the user is serious.
6507c478bd9Sstevel@tonic-gate 	 */
6517c478bd9Sstevel@tonic-gate 	if (check("ready to update working list, continue"))
6527c478bd9Sstevel@tonic-gate 		return (-1);
6537c478bd9Sstevel@tonic-gate 	/*
6547c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so the list doesn't get half loaded.
6557c478bd9Sstevel@tonic-gate 	 */
6567c478bd9Sstevel@tonic-gate 	enter_critical();
6577c478bd9Sstevel@tonic-gate 	/*
6587c478bd9Sstevel@tonic-gate 	 * Open the defect file.
6597c478bd9Sstevel@tonic-gate 	 */
6607c478bd9Sstevel@tonic-gate 	if ((fptr = fopen(filename, "r")) == NULL) {
6617c478bd9Sstevel@tonic-gate 		err_print("unable to open defect file.\n");
6627c478bd9Sstevel@tonic-gate 		exit_critical();
6637c478bd9Sstevel@tonic-gate 		return (-1);
6647c478bd9Sstevel@tonic-gate 	}
6657c478bd9Sstevel@tonic-gate 	/*
6667c478bd9Sstevel@tonic-gate 	 * Scan in the header.
6677c478bd9Sstevel@tonic-gate 	 */
6687c478bd9Sstevel@tonic-gate 	items = fscanf(fptr, "0x%x%d  0x%x\n", &magicno,
6697c478bd9Sstevel@tonic-gate 	    &count, (uint_t *)&cksum);
6707c478bd9Sstevel@tonic-gate 	/*
6717c478bd9Sstevel@tonic-gate 	 * If the header is wrong, this isn't a good defect file.
6727c478bd9Sstevel@tonic-gate 	 */
6737c478bd9Sstevel@tonic-gate 	if (items != 3 || count < 0 ||
6747c478bd9Sstevel@tonic-gate 	    (magicno != (uint_t)DEFECT_MAGIC &&
6757c478bd9Sstevel@tonic-gate 	    magicno != (uint_t)NO_CHECKSUM)) {
6767c478bd9Sstevel@tonic-gate 		err_print("Defect file is corrupted.\n");
6777c478bd9Sstevel@tonic-gate 		status = -1;
6787c478bd9Sstevel@tonic-gate 		goto out;
6797c478bd9Sstevel@tonic-gate 	}
6807c478bd9Sstevel@tonic-gate 	/*
6817c478bd9Sstevel@tonic-gate 	 * Kill off any old defects in the working list.
6827c478bd9Sstevel@tonic-gate 	 */
6837c478bd9Sstevel@tonic-gate 	kill_deflist(&work_list);
6847c478bd9Sstevel@tonic-gate 	/*
6857c478bd9Sstevel@tonic-gate 	 * Load the working list header with the header info.
6867c478bd9Sstevel@tonic-gate 	 */
6877c478bd9Sstevel@tonic-gate 	if (magicno == NO_CHECKSUM)
6887c478bd9Sstevel@tonic-gate 		work_list.header.magicno = (uint_t)DEFECT_MAGIC;
6897c478bd9Sstevel@tonic-gate 	else
6907c478bd9Sstevel@tonic-gate 		work_list.header.magicno = magicno;
6917c478bd9Sstevel@tonic-gate 	work_list.header.count = count;
6927c478bd9Sstevel@tonic-gate 	work_list.header.cksum = cksum;
6937c478bd9Sstevel@tonic-gate 	/*
6947c478bd9Sstevel@tonic-gate 	 * Allocate space for the new list.
6957c478bd9Sstevel@tonic-gate 	 */
696*65908c77Syu, larry liu - Sun Microsystems - Beijing China 	work_list.list = (struct defect_entry *)zalloc(
697*65908c77Syu, larry liu - Sun Microsystems - Beijing China 	    deflist_size(cur_blksz, count) * cur_blksz);
6987c478bd9Sstevel@tonic-gate 	/*
6997c478bd9Sstevel@tonic-gate 	 * Mark the working list dirty since we are modifying it.
7007c478bd9Sstevel@tonic-gate 	 */
7017c478bd9Sstevel@tonic-gate 	work_list.flags |= LIST_DIRTY;
7027c478bd9Sstevel@tonic-gate 	/*
7037c478bd9Sstevel@tonic-gate 	 * Loop through each defect in the defect file.
7047c478bd9Sstevel@tonic-gate 	 */
7057c478bd9Sstevel@tonic-gate 	for (i = 0; i < count; i++) {
7067c478bd9Sstevel@tonic-gate 		dptr = work_list.list + i;
7077c478bd9Sstevel@tonic-gate 		/*
7087c478bd9Sstevel@tonic-gate 		 * Scan the info into the defect entry.
7097c478bd9Sstevel@tonic-gate 		 */
7107c478bd9Sstevel@tonic-gate 		items = fscanf(fptr, "%*d%hd%hd%d%hd%hd\n", &dptr->cyl,
7117c478bd9Sstevel@tonic-gate 		    &dptr->head, &dptr->bfi, &dptr->nbits, &dptr->sect);
7127c478bd9Sstevel@tonic-gate 		/*
7137c478bd9Sstevel@tonic-gate 		 * If it didn't scan right, give up.
7147c478bd9Sstevel@tonic-gate 		 */
7157c478bd9Sstevel@tonic-gate 		if (items != 5)
7167c478bd9Sstevel@tonic-gate 			goto bad;
7177c478bd9Sstevel@tonic-gate 	}
7187c478bd9Sstevel@tonic-gate 	/*
7197c478bd9Sstevel@tonic-gate 	 * Check to be sure the checksum from the defect file was correct
7207c478bd9Sstevel@tonic-gate 	 * unless there wasn't supposed to be a checksum.
7217c478bd9Sstevel@tonic-gate 	 * If there was supposed to be a valid checksum and there isn't
7227c478bd9Sstevel@tonic-gate 	 * then give up.
7237c478bd9Sstevel@tonic-gate 	 */
7247c478bd9Sstevel@tonic-gate 	if (magicno != NO_CHECKSUM && checkdefsum(&work_list, CK_CHECKSUM))
7257c478bd9Sstevel@tonic-gate 		goto bad;
7267c478bd9Sstevel@tonic-gate 	fmt_print("working list updated, total of %d defects.\n", i);
7277c478bd9Sstevel@tonic-gate 	goto out;
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate bad:
7307c478bd9Sstevel@tonic-gate 	/*
7317c478bd9Sstevel@tonic-gate 	 * Some kind of error occurred.  Kill off the working list and
7327c478bd9Sstevel@tonic-gate 	 * mark the status bad.
7337c478bd9Sstevel@tonic-gate 	 */
7347c478bd9Sstevel@tonic-gate 	err_print("Defect file is corrupted, working list set to NULL.\n");
7357c478bd9Sstevel@tonic-gate 	kill_deflist(&work_list);
7367c478bd9Sstevel@tonic-gate 	status = -1;
7377c478bd9Sstevel@tonic-gate out:
7387c478bd9Sstevel@tonic-gate 	/*
7397c478bd9Sstevel@tonic-gate 	 * Close the defect file.
7407c478bd9Sstevel@tonic-gate 	 */
7417c478bd9Sstevel@tonic-gate 	(void) fclose(fptr);
7427c478bd9Sstevel@tonic-gate 	exit_critical();
7437c478bd9Sstevel@tonic-gate 	fmt_print("\n");
7447c478bd9Sstevel@tonic-gate 	return (status);
7457c478bd9Sstevel@tonic-gate }
7467c478bd9Sstevel@tonic-gate 
7477c478bd9Sstevel@tonic-gate /*
7487c478bd9Sstevel@tonic-gate  * This routine implements the 'commit' command.  It causes the current
7497c478bd9Sstevel@tonic-gate  * defect list to be set equal to the working defect list.  It is the only
7507c478bd9Sstevel@tonic-gate  * way that changes made to the working list can actually take effect in
7517c478bd9Sstevel@tonic-gate  * the next format.
7527c478bd9Sstevel@tonic-gate  */
7537c478bd9Sstevel@tonic-gate int
7547c478bd9Sstevel@tonic-gate d_commit()
7557c478bd9Sstevel@tonic-gate {
7567c478bd9Sstevel@tonic-gate 	/*
7577c478bd9Sstevel@tonic-gate 	 * If the working list wasn't modified, no commit is necessary.
7587c478bd9Sstevel@tonic-gate 	 */
7597c478bd9Sstevel@tonic-gate 	if (work_list.list != NULL && !(work_list.flags & LIST_DIRTY)) {
7607c478bd9Sstevel@tonic-gate 		err_print("working list was not modified.\n");
7617c478bd9Sstevel@tonic-gate 		return (0);
7627c478bd9Sstevel@tonic-gate 	}
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 	/*
7657c478bd9Sstevel@tonic-gate 	 * Make sure the user is serious.
7667c478bd9Sstevel@tonic-gate 	 */
7677c478bd9Sstevel@tonic-gate 	if (check("Ready to update Current Defect List, continue"))
7687c478bd9Sstevel@tonic-gate 		return (-1);
7697c478bd9Sstevel@tonic-gate 	return (do_commit());
7707c478bd9Sstevel@tonic-gate }
7717c478bd9Sstevel@tonic-gate 
7727c478bd9Sstevel@tonic-gate int
7737c478bd9Sstevel@tonic-gate do_commit()
7747c478bd9Sstevel@tonic-gate {
7757c478bd9Sstevel@tonic-gate 	int	status;
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 	if ((status = commit_list()) == 0) {
7787c478bd9Sstevel@tonic-gate 		/*
7797c478bd9Sstevel@tonic-gate 		 * Remind the user to format the drive, since changing
7807c478bd9Sstevel@tonic-gate 		 * the list does nothing unless a format is performed.
7817c478bd9Sstevel@tonic-gate 		 */
7827c478bd9Sstevel@tonic-gate 		fmt_print(\
7837c478bd9Sstevel@tonic-gate "Disk must be reformatted for changes to take effect.\n\n");
7847c478bd9Sstevel@tonic-gate 	}
7857c478bd9Sstevel@tonic-gate 	return (status);
7867c478bd9Sstevel@tonic-gate }
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate 
7897c478bd9Sstevel@tonic-gate static int
7907c478bd9Sstevel@tonic-gate commit_list()
7917c478bd9Sstevel@tonic-gate {
7927c478bd9Sstevel@tonic-gate 	int	i;
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 	/*
7957c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so the list doesn't get half copied.
7967c478bd9Sstevel@tonic-gate 	 */
7977c478bd9Sstevel@tonic-gate 	enter_critical();
7987c478bd9Sstevel@tonic-gate 	/*
7997c478bd9Sstevel@tonic-gate 	 * Kill off any current defect list.
8007c478bd9Sstevel@tonic-gate 	 */
8017c478bd9Sstevel@tonic-gate 	kill_deflist(&cur_list);
8027c478bd9Sstevel@tonic-gate 	/*
8037c478bd9Sstevel@tonic-gate 	 * If the working list is null, initialize it to zero length.
8047c478bd9Sstevel@tonic-gate 	 * This is so the user can do a commit on a null list and get
8057c478bd9Sstevel@tonic-gate 	 * a zero length list.  Otherwise there would be no way to get
8067c478bd9Sstevel@tonic-gate 	 * a zero length list conveniently.
8077c478bd9Sstevel@tonic-gate 	 */
8087c478bd9Sstevel@tonic-gate 	if (work_list.list == NULL) {
8097c478bd9Sstevel@tonic-gate 		work_list.header.magicno = (uint_t)DEFECT_MAGIC;
8107c478bd9Sstevel@tonic-gate 		work_list.header.count = 0;
8117c478bd9Sstevel@tonic-gate 		work_list.list = (struct defect_entry *)zalloc(
812*65908c77Syu, larry liu - Sun Microsystems - Beijing China 		    deflist_size(cur_blksz, 0) * cur_blksz);
8137c478bd9Sstevel@tonic-gate 	}
8147c478bd9Sstevel@tonic-gate 	/*
8157c478bd9Sstevel@tonic-gate 	 * Copy the working list into the current list.
8167c478bd9Sstevel@tonic-gate 	 */
8177c478bd9Sstevel@tonic-gate 	cur_list.header = work_list.header;
8187c478bd9Sstevel@tonic-gate 	cur_list.list = (struct defect_entry *)zalloc(
819*65908c77Syu, larry liu - Sun Microsystems - Beijing China 	    deflist_size(cur_blksz, cur_list.header.count) * cur_blksz);
8207c478bd9Sstevel@tonic-gate 	for (i = 0; i < cur_list.header.count; i++)
8217c478bd9Sstevel@tonic-gate 		*(cur_list.list + i) = *(work_list.list + i);
8227c478bd9Sstevel@tonic-gate 	/*
8237c478bd9Sstevel@tonic-gate 	 * Mark the working list clean, since it is now the same as the
8247c478bd9Sstevel@tonic-gate 	 * current list.  Note we do not mark the current list dirty,
8257c478bd9Sstevel@tonic-gate 	 * even though it has been changed.  This is because it does
8267c478bd9Sstevel@tonic-gate 	 * not reflect the state of disk, so we don't want it written
8277c478bd9Sstevel@tonic-gate 	 * out until a format has been done.  The format will mark it
8287c478bd9Sstevel@tonic-gate 	 * dirty and write it out.
8297c478bd9Sstevel@tonic-gate 	 */
8307c478bd9Sstevel@tonic-gate 	work_list.flags &= ~(LIST_DIRTY|LIST_RELOAD);
8317c478bd9Sstevel@tonic-gate 	cur_list.flags = work_list.flags;
8327c478bd9Sstevel@tonic-gate 	if (EMBEDDED_SCSI)
8337c478bd9Sstevel@tonic-gate 		fmt_print("Defect List has a total of %d defects.\n",
8347c478bd9Sstevel@tonic-gate 		    cur_list.header.count);
8357c478bd9Sstevel@tonic-gate 	else
8367c478bd9Sstevel@tonic-gate 		fmt_print("Current Defect List updated, total of %d defects.\n",
8377c478bd9Sstevel@tonic-gate 		    cur_list.header.count);
8387c478bd9Sstevel@tonic-gate 	exit_critical();
8397c478bd9Sstevel@tonic-gate 	return (0);
8407c478bd9Sstevel@tonic-gate }
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 
8437c478bd9Sstevel@tonic-gate /*
8447c478bd9Sstevel@tonic-gate  * This routine implements the 'create' command.  It creates the
8457c478bd9Sstevel@tonic-gate  * manufacturer's defect on the current disk from the defect list
8467c478bd9Sstevel@tonic-gate  */
8477c478bd9Sstevel@tonic-gate int
8487c478bd9Sstevel@tonic-gate d_create()
8497c478bd9Sstevel@tonic-gate {
8507c478bd9Sstevel@tonic-gate 	int	status;
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate 	assert(!EMBEDDED_SCSI);
8537c478bd9Sstevel@tonic-gate 
8547c478bd9Sstevel@tonic-gate 	/*
8557c478bd9Sstevel@tonic-gate 	 * If the controller does not support the extraction, we're out
8567c478bd9Sstevel@tonic-gate 	 * of luck.
8577c478bd9Sstevel@tonic-gate 	 */
8587c478bd9Sstevel@tonic-gate 	if (cur_ops->op_create == NULL) {
8597c478bd9Sstevel@tonic-gate 		err_print("Controller does not support creating ");
8607c478bd9Sstevel@tonic-gate 		err_print("manufacturer's defect list.\n");
8617c478bd9Sstevel@tonic-gate 		return (-1);
8627c478bd9Sstevel@tonic-gate 	}
8637c478bd9Sstevel@tonic-gate 	/*
8647c478bd9Sstevel@tonic-gate 	 * Make sure the user is serious.  Note, for SCSI disks
8657c478bd9Sstevel@tonic-gate 	 * since this is instantaneous, we will just do it and
8667c478bd9Sstevel@tonic-gate 	 * not ask for confirmation.
8677c478bd9Sstevel@tonic-gate 	 */
8687c478bd9Sstevel@tonic-gate 	if (! (cur_ctype->ctype_flags & CF_SCSI) &&
8697c478bd9Sstevel@tonic-gate 	    check(
8707c478bd9Sstevel@tonic-gate "Ready to create the manufacturers defect information on the disk.\n\
8717c478bd9Sstevel@tonic-gate This cannot be interrupted and may take a long while.\n\
8727c478bd9Sstevel@tonic-gate IT WILL DESTROY ALL OF THE DATA ON THE DISK! Continue"))
8737c478bd9Sstevel@tonic-gate 		return (-1);
8747c478bd9Sstevel@tonic-gate 	/*
8757c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so we don't get half the list.
8767c478bd9Sstevel@tonic-gate 	 */
8777c478bd9Sstevel@tonic-gate 	enter_critical();
8787c478bd9Sstevel@tonic-gate 	fmt_print("Creating manufacturer's defect list...");
8797c478bd9Sstevel@tonic-gate 	/*
8807c478bd9Sstevel@tonic-gate 	 * Do the Creation
8817c478bd9Sstevel@tonic-gate 	 */
8827c478bd9Sstevel@tonic-gate 	status = (*cur_ops->op_create)(&work_list);
8837c478bd9Sstevel@tonic-gate 	if (status) {
8847c478bd9Sstevel@tonic-gate 		fmt_print("Creation failed.\n\n");
8857c478bd9Sstevel@tonic-gate 	} else {
8867c478bd9Sstevel@tonic-gate 		fmt_print("Creation complete.\n");
8877c478bd9Sstevel@tonic-gate 	}
8887c478bd9Sstevel@tonic-gate 	exit_critical();
8897c478bd9Sstevel@tonic-gate 	/*
8907c478bd9Sstevel@tonic-gate 	 * Return status.
8917c478bd9Sstevel@tonic-gate 	 */
8927c478bd9Sstevel@tonic-gate 	return (status);
8937c478bd9Sstevel@tonic-gate }
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate /*
8977c478bd9Sstevel@tonic-gate  * Extract primary defect list - SCSI only
8987c478bd9Sstevel@tonic-gate  */
8997c478bd9Sstevel@tonic-gate int
9007c478bd9Sstevel@tonic-gate d_primary()
9017c478bd9Sstevel@tonic-gate {
9027c478bd9Sstevel@tonic-gate 	int	status;
9037c478bd9Sstevel@tonic-gate 
9047c478bd9Sstevel@tonic-gate 	assert(EMBEDDED_SCSI);
9057c478bd9Sstevel@tonic-gate 
9067c478bd9Sstevel@tonic-gate 	/*
9077c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so we don't get half the list and
9087c478bd9Sstevel@tonic-gate 	 * Kill off the working list.
9097c478bd9Sstevel@tonic-gate 	 */
9107c478bd9Sstevel@tonic-gate 	enter_critical();
9117c478bd9Sstevel@tonic-gate 	kill_deflist(&work_list);
9127c478bd9Sstevel@tonic-gate 	fmt_print("Extracting primary defect list...");
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 	/*
9157c478bd9Sstevel@tonic-gate 	 * Do the extraction.
9167c478bd9Sstevel@tonic-gate 	 */
9177c478bd9Sstevel@tonic-gate 	status = scsi_ex_man(&work_list);
9187c478bd9Sstevel@tonic-gate 	if (status) {
9197c478bd9Sstevel@tonic-gate 		fmt_print("Extraction failed.\n\n");
9207c478bd9Sstevel@tonic-gate 	} else {
9217c478bd9Sstevel@tonic-gate 		fmt_print("Extraction complete.\n");
9227c478bd9Sstevel@tonic-gate 		/*
9237c478bd9Sstevel@tonic-gate 		 * Mark the working list dirty since we modified it.
9247c478bd9Sstevel@tonic-gate 		 * Automatically commit it, for SCSI only.
9257c478bd9Sstevel@tonic-gate 		 */
9267c478bd9Sstevel@tonic-gate 		work_list.flags |= LIST_DIRTY;
9277c478bd9Sstevel@tonic-gate 		status = commit_list();
9287c478bd9Sstevel@tonic-gate 		fmt_print("\n");
9297c478bd9Sstevel@tonic-gate 	}
9307c478bd9Sstevel@tonic-gate 	exit_critical();
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	/*
9337c478bd9Sstevel@tonic-gate 	 * Return status.
9347c478bd9Sstevel@tonic-gate 	 */
9357c478bd9Sstevel@tonic-gate 	return (status);
9367c478bd9Sstevel@tonic-gate }
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate 
9397c478bd9Sstevel@tonic-gate /*
9407c478bd9Sstevel@tonic-gate  * Extract grown defects list - SCSI only
9417c478bd9Sstevel@tonic-gate  */
9427c478bd9Sstevel@tonic-gate int
9437c478bd9Sstevel@tonic-gate d_grown()
9447c478bd9Sstevel@tonic-gate {
9457c478bd9Sstevel@tonic-gate 	int	status;
9467c478bd9Sstevel@tonic-gate 
9477c478bd9Sstevel@tonic-gate 	assert(EMBEDDED_SCSI);
9487c478bd9Sstevel@tonic-gate 
9497c478bd9Sstevel@tonic-gate 	/*
9507c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so we don't get half the list and
9517c478bd9Sstevel@tonic-gate 	 * Kill off the working list.
9527c478bd9Sstevel@tonic-gate 	 */
9537c478bd9Sstevel@tonic-gate 	enter_critical();
9547c478bd9Sstevel@tonic-gate 	kill_deflist(&work_list);
9557c478bd9Sstevel@tonic-gate 	fmt_print("Extracting grown defects list...");
9567c478bd9Sstevel@tonic-gate 
9577c478bd9Sstevel@tonic-gate 	/*
9587c478bd9Sstevel@tonic-gate 	 * Do the extraction.
9597c478bd9Sstevel@tonic-gate 	 */
9607c478bd9Sstevel@tonic-gate 	status = scsi_ex_grown(&work_list);
9617c478bd9Sstevel@tonic-gate 	if (status) {
9627c478bd9Sstevel@tonic-gate 		fmt_print("Extraction failed.\n\n");
9637c478bd9Sstevel@tonic-gate 	} else {
9647c478bd9Sstevel@tonic-gate 		fmt_print("Extraction complete.\n");
9657c478bd9Sstevel@tonic-gate 		/*
9667c478bd9Sstevel@tonic-gate 		 * Mark the working list dirty since we modified it.
9677c478bd9Sstevel@tonic-gate 		 * Automatically commit it, for SCSI only.
9687c478bd9Sstevel@tonic-gate 		 */
9697c478bd9Sstevel@tonic-gate 		work_list.flags |= LIST_DIRTY;
9707c478bd9Sstevel@tonic-gate 		status = commit_list();
9717c478bd9Sstevel@tonic-gate 		fmt_print("\n");
9727c478bd9Sstevel@tonic-gate 	}
9737c478bd9Sstevel@tonic-gate 	exit_critical();
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate 	/*
9767c478bd9Sstevel@tonic-gate 	 * Return status.
9777c478bd9Sstevel@tonic-gate 	 */
9787c478bd9Sstevel@tonic-gate 	return (status);
9797c478bd9Sstevel@tonic-gate }
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate /*
9837c478bd9Sstevel@tonic-gate  * Extract both primary and grown defects list - SCSI only
9847c478bd9Sstevel@tonic-gate  */
9857c478bd9Sstevel@tonic-gate int
9867c478bd9Sstevel@tonic-gate d_both()
9877c478bd9Sstevel@tonic-gate {
9887c478bd9Sstevel@tonic-gate 	int	status;
9897c478bd9Sstevel@tonic-gate 
9907c478bd9Sstevel@tonic-gate 	assert(EMBEDDED_SCSI);
9917c478bd9Sstevel@tonic-gate 
9927c478bd9Sstevel@tonic-gate 	/*
9937c478bd9Sstevel@tonic-gate 	 * Lock out interrupts so we don't get half the list and
9947c478bd9Sstevel@tonic-gate 	 * Kill off the working list.
9957c478bd9Sstevel@tonic-gate 	 */
9967c478bd9Sstevel@tonic-gate 	enter_critical();
9977c478bd9Sstevel@tonic-gate 	kill_deflist(&work_list);
9987c478bd9Sstevel@tonic-gate 	fmt_print("Extracting both primary and grown defects lists...");
9997c478bd9Sstevel@tonic-gate 
10007c478bd9Sstevel@tonic-gate 	/*
10017c478bd9Sstevel@tonic-gate 	 * Do the extraction.
10027c478bd9Sstevel@tonic-gate 	 */
10037c478bd9Sstevel@tonic-gate 	status = scsi_ex_cur(&work_list);
10047c478bd9Sstevel@tonic-gate 	if (status) {
10057c478bd9Sstevel@tonic-gate 		fmt_print("Extraction failed.\n\n");
10067c478bd9Sstevel@tonic-gate 	} else {
10077c478bd9Sstevel@tonic-gate 		fmt_print("Extraction complete.\n");
10087c478bd9Sstevel@tonic-gate 		/*
10097c478bd9Sstevel@tonic-gate 		 * Mark the working list dirty since we modified it.
10107c478bd9Sstevel@tonic-gate 		 * Automatically commit it, for SCSI only.
10117c478bd9Sstevel@tonic-gate 		 */
10127c478bd9Sstevel@tonic-gate 		work_list.flags |= LIST_DIRTY;
10137c478bd9Sstevel@tonic-gate 		status = commit_list();
10147c478bd9Sstevel@tonic-gate 		fmt_print("\n");
10157c478bd9Sstevel@tonic-gate 	}
10167c478bd9Sstevel@tonic-gate 	exit_critical();
10177c478bd9Sstevel@tonic-gate 
10187c478bd9Sstevel@tonic-gate 	/*
10197c478bd9Sstevel@tonic-gate 	 * Return status.
10207c478bd9Sstevel@tonic-gate 	 */
10217c478bd9Sstevel@tonic-gate 	return (status);
10227c478bd9Sstevel@tonic-gate }
1023