17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50972747aSyl194034 * Common Development and Distribution License (the "License").
60972747aSyl194034 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*589271a4SSheng-Liang Eric Zhang * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate */
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate * This file contains functions that implement the fdisk menu commands.
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate #include "global.h"
297c478bd9Sstevel@tonic-gate #include <errno.h>
307c478bd9Sstevel@tonic-gate #include <sys/time.h>
317c478bd9Sstevel@tonic-gate #include <sys/resource.h>
327c478bd9Sstevel@tonic-gate #include <sys/wait.h>
337c478bd9Sstevel@tonic-gate #include <signal.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <fcntl.h>
367c478bd9Sstevel@tonic-gate #include <stdlib.h>
377c478bd9Sstevel@tonic-gate #include <sys/dktp/fdisk.h>
387c478bd9Sstevel@tonic-gate #include <sys/stat.h>
397c478bd9Sstevel@tonic-gate #include <sys/dklabel.h>
40aa1b14e7SSheshadri Vasudevan #ifdef i386
41aa1b14e7SSheshadri Vasudevan #include <libfdisk.h>
42aa1b14e7SSheshadri Vasudevan #endif
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #include "main.h"
457c478bd9Sstevel@tonic-gate #include "analyze.h"
467c478bd9Sstevel@tonic-gate #include "menu.h"
477c478bd9Sstevel@tonic-gate #include "menu_command.h"
487c478bd9Sstevel@tonic-gate #include "menu_defect.h"
497c478bd9Sstevel@tonic-gate #include "menu_partition.h"
507c478bd9Sstevel@tonic-gate #include "menu_fdisk.h"
517c478bd9Sstevel@tonic-gate #include "param.h"
527c478bd9Sstevel@tonic-gate #include "misc.h"
537c478bd9Sstevel@tonic-gate #include "label.h"
547c478bd9Sstevel@tonic-gate #include "startup.h"
557c478bd9Sstevel@tonic-gate #include "partition.h"
567c478bd9Sstevel@tonic-gate #include "prompts.h"
573e1bd7a2Ssjelinek #include "checkdev.h"
587c478bd9Sstevel@tonic-gate #include "io.h"
597c478bd9Sstevel@tonic-gate #include "ctlr_scsi.h"
607c478bd9Sstevel@tonic-gate #include "auto_sense.h"
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate extern struct menu_item menu_fdisk[];
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate * Byte swapping macros for accessing struct ipart
667c478bd9Sstevel@tonic-gate * to resolve little endian on Sparc.
677c478bd9Sstevel@tonic-gate */
687c478bd9Sstevel@tonic-gate #if defined(sparc)
697c478bd9Sstevel@tonic-gate #define les(val) ((((val)&0xFF)<<8)|(((val)>>8)&0xFF))
707c478bd9Sstevel@tonic-gate #define lel(val) (((unsigned)(les((val)&0x0000FFFF))<<16) | \
717c478bd9Sstevel@tonic-gate (les((unsigned)((val)&0xffff0000)>>16)))
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate #elif defined(i386)
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate #define les(val) (val)
767c478bd9Sstevel@tonic-gate #define lel(val) (val)
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate #else /* defined(sparc) */
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate #error No Platform defined
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate #endif /* defined(sparc) */
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate /* Function prototypes */
867c478bd9Sstevel@tonic-gate #ifdef __STDC__
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate #if defined(sparc)
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate static int getbyte(uchar_t **);
917c478bd9Sstevel@tonic-gate static int getlong(uchar_t **);
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate #endif /* defined(sparc) */
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate static int get_solaris_part(int fd, struct ipart *ipart);
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate #else /* __STDC__ */
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate #if defined(sparc)
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate static int getbyte();
1027c478bd9Sstevel@tonic-gate static int getlong();
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate #endif /* defined(sparc) */
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate static int get_solaris_part();
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate #endif /* __STDC__ */
1097c478bd9Sstevel@tonic-gate
110aa1b14e7SSheshadri Vasudevan #ifdef i386
111aa1b14e7SSheshadri Vasudevan int extpart_init(ext_part_t **epp);
112aa1b14e7SSheshadri Vasudevan #endif
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate * Handling the alignment problem of struct ipart.
1157c478bd9Sstevel@tonic-gate */
1167c478bd9Sstevel@tonic-gate static void
fill_ipart(char * bootptr,struct ipart * partp)1177c478bd9Sstevel@tonic-gate fill_ipart(char *bootptr, struct ipart *partp)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate #if defined(sparc)
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate * Sparc platform:
1227c478bd9Sstevel@tonic-gate *
1237c478bd9Sstevel@tonic-gate * Packing short/word for struct ipart to resolve
1247c478bd9Sstevel@tonic-gate * little endian on Sparc since it is not
1257c478bd9Sstevel@tonic-gate * properly aligned on Sparc.
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate partp->bootid = getbyte((uchar_t **)&bootptr);
1287c478bd9Sstevel@tonic-gate partp->beghead = getbyte((uchar_t **)&bootptr);
1297c478bd9Sstevel@tonic-gate partp->begsect = getbyte((uchar_t **)&bootptr);
1307c478bd9Sstevel@tonic-gate partp->begcyl = getbyte((uchar_t **)&bootptr);
1317c478bd9Sstevel@tonic-gate partp->systid = getbyte((uchar_t **)&bootptr);
1327c478bd9Sstevel@tonic-gate partp->endhead = getbyte((uchar_t **)&bootptr);
1337c478bd9Sstevel@tonic-gate partp->endsect = getbyte((uchar_t **)&bootptr);
1347c478bd9Sstevel@tonic-gate partp->endcyl = getbyte((uchar_t **)&bootptr);
1357c478bd9Sstevel@tonic-gate partp->relsect = getlong((uchar_t **)&bootptr);
1367c478bd9Sstevel@tonic-gate partp->numsect = getlong((uchar_t **)&bootptr);
1377c478bd9Sstevel@tonic-gate #elif defined(i386)
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate * i386 platform:
1407c478bd9Sstevel@tonic-gate *
1417c478bd9Sstevel@tonic-gate * The fdisk table does not begin on a 4-byte boundary within
1427c478bd9Sstevel@tonic-gate * the master boot record; so, we need to recopy its contents
1437c478bd9Sstevel@tonic-gate * to another data structure to avoid an alignment exception.
1447c478bd9Sstevel@tonic-gate */
1457c478bd9Sstevel@tonic-gate (void) bcopy(bootptr, partp, sizeof (struct ipart));
1467c478bd9Sstevel@tonic-gate #else
1477c478bd9Sstevel@tonic-gate #error No Platform defined
1487c478bd9Sstevel@tonic-gate #endif /* defined(sparc) */
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate * Get a correct byte/short/word routines for Sparc platform.
1537c478bd9Sstevel@tonic-gate */
1547c478bd9Sstevel@tonic-gate #if defined(sparc)
1557c478bd9Sstevel@tonic-gate static int
getbyte(uchar_t ** bp)1567c478bd9Sstevel@tonic-gate getbyte(uchar_t **bp)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate int b;
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate b = **bp;
1617c478bd9Sstevel@tonic-gate *bp = *bp + 1;
1627c478bd9Sstevel@tonic-gate return (b);
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate #ifdef DEADCODE
1667c478bd9Sstevel@tonic-gate static int
getshort(uchar_t ** bp)1677c478bd9Sstevel@tonic-gate getshort(uchar_t **bp)
1687c478bd9Sstevel@tonic-gate {
1697c478bd9Sstevel@tonic-gate int b;
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate b = ((**bp) << 8) | *(*bp + 1);
1727c478bd9Sstevel@tonic-gate *bp += 2;
1737c478bd9Sstevel@tonic-gate return (b);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate #endif /* DEADCODE */
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate static int
getlong(uchar_t ** bp)1787c478bd9Sstevel@tonic-gate getlong(uchar_t **bp)
1797c478bd9Sstevel@tonic-gate {
1807c478bd9Sstevel@tonic-gate int b, bh, bl;
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate bh = ((**bp) << 8) | *(*bp + 1);
1837c478bd9Sstevel@tonic-gate *bp += 2;
1847c478bd9Sstevel@tonic-gate bl = ((**bp) << 8) | *(*bp + 1);
1857c478bd9Sstevel@tonic-gate *bp += 2;
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate b = (bh << 16) | bl;
1887c478bd9Sstevel@tonic-gate return (b);
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate #endif /* defined(sparc) */
1917c478bd9Sstevel@tonic-gate
192*589271a4SSheng-Liang Eric Zhang #ifdef i386
193*589271a4SSheng-Liang Eric Zhang /*
194*589271a4SSheng-Liang Eric Zhang * Convert emcpowerN[a-p,p0,p1,p2,p3,p4] to emcpowerNp0 path,
195*589271a4SSheng-Liang Eric Zhang * this is specific for emc powerpath driver.
196*589271a4SSheng-Liang Eric Zhang */
197*589271a4SSheng-Liang Eric Zhang static void
get_emcpower_pname(char * name,char * devname)198*589271a4SSheng-Liang Eric Zhang get_emcpower_pname(char *name, char *devname)
199*589271a4SSheng-Liang Eric Zhang {
200*589271a4SSheng-Liang Eric Zhang char *emcp = "emcpower";
201*589271a4SSheng-Liang Eric Zhang char *npt = NULL;
202*589271a4SSheng-Liang Eric Zhang char np[MAXNAMELEN];
203*589271a4SSheng-Liang Eric Zhang int i = strlen(emcp);
204*589271a4SSheng-Liang Eric Zhang
205*589271a4SSheng-Liang Eric Zhang (void) strcpy(np, devname);
206*589271a4SSheng-Liang Eric Zhang npt = strstr(np, emcp);
207*589271a4SSheng-Liang Eric Zhang while ((i < strlen(npt)) && (isdigit(npt[i])))
208*589271a4SSheng-Liang Eric Zhang i++;
209*589271a4SSheng-Liang Eric Zhang npt[i] = '\0';
210*589271a4SSheng-Liang Eric Zhang (void) snprintf(name, MAXNAMELEN, "/dev/rdsk/%sp0", npt);
211*589271a4SSheng-Liang Eric Zhang }
212*589271a4SSheng-Liang Eric Zhang #endif
213*589271a4SSheng-Liang Eric Zhang
214895142e0Syl194034 /*
215895142e0Syl194034 * Convert cn[tn]dn to cn[tn]dns2 path
216895142e0Syl194034 */
217895142e0Syl194034 static void
get_sname(char * name)218895142e0Syl194034 get_sname(char *name)
219895142e0Syl194034 {
220895142e0Syl194034 char buf[MAXPATHLEN];
221895142e0Syl194034 char *devp = "/dev/dsk";
222895142e0Syl194034 char *rdevp = "/dev/rdsk";
223895142e0Syl194034 char np[MAXNAMELEN];
224895142e0Syl194034 char *npt;
225895142e0Syl194034
226*589271a4SSheng-Liang Eric Zhang #ifdef i386
227*589271a4SSheng-Liang Eric Zhang if (emcpower_name(cur_disk->disk_name)) {
228*589271a4SSheng-Liang Eric Zhang get_emcpower_pname(name, cur_disk->disk_name);
229*589271a4SSheng-Liang Eric Zhang return;
230*589271a4SSheng-Liang Eric Zhang }
231*589271a4SSheng-Liang Eric Zhang #endif
232*589271a4SSheng-Liang Eric Zhang
233895142e0Syl194034 /*
234895142e0Syl194034 * If it is a full path /dev/[r]dsk/cn[tn]dn, use this path
235895142e0Syl194034 */
236895142e0Syl194034 (void) strcpy(np, cur_disk->disk_name);
237895142e0Syl194034 if (strncmp(rdevp, cur_disk->disk_name, strlen(rdevp)) == 0 ||
238895142e0Syl194034 strncmp(devp, cur_disk->disk_name, strlen(devp)) == 0) {
239895142e0Syl194034 /*
240895142e0Syl194034 * Skip if the path is already included with sN
241895142e0Syl194034 */
242895142e0Syl194034 if (strchr(np, 's') == strrchr(np, 's')) {
243895142e0Syl194034 npt = strrchr(np, 'p');
244895142e0Syl194034 /* If pN is found, do not include it */
24576871191Syl194034 if (npt != NULL) {
24676871191Syl194034 *npt = '\0';
247895142e0Syl194034 }
248895142e0Syl194034 (void) snprintf(buf, sizeof (buf), "%ss2", np);
249895142e0Syl194034 } else {
250895142e0Syl194034 (void) snprintf(buf, sizeof (buf), "%s", np);
251895142e0Syl194034 }
252895142e0Syl194034 } else {
253895142e0Syl194034 (void) snprintf(buf, sizeof (buf), "/dev/rdsk/%ss2", np);
254895142e0Syl194034 }
255895142e0Syl194034 (void) strcpy(name, buf);
256895142e0Syl194034 }
2577c478bd9Sstevel@tonic-gate
2587c478bd9Sstevel@tonic-gate /*
2597c478bd9Sstevel@tonic-gate * Convert cn[tn]dnsn to cn[tn]dnp0 path
2607c478bd9Sstevel@tonic-gate */
2617c478bd9Sstevel@tonic-gate static void
get_pname(char * name)2627c478bd9Sstevel@tonic-gate get_pname(char *name)
2637c478bd9Sstevel@tonic-gate {
2647c478bd9Sstevel@tonic-gate char buf[MAXPATHLEN];
2657c478bd9Sstevel@tonic-gate char *devp = "/dev/dsk";
2667c478bd9Sstevel@tonic-gate char *rdevp = "/dev/rdsk";
2677c478bd9Sstevel@tonic-gate char np[MAXNAMELEN];
2687c478bd9Sstevel@tonic-gate char *npt;
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate /*
2717c478bd9Sstevel@tonic-gate * If it is a full path /dev/[r]dsk/cn[tn]dnsn, use this path
2727c478bd9Sstevel@tonic-gate */
2730972747aSyl194034 if (cur_disk == NULL) {
2740972747aSyl194034 (void) strcpy(np, x86_devname);
2750972747aSyl194034 } else {
2767c478bd9Sstevel@tonic-gate (void) strcpy(np, cur_disk->disk_name);
2770972747aSyl194034 }
2780972747aSyl194034
279*589271a4SSheng-Liang Eric Zhang #ifdef i386
280*589271a4SSheng-Liang Eric Zhang if (emcpower_name(np)) {
281*589271a4SSheng-Liang Eric Zhang get_emcpower_pname(name, np);
282*589271a4SSheng-Liang Eric Zhang return;
283*589271a4SSheng-Liang Eric Zhang }
284*589271a4SSheng-Liang Eric Zhang #endif
285*589271a4SSheng-Liang Eric Zhang
2860972747aSyl194034 if (strncmp(rdevp, np, strlen(rdevp)) == 0 ||
2870972747aSyl194034 strncmp(devp, np, strlen(devp)) == 0) {
2887c478bd9Sstevel@tonic-gate /*
2897c478bd9Sstevel@tonic-gate * Skip if the path is already included with pN
2907c478bd9Sstevel@tonic-gate */
2917c478bd9Sstevel@tonic-gate if (strchr(np, 'p') == NULL) {
2927c478bd9Sstevel@tonic-gate npt = strrchr(np, 's');
2937c478bd9Sstevel@tonic-gate /* If sN is found, do not include it */
2947c478bd9Sstevel@tonic-gate if (isdigit(*++npt)) {
2957c478bd9Sstevel@tonic-gate *--npt = '\0';
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%sp0", np);
2987c478bd9Sstevel@tonic-gate } else {
2997c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s", np);
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate } else {
3027c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "/dev/rdsk/%sp0", np);
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate (void) strcpy(name, buf);
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate /*
3087c478bd9Sstevel@tonic-gate * Open file descriptor for current disk (cur_file)
3097c478bd9Sstevel@tonic-gate * with "p0" path or cur_disk->disk_path
3107c478bd9Sstevel@tonic-gate */
3117c478bd9Sstevel@tonic-gate void
open_cur_file(int mode)3127c478bd9Sstevel@tonic-gate open_cur_file(int mode)
3137c478bd9Sstevel@tonic-gate {
3147c478bd9Sstevel@tonic-gate char *dkpath;
3157c478bd9Sstevel@tonic-gate char pbuf[MAXPATHLEN];
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate switch (mode) {
3187c478bd9Sstevel@tonic-gate case FD_USE_P0_PATH:
3197c478bd9Sstevel@tonic-gate (void) get_pname(&pbuf[0]);
3207c478bd9Sstevel@tonic-gate dkpath = pbuf;
3217c478bd9Sstevel@tonic-gate break;
3227c478bd9Sstevel@tonic-gate case FD_USE_CUR_DISK_PATH:
323895142e0Syl194034 if (cur_disk->fdisk_part.systid == SUNIXOS ||
324895142e0Syl194034 cur_disk->fdisk_part.systid == SUNIXOS2) {
325895142e0Syl194034 (void) get_sname(&pbuf[0]);
326895142e0Syl194034 dkpath = pbuf;
327895142e0Syl194034 } else {
3287c478bd9Sstevel@tonic-gate dkpath = cur_disk->disk_path;
329895142e0Syl194034 }
3307c478bd9Sstevel@tonic-gate break;
3317c478bd9Sstevel@tonic-gate default:
332aa1b14e7SSheshadri Vasudevan err_print("Error: Invalid mode option for opening "
333aa1b14e7SSheshadri Vasudevan "cur_file\n");
3347c478bd9Sstevel@tonic-gate fullabort();
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate /* Close previous cur_file */
3387c478bd9Sstevel@tonic-gate (void) close(cur_file);
3397c478bd9Sstevel@tonic-gate /* Open cur_file with the required path dkpath */
3407c478bd9Sstevel@tonic-gate if ((cur_file = open_disk(dkpath, O_RDWR | O_NDELAY)) < 0) {
3417c478bd9Sstevel@tonic-gate err_print(
3427c478bd9Sstevel@tonic-gate "Error: can't open selected disk '%s'.\n", dkpath);
3437c478bd9Sstevel@tonic-gate fullabort();
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate /*
3497c478bd9Sstevel@tonic-gate * This routine implements the 'fdisk' command. It simply runs
3507c478bd9Sstevel@tonic-gate * the fdisk command on the current disk.
3517c478bd9Sstevel@tonic-gate * Use of this is restricted to interactive mode only.
3527c478bd9Sstevel@tonic-gate */
3537c478bd9Sstevel@tonic-gate int
c_fdisk()3547c478bd9Sstevel@tonic-gate c_fdisk()
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate char buf[MAXPATHLEN];
3587c478bd9Sstevel@tonic-gate char pbuf[MAXPATHLEN];
3597c478bd9Sstevel@tonic-gate struct stat statbuf;
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate /*
3627c478bd9Sstevel@tonic-gate * We must be in interactive mode to use the fdisk command
3637c478bd9Sstevel@tonic-gate */
3647c478bd9Sstevel@tonic-gate if (option_f != (char *)NULL || isatty(0) != 1 || isatty(1) != 1) {
3657c478bd9Sstevel@tonic-gate err_print("Fdisk command is for interactive use only!\n");
3667c478bd9Sstevel@tonic-gate return (-1);
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate /*
3707c478bd9Sstevel@tonic-gate * There must be a current disk type and a current disk
3717c478bd9Sstevel@tonic-gate */
3727c478bd9Sstevel@tonic-gate if (cur_dtype == NULL) {
3737c478bd9Sstevel@tonic-gate err_print("Current Disk Type is not set.\n");
3747c478bd9Sstevel@tonic-gate return (-1);
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate /*
3787c478bd9Sstevel@tonic-gate * Before running the fdisk command, get file status of
3797c478bd9Sstevel@tonic-gate * /dev/rdsk/cn[tn]dnp0 path to see if this disk
3807c478bd9Sstevel@tonic-gate * supports fixed disk partition table.
3817c478bd9Sstevel@tonic-gate */
3827c478bd9Sstevel@tonic-gate (void) get_pname(&pbuf[0]);
3837c478bd9Sstevel@tonic-gate if (stat(pbuf, (struct stat *)&statbuf) == -1 ||
3847c478bd9Sstevel@tonic-gate !S_ISCHR(statbuf.st_mode)) {
3857c478bd9Sstevel@tonic-gate err_print(
3867c478bd9Sstevel@tonic-gate "Disk does not support fixed disk partition table\n");
3877c478bd9Sstevel@tonic-gate return (0);
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate /*
3917c478bd9Sstevel@tonic-gate * Run the fdisk program.
3927c478bd9Sstevel@tonic-gate */
3937c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "fdisk %s\n", pbuf);
3947c478bd9Sstevel@tonic-gate (void) system(buf);
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate /*
3977c478bd9Sstevel@tonic-gate * Open cur_file with "p0" path for accessing the fdisk table
3987c478bd9Sstevel@tonic-gate */
3997c478bd9Sstevel@tonic-gate (void) open_cur_file(FD_USE_P0_PATH);
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate /*
4027c478bd9Sstevel@tonic-gate * Get solaris partition information in the fdisk partition table
4037c478bd9Sstevel@tonic-gate */
4047c478bd9Sstevel@tonic-gate if (get_solaris_part(cur_file, &cur_disk->fdisk_part) == -1) {
4057c478bd9Sstevel@tonic-gate err_print("No fdisk solaris partition found\n");
4067c478bd9Sstevel@tonic-gate cur_disk->fdisk_part.numsect = 0; /* No Solaris */
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate /*
4107c478bd9Sstevel@tonic-gate * Restore cur_file with cur_disk->disk_path
4117c478bd9Sstevel@tonic-gate */
4127c478bd9Sstevel@tonic-gate (void) open_cur_file(FD_USE_CUR_DISK_PATH);
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate return (0);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate * Read MBR on the disk
4197c478bd9Sstevel@tonic-gate * if the Solaris partition has changed,
4207c478bd9Sstevel@tonic-gate * reread the vtoc
4217c478bd9Sstevel@tonic-gate */
4227c478bd9Sstevel@tonic-gate #ifdef DEADCODE
4237c478bd9Sstevel@tonic-gate static void
update_cur_parts()4247c478bd9Sstevel@tonic-gate update_cur_parts()
4257c478bd9Sstevel@tonic-gate {
4267c478bd9Sstevel@tonic-gate
4277c478bd9Sstevel@tonic-gate int i;
4287c478bd9Sstevel@tonic-gate register struct partition_info *parts;
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate for (i = 0; i < NDKMAP; i++) {
4317c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
4327c478bd9Sstevel@tonic-gate if (cur_parts->vtoc.v_part[i].p_tag &&
4337c478bd9Sstevel@tonic-gate cur_parts->vtoc.v_part[i].p_tag != V_ALTSCTR) {
4347c478bd9Sstevel@tonic-gate cur_parts->vtoc.v_part[i].p_start = 0;
4357c478bd9Sstevel@tonic-gate cur_parts->vtoc.v_part[i].p_size = 0;
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate #endif
4387c478bd9Sstevel@tonic-gate cur_parts->pinfo_map[i].dkl_nblk = 0;
4397c478bd9Sstevel@tonic-gate cur_parts->pinfo_map[i].dkl_cylno = 0;
4407c478bd9Sstevel@tonic-gate cur_parts->vtoc.v_part[i].p_tag =
4417c478bd9Sstevel@tonic-gate default_vtoc_map[i].p_tag;
4427c478bd9Sstevel@tonic-gate cur_parts->vtoc.v_part[i].p_flag =
4437c478bd9Sstevel@tonic-gate default_vtoc_map[i].p_flag;
4447c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
4457c478bd9Sstevel@tonic-gate }
4467c478bd9Sstevel@tonic-gate #endif
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate cur_parts->pinfo_map[C_PARTITION].dkl_nblk = ncyl * spc();
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
4517c478bd9Sstevel@tonic-gate /*
4527c478bd9Sstevel@tonic-gate * Adjust for the boot partitions
4537c478bd9Sstevel@tonic-gate */
4547c478bd9Sstevel@tonic-gate cur_parts->pinfo_map[I_PARTITION].dkl_nblk = spc();
4557c478bd9Sstevel@tonic-gate cur_parts->pinfo_map[I_PARTITION].dkl_cylno = 0;
4567c478bd9Sstevel@tonic-gate cur_parts->vtoc.v_part[C_PARTITION].p_start =
4577c478bd9Sstevel@tonic-gate cur_parts->pinfo_map[C_PARTITION].dkl_cylno * nhead * nsect;
4587c478bd9Sstevel@tonic-gate cur_parts->vtoc.v_part[C_PARTITION].p_size =
4597c478bd9Sstevel@tonic-gate cur_parts->pinfo_map[C_PARTITION].dkl_nblk;
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate cur_parts->vtoc.v_part[I_PARTITION].p_start =
4627c478bd9Sstevel@tonic-gate cur_parts->pinfo_map[I_PARTITION].dkl_cylno;
4637c478bd9Sstevel@tonic-gate cur_parts->vtoc.v_part[I_PARTITION].p_size =
4647c478bd9Sstevel@tonic-gate cur_parts->pinfo_map[I_PARTITION].dkl_nblk;
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate #endif /* defined(_SUNOS_VTOC_16) */
4677c478bd9Sstevel@tonic-gate parts = cur_dtype->dtype_plist;
4687c478bd9Sstevel@tonic-gate cur_dtype->dtype_ncyl = ncyl;
4697c478bd9Sstevel@tonic-gate cur_dtype->dtype_plist = cur_parts;
4707c478bd9Sstevel@tonic-gate parts->pinfo_name = cur_parts->pinfo_name;
4717c478bd9Sstevel@tonic-gate cur_disk->disk_parts = cur_parts;
4727c478bd9Sstevel@tonic-gate cur_ctype->ctype_dlist = cur_dtype;
4737c478bd9Sstevel@tonic-gate
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate #endif /* DEADCODE */
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate static int
get_solaris_part(int fd,struct ipart * ipart)4787c478bd9Sstevel@tonic-gate get_solaris_part(int fd, struct ipart *ipart)
4797c478bd9Sstevel@tonic-gate {
4807c478bd9Sstevel@tonic-gate int i;
4817c478bd9Sstevel@tonic-gate struct ipart ip;
4827c478bd9Sstevel@tonic-gate int status;
48365908c77Syu, larry liu - Sun Microsystems - Beijing China char *mbr;
4847c478bd9Sstevel@tonic-gate char *bootptr;
48541ebd847Syl194034 struct dk_label update_label;
486aa1b14e7SSheshadri Vasudevan ushort_t found = 0;
487aa1b14e7SSheshadri Vasudevan #ifdef i386
488aa1b14e7SSheshadri Vasudevan uint32_t relsec, numsec;
489aa1b14e7SSheshadri Vasudevan int pno, rval, ext_part_found = 0;
490aa1b14e7SSheshadri Vasudevan ext_part_t *epp;
491aa1b14e7SSheshadri Vasudevan #endif
4927c478bd9Sstevel@tonic-gate
4937c478bd9Sstevel@tonic-gate (void) lseek(fd, 0, 0);
4947c478bd9Sstevel@tonic-gate
49565908c77Syu, larry liu - Sun Microsystems - Beijing China /*
49665908c77Syu, larry liu - Sun Microsystems - Beijing China * We may get mbr of different size, but the first 512 bytes
49765908c77Syu, larry liu - Sun Microsystems - Beijing China * are valid information.
49865908c77Syu, larry liu - Sun Microsystems - Beijing China */
49965908c77Syu, larry liu - Sun Microsystems - Beijing China mbr = malloc(cur_blksz);
50065908c77Syu, larry liu - Sun Microsystems - Beijing China if (mbr == NULL) {
50165908c77Syu, larry liu - Sun Microsystems - Beijing China err_print("No memory available.\n");
5027c478bd9Sstevel@tonic-gate return (-1);
5037c478bd9Sstevel@tonic-gate }
50465908c77Syu, larry liu - Sun Microsystems - Beijing China status = read(fd, mbr, cur_blksz);
50565908c77Syu, larry liu - Sun Microsystems - Beijing China
50665908c77Syu, larry liu - Sun Microsystems - Beijing China if (status != cur_blksz) {
50765908c77Syu, larry liu - Sun Microsystems - Beijing China err_print("Bad read of fdisk partition. Status = %x\n", status);
50865908c77Syu, larry liu - Sun Microsystems - Beijing China err_print("Cannot read fdisk partition information.\n");
50965908c77Syu, larry liu - Sun Microsystems - Beijing China free(mbr);
51065908c77Syu, larry liu - Sun Microsystems - Beijing China return (-1);
51165908c77Syu, larry liu - Sun Microsystems - Beijing China }
51265908c77Syu, larry liu - Sun Microsystems - Beijing China
51365908c77Syu, larry liu - Sun Microsystems - Beijing China (void) memcpy(&boot_sec, mbr, sizeof (struct mboot));
51465908c77Syu, larry liu - Sun Microsystems - Beijing China free(mbr);
5157c478bd9Sstevel@tonic-gate
516e998e519SSheshadri Vasudevan #ifdef i386
517e998e519SSheshadri Vasudevan (void) extpart_init(&epp);
518e998e519SSheshadri Vasudevan #endif
5197c478bd9Sstevel@tonic-gate for (i = 0; i < FD_NUMPART; i++) {
5207c478bd9Sstevel@tonic-gate int ipc;
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate ipc = i * sizeof (struct ipart);
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate /* Handling the alignment problem of struct ipart */
5257c478bd9Sstevel@tonic-gate bootptr = &boot_sec.parts[ipc];
5267c478bd9Sstevel@tonic-gate (void) fill_ipart(bootptr, &ip);
5277c478bd9Sstevel@tonic-gate
528aa1b14e7SSheshadri Vasudevan #ifdef i386
529aa1b14e7SSheshadri Vasudevan if (fdisk_is_dos_extended(ip.systid) && (ext_part_found == 0)) {
530aa1b14e7SSheshadri Vasudevan /* We support only one extended partition per disk */
531aa1b14e7SSheshadri Vasudevan ext_part_found = 1;
532aa1b14e7SSheshadri Vasudevan rval = fdisk_get_solaris_part(epp, &pno, &relsec,
533aa1b14e7SSheshadri Vasudevan &numsec);
534aa1b14e7SSheshadri Vasudevan if (rval == FDISK_SUCCESS) {
535aa1b14e7SSheshadri Vasudevan /*
536aa1b14e7SSheshadri Vasudevan * Found a solaris partition inside the
537aa1b14e7SSheshadri Vasudevan * extended partition. Update the statistics.
538aa1b14e7SSheshadri Vasudevan */
539aa1b14e7SSheshadri Vasudevan if (nhead != 0 && nsect != 0) {
540aa1b14e7SSheshadri Vasudevan pcyl = numsec / (nhead * nsect);
541aa1b14e7SSheshadri Vasudevan xstart = relsec / (nhead * nsect);
542aa1b14e7SSheshadri Vasudevan ncyl = pcyl - acyl;
543aa1b14e7SSheshadri Vasudevan }
544aa1b14e7SSheshadri Vasudevan solaris_offset = relsec;
545aa1b14e7SSheshadri Vasudevan found = 2;
546aa1b14e7SSheshadri Vasudevan ip.bootid = 0;
547aa1b14e7SSheshadri Vasudevan ip.beghead = ip.begsect = ip.begcyl = 0xff;
548aa1b14e7SSheshadri Vasudevan ip.endhead = ip.endsect = ip.endcyl = 0xff;
549aa1b14e7SSheshadri Vasudevan ip.systid = SUNIXOS2;
550aa1b14e7SSheshadri Vasudevan ip.relsect = relsec;
551aa1b14e7SSheshadri Vasudevan ip.numsect = numsec;
552aa1b14e7SSheshadri Vasudevan ipart->bootid = ip.bootid;
553aa1b14e7SSheshadri Vasudevan status = bcmp(&ip, ipart,
554aa1b14e7SSheshadri Vasudevan sizeof (struct ipart));
555aa1b14e7SSheshadri Vasudevan bcopy(&ip, ipart, sizeof (struct ipart));
556aa1b14e7SSheshadri Vasudevan }
557aa1b14e7SSheshadri Vasudevan continue;
558aa1b14e7SSheshadri Vasudevan }
559aa1b14e7SSheshadri Vasudevan #endif
560aa1b14e7SSheshadri Vasudevan
5617c478bd9Sstevel@tonic-gate /*
5627c478bd9Sstevel@tonic-gate * we are interested in Solaris and EFI partition types
5637c478bd9Sstevel@tonic-gate */
564e998e519SSheshadri Vasudevan #ifdef i386
565e998e519SSheshadri Vasudevan if ((ip.systid == SUNIXOS &&
566e998e519SSheshadri Vasudevan (fdisk_is_linux_swap(epp, lel(ip.relsect), NULL) != 0)) ||
567e998e519SSheshadri Vasudevan ip.systid == SUNIXOS2 ||
568e998e519SSheshadri Vasudevan ip.systid == EFI_PMBR) {
569e998e519SSheshadri Vasudevan #else
5707c478bd9Sstevel@tonic-gate if (ip.systid == SUNIXOS ||
5717c478bd9Sstevel@tonic-gate ip.systid == SUNIXOS2 ||
5727c478bd9Sstevel@tonic-gate ip.systid == EFI_PMBR) {
573e998e519SSheshadri Vasudevan #endif
5747c478bd9Sstevel@tonic-gate /*
5757c478bd9Sstevel@tonic-gate * if the disk has an EFI label, nhead and nsect may
5767c478bd9Sstevel@tonic-gate * be zero. This test protects us from FPE's, and
5777c478bd9Sstevel@tonic-gate * format still seems to work fine
5787c478bd9Sstevel@tonic-gate */
5797c478bd9Sstevel@tonic-gate if (nhead != 0 && nsect != 0) {
5807c478bd9Sstevel@tonic-gate pcyl = lel(ip.numsect) / (nhead * nsect);
5817c478bd9Sstevel@tonic-gate xstart = lel(ip.relsect) / (nhead * nsect);
5827c478bd9Sstevel@tonic-gate ncyl = pcyl - acyl;
5837c478bd9Sstevel@tonic-gate }
5847c478bd9Sstevel@tonic-gate #ifdef DEBUG
5857c478bd9Sstevel@tonic-gate else {
5867c478bd9Sstevel@tonic-gate err_print("Critical geometry values are zero:\n"
587aa1b14e7SSheshadri Vasudevan "\tnhead = %d; nsect = %d\n", nhead, nsect);
5887c478bd9Sstevel@tonic-gate }
5897c478bd9Sstevel@tonic-gate #endif /* DEBUG */
5907c478bd9Sstevel@tonic-gate
591342440ecSPrasad Singamsetty solaris_offset = (uint_t)lel(ip.relsect);
592aa1b14e7SSheshadri Vasudevan found = 1;
5937c478bd9Sstevel@tonic-gate break;
5947c478bd9Sstevel@tonic-gate }
5957c478bd9Sstevel@tonic-gate }
5967c478bd9Sstevel@tonic-gate
597e998e519SSheshadri Vasudevan #ifdef i386
598e998e519SSheshadri Vasudevan libfdisk_fini(&epp);
599e998e519SSheshadri Vasudevan #endif
600e998e519SSheshadri Vasudevan
601aa1b14e7SSheshadri Vasudevan if (!found) {
6027c478bd9Sstevel@tonic-gate err_print("Solaris fdisk partition not found\n");
6037c478bd9Sstevel@tonic-gate return (-1);
604aa1b14e7SSheshadri Vasudevan } else if (found == 1) {
6057c478bd9Sstevel@tonic-gate /*
606aa1b14e7SSheshadri Vasudevan * Found a primary solaris partition.
6077c478bd9Sstevel@tonic-gate * compare the previous and current Solaris partition
608aa1b14e7SSheshadri Vasudevan * but don't use bootid in determination of Solaris partition
609aa1b14e7SSheshadri Vasudevan * changes
6107c478bd9Sstevel@tonic-gate */
6117c478bd9Sstevel@tonic-gate ipart->bootid = ip.bootid;
6127c478bd9Sstevel@tonic-gate status = bcmp(&ip, ipart, sizeof (struct ipart));
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate bcopy(&ip, ipart, sizeof (struct ipart));
615aa1b14e7SSheshadri Vasudevan }
6167c478bd9Sstevel@tonic-gate
6179773101cSdduvall /* if the disk partitioning has changed - get the VTOC */
6187c478bd9Sstevel@tonic-gate if (status) {
619342440ecSPrasad Singamsetty struct extvtoc exvtoc;
620342440ecSPrasad Singamsetty struct vtoc vtoc;
621342440ecSPrasad Singamsetty
622342440ecSPrasad Singamsetty status = ioctl(fd, DKIOCGEXTVTOC, &exvtoc);
6237c478bd9Sstevel@tonic-gate if (status == -1) {
6247c478bd9Sstevel@tonic-gate i = errno;
625342440ecSPrasad Singamsetty /* Try the old ioctl DKIOCGVTOC */
626342440ecSPrasad Singamsetty status = ioctl(fd, DKIOCGVTOC, &vtoc);
627342440ecSPrasad Singamsetty if (status == -1) {
628342440ecSPrasad Singamsetty err_print("Bad ioctl DKIOCGEXTVTOC.\n");
6297c478bd9Sstevel@tonic-gate err_print("errno=%d %s\n", i, strerror(i));
6307c478bd9Sstevel@tonic-gate err_print("Cannot read vtoc information.\n");
6317c478bd9Sstevel@tonic-gate return (-1);
6327c478bd9Sstevel@tonic-gate }
633342440ecSPrasad Singamsetty }
63441ebd847Syl194034
63541ebd847Syl194034 status = read_label(fd, &update_label);
63641ebd847Syl194034 if (status == -1) {
63741ebd847Syl194034 err_print("Cannot read label information.\n");
63841ebd847Syl194034 return (-1);
63941ebd847Syl194034 }
64041ebd847Syl194034
641342440ecSPrasad Singamsetty /* copy vtoc information */
642342440ecSPrasad Singamsetty cur_parts->vtoc = update_label.dkl_vtoc;
643342440ecSPrasad Singamsetty
64441ebd847Syl194034 #if defined(_SUNOS_VTOC_16)
64541ebd847Syl194034 /*
64641ebd847Syl194034 * this is to update the slice table on x86
64741ebd847Syl194034 * we don't care about VTOC8 here
64841ebd847Syl194034 */
64941ebd847Syl194034 for (i = 0; i < NDKMAP; i ++) {
65041ebd847Syl194034 cur_parts->pinfo_map[i].dkl_cylno =
65141ebd847Syl194034 update_label.dkl_vtoc.v_part[i].p_start /
65241ebd847Syl194034 ((int)(update_label.dkl_nhead *
65341ebd847Syl194034 update_label.dkl_nsect));
65441ebd847Syl194034 cur_parts->pinfo_map[i].dkl_nblk =
65541ebd847Syl194034 update_label.dkl_vtoc.v_part[i].p_size;
65641ebd847Syl194034 }
65741ebd847Syl194034 #endif /* defined(_SUNOS_VTOC_16) */
65841ebd847Syl194034
65941ebd847Syl194034 cur_dtype->dtype_ncyl = update_label.dkl_ncyl;
66041ebd847Syl194034 cur_dtype->dtype_pcyl = update_label.dkl_pcyl;
66141ebd847Syl194034 cur_dtype->dtype_acyl = update_label.dkl_acyl;
66241ebd847Syl194034 cur_dtype->dtype_nhead = update_label.dkl_nhead;
66341ebd847Syl194034 cur_dtype->dtype_nsect = update_label.dkl_nsect;
66441ebd847Syl194034 ncyl = cur_dtype->dtype_ncyl;
66541ebd847Syl194034 acyl = cur_dtype->dtype_acyl;
66641ebd847Syl194034 pcyl = cur_dtype->dtype_pcyl;
66741ebd847Syl194034 nsect = cur_dtype->dtype_nsect;
66841ebd847Syl194034 nhead = cur_dtype->dtype_nhead;
6697c478bd9Sstevel@tonic-gate }
6707c478bd9Sstevel@tonic-gate return (0);
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate int
6757c478bd9Sstevel@tonic-gate copy_solaris_part(struct ipart *ipart)
6767c478bd9Sstevel@tonic-gate {
6777c478bd9Sstevel@tonic-gate
6787c478bd9Sstevel@tonic-gate int status, i, fd;
6797c478bd9Sstevel@tonic-gate struct mboot mboot;
68065908c77Syu, larry liu - Sun Microsystems - Beijing China char *mbr;
6817c478bd9Sstevel@tonic-gate struct ipart ip;
6827c478bd9Sstevel@tonic-gate char buf[MAXPATHLEN];
6837c478bd9Sstevel@tonic-gate char *bootptr;
6847c478bd9Sstevel@tonic-gate struct stat statbuf;
685aa1b14e7SSheshadri Vasudevan #ifdef i386
686aa1b14e7SSheshadri Vasudevan uint32_t relsec, numsec;
687aa1b14e7SSheshadri Vasudevan int pno, rval, ext_part_found = 0;
688aa1b14e7SSheshadri Vasudevan ext_part_t *epp;
689aa1b14e7SSheshadri Vasudevan #endif
6907c478bd9Sstevel@tonic-gate
6917c478bd9Sstevel@tonic-gate (void) get_pname(&buf[0]);
6927c478bd9Sstevel@tonic-gate if (stat(buf, &statbuf) == -1 ||
6937c478bd9Sstevel@tonic-gate !S_ISCHR(statbuf.st_mode) ||
6947c478bd9Sstevel@tonic-gate ((cur_label == L_TYPE_EFI) &&
6957c478bd9Sstevel@tonic-gate (cur_disk->disk_flags & DSK_LABEL_DIRTY))) {
6967c478bd9Sstevel@tonic-gate /*
6977c478bd9Sstevel@tonic-gate * Make sure to reset solaris_offset to zero if it is
6987c478bd9Sstevel@tonic-gate * previously set by a selected disk that
6997c478bd9Sstevel@tonic-gate * supports the fdisk table.
7007c478bd9Sstevel@tonic-gate */
7017c478bd9Sstevel@tonic-gate solaris_offset = 0;
7027c478bd9Sstevel@tonic-gate /*
7037c478bd9Sstevel@tonic-gate * Return if this disk does not support fdisk table or
7047c478bd9Sstevel@tonic-gate * if it uses an EFI label but has not yet been labelled.
7057c478bd9Sstevel@tonic-gate * If the EFI label has not been written then the open
7067c478bd9Sstevel@tonic-gate * on the partition will fail.
7077c478bd9Sstevel@tonic-gate */
7087c478bd9Sstevel@tonic-gate return (0);
7097c478bd9Sstevel@tonic-gate }
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate if ((fd = open(buf, O_RDONLY)) < 0) {
7127c478bd9Sstevel@tonic-gate err_print("Error: can't open disk '%s'.\n", buf);
7137c478bd9Sstevel@tonic-gate return (-1);
7147c478bd9Sstevel@tonic-gate }
7157c478bd9Sstevel@tonic-gate
71665908c77Syu, larry liu - Sun Microsystems - Beijing China /*
71765908c77Syu, larry liu - Sun Microsystems - Beijing China * We may get mbr of different size, but the first 512 bytes
71865908c77Syu, larry liu - Sun Microsystems - Beijing China * are valid information.
71965908c77Syu, larry liu - Sun Microsystems - Beijing China */
72065908c77Syu, larry liu - Sun Microsystems - Beijing China mbr = malloc(cur_blksz);
72165908c77Syu, larry liu - Sun Microsystems - Beijing China if (mbr == NULL) {
72265908c77Syu, larry liu - Sun Microsystems - Beijing China err_print("No memory available.\n");
7237c478bd9Sstevel@tonic-gate return (-1);
7247c478bd9Sstevel@tonic-gate }
72565908c77Syu, larry liu - Sun Microsystems - Beijing China status = read(fd, mbr, cur_blksz);
72665908c77Syu, larry liu - Sun Microsystems - Beijing China
72765908c77Syu, larry liu - Sun Microsystems - Beijing China if (status != cur_blksz) {
72865908c77Syu, larry liu - Sun Microsystems - Beijing China err_print("Bad read of fdisk partition.\n");
72965908c77Syu, larry liu - Sun Microsystems - Beijing China (void) close(fd);
73065908c77Syu, larry liu - Sun Microsystems - Beijing China free(mbr);
73165908c77Syu, larry liu - Sun Microsystems - Beijing China return (-1);
73265908c77Syu, larry liu - Sun Microsystems - Beijing China }
73365908c77Syu, larry liu - Sun Microsystems - Beijing China
73465908c77Syu, larry liu - Sun Microsystems - Beijing China (void) memcpy(&mboot, mbr, sizeof (struct mboot));
7357c478bd9Sstevel@tonic-gate
736e998e519SSheshadri Vasudevan #ifdef i386
737e998e519SSheshadri Vasudevan (void) extpart_init(&epp);
738e998e519SSheshadri Vasudevan #endif
7397c478bd9Sstevel@tonic-gate for (i = 0; i < FD_NUMPART; i++) {
7407c478bd9Sstevel@tonic-gate int ipc;
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate ipc = i * sizeof (struct ipart);
7437c478bd9Sstevel@tonic-gate
7447c478bd9Sstevel@tonic-gate /* Handling the alignment problem of struct ipart */
7457c478bd9Sstevel@tonic-gate bootptr = &mboot.parts[ipc];
7467c478bd9Sstevel@tonic-gate (void) fill_ipart(bootptr, &ip);
7477c478bd9Sstevel@tonic-gate
748aa1b14e7SSheshadri Vasudevan #ifdef i386
749aa1b14e7SSheshadri Vasudevan if (fdisk_is_dos_extended(ip.systid) && (ext_part_found == 0)) {
750aa1b14e7SSheshadri Vasudevan /* We support only one extended partition per disk */
751aa1b14e7SSheshadri Vasudevan ext_part_found = 1;
752aa1b14e7SSheshadri Vasudevan rval = fdisk_get_solaris_part(epp, &pno, &relsec,
753aa1b14e7SSheshadri Vasudevan &numsec);
754aa1b14e7SSheshadri Vasudevan if (rval == FDISK_SUCCESS) {
755aa1b14e7SSheshadri Vasudevan /*
756aa1b14e7SSheshadri Vasudevan * Found a solaris partition inside the
757aa1b14e7SSheshadri Vasudevan * extended partition. Update the statistics.
758aa1b14e7SSheshadri Vasudevan */
759aa1b14e7SSheshadri Vasudevan if (nhead != 0 && nsect != 0) {
760aa1b14e7SSheshadri Vasudevan pcyl = numsec / (nhead * nsect);
761aa1b14e7SSheshadri Vasudevan ncyl = pcyl - acyl;
762aa1b14e7SSheshadri Vasudevan }
763aa1b14e7SSheshadri Vasudevan solaris_offset = relsec;
764aa1b14e7SSheshadri Vasudevan ip.bootid = 0;
765aa1b14e7SSheshadri Vasudevan ip.beghead = ip.begsect = ip.begcyl = 0xff;
766aa1b14e7SSheshadri Vasudevan ip.endhead = ip.endsect = ip.endcyl = 0xff;
767aa1b14e7SSheshadri Vasudevan ip.systid = SUNIXOS2;
768aa1b14e7SSheshadri Vasudevan ip.relsect = relsec;
769aa1b14e7SSheshadri Vasudevan ip.numsect = numsec;
770aa1b14e7SSheshadri Vasudevan bcopy(&ip, ipart, sizeof (struct ipart));
771aa1b14e7SSheshadri Vasudevan }
772aa1b14e7SSheshadri Vasudevan continue;
773aa1b14e7SSheshadri Vasudevan }
774aa1b14e7SSheshadri Vasudevan #endif
775aa1b14e7SSheshadri Vasudevan
776e998e519SSheshadri Vasudevan
777e998e519SSheshadri Vasudevan #ifdef i386
778e998e519SSheshadri Vasudevan if ((ip.systid == SUNIXOS &&
779e998e519SSheshadri Vasudevan (fdisk_is_linux_swap(epp, lel(ip.relsect), NULL) != 0)) ||
780e998e519SSheshadri Vasudevan ip.systid == SUNIXOS2 ||
781e998e519SSheshadri Vasudevan ip.systid == EFI_PMBR) {
782e998e519SSheshadri Vasudevan #else
7837c478bd9Sstevel@tonic-gate if (ip.systid == SUNIXOS ||
7847c478bd9Sstevel@tonic-gate ip.systid == SUNIXOS2 ||
7857c478bd9Sstevel@tonic-gate ip.systid == EFI_PMBR) {
786e998e519SSheshadri Vasudevan #endif
7877c478bd9Sstevel@tonic-gate solaris_offset = lel(ip.relsect);
7887c478bd9Sstevel@tonic-gate bcopy(&ip, ipart, sizeof (struct ipart));
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate /*
7917c478bd9Sstevel@tonic-gate * if the disk has an EFI label, we typically won't
7927c478bd9Sstevel@tonic-gate * have values for nhead and nsect. format seems to
7937c478bd9Sstevel@tonic-gate * work without them, and we need to protect ourselves
7947c478bd9Sstevel@tonic-gate * from FPE's
7957c478bd9Sstevel@tonic-gate */
7967c478bd9Sstevel@tonic-gate if (nhead != 0 && nsect != 0) {
7977c478bd9Sstevel@tonic-gate pcyl = lel(ip.numsect) / (nhead * nsect);
7987c478bd9Sstevel@tonic-gate ncyl = pcyl - acyl;
7997c478bd9Sstevel@tonic-gate }
8007c478bd9Sstevel@tonic-gate #ifdef DEBUG
8017c478bd9Sstevel@tonic-gate else {
8027c478bd9Sstevel@tonic-gate err_print("Critical geometry values are zero:\n"
803aa1b14e7SSheshadri Vasudevan "\tnhead = %d; nsect = %d\n", nhead, nsect);
8047c478bd9Sstevel@tonic-gate }
8057c478bd9Sstevel@tonic-gate #endif /* DEBUG */
8067c478bd9Sstevel@tonic-gate
8077c478bd9Sstevel@tonic-gate break;
8087c478bd9Sstevel@tonic-gate }
8097c478bd9Sstevel@tonic-gate }
810e998e519SSheshadri Vasudevan #ifdef i386
811e998e519SSheshadri Vasudevan libfdisk_fini(&epp);
812e998e519SSheshadri Vasudevan #endif
8137c478bd9Sstevel@tonic-gate
8147c478bd9Sstevel@tonic-gate (void) close(fd);
81565908c77Syu, larry liu - Sun Microsystems - Beijing China free(mbr);
8167c478bd9Sstevel@tonic-gate return (0);
8177c478bd9Sstevel@tonic-gate }
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate #if defined(_FIRMWARE_NEEDS_FDISK)
8207c478bd9Sstevel@tonic-gate int
8217c478bd9Sstevel@tonic-gate auto_solaris_part(struct dk_label *label)
8227c478bd9Sstevel@tonic-gate {
8237c478bd9Sstevel@tonic-gate
8247c478bd9Sstevel@tonic-gate int status, i, fd;
8257c478bd9Sstevel@tonic-gate struct mboot mboot;
82665908c77Syu, larry liu - Sun Microsystems - Beijing China char *mbr;
8277c478bd9Sstevel@tonic-gate struct ipart ip;
8287c478bd9Sstevel@tonic-gate char *bootptr;
8293ccda647Slclee char pbuf[MAXPATHLEN];
830aa1b14e7SSheshadri Vasudevan #ifdef i386
831aa1b14e7SSheshadri Vasudevan uint32_t relsec, numsec;
832aa1b14e7SSheshadri Vasudevan int pno, rval, ext_part_found = 0;
833aa1b14e7SSheshadri Vasudevan ext_part_t *epp;
834aa1b14e7SSheshadri Vasudevan #endif
835f85c7842SSuhasini Peddada
8360972747aSyl194034 (void) get_pname(&pbuf[0]);
8373ccda647Slclee if ((fd = open_disk(pbuf, O_RDONLY)) < 0) {
8383ccda647Slclee err_print("Error: can't open selected disk '%s'.\n", pbuf);
8397c478bd9Sstevel@tonic-gate return (-1);
8407c478bd9Sstevel@tonic-gate }
8413ccda647Slclee
84265908c77Syu, larry liu - Sun Microsystems - Beijing China /*
84365908c77Syu, larry liu - Sun Microsystems - Beijing China * We may get mbr of different size, but the first 512 bytes
84465908c77Syu, larry liu - Sun Microsystems - Beijing China * are valid information.
84565908c77Syu, larry liu - Sun Microsystems - Beijing China */
84665908c77Syu, larry liu - Sun Microsystems - Beijing China mbr = malloc(cur_blksz);
84765908c77Syu, larry liu - Sun Microsystems - Beijing China if (mbr == NULL) {
84865908c77Syu, larry liu - Sun Microsystems - Beijing China err_print("No memory available.\n");
8497c478bd9Sstevel@tonic-gate return (-1);
8507c478bd9Sstevel@tonic-gate }
85165908c77Syu, larry liu - Sun Microsystems - Beijing China status = read(fd, mbr, cur_blksz);
85265908c77Syu, larry liu - Sun Microsystems - Beijing China
85365908c77Syu, larry liu - Sun Microsystems - Beijing China if (status != cur_blksz) {
85465908c77Syu, larry liu - Sun Microsystems - Beijing China err_print("Bad read of fdisk partition.\n");
85565908c77Syu, larry liu - Sun Microsystems - Beijing China free(mbr);
85665908c77Syu, larry liu - Sun Microsystems - Beijing China return (-1);
85765908c77Syu, larry liu - Sun Microsystems - Beijing China }
85865908c77Syu, larry liu - Sun Microsystems - Beijing China
85965908c77Syu, larry liu - Sun Microsystems - Beijing China (void) memcpy(&mboot, mbr, sizeof (struct mboot));
8607c478bd9Sstevel@tonic-gate
861e998e519SSheshadri Vasudevan #ifdef i386
862e998e519SSheshadri Vasudevan (void) extpart_init(&epp);
863e998e519SSheshadri Vasudevan #endif
8647c478bd9Sstevel@tonic-gate for (i = 0; i < FD_NUMPART; i++) {
8657c478bd9Sstevel@tonic-gate int ipc;
8667c478bd9Sstevel@tonic-gate
8677c478bd9Sstevel@tonic-gate ipc = i * sizeof (struct ipart);
8687c478bd9Sstevel@tonic-gate
8697c478bd9Sstevel@tonic-gate /* Handling the alignment problem of struct ipart */
8707c478bd9Sstevel@tonic-gate bootptr = &mboot.parts[ipc];
8717c478bd9Sstevel@tonic-gate (void) fill_ipart(bootptr, &ip);
8727c478bd9Sstevel@tonic-gate
873aa1b14e7SSheshadri Vasudevan #ifdef i386
874aa1b14e7SSheshadri Vasudevan if (fdisk_is_dos_extended(ip.systid) && (ext_part_found == 0)) {
875aa1b14e7SSheshadri Vasudevan /* We support only one extended partition per disk */
876aa1b14e7SSheshadri Vasudevan ext_part_found = 1;
877aa1b14e7SSheshadri Vasudevan rval = fdisk_get_solaris_part(epp, &pno, &relsec,
878aa1b14e7SSheshadri Vasudevan &numsec);
879aa1b14e7SSheshadri Vasudevan if (rval == FDISK_SUCCESS) {
880aa1b14e7SSheshadri Vasudevan /*
881aa1b14e7SSheshadri Vasudevan * Found a solaris partition inside the
882aa1b14e7SSheshadri Vasudevan * extended partition. Update the statistics.
883aa1b14e7SSheshadri Vasudevan */
884aa1b14e7SSheshadri Vasudevan if ((label->dkl_nhead != 0) &&
885aa1b14e7SSheshadri Vasudevan (label->dkl_nsect != 0)) {
886aa1b14e7SSheshadri Vasudevan label->dkl_pcyl =
887aa1b14e7SSheshadri Vasudevan numsec / (label->dkl_nhead *
888aa1b14e7SSheshadri Vasudevan label->dkl_nsect);
889aa1b14e7SSheshadri Vasudevan label->dkl_ncyl = label->dkl_pcyl -
890aa1b14e7SSheshadri Vasudevan label->dkl_acyl;
891aa1b14e7SSheshadri Vasudevan }
892aa1b14e7SSheshadri Vasudevan solaris_offset = relsec;
893aa1b14e7SSheshadri Vasudevan }
894aa1b14e7SSheshadri Vasudevan continue;
895aa1b14e7SSheshadri Vasudevan }
896aa1b14e7SSheshadri Vasudevan #endif
897aa1b14e7SSheshadri Vasudevan
8987c478bd9Sstevel@tonic-gate /*
8997c478bd9Sstevel@tonic-gate * if the disk has an EFI label, the nhead and nsect fields
9007c478bd9Sstevel@tonic-gate * the label may be zero. This protects us from FPE's, and
9017c478bd9Sstevel@tonic-gate * format still seems to work happily
9027c478bd9Sstevel@tonic-gate */
903e998e519SSheshadri Vasudevan
904e998e519SSheshadri Vasudevan
905e998e519SSheshadri Vasudevan #ifdef i386
906e998e519SSheshadri Vasudevan if ((ip.systid == SUNIXOS &&
907e998e519SSheshadri Vasudevan (fdisk_is_linux_swap(epp, lel(ip.relsect), NULL) != 0)) ||
908e998e519SSheshadri Vasudevan ip.systid == SUNIXOS2 ||
909e998e519SSheshadri Vasudevan ip.systid == EFI_PMBR) {
910e998e519SSheshadri Vasudevan #else
9117c478bd9Sstevel@tonic-gate if (ip.systid == SUNIXOS ||
9127c478bd9Sstevel@tonic-gate ip.systid == SUNIXOS2 ||
9137c478bd9Sstevel@tonic-gate ip.systid == EFI_PMBR) {
914e998e519SSheshadri Vasudevan #endif
9157c478bd9Sstevel@tonic-gate if ((label->dkl_nhead != 0) &&
9167c478bd9Sstevel@tonic-gate (label->dkl_nsect != 0)) {
9177c478bd9Sstevel@tonic-gate label->dkl_pcyl = lel(ip.numsect) /
9187c478bd9Sstevel@tonic-gate (label->dkl_nhead * label->dkl_nsect);
9197c478bd9Sstevel@tonic-gate label->dkl_ncyl = label->dkl_pcyl -
9207c478bd9Sstevel@tonic-gate label->dkl_acyl;
9217c478bd9Sstevel@tonic-gate }
9227c478bd9Sstevel@tonic-gate #ifdef DEBUG
9237c478bd9Sstevel@tonic-gate else {
9247c478bd9Sstevel@tonic-gate err_print("Critical label fields aren't "
9257c478bd9Sstevel@tonic-gate "non-zero:\n"
9267c478bd9Sstevel@tonic-gate "\tlabel->dkl_nhead = %d; "
9277c478bd9Sstevel@tonic-gate "label->dkl_nsect = "
9287c478bd9Sstevel@tonic-gate "%d\n", label->dkl_nhead,
9297c478bd9Sstevel@tonic-gate label->dkl_nsect);
9307c478bd9Sstevel@tonic-gate }
9317c478bd9Sstevel@tonic-gate #endif /* DEBUG */
9327c478bd9Sstevel@tonic-gate
9337c478bd9Sstevel@tonic-gate solaris_offset = lel(ip.relsect);
9347c478bd9Sstevel@tonic-gate break;
9357c478bd9Sstevel@tonic-gate }
9367c478bd9Sstevel@tonic-gate }
9377c478bd9Sstevel@tonic-gate
938e998e519SSheshadri Vasudevan #ifdef i386
939e998e519SSheshadri Vasudevan libfdisk_fini(&epp);
940e998e519SSheshadri Vasudevan #endif
9417c478bd9Sstevel@tonic-gate (void) close(fd);
94265908c77Syu, larry liu - Sun Microsystems - Beijing China free(mbr);
9437c478bd9Sstevel@tonic-gate return (0);
9447c478bd9Sstevel@tonic-gate }
9457c478bd9Sstevel@tonic-gate #endif /* defined(_FIRMWARE_NEEDS_FDISK) */
9467c478bd9Sstevel@tonic-gate
9477c478bd9Sstevel@tonic-gate
9487c478bd9Sstevel@tonic-gate int
9497c478bd9Sstevel@tonic-gate good_fdisk()
9507c478bd9Sstevel@tonic-gate {
9517c478bd9Sstevel@tonic-gate char buf[MAXPATHLEN];
9527c478bd9Sstevel@tonic-gate struct stat statbuf;
9537c478bd9Sstevel@tonic-gate
9547c478bd9Sstevel@tonic-gate (void) get_pname(&buf[0]);
9557c478bd9Sstevel@tonic-gate if (stat(buf, &statbuf) == -1 ||
9567c478bd9Sstevel@tonic-gate !S_ISCHR(statbuf.st_mode) ||
9577c478bd9Sstevel@tonic-gate cur_label == L_TYPE_EFI) {
9587c478bd9Sstevel@tonic-gate /*
9597c478bd9Sstevel@tonic-gate * Return if this disk does not support fdisk table or
9607c478bd9Sstevel@tonic-gate * if the disk is labeled with EFI.
9617c478bd9Sstevel@tonic-gate */
9627c478bd9Sstevel@tonic-gate return (1);
9637c478bd9Sstevel@tonic-gate }
9647c478bd9Sstevel@tonic-gate
965cc0efcfeSqd208687 if (lel(cur_disk->fdisk_part.numsect) > 0) {
9667c478bd9Sstevel@tonic-gate return (1);
967cc0efcfeSqd208687 } else {
968cc0efcfeSqd208687 err_print("WARNING - ");
969cc0efcfeSqd208687 err_print("This disk may be in use by an application "
970cc0efcfeSqd208687 "that has\n\t modified the fdisk table. Ensure "
971cc0efcfeSqd208687 "that this disk is\n\t not currently in use "
972cc0efcfeSqd208687 "before proceeding to use fdisk.\n");
9737c478bd9Sstevel@tonic-gate return (0);
9747c478bd9Sstevel@tonic-gate }
975cc0efcfeSqd208687 }
976aa1b14e7SSheshadri Vasudevan
977aa1b14e7SSheshadri Vasudevan #ifdef i386
978aa1b14e7SSheshadri Vasudevan int
979aa1b14e7SSheshadri Vasudevan extpart_init(ext_part_t **epp)
980aa1b14e7SSheshadri Vasudevan {
981aa1b14e7SSheshadri Vasudevan int rval, lf_op_flag = 0;
982aa1b14e7SSheshadri Vasudevan char p0_path[MAXPATHLEN];
983aa1b14e7SSheshadri Vasudevan
984aa1b14e7SSheshadri Vasudevan get_pname(&p0_path[0]);
985aa1b14e7SSheshadri Vasudevan lf_op_flag |= FDISK_READ_DISK;
986aa1b14e7SSheshadri Vasudevan if ((rval = libfdisk_init(epp, p0_path, NULL, lf_op_flag)) !=
987aa1b14e7SSheshadri Vasudevan FDISK_SUCCESS) {
988aa1b14e7SSheshadri Vasudevan switch (rval) {
989aa1b14e7SSheshadri Vasudevan /*
9906cb5747bSSharath M Srinivasan * FDISK_EBADLOGDRIVE, FDISK_ENOLOGDRIVE
9916cb5747bSSharath M Srinivasan * and FDISK_EBADMAGIC can be considered
9926cb5747bSSharath M Srinivasan * as soft errors and hence we do not exit.
993aa1b14e7SSheshadri Vasudevan */
994aa1b14e7SSheshadri Vasudevan case FDISK_EBADLOGDRIVE:
995aa1b14e7SSheshadri Vasudevan break;
996aa1b14e7SSheshadri Vasudevan case FDISK_ENOLOGDRIVE:
997aa1b14e7SSheshadri Vasudevan break;
9986cb5747bSSharath M Srinivasan case FDISK_EBADMAGIC:
9996cb5747bSSharath M Srinivasan break;
1000aa1b14e7SSheshadri Vasudevan case FDISK_ENOVGEOM:
1001aa1b14e7SSheshadri Vasudevan err_print("Could not get virtual geometry for"
1002aa1b14e7SSheshadri Vasudevan " this device\n");
1003aa1b14e7SSheshadri Vasudevan fullabort();
1004aa1b14e7SSheshadri Vasudevan break;
1005aa1b14e7SSheshadri Vasudevan case FDISK_ENOPGEOM:
1006aa1b14e7SSheshadri Vasudevan err_print("Could not get physical geometry for"
1007aa1b14e7SSheshadri Vasudevan " this device\n");
1008aa1b14e7SSheshadri Vasudevan fullabort();
1009aa1b14e7SSheshadri Vasudevan break;
1010aa1b14e7SSheshadri Vasudevan case FDISK_ENOLGEOM:
1011aa1b14e7SSheshadri Vasudevan err_print("Could not get label geometry for "
1012aa1b14e7SSheshadri Vasudevan " this device\n");
1013aa1b14e7SSheshadri Vasudevan fullabort();
1014aa1b14e7SSheshadri Vasudevan break;
1015aa1b14e7SSheshadri Vasudevan default:
1016aa1b14e7SSheshadri Vasudevan err_print("Failed to initialise libfdisk.\n");
1017aa1b14e7SSheshadri Vasudevan fullabort();
1018aa1b14e7SSheshadri Vasudevan break;
1019aa1b14e7SSheshadri Vasudevan }
1020aa1b14e7SSheshadri Vasudevan }
1021aa1b14e7SSheshadri Vasudevan return (0);
1022aa1b14e7SSheshadri Vasudevan }
1023aa1b14e7SSheshadri Vasudevan #endif
1024