1995-05-04 23:36:23 +00:00
|
|
|
/*
|
|
|
|
* The new sysinstall program.
|
|
|
|
*
|
|
|
|
* This is probably the last program in the `sysinstall' line - the next
|
|
|
|
* generation being essentially a complete rewrite.
|
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-05-04 23:36:23 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* Jordan Hubbard. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
1995-05-30 08:29:07 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
* verbatim and that no modifications are made prior to this
|
1995-05-04 23:36:23 +00:00
|
|
|
* point in the file.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysinstall.h"
|
1995-05-05 23:47:47 +00:00
|
|
|
#include <ctype.h>
|
1999-01-02 07:23:37 +00:00
|
|
|
#include <fcntl.h>
|
2004-03-16 17:07:06 +00:00
|
|
|
#include <inttypes.h>
|
1999-01-02 07:23:37 +00:00
|
|
|
#include <sys/stat.h>
|
1995-05-06 09:34:24 +00:00
|
|
|
#include <sys/disklabel.h>
|
1995-05-05 23:47:47 +00:00
|
|
|
|
2002-11-27 19:57:39 +00:00
|
|
|
#ifdef WITH_SLICES
|
2003-08-19 17:51:49 +00:00
|
|
|
enum size_units_t { UNIT_BLOCKS, UNIT_KILO, UNIT_MEG, UNIT_GIG, UNIT_SIZE };
|
2000-05-26 00:38:20 +00:00
|
|
|
|
2000-06-05 13:17:23 +00:00
|
|
|
#ifdef PC98
|
|
|
|
#define SUBTYPE_FREEBSD 50324
|
|
|
|
#define SUBTYPE_FAT 37218
|
|
|
|
#else
|
|
|
|
#define SUBTYPE_FREEBSD 165
|
|
|
|
#define SUBTYPE_FAT 6
|
|
|
|
#endif
|
2002-11-15 13:18:41 +00:00
|
|
|
#define SUBTYPE_EFI 239
|
2000-06-05 13:17:23 +00:00
|
|
|
|
2002-12-05 22:10:39 +00:00
|
|
|
#ifdef PC98
|
|
|
|
#define OTHER_SLICE_VALUES \
|
|
|
|
"Other popular values are 37218 for a\n" \
|
|
|
|
"DOS FAT partition.\n\n"
|
|
|
|
#else
|
|
|
|
#define OTHER_SLICE_VALUES \
|
|
|
|
"Other popular values are 6 for a\n" \
|
|
|
|
"DOS FAT partition, 131 for a Linux ext2fs partition, or\n" \
|
|
|
|
"130 for a Linux swap partition.\n\n"
|
|
|
|
#endif
|
|
|
|
#define NON_FREEBSD_NOTE \
|
|
|
|
"Note: If you choose a non-FreeBSD partition type, it will not\n" \
|
|
|
|
"be formatted or otherwise prepared, it will simply reserve space\n" \
|
|
|
|
"for you to use another tool, such as DOS format, to later format\n" \
|
|
|
|
"and actually use the partition."
|
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
/* Where we start displaying chunk information on the screen */
|
|
|
|
#define CHUNK_START_ROW 5
|
1995-05-08 00:38:02 +00:00
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
/* Where we keep track of MBR chunks */
|
1995-12-07 10:34:59 +00:00
|
|
|
static struct chunk *chunk_info[16];
|
1995-05-05 23:47:47 +00:00
|
|
|
static int current_chunk;
|
|
|
|
|
1997-10-12 16:21:21 +00:00
|
|
|
static void diskPartitionNonInteractive(Device *dev);
|
2002-03-28 08:23:33 +00:00
|
|
|
static u_char * bootalloc(char *name, size_t *size);
|
1997-06-05 09:48:03 +00:00
|
|
|
|
1995-05-05 23:47:47 +00:00
|
|
|
static void
|
1995-05-16 02:53:31 +00:00
|
|
|
record_chunks(Disk *d)
|
1995-05-05 23:47:47 +00:00
|
|
|
{
|
1996-10-03 06:01:44 +00:00
|
|
|
struct chunk *c1 = NULL;
|
1995-05-16 02:53:31 +00:00
|
|
|
int i = 0;
|
2004-03-16 17:07:06 +00:00
|
|
|
daddr_t last_free = 0;
|
1996-10-03 06:01:44 +00:00
|
|
|
|
1995-05-16 02:53:31 +00:00
|
|
|
if (!d->chunks)
|
|
|
|
msgFatal("No chunk list found for %s!", d->name);
|
1996-10-03 06:01:44 +00:00
|
|
|
|
1995-12-07 10:34:59 +00:00
|
|
|
for (c1 = d->chunks->part; c1; c1 = c1->next) {
|
1995-05-16 02:53:31 +00:00
|
|
|
if (c1->type == unused && c1->size > last_free) {
|
|
|
|
last_free = c1->size;
|
|
|
|
current_chunk = i;
|
1995-05-05 23:47:47 +00:00
|
|
|
}
|
1995-05-16 02:53:31 +00:00
|
|
|
chunk_info[i++] = c1;
|
1995-05-05 23:47:47 +00:00
|
|
|
}
|
1995-05-16 02:53:31 +00:00
|
|
|
chunk_info[i] = NULL;
|
1996-10-06 11:40:31 +00:00
|
|
|
if (current_chunk >= i)
|
|
|
|
current_chunk = i - 1;
|
1995-05-07 23:37:34 +00:00
|
|
|
}
|
|
|
|
|
2004-03-16 17:07:06 +00:00
|
|
|
static daddr_t Total;
|
1996-10-06 11:40:31 +00:00
|
|
|
|
1995-05-05 23:47:47 +00:00
|
|
|
static void
|
2000-05-26 00:38:20 +00:00
|
|
|
print_chunks(Disk *d, int u)
|
1995-05-05 23:47:47 +00:00
|
|
|
{
|
1995-05-16 02:53:31 +00:00
|
|
|
int row;
|
1996-10-06 11:40:31 +00:00
|
|
|
int i;
|
2004-03-16 17:07:06 +00:00
|
|
|
daddr_t sz;
|
2000-05-26 00:38:20 +00:00
|
|
|
char *szstr;
|
|
|
|
|
2003-08-19 17:51:49 +00:00
|
|
|
szstr = (u == UNIT_GIG ? "GB" : (u == UNIT_MEG ? "MB" :
|
|
|
|
(u == UNIT_KILO ? "KB" : "ST")));
|
1995-05-05 23:47:47 +00:00
|
|
|
|
2004-03-16 17:07:06 +00:00
|
|
|
Total = 0;
|
|
|
|
for (i = 0; chunk_info[i]; i++)
|
1996-10-06 11:40:31 +00:00
|
|
|
Total += chunk_info[i]->size;
|
2002-10-14 13:15:14 +00:00
|
|
|
#ifdef PC98
|
|
|
|
if (d->bios_cyl >= 65536 || d->bios_hd > 16 || d->bios_sect >= 256) {
|
|
|
|
#else
|
1996-11-27 22:52:34 +00:00
|
|
|
if (d->bios_cyl > 65536 || d->bios_hd > 256 || d->bios_sect >= 64) {
|
2002-10-14 13:15:14 +00:00
|
|
|
#endif
|
1996-08-03 10:11:56 +00:00
|
|
|
dialog_clear_norefresh();
|
2001-09-22 23:17:37 +00:00
|
|
|
msgConfirm("WARNING: A geometry of %lu/%lu/%lu for %s is incorrect. Using\n"
|
1996-11-27 22:52:34 +00:00
|
|
|
"a more likely geometry. If this geometry is incorrect or you\n"
|
|
|
|
"are unsure as to whether or not it's correct, please consult\n"
|
|
|
|
"the Hardware Guide in the Documentation submenu or use the\n"
|
1997-03-11 16:27:25 +00:00
|
|
|
"(G)eometry command to change it now.\n\n"
|
|
|
|
"Remember: you need to enter whatever your BIOS thinks the\n"
|
1997-04-20 16:46:36 +00:00
|
|
|
"geometry is! For IDE, it's what you were told in the BIOS\n"
|
|
|
|
"setup. For SCSI, it's the translation mode your controller is\n"
|
1997-03-11 16:27:25 +00:00
|
|
|
"using. Do NOT use a ``physical geometry''.",
|
1996-11-27 22:52:34 +00:00
|
|
|
d->bios_cyl, d->bios_hd, d->bios_sect, d->name);
|
|
|
|
Sanitize_Bios_Geom(d);
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
1995-05-05 23:47:47 +00:00
|
|
|
attrset(A_NORMAL);
|
1995-05-16 02:53:31 +00:00
|
|
|
mvaddstr(0, 0, "Disk name:\t");
|
1995-05-21 04:34:12 +00:00
|
|
|
clrtobot();
|
1995-05-16 02:53:31 +00:00
|
|
|
attrset(A_REVERSE); addstr(d->name); attrset(A_NORMAL);
|
1995-06-11 19:33:05 +00:00
|
|
|
attrset(A_REVERSE); mvaddstr(0, 55, "FDISK Partition Editor"); attrset(A_NORMAL);
|
1995-05-16 02:53:31 +00:00
|
|
|
mvprintw(1, 0,
|
2004-03-16 17:07:06 +00:00
|
|
|
"DISK Geometry:\t%lu cyls/%lu heads/%lu sectors = %jd sectors (%jdMB)",
|
1996-11-27 22:52:34 +00:00
|
|
|
d->bios_cyl, d->bios_hd, d->bios_sect,
|
2004-03-16 17:07:06 +00:00
|
|
|
(intmax_t)d->bios_cyl * d->bios_hd * d->bios_sect,
|
|
|
|
(intmax_t)d->bios_cyl * d->bios_hd * d->bios_sect / (1024/512) / 1024);
|
2000-05-26 00:38:20 +00:00
|
|
|
mvprintw(3, 0, "%6s %10s(%s) %10s %8s %6s %10s %8s %8s",
|
|
|
|
"Offset", "Size", szstr, "End", "Name", "PType", "Desc",
|
1995-05-16 02:53:31 +00:00
|
|
|
"Subtype", "Flags");
|
|
|
|
for (i = 0, row = CHUNK_START_ROW; chunk_info[i]; i++, row++) {
|
2000-05-26 00:38:20 +00:00
|
|
|
switch(u) {
|
|
|
|
default: /* fall thru */
|
|
|
|
case UNIT_BLOCKS:
|
|
|
|
sz = chunk_info[i]->size;
|
|
|
|
break;
|
|
|
|
case UNIT_KILO:
|
2002-05-31 17:03:01 +00:00
|
|
|
sz = chunk_info[i]->size / (1024/512);
|
2000-05-26 00:38:20 +00:00
|
|
|
break;
|
|
|
|
case UNIT_MEG:
|
2002-05-31 17:03:01 +00:00
|
|
|
sz = chunk_info[i]->size / (1024/512) / 1024;
|
2000-05-26 00:38:20 +00:00
|
|
|
break;
|
2003-08-19 17:51:49 +00:00
|
|
|
case UNIT_GIG:
|
|
|
|
sz = chunk_info[i]->size / (1024/512) / 1024 / 1024;
|
|
|
|
break;
|
2000-05-26 00:38:20 +00:00
|
|
|
}
|
1995-05-05 23:47:47 +00:00
|
|
|
if (i == current_chunk)
|
1996-06-08 09:08:51 +00:00
|
|
|
attrset(ATTR_SELECTED);
|
2004-03-16 17:07:06 +00:00
|
|
|
mvprintw(row, 0, "%10jd %10jd %10jd %8s %6d %10s %8d\t%-6s",
|
|
|
|
(intmax_t)chunk_info[i]->offset, (intmax_t)sz,
|
|
|
|
(intmax_t)chunk_info[i]->end, chunk_info[i]->name,
|
1997-01-24 02:26:42 +00:00
|
|
|
chunk_info[i]->type,
|
|
|
|
slice_type_name(chunk_info[i]->type, chunk_info[i]->subtype),
|
1995-06-11 19:33:05 +00:00
|
|
|
chunk_info[i]->subtype, ShowChunkFlags(chunk_info[i]));
|
1995-05-05 23:47:47 +00:00
|
|
|
if (i == current_chunk)
|
|
|
|
attrset(A_NORMAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_command_summary()
|
|
|
|
{
|
1995-05-16 02:53:31 +00:00
|
|
|
mvprintw(14, 0, "The following commands are supported (in upper or lower case):");
|
2001-04-18 20:26:28 +00:00
|
|
|
mvprintw(16, 0, "A = Use Entire Disk G = set Drive Geometry C = Create Slice F = `DD' mode");
|
|
|
|
mvprintw(17, 0, "D = Delete Slice Z = Toggle Size Units S = Set Bootable | = Wizard m.");
|
|
|
|
mvprintw(18, 0, "T = Change Type U = Undo All Changes Q = Finish");
|
1996-03-18 15:28:10 +00:00
|
|
|
if (!RunningAsInit)
|
2001-04-18 20:26:28 +00:00
|
|
|
mvprintw(18, 47, "W = Write Changes");
|
1996-05-09 09:42:17 +00:00
|
|
|
mvprintw(21, 0, "Use F1 or ? to get more help, arrow keys to select.");
|
1995-05-05 23:47:47 +00:00
|
|
|
move(0, 0);
|
|
|
|
}
|
|
|
|
|
2000-08-12 14:20:31 +00:00
|
|
|
#ifdef PC98
|
|
|
|
static void
|
|
|
|
getBootMgr(char *dname, u_char **bootipl, size_t *bootipl_size,
|
|
|
|
u_char **bootmenu, size_t *bootmenu_size)
|
|
|
|
{
|
2002-03-28 08:23:33 +00:00
|
|
|
static u_char *boot0;
|
|
|
|
static size_t boot0_size;
|
|
|
|
static u_char *boot05;
|
|
|
|
static size_t boot05_size;
|
2000-08-12 14:20:31 +00:00
|
|
|
|
|
|
|
char str[80];
|
|
|
|
char *cp;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
cp = variable_get(VAR_BOOTMGR);
|
|
|
|
if (!cp) {
|
2002-11-03 10:06:22 +00:00
|
|
|
/* Figure out what kind of IPL the user wants */
|
2000-08-12 14:20:31 +00:00
|
|
|
sprintf(str, "Install Boot Manager for drive %s?", dname);
|
2002-11-03 10:06:22 +00:00
|
|
|
MenuIPLType.title = str;
|
|
|
|
i = dmenuOpenSimple(&MenuIPLType, FALSE);
|
2000-08-12 14:20:31 +00:00
|
|
|
} else {
|
|
|
|
if (!strncmp(cp, "boot", 4))
|
|
|
|
BootMgr = 0;
|
|
|
|
else
|
2002-11-03 10:06:22 +00:00
|
|
|
BootMgr = 1;
|
2000-08-12 14:20:31 +00:00
|
|
|
}
|
|
|
|
if (cp || i) {
|
|
|
|
switch (BootMgr) {
|
|
|
|
case 0:
|
2002-03-28 08:23:33 +00:00
|
|
|
if (!boot0) boot0 = bootalloc("boot0", &boot0_size);
|
2000-08-12 14:20:31 +00:00
|
|
|
*bootipl = boot0;
|
|
|
|
*bootipl_size = boot0_size;
|
2002-03-28 08:23:33 +00:00
|
|
|
if (!boot05) boot05 = bootalloc("boot0.5", &boot05_size);
|
2000-08-12 14:20:31 +00:00
|
|
|
*bootmenu = boot05;
|
|
|
|
*bootmenu_size = boot05_size;
|
|
|
|
return;
|
2002-11-03 10:06:22 +00:00
|
|
|
case 1:
|
2000-08-12 14:20:31 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*bootipl = NULL;
|
|
|
|
*bootipl_size = 0;
|
|
|
|
*bootmenu = NULL;
|
|
|
|
*bootmenu_size = 0;
|
|
|
|
}
|
|
|
|
#else
|
2000-07-12 18:08:27 +00:00
|
|
|
static void
|
|
|
|
getBootMgr(char *dname, u_char **bootCode, size_t *bootCodeSize)
|
1995-12-07 10:34:59 +00:00
|
|
|
{
|
2003-05-24 21:12:14 +00:00
|
|
|
#if defined(__i386__) || defined(__amd64__) /* only meaningful on x86 */
|
2002-03-28 08:23:33 +00:00
|
|
|
static u_char *mbr, *boot0;
|
|
|
|
static size_t mbr_size, boot0_size;
|
1995-12-07 10:34:59 +00:00
|
|
|
char str[80];
|
|
|
|
char *cp;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
cp = variable_get(VAR_BOOTMGR);
|
|
|
|
if (!cp) {
|
|
|
|
/* Figure out what kind of MBR the user wants */
|
|
|
|
sprintf(str, "Install Boot Manager for drive %s?", dname);
|
|
|
|
MenuMBRType.title = str;
|
1996-07-02 01:03:55 +00:00
|
|
|
i = dmenuOpenSimple(&MenuMBRType, FALSE);
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!strncmp(cp, "boot", 4))
|
|
|
|
BootMgr = 0;
|
|
|
|
else if (!strcmp(cp, "standard"))
|
|
|
|
BootMgr = 1;
|
|
|
|
else
|
|
|
|
BootMgr = 2;
|
|
|
|
}
|
|
|
|
if (cp || i) {
|
|
|
|
switch (BootMgr) {
|
|
|
|
case 0:
|
2002-03-28 08:23:33 +00:00
|
|
|
if (!boot0) boot0 = bootalloc("boot0", &boot0_size);
|
2000-07-12 18:08:27 +00:00
|
|
|
*bootCode = boot0;
|
|
|
|
*bootCodeSize = boot0_size;
|
|
|
|
return;
|
1995-12-07 10:34:59 +00:00
|
|
|
case 1:
|
2002-03-28 08:23:33 +00:00
|
|
|
if (!mbr) mbr = bootalloc("mbr", &mbr_size);
|
2000-07-12 18:08:27 +00:00
|
|
|
*bootCode = mbr;
|
|
|
|
*bootCodeSize = mbr_size;
|
|
|
|
return;
|
1995-12-07 10:34:59 +00:00
|
|
|
case 2:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-09-30 21:58:36 +00:00
|
|
|
#endif
|
2000-07-12 18:08:27 +00:00
|
|
|
*bootCode = NULL;
|
|
|
|
*bootCodeSize = 0;
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
2000-06-05 13:17:23 +00:00
|
|
|
#endif
|
2002-11-27 19:57:39 +00:00
|
|
|
#endif /* WITH_SLICES */
|
1995-12-07 10:34:59 +00:00
|
|
|
|
1997-10-12 16:21:21 +00:00
|
|
|
int
|
|
|
|
diskGetSelectCount(Device ***devs)
|
|
|
|
{
|
|
|
|
int i, cnt, enabled;
|
|
|
|
char *cp;
|
|
|
|
Device **dp;
|
|
|
|
|
|
|
|
cp = variable_get(VAR_DISK);
|
|
|
|
dp = *devs = deviceFind(cp, DEVICE_TYPE_DISK);
|
|
|
|
cnt = deviceCount(dp);
|
|
|
|
if (!cnt)
|
|
|
|
return -1;
|
|
|
|
for (i = 0, enabled = 0; i < cnt; i++) {
|
|
|
|
if (dp[i]->enabled)
|
|
|
|
++enabled;
|
|
|
|
}
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
2002-11-27 19:57:39 +00:00
|
|
|
#ifdef WITH_SLICES
|
1995-12-07 10:34:59 +00:00
|
|
|
void
|
1997-10-12 16:21:21 +00:00
|
|
|
diskPartition(Device *dev)
|
1995-05-04 23:36:23 +00:00
|
|
|
{
|
1996-10-06 11:40:31 +00:00
|
|
|
char *cp, *p;
|
1996-10-03 06:01:44 +00:00
|
|
|
int rv, key = 0;
|
1995-05-16 02:53:31 +00:00
|
|
|
Boolean chunking;
|
1995-05-05 23:47:47 +00:00
|
|
|
char *msg = NULL;
|
2000-08-12 14:20:31 +00:00
|
|
|
#ifdef PC98
|
|
|
|
u_char *bootipl;
|
|
|
|
size_t bootipl_size;
|
|
|
|
u_char *bootmenu;
|
|
|
|
size_t bootmenu_size;
|
|
|
|
#else
|
1995-12-07 10:34:59 +00:00
|
|
|
u_char *mbrContents;
|
2000-07-12 18:08:27 +00:00
|
|
|
size_t mbrSize;
|
2000-06-05 13:17:23 +00:00
|
|
|
#endif
|
1996-10-03 06:01:44 +00:00
|
|
|
WINDOW *w = savescr();
|
1997-10-12 16:21:21 +00:00
|
|
|
Disk *d = (Disk *)dev->private;
|
2000-05-26 00:38:20 +00:00
|
|
|
int size_unit;
|
1995-05-05 23:47:47 +00:00
|
|
|
|
2000-05-26 00:38:20 +00:00
|
|
|
size_unit = UNIT_BLOCKS;
|
1995-05-16 02:53:31 +00:00
|
|
|
chunking = TRUE;
|
1995-05-05 23:47:47 +00:00
|
|
|
keypad(stdscr, TRUE);
|
|
|
|
|
1996-10-03 06:01:44 +00:00
|
|
|
/* Flush both the dialog and curses library views of the screen
|
|
|
|
since we don't always know who called us */
|
|
|
|
dialog_clear_norefresh(), clear();
|
1996-11-07 16:40:10 +00:00
|
|
|
current_chunk = 0;
|
1996-10-03 06:01:44 +00:00
|
|
|
|
1996-10-04 13:33:49 +00:00
|
|
|
/* Set up the chunk array */
|
|
|
|
record_chunks(d);
|
1996-10-03 06:01:44 +00:00
|
|
|
|
1996-10-04 13:33:49 +00:00
|
|
|
while (chunking) {
|
1996-10-06 11:40:31 +00:00
|
|
|
char *val, geometry[80];
|
|
|
|
|
1996-10-03 06:01:44 +00:00
|
|
|
/* Now print our overall state */
|
1997-01-16 14:42:21 +00:00
|
|
|
if (d)
|
2000-05-26 00:38:20 +00:00
|
|
|
print_chunks(d, size_unit);
|
1995-05-05 23:47:47 +00:00
|
|
|
print_command_summary();
|
|
|
|
if (msg) {
|
1996-05-09 09:42:17 +00:00
|
|
|
attrset(title_attr); mvprintw(23, 0, msg); attrset(A_NORMAL);
|
1995-05-05 23:47:47 +00:00
|
|
|
beep();
|
|
|
|
msg = NULL;
|
|
|
|
}
|
1996-10-03 06:01:44 +00:00
|
|
|
else {
|
|
|
|
move(23, 0);
|
|
|
|
clrtoeol();
|
|
|
|
}
|
1995-05-16 02:53:31 +00:00
|
|
|
|
1996-10-03 06:01:44 +00:00
|
|
|
/* Get command character */
|
1996-08-03 05:29:24 +00:00
|
|
|
key = getch();
|
|
|
|
switch (toupper(key)) {
|
1996-10-06 11:40:31 +00:00
|
|
|
case '\014': /* ^L (redraw) */
|
1995-05-25 18:48:33 +00:00
|
|
|
clear();
|
1996-10-03 06:01:44 +00:00
|
|
|
msg = NULL;
|
|
|
|
break;
|
1996-10-06 11:40:31 +00:00
|
|
|
|
1997-01-15 02:52:00 +00:00
|
|
|
case '\020': /* ^P */
|
1995-05-05 23:47:47 +00:00
|
|
|
case KEY_UP:
|
|
|
|
case '-':
|
|
|
|
if (current_chunk != 0)
|
|
|
|
--current_chunk;
|
|
|
|
break;
|
1996-10-06 11:40:31 +00:00
|
|
|
|
1997-01-15 02:52:00 +00:00
|
|
|
case '\016': /* ^N */
|
1995-05-05 23:47:47 +00:00
|
|
|
case KEY_DOWN:
|
|
|
|
case '+':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
1995-05-16 02:53:31 +00:00
|
|
|
if (chunk_info[current_chunk + 1])
|
1995-05-05 23:47:47 +00:00
|
|
|
++current_chunk;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_HOME:
|
|
|
|
current_chunk = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_END:
|
1995-05-16 02:53:31 +00:00
|
|
|
while (chunk_info[current_chunk + 1])
|
1995-05-05 23:47:47 +00:00
|
|
|
++current_chunk;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_F(1):
|
|
|
|
case '?':
|
1995-12-07 10:34:59 +00:00
|
|
|
systemDisplayHelp("slice");
|
1996-10-01 04:56:34 +00:00
|
|
|
clear();
|
1995-05-16 02:53:31 +00:00
|
|
|
break;
|
|
|
|
|
1996-10-03 06:01:44 +00:00
|
|
|
case 'A':
|
2001-01-15 08:15:19 +00:00
|
|
|
case 'F': /* Undocumented magic Dangerously Dedicated mode */
|
2003-06-04 19:28:39 +00:00
|
|
|
#if !defined(__i386__) && !defined(__amd64__) && !defined(__ia64__)
|
1998-09-30 21:48:11 +00:00
|
|
|
rv = 1;
|
|
|
|
#else /* The rest is only relevant on x86 */
|
1997-05-05 05:16:03 +00:00
|
|
|
cp = variable_get(VAR_DEDICATE_DISK);
|
1997-05-10 17:11:24 +00:00
|
|
|
if (cp && !strcasecmp(cp, "always"))
|
1997-05-05 05:16:03 +00:00
|
|
|
rv = 1;
|
2001-01-15 08:15:19 +00:00
|
|
|
else if (toupper(key) == 'A')
|
2001-01-15 05:29:53 +00:00
|
|
|
rv = 0;
|
2001-01-15 08:15:19 +00:00
|
|
|
else {
|
|
|
|
rv = msgYesNo("Do you want to do this with a true partition entry\n"
|
|
|
|
"so as to remain cooperative with any future possible\n"
|
|
|
|
"operating systems on the drive(s)?\n"
|
|
|
|
"(See also the section about ``dangerously dedicated''\n"
|
|
|
|
"disks in the FreeBSD FAQ.)");
|
|
|
|
if (rv == -1)
|
|
|
|
rv = 0;
|
|
|
|
}
|
1998-09-30 21:48:11 +00:00
|
|
|
#endif
|
1995-12-07 10:34:59 +00:00
|
|
|
All_FreeBSD(d, rv);
|
1999-02-05 22:15:52 +00:00
|
|
|
variable_set2(DISK_PARTITIONED, "yes", 0);
|
1996-10-04 13:33:49 +00:00
|
|
|
record_chunks(d);
|
1996-10-03 06:01:44 +00:00
|
|
|
clear();
|
|
|
|
break;
|
1996-10-06 11:40:31 +00:00
|
|
|
|
1995-05-05 23:47:47 +00:00
|
|
|
case 'C':
|
1995-05-16 02:53:31 +00:00
|
|
|
if (chunk_info[current_chunk]->type != unused)
|
1997-01-24 07:47:17 +00:00
|
|
|
msg = "Slice in use, delete it first or move to an unused one.";
|
1995-05-05 23:47:47 +00:00
|
|
|
else {
|
2002-11-16 16:36:01 +00:00
|
|
|
char *val, tmp[20], name[16], *cp;
|
2004-03-16 17:07:06 +00:00
|
|
|
daddr_t size;
|
|
|
|
int subtype;
|
2002-11-16 16:36:01 +00:00
|
|
|
chunk_e partitiontype;
|
2000-06-05 13:17:23 +00:00
|
|
|
#ifdef PC98
|
2002-11-16 16:36:01 +00:00
|
|
|
snprintf(name, sizeof (name), "%s", "FreeBSD");
|
2000-06-05 13:17:23 +00:00
|
|
|
val = msgGetInput(name,
|
|
|
|
"Please specify the name for new FreeBSD slice.");
|
|
|
|
if (val)
|
2002-11-16 16:36:01 +00:00
|
|
|
strncpy(name, val, sizeof (name));
|
2000-06-05 13:17:23 +00:00
|
|
|
#else
|
2002-11-16 16:36:01 +00:00
|
|
|
name[0] = '\0';
|
2000-06-05 13:17:23 +00:00
|
|
|
#endif
|
2004-03-16 17:07:06 +00:00
|
|
|
snprintf(tmp, 20, "%jd", (intmax_t)chunk_info[current_chunk]->size);
|
1997-01-24 07:47:17 +00:00
|
|
|
val = msgGetInput(tmp, "Please specify the size for new FreeBSD slice in blocks\n"
|
1996-10-06 11:40:31 +00:00
|
|
|
"or append a trailing `M' for megabytes (e.g. 20M).");
|
2004-03-16 17:07:06 +00:00
|
|
|
if (val && (size = strtoimax(val, &cp, 0)) > 0) {
|
1995-05-16 11:37:27 +00:00
|
|
|
if (*cp && toupper(*cp) == 'M')
|
1995-12-07 10:34:59 +00:00
|
|
|
size *= ONE_MEG;
|
2000-02-29 10:40:59 +00:00
|
|
|
else if (*cp && toupper(*cp) == 'G')
|
|
|
|
size *= ONE_GIG;
|
2002-11-16 16:36:01 +00:00
|
|
|
sprintf(tmp, "%d", SUBTYPE_FREEBSD);
|
|
|
|
val = msgGetInput(tmp, "Enter type of partition to create:\n\n"
|
2002-12-05 22:10:39 +00:00
|
|
|
"Pressing Enter will choose the default, a native FreeBSD\n"
|
|
|
|
"slice (type %u). "
|
|
|
|
OTHER_SLICE_VALUES
|
|
|
|
NON_FREEBSD_NOTE, SUBTYPE_FREEBSD);
|
1996-06-08 08:01:52 +00:00
|
|
|
if (val && (subtype = strtol(val, NULL, 0)) > 0) {
|
2000-06-05 13:17:23 +00:00
|
|
|
if (subtype == SUBTYPE_FREEBSD)
|
1997-09-11 17:12:08 +00:00
|
|
|
partitiontype = freebsd;
|
2000-06-05 13:17:23 +00:00
|
|
|
else if (subtype == SUBTYPE_FAT)
|
1997-09-11 17:12:08 +00:00
|
|
|
partitiontype = fat;
|
2002-11-10 20:56:53 +00:00
|
|
|
else if (subtype == SUBTYPE_EFI)
|
|
|
|
partitiontype = efi;
|
1996-06-08 08:01:52 +00:00
|
|
|
else
|
2002-12-04 15:07:05 +00:00
|
|
|
#ifdef PC98
|
|
|
|
partitiontype = pc98;
|
|
|
|
#else
|
2002-12-03 16:09:55 +00:00
|
|
|
partitiontype = mbr;
|
2002-12-04 15:07:05 +00:00
|
|
|
#endif
|
1996-10-06 11:40:31 +00:00
|
|
|
Create_Chunk(d, chunk_info[current_chunk]->offset, size, partitiontype, subtype,
|
2002-11-16 16:36:01 +00:00
|
|
|
(chunk_info[current_chunk]->flags & CHUNK_ALIGN), name);
|
1999-02-05 22:15:52 +00:00
|
|
|
variable_set2(DISK_PARTITIONED, "yes", 0);
|
1996-10-06 11:40:31 +00:00
|
|
|
record_chunks(d);
|
1996-06-08 08:01:52 +00:00
|
|
|
}
|
1995-05-05 23:47:47 +00:00
|
|
|
}
|
1996-10-03 06:01:44 +00:00
|
|
|
clear();
|
1995-05-05 23:47:47 +00:00
|
|
|
}
|
|
|
|
break;
|
1996-10-06 11:40:31 +00:00
|
|
|
|
1996-08-03 05:29:24 +00:00
|
|
|
case KEY_DC:
|
1995-05-16 02:53:31 +00:00
|
|
|
case 'D':
|
|
|
|
if (chunk_info[current_chunk]->type == unused)
|
1997-01-24 07:47:17 +00:00
|
|
|
msg = "Slice is already unused!";
|
1995-05-16 02:53:31 +00:00
|
|
|
else {
|
|
|
|
Delete_Chunk(d, chunk_info[current_chunk]);
|
1999-02-05 22:15:52 +00:00
|
|
|
variable_set2(DISK_PARTITIONED, "yes", 0);
|
1996-10-04 13:33:49 +00:00
|
|
|
record_chunks(d);
|
1995-05-06 09:34:24 +00:00
|
|
|
}
|
|
|
|
break;
|
1996-10-06 11:40:31 +00:00
|
|
|
|
1997-09-11 17:12:08 +00:00
|
|
|
case 'T':
|
|
|
|
if (chunk_info[current_chunk]->type == unused)
|
|
|
|
msg = "Slice is currently unused (use create instead)";
|
|
|
|
else {
|
|
|
|
char *val, tmp[20];
|
|
|
|
int subtype;
|
|
|
|
chunk_e partitiontype;
|
|
|
|
|
2002-12-05 22:10:39 +00:00
|
|
|
sprintf(tmp, "%d", chunk_info[current_chunk]->subtype);
|
1997-09-11 17:12:08 +00:00
|
|
|
val = msgGetInput(tmp, "New partition type:\n\n"
|
2002-12-05 22:10:39 +00:00
|
|
|
"Pressing Enter will use the current type. To choose a native\n"
|
|
|
|
"FreeBSD slice enter %u. "
|
|
|
|
OTHER_SLICE_VALUES
|
|
|
|
NON_FREEBSD_NOTE, SUBTYPE_FREEBSD);
|
1997-09-11 17:12:08 +00:00
|
|
|
if (val && (subtype = strtol(val, NULL, 0)) > 0) {
|
2000-06-05 13:17:23 +00:00
|
|
|
if (subtype == SUBTYPE_FREEBSD)
|
1997-09-11 17:12:08 +00:00
|
|
|
partitiontype = freebsd;
|
2000-06-05 13:17:23 +00:00
|
|
|
else if (subtype == SUBTYPE_FAT)
|
1997-09-11 17:12:08 +00:00
|
|
|
partitiontype = fat;
|
2002-11-13 05:39:59 +00:00
|
|
|
else if (subtype == SUBTYPE_EFI)
|
|
|
|
partitiontype = efi;
|
1997-09-11 17:12:08 +00:00
|
|
|
else
|
2002-12-04 15:07:05 +00:00
|
|
|
#ifdef PC98
|
|
|
|
partitiontype = pc98;
|
|
|
|
#else
|
2002-12-03 16:09:55 +00:00
|
|
|
partitiontype = mbr;
|
2002-12-04 15:07:05 +00:00
|
|
|
#endif
|
1997-09-11 17:12:08 +00:00
|
|
|
chunk_info[current_chunk]->type = partitiontype;
|
|
|
|
chunk_info[current_chunk]->subtype = subtype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1996-10-06 11:40:31 +00:00
|
|
|
case 'G':
|
1995-09-18 16:53:06 +00:00
|
|
|
snprintf(geometry, 80, "%lu/%lu/%lu", d->bios_cyl, d->bios_hd, d->bios_sect);
|
1995-12-07 10:34:59 +00:00
|
|
|
val = msgGetInput(geometry, "Please specify the new geometry in cyl/hd/sect format.\n"
|
|
|
|
"Don't forget to use the two slash (/) separator characters!\n"
|
|
|
|
"It's not possible to parse the field without them.");
|
1995-05-16 02:53:31 +00:00
|
|
|
if (val) {
|
1996-11-27 22:52:34 +00:00
|
|
|
long nc, nh, ns;
|
|
|
|
nc = strtol(val, &val, 0);
|
|
|
|
nh = strtol(val + 1, &val, 0);
|
|
|
|
ns = strtol(val + 1, 0, 0);
|
|
|
|
Set_Bios_Geom(d, nc, nh, ns);
|
1995-05-07 05:58:57 +00:00
|
|
|
}
|
1996-10-01 04:56:34 +00:00
|
|
|
clear();
|
1996-10-06 11:40:31 +00:00
|
|
|
break;
|
1995-12-07 10:34:59 +00:00
|
|
|
|
1996-10-06 11:40:31 +00:00
|
|
|
case 'S':
|
|
|
|
/* Set Bootable */
|
|
|
|
chunk_info[current_chunk]->flags |= CHUNK_ACTIVE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'U':
|
2001-03-12 10:18:54 +00:00
|
|
|
if (!variable_cmp(DISK_LABELLED, "written")) {
|
1996-10-06 11:40:31 +00:00
|
|
|
msgConfirm("You've already written this information out - you\n"
|
|
|
|
"can't undo it.");
|
1996-10-01 04:56:34 +00:00
|
|
|
}
|
2000-12-14 02:49:02 +00:00
|
|
|
else if (!msgNoYes("Are you SURE you want to Undo everything?")) {
|
1997-01-16 14:42:21 +00:00
|
|
|
char cp[BUFSIZ];
|
|
|
|
|
|
|
|
sstrncpy(cp, d->name, sizeof cp);
|
1996-10-06 11:40:31 +00:00
|
|
|
Free_Disk(dev->private);
|
1997-01-16 14:42:21 +00:00
|
|
|
d = Open_Disk(cp);
|
|
|
|
if (!d)
|
|
|
|
msgConfirm("Can't reopen disk %s! Internal state is probably corrupted", cp);
|
1996-10-06 11:40:31 +00:00
|
|
|
dev->private = d;
|
|
|
|
variable_unset(DISK_PARTITIONED);
|
|
|
|
variable_unset(DISK_LABELLED);
|
1997-01-16 14:42:21 +00:00
|
|
|
if (d)
|
|
|
|
record_chunks(d);
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
1996-10-01 04:56:34 +00:00
|
|
|
clear();
|
1995-05-07 23:37:34 +00:00
|
|
|
break;
|
|
|
|
|
1995-05-08 00:56:28 +00:00
|
|
|
case 'W':
|
2000-12-14 02:49:02 +00:00
|
|
|
if (!msgNoYes("WARNING: This should only be used when modifying an EXISTING\n"
|
1996-10-06 11:40:31 +00:00
|
|
|
"installation. If you are installing FreeBSD for the first time\n"
|
|
|
|
"then you should simply type Q when you're finished here and your\n"
|
|
|
|
"changes will be committed in one batch automatically at the end of\n"
|
1997-10-12 16:21:21 +00:00
|
|
|
"these questions. If you're adding a disk, you should NOT write\n"
|
|
|
|
"from this screen, you should do it from the label editor.\n\n"
|
1996-10-06 11:40:31 +00:00
|
|
|
"Are you absolutely sure you want to do this now?")) {
|
1999-02-05 22:15:52 +00:00
|
|
|
variable_set2(DISK_PARTITIONED, "yes", 0);
|
2000-08-12 14:20:31 +00:00
|
|
|
|
2002-11-03 10:06:22 +00:00
|
|
|
#ifdef PC98
|
2000-08-12 14:20:31 +00:00
|
|
|
/*
|
2002-11-03 10:06:22 +00:00
|
|
|
* Don't trash the IPL if the first (and therefore only) chunk
|
2000-08-12 14:20:31 +00:00
|
|
|
* is marked for a truly dedicated disk (i.e., the disklabel
|
|
|
|
* starts at sector 0), even in cases where the user has
|
2002-11-03 10:06:22 +00:00
|
|
|
* requested a FreeBSD Boot Manager -- both would be fatal in
|
|
|
|
* this case.
|
1995-12-07 10:34:59 +00:00
|
|
|
*/
|
1998-03-23 05:59:18 +00:00
|
|
|
/*
|
2002-11-03 10:06:22 +00:00
|
|
|
* Don't offer to update the IPL on this disk if the first
|
2000-08-12 14:20:31 +00:00
|
|
|
* "real" chunk looks like a FreeBSD "all disk" partition,
|
|
|
|
* or the disk is entirely FreeBSD.
|
1998-03-23 05:59:18 +00:00
|
|
|
*/
|
2000-08-12 14:20:31 +00:00
|
|
|
if ((d->chunks->part->type != freebsd) ||
|
|
|
|
(d->chunks->part->offset > 1))
|
|
|
|
getBootMgr(d->name, &bootipl, &bootipl_size,
|
|
|
|
&bootmenu, &bootmenu_size);
|
|
|
|
else {
|
|
|
|
bootipl = NULL;
|
|
|
|
bootipl_size = 0;
|
|
|
|
bootmenu = NULL;
|
|
|
|
bootmenu_size = 0;
|
|
|
|
}
|
|
|
|
Set_Boot_Mgr(d, bootipl, bootipl_size, bootmenu, bootmenu_size);
|
|
|
|
#else
|
2002-11-03 10:06:22 +00:00
|
|
|
/*
|
|
|
|
* Don't trash the MBR if the first (and therefore only) chunk
|
|
|
|
* is marked for a truly dedicated disk (i.e., the disklabel
|
|
|
|
* starts at sector 0), even in cases where the user has
|
|
|
|
* requested booteasy or a "standard" MBR -- both would be
|
|
|
|
* fatal in this case.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Don't offer to update the MBR on this disk if the first
|
|
|
|
* "real" chunk looks like a FreeBSD "all disk" partition,
|
|
|
|
* or the disk is entirely FreeBSD.
|
|
|
|
*/
|
2000-08-12 14:20:31 +00:00
|
|
|
if ((d->chunks->part->type != freebsd) ||
|
|
|
|
(d->chunks->part->offset > 1))
|
2000-07-12 18:08:27 +00:00
|
|
|
getBootMgr(d->name, &mbrContents, &mbrSize);
|
|
|
|
else {
|
1999-09-02 00:51:16 +00:00
|
|
|
mbrContents = NULL;
|
2000-07-12 18:08:27 +00:00
|
|
|
mbrSize = 0;
|
|
|
|
}
|
|
|
|
Set_Boot_Mgr(d, mbrContents, mbrSize);
|
2000-08-12 14:20:31 +00:00
|
|
|
#endif
|
1999-09-02 00:51:16 +00:00
|
|
|
|
1996-04-28 03:27:26 +00:00
|
|
|
if (DITEM_STATUS(diskPartitionWrite(NULL)) != DITEM_SUCCESS)
|
1995-12-07 10:34:59 +00:00
|
|
|
msgConfirm("Disk partition write returned an error status!");
|
1996-04-23 01:29:35 +00:00
|
|
|
else
|
1995-12-07 10:34:59 +00:00
|
|
|
msgConfirm("Wrote FDISK partition information out successfully.");
|
|
|
|
}
|
1996-10-01 04:56:34 +00:00
|
|
|
clear();
|
1995-09-18 16:53:06 +00:00
|
|
|
break;
|
1996-10-06 11:40:31 +00:00
|
|
|
|
2003-11-01 20:04:12 +00:00
|
|
|
#ifndef __ia64__
|
1995-09-18 16:53:06 +00:00
|
|
|
case '|':
|
2000-12-14 02:49:02 +00:00
|
|
|
if (!msgNoYes("Are you SURE you want to go into Wizard mode?\n"
|
1995-12-07 10:34:59 +00:00
|
|
|
"No seat belts whatsoever are provided!")) {
|
1996-10-03 06:01:44 +00:00
|
|
|
clear();
|
|
|
|
refresh();
|
1995-05-16 02:53:31 +00:00
|
|
|
slice_wizard(d);
|
1999-02-05 22:15:52 +00:00
|
|
|
variable_set2(DISK_PARTITIONED, "yes", 0);
|
1996-10-04 13:33:49 +00:00
|
|
|
record_chunks(d);
|
1995-05-08 00:56:28 +00:00
|
|
|
}
|
|
|
|
else
|
1995-05-16 02:53:31 +00:00
|
|
|
msg = "Wise choice!";
|
1996-10-03 06:01:44 +00:00
|
|
|
clear();
|
1995-05-08 00:56:28 +00:00
|
|
|
break;
|
2003-11-01 20:04:12 +00:00
|
|
|
#endif
|
1995-05-08 00:56:28 +00:00
|
|
|
|
1997-01-15 02:52:00 +00:00
|
|
|
case '\033': /* ESC */
|
1995-06-11 19:33:05 +00:00
|
|
|
case 'Q':
|
1995-05-16 02:53:31 +00:00
|
|
|
chunking = FALSE;
|
2002-11-03 10:06:22 +00:00
|
|
|
#ifdef PC98
|
2000-08-12 14:20:31 +00:00
|
|
|
/*
|
2002-11-03 10:06:22 +00:00
|
|
|
* Don't trash the IPL if the first (and therefore only) chunk
|
2000-08-12 14:20:31 +00:00
|
|
|
* is marked for a truly dedicated disk (i.e., the disklabel
|
|
|
|
* starts at sector 0), even in cases where the user has requested
|
2002-11-03 10:06:22 +00:00
|
|
|
* a FreeBSD Boot Manager -- both would be fatal in this case.
|
1995-12-07 10:34:59 +00:00
|
|
|
*/
|
1998-03-23 08:36:27 +00:00
|
|
|
/*
|
2002-11-03 10:06:22 +00:00
|
|
|
* Don't offer to update the IPL on this disk if the first "real"
|
2000-08-12 14:20:31 +00:00
|
|
|
* chunk looks like a FreeBSD "all disk" partition, or the disk is
|
|
|
|
* entirely FreeBSD.
|
1998-03-23 08:36:27 +00:00
|
|
|
*/
|
2000-07-12 18:08:27 +00:00
|
|
|
if ((d->chunks->part->type != freebsd) ||
|
|
|
|
(d->chunks->part->offset > 1)) {
|
2001-03-12 10:18:54 +00:00
|
|
|
if (variable_cmp(DISK_PARTITIONED, "written")) {
|
|
|
|
getBootMgr(d->name, &bootipl, &bootipl_size,
|
|
|
|
&bootmenu, &bootmenu_size);
|
|
|
|
if (bootipl != NULL && bootmenu != NULL)
|
|
|
|
Set_Boot_Mgr(d, bootipl, bootipl_size,
|
|
|
|
bootmenu, bootmenu_size);
|
2002-11-03 10:06:22 +00:00
|
|
|
}
|
|
|
|
}
|
2000-08-12 14:20:31 +00:00
|
|
|
#else
|
2002-11-03 10:06:22 +00:00
|
|
|
/*
|
|
|
|
* Don't trash the MBR if the first (and therefore only) chunk
|
|
|
|
* is marked for a truly dedicated disk (i.e., the disklabel
|
|
|
|
* starts at sector 0), even in cases where the user has requested
|
|
|
|
* booteasy or a "standard" MBR -- both would be fatal in this case.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Don't offer to update the MBR on this disk if the first "real"
|
|
|
|
* chunk looks like a FreeBSD "all disk" partition, or the disk is
|
|
|
|
* entirely FreeBSD.
|
|
|
|
*/
|
|
|
|
if ((d->chunks->part->type != freebsd) ||
|
|
|
|
(d->chunks->part->offset > 1)) {
|
|
|
|
if (variable_cmp(DISK_PARTITIONED, "written")) {
|
2001-03-12 10:18:54 +00:00
|
|
|
getBootMgr(d->name, &mbrContents, &mbrSize);
|
|
|
|
if (mbrContents != NULL)
|
|
|
|
Set_Boot_Mgr(d, mbrContents, mbrSize);
|
2001-03-15 12:33:52 +00:00
|
|
|
}
|
2000-07-12 18:08:27 +00:00
|
|
|
}
|
2002-11-03 10:06:22 +00:00
|
|
|
#endif
|
1995-05-05 23:47:47 +00:00
|
|
|
break;
|
2000-05-26 00:38:20 +00:00
|
|
|
|
|
|
|
case 'Z':
|
2000-06-05 13:17:23 +00:00
|
|
|
size_unit = (size_unit + 1) % UNIT_SIZE;
|
2000-05-26 00:38:20 +00:00
|
|
|
break;
|
1996-10-06 11:40:31 +00:00
|
|
|
|
1995-05-07 23:37:34 +00:00
|
|
|
default:
|
|
|
|
beep();
|
|
|
|
msg = "Type F1 or ? for help";
|
|
|
|
break;
|
1995-05-05 23:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
1995-05-16 02:53:31 +00:00
|
|
|
p = CheckRules(d);
|
|
|
|
if (p) {
|
1996-04-30 05:23:49 +00:00
|
|
|
char buf[FILENAME_MAX];
|
1996-10-06 11:40:31 +00:00
|
|
|
|
1997-01-24 07:47:17 +00:00
|
|
|
use_helpline("Press F1 to read more about disk slices.");
|
1996-04-30 05:23:49 +00:00
|
|
|
use_helpfile(systemHelpFile("partition", buf));
|
1997-06-18 05:11:37 +00:00
|
|
|
if (!variable_get(VAR_NO_WARN))
|
|
|
|
dialog_mesgbox("Disk slicing warning:", p, -1, -1);
|
1995-05-16 02:53:31 +00:00
|
|
|
free(p);
|
|
|
|
}
|
1996-04-23 01:29:35 +00:00
|
|
|
restorescr(w);
|
1995-05-04 23:36:23 +00:00
|
|
|
}
|
2002-11-27 19:57:39 +00:00
|
|
|
#endif /* WITH_SLICES */
|
1995-05-04 23:36:23 +00:00
|
|
|
|
1999-01-02 07:23:37 +00:00
|
|
|
static u_char *
|
2002-03-28 08:23:33 +00:00
|
|
|
bootalloc(char *name, size_t *size)
|
1999-01-02 07:23:37 +00:00
|
|
|
{
|
|
|
|
char buf[FILENAME_MAX];
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
snprintf(buf, sizeof buf, "/boot/%s", name);
|
|
|
|
if (stat(buf, &sb) != -1) {
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open(buf, O_RDONLY);
|
|
|
|
if (fd != -1) {
|
|
|
|
u_char *cp;
|
|
|
|
|
|
|
|
cp = malloc(sb.st_size);
|
|
|
|
if (read(fd, cp, sb.st_size) != sb.st_size) {
|
|
|
|
free(cp);
|
|
|
|
close(fd);
|
2001-09-22 23:17:37 +00:00
|
|
|
msgDebug("bootalloc: couldn't read %ld bytes from %s\n", (long)sb.st_size, buf);
|
1999-01-02 07:23:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
close(fd);
|
2002-03-28 08:23:33 +00:00
|
|
|
if (size != NULL)
|
|
|
|
*size = sb.st_size;
|
1999-01-02 07:23:37 +00:00
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
msgDebug("bootalloc: couldn't open %s\n", buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
msgDebug("bootalloc: can't stat %s\n", buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-11-27 19:57:39 +00:00
|
|
|
|
|
|
|
#ifdef WITH_SLICES
|
1995-05-16 02:53:31 +00:00
|
|
|
static int
|
1996-04-13 13:32:15 +00:00
|
|
|
partitionHook(dialogMenuItem *selected)
|
1995-05-04 23:36:23 +00:00
|
|
|
{
|
1995-05-16 11:37:27 +00:00
|
|
|
Device **devs = NULL;
|
1995-05-16 02:53:31 +00:00
|
|
|
|
1996-04-13 13:32:15 +00:00
|
|
|
devs = deviceFind(selected->prompt, DEVICE_TYPE_DISK);
|
|
|
|
if (!devs) {
|
|
|
|
msgConfirm("Unable to find disk %s!", selected->prompt);
|
|
|
|
return DITEM_FAILURE;
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
1996-05-09 09:42:17 +00:00
|
|
|
/* Toggle enabled status? */
|
|
|
|
if (!devs[0]->enabled) {
|
|
|
|
devs[0]->enabled = TRUE;
|
1997-10-12 16:21:21 +00:00
|
|
|
diskPartition(devs[0]);
|
1996-05-09 09:42:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
devs[0]->enabled = FALSE;
|
1999-12-14 04:25:29 +00:00
|
|
|
return DITEM_SUCCESS;
|
1996-04-13 13:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
partitionCheck(dialogMenuItem *selected)
|
|
|
|
{
|
|
|
|
Device **devs = NULL;
|
|
|
|
|
|
|
|
devs = deviceFind(selected->prompt, DEVICE_TYPE_DISK);
|
|
|
|
if (!devs || devs[0]->enabled == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
1995-05-16 02:53:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1996-04-07 03:52:36 +00:00
|
|
|
diskPartitionEditor(dialogMenuItem *self)
|
1995-05-16 02:53:31 +00:00
|
|
|
{
|
|
|
|
DMenu *menu;
|
1995-06-11 19:33:05 +00:00
|
|
|
Device **devs;
|
1997-10-18 21:22:25 +00:00
|
|
|
int i, cnt, devcnt;
|
1995-06-11 19:33:05 +00:00
|
|
|
|
1997-10-12 16:21:21 +00:00
|
|
|
cnt = diskGetSelectCount(&devs);
|
1997-10-18 21:22:25 +00:00
|
|
|
devcnt = deviceCount(devs);
|
1997-10-12 16:21:21 +00:00
|
|
|
if (cnt == -1) {
|
1995-12-07 10:34:59 +00:00
|
|
|
msgConfirm("No disks found! Please verify that your disk controller is being\n"
|
|
|
|
"properly probed at boot time. See the Hardware Guide on the\n"
|
|
|
|
"Documentation menu for clues on diagnosing this type of problem.");
|
1997-10-12 16:21:21 +00:00
|
|
|
return DITEM_FAILURE;
|
1995-06-11 19:33:05 +00:00
|
|
|
}
|
1997-10-12 16:21:21 +00:00
|
|
|
else if (cnt) {
|
|
|
|
/* Some are already selected */
|
1997-10-18 21:22:25 +00:00
|
|
|
for (i = 0; i < devcnt; i++) {
|
1997-10-12 16:21:21 +00:00
|
|
|
if (devs[i]->enabled) {
|
2002-05-31 13:38:17 +00:00
|
|
|
if (variable_get(VAR_NONINTERACTIVE) &&
|
|
|
|
!variable_get(VAR_DISKINTERACTIVE))
|
1997-10-12 16:21:21 +00:00
|
|
|
diskPartitionNonInteractive(devs[i]);
|
|
|
|
else
|
|
|
|
diskPartition(devs[i]);
|
|
|
|
}
|
|
|
|
}
|
1995-05-04 23:36:23 +00:00
|
|
|
}
|
1995-05-17 14:40:00 +00:00
|
|
|
else {
|
1997-10-12 16:21:21 +00:00
|
|
|
/* No disks are selected, fall-back case now */
|
1997-10-18 21:22:25 +00:00
|
|
|
if (devcnt == 1) {
|
1997-10-12 16:21:21 +00:00
|
|
|
devs[0]->enabled = TRUE;
|
2002-05-31 13:38:17 +00:00
|
|
|
if (variable_get(VAR_NONINTERACTIVE) &&
|
|
|
|
!variable_get(VAR_DISKINTERACTIVE))
|
1997-10-12 16:21:21 +00:00
|
|
|
diskPartitionNonInteractive(devs[0]);
|
|
|
|
else
|
|
|
|
diskPartition(devs[0]);
|
|
|
|
return DITEM_SUCCESS;
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
1995-06-11 19:33:05 +00:00
|
|
|
else {
|
1997-10-12 16:21:21 +00:00
|
|
|
menu = deviceCreateMenu(&MenuDiskDevices, DEVICE_TYPE_DISK, partitionHook, partitionCheck);
|
|
|
|
if (!menu) {
|
|
|
|
msgConfirm("No devices suitable for installation found!\n\n"
|
|
|
|
"Please verify that your disk controller (and attached drives)\n"
|
|
|
|
"were detected properly. This can be done by pressing the\n"
|
|
|
|
"[Scroll Lock] key and using the Arrow keys to move back to\n"
|
|
|
|
"the boot messages. Press [Scroll Lock] again to return.");
|
|
|
|
return DITEM_FAILURE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
i = dmenuOpenSimple(menu, FALSE) ? DITEM_SUCCESS : DITEM_FAILURE;
|
|
|
|
free(menu);
|
|
|
|
}
|
1999-12-14 04:25:29 +00:00
|
|
|
return i;
|
1995-06-11 19:33:05 +00:00
|
|
|
}
|
1995-05-17 14:40:00 +00:00
|
|
|
}
|
1998-02-13 08:01:01 +00:00
|
|
|
return DITEM_SUCCESS;
|
1995-09-18 16:53:06 +00:00
|
|
|
}
|
2002-11-27 19:57:39 +00:00
|
|
|
#endif /* WITH_SLICES */
|
1995-09-18 16:53:06 +00:00
|
|
|
|
|
|
|
int
|
1996-04-07 03:52:36 +00:00
|
|
|
diskPartitionWrite(dialogMenuItem *self)
|
1995-09-18 16:53:06 +00:00
|
|
|
{
|
|
|
|
Device **devs;
|
|
|
|
int i;
|
2001-03-12 10:18:54 +00:00
|
|
|
|
|
|
|
if (!variable_cmp(DISK_PARTITIONED, "written"))
|
|
|
|
return DITEM_SUCCESS;
|
1995-09-18 16:53:06 +00:00
|
|
|
|
|
|
|
devs = deviceFind(NULL, DEVICE_TYPE_DISK);
|
|
|
|
if (!devs) {
|
|
|
|
msgConfirm("Unable to find any disks to write to??");
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_FAILURE;
|
1995-09-18 16:53:06 +00:00
|
|
|
}
|
1996-04-29 06:47:10 +00:00
|
|
|
if (isDebug())
|
|
|
|
msgDebug("diskPartitionWrite: Examining %d devices\n", deviceCount(devs));
|
1995-09-18 16:53:06 +00:00
|
|
|
for (i = 0; devs[i]; i++) {
|
|
|
|
Disk *d = (Disk *)devs[i]->private;
|
1999-01-02 07:23:37 +00:00
|
|
|
static u_char *boot1;
|
2003-05-24 21:12:14 +00:00
|
|
|
#if defined(__i386__) || defined(__ia64__) || defined(__amd64__)
|
1999-01-02 07:23:37 +00:00
|
|
|
static u_char *boot2;
|
1999-01-08 00:14:22 +00:00
|
|
|
#endif
|
1995-09-18 16:53:06 +00:00
|
|
|
|
|
|
|
if (!devs[i]->enabled)
|
|
|
|
continue;
|
|
|
|
|
2003-11-01 20:04:12 +00:00
|
|
|
#if defined(__i386__) || defined(__amd64__)
|
2002-03-28 08:23:33 +00:00
|
|
|
if (!boot1) boot1 = bootalloc("boot1", NULL);
|
|
|
|
if (!boot2) boot2 = bootalloc("boot2", NULL);
|
1995-09-18 16:53:06 +00:00
|
|
|
Set_Boot_Blocks(d, boot1, boot2);
|
2003-11-01 20:04:12 +00:00
|
|
|
#elif !defined(__ia64__)
|
2002-10-11 22:30:09 +00:00
|
|
|
if (!boot1) boot1 = bootalloc("boot1", NULL);
|
|
|
|
Set_Boot_Blocks(d, boot1, NULL);
|
1999-01-08 00:14:22 +00:00
|
|
|
#endif
|
1999-01-02 07:23:37 +00:00
|
|
|
|
1995-09-18 16:53:06 +00:00
|
|
|
msgNotify("Writing partition information to drive %s", d->name);
|
1996-04-28 20:54:11 +00:00
|
|
|
if (!Fake && Write_Disk(d)) {
|
1995-12-07 10:34:59 +00:00
|
|
|
msgConfirm("ERROR: Unable to write data to disk %s!", d->name);
|
1996-04-13 13:32:15 +00:00
|
|
|
return DITEM_FAILURE;
|
1995-12-07 10:34:59 +00:00
|
|
|
}
|
1995-09-18 16:53:06 +00:00
|
|
|
}
|
1995-12-07 10:34:59 +00:00
|
|
|
/* Now it's not "yes", but "written" */
|
1999-02-05 22:15:52 +00:00
|
|
|
variable_set2(DISK_PARTITIONED, "written", 0);
|
1999-12-17 02:46:04 +00:00
|
|
|
return DITEM_SUCCESS | DITEM_RESTORE;
|
1995-09-18 16:53:06 +00:00
|
|
|
}
|
1997-06-05 09:48:03 +00:00
|
|
|
|
2002-11-27 19:57:39 +00:00
|
|
|
#ifdef WITH_SLICES
|
1997-06-05 09:48:03 +00:00
|
|
|
/* Partition a disk based wholly on which variables are set */
|
|
|
|
static void
|
1997-10-12 16:21:21 +00:00
|
|
|
diskPartitionNonInteractive(Device *dev)
|
1997-06-05 09:48:03 +00:00
|
|
|
{
|
|
|
|
char *cp;
|
2004-03-16 17:07:06 +00:00
|
|
|
int i, all_disk = 0;
|
|
|
|
daddr_t sz;
|
2000-08-12 14:20:31 +00:00
|
|
|
#ifdef PC98
|
|
|
|
u_char *bootipl;
|
|
|
|
size_t bootipl_size;
|
|
|
|
u_char *bootmenu;
|
|
|
|
size_t bootmenu_size;
|
|
|
|
#else
|
1997-06-12 08:46:51 +00:00
|
|
|
u_char *mbrContents;
|
2000-07-12 18:08:27 +00:00
|
|
|
size_t mbrSize;
|
2000-06-05 13:17:23 +00:00
|
|
|
#endif
|
1997-10-12 16:21:21 +00:00
|
|
|
Disk *d = (Disk *)dev->private;
|
1997-06-05 09:48:03 +00:00
|
|
|
|
|
|
|
record_chunks(d);
|
|
|
|
cp = variable_get(VAR_GEOMETRY);
|
|
|
|
if (cp) {
|
|
|
|
msgDebug("Setting geometry from script to: %s\n", cp);
|
|
|
|
d->bios_cyl = strtol(cp, &cp, 0);
|
|
|
|
d->bios_hd = strtol(cp + 1, &cp, 0);
|
|
|
|
d->bios_sect = strtol(cp + 1, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
cp = variable_get(VAR_PARTITION);
|
|
|
|
if (cp) {
|
|
|
|
if (!strcmp(cp, "free")) {
|
|
|
|
/* Do free disk space case */
|
|
|
|
for (i = 0; chunk_info[i]; i++) {
|
|
|
|
/* If a chunk is at least 10MB in size, use it. */
|
|
|
|
if (chunk_info[i]->type == unused && chunk_info[i]->size > (10 * ONE_MEG)) {
|
2000-06-05 13:17:23 +00:00
|
|
|
Create_Chunk(d, chunk_info[i]->offset, chunk_info[i]->size,
|
|
|
|
freebsd, 3,
|
|
|
|
(chunk_info[i]->flags & CHUNK_ALIGN),
|
|
|
|
"FreeBSD");
|
1999-02-05 22:15:52 +00:00
|
|
|
variable_set2(DISK_PARTITIONED, "yes", 0);
|
1997-06-05 09:48:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!chunk_info[i]) {
|
|
|
|
msgConfirm("Unable to find any free space on this disk!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp(cp, "all")) {
|
|
|
|
/* Do all disk space case */
|
|
|
|
msgDebug("Warning: Devoting all of disk %s to FreeBSD.\n", d->name);
|
|
|
|
|
|
|
|
All_FreeBSD(d, FALSE);
|
|
|
|
}
|
|
|
|
else if (!strcmp(cp, "exclusive")) {
|
|
|
|
/* Do really-all-the-disk-space case */
|
|
|
|
msgDebug("Warning: Devoting all of disk %s to FreeBSD.\n", d->name);
|
|
|
|
|
1997-06-12 08:46:51 +00:00
|
|
|
All_FreeBSD(d, all_disk = TRUE);
|
1997-06-05 09:48:03 +00:00
|
|
|
}
|
2004-03-16 17:07:06 +00:00
|
|
|
else if ((sz = strtoimax(cp, &cp, 0))) {
|
1997-06-05 09:48:03 +00:00
|
|
|
/* Look for sz bytes free */
|
|
|
|
if (*cp && toupper(*cp) == 'M')
|
|
|
|
sz *= ONE_MEG;
|
2000-02-29 10:40:59 +00:00
|
|
|
else if (*cp && toupper(*cp) == 'G')
|
|
|
|
sz *= ONE_GIG;
|
1997-06-05 09:48:03 +00:00
|
|
|
for (i = 0; chunk_info[i]; i++) {
|
|
|
|
/* If a chunk is at least sz MB, use it. */
|
|
|
|
if (chunk_info[i]->type == unused && chunk_info[i]->size >= sz) {
|
2000-06-05 13:17:23 +00:00
|
|
|
Create_Chunk(d, chunk_info[i]->offset, sz, freebsd, 3,
|
|
|
|
(chunk_info[i]->flags & CHUNK_ALIGN),
|
|
|
|
"FreeBSD");
|
1999-02-05 22:15:52 +00:00
|
|
|
variable_set2(DISK_PARTITIONED, "yes", 0);
|
1997-06-05 09:48:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!chunk_info[i]) {
|
2004-03-16 17:07:06 +00:00
|
|
|
msgConfirm("Unable to find %jd free blocks on this disk!",
|
|
|
|
(intmax_t)sz);
|
1997-06-05 09:48:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp(cp, "existing")) {
|
|
|
|
/* Do existing FreeBSD case */
|
|
|
|
for (i = 0; chunk_info[i]; i++) {
|
|
|
|
if (chunk_info[i]->type == freebsd)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!chunk_info[i]) {
|
|
|
|
msgConfirm("Unable to find any existing FreeBSD partitions on this disk!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
msgConfirm("`%s' is an invalid value for %s - is config file valid?", cp, VAR_PARTITION);
|
|
|
|
return;
|
|
|
|
}
|
1997-06-12 08:46:51 +00:00
|
|
|
if (!all_disk) {
|
2000-08-12 14:20:31 +00:00
|
|
|
#ifdef PC98
|
|
|
|
getBootMgr(d->name, &bootipl, &bootipl_size,
|
|
|
|
&bootmenu, &bootmenu_size);
|
|
|
|
Set_Boot_Mgr(d, bootipl, bootipl_size, bootmenu, bootmenu_size);
|
|
|
|
#else
|
2000-07-12 18:08:27 +00:00
|
|
|
getBootMgr(d->name, &mbrContents, &mbrSize);
|
|
|
|
Set_Boot_Mgr(d, mbrContents, mbrSize);
|
2000-06-05 13:17:23 +00:00
|
|
|
#endif
|
2000-08-12 14:20:31 +00:00
|
|
|
}
|
1999-02-05 22:15:52 +00:00
|
|
|
variable_set2(DISK_PARTITIONED, "yes", 0);
|
1997-06-05 09:48:03 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-27 19:57:39 +00:00
|
|
|
#endif /* WITH_SLICES */
|