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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23052b6e8aSbg  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * This file contains the code to add new disk_type and partition
297c478bd9Sstevel@tonic-gate  * definitions to a format data file.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate #include "global.h"
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <ctype.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate #include <fcntl.h>
387c478bd9Sstevel@tonic-gate #include <errno.h>
397c478bd9Sstevel@tonic-gate #include <memory.h>
407c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
417c478bd9Sstevel@tonic-gate #include <sys/param.h>
427c478bd9Sstevel@tonic-gate #include <time.h>
437c478bd9Sstevel@tonic-gate #include <sys/time.h>
447c478bd9Sstevel@tonic-gate #include <stdarg.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #include "add_definition.h"
477c478bd9Sstevel@tonic-gate #include "misc.h"
487c478bd9Sstevel@tonic-gate #include "partition.h"
497c478bd9Sstevel@tonic-gate #include "menu_command.h"
507c478bd9Sstevel@tonic-gate #include "startup.h"
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate extern	struct	ctlr_type ctlr_types[];
537c478bd9Sstevel@tonic-gate extern	int	nctypes;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate extern	int	errno;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /* Function prototypes */
587c478bd9Sstevel@tonic-gate #ifdef	__STDC__
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate static void	add_disktype(FILE *fd, struct disk_info *disk_info);
617c478bd9Sstevel@tonic-gate static void	add_partition(FILE *fd, struct disk_info *,
627c478bd9Sstevel@tonic-gate 		struct partition_info *);
637c478bd9Sstevel@tonic-gate static int	add_entry(int col, FILE *fd, char *format, ...);
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #else	/* __STDC__ */
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate static void	add_disktype();
687c478bd9Sstevel@tonic-gate static void	add_partition();
697c478bd9Sstevel@tonic-gate static int	add_entry();
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * Add new definitions for the current disk/partition to a format data file.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate int
add_definition(void)77*b12aaafbSToomas Soome add_definition(void)
787c478bd9Sstevel@tonic-gate {
797c478bd9Sstevel@tonic-gate 	FILE	*fd;
807c478bd9Sstevel@tonic-gate 	char	*filename;
817c478bd9Sstevel@tonic-gate 	time_t	clock;
827c478bd9Sstevel@tonic-gate 	char	*prompt;
837c478bd9Sstevel@tonic-gate 	union {
847c478bd9Sstevel@tonic-gate 		int	xfoo;
857c478bd9Sstevel@tonic-gate 		char	deflt_str[MAXPATHLEN];
867c478bd9Sstevel@tonic-gate 	} x;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	/*
897c478bd9Sstevel@tonic-gate 	 * There must be a current disk and partition table
907c478bd9Sstevel@tonic-gate 	 */
917c478bd9Sstevel@tonic-gate 	if (cur_disk == NULL) {
927c478bd9Sstevel@tonic-gate 		err_print("No Current Disk.\n");
937c478bd9Sstevel@tonic-gate 		return (0);
947c478bd9Sstevel@tonic-gate 	}
957c478bd9Sstevel@tonic-gate 	if (cur_dtype == NULL) {
967c478bd9Sstevel@tonic-gate 		err_print("Current disk type is not set.\n");
977c478bd9Sstevel@tonic-gate 		return (-1);
987c478bd9Sstevel@tonic-gate 	}
997c478bd9Sstevel@tonic-gate 	if (cur_parts == NULL) {
1007c478bd9Sstevel@tonic-gate 		err_print("Current partition is not set.\n");
1017c478bd9Sstevel@tonic-gate 		return (-1);
1027c478bd9Sstevel@tonic-gate 	}
1037c478bd9Sstevel@tonic-gate 	/*
1047c478bd9Sstevel@tonic-gate 	 * If neither the disk definition nor the partition
1057c478bd9Sstevel@tonic-gate 	 * information has been changed, there's nothing to save.
1067c478bd9Sstevel@tonic-gate 	 */
1077c478bd9Sstevel@tonic-gate 	if (cur_dtype->dtype_filename != NULL &&
108*b12aaafbSToomas Soome 	    cur_parts->pinfo_filename != NULL) {
1097c478bd9Sstevel@tonic-gate 		err_print("\
1107c478bd9Sstevel@tonic-gate Neither the disk type nor the partitioning has been changed.\n");
1117c478bd9Sstevel@tonic-gate 		return (-1);
1127c478bd9Sstevel@tonic-gate 	}
1137c478bd9Sstevel@tonic-gate 	/*
1147c478bd9Sstevel@tonic-gate 	 * If saving the partition, and it's unnamed, the user should name
1157c478bd9Sstevel@tonic-gate 	 * it first.
1167c478bd9Sstevel@tonic-gate 	 */
1177c478bd9Sstevel@tonic-gate 	if (cur_parts->pinfo_name == NULL) {
1187c478bd9Sstevel@tonic-gate 		assert(cur_parts->pinfo_filename == NULL);
1197c478bd9Sstevel@tonic-gate 		err_print("Please name this partition type before saving it\n");
1207c478bd9Sstevel@tonic-gate 		return (-1);
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 	/*
1237c478bd9Sstevel@tonic-gate 	 * Let the user know what we're doing
1247c478bd9Sstevel@tonic-gate 	 */
1257c478bd9Sstevel@tonic-gate 	if (cur_dtype->dtype_filename == NULL &&
126*b12aaafbSToomas Soome 	    cur_parts->pinfo_filename == NULL) {
1277c478bd9Sstevel@tonic-gate 		fmt_print("Saving new disk and partition definitions\n");
1287c478bd9Sstevel@tonic-gate 	} else if (cur_dtype->dtype_filename == NULL) {
1297c478bd9Sstevel@tonic-gate 		fmt_print("Saving new disk definition\n");
1307c478bd9Sstevel@tonic-gate 	} else {
1317c478bd9Sstevel@tonic-gate 		assert(cur_parts->pinfo_filename == NULL);
1327c478bd9Sstevel@tonic-gate 		fmt_print("Saving new partition definition\n");
1337c478bd9Sstevel@tonic-gate 	}
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * Ask for the file to which to append the new definitions
1367c478bd9Sstevel@tonic-gate 	 */
1377c478bd9Sstevel@tonic-gate 	prompt = "Enter file name";
1387c478bd9Sstevel@tonic-gate 	(void) strcpy(x.deflt_str, "./format.dat");
139052b6e8aSbg 	filename = (char *)(uintptr_t)input(FIO_OSTR, prompt,
140*b12aaafbSToomas Soome 	    ':', NULL, &x.xfoo, DATA_INPUT);
1417c478bd9Sstevel@tonic-gate 	assert(filename != NULL);
1427c478bd9Sstevel@tonic-gate 	/*
1437c478bd9Sstevel@tonic-gate 	 * Open the file in append mode, or create it, if necessary
1447c478bd9Sstevel@tonic-gate 	 */
1457c478bd9Sstevel@tonic-gate 	if ((fd = fopen(filename, "a")) == NULL) {
1467c478bd9Sstevel@tonic-gate 		err_print("Cannot open `%s' - %s\n", filename,
147*b12aaafbSToomas Soome 		    strerror(errno));
1487c478bd9Sstevel@tonic-gate 		destroy_data(filename);
1497c478bd9Sstevel@tonic-gate 		return (-1);
1507c478bd9Sstevel@tonic-gate 	}
1517c478bd9Sstevel@tonic-gate 	/*
1527c478bd9Sstevel@tonic-gate 	 * Write a header for the new definitions
1537c478bd9Sstevel@tonic-gate 	 */
1547c478bd9Sstevel@tonic-gate 	if ((cur_dtype->dtype_filename == NULL) &&
155*b12aaafbSToomas Soome 	    (cur_parts->pinfo_filename == NULL)) {
1567c478bd9Sstevel@tonic-gate 		(void) fprintf(fd, "#\n# New disk/partition type ");
1577c478bd9Sstevel@tonic-gate 	} else if (cur_dtype->dtype_filename == NULL) {
1587c478bd9Sstevel@tonic-gate 		(void) fprintf(fd, "#\n# New disk type ");
1597c478bd9Sstevel@tonic-gate 	} else {
1607c478bd9Sstevel@tonic-gate 		(void) fprintf(fd, "#\n# New partition type ");
1617c478bd9Sstevel@tonic-gate 	}
1627c478bd9Sstevel@tonic-gate 	(void) time(&clock);
1637c478bd9Sstevel@tonic-gate 	(void) fprintf(fd, " saved on %s#\n", ctime(&clock));
1647c478bd9Sstevel@tonic-gate 	/*
1657c478bd9Sstevel@tonic-gate 	 * Save the new definitions
1667c478bd9Sstevel@tonic-gate 	 */
1677c478bd9Sstevel@tonic-gate 	if (cur_dtype->dtype_filename == NULL) {
1687c478bd9Sstevel@tonic-gate 		add_disktype(fd, cur_disk);
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 	if (cur_parts->pinfo_filename == NULL) {
1717c478bd9Sstevel@tonic-gate 		add_partition(fd, cur_disk, cur_parts);
1727c478bd9Sstevel@tonic-gate 	}
1737c478bd9Sstevel@tonic-gate 	/*
1747c478bd9Sstevel@tonic-gate 	 * We're finished.  Clean up
1757c478bd9Sstevel@tonic-gate 	 */
1767c478bd9Sstevel@tonic-gate 	(void) fclose(fd);
1777c478bd9Sstevel@tonic-gate 	destroy_data(filename);
1787c478bd9Sstevel@tonic-gate 	return (0);
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate  * Add a disk_type definition to the file fd
1837c478bd9Sstevel@tonic-gate  */
1847c478bd9Sstevel@tonic-gate static void
add_disktype(FILE * fd,struct disk_info * disk_info)185*b12aaafbSToomas Soome add_disktype(FILE *fd, struct disk_info *disk_info)
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate 	int			col;
1887c478bd9Sstevel@tonic-gate 	struct disk_type	*disk_type;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	disk_type = disk_info->disk_type;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	(void) fprintf(fd, "disk_type = \"%s\" \\\n",
193*b12aaafbSToomas Soome 	    disk_type->dtype_asciilabel);
1947c478bd9Sstevel@tonic-gate 	col = add_entry(0, fd, " : ctlr = %s",
195*b12aaafbSToomas Soome 	    ((disk_info->disk_ctlr)->ctlr_ctype)->ctype_name);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	col = add_entry(col, fd, " : ncyl = %d", disk_type->dtype_ncyl);
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	col = add_entry(col, fd, " : acyl = %d", disk_type->dtype_acyl);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	col = add_entry(col, fd, " : pcyl = %d", disk_type->dtype_pcyl);
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	col = add_entry(col, fd, " : nhead = %d", disk_type->dtype_nhead);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_PHEAD) {
2067c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : phead = %d",
207*b12aaafbSToomas Soome 		    disk_type->dtype_phead);
2087c478bd9Sstevel@tonic-gate 	}
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	col = add_entry(col, fd, " : nsect = %d", disk_type->dtype_nsect);
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_PSECT) {
2137c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : psect = %d",
214*b12aaafbSToomas Soome 		    disk_type->dtype_psect);
2157c478bd9Sstevel@tonic-gate 	}
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_BPT) {
2187c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : bpt = %d", disk_type->dtype_bpt);
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	col = add_entry(col, fd, " : rpm = %d", disk_type->dtype_rpm);
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_FMTTIME) {
2247c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : fmt_time = %d",
225*b12aaafbSToomas Soome 		    disk_type->dtype_fmt_time);
2267c478bd9Sstevel@tonic-gate 	}
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_CYLSKEW) {
2297c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : cyl_skew = %d",
230*b12aaafbSToomas Soome 		    disk_type->dtype_cyl_skew);
2317c478bd9Sstevel@tonic-gate 	}
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_TRKSKEW) {
2347c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : trk_skew = %d",
235*b12aaafbSToomas Soome 		    disk_type->dtype_trk_skew);
2367c478bd9Sstevel@tonic-gate 	}
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_TRKS_ZONE) {
2397c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : trks_zone = %d",
240*b12aaafbSToomas Soome 		    disk_type->dtype_trks_zone);
2417c478bd9Sstevel@tonic-gate 	}
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_ATRKS) {
2447c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : atrks = %d",
245*b12aaafbSToomas Soome 		    disk_type->dtype_atrks);
2467c478bd9Sstevel@tonic-gate 	}
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_ASECT) {
2497c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : asect = %d",
250*b12aaafbSToomas Soome 		    disk_type->dtype_asect);
2517c478bd9Sstevel@tonic-gate 	}
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_CACHE) {
2547c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : cache = %d",
255*b12aaafbSToomas Soome 		    disk_type->dtype_cache);
2567c478bd9Sstevel@tonic-gate 	}
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_PREFETCH) {
2597c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : prefetch = %d",
260*b12aaafbSToomas Soome 		    disk_type->dtype_threshold);
2617c478bd9Sstevel@tonic-gate 	}
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_CACHE_MIN) {
2647c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : min_prefetch = %d",
265*b12aaafbSToomas Soome 		    disk_type->dtype_prefetch_min);
2667c478bd9Sstevel@tonic-gate 	}
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_CACHE_MAX) {
2697c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : max_prefetch = %d",
270*b12aaafbSToomas Soome 		    disk_type->dtype_prefetch_max);
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_BPS) {
2747c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : bps = %d",
275*b12aaafbSToomas Soome 		    disk_type->dtype_bps);
2767c478bd9Sstevel@tonic-gate 	}
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	if (disk_type->dtype_options & SUP_DRTYPE) {
2797c478bd9Sstevel@tonic-gate 		col = add_entry(col, fd, " : drive_type = %d",
280*b12aaafbSToomas Soome 		    disk_type->dtype_dr_type);
2817c478bd9Sstevel@tonic-gate 	}
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	/*
2847c478bd9Sstevel@tonic-gate 	 * Terminate the last line, and print one blank line
2857c478bd9Sstevel@tonic-gate 	 */
2867c478bd9Sstevel@tonic-gate 	(void) fprintf(fd, col == 0 ? "\n" : "\n\n");
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /*
2927c478bd9Sstevel@tonic-gate  * Once we exceed this length, wrap to a new line
2937c478bd9Sstevel@tonic-gate  */
2947c478bd9Sstevel@tonic-gate #define	MAX_COLUMNS	50
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate /*
2977c478bd9Sstevel@tonic-gate  * Add a partition definition to the file fd
2987c478bd9Sstevel@tonic-gate  */
2997c478bd9Sstevel@tonic-gate static void
add_partition(FILE * fd,struct disk_info * disk_info,struct partition_info * part)300*b12aaafbSToomas Soome add_partition(FILE *fd, struct disk_info *disk_info,
301*b12aaafbSToomas Soome     struct partition_info *part)
3027c478bd9Sstevel@tonic-gate {
3037c478bd9Sstevel@tonic-gate 	int			col;
3047c478bd9Sstevel@tonic-gate 	int			i;
3057c478bd9Sstevel@tonic-gate 	struct disk_type	*disk_type;
3067c478bd9Sstevel@tonic-gate 	struct dk_map32		*pp;
3077c478bd9Sstevel@tonic-gate 	char			*s;
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_8)
3107c478bd9Sstevel@tonic-gate 	struct dk_map2		*pv;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_16)
3137c478bd9Sstevel@tonic-gate 	struct dkl_partition	*pv;
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate #else
3167c478bd9Sstevel@tonic-gate #error No VTOC format defined.
3177c478bd9Sstevel@tonic-gate #endif			/* defined (_SUNOS_VTOC_8) */
3187c478bd9Sstevel@tonic-gate 	struct dk_map2		*dv;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	disk_type = disk_info->disk_type;
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	(void) fprintf(fd, "partition = \"%s\" \\\n", part->pinfo_name);
3237c478bd9Sstevel@tonic-gate 	(void) fprintf(fd, "\t : disk = \"%s\" : ctlr = %s \\\n",
324*b12aaafbSToomas Soome 	    disk_type->dtype_asciilabel,
325*b12aaafbSToomas Soome 	    ((disk_info->disk_ctlr)->ctlr_ctype)->ctype_name);
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	/*
3287c478bd9Sstevel@tonic-gate 	 * Print the specifications for each useful partition
3297c478bd9Sstevel@tonic-gate 	 */
3307c478bd9Sstevel@tonic-gate 	col = 0;
3317c478bd9Sstevel@tonic-gate 	pp = part->pinfo_map;
3327c478bd9Sstevel@tonic-gate 	pv = part->vtoc.v_part;
3337c478bd9Sstevel@tonic-gate 	dv = default_vtoc_map;
3347c478bd9Sstevel@tonic-gate 	for (i = 0; i < NDKMAP; i++, pp++, pv++, dv++) {
3357c478bd9Sstevel@tonic-gate 		if (pp->dkl_nblk != 0) {
3367c478bd9Sstevel@tonic-gate 			col = add_entry(col, fd, " : %c = ",
337*b12aaafbSToomas Soome 			    i + PARTITION_BASE);
3387c478bd9Sstevel@tonic-gate 			if (pv->p_tag != dv->p_tag ||
339*b12aaafbSToomas Soome 			    pv->p_flag != dv->p_flag) {
340*b12aaafbSToomas Soome 				s = find_string(ptag_choices, (int)pv->p_tag);
3417c478bd9Sstevel@tonic-gate 				if (s != NULL) {
3427c478bd9Sstevel@tonic-gate 					col = add_entry(col, fd, " %s,", s);
3437c478bd9Sstevel@tonic-gate 				}
344*b12aaafbSToomas Soome 				s = find_string(pflag_choices, (int)pv->p_flag);
3457c478bd9Sstevel@tonic-gate 				if (s != NULL) {
3467c478bd9Sstevel@tonic-gate 					col = add_entry(col, fd, " %s,", s);
3477c478bd9Sstevel@tonic-gate 				}
3487c478bd9Sstevel@tonic-gate 			}
3497c478bd9Sstevel@tonic-gate 			col = add_entry(col, fd, " %d, %d", pp->dkl_cylno,
350*b12aaafbSToomas Soome 			    pp->dkl_nblk);
3517c478bd9Sstevel@tonic-gate 		}
3527c478bd9Sstevel@tonic-gate 	}
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	/*
3557c478bd9Sstevel@tonic-gate 	 * Terminate the last line, and print one blank line
3567c478bd9Sstevel@tonic-gate 	 */
3577c478bd9Sstevel@tonic-gate 	(void) fprintf(fd, col == 0 ? "\n" : "\n\n");
3587c478bd9Sstevel@tonic-gate }
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate /*
3617c478bd9Sstevel@tonic-gate  * Add an entry to the file fd.  col is the current starting column.
3627c478bd9Sstevel@tonic-gate  * Return the resulting new column position.
3637c478bd9Sstevel@tonic-gate  */
3647c478bd9Sstevel@tonic-gate /*PRINTFLIKE3*/
3657c478bd9Sstevel@tonic-gate static int
add_entry(int col,FILE * fd,char * format,...)3667c478bd9Sstevel@tonic-gate add_entry(int col, FILE *fd, char *format, ...)
3677c478bd9Sstevel@tonic-gate {
3687c478bd9Sstevel@tonic-gate 	va_list	ap;
3697c478bd9Sstevel@tonic-gate 	va_start(ap, format);
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 	if (col > MAX_COLUMNS) {
3727c478bd9Sstevel@tonic-gate 		(void) fprintf(fd, " \\\n");
3737c478bd9Sstevel@tonic-gate 		col = 0;
3747c478bd9Sstevel@tonic-gate 	}
3757c478bd9Sstevel@tonic-gate 	if (col == 0) {
3767c478bd9Sstevel@tonic-gate 		col += fprintf(fd, "\t");
3777c478bd9Sstevel@tonic-gate 	}
3787c478bd9Sstevel@tonic-gate 	col += vfprintf(fd, format, ap);
3797c478bd9Sstevel@tonic-gate 	va_end(ap);
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate 	return (col);
3827c478bd9Sstevel@tonic-gate }
383