menu_partition.c revision 3a5b922f0684c84516905a0053650ade21556f43
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* This file contains functions to implement the partition menu commands.
*/
#include "global.h"
#include <stdlib.h>
#include <string.h>
#include "partition.h"
#include "menu_partition.h"
#include "menu_command.h"
#include "misc.h"
#include "param.h"
#ifdef __STDC__
/* Function prototypes for ANSI C Compilers */
static void nspaces(int);
#else /* __STDC__ */
/* Function prototypes for non-ANSI C Compilers */
static void nspaces();
static int ndigits();
#endif /* __STDC__ */
/*
* This routine implements the 'a' command. It changes the 'a' partition.
*/
int
p_apart()
{
change_partition(0);
return (0);
}
/*
* This routine implements the 'b' command. It changes the 'b' partition.
*/
int
p_bpart()
{
change_partition(1);
return (0);
}
/*
* This routine implements the 'c' command. It changes the 'c' partition.
*/
int
p_cpart()
{
change_partition(2);
return (0);
}
/*
* This routine implements the 'd' command. It changes the 'd' partition.
*/
int
p_dpart()
{
change_partition(3);
return (0);
}
/*
* This routine implements the 'e' command. It changes the 'e' partition.
*/
int
p_epart()
{
change_partition(4);
return (0);
}
/*
* This routine implements the 'f' command. It changes the 'f' partition.
*/
int
p_fpart()
{
change_partition(5);
return (0);
}
/*
* This routine implements the 'g' command. It changes the 'g' partition.
*/
int
p_gpart()
{
change_partition(6);
return (0);
}
/*
* This routine implements the 'h' command. It changes the 'h' partition.
*/
int
p_hpart()
{
change_partition(7);
return (0);
}
/*
* This routine implements the 'i' command. It is valid only for EFI
* labeled disks. This can be used only in expert mode.
*/
int
p_ipart()
{
change_partition(8);
return (0);
}
#if defined(i386)
/*
* This routine implements the 'j' command. It changes the 'j' partition.
*/
int
p_jpart()
{
change_partition(9);
return (0);
}
#endif /* defined(i386) */
int
p_expand()
{
err_print("Warning: No expanded capacity is found.\n");
return (0);
}
fmt_print("The expanded capacity is added to the unallocated space.\n");
return (0);
}
/*
* This routine implements the 'select' command. It allows the user
* to make a pre-defined partition map the current map.
*/
int
p_select()
{
#if defined(i386)
#endif
/*
* If there are no pre-defined maps for this disk type, it's
* an error.
*/
err_print("No defined partition tables.\n");
return (-1);
}
/*
* Loop through the pre-defined maps and list them by name. If
* the current map is one of them, make it the default. If any
* the maps are unnamed, label them as such.
*/
deflt = i;
}
fmt_print(" %d. unnamed\n", i++);
else
}
/*
* Ask which map should be made current.
*/
;
if (cur_label == L_TYPE_EFI) {
fmt_print("\n");
return (0);
}
#if defined(i386)
/*
* Adjust for the boot and alternate sectors partition - assuming that
* the alternate sectors partition physical location follows
* immediately the boot partition and partition sizes are
* expressed in multiple of cylinder size.
*/
}
#else /* !defined(i386) */
b_cylno = 0;
#endif /* defined(i386) */
/*
* Before we blow the current map away, do some limits checking.
*/
for (i = 0; i < NDKMAP; i++) {
#if defined(i386)
b_cylno = 0;
/*
* Always accept starting cyl 0 if the size is 0 also
*/
b_cylno = 0;
} else {
}
#endif /* defined(i386) */
"partition %c: starting cylinder %d is out of range\n",
(PARTITION_BASE+i),
return (0);
}
"partition %c: specified # of blocks, %u, "
"is out of range\n",
(PARTITION_BASE+i),
return (0);
}
}
/*
* Lock out interrupts so the lists don't get mangled.
*/
/*
* If the old current map is unnamed, delete it.
*/
/*
* Make the selected map current.
*/
#if defined(_SUNOS_VTOC_16)
for (i = 0; i < NDKMAP; i++) {
}
#endif /* defined(_SUNOS_VTOC_16) */
fmt_print("\n");
return (0);
}
/*
* This routine implements the 'name' command. It allows the user
* to name the current partition map. If the map was already named,
* the name is changed. Once a map is named, the values of the partitions
* cannot be changed. Attempts to change them will cause another map
* to be created.
*/
int
p_name()
{
char *name;
/*
* check if there exists a partition table for the disk.
*/
err_print("Current Disk has no partition table.\n");
return (-1);
}
/*
* Ask for the name. Note that the input routine will malloc
* space for the name since we are using the OSTR input type.
*/
"Enter table name (remember quotes)",
/*
* Lock out interrupts.
*/
/*
* If it was already named, destroy the old name.
*/
/*
* Set the name.
*/
fmt_print("\n");
return (0);
}
/*
* This routine implements the 'print' command. It lists the values
* for all the partitions in the current partition map.
*/
int
p_print()
{
/*
* check if there exists a partition table for the disk.
*/
err_print("Current Disk has no partition table.\n");
return (-1);
}
/*
* Print the volume name, if it appears to be set
*/
if (chk_volname(cur_disk)) {
fmt_print("Volume: ");
fmt_print("\n");
}
/*
* Print the name of the current map.
*/
fmt_print("Current partition table (%s):\n",
fmt_print("Total disk cylinders available: %d + %d "
} else if (cur_label == L_TYPE_SOLARIS) {
fmt_print("Current partition table (unnamed):\n");
fmt_print("Total disk cylinders available: %d + %d "
} else if (cur_label == L_TYPE_EFI) {
fmt_print("Current partition table (%s):\n",
fmt_print("Total disk sectors available: %llu + %d "
"(reserved sectors)\n\n",
}
/*
* Print the partition map itself
*/
return (0);
}
/*
* Print a partition map
*/
void
{
int i;
int want_header;
if (cur_label == L_TYPE_EFI) {
want_header = 1;
for (i = 0; i < vtoc64->efi_nparts; i++) {
/*
* we want to print partitions above 7 in expert mode only
* or if the partition is reserved
*/
if (i >= 7 && !expert_mode &&
V_RESERVED)) {
continue;
}
want_header = 0;
}
fmt_print("\n");
return;
}
/*
* Loop through each partition, printing the header
* the first time.
*/
want_header = 1;
for (i = 0; i < NDKMAP; i++) {
if (i > 9) {
break;
}
want_header = 0;
}
fmt_print("\n");
}
/*
* Print out one line of partition information,
* with optional header for EFI type disks.
*/
/*ARGSUSED*/
void
{
int ncyl2_digits = 0;
float scaled;
char *s;
if (want_header) {
fmt_print("Part ");
fmt_print("Tag Flag ");
fmt_print("First Sector");
fmt_print("Size");
fmt_print("Last Sector\n");
}
s = find_string(ptag_choices,
if (s == (char *)NULL)
s = "-";
fmt_print("%s", s);
s = find_string(pflag_choices,
if (s == (char *)NULL)
s = "-";
fmt_print("%s", s);
nspaces(2);
if (secsize == 0) {
fmt_print(" 0 ");
} else {
} else if (scaled >= (float)1024.0) {
} else {
}
}
UINT_MAX64) {
fmt_print(" 0 \n");
} else {
fmt_print(" %llu \n",
}
}
/*
* Print out one line of partition information,
* with optional header.
*/
/*ARGSUSED*/
void
{
int i;
int cyl1;
int cyl2;
float scaled;
int maxcyl2;
int ncyl2_digits;
char *s;
/*
* To align things nicely, we need to know the maximum
* width of the number of cylinders field.
*/
maxcyl2 = 0;
for (i = 0; i < NDKMAP; i++) {
if (nblks > 0) {
}
}
/*
* Get the number of digits required
*/
/*
* Print the header, if necessary
*/
if (want_header) {
fmt_print("Part ");
fmt_print("Tag Flag ");
fmt_print("Cylinders");
fmt_print(" Size Blocks\n");
}
/*
* Print the partition information
*/
/*
* Print the partition tag. If invalid, print -
*/
s = find_string(ptag_choices,
if (s == (char *)NULL)
s = "-";
fmt_print("%s", s);
/*
* Print the partition flag. If invalid print -
*/
s = find_string(pflag_choices,
if (s == (char *)NULL)
s = "-";
fmt_print("%s", s);
nspaces(2);
if (nblks == 0) {
fmt_print(" 0 ");
} else {
fmt_print("%8.2fTB ",
} else if (scaled > (float)1024.0) {
} else {
}
}
fmt_print("(");
fmt_print(")");
/*
* Allocates size of the printf format string.
* ndigits(ndigits(maxblks)) gives the byte size of
* the printf width field for maxnblks.
*/
(void) free(s);
}
/*
* Return true if a disk has a volume name
*/
int
{
}
/*
* Print the volume name, if it appears to be set
*/
void
{
int i;
char *p;
for (i = 0; i < LEN_DKL_VVOL; i++, p++) {
if (*p == 0)
break;
fmt_print("%c", *p);
}
}
/*
* Print a number of spaces
*/
static void
nspaces(n)
int n;
{
while (n-- > 0)
fmt_print(" ");
}
/*
* Return the number of digits required to print a number
*/
static int
ndigits(n)
uint64_t n;
{
int i;
i = 0;
while (n > 0) {
n /= 10;
i++;
}
return (i == 0 ? 1 : i);
}