diff options
Diffstat (limited to 'usr/src/cmd/format/modify_partition.c')
-rw-r--r-- | usr/src/cmd/format/modify_partition.c | 306 |
1 files changed, 140 insertions, 166 deletions
diff --git a/usr/src/cmd/format/modify_partition.c b/usr/src/cmd/format/modify_partition.c index 8f4905b594..ba168bb79e 100644 --- a/usr/src/cmd/format/modify_partition.c +++ b/usr/src/cmd/format/modify_partition.c @@ -38,26 +38,11 @@ #include "label.h" #include "auto_sense.h" -#ifdef __STDC__ - -/* Function prototypes for ANSI C Compilers */ - static void adj_cyl_offset(struct dk_map32 *map); static int check_map(struct dk_map32 *map); static void get_user_map(struct dk_map32 *map, int float_part); static void get_user_map_efi(struct dk_gpt *map, int float_part); -#else /* __STDC__ */ - -/* Function prototypes for non-ANSI C Compilers */ - -static void adj_cyl_offset(); -static int check_map(); -static void get_user_map(); -static void get_user_map_efi(); - -#endif /* __STDC__ */ - static char *partn_list[] = { "0", "1", "2", "3", "4", "5", "6", "7", NULL }; static char *sel_list[] = { "0", "1", "2", "3", NULL }; @@ -69,7 +54,7 @@ static char *sel_list[] = { "0", "1", "2", "3", NULL }; * Modify/Create a predefined partition table. */ int -p_modify() +p_modify(void) { struct partition_info tmp_pinfo[1]; struct dk_map32 *map = tmp_pinfo->pinfo_map; @@ -134,89 +119,92 @@ currently being used for swapping.\n"); */ if (cur_parts->pinfo_name != NULL) { (void) snprintf(tmpstr, sizeof (tmpstr), - "\t0. Current partition table (%s)", - cur_parts->pinfo_name); + "\t0. Current partition table (%s)", + cur_parts->pinfo_name); } else { (void) sprintf(tmpstr, - "\t0. Current partition table (unnamed)"); + "\t0. Current partition table (unnamed)"); } (void) snprintf(tmpstr2, sizeof (tmpstr2), -"Select partitioning base:\n%s\n" -"\t1. All Free Hog\n" -"Choose base (enter number) ", - tmpstr); + "Select partitioning base:\n%s\n" + "\t1. All Free Hog\n" + "Choose base (enter number) ", + tmpstr); ioparam.io_charlist = sel_list; sel_type = input(FIO_MSTR, tmpstr2, '?', &ioparam, - &sel_type, DATA_INPUT); + &sel_type, DATA_INPUT); switch (cur_label) { case L_TYPE_SOLARIS: - if (sel_type == 0) { - /* - * Check for invalid parameters but do - * not modify the table. - */ - if (check_map(cur_parts->pinfo_map)) { - err_print("\ -Warning: Fix, or select a different partition table.\n"); - return (0); - } - /* - * Create partition map from existing map - */ - tmp_pinfo->vtoc = cur_parts->vtoc; - for (i = 0; i < NDKMAP; i++) { - map[i].dkl_nblk = cur_parts->pinfo_map[i].dkl_nblk; - map[i].dkl_cylno = cur_parts->pinfo_map[i].dkl_cylno; - } - } else { - /* - * Make an empty partition map, with all the space - * in the c partition. - */ - set_vtoc_defaults(tmp_pinfo); - for (i = 0; i < NDKMAP; i++) { - map[i].dkl_nblk = 0; - map[i].dkl_cylno = 0; - } - map[C_PARTITION].dkl_nblk = ncyl * spc(); + if (sel_type == 0) { + /* + * Check for invalid parameters but do + * not modify the table. + */ + if (check_map(cur_parts->pinfo_map)) { + err_print("Warning: Fix, or select a " + "different partition table.\n"); + return (0); + } + /* + * Create partition map from existing map + */ + tmp_pinfo->vtoc = cur_parts->vtoc; + for (i = 0; i < NDKMAP; i++) { + map[i].dkl_nblk = + cur_parts->pinfo_map[i].dkl_nblk; + map[i].dkl_cylno = + cur_parts->pinfo_map[i].dkl_cylno; + } + } else { + /* + * Make an empty partition map, with all the space + * in the c partition. + */ + set_vtoc_defaults(tmp_pinfo); + for (i = 0; i < NDKMAP; i++) { + map[i].dkl_nblk = 0; + map[i].dkl_cylno = 0; + } + map[C_PARTITION].dkl_nblk = ncyl * spc(); #if defined(i386) - /* - * Adjust for the boot and possibly alternates partitions - */ - map[I_PARTITION].dkl_nblk = spc(); - map[I_PARTITION].dkl_cylno = 0; - if (cur_ctype->ctype_ctype != DKC_SCSI_CCS) { - map[J_PARTITION].dkl_nblk = 2 * spc(); - map[J_PARTITION].dkl_cylno = spc() / spc(); - } + /* + * Adjust for the boot and possibly alternates + * partitions. + */ + map[I_PARTITION].dkl_nblk = spc(); + map[I_PARTITION].dkl_cylno = 0; + if (cur_ctype->ctype_ctype != DKC_SCSI_CCS) { + map[J_PARTITION].dkl_nblk = 2 * spc(); + map[J_PARTITION].dkl_cylno = spc() / spc(); + } #endif /* defined(i386) */ - } - break; + } + break; case L_TYPE_EFI: - if (sel_type == 1) { - for (i = 0; i < cur_parts->etoc->efi_nparts; i++) { - cur_parts->etoc->efi_parts[i].p_start = 0; - cur_parts->etoc->efi_parts[i].p_size = 0; + if (sel_type == 1) { + for (i = 0; i < cur_parts->etoc->efi_nparts; i++) { + cur_parts->etoc->efi_parts[i].p_start = 0; + cur_parts->etoc->efi_parts[i].p_size = 0; + } } - } - break; + break; } fmt_print("\n"); if (cur_label == L_TYPE_SOLARIS) { - print_map(tmp_pinfo); + print_map(tmp_pinfo); } else { - print_map(cur_parts); + print_map(cur_parts); } ioparam.io_charlist = confirm_list; - if (input(FIO_MSTR, -"Do you wish to continue creating a new partition\ntable based on above table", - '?', &ioparam, &inpt_dflt, DATA_INPUT)) { + if (input(FIO_MSTR, "Do you wish to continue creating a new " + "partition\ntable based on above table", + '?', &ioparam, &inpt_dflt, DATA_INPUT)) { return (0); } @@ -228,11 +216,11 @@ Warning: Fix, or select a different partition table.\n"); free_hog = G_PARTITION; /* default to g partition */ ioparam.io_charlist = partn_list; free_hog = input(FIO_MSTR, "Free Hog partition", '?', - &ioparam, &free_hog, DATA_INPUT); + &ioparam, &free_hog, DATA_INPUT); /* disallow c partition */ if (free_hog == C_PARTITION) { fmt_print("'%c' cannot be the 'Free Hog' partition.\n", - C_PARTITION + PARTITION_BASE); + C_PARTITION + PARTITION_BASE); free_hog = -1; continue; } @@ -246,7 +234,7 @@ Warning: Fix, or select a different partition table.\n"); map[free_hog].dkl_nblk -= map[I_PARTITION].dkl_nblk; if (cur_ctype->ctype_ctype != DKC_SCSI_CCS) { map[free_hog].dkl_nblk -= - map[J_PARTITION].dkl_nblk; + map[J_PARTITION].dkl_nblk; } #endif /* defined(i386) */ break; @@ -256,11 +244,11 @@ Warning: Fix, or select a different partition table.\n"); * the float partition. */ if (map[free_hog].dkl_nblk == 0) { - err_print("\ -Warning: No space available from Free Hog partition.\n"); + err_print("Warning: No space available from Free Hog " + "partition.\n"); ioparam.io_charlist = confirm_list; if (input(FIO_MSTR, "Continue", '?', - &ioparam, &inpt_dflt, DATA_INPUT)) { + &ioparam, &inpt_dflt, DATA_INPUT)) { free_hog = -1; } } @@ -268,27 +256,27 @@ Warning: No space available from Free Hog partition.\n"); inpt_dflt = 0; if (cur_label == L_TYPE_EFI) { - free_hog = G_PARTITION; /* default to g partition */ - ioparam.io_charlist = partn_list; - free_hog = input(FIO_MSTR, "Free Hog partition", '?', - &ioparam, &free_hog, DATA_INPUT); - /* disallow c partition */ - if (free_hog == C_PARTITION) { - fmt_print("'%c' cannot be the 'Free Hog' partition.\n", - C_PARTITION + PARTITION_BASE); - return (-1); - } - get_user_map_efi(cur_parts->etoc, free_hog); - print_map(cur_parts); - if (check("Ready to label disk, continue")) { - return (-1); - } - fmt_print("\n"); - if (write_label()) { - err_print("Writing label failed\n"); - return (-1); - } - return (0); + free_hog = G_PARTITION; /* default to g partition */ + ioparam.io_charlist = partn_list; + free_hog = input(FIO_MSTR, "Free Hog partition", '?', + &ioparam, &free_hog, DATA_INPUT); + /* disallow c partition */ + if (free_hog == C_PARTITION) { + fmt_print("'%c' cannot be the 'Free Hog' partition.\n", + C_PARTITION + PARTITION_BASE); + return (-1); + } + get_user_map_efi(cur_parts->etoc, free_hog); + print_map(cur_parts); + if (check("Ready to label disk, continue")) { + return (-1); + } + fmt_print("\n"); + if (write_label()) { + err_print("Writing label failed\n"); + return (-1); + } + return (0); } /* * get user modified partition table @@ -304,9 +292,8 @@ Warning: No space available from Free Hog partition.\n"); print_map(tmp_pinfo); ioparam.io_charlist = confirm_list; - if (input(FIO_MSTR, "\ -Okay to make this the current partition table", '?', - &ioparam, &inpt_dflt, DATA_INPUT)) { + if (input(FIO_MSTR, "Okay to make this the current partition table", + '?', &ioparam, &inpt_dflt, DATA_INPUT)) { return (0); } else { make_partition(); @@ -318,9 +305,9 @@ Okay to make this the current partition table", '?', cur_parts->pinfo_map[i].dkl_cylno = map[i].dkl_cylno; #ifdef i386 cur_parts->vtoc.v_part[i].p_start = - map[i].dkl_cylno * nhead * nsect; + map[i].dkl_cylno * nhead * nsect; cur_parts->vtoc.v_part[i].p_size = - map[i].dkl_nblk; + map[i].dkl_nblk; #endif } (void) p_name(); @@ -340,14 +327,11 @@ Okay to make this the current partition table", '?', } } - - /* * Adjust cylinder offsets */ static void -adj_cyl_offset(map) - struct dk_map32 *map; +adj_cyl_offset(struct dk_map32 *map) { int i; int cyloffset = 0; @@ -390,8 +374,7 @@ adj_cyl_offset(map) * Check partition table */ static int -check_map(map) - struct dk_map32 *map; +check_map(struct dk_map32 *map) { int i; int cyloffset = 0; @@ -411,16 +394,16 @@ check_map(map) */ for (i = 0; i < NDKMAP; i++) { if (map[i].dkl_cylno > (blkaddr32_t)ncyl-1) { - err_print("\ -Warning: Partition %c starting cylinder %d is out of range.\n", - (PARTITION_BASE+i), map[i].dkl_cylno); + err_print("Warning: Partition %c starting cylinder " + "%d is out of range.\n", + (PARTITION_BASE+i), map[i].dkl_cylno); return (-1); } if (map[i].dkl_nblk > - (blkaddr32_t)(ncyl - map[i].dkl_cylno) * spc()) { - err_print("\ -Warning: Partition %c, specified # of blocks, %u, is out of range.\n", - (PARTITION_BASE+i), map[i].dkl_nblk); + (blkaddr32_t)(ncyl - map[i].dkl_cylno) * spc()) { + err_print("Warning: Partition %c, specified # of " + "blocks, %u, is out of range.\n", + (PARTITION_BASE+i), map[i].dkl_nblk); return (-1); } if (i != C_PARTITION && map[i].dkl_nblk) { @@ -429,21 +412,21 @@ Warning: Partition %c, specified # of blocks, %u, is out of range.\n", continue; #endif if (map[i].dkl_cylno < cyloffset) { - err_print( -"Warning: Overlapping partition (%c) in table.\n", PARTITION_BASE+i); + err_print("Warning: Overlapping partition " + "(%c) in table.\n", PARTITION_BASE+i); return (-1); } else if (map[i].dkl_cylno > cyloffset) { - err_print( -"Warning: Non-contiguous partition (%c) in table.\n", PARTITION_BASE+i); + err_print("Warning: Non-contiguous partition " + "(%c) in table.\n", PARTITION_BASE+i); } cyloffset += (map[i].dkl_nblk + (spc()-1))/spc(); tot_blks = map[i].dkl_nblk; } } if (tot_blks > map[C_PARTITION].dkl_nblk) { - err_print("\ -Warning: Total blocks used is greater than number of blocks in '%c'\n\ -\tpartition.\n", C_PARTITION + PARTITION_BASE); + err_print("Warning: Total blocks used is greater than number " + "of blocks in '%c'\n\tpartition.\n", + C_PARTITION + PARTITION_BASE); return (-1); } return (0); @@ -455,9 +438,7 @@ Warning: Total blocks used is greater than number of blocks in '%c'\n\ * get user defined partitions */ static void -get_user_map(map, float_part) - struct dk_map32 *map; - int float_part; +get_user_map(struct dk_map32 *map, int float_part) { int i; blkaddr32_t newsize; @@ -471,24 +452,24 @@ get_user_map(map, float_part) for (i = 0; i < NDKMAP; i++) { if (partn_list[i] == NULL) break; - if ((i == C_PARTITION) || (i == float_part)) + if ((i == C_PARTITION) || (i == float_part)) { continue; - else { + } else { ioparam.io_bounds.lower = 0; ioparam.io_bounds.upper = map[i].dkl_nblk + - map[float_part].dkl_nblk; + map[float_part].dkl_nblk; deflt = map[i].dkl_nblk; if (ioparam.io_bounds.upper == 0) { - err_print("\ -Warning: no space available for '%s' from Free Hog partition\n", - partn_list[i]); + err_print("Warning: no space available for " + "'%s' from Free Hog partition\n", + partn_list[i]); continue; } (void) snprintf(tmpstr, sizeof (tmpstr), - "Enter size of partition '%s' ", - partn_list[i]); + "Enter size of partition '%s' ", + partn_list[i]); newsize = (blkaddr32_t)input(FIO_CYL, tmpstr, ':', - &ioparam, (int *)&deflt, DATA_INPUT); + &ioparam, (int *)&deflt, DATA_INPUT); map[float_part].dkl_nblk -= (newsize - map[i].dkl_nblk); map[i].dkl_nblk = newsize; } @@ -496,8 +477,7 @@ Warning: no space available for '%s' from Free Hog partition\n", } static struct partition_info * -build_partition(tptr) -struct disk_type *tptr; +build_partition(struct disk_type *tptr) { struct partition_info *part; struct dk_label *label; @@ -524,21 +504,20 @@ struct disk_type *tptr; if (!build_default_partition(label, cur_ctype->ctype_ctype)) return (NULL); - part = (struct partition_info *) - zalloc(sizeof (struct partition_info)); + part = zalloc(sizeof (struct partition_info)); part->pinfo_name = alloc_string(tptr->dtype_asciilabel); /* * Fill in the partition info from the label */ for (i = 0; i < NDKMAP; i++) { #if defined(_SUNOS_VTOC_8) - part->pinfo_map[i] = label->dkl_map[i]; + part->pinfo_map[i] = label->dkl_map[i]; #else - part->pinfo_map[i].dkl_cylno = - label->dkl_vtoc.v_part[i].p_start / - (blkaddr32_t)(tptr->dtype_nhead * tptr->dtype_nsect - apc); - part->pinfo_map[i].dkl_nblk = - label->dkl_vtoc.v_part[i].p_size; + part->pinfo_map[i].dkl_cylno = + label->dkl_vtoc.v_part[i].p_start / + (blkaddr32_t)(tptr->dtype_nhead * tptr->dtype_nsect - apc); + part->pinfo_map[i].dkl_nblk = + label->dkl_vtoc.v_part[i].p_size; #endif /* ifdefined(_SUNOS_VTOC_8) */ } part->vtoc = label->dkl_vtoc; @@ -549,11 +528,8 @@ struct disk_type *tptr; * build new partition table for given disk type */ static void -get_user_map_efi(map, float_part) - struct dk_gpt *map; - int float_part; +get_user_map_efi(struct dk_gpt *map, int float_part) { - int i; efi_deflt_t efi_deflt; u_ioparam_t ioparam; @@ -591,7 +567,7 @@ get_user_map_efi(map, float_part) } map->efi_parts[float_part].p_start = start_lba; map->efi_parts[float_part].p_size = map->efi_last_u_lba + 1 - - start_lba - reserved; + start_lba - reserved; map->efi_parts[float_part].p_tag = V_USR; if (map->efi_parts[float_part].p_size == 0) { map->efi_parts[float_part].p_size = 0; @@ -612,8 +588,7 @@ get_user_map_efi(map, float_part) void -new_partitiontable(tptr, oldtptr) -struct disk_type *tptr, *oldtptr; +new_partitiontable(struct disk_type *tptr, struct disk_type *oldtptr) { struct partition_info *part; @@ -622,16 +597,15 @@ struct disk_type *tptr, *oldtptr; * partition table else copy the old partition table.(best guess). */ if ((oldtptr != NULL) && - (tptr->dtype_ncyl == oldtptr->dtype_ncyl) && - (tptr->dtype_nhead == oldtptr->dtype_nhead) && - (tptr->dtype_nsect == oldtptr->dtype_nsect)) { - - part = (struct partition_info *) - zalloc(sizeof (struct partition_info)); - bcopy((char *)cur_parts, (char *)part, - sizeof (struct partition_info)); - part->pinfo_next = tptr->dtype_plist; - tptr->dtype_plist = part; + (tptr->dtype_ncyl == oldtptr->dtype_ncyl) && + (tptr->dtype_nhead == oldtptr->dtype_nhead) && + (tptr->dtype_nsect == oldtptr->dtype_nsect)) { + part = (struct partition_info *) + zalloc(sizeof (struct partition_info)); + bcopy((char *)cur_parts, (char *)part, + sizeof (struct partition_info)); + part->pinfo_next = tptr->dtype_plist; + tptr->dtype_plist = part; } else { #ifdef DEBUG |