/*
* 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
*/
/*
*/
/* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
/* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1987, 1988 Microsoft Corporation */
/* All Rights Reserved */
/*
* PROGRAM: fdisk(1M)
* This program reads the partition table on the specified device and
* also reads the drive parameters. The user can perform various
* operations from a supplied menu or from the command line. Diagnostic
* options are also available.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <ctype.h>
#include <limits.h>
#include <sys/systeminfo.h>
#include <sys/efi_partition.h>
#include <sys/byteorder.h>
#include <sys/systeminfo.h>
#ifdef i386
#include <libfdisk.h>
#endif
"[6;1H[0K[7;1H[0K[8;1H[0K[9;1H[0K[10;1H[0K[1;1H"
#ifdef i386
#else
#endif
#ifdef i386
"[16;1H[0K[17;1H[0K[18;1H[0K[19;1H[0K[12;1H"
#else
"[0K[18;1H[0K[19;1H[0K[13;1H"
#endif
/* XXX - should be in fdisk.h, used by sd as well */
/*
* the MAX values are the maximum usable values for BIOS chs values
* The MAX_CYL value of 1022 is the maximum usable value
* the value of 1023 is a fence value,
* indicating no CHS geometry exists for the corresponding LBA value.
* HEAD range [ 0 .. MAX_HEAD ], so number of heads is (MAX_HEAD + 1)
* SECT range [ 1 .. MAX_SECT ], so number of sectors is (MAX_SECT)
*/
/* for clear_vtoc() */
#define OLD 0
/*
* Support for fdisk(1M) on the SPARC platform
* In order to convert little endian values to big endian for SPARC,
* These swapping macros will be used to access information in the
* mboot and ipart structures.
*/
#ifdef sparc
#else
#endif
#if defined(_SUNOS_VTOC_16)
#elif defined(_SUNOS_VTOC_8)
#define VTOC_OFFSET 0
#else
#endif
#ifdef i386
/* Maximum number of digits for a valid partition size */
/* Minimum partition size in cylinders */
#endif
"[ -A id:act:bhead:bsect:bcyl:ehead:esect:ecyl:rsect:numsect ]\n"
"[ -b masterboot ]\n"
"[ -D id:act:bhead:bsect:bcyl:ehead:esect:ecyl:rsect:numsect ]\n"
"[ -F fdisk_file ] [ -h ] [ -o offset ] [ -P fill_patt ] [ -s size ]\n"
"[ -S geom_file ] [ [ -v ] -W { creat_fdisk_file | - } ]\n"
"[ -w | r | d | n | I | B | E | g | G | R | t | T ] rdevice";
" -A id:act:bhead:bsect:bcyl:ehead:esect:ecyl:rsect:numsect\n"
" Create a partition with specific attributes:\n"
" id = system id number (fdisk.h) for the partition type\n"
" act = active partition flag (0 is off and 128 is on)\n"
" bhead = beginning head for start of partition\n"
" bsect = beginning sector for start of partition\n"
" bcyl = beginning cylinder for start of partition\n"
" ehead = ending head for end of partition\n"
" esect = ending sector for end of partition\n"
" ecyl = ending cylinder for end of partition\n"
" rsect = sector number from start of disk for\n"
" start of partition\n"
" numsect = partition size in sectors\n"
" -b master_boot\n"
" Use master_boot as the master boot file.\n"
" -B Create one Solaris partition that uses the entire disk.\n"
" -E Create one EFI partition that uses the entire disk.\n"
" -D id:act:bhead:bsect:bcyl:ehead:esect:ecyl:rsect:numsect\n"
" Delete a partition. See attribute definitions for -A.\n"
" -F fdisk_file\n"
" Use fdisk_file to initialize on-line fdisk table.\n"
" -I Forego device checks. Generate a file image of what would go\n"
" on a disk using the geometry specified with the -S option.\n"
" -n Do not run in interactive mode.\n"
" -R Open the disk device as read-only.\n"
" -t Check and adjust VTOC to be consistent with fdisk table.\n"
" VTOC slices exceeding the partition size will be truncated.\n"
" -T Check and adjust VTOC to be consistent with fdisk table.\n"
" VTOC slices exceeding the partition size will be removed.\n"
" -W fdisk_file\n"
" Write on-disk table to fdisk_file.\n"
" -W - Write on-disk table to standard output.\n"
" -v Display virtual geometry. Must be used with the -W option.\n"
" Diagnostic options:\n"
" -d Activate debug information about progress.\n"
" -g Write label geometry to standard output:\n"
" PCYL number of physical cylinders\n"
" NCYL number of usable cylinders\n"
" ACYL number of alternate cylinders\n"
" BCYL cylinder offset\n"
" NHEADS number of heads\n"
" NSECTORS number of sectors per track\n"
" SECTSIZ size of a sector in bytes\n"
" -G Write physical geometry to standard output (see -g).\n"
" -h Issue this verbose help message.\n"
" -o offset\n"
" Block offset from start of disk (default 0). Ignored if\n"
" -P # specified.\n"
" -P fill_patt\n"
" Fill disk with pattern fill_patt. fill_patt can be decimal or\n"
" hexadecimal and is used as number for constant long word\n"
" pattern. If fill_patt is \"#\" then pattern of block #\n"
" for each block. Pattern is put in each block as long words\n"
" and fills each block (see -o and -s).\n"
" -r Read from a disk to stdout (see -o and -s).\n"
" -s size Number of blocks on which to perform operation (see -o).\n"
" -S geom_file\n"
" Use geom_file to set the label geometry (see -g).\n"
" -w Write to a disk from stdin (see -o and -s).";
#ifdef i386
#endif
/* All the user options and flags */
/* Diagnostic options */
/* The -o offset and -s size options specify the area of the disk on */
/* which to perform the particular operation; i.e., -P, -r, or -w. */
/* Partition table flags */
static char *Nullsect;
static int vt_inval = 0;
/* Disk geometry information */
/* used to limit fdisk to 2TB */
/* Physical geometry for the drive */
/* HBA (virtual) geometry for the drive */
/* Load functions for fdisk table modification */
static char s[CBUFLEN];
#ifdef i386
/*
* Complete list of all the 255 partition types. Some are unknown types
* and some entries are known to be unused.
*
*/
char *fdisk_part_types[] = {
"Empty", /* 0 */
"FAT12", /* 1 */
"XENIX /", /* 2 */
"XENIX /usr", /* 3 */
"FAT16 (Upto 32M)", /* 4 */
"DOS Extended", /* 5 */
"FAT16 (>32M, HUGEDOS)", /* 6 */
"IFS: NTFS", /* 7 */
"WIN95 FAT32(Upto 2047GB)", /* 11 */
"WIN95 FAT32(LBA)", /* 12 */
"Unused", /* 13 */
"WIN95 FAT16(LBA)", /* 14 */
"WIN95 Extended(LBA)", /* 15 */
"OPUS", /* 16 */
"Hidden FAT12", /* 17 */
"Diagnostic", /* 18 */
"Unknown", /* 19 */
"Hidden FAT16(Upto 32M)", /* 20 */
"Unknown", /* 21 */
"Hidden FAT16(>=32M)", /* 22 */
"Hidden IFS: HPFS", /* 23 */
"AST SmartSleep Partition", /* 24 */
"Unused/Willowtech Photon", /* 25 */
"Unknown", /* 26 */
"Hidden FAT32", /* 27 */
"Hidden FAT32(LBA)", /* 28 */
"Unused", /* 29 */
"Hidden FAT16(LBA)", /* 30 */
"Unknown", /* 31 */
"Unused/(Oxygen EXT)", /* 34 */
"Reserved", /* 35 */
"NEC DOS 3.x", /* 36 */
"Unknown", /* 37 */
"Reserved", /* 38 */
"Unknown", /* 39 */
"Unknown", /* 40 */
"Unknown", /* 41 */
"AtheOS File System", /* 42 */
"SyllableSecure", /* 43 */
"Unknown", /* 44 */
"Unknown", /* 45 */
"Unknown", /* 46 */
"Unknown", /* 47 */
"Unknown", /* 48 */
"Reserved", /* 49 */
"NOS", /* 50 */
"Reserved", /* 51 */
"Reserved", /* 52 */
"JFS on OS/2", /* 53 */
"Reserved", /* 54 */
"Unknown", /* 55 */
"THEOS 3.2 2GB", /* 56 */
"THEOS 4 4GB", /* 58 */
"THEOS 4 Extended", /* 59 */
"PartitionMagic Recovery", /* 60 */
"Hidden NetWare", /* 61 */
"Unknown", /* 62 */
"Unknown", /* 63 */
"Venix 80286", /* 64 */
"Linux+DRDOS shared", /* 67 */
"GoBack partition", /* 68 */
"Boot-US boot manager", /* 69 */
"Unknown", /* 73 */
"Unknown", /* 75 */
"Oberon partition", /* 76 */
"QNX 4,x", /* 77 */
"QNX 4,x 2nd Part", /* 78 */
"QNX 4,x 3rd Part", /* 79 */
"OnTrack DM R/O, Lynx RTOS", /* 80 */
"OnTrack DM R/W, Novell", /* 81 */
"CP/M", /* 82 */
"Disk Manager 6.0 Aux3", /* 83 */
"Disk Manager 6.0 DDO", /* 84 */
"EZ-Drive", /* 85 */
"DrivePro", /* 87 */
"Unknown", /* 88 */
"Unknown", /* 89 */
"Unknown", /* 90 */
"Unknown", /* 91 */
"Priam EDisk", /* 92 */
"Unknown", /* 93 */
"Unknown", /* 94 */
"Unknown", /* 95 */
"Unknown", /* 96 */
"SpeedStor", /* 97 */
"Unknown", /* 98 */
"Unix SysV, Mach, GNU Hurd", /* 99 */
"PC-ARMOUR, Netware 286", /* 100 */
"Netware 386", /* 101 */
"Netware SMS", /* 102 */
"Novell", /* 103 */
"Novell", /* 104 */
"Netware NSS", /* 105 */
"Unknown", /* 106 */
"Unknown", /* 107 */
"Unknown", /* 108 */
"Unknown", /* 109 */
"Unknown", /* 110 */
"Unknown", /* 111 */
"DiskSecure Multi-Boot", /* 112 */
"Reserved", /* 113 */
"Unknown", /* 114 */
"Reserved", /* 115 */
"Scramdisk partition", /* 116 */
"Reserved", /* 118 */
"XOSL FS", /* 120 */
"Unknown", /* 121 */
"Unknown", /* 122 */
"Unknown", /* 123 */
"Unknown", /* 124 */
"Unknown", /* 125 */
"Unused", /* 126 */
"Unused", /* 127 */
"MINIX until 1.4a", /* 128 */
"MINIX since 1.4b, early Linux", /* 129 */
"Linux native", /* 131 */
"OS/2 hidden,Win Hibernation", /* 132 */
"Linux extended", /* 133 */
"Old Linux RAID,NT FAT16 RAID", /* 134 */
"NTFS volume set", /* 135 */
"Linux plaintext part table", /* 136 */
"Unknown", /* 137 */
"Linux Kernel Partition", /* 138 */
"Fault Tolerant FAT32 volume", /* 139 */
"Fault Tolerant FAT32 volume", /* 140 */
"Free FDISK hidden PDOS FAT12", /* 141 */
"Linux LVM partition", /* 142 */
"Unknown", /* 143 */
"Free FDISK hidden PDOS FAT16", /* 144 */
"Free FDISK hidden DOS EXT", /* 145 */
"Free FDISK hidden FAT16 Large", /* 146 */
"Hidden Linux native, Amoeba", /* 147 */
"Amoeba Bad Block Table", /* 148 */
"MIT EXOPC Native", /* 149 */
"Unknown", /* 150 */
"Free FDISK hidden PDOS FAT32", /* 151 */
"Free FDISK hidden FAT32 LBA", /* 152 */
"DCE376 logical drive", /* 153 */
"Free FDISK hidden FAT16 LBA", /* 154 */
"Free FDISK hidden DOS EXT", /* 155 */
"Unknown", /* 156 */
"Unknown", /* 157 */
"Unknown", /* 158 */
"Laptop hibernation", /* 160 */
"Laptop hibernate,HP SpeedStor", /* 161 */
"Unknown", /* 162 */
"HP SpeedStor", /* 163 */
"HP SpeedStor", /* 164 */
"BSD/386,386BSD,NetBSD,FreeBSD", /* 165 */
"OpenBSD,HP SpeedStor", /* 166 */
"NeXTStep", /* 167 */
"Mac OS-X", /* 168 */
"NetBSD", /* 169 */
"Olivetti FAT12 1.44MB Service", /* 170 */
"Mac OS-X Boot", /* 171 */
"Unknown", /* 172 */
"Unknown", /* 173 */
"ShagOS filesystem", /* 174 */
"ShagOS swap", /* 175 */
"BootStar Dummy", /* 176 */
"HP SpeedStor", /* 177 */
"Unknown", /* 178 */
"HP SpeedStor", /* 179 */
"HP SpeedStor", /* 180 */
"Unknown", /* 181 */
"Corrupted FAT16 NT Mirror Set", /* 182 */
"Corrupted NTFS NT Mirror Set", /* 183 */
"Old BSDI BSD/386 swap", /* 184 */
"Unknown", /* 185 */
"Unknown", /* 186 */
"Boot Wizard hidden", /* 187 */
"Unknown", /* 188 */
"Unknown", /* 189 */
"Solaris x86 boot", /* 190 */
"Solaris2", /* 191 */
"REAL/32 or Novell DOS secured", /* 192 */
"Hidden Linux", /* 194 */
"Hidden Linux swap", /* 195 */
"NT corrupted FAT16 volume", /* 198 */
"NT corrupted NTFS volume", /* 199 */
"DRDOS8.0+", /* 200 */
"DRDOS8.0+", /* 201 */
"DRDOS8.0+", /* 202 */
"DRDOS7.04+ secured FAT32(CHS)", /* 203 */
"DRDOS7.04+ secured FAT32(LBA)", /* 204 */
"CTOS Memdump", /* 205 */
"DRDOS7.04+ FAT16X(LBA)", /* 206 */
"DRDOS7.04+ secure EXT DOS(LBA)", /* 207 */
"REAL/32 secure big, MDOS", /* 208 */
"Old MDOS secure FAT12", /* 209 */
"Unknown", /* 210 */
"Unknown", /* 211 */
"Old MDOS secure FAT16 <32M", /* 212 */
"Old MDOS secure EXT", /* 213 */
"Old MDOS secure FAT16 >=32M", /* 214 */
"Unknown", /* 215 */
"Unknown", /* 217 */
"Non-FS Data", /* 218 */
"CP/M,Concurrent DOS,CTOS", /* 219 */
"Unknown", /* 220 */
"Hidden CTOS memdump", /* 221 */
"Dell PowerEdge utilities(FAT)", /* 222 */
"ST AVFS(STMicroelectronics)", /* 224 */
"SpeedStor 12-bit FAT EXT", /* 225 */
"Unknown", /* 226 */
"SpeedStor", /* 227 */
"SpeedStor 16-bit FAT EXT", /* 228 */
"Tandy MSDOS", /* 229 */
"Storage Dimensions SpeedStor", /* 230 */
"Unknown", /* 231 */
"Unknown", /* 232 */
"Unknown", /* 233 */
"Unknown", /* 234 */
"BeOS BFS", /* 235 */
"SkyOS SkyFS", /* 236 */
"Unused", /* 237 */
"EFI Header Indicator", /* 238 */
"EFI Filesystem", /* 239 */
"SpeedStor", /* 241 */
"DOS 3.3+ secondary", /* 242 */
"SpeedStor Reserved", /* 243 */
"SpeedStor Large", /* 244 */
"Prologue multi-volume", /* 245 */
"SpeedStor", /* 246 */
"Unused", /* 247 */
"Unknown", /* 248 */
"pCache", /* 249 */
"Bochs", /* 250 */
"VMware File System", /* 251 */
"VMware swap", /* 252 */
"Linux raid autodetect", /* 253 */
"NT Disk Administrator hidden", /* 254 */
"Xenix Bad Block Table" /* 255 */
};
/* Allowed extended partition menu options */
/*
* Structure holding all information about the extended partition
* NOTE : As of now, there will be just one instance of ext_part_t, since most
* known systems allow only one extended dos partition per disk.
*/
#endif
static void dev_mboot_read(void);
static void mboot_read(void);
static void fill_patt(void);
static void abs_read(void);
static void abs_write(void);
static void Set_Table_CHS_Values(int ti);
static int nopartdefined();
static int verify_tbl(void);
static int pars_fdisk(char *line,
static void stage0(void);
static int pcreate(void);
static void dispmenu(void);
static int pchange(void);
static int ppartid(void);
static char pdelete(void);
static void rm_blanks(char *s);
static int getcyl(void);
static void disptbl(void);
static void print_Table(void);
static void copy_Table_to_Old_Table(void);
static void nulltbl(void);
static void copy_Bootblk_to_Table(void);
#ifdef sparc
#endif
static void copy_Table_to_Bootblk(void);
static int TableChanged(void);
static void ffile_write(char *file);
static void fix_slice(void);
static int yesno(void);
static int readvtoc(void);
static int writevtoc(void);
static int clear_efi(void);
#ifdef i386
static void ext_read_input(char *buf);
static int ext_read_options(char *buf);
static int ext_invalid_option(char ch);
static void ext_read_valid_part_num(int *pno);
static void ext_part_menu();
static void add_logical_drive();
static void delete_logical_drive();
static void ext_print_help_menu();
static void ext_change_logical_drive_id();
static void ext_print_part_types();
static void ext_print_logical_drive_layout();
static void preach_and_continue();
#ifdef DEBUG
static void ext_print_logdrive_layout_debug();
#endif /* DEBUG */
#endif /* i386 */
/*
* This function is called only during the non-interactive mode.
* It is touchy and does not tolerate any errors. If there are
* mounted logical drives, changes to the partition table
* is disallowed.
*/
static void
{
#ifdef i386
int rval;
#endif
if (table_changed) {
/*
* Copy the new table back to the sector buffer
* and write it to disk
*/
}
/* If the VTOC table is wrong fix it (truncation only) */
if (io_adjt)
fix_slice();
#ifdef i386
if (!io_readonly) {
switch (rval) {
case FDISK_SUCCESS:
/* Success */
break;
case FDISK_ENOEXTPART:
/* Nothing to do */
break;
default:
" fdisk_commit_ext_part\n");
}
}
libfdisk_fini(&epp);
#endif
exit(0);
}
/*
* main
* Process command-line options.
*/
int
{
int c, i;
extern int optind;
extern char *optarg;
int errflg = 0;
int diag_cnt = 0;
int openmode;
#ifdef i386
int rval;
int lf_op_flag = 0;
#endif
/* Process the options. */
!= EOF) {
switch (c) {
case 'o':
continue;
case 's':
continue;
case 'P':
diag_cnt++;
io_patt++;
continue;
case 'w':
diag_cnt++;
io_wrt++;
continue;
case 'r':
diag_cnt++;
io_rd++;
continue;
case 'd':
io_debug++;
continue;
case 'I':
io_image++;
continue;
case 'R':
io_readonly++;
continue;
case 'S':
diag_cnt++;
continue;
case 'T':
io_ADJT++;
/* FALLTHRU */
case 't':
io_adjt++;
continue;
case 'B':
io_wholedisk++;
io_fdisk++;
continue;
case 'E':
io_EFIdisk++;
io_fdisk++;
continue;
case 'g':
diag_cnt++;
io_lgeom++;
continue;
case 'G':
diag_cnt++;
io_pgeom++;
continue;
case 'n':
io_nifdisk++;
io_fdisk++;
continue;
case 'F':
io_fdisk++;
continue;
case 'b':
continue;
case 'W':
/*
* If '-' is the -W argument, then write
* to standard output, otherwise write
* to the specified file.
*/
stdo_flag = 1;
else
io_fdisk++;
continue;
case 'A':
io_fdisk++;
continue;
case 'D':
io_fdisk++;
continue;
case 'h':
exit(0);
/* FALLTHRU */
case 'v':
v_flag = 1;
continue;
case '?':
errflg++;
break;
}
break;
}
diag_cnt = 0;
}
/* User option checking */
/* By default, run in interactive mode */
io_ifdisk++;
io_fdisk++;
}
errflg++;
}
/* Was any error detected? */
"\nDetailed help is available with the -h option.\n");
exit(2);
}
/* Figure out the correct device node to open */
if (io_readonly)
else
"fdisk: Cannot open device %s.\n",
Dfltdev);
exit(1);
}
/*
* not all disk (or disklike) drivers support DKIOCGMEDIAINFO
* in that case leave the minfo structure zeroed
*/
}
/* Get the disk geometry */
if (!io_image) {
/* Get disk's HBA (virtual) geometry */
errno = 0;
/*
* If ioctl isn't implemented on this platform, then
* turn off flag to print out virtual geometry (-v),
* otherwise use the virtual geometry.
*/
v_flag = 0;
no_virtgeom_ioctl = 1;
/*
* This means that the ioctl exists, but
* is invalid for this disk, meaning the
* disk doesn't have an HBA geometry
* (like, say, it's larger than 8GB).
*/
v_flag = 0;
} else {
"%s: Cannot get virtual disk geometry.\n",
exit(1);
}
} else {
/* save virtual geometry values obtained by ioctl */
}
errno = 0;
no_physgeom_ioctl = 1;
} else {
"%s: Cannot get physical disk geometry.\n",
exit(1);
}
}
/*
* Call DKIOCGGEOM if the ioctls for physical and virtual
* geometry fail. Get both from this generic call.
*/
if (no_virtgeom_ioctl && no_physgeom_ioctl) {
errno = 0;
"%s: Cannot get disk label geometry.\n",
exit(1);
}
}
if (minfo.dki_lbsize != 0)
else
sectsiz = 512;
/*
* if hba geometry was not set by DKIOC_VIRTGEOM
* or we got an invalid hba geometry
* then set hba geometry based on max values
*/
if (no_virtgeom_ioctl ||
/*
* turn off flag to print out virtual geometry (-v)
*/
v_flag = 0;
(hba_sectors * hba_heads);
}
if (io_debug) {
" cylinders[%d] heads[%d] sectors[%d]\n"
" sector size[%d] blocks[%d] mbytes[%d]\n",
" cylinders[%d] heads[%d] sectors[%d]\n"
" sector size[%d] blocks[%d] mbytes[%d]\n",
1048576);
}
}
/* If user has requested a geometry report just do it and exit */
if (io_lgeom) {
"%s: Cannot get disk label geometry.\n",
exit(1);
}
if (minfo.dki_lbsize != 0)
else
sectsiz = 512;
(void) printf(
"* PCYL NCYL ACYL BCYL NHEAD NSECT"
" SECSIZ\n");
(void) printf(" %-8d %-8d %-8d %-8d %-5d %-5d %-6d\n",
sectsiz);
exit(0);
} else if (io_pgeom) {
"%s: Cannot get physical disk geometry.\n",
exit(1);
}
(void) printf(
"* PCYL NCYL ACYL BCYL NHEAD NSECT"
" SECSIZ\n");
(void) printf(" %-8d %-8d %-8d %-8d %-5d %-5d %-6d\n",
sectsiz);
exit(0);
} else if (io_sgeom) {
exit(1);
} else if (!io_image) {
exit(0);
}
}
/*
* some drivers may not support DKIOCGMEDIAINFO
* in that case use CHS
*/
if (chs_capacity > DK_MAX_2TB) {
/* limit to 2TB */
}
if (minfo.dki_capacity > 0)
/* Allocate memory to hold three complete sectors */
"fdisk: Unable to obtain enough buffer memory"
" (%d bytes).\n",
3 * sectsiz);
exit(1);
}
/* Zero out the "NULL" sector */
for (i = 0; i < sectsiz; i++) {
Nullsect[i] = 0;
}
/* Find out what the user wants done */
if (io_rd) { /* abs disk read */
abs_read(); /* will not return */
} else if (io_wrt && !io_readonly) {
abs_write(); /* will not return */
} else if (io_patt && !io_readonly) {
fill_patt(); /* will not return */
}
/* This is the fdisk edit, the real reason for the program. */
/* Get the new BOOT program in case we write a new fdisk table */
mboot_read();
/* Read from disk master boot */
/*
* Verify and copy the device's fdisk table. This will be used
* as the prototype mboot if the device's mboot looks invalid.
*/
/* save away a copy of Table in Old_Table for sensing changes */
#ifdef i386
/*
* Read extended partition only when the fdisk table is not
* supplied from a file
*/
if (!io_ffdisk) {
}
!= FDISK_SUCCESS) {
switch (rval) {
/*
* FDISK_EBADLOGDRIVE, FDISK_ENOLOGDRIVE and
* FDISK_EBADMAGIC can be considered as
* soft errors and hence we do not exit
*/
case FDISK_EBADLOGDRIVE:
break;
case FDISK_ENOLOGDRIVE:
break;
case FDISK_EBADMAGIC:
break;
case FDISK_ENOVGEOM:
" geometry for this device\n");
exit(1);
break;
case FDISK_ENOPGEOM:
" geometry for this device\n");
exit(1);
break;
case FDISK_ENOLGEOM:
" geometry for this device\n");
exit(1);
break;
default:
perror("Failed to initialise libfdisk.\n");
exit(1);
break;
}
}
#endif
/* Load fdisk table from specified file (-F fdisk_file) */
if (io_ffdisk) {
/* Load and verify user-specified table parameters */
}
/* Does user want to delete or add an entry? */
if (io_Dfdisk) {
}
if (io_Afdisk) {
}
/* Check if there is no fdisk table */
(void) printf(
"No fdisk table exists. The default"
" partition for the disk is:\n\n"
" a 100%% \"SOLARIS System\" "
"partition\n\n"
"Type \"y\" to accept the default "
"partition, otherwise type \"n\" to "
"edit the\n partition table.\n");
if (Numcyl > Numcyl_usable)
(void) printf("WARNING: Disk is larger"
" than 2TB. Solaris partition will"
" be limited to 2 TB.\n");
}
/* Edit the partition table as directed */
/* Default scenario */
nulltbl();
/* now set up UNIX System partition */
/* calculate CHS values for table entry 0 */
} else if (io_EFIdisk) {
/* create an EFI partition for the whole disk */
nulltbl();
(dev_capacity - 1), 0);
if (i != 0) {
"Error creating EFI partition\n");
exit(1);
}
}
}
}
/* Display complete fdisk table entries for debugging purposes */
if (io_debug) {
print_Table();
if (io_ifdisk) {
}
}
/* Interactive fdisk mode */
if (io_ifdisk) {
disptbl();
for (;;) {
stage0();
disptbl();
}
}
/* If user wants to write the table to a file, do it */
if (io_Wfdisk)
else if (stdo_flag)
ffile_write((char *)stdout);
return (0);
}
/*
* read_geom
* Read geometry from specified file (-S).
*/
static int
{
/* open the prototype file */
io_sgeom);
return (1);
}
/* Read a line from the file */
continue;
else {
§siz) != 7) {
"Syntax error:\n \"%s\".\n",
line);
return (1);
}
break;
} /* else */
} /* while (fgets(line, sizeof (line) - 1, fp)) */
if (!io_image) {
"fdisk: Cannot set label geometry.\n");
return (1);
}
} else {
}
return (0);
}
/*
* dev_mboot_read
* Read the master boot sector from the device.
*/
static void
dev_mboot_read(void)
{
perror("Error in ioctl DKIOCGMBOOT");
}
if (errno == 0)
return;
"fdisk: Error seeking to partition table on %s.\n",
Dfltdev);
if (!io_image)
exit(1);
}
"fdisk: Error reading partition table from %s.\n",
Dfltdev);
if (!io_image)
exit(1);
}
}
/*
* dev_mboot_write
* Write the master boot sector to the device.
*/
static void
{
if (io_readonly)
return;
if (io_debug) {
print_Table();
if (io_ifdisk) {
}
}
/*
* If the new table has any Solaris partitions and the old
* table does not have an entry that describes it
* exactly then clear the old vtoc (if any).
*/
/* We only care about potential Solaris parts. */
continue;
/* Does the old table have an exact entry for the new entry? */
/* We only care about old Solaris partitions. */
/* Is this old one the same as a new one? */
break; /* Yes */
}
}
/* Did a solaris partition change location or size? */
if (old_pt >= FD_NUMPART) {
/* Yes clear old vtoc */
if (io_debug) {
"Clearing VTOC labels from NEW"
" table\n");
}
}
}
/* see if the old table had EFI */
}
}
continue;
break;
}
/*
* if EFI partition changed, set the flag to clear
* the EFI GPT
*/
clr_efi = 0;
}
break;
}
/* clear labels if necessary */
if (clr_efi >= 0) {
if (io_debug) {
}
if (io_debug) {
"\tError %d clearing EFI labels"
" (probably no EFI labels exist)\n",
error);
}
}
}
"fdisk: Error in ioctl DKIOCSMBOOT on %s.\n",
Dfltdev);
}
if (errno == 0)
return;
/* write to disk drive */
"fdisk: Error seeking to master boot record on %s.\n",
Dfltdev);
exit(1);
}
"fdisk: Error writing master boot record to %s.\n",
Dfltdev);
exit(1);
}
}
/*
* mboot_read
* Read the prototype boot records from the files.
*/
static void
mboot_read(void)
{
int mDev, i;
/*
* If the master boot file hasn't been specified, use the
* implementation architecture name to generate the default one.
*/
if (io_mboot == (char *)0) {
/*
* Bug ID 1249035:
* The mboot file must be delivered on all platforms
* and installed in a non-platform-dependent
*/
}
/* First read in the master boot record */
/* Open the master boot proto file */
"fdisk: Cannot open master boot file %s.\n",
io_mboot);
exit(1);
}
/* Read the master boot program */
(struct mboot)) {
"fdisk: Cannot read master boot file %s.\n",
io_mboot);
exit(1);
}
/* Is this really a master boot record? */
"fdisk: Invalid master boot file %s.\n", io_mboot);
"Bad magic number: is %x, but should be %x.\n",
exit(1);
}
#else
#endif
/* Zero out the partitions part of this record */
for (i = 0; i < FD_NUMPART; i++, part++) {
}
}
/*
* fill_patt
*/
static void
fill_patt(void)
{
int *buff_ptr, i;
int io_fpatt = 0;
int io_ipatt = 0;
io_fpatt++;
}
/*
* Fill disk with pattern based on block number.
* Write to the disk at absolute relative block io_offset
* for io_size blocks.
*/
while (io_size--) {
if (!io_fpatt) {
for (i = 0; i < sectsiz;
}
/* Write the data to disk */
SEEK_SET) == -1) {
Dfltdev);
exit(1);
}
Dfltdev);
exit(1);
}
} /* while (--io_size); */
}
/*
* abs_read
* Read from the disk at absolute relative block io_offset for
* io_size blocks. Write the data to standard ouput (-r).
*/
static void
abs_read(void)
{
int c;
while (io_size--) {
SEEK_SET) == -1) {
Dfltdev);
exit(1);
}
Dfltdev);
exit(1);
}
/* Write to standard ouptut */
if (c >= 0) {
if (io_debug)
"fdisk: Output warning: %d of %d"
" characters written.\n",
c, sectsiz);
exit(2);
} else {
perror("write error on output file.");
exit(2);
}
} /* if ((c = write(1, Bootsect, (unsigned)sectsiz)) */
/* != sectsiz) */
} /* while (--io_size); */
exit(0);
}
/*
* abs_write
* Read the data from standard input. Write to the disk at
* absolute relative block io_offset for io_size blocks (-w).
*/
static void
abs_write(void)
{
int c, i;
while (io_size--) {
int part_exit = 0;
/* Read from standard input */
if (c >= 0) {
if (io_debug)
"fdisk: WARNING: Incomplete read (%d of"
" %d characters read) on input file.\n",
c, sectsiz);
/* Fill pattern to mark partial sector in buf */
for (i = c; i < sectsiz; ) {
Bootsect[i++] = 0x41;
Bootsect[i++] = 0x62;
Bootsect[i++] = 0x65;
Bootsect[i++] = 0;
}
part_exit++;
} else {
perror("read error on input file.");
exit(2);
}
}
/* Write to disk drive */
SEEK_SET) == -1) {
Dfltdev);
exit(1);
}
Dfltdev);
exit(1);
}
if (part_exit)
exit(0);
} /* while (--io_size); */
exit(1);
}
/*
* load
* Load will either read the fdisk table from a file or add or
* delete an entry (-A, -D, -F).
*/
static void
{
int id;
int act;
int bhead;
int bsect;
int bcyl;
int ehead;
int esect;
int ecyl;
int i = 0;
int startindex = 0;
int tmpindex = 0;
#ifdef i386
int ext_part_present = 0;
int ext_part_inited = 0;
#endif
switch (funct) {
case LOADFILE:
/*
* Zero out the table before loading it, which will
* force it to be updated on disk later (-F
* fdisk_file).
*/
nulltbl();
/* Open the prototype file */
"fdisk: Cannot open prototype partition file %s.\n",
file);
exit(1);
}
/* Read a line from the file */
continue;
}
#ifdef i386
part_count++;
if (ext_part_present) {
"Extended partition"
" already exists\n");
" entry \"%s\".\n", line);
exit(1);
}
ext_part_present = 1;
/*
* If the existing extended partition's start
* and size matches the new one, do not
* initialize the extended partition EBR
* (Extended Boot Record) because there could
* be existing logical drives.
*/
for (i = 0; i < FD_NUMPART; i++) {
if (fdisk_is_dos_extended(systid)) {
break;
}
}
if ((old_ext_beg_sec != new_ext_beg_sec) ||
(old_ext_num_sec != new_ext_num_sec)) {
(void) fdisk_init_ext_part(epp,
ext_part_inited = 1;
}
}
if (part_count > FD_NUMPART) {
/* This line should be logical drive info */
if (!ext_part_present) {
/* Erroneous input file */
"More than 4 primary"
" partitions found in input\n");
exit(1);
}
if (numsect == 0) {
continue;
}
/*
* If the start and size of the existing
* extended partition matches the new one and
* new logical drives are being defined via
* the input file, initialize the EBR.
*/
if (!ext_part_inited) {
(void) fdisk_init_ext_part(epp,
ext_part_inited = 1;
}
if ((ldcnt =
fdisk_get_logical_drive_count(epp)) == 0) {
/* Adding the first logical drive */
/*
* Make sure that begsec doesnt wrap
* around. This can happen if rsect is
* less than offset.
*/
"Minimum of "
"63 free sectors required "
"before the beginning of "
"a logical drive.");
exit(1);
}
/*
* Check if the first logical drive
* is out of order. In that case, do
* not subtract MAX_LOGDRIVE_OFFSET
* from the given start of partition.
*/
if (begsec != new_ext_beg_sec) {
offset = 0;
}
}
if (ldcnt >= MAX_EXT_PARTS) {
"\nError : Number of "
"logical drives exceeds limit of "
"%d.\n", MAX_EXT_PARTS);
exit(1);
}
if (id > FDISK_MAX_VALID_PART_ID) {
"Invalid partition ID\n");
" entry \"%s\".\n", line);
exit(1);
}
"partitions not supported "
"inside extended "
"partition\n");
exit(1);
}
continue;
} else {
" entry \"%s\".\n", line);
exit(1);
}
}
#endif
/*
* Validate the partition. It cannot start at sector
* 0 unless it is UNUSED or already exists
*/
"fdisk: Error on entry \"%s\".\n",
line);
exit(1);
}
startindex)) != -1) {
/*
* If we got here it means we copied an
* unmodified entry. So there is no need
* to insert it in the table or do any
* checks against disk size.
*
* This is a work around on the following
* situation (for IDE disks, at least):
* Different operation systems calculate
* disk size different ways, of which there
* are two main ways.
*
* The first, rounds the disk size to modulo
* cylinder size (virtual made-up cylinder
* usually based on maximum number of heads
* and sectors in partition table fields).
* Our OS's (for IDE) and most other "Unix"
* type OS's do this.
*
* The second, uses every single block
* on the disk (to maximize available space).
* Since disk manufactures do not know about
* "virtual cylinders", there are some number
* of blocks that make up a partial cylinder
* at the end of the disk.
*
* The difference between these two methods
* is where the problem is. When one
* tries to install Solaris/OpenSolaris on
* a disk that has another OS using that
* "partial cylinder", install fails. It fails
* since fdisk thinks its asked to create a
* partition with the -F option that contains
* a partition that runs off the end of the
* disk.
*/
continue;
}
/*
* Find an unused entry to use and put the entry
* in table
*/
startindex)) < 0) {
"fdisk: Error on entry \"%s\".\n",
line);
exit(1);
}
startindex++;
} /* while (fgets(line, sizeof (line) - 1, fp)) */
if (verify_tbl() < 0) {
"fdisk: Cannot create partition table\n");
exit(1);
}
return;
case LOADDEL:
/* Parse the user-supplied deletion line (-D) */
"fdisk: Syntax error \"%s\"\n", file);
exit(1);
}
/* Find the exact entry in the table */
for (i = 0; i < FD_NUMPART; i++) {
sizeof (struct ipart));
#ifdef i386
if (fdisk_is_dos_extended(id)) {
(void) fdisk_delete_ext_part(epp);
}
#endif
return;
}
}
#ifdef i386
return;
}
ldcnt++;
}
#endif
"fdisk: Entry does not match any existing partition:\n"
" \"%s\"\n",
file);
exit(1);
/* FALLTHRU */
case LOADADD:
/* Parse the user-supplied addition line (-A) */
"fdisk: Syntax error \"%s\"\n", file);
exit(1);
}
/* Validate the partition. It cannot start at sector 0 */
if (rsect == 0) {
"fdisk: New partition cannot start at sector 0:\n"
" \"%s\".\n",
file);
exit(1);
}
/*
* if the user wishes to add an EFI partition, we need
* more extensive validation. rsect should be 1, and
* numsect should equal the entire disk capacity - 1
*/
if (rsect != 1) {
"fdisk: EFI partitions must start at sector"
" 1 (input rsect = %d)\n", rsect);
exit(1);
}
if (dev_capacity > DK_MAX_2TB) {
if (numsect != DK_MAX_2TB) {
"fdisk: EFI partitions must "
"encompass the entire maximum 2 TB "
"(input numsect: %u - max: %llu)\n",
exit(1);
}
"fdisk: EFI partitions must encompass the "
"entire disk\n"
"(input numsect: %u - avail: %llu)\n",
dev_capacity - 1);
exit(1);
}
}
#ifdef i386
if (id > FDISK_MAX_VALID_PART_ID) {
(void) printf("Invalid partition ID\n");
exit(1);
}
if ((fdisk_ext_part_exists(epp)) &&
(fdisk_is_dos_extended(id))) {
"Extended partition already exists.\n");
"fdisk: Invalid entry could not be "
"inserted:\n \"%s\"\n", file);
exit(1);
}
if (fdisk_ext_part_exists(epp) &&
/*
* Make sure that begsec doesnt wrap around.
* This can happen if rsect is less than offset
*/
return;
}
/*
* Adding the first logical drive
* Check if the first logical drive
* is out of order. In that case, do
* not subtract MAX_LOGDRIVE_OFFSET
* from the given start of partition.
*/
if (begsec != ext_beg_sec) {
offset = 0;
}
}
if (ldcnt >= MAX_EXT_PARTS) {
(void) printf("\nNumber of logical drives "
"exceeds limit of %d.\n", MAX_EXT_PARTS);
(void) printf("Failing further additions.\n");
exit(1);
}
if (numsect == 0) {
"fdisk: Partition size cannot be zero:\n"
" \"%s\".\n",
file);
exit(1);
}
/* Valid logical drive */
id);
return;
} else {
"fdisk: Invalid entry could not be "
"inserted:\n \"%s\"\n", file);
exit(1);
}
}
#endif
/* Find unused entry for use and put entry in table */
"fdisk: Invalid entry could not be inserted:\n"
" \"%s\"\n",
file);
exit(1);
}
/* Make sure new entry does not overlap existing entry */
if (verify_tbl() < 0) {
"fdisk: Cannot create partition \"%s\"\n", file);
exit(1);
}
} /* switch funct */
}
/*
* Set_Table_CHS_Values
*
* This will calculate the CHS values for beginning and ending CHS
* for a single partition table entry (ti) based on the relsect
* and numsect values contained in the partion table entry.
*
* hba_heads and hba_sectors contain the number of heads and sectors.
*
* If the number of cylinders exceeds the MAX_CYL,
* then maximum values will be placed in the corresponding chs entry.
*/
static void
{
/*
* the lba address cannot be expressed in CHS value
* so store the maximum CHS field values in the CHS fields.
*/
} else {
}
/*
* This code is identical to the code above
* except that it works on ending CHS values
*/
} else {
}
}
/*
* insert_tbl
* Insert entry into fdisk table. Check all user-supplied values
* for the entry, but not the validity relative to other table
* entries!
*/
static int
{
int i;
/* validate partition size */
"fdisk: Partition table exceeds the size of the disk.\n");
return (-1);
}
/* find UNUSED partition table entry */
for (i = startindex; i < FD_NUMPART; i++) {
break;
}
}
if (i >= FD_NUMPART) {
return (-1);
}
/*
* If we have been called with a valid geometry, use it
* valid means non-zero values that fit in the BIOS fields
*/
} else {
/*
* The specified values are invalid,
* so calculate the values based on hba_heads, hba_sectors
*/
}
/*
* return partition index
*/
return (i);
}
/*
* entry_from_old_table
* If the specified entry is in the old table and is not a Solaris entry
* then insert same entry into new fdisk table. If we do this then
* all checks are skipped for that entry!
*/
static int
{
uint32_t i, j;
return (-1);
for (i = 0; i < FD_NUMPART; i++) {
/* find UNUSED partition table entry */
for (j = startindex; j < FD_NUMPART; j++) {
sizeof (Table[0]));
skip_verify[j] = 1;
return (j);
}
}
return (-1);
}
}
return (-1);
}
/*
* verify_tbl
* Verify that no partition entries overlap or exceed the size of
* the disk.
*/
static int
verify_tbl(void)
{
int noMoreParts = 0;
int numParts = 0;
/* Make sure new entry does not overlap an existing entry */
for (i = 0; i < FD_NUMPART - 1; i++) {
numParts++;
/*
* No valid partitions allowed after EFI_PMBR part
*/
if (noMoreParts) {
return (-1);
}
/*
* EFI_PMBR partition must be the only
* partition
*/
noMoreParts = 1;
"Invalid starting sector "
"for EFI_PMBR partition:\n"
"relsect %d "
"(should be 1)\n",
return (-1);
}
(dev_capacity - 1))) {
"EFI_PMBR partition must "
"encompass the entire");
if (dev_capacity > DK_MAX_2TB)
"maximum 2 TB.\n "
"numsect %u - "
"actual %llu\n",
else
"disk.\n numsect %u - "
"actual %llu\n",
dev_capacity - 1);
return (-1);
}
}
/* make sure the partition isn't larger than the disk */
if (!skip_verify[i])
return (-1);
}
for (j = i + 1; j < FD_NUMPART; j++) {
if (noMoreParts) {
"Cannot add partition to "
"table; no more partitions "
"allowed\n");
if (io_debug) {
"DEBUG: Current "
"partition:\t"
"%d:%d:%d:%d:%d:"
"%d:%d:%d:%d:%d\n"
" Next "
"partition:\t\t"
"%d:%d:%d:%d:%d:"
"%d:%d:%d:%d:%d\n",
}
return (-1);
}
if ((rsect >=
continue;
} else {
"current partition overlaps"
" following partition\n");
return (-1);
}
}
}
}
}
if (noMoreParts)
return (-1);
if (!skip_verify[i] &&
return (-1);
}
}
return (numParts);
}
/*
* pars_fdisk
* Parse user-supplied data to set up fdisk partitions
* (-A, -D, -F).
*/
static int
char *line,
{
int i;
char *tok, *p;
return (1);
if (line[i] == '\0') {
break;
} else if (line[i] == ':') {
line[i] = ' ';
}
}
errno = 0;
for (p = tok; *p != '\0'; p++) {
if (!isdigit(*p)) {
(void) printf("Invalid input %s in line %s.\n",
exit(1);
}
}
line);
exit(1);
}
}
exit(1);
}
return (0);
}
/*
* validate_part
* Validate that a new partition does not start at sector 0. Only UNUSED
* partitions and previously existing partitions are allowed to start at 0.
*/
static int
{
int i;
for (i = 0; i < FD_NUMPART; i++) {
return (0);
}
"New partition cannot start at sector 0\n");
return (-1);
}
#ifdef i386
if (id > FDISK_MAX_VALID_PART_ID) {
return (-1);
}
#endif
return (0);
}
/*
* stage0
* Print out interactive menu and process user input.
*/
static void
stage0(void)
{
#ifdef i386
int rval;
#endif
dispmenu();
for (;;) {
(void) printf("Enter Selection: ");
rm_blanks(s);
#ifdef i386
while (!((s[0] > '0') && (s[0] < '8') &&
((s[1] == '\0') || (s[1] == '\n')))) {
#else
while (!((s[0] > '0') && (s[0] < '7') &&
((s[1] == '\0') || (s[1] == '\n')))) {
#endif
#ifdef i386
(void) printf(
"Enter a one-digit number between 1 and 7.");
#else
(void) printf(
"Enter a one-digit number between 1 and 6.");
#endif
(void) printf("Enter Selection: ");
rm_blanks(s);
}
switch (s[0]) {
case '1':
if (pcreate() == -1)
return;
break;
case '2':
if (pchange() == -1)
return;
break;
case '3':
if (pdelete() == -1)
return;
break;
case '4':
if (ppartid() == -1)
return;
break;
#ifdef i386
case '5':
if (fdisk_ext_part_exists(epp)) {
} else {
(void) printf("\nNo extended partition"
" found\n");
(void) printf("Press enter to "
"continue\n");
ext_read_input(s);
}
break;
case '6':
/* update disk partition table, if changed */
if (TableChanged() == 1) {
}
/*
* If the VTOC table is wrong fix it
* (truncate only)
*/
if (io_adjt) {
fix_slice();
}
if (!io_readonly) {
switch (rval) {
case FDISK_SUCCESS:
/* Success */
/* Fallthrough */
case FDISK_ENOEXTPART:
/* Nothing to do */
break;
case FDISK_EMOUNTED:
continue;
default:
perror("Commit failed");
exit(1);
}
libfdisk_fini(&epp);
}
exit(0);
/* NOTREACHED */
#else
case '5':
/* update disk partition table, if changed */
if (TableChanged() == 1) {
}
/*
* If the VTOC table is wrong fix it
* (truncate only)
*/
if (io_adjt) {
fix_slice();
}
exit(0);
/* FALLTHRU */
#endif
#ifdef i386
case '7':
#else
case '6':
#endif
/*
* If the VTOC table is wrong fix it
* (truncate only)
*/
if (io_adjt) {
fix_slice();
}
exit(0);
/* FALLTHRU */
default:
break;
}
disptbl();
dispmenu();
}
}
/*
* pcreate
* Create partition entry in the table (interactive mode).
*/
static int
pcreate(void)
{
int i, j;
int retCode = 0;
#ifdef i386
int ext_part_present = 0;
#endif
i = 0;
for (;;) {
if (i == FD_NUMPART) {
(void) printf(
"The partition table is full!\n"
"You must delete a partition before creating"
" a new one.\n");
return (-1);
}
break;
}
i++;
}
numsect = 0;
for (i = 0; i < FD_NUMPART; i++) {
}
#ifdef i386
/* Check if an extended partition already exists */
ext_part_present = 1;
}
#endif
if (numsect >= chs_capacity) {
(void) printf("There is no more room on the disk for"
" another partition.\n");
(void) printf(
"You must delete a partition before creating"
" a new one.\n");
return (-1);
}
}
while (tsystid == 'z') {
/*
* The question here is expanding to more than what is
* allocated for question lines (Q_LINE) which garbles
* at least warning line. Clearing warning line as workaround
* for now.
*/
(void) printf(
"Select the partition type to create:\n"
" 1=SOLARIS2 2=UNIX 3=PCIXOS 4=Other\n"
" 5=DOS12 6=DOS16 7=DOSEXT 8=DOSBIG\n"
" 9=DOS16LBA A=x86 Boot B=Diagnostic C=FAT32\n"
" D=FAT32LBA E=DOSEXTLBA F=EFI 0=Exit? ");
rm_blanks(s);
if ((s[1] != '\0') && (s[1] != '\n')) {
(void) printf("Invalid selection, try again.");
continue;
}
switch (s[0]) {
case '0': /* exit */
return (-1);
case '1': /* Solaris partition */
break;
case '2': /* UNIX partition */
break;
case '3': /* PCIXOS partition */
break;
case '4': /* OTHEROS System partition */
break;
case '5':
break;
case '6':
break;
case '7':
#ifdef i386
if (ext_part_present) {
"Extended partition already exists\n");
"Press enter to continue\n");
ext_read_input(s);
continue;
}
#endif
break;
case '8':
break;
case '9':
break;
case 'a': /* x86 Boot partition */
case 'A':
break;
case 'b': /* Diagnostic boot partition */
case 'B':
break;
case 'c': /* FAT32 */
case 'C':
break;
case 'd': /* FAT32 and need extended int13 */
case 'D':
break;
case 'e': /* Extended partition, need extended int13 */
case 'E':
#ifdef i386
if (ext_part_present) {
"Extended partition already exists\n");
"Press enter to continue\n");
ext_read_input(s);
continue;
}
#endif
break;
case 'f':
case 'F':
break;
default:
(void) printf("Invalid selection, try again.");
continue;
}
}
if ((dev_capacity > DK_MAX_2TB))
(void) printf("WARNING: Disk is larger than 2 TB. "
"Upper limit is 2 TB for non-EFI partition ID\n");
/* create the new partition */
if (i != -1) {
/* see if it should be the active partition */
(void) printf(
"Should this become the active partition? If "
"yes, it will be activated\n"
"each time the computer is reset or turned on.\n"
"Please type \"y\" or \"n\". ");
if (yesno()) {
for (j = 0; j < FD_NUMPART; j++) {
if (j == i) {
(void) printf(
"Partition %d is now "
"the active partition.",
j + 1);
} else {
}
}
} else {
}
#ifdef i386
/*
* If partition created is an extended partition, null
* out the first sector of the first cylinder of the
* extended partition
*/
(void) fdisk_init_ext_part(epp,
}
#endif
/* set up the return code */
i = 1;
}
} else {
/*
* partitions of type EFI_PMBR must be the only partitions in
* the table
*
* First, make sure there were no errors the table is
* empty
*/
retCode = verify_tbl();
if (retCode < 0) {
"fdisk: Cannot create EFI partition table; \n"
"current partition table is invalid.\n");
return (-1);
} else if (retCode > 0) {
(void) printf(
"An EFI partition must be the only partition on "
"disk. You may manually delete existing\n"
"partitions, or fdisk can do it.\n"
"Do you want fdisk to destroy existing "
"partitions?\n"
"Please type \"y\" or \"n\". ");
if (yesno()) {
nulltbl();
} else {
return (-1);
}
}
/* create the table entry - i should be 0 */
(dev_capacity - 1), 0);
if (i != 0) {
(void) printf("Error creating EFI partition!!!\n");
i = -1;
} else {
/* EFI partitions are currently never active */
/* set up the return code */
i = 1;
}
}
return (i);
}
/*
* specify
* Query the user to specify the size of the new partition in
* terms of percentage of the disk or by specifying the starting
* cylinder and length in cylinders.
*/
static int
{
int cyl_size;
/*
* make a local copy of the partition table
* and sort it into relsect order
*/
for (i = 0, j = 0; i < FD_NUMPART; i++) {
j++;
}
}
while (j < FD_NUMPART) {
j++;
}
for (i = 0; i < FD_NUMPART; i++)
for (i = 0; i < FD_NUMPART - 1; i++) {
break;
for (j = i + 1; j < FD_NUMPART; j++) {
break;
}
}
}
(void) printf(
"Specify the percentage of disk to use for this partition\n"
"(or type \"c\" to specify the size in cylinders). ");
rm_blanks(s);
if (s[0] != 'c') { /* Specify size in percentage of disk */
i = 0;
while ((s[i] != '\0') && (s[i] != '\n')) {
if (s[i] < '0' || s[i] > '9') {
(void) printf("Invalid percentage value "
"specified; retry the operation.");
return (-1);
}
i++;
if (i > 3) {
(void) printf("Invalid percentage value "
"specified; retry the operation.");
return (-1);
}
}
(void) printf(
"Percentage value is too large. The value must be"
" between 1 and 100;\nretry the operation.\n");
return (-1);
}
if (percent < 1) {
(void) printf(
"Percentage value is too small. The value must be"
" between 1 and 100;\nretry the operation.\n");
return (-1);
}
if (percent == 100)
else
/* Verify DOS12 partition doesn't exceed max size of 32MB. */
int n;
(void) printf("Maximum size for a DOS partition "
"is %d%%; retry the operation.",
n <= 100 ? n : 100);
return (-1);
}
max_free = 0;
for (i = 0; i < FD_NUMPART; i++) {
/*
* check for free space before partition i
* where i varies from 0 to 3
*
* freespace after partition 3 is unusable
* because there are no free partitions
*
* freespace begins at the end of previous partition
* or cylinder 1
*/
if (i) {
/* Not an empty table */
} else {
}
/*
* freespace ends before the current partition
* or the end of the disk (chs end)
*/
} else {
/*
* Partition might start before cylinder 1.
* Make sure free space is not negative.
*/
first_free) : 0;
}
/* save largest free space */
/* We found a place to use */
break;
}
"Maximum percentage available is %lld\n",
return (-1);
}
}
if (i >= FD_NUMPART) {
"fdisk: Partition table is full.\n");
return (-1);
}
if ((i = insert_tbl(tsystid, 0, 0, 0, 0, 0, 0, 0,
return (i);
}
return (-1);
} else {
/* Specifying size in cylinders */
(void) printf("Enter starting cylinder number: ");
(void) printf("Invalid number; retry the operation.");
return (-1);
}
if (cyl == 0) {
(void) printf(
"New partition cannot start at cylinder 0.\n");
return (-1);
}
if (cyl >= Numcyl_usable) {
(void) printf(
"Cylinder %d is out of bounds, "
"the maximum is %d.\n",
return (-1);
}
(void) printf("Enter partition size in cylinders: ");
(void) printf("Invalid number, retry the operation.");
return (-1);
}
for (i = 0; i < FD_NUMPART; i++) {
break;
(void) printf(
"Cylinder %d is already allocated"
"\nretry the operation.",
cyl);
return (-1);
}
(void) printf(
"Maximum size for partition is %u cylinders"
"\nretry the operation.",
return (-1);
}
}
/* Verify partition doesn't exceed disk size or 2 TB */
if (Numcyl > Numcyl_usable) {
(void) printf(
"Maximum size for partition is %d "
"cylinders; \nretry the operation.",
Numcyl_usable - cyl);
} else {
(void) printf(
"Maximum size for partition is %d "
"cylinders; \nretry the operation.",
Numcyl_usable - cyl);
}
return (-1);
}
/* Verify DOS12 partition doesn't exceed max size of 32MB. */
(void) printf(
"Maximum size for a %s partition is %ld cylinders;"
"\nretry the operation.",
return (-1);
}
i = insert_tbl(tsystid, 0, 0, 0, 0, 0, 0, 0,
if (i < 0)
return (-1);
if (verify_tbl() < 0) {
(void) printf("fdisk: Cannot create partition table\n");
return (-1);
}
return (i);
}
}
/*
* dispmenu
* Display command menu (interactive mode).
*/
static void
dispmenu(void)
{
#ifdef i386
(void) printf(
"SELECT ONE OF THE FOLLOWING:\n"
" 1. Create a partition\n"
" 2. Specify the active partition\n"
" 3. Delete a partition\n"
" 4. Change between Solaris and Solaris2 Partition IDs\n"
" 6. Exit (update disk configuration and exit)\n"
" 7. Cancel (exit without updating disk configuration)\n");
#else
(void) printf(
"SELECT ONE OF THE FOLLOWING:\n"
" 1. Create a partition\n"
" 2. Specify the active partition\n"
" 3. Delete a partition\n"
" 4. Change between Solaris and Solaris2 Partition IDs\n"
" 5. Exit (update disk configuration and exit)\n"
" 6. Cancel (exit without updating disk configuration)\n");
#endif
}
/*
* pchange
* Change the ACTIVE designation of a partition.
*/
static int
pchange(void)
{
char s[80];
int i, j;
for (;;) {
{
(void) printf(
"Specify the partition number to boot from"
" (or specify 0 for none): ");
}
rm_blanks(s);
if (((s[1] != '\0') && (s[1] != '\n')) ||
(s[0] < '0') || (s[0] > '4')) {
(void) printf(
"Invalid response, please specify a number"
" between 0 and 4.\n");
} else {
break;
}
}
if (s[0] == '0') { /* No active partitions */
for (i = 0; i < FD_NUMPART; i++) {
}
(void) printf(
"No partition is currently marked as active.");
return (0);
} else { /* User has selected a partition to be active */
i = s[0] - '1';
(void) printf("Partition does not exist.");
return (-1);
}
/* a DOS-DATA or EXT-DOS partition cannot be active */
(void) printf(
"DOS-DATA, EXT_DOS and EXT_DOS_LBA partitions "
"cannot be made active.\n");
(void) printf("Select another partition.");
return (-1);
}
for (j = 0; j < FD_NUMPART; j++) {
if (j != i)
}
}
{
(void) printf(
"Partition %d is now active. The system will start up"
" from this\n", i + 1);
(void) printf("partition after the next reboot.");
}
return (1);
}
/*
* Change between SOLARIS and SOLARIS2 partition id
*/
static int
ppartid(void)
{
char *p, s[80];
int i;
for (;;) {
(void) printf("Specify the partition number to change"
" (or enter 0 to exit): ");
return (1);
i = strtol(s, &p, 10);
if (*p != '\n' || i < 0 || i > FD_NUMPART) {
(void) printf(
"Invalid response, retry the operation.\n");
continue;
}
if (i == 0) {
/* exit delete command */
return (1);
}
i -= 1;
} else {
(void) printf(
"Partition %d is not a Solaris partition.",
i + 1);
continue;
}
return (1);
}
}
/*
* pdelete
* Remove partition entry from the table (interactive mode).
*/
static char
pdelete(void)
{
char s[80];
int i;
char pactive;
(void) printf("Specify the partition number to delete"
" (or enter 0 to exit): ");
rm_blanks(s);
if ((s[0] == '0')) { /* exit delete command */
return (1);
}
/* Accept only a single digit between 1 and 4 */
if (((s[1] != '\0') && (s[1] != '\n')) ||
(void) printf("Invalid response, retry the operation.\n");
goto DEL1;
} else { /* Found a digit between 1 and 4 */
--i; /* Structure begins with element 0 */
}
return (-1);
}
#ifdef i386
(void) printf("There are logical drives inside the"
" extended partition\n");
(void) printf("Are you sure of proceeding with deletion ?"
" (type \"y\" or \"n\") ");
if (! yesno()) {
return (1);
}
(void) printf("There are mounted logical drives. "
"Committing changes now can cause data loss or "
"corruption. Unmount all logical drives and then "
"try committing the changes again.\n");
(void) printf("Press enter to continue.\n");
ext_read_input(s);
return (1);
}
(void) fdisk_delete_ext_part(epp);
} else {
#endif
(void) printf("Are you sure you want to delete partition %d?"
" This will make all files and \n", i + 1);
(void) printf("programs in this partition inaccessible (type"
" \"y\" or \"n\"). ");
if (! yesno()) {
return (1);
}
#ifdef i386
}
#endif
pactive = 1;
} else {
pactive = 0;
}
if (pactive) {
(void) printf(" This was the active partition.");
}
return (1);
}
/*
* rm_blanks
* Remove blanks from strings of user responses.
*/
static void
rm_blanks(char *s)
{
register int i, j;
for (i = 0; i < CBUFLEN; i++) {
if ((s[i] == ' ') || (s[i] == '\t'))
continue;
else
/* Found first non-blank character of the string */
break;
}
for (j = 0; i < CBUFLEN; j++, i++) {
if ((s[j] = s[i]) == '\0') {
/* Reached end of string */
return;
}
}
}
/*
* getcyl
* Take the user-specified cylinder number and convert it from a
* string to a decimal value.
*/
static int
getcyl(void)
{
int slen, i, j;
unsigned int cyl;
rm_blanks(s);
slen--;
j = 1;
cyl = 0;
for (i = slen - 1; i >= 0; i--) {
if (s[i] < '0' || s[i] > '9') {
return (-1);
}
cyl += (j * (s[i] - '0'));
j *= 10;
}
return (cyl);
}
/*
* disptbl
* Display the current fdisk table; determine percentage
* of the disk used for each partition.
*/
static void
disptbl(void)
{
int i;
int is_pmbr = 0;
(void) printf("WARNING: critical disk geometry information"
" missing!\n");
exit(1);
}
(void) printf(" Cylinder size is %d (%d byte) blocks\n\n",
(void) printf(
" Cylinders\n");
(void) printf(
" Partition Status Type Start End Length"
" %%\n");
(void) printf(
" ========= ====== ============ ===== === ======"
" ===");
for (i = 0; i < FD_NUMPART; i++) {
continue;
}
else
case UNIXOS:
break;
case SUNIXOS:
#ifdef i386
NULL) == 0)
type = LINSWAPstr;
#endif
break;
case SUNIXOS2:
break;
case X86BOOT:
break;
case DOSOS12:
break;
case DOSOS16:
break;
case EXTDOS:
break;
case DOSDATA:
break;
case DOSHUGE:
break;
case PCIXOS:
break;
case DIAGPART:
break;
case FDISK_IFS:
break;
case FDISK_AIXBOOT:
break;
case FDISK_AIXDATA:
break;
case FDISK_OS2BOOT:
break;
case FDISK_WINDOWS:
break;
case FDISK_EXT_WIN:
break;
case FDISK_FAT95:
break;
case FDISK_EXTLBA:
break;
case FDISK_LINUX:
break;
case FDISK_CPM:
break;
case FDISK_NOVELL2:
break;
case FDISK_NOVELL3:
break;
case FDISK_QNX4:
break;
case FDISK_QNX42:
break;
case FDISK_QNX43:
break;
case FDISK_LINUXNAT:
break;
case FDISK_NTFSVOL1:
type = NTFSVOL1str;
break;
case FDISK_NTFSVOL2:
type = NTFSVOL2str;
break;
case FDISK_BSD:
break;
case FDISK_NEXTSTEP:
type = NEXTSTEPstr;
break;
case FDISK_BSDIFS:
break;
case FDISK_BSDISWAP:
type = BSDISWAPstr;
break;
case EFI_PMBR:
is_pmbr = 1;
break;
default:
break;
}
} else {
length++;
}
/* round up */
percent++;
}
/* Else leave the percent as is since it's already */
/* rounded down */
}
if (percent > 100)
percent = 100;
(void) printf(
"\n %d %s %-12.12s %4d %4d %4d"
" %3d",
}
/* Print warning message if table is empty */
if (nopartdefined()) {
(void) printf("WARNING: no partitions are defined!");
} else {
/* Clear the warning line */
/* Print warning if disk > 2TB and is not EFI PMBR */
(void) printf("WARNING: Disk is larger than 2 TB. "
"Upper limit is 2 TB for non-EFI partition ID\n");
}
}
/*
* print_Table
* Write the detailed fdisk table to standard error for
* the selected disk device.
*/
static void
print_Table(void)
{
int i;
" SYSID ACT BHEAD BSECT BEGCYL EHEAD ESECT ENDCYL RELSECT"
" NUMSECT\n");
for (i = 0; i < FD_NUMPART; i++) {
}
}
/*
* copy_Table_to_Old_Table
* Copy Table into Old_Table. The function only copies the systid,
* numsect, relsect, and bootid values because they are the only
* ones compared when determining if Table has changed.
*/
static void
copy_Table_to_Old_Table(void)
{
int i;
for (i = 0; i < FD_NUMPART; i++) {
}
}
/*
* nulltbl
* Zero out the systid, numsect, relsect, and bootid values in the
* fdisk table.
*/
static void
nulltbl(void)
{
int i;
for (i = 0; i < FD_NUMPART; i++) {
skip_verify[i] = 0;
}
}
/*
* copy_Bootblk_to_Table
* Copy the bytes from the boot record to an internal "Table".
* All unused are padded with zeros starting at offset 446.
*/
static void
copy_Bootblk_to_Table(void)
{
int i;
char *bootptr;
/* Get an aligned copy of the partition tables */
/* Signature is missing */
nulltbl();
return;
}
/*
* When the DOS fdisk command deletes a partition, it is not
* recognized by the old algorithm. The algorithm that
* follows looks at each entry in the Bootrec and copies all
* those that are valid.
*/
for (i = 0; i < FD_NUMPART; i++) {
/* Null entry */
} else {
}
}
/* For now, always replace the bootcode with ours */
}
/*
* fill_ipart
* Initialize ipart structure values.
*/
static void
{
#ifdef sparc
/* Packing struct ipart for Sparc */
#else
#endif
}
/*
* getbyte, getlong
* Get a byte, a short, or a long (SPARC only).
*/
#ifdef sparc
{
uchar_t b;
return (b);
}
{
*bp += 2;
*bp += 2;
return ((uint32_t)b);
}
#endif
/*
* copy_Table_to_Bootblk
* Copy the table into the boot record. Note that the unused
* entries will always be the last ones in the table and they are
* marked with 100 in sysind. The the unused portion of the table
* is padded with zeros in the bytes after the used entries.
*/
static void
copy_Table_to_Bootblk(void)
{
else
}
}
/*
* TableChanged
* Check for any changes in the partition table.
*/
static int
TableChanged(void)
{
int i, changed;
changed = 0;
for (i = 0; i < FD_NUMPART; i++) {
/* Partition table changed, write back to disk */
changed = 1;
}
}
return (changed);
}
/*
* ffile_write
* Display contents of partition table to standard output or
* another file name without writing it to the disk (-W file).
*/
static void
{
register int i;
/*
* If file isn't standard output, then it's a file name.
* Open file and write it.
*/
"fdisk: Cannot open output file %s.\n",
file);
exit(1);
}
}
else
/*
* Write the fdisk table information
*/
/* Write virtual (HBA) geometry, if required */
if (v_flag) {
}
"\n* Id Act Bhead Bsect Bcyl Ehead Esect Ecyl"
" Rsect Numsect\n");
for (i = 0; i < FD_NUMPART; i++) {
" %-5d %-4d %-6d %-6d %-7d %-6d %-6d %-7d %-10u"
" %-10u\n",
0xc0) << 2)),
0xc0) << 2)),
}
#ifdef i386
if (fdisk_ext_part_exists(epp)) {
" %-5d %-4d %-6d %-6d %-7d %-6d %-6d "
"%-7d %-8u %-8u\n",
numsect);
}
}
#endif
}
/*
* fix_slice
* Read the VTOC table on the Solaris partition and check that no
* slices exist that extend past the end of the Solaris partition.
* If no Solaris partition exists, nothing is done.
*/
static void
fix_slice(void)
{
int i;
if (io_image) {
return;
}
for (i = 0; i < FD_NUMPART; i++) {
/*
* Only the size matters (not starting point), since
* VTOC entries are relative to the start of
* the partition.
*/
break;
}
}
if (i >= FD_NUMPART) {
if (!io_nifdisk) {
"fdisk: No Solaris partition found - VTOC not"
" checked.\n");
}
return;
}
}
for (i = 0; i < V_NUMPAR; i++) {
/* Special case for slice two (entire disk) */
if (i == 2) {
"slice %d starts at %llu, is not at"
" start of partition",
if (!io_nifdisk) {
(void) printf(" adjust ?:");
if (yesno())
} else {
}
}
"slice %d size %llu does not cover"
" complete partition",
if (!io_nifdisk) {
(void) printf(" adjust ?:");
if (yesno())
} else {
}
}
"slice %d tag was %d should be %d",
V_BACKUP);
if (!io_nifdisk) {
(void) printf(" fix ?:");
if (yesno())
} else {
}
}
continue;
}
if (io_ADJT) {
"slice %d (start %llu, end %llu)"
" is larger than the partition",
if (!io_nifdisk) {
(void) printf(" remove ?:");
if (yesno()) {
}
} else {
" removed!\n");
}
}
continue;
}
"slice %d (start %llu) is larger than the "
if (!io_nifdisk) {
(void) printf(" remove ?:");
if (yesno()) {
}
} else {
" removed!\n");
}
"slice %d (end %llu) is larger"
" than the partition",
i,
if (!io_nifdisk) {
(void) printf(" adjust ?:");
if (yesno()) {
}
} else {
}
}
}
#if 1 /* bh for now */
/* Make the VTOC look sane - ha ha */
if (disk_vtoc.v_sectorsz == 0)
#endif
/* Write the VTOC back to the disk */
if (!io_readonly)
(void) writevtoc();
}
/*
* yesno
* Get yes or no answer. Return 1 for yes and 0 for no.
*/
static int
yesno(void)
{
char s[80];
for (;;) {
rm_blanks(s);
if (((s[1] != '\0') && (s[1] != '\n')) ||
((s[0] != 'y') && (s[0] != 'n'))) {
(void) printf("Please answer with \"y\" or \"n\": ");
continue;
}
if (s[0] == 'y')
return (1);
else
return (0);
}
}
/*
* readvtoc
* Read the VTOC from the Solaris partition of the device.
*/
static int
readvtoc(void)
{
int i;
if (i == VT_EINVAL) {
vt_inval++;
retval = VTOC_INVAL;
} else if (i == VT_ENOTSUP) {
"GPT\n");
} else {
retval = VTOC_RWERR;
}
}
return (retval);
}
/*
* writevtoc
* Write the VTOC to the Solaris partition on the device.
*/
static int
writevtoc(void)
{
int i;
int retval = 0;
if (i == VT_EINVAL) {
"fdisk: Invalid entry exists in VTOC.\n");
retval = VTOC_INVAL;
} else if (i == VT_ENOTSUP) {
"GPT\n");
} else {
retval = VTOC_RWERR;
}
}
return (retval);
}
/*
* efi_ioctl
* issues DKIOCSETEFI IOCTL
* (duplicate of private efi_ioctl() in rdwr_efi.c
*/
static int
{
int error;
return (error);
}
/*
* clear_efi
* Clear EFI labels from the EFI_PMBR partition on the device
* This function is modeled on the libefi(3LIB) call efi_write()
*/
static int
clear_efi(void)
{
/*
* see if we can read the EFI label
*/
return (VT_ERROR);
}
/*
* set up the dk_ioc structure for writing
*/
return (VT_ERROR);
}
/*
* clear the primary label
*/
if (io_debug) {
"\tClearing primary EFI label at block %lld\n",
}
switch (errno) {
case EIO:
return (VT_EIO);
case EINVAL:
return (VT_EINVAL);
default:
return (VT_ERROR);
}
}
/*
* clear the backup partition table
*/
if (io_debug) {
"\tClearing backup partition table at block %lld\n",
}
errno);
}
/*
* clear the backup label
*/
if (io_debug) {
}
"\tUnable to clear backup EFI label at "
"block %llu; errno %d\n",
errno);
}
return (0);
}
/*
* clear_vtoc
* Clear the VTOC from the current or previous Solaris partition on the
* device.
*/
static void
{
char *disk_label;
#ifdef DEBUG
char *read_label;
#endif /* DEBUG */
} else {
}
if (disk_label == NULL) {
return;
}
if (io_debug) {
"\tClearing primary VTOC at byte %llu (block %llu)\n",
}
"\tError seeking to primary label at byte %llu\n",
return;
}
"\tWarning: only %d bytes written to clear primary"
" VTOC!\n", bytes);
}
#ifdef DEBUG
"DEBUG: Error seeking to primary label at byte %llu\n",
return;
} else {
"DEBUG: Successful lseek() to byte %llu\n",
}
if (read_label == NULL) {
return;
}
"DEBUG: Warning: only %d bytes read of label\n",
bytes);
}
"DEBUG: Warning: disk_label and read_label differ!!!\n");
} else {
"read_label\n");
}
#endif /* DEBUG */
/* Clear backup label */
"\tError seeking to backup label at byte %llu on "
#ifdef DEBUG
#endif /* DEBUG */
return;
}
if (io_debug) {
" byte %llu (block %llu)\n",
}
"\t\tWarning: only %d bytes written to "
"clear backup VTOC at block %llu!\n", bytes,
}
#ifdef DEBUG
"DEBUG: Error seeking to backup label at byte %llu\n",
return;
} else {
"DEBUG: Successful lseek() to byte %llu\n",
}
"DEBUG: Warning: only %d bytes read of backup label\n",
bytes);
}
"DEBUG: Warning: disk_label and read_label differ!!!\n");
} else {
"DEBUG: Good compare of disk_label and backup "
"read_label\n");
}
#endif /* DEBUG */
backup_block += 2;
}
#ifdef DEBUG
#endif /* DEBUG */
}
#define FDISK_STANDARD_LECTURE \
"Fdisk is normally used with the device that " \
"represents the entire fixed disk.\n" \
#define FDISK_LECTURE_NOT_SECTOR_ZERO \
"The device does not appear to include absolute\n" \
"sector 0 of the PHYSICAL disk " \
"(the normal location for an fdisk table).\n"
#define FDISK_LECTURE_NOT_FULL \
"The device does not appear to encompass the entire PHYSICAL disk.\n"
#define FDISK_LECTURE_NO_VTOC \
"Unable to find a volume table of contents.\n" \
"Cannot verify the device encompasses the full PHYSICAL disk.\n"
#define FDISK_LECTURE_NO_GEOM \
"Unable to get geometry from device.\n" \
"Cannot verify the device encompasses the full PHYSICAL disk.\n"
#define FDISK_SHALL_I_CONTINUE \
"Are you sure you want to continue? (y/n) "
/*
* lecture_and_query
* Called when a sanity check fails. This routine gives a warning
* specific to the check that fails, followed by a generic lecture
* about the "right" device to supply as input. Then, if appropriate,
* it will prompt the user on whether or not they want to continue.
* Inappropriate times for prompting are when the user has selected
* non-interactive mode or read-only mode.
*/
static int
{
if (io_nifdisk)
return (0);
return (yesno());
}
static void
{
struct extvtoc v;
struct dk_geom d;
/*
* First try the PARTINFO ioctl. If it works, we will be able
* to tell if they've specified the full disk partition by checking
* to see if they've specified a partition that starts at sector 0.
*/
devname)) {
exit(1);
}
}
devname)) {
exit(1);
}
}
} else {
devname)) {
exit(1);
}
return;
}
devname)) {
exit(1);
}
return;
}
devname)) {
exit(1);
}
}
}
}
/*
* get_node
* Called from main to construct the name of the device node to open.
* Initially tries to stat the node exactly as provided, if that fails
*/
static char *
{
char *node;
/* Don't do anything if we are skipping device checks */
if (io_image)
return (devname);
/* Try the node as provided first */
/*
* Copy the passed in string to a new buffer, prepend the
* default path and try again.
*/
"for device node.\n");
exit(1);
}
/* Copy over the default path and the provided node */
/* Try to stat it again */
/* Failed all options, give up */
"fdisk: Cannot stat device %s.\n",
devname);
exit(1);
}
}
/* Make sure the device specified is the raw device */
"fdisk: %s must be a raw device.\n", node);
exit(1);
}
return (node);
}
#ifdef i386
static void
{
"changes now can lead to inconsistancy in internal system state "
"which can eventually cause data loss or corruption. Unmount all "
"logical drives and try committing the changes again.\n");
ext_read_input(s);
}
/*
* Convert a given partition ID to an descriptive string.
* Just an index into the partition types table.
*/
void
{
}
/*
* Procedure to check the validity of the extended partition menu option
* entered by the user
*/
static int
{
char *p;
if (p == NULL) {
return (1);
}
return (0);
}
/*
* Read 16 bytes of the input (assuming that no valid user input spans more
* than that). Flush the input stream, so that the next read does not reap
* stale data from the previous input that was not processed.
* Note that fgets also reads the trailing '\n'
*/
static void
{
}
/*
* Procedure to read and validate the user option at the extended partition menu
*/
static int
{
(void) printf("\nUnknown Command\n");
return (-1);
}
return (0);
}
/*
* Procedure to print the list of known partition types and their IDs
*/
static void
{
/* Get the current window dimensions */
perror("ioctl");
rowmax = 20;
} else {
/*
* Accommodate the initial headings by reducing the number of
* partition IDs being printed.
*/
}
if (rowmax < 3) {
" Try resizing the window\n");
return;
}
(void) printf("List of known partition types : \n");
(void) printf("PartID Partition Type\n");
(void) printf("====== ==============\n");
for (i = 0; i <= FDISK_MAX_VALID_PART_ID; i++) {
rowcount++;
/*
* After the initial screen, use all the rows for
* printing the partition IDs, but one.
*/
"page or 'q' to quit : ");
return;
}
rowcount = 1;
}
}
}
static void
{
int len, i;
for (;;) {
(void) printf("Enter the partition number : ");
/* Check length of the input */
goto print_error_and_continue;
}
/* Check if there is a non-digit in the input */
for (i = 0; i < len-1; i++) {
goto print_error_and_continue;
}
}
if ((*pno <= FD_NUMPART) ||
goto print_error_and_continue;
}
break;
(void) printf("Invalid partition number\n");
continue;
}
}
static void
{
for (;;) {
(void) printf("Enter the ID ( Type I for list of "
"partition IDs ) : ");
(void) printf("Invalid partition ID\n");
continue;
}
continue;
}
/* Check if there is a non-digit in the input */
for (i = 0; i < len-1; i++) {
(void) printf("Invalid partition ID\n");
break;
}
}
if (i < len - 1) {
continue;
}
/* Check if the (now) valid number is greater than the limit */
(void) printf("Invalid partition ID\n");
continue;
}
/* Disallow multiple extended partitions */
if (fdisk_is_dos_extended(*partid)) {
(void) printf("Multiple extended partitions not "
"allowed\n");
continue;
}
/* Disallow EFI partitions within extended partition */
(void) printf("EFI partitions within an extended "
"partition is not allowed\n");
continue;
}
return; /* Valid partition ID is in partid */
}
}
static void
{
int pno;
if (!fdisk_get_logical_drive_count(epp)) {
(void) printf("\nNo logical drives defined.\n");
return;
}
(void) printf("\n");
}
static int
{
if (ret != FDISK_SUCCESS) {
return (ret);
}
for (;;) {
(void) printf("Enter the beginning cylinder (Default - %d) : ",
*begsec = first_free_sec;
return (FDISK_SUCCESS);
}
(void) printf("Input too long\n");
(void) printf("Invalid beginning cylinder number\n");
continue;
}
/* Check if there is a non-digit in the input */
for (i = 0; i < len - 1; i++) {
(void) printf("Invalid beginning cylinder "
"number\n");
break;
}
}
if (i < len - 1) {
continue;
}
switch (ret) {
case FDISK_SUCCESS:
/*
* Success.
* Valid beginning sector is in begsec
*/
break;
case FDISK_EOVERLAP:
(void) printf("Partition boundary overlaps "
"with ");
(void) printf("existing partitions\n");
(void) printf("Invalid beginning cylinder "
"number\n");
continue;
case FDISK_EOOBOUND:
(void) printf("Cylinder boundary beyond the "
"limits\n");
(void) printf("Invalid beginning cylinder "
"number\n");
continue;
}
return (FDISK_SUCCESS);
}
}
/*
* Algorithm :
* 1. Check if the first character is a +
* a) If yes, check if the last character is 'k', 'm' or 'g'
* 2. If not, check if there are any non-digits
* 3. Check for the length of the numeral string
* 4. atoi the numeral string
* 5. In case of data entered in KB, MB or GB, convert it to number of cylinders
* a) Adjust size to be cylinder boundary aligned
* 6. If size specifies is zero, flag error
* 7. Check if the size is less than 1 cylinder
* a) If yes, default the size FDISK_MIN_PART_SIZE
* b) If no, Check if the size is within endcyl - begcyl
*/
static void
{
int copy_len;
exit(1);
}
for (;;) {
(void) printf("Enter the size in cylinders (Default End "
"Cylinder -");
(void) printf("Type +<size>K, +<size>M or +<size>G to enter "
"size in");
(void) printf("KB, MB or GB : ");
mbgb = 0;
*endsec = last_free_sec;
return;
}
copy_len--;
copy_len--;
}
(void) printf("Invalid partition size\n");
continue;
}
copy_len--;
mbgb = 1;
}
if (copy_len > FDISK_MAX_VALID_CYL_NUM_DIGITS) {
(void) printf("Input too long\n");
(void) printf("Invalid partition size\n");
continue;
}
break;
}
}
(void) printf("Invalid partition size\n");
continue;
}
if (size == 0) {
(void) printf("Zero size is invalid\n");
(void) printf("Invalid partition size\n");
continue;
}
if (mbgb) {
}
(void) printf("Cylinder boundary beyond the limits");
(void) printf(" or overlaps with existing");
(void) printf(" partitions\n");
(void) printf("Invalid partition size\n");
continue;
}
/*
* Adjust the ending sector such that there are no partial
* cylinders allocated. But at the same time, make sure it
* doesn't over shoot boundaries.
*/
}
return;
}
}
/*
* ALGORITHM:
* 3. Allow the user to specify the beginning cylinder of the new partition
* 4. Check for the validity of the entered data
* a) If it is non-numeric
* b) If it is beyond the extended partition limits
* c) If it overlaps with the current logical drives
* 5. Allow the user to specify the size in cylinders/ human readable form
* 6. Check for the validity of the entered data
* a) If it is non-numeric
* b) If it is beyond the extended partition limits
* c) If it overlaps with the current logical drives
* d) If it is a number lesser than the starting cylinder
* 7. Request partition ID for the new partition.
* 8. Update the first free cylinder available
* 9. Display Success message
*/
static void
{
int rval;
(void) printf("\nNumber of logical drives exceeds limit of "
"%d.\n", MAX_EXT_PARTS);
(void) printf("Command did not succeed. Press enter to "
"continue\n");
return;
}
(void) printf("\n");
switch (rval) {
case FDISK_SUCCESS:
break;
case FDISK_EOOBOUND:
(void) printf("\nNo space left in the extended "
"partition\n");
(void) printf("Press enter to continue\n");
return;
}
}
static void
{
int pno;
if (!fdisk_get_logical_drive_count(epp)) {
(void) printf("\nNo logical drives defined.\n");
return;
}
(void) printf("\n");
partid);
}
#ifdef DEBUG
static void
{
int pno;
if (!fdisk_get_logical_drive_count(epp)) {
(void) printf("\nNo logical drives defined.\n");
return;
}
(void) printf("\n\n");
puts("# start block end block abs start abs end OSType");
/* Print the logical drive details */
(void) printf("%d: %.10u %.10u %.10u %.10u",
pno,
/*
* Print the second entry in the EBR which is information
* about the location and the size of the next extended
* partition.
*/
(void) printf("%d: %.10u %.10u %.10s %.10s",
pno,
" ", " ");
}
}
#endif
static void
{
int sysid;
int pno;
exit(1);
}
if (!fdisk_get_logical_drive_count(epp)) {
(void) printf("\nNo logical drives defined.\n");
return;
}
(void) printf("\n");
(void) printf("Number of cylinders in disk : %u\n",
numcyl);
(void) printf("Beginning cylinder of extended partition : %u\n",
(void) printf("Ending cylinder of extended partition : %u\n",
(void) printf("\n");
(void) printf("Part# StartCyl EndCyl Length %% "
"Part ID (Type)\n");
(void) printf("===== ======== ======== ======= ==="
" ==============\n");
/* Print the logical drive details */
/*
* Check if partition id 0x82 is Solaris
* or a Linux swap. Print the string
* accordingly.
*/
NULL) == 0)
else
} else {
}
length = 1;
} else {
}
/* round up */
percent++;
}
/* Else leave the percent as is since it's already */
/* rounded down */
}
if (percent > 100) {
percent = 100;
}
(void) printf("%-5d %-8u %-8u %-7u %-3d "
"%-3d (%-.28s)\n",
}
#ifdef DEBUG
#endif
(void) printf("\n");
}
static void
{
(void) printf("\n");
(void) printf("a Add a logical drive\n");
(void) printf("d Delete a logical drive\n");
(void) printf("h Print this help menu\n");
(void) printf("i Change the id of the logical drive\n");
(void) printf("p Print the logical drive layout\n");
(void) printf("r Return to the main fdisk menu\n");
(void) printf(" (To commit or cancel the changes)\n");
(void) printf("\n");
}
static void
{
int i;
if (fdisk_corrupt_logical_drives(epp)) {
(void) printf("One or more logical drives seem to be "
"corrupt.\n");
(void) printf("Displaying only sane logical drives.\n");
}
(void) printf("The following logical drives have a wrong "
"boot block signature :\n\n");
for (i = 0; bbsigp[i]; i++) {
}
(void) printf("\n\n");
(void) printf("They will be corrected when you choose to "
"commit\n");
bbsig_disp_flag = 0;
}
(void) printf("Extended partition menu\n");
for (;;) {
(void) printf("\nEnter Command (Type h for help) : ");
if ((ext_read_options(buf)) < 0) {
(void) printf("\nCommand Options : \n");
continue;
}
switch (buf[0]) {
case 'a':
break;
case 'd':
break;
case 'h':
break;
case 'i':
break;
case 'p':
break;
case 'r':
return;
default : /* NOTREACHED */
break;
}
}
}
#endif /* i386 */
static int
{
int i;
for (i = 0; i < FD_NUMPART; i++)
return (0);
return (1);
}