modify_partition.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains functions to implement the partition menu commands.
*/
#include "global.h"
#include "partition.h"
#include "menu_partition.h"
#include "menu_command.h"
#include "modify_partition.h"
#include "checkmount.h"
#include "misc.h"
#include "label.h"
#include "auto_sense.h"
#include <stdlib.h>
#include <string.h>
#ifdef __STDC__
/* Function prototypes for ANSI C Compilers */
#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__ */
/*
*/
int
p_modify()
{
int inpt_dflt = 0;
int free_hog = -1;
int i;
char tmpstr[80];
char tmpstr2[300];
int sel_type = 0;
/*
* There must be a current disk type (and therefore a current disk).
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* check if there exists a partition table for the disk.
*/
err_print("Current Disk has no partition table.\n");
return (-1);
}
/*
* If the disk has mounted partitions, cannot modify
*/
"Cannot modify disk partitions while it has mounted partitions.\n\n");
return (-1);
}
/*
* If the disk has partitions currently being used for
* swapping, cannot modify
*/
"Cannot modify disk partitions while it is \
currently being used for swapping.\n");
return (-1);
}
/*
* prompt user for a partition table base
*/
"\t0. Current partition table (%s)",
} else {
"\t0. Current partition table (unnamed)");
}
"Select partitioning base:\n%s\n"
"\t1. All Free Hog\n"
"Choose base (enter number) ",
tmpstr);
&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.
*/
err_print("\
Warning: Fix, or select a different partition table.\n");
return (0);
}
/*
* Create partition map from existing map
*/
for (i = 0; i < NDKMAP; i++) {
}
} else {
/*
* Make an empty partition map, with all the space
* in the c partition.
*/
for (i = 0; i < NDKMAP; i++) {
}
#if defined(i386)
/*
* Adjust for the boot and possibly alternates partitions
*/
}
#endif /* defined(i386) */
}
break;
case L_TYPE_EFI:
if (sel_type == 1) {
}
}
break;
}
fmt_print("\n");
if (cur_label == L_TYPE_SOLARIS) {
} else {
}
"Do you wish to continue creating a new partition\ntable based on above table",
return (0);
}
/*
* get Free Hog partition
*/
inpt_dflt = 1;
/* disallow c partition */
if (free_hog == C_PARTITION) {
fmt_print("'%c' cannot be the 'Free Hog' partition.\n",
free_hog = -1;
continue;
}
/*
* If user selected all float set the
* float to be the whole disk.
*/
if (sel_type == 1) {
#if defined(i386)
}
#endif /* defined(i386) */
break;
}
/*
* Warn the user if there is no free space in
* the float partition.
*/
err_print("\
Warning: No space available from Free Hog partition.\n");
free_hog = -1;
}
}
}
inpt_dflt = 0;
if (cur_label == L_TYPE_EFI) {
/* disallow c partition */
if (free_hog == C_PARTITION) {
fmt_print("'%c' cannot be the 'Free Hog' partition.\n",
return (-1);
}
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
*/
/*
* Update cylno offsets
*/
fmt_print("\n");
Okay to make this the current partition table", '?',
return (0);
} else {
/*
* Update new partition map
*/
for (i = 0; i < NDKMAP; i++) {
#ifdef i386
#endif
}
(void) p_name();
/*
* Label the disk now
*/
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);
}
}
/*
* Adjust cylinder offsets
*/
static void
{
int i;
int cyloffset = 0;
/*
* Update cylno offsets
*/
#if defined(_SUNOS_VTOC_16)
/*
* Correct cylinder allocation for having the boot and alternates
* slice in the beginning of the disk
*/
}
}
for (i = 0; i < NDKMAP/2; i++) {
#else /* !defined(_SUNOS_VTOC_16) */
for (i = 0; i < NDKMAP; i++) {
#endif /* defined(_SUNOS_VTOC_16) */
}
}
}
/*
* Check partition table
*/
static int
{
int i;
int cyloffset = 0;
int tot_blks = 0;
#ifdef i386
/*
* On x86, we must account for the boot and alternates
*/
#endif
/*
* Do some checks for invalid parameters but do
* not modify the table.
*/
for (i = 0; i < NDKMAP; i++) {
err_print("\
Warning: Partition %c starting cylinder %d is out of range.\n",
return (-1);
}
err_print("\
Warning: Partition %c, specified # of blocks, %d, is out of range.\n",
return (-1);
}
#ifdef i386
if (i == I_PARTITION || i == J_PARTITION)
continue;
#endif
"Warning: Overlapping partition (%c) in table.\n", PARTITION_BASE+i);
return (-1);
"Warning: Non-contiguous partition (%c) in table.\n", PARTITION_BASE+i);
}
}
}
err_print("\
Warning: Total blocks used is greater than number of blocks in '%c'\n\
return (-1);
}
return (0);
}
/*
* get user defined partitions
*/
static void
int float_part;
{
int i;
int newsize;
int deflt;
char tmpstr[80];
/*
* Get partition sizes
*/
for (i = 0; i < NDKMAP; i++) {
if (partn_list[i] == NULL)
break;
if ((i == C_PARTITION) || (i == float_part))
continue;
else {
err_print("\
Warning: no space available for '%s' from Free Hog partition\n",
partn_list[i]);
continue;
}
"Enter size of partition '%s' ",
partn_list[i]);
}
}
}
static struct partition_info *
{
struct partition_info *part;
int i;
#ifdef DEBUG
fmt_print("Creating Default Partition for the disk \n");
#endif
/*
* construct a label and pass it on to
* build_default_partition() which builds the
* default partition list.
*/
return (NULL);
part = (struct partition_info *)
zalloc(sizeof (struct partition_info));
/*
* Fill in the partition info from the label
*/
for (i = 0; i < NDKMAP; i++) {
#if defined(_SUNOS_VTOC_8)
#else
#endif /* ifdefined(_SUNOS_VTOC_8) */
}
return (part);
}
/*
* build new partition table for given disk type
*/
static void
int float_part;
{
int i;
char tmpstr[80];
if (i == float_part)
continue;
else {
"Enter size of partition %d ", i);
if (i64 == 0) {
V_UNASSIGNED)) {
}
if (i64 == 0) {
} else {
}
}
}
fmt_print("Warning: No space left for HOG\n");
}
for (i = 0; i < map->efi_nparts; i++) {
(1024 * 16);
break;
}
}
}
void
{
struct partition_info *part;
/*
* check if disk geometry has changed , if so add new
* partition table else copy the old partition table.(best guess).
*/
part = (struct partition_info *)
zalloc(sizeof (struct partition_info));
sizeof (struct partition_info));
} else {
#ifdef DEBUG
fmt_print("Warning: Partition Table is set");
fmt_print("to default partition table. \n");
}
#endif
}
}
}
}