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 /*
23*052b6e8aSbg159949 * 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 #pragma ident "%Z%%M% %I% %E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate * This file contains the code to add new disk_type and partition
317c478bd9Sstevel@tonic-gate * definitions to a format data file.
327c478bd9Sstevel@tonic-gate */
337c478bd9Sstevel@tonic-gate #include "global.h"
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include <ctype.h>
367c478bd9Sstevel@tonic-gate #include <stdlib.h>
377c478bd9Sstevel@tonic-gate #include <unistd.h>
387c478bd9Sstevel@tonic-gate #include <string.h>
397c478bd9Sstevel@tonic-gate #include <fcntl.h>
407c478bd9Sstevel@tonic-gate #include <errno.h>
417c478bd9Sstevel@tonic-gate #include <memory.h>
427c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
437c478bd9Sstevel@tonic-gate #include <sys/param.h>
447c478bd9Sstevel@tonic-gate #include <time.h>
457c478bd9Sstevel@tonic-gate #include <sys/time.h>
467c478bd9Sstevel@tonic-gate #include <stdarg.h>
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate #include "add_definition.h"
497c478bd9Sstevel@tonic-gate #include "misc.h"
507c478bd9Sstevel@tonic-gate #include "partition.h"
517c478bd9Sstevel@tonic-gate #include "menu_command.h"
527c478bd9Sstevel@tonic-gate #include "startup.h"
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate extern struct ctlr_type ctlr_types[];
557c478bd9Sstevel@tonic-gate extern int nctypes;
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate extern int errno;
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate /* Function prototypes */
607c478bd9Sstevel@tonic-gate #ifdef __STDC__
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate static void add_disktype(FILE *fd, struct disk_info *disk_info);
637c478bd9Sstevel@tonic-gate static void add_partition(FILE *fd, struct disk_info *,
647c478bd9Sstevel@tonic-gate struct partition_info *);
657c478bd9Sstevel@tonic-gate static int add_entry(int col, FILE *fd, char *format, ...);
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate #else /* __STDC__ */
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate static void add_disktype();
707c478bd9Sstevel@tonic-gate static void add_partition();
717c478bd9Sstevel@tonic-gate static int add_entry();
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate * Add new definitions for the current disk/partition to a format data file.
777c478bd9Sstevel@tonic-gate */
787c478bd9Sstevel@tonic-gate int
add_definition()797c478bd9Sstevel@tonic-gate add_definition()
807c478bd9Sstevel@tonic-gate {
817c478bd9Sstevel@tonic-gate FILE *fd;
827c478bd9Sstevel@tonic-gate char *filename;
837c478bd9Sstevel@tonic-gate time_t clock;
847c478bd9Sstevel@tonic-gate char *prompt;
857c478bd9Sstevel@tonic-gate union {
867c478bd9Sstevel@tonic-gate int xfoo;
877c478bd9Sstevel@tonic-gate char deflt_str[MAXPATHLEN];
887c478bd9Sstevel@tonic-gate } x;
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate * There must be a current disk and partition table
927c478bd9Sstevel@tonic-gate */
937c478bd9Sstevel@tonic-gate if (cur_disk == NULL) {
947c478bd9Sstevel@tonic-gate err_print("No Current Disk.\n");
957c478bd9Sstevel@tonic-gate return (0);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate if (cur_dtype == NULL) {
987c478bd9Sstevel@tonic-gate err_print("Current disk type is not set.\n");
997c478bd9Sstevel@tonic-gate return (-1);
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate if (cur_parts == NULL) {
1027c478bd9Sstevel@tonic-gate err_print("Current partition is not set.\n");
1037c478bd9Sstevel@tonic-gate return (-1);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate * If neither the disk definition nor the partition
1077c478bd9Sstevel@tonic-gate * information has been changed, there's nothing to save.
1087c478bd9Sstevel@tonic-gate */
1097c478bd9Sstevel@tonic-gate if (cur_dtype->dtype_filename != NULL &&
1107c478bd9Sstevel@tonic-gate cur_parts->pinfo_filename != NULL) {
1117c478bd9Sstevel@tonic-gate err_print("\
1127c478bd9Sstevel@tonic-gate Neither the disk type nor the partitioning has been changed.\n");
1137c478bd9Sstevel@tonic-gate return (-1);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate * If saving the partition, and it's unnamed, the user should name
1177c478bd9Sstevel@tonic-gate * it first.
1187c478bd9Sstevel@tonic-gate */
1197c478bd9Sstevel@tonic-gate if (cur_parts->pinfo_name == NULL) {
1207c478bd9Sstevel@tonic-gate assert(cur_parts->pinfo_filename == NULL);
1217c478bd9Sstevel@tonic-gate err_print("Please name this partition type before saving it\n");
1227c478bd9Sstevel@tonic-gate return (-1);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate * Let the user know what we're doing
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate if (cur_dtype->dtype_filename == NULL &&
1287c478bd9Sstevel@tonic-gate cur_parts->pinfo_filename == NULL) {
1297c478bd9Sstevel@tonic-gate fmt_print("Saving new disk and partition definitions\n");
1307c478bd9Sstevel@tonic-gate } else if (cur_dtype->dtype_filename == NULL) {
1317c478bd9Sstevel@tonic-gate fmt_print("Saving new disk definition\n");
1327c478bd9Sstevel@tonic-gate } else {
1337c478bd9Sstevel@tonic-gate assert(cur_parts->pinfo_filename == NULL);
1347c478bd9Sstevel@tonic-gate fmt_print("Saving new partition definition\n");
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate * Ask for the file to which to append the new definitions
1387c478bd9Sstevel@tonic-gate */
1397c478bd9Sstevel@tonic-gate prompt = "Enter file name";
1407c478bd9Sstevel@tonic-gate (void) strcpy(x.deflt_str, "./format.dat");
141*052b6e8aSbg159949 filename = (char *)(uintptr_t)input(FIO_OSTR, prompt,
1427c478bd9Sstevel@tonic-gate ':', (u_ioparam_t *)NULL, &x.xfoo, DATA_INPUT);
1437c478bd9Sstevel@tonic-gate assert(filename != NULL);
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate * Open the file in append mode, or create it, if necessary
1467c478bd9Sstevel@tonic-gate */
1477c478bd9Sstevel@tonic-gate if ((fd = fopen(filename, "a")) == NULL) {
1487c478bd9Sstevel@tonic-gate err_print("Cannot open `%s' - %s\n", filename,
1497c478bd9Sstevel@tonic-gate strerror(errno));
1507c478bd9Sstevel@tonic-gate destroy_data(filename);
1517c478bd9Sstevel@tonic-gate return (-1);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate * Write a header for the new definitions
1557c478bd9Sstevel@tonic-gate */
1567c478bd9Sstevel@tonic-gate if ((cur_dtype->dtype_filename == NULL) &&
1577c478bd9Sstevel@tonic-gate (cur_parts->pinfo_filename == NULL)) {
1587c478bd9Sstevel@tonic-gate (void) fprintf(fd, "#\n# New disk/partition type ");
1597c478bd9Sstevel@tonic-gate } else if (cur_dtype->dtype_filename == NULL) {
1607c478bd9Sstevel@tonic-gate (void) fprintf(fd, "#\n# New disk type ");
1617c478bd9Sstevel@tonic-gate } else {
1627c478bd9Sstevel@tonic-gate (void) fprintf(fd, "#\n# New partition type ");
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate (void) time(&clock);
1657c478bd9Sstevel@tonic-gate (void) fprintf(fd, " saved on %s#\n", ctime(&clock));
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate * Save the new definitions
1687c478bd9Sstevel@tonic-gate */
1697c478bd9Sstevel@tonic-gate if (cur_dtype->dtype_filename == NULL) {
1707c478bd9Sstevel@tonic-gate add_disktype(fd, cur_disk);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate if (cur_parts->pinfo_filename == NULL) {
1737c478bd9Sstevel@tonic-gate add_partition(fd, cur_disk, cur_parts);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate * We're finished. Clean up
1777c478bd9Sstevel@tonic-gate */
1787c478bd9Sstevel@tonic-gate (void) fclose(fd);
1797c478bd9Sstevel@tonic-gate destroy_data(filename);
1807c478bd9Sstevel@tonic-gate return (0);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate /*
1847c478bd9Sstevel@tonic-gate * Add a disk_type definition to the file fd
1857c478bd9Sstevel@tonic-gate */
1867c478bd9Sstevel@tonic-gate static void
add_disktype(fd,disk_info)1877c478bd9Sstevel@tonic-gate add_disktype(fd, disk_info)
1887c478bd9Sstevel@tonic-gate FILE *fd;
1897c478bd9Sstevel@tonic-gate struct disk_info *disk_info;
1907c478bd9Sstevel@tonic-gate {
1917c478bd9Sstevel@tonic-gate int col;
1927c478bd9Sstevel@tonic-gate struct disk_type *disk_type;
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate disk_type = disk_info->disk_type;
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate (void) fprintf(fd, "disk_type = \"%s\" \\\n",
1977c478bd9Sstevel@tonic-gate disk_type->dtype_asciilabel);
1987c478bd9Sstevel@tonic-gate col = add_entry(0, fd, " : ctlr = %s",
1997c478bd9Sstevel@tonic-gate ((disk_info->disk_ctlr)->ctlr_ctype)->ctype_name);
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : ncyl = %d", disk_type->dtype_ncyl);
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : acyl = %d", disk_type->dtype_acyl);
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : pcyl = %d", disk_type->dtype_pcyl);
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : nhead = %d", disk_type->dtype_nhead);
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_PHEAD) {
2107c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : phead = %d",
2117c478bd9Sstevel@tonic-gate disk_type->dtype_phead);
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : nsect = %d", disk_type->dtype_nsect);
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_PSECT) {
2177c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : psect = %d",
2187c478bd9Sstevel@tonic-gate disk_type->dtype_psect);
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_BPT) {
2227c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : bpt = %d", disk_type->dtype_bpt);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : rpm = %d", disk_type->dtype_rpm);
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_FMTTIME) {
2287c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : fmt_time = %d",
2297c478bd9Sstevel@tonic-gate disk_type->dtype_fmt_time);
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_CYLSKEW) {
2337c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : cyl_skew = %d",
2347c478bd9Sstevel@tonic-gate disk_type->dtype_cyl_skew);
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_TRKSKEW) {
2387c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : trk_skew = %d",
2397c478bd9Sstevel@tonic-gate disk_type->dtype_trk_skew);
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_TRKS_ZONE) {
2437c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : trks_zone = %d",
2447c478bd9Sstevel@tonic-gate disk_type->dtype_trks_zone);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_ATRKS) {
2487c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : atrks = %d",
2497c478bd9Sstevel@tonic-gate disk_type->dtype_atrks);
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_ASECT) {
2537c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : asect = %d",
2547c478bd9Sstevel@tonic-gate disk_type->dtype_asect);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_CACHE) {
2587c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : cache = %d",
2597c478bd9Sstevel@tonic-gate disk_type->dtype_cache);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_PREFETCH) {
2637c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : prefetch = %d",
2647c478bd9Sstevel@tonic-gate disk_type->dtype_threshold);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_CACHE_MIN) {
2687c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : min_prefetch = %d",
2697c478bd9Sstevel@tonic-gate disk_type->dtype_prefetch_min);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_CACHE_MAX) {
2737c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : max_prefetch = %d",
2747c478bd9Sstevel@tonic-gate disk_type->dtype_prefetch_max);
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_BPS) {
2787c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : bps = %d",
2797c478bd9Sstevel@tonic-gate disk_type->dtype_bps);
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate if (disk_type->dtype_options & SUP_DRTYPE) {
2837c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : drive_type = %d",
2847c478bd9Sstevel@tonic-gate disk_type->dtype_dr_type);
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate /*
2887c478bd9Sstevel@tonic-gate * Terminate the last line, and print one blank line
2897c478bd9Sstevel@tonic-gate */
2907c478bd9Sstevel@tonic-gate (void) fprintf(fd, col == 0 ? "\n" : "\n\n");
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate * Once we exceed this length, wrap to a new line
2977c478bd9Sstevel@tonic-gate */
2987c478bd9Sstevel@tonic-gate #define MAX_COLUMNS 50
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate /*
3017c478bd9Sstevel@tonic-gate * Add a partition definition to the file fd
3027c478bd9Sstevel@tonic-gate */
3037c478bd9Sstevel@tonic-gate static void
add_partition(fd,disk_info,part)3047c478bd9Sstevel@tonic-gate add_partition(fd, disk_info, part)
3057c478bd9Sstevel@tonic-gate FILE *fd;
3067c478bd9Sstevel@tonic-gate struct disk_info *disk_info;
3077c478bd9Sstevel@tonic-gate struct partition_info *part;
3087c478bd9Sstevel@tonic-gate {
3097c478bd9Sstevel@tonic-gate int col;
3107c478bd9Sstevel@tonic-gate int i;
3117c478bd9Sstevel@tonic-gate struct disk_type *disk_type;
3127c478bd9Sstevel@tonic-gate struct dk_map32 *pp;
3137c478bd9Sstevel@tonic-gate char *s;
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_8)
3167c478bd9Sstevel@tonic-gate struct dk_map2 *pv;
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_16)
3197c478bd9Sstevel@tonic-gate struct dkl_partition *pv;
3207c478bd9Sstevel@tonic-gate
3217c478bd9Sstevel@tonic-gate #else
3227c478bd9Sstevel@tonic-gate #error No VTOC format defined.
3237c478bd9Sstevel@tonic-gate #endif /* defined (_SUNOS_VTOC_8) */
3247c478bd9Sstevel@tonic-gate struct dk_map2 *dv;
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate disk_type = disk_info->disk_type;
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate (void) fprintf(fd, "partition = \"%s\" \\\n", part->pinfo_name);
3297c478bd9Sstevel@tonic-gate (void) fprintf(fd, "\t : disk = \"%s\" : ctlr = %s \\\n",
3307c478bd9Sstevel@tonic-gate disk_type->dtype_asciilabel,
3317c478bd9Sstevel@tonic-gate ((disk_info->disk_ctlr)->ctlr_ctype)->ctype_name);
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate /*
3347c478bd9Sstevel@tonic-gate * Print the specifications for each useful partition
3357c478bd9Sstevel@tonic-gate */
3367c478bd9Sstevel@tonic-gate col = 0;
3377c478bd9Sstevel@tonic-gate pp = part->pinfo_map;
3387c478bd9Sstevel@tonic-gate pv = part->vtoc.v_part;
3397c478bd9Sstevel@tonic-gate dv = default_vtoc_map;
3407c478bd9Sstevel@tonic-gate for (i = 0; i < NDKMAP; i++, pp++, pv++, dv++) {
3417c478bd9Sstevel@tonic-gate if (pp->dkl_nblk != 0) {
3427c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " : %c = ",
3437c478bd9Sstevel@tonic-gate i + PARTITION_BASE);
3447c478bd9Sstevel@tonic-gate if (pv->p_tag != dv->p_tag ||
3457c478bd9Sstevel@tonic-gate pv->p_flag != dv->p_flag) {
3467c478bd9Sstevel@tonic-gate s = find_string(ptag_choices,
3477c478bd9Sstevel@tonic-gate (int)pv->p_tag);
3487c478bd9Sstevel@tonic-gate if (s != NULL) {
3497c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " %s,", s);
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate s = find_string(pflag_choices,
3527c478bd9Sstevel@tonic-gate (int)pv->p_flag);
3537c478bd9Sstevel@tonic-gate if (s != NULL) {
3547c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " %s,", s);
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate col = add_entry(col, fd, " %d, %d", pp->dkl_cylno,
3587c478bd9Sstevel@tonic-gate pp->dkl_nblk);
3597c478bd9Sstevel@tonic-gate }
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate
3627c478bd9Sstevel@tonic-gate /*
3637c478bd9Sstevel@tonic-gate * Terminate the last line, and print one blank line
3647c478bd9Sstevel@tonic-gate */
3657c478bd9Sstevel@tonic-gate (void) fprintf(fd, col == 0 ? "\n" : "\n\n");
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate /*
3697c478bd9Sstevel@tonic-gate * Add an entry to the file fd. col is the current starting column.
3707c478bd9Sstevel@tonic-gate * Return the resulting new column position.
3717c478bd9Sstevel@tonic-gate */
3727c478bd9Sstevel@tonic-gate /*PRINTFLIKE3*/
3737c478bd9Sstevel@tonic-gate static int
add_entry(int col,FILE * fd,char * format,...)3747c478bd9Sstevel@tonic-gate add_entry(int col, FILE *fd, char *format, ...)
3757c478bd9Sstevel@tonic-gate {
3767c478bd9Sstevel@tonic-gate va_list ap;
3777c478bd9Sstevel@tonic-gate va_start(ap, format);
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate if (col > MAX_COLUMNS) {
3807c478bd9Sstevel@tonic-gate (void) fprintf(fd, " \\\n");
3817c478bd9Sstevel@tonic-gate col = 0;
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate if (col == 0) {
3847c478bd9Sstevel@tonic-gate col += fprintf(fd, "\t");
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate col += vfprintf(fd, format, ap);
3877c478bd9Sstevel@tonic-gate va_end(ap);
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate return (col);
3907c478bd9Sstevel@tonic-gate }
391