summaryrefslogtreecommitdiffstats
path: root/usr.sbin/sade/disks.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/sade/disks.c')
-rw-r--r--usr.sbin/sade/disks.c359
1 files changed, 357 insertions, 2 deletions
diff --git a/usr.sbin/sade/disks.c b/usr.sbin/sade/disks.c
index 0313372..be7d803 100644
--- a/usr.sbin/sade/disks.c
+++ b/usr.sbin/sade/disks.c
@@ -4,7 +4,7 @@
* This is probably the last program in the `sysinstall' line - the next
* generation being essentially a complete rewrite.
*
- * $Id: install.c,v 1.5 1995/05/04 03:51:16 jkh Exp $
+ * $Id$
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -42,17 +42,370 @@
*/
#include "sysinstall.h"
+#include <ctype.h>
+
+/*
+ * I make some pretty gross assumptions about having a max of 50 chunks
+ * total - 8 slices and 42 partitions. I can't easily display many more
+ * than that on the screen at once!
+ *
+ * For 2.1 I'll revisit this and try to make it more dynamic, but since
+ * this will catch 99.99% of all possible cases, I'm not too worried.
+ */
+
+#define MAX_CHUNKS 50
+
+#define FS_SWAP 1
+
+/* Where to start printing the freebsd slices */
+#define CHUNK_SLICE_START_ROW 2
+#define CHUNK_PART_START_ROW 10
+
+/* The smallest filesystem we're willing to create */
+#define FS_MIN_SIZE 2048
+
+typedef enum { PART_NONE, PART_SLICE, PART_SWAP, PART_FILESYSTEM } part_type;
+
+struct part_info {
+ Boolean newfs;
+ char mountpoint[FILENAME_MAX];
+};
+
+static struct {
+ struct disk *d;
+ struct chunk *c;
+ struct part_info *p;
+ part_type type;
+} fbsd_chunk_info[MAX_CHUNKS + 1];
+static int current_chunk;
+
/* If the given disk has a root partition on it, return TRUE */
static Boolean
contains_root_partition(struct disk *d)
{
+ struct chunk *c1;
+
+ if (!d->chunks)
+ msgFatal("Disk %s has no chunks!", d->name);
+ c1 = d->chunks->part;
+ while (c1) {
+ if (c1->type == freebsd) {
+ struct chunk *c2 = c1->part;
+
+ while (c2) {
+ if (c2->flags & CHUNK_IS_ROOT)
+ return TRUE;
+ c2 = c2->next;
+ }
+ }
+ c1 = c1->next;
+ }
+ return FALSE;
+}
+
+static Boolean
+check_conflict(char *name)
+{
+ int i;
+
+ for (i = 0; fbsd_chunk_info[i].d; i++)
+ if (fbsd_chunk_info[i].type == PART_FILESYSTEM &&
+ !strcmp(fbsd_chunk_info[i].c->name, name))
+ return TRUE;
return FALSE;
}
+static int
+space_free(struct chunk *c)
+{
+ struct chunk *c1 = c->part;
+ int sz = c->size;
+
+ while (c1) {
+ if (c1->type != unused)
+ sz -= c1->size;
+ c1 = c1->next;
+ }
+ if (sz < 0)
+ msgFatal("Partitions are larger than actual chunk??");
+ return sz;
+}
+
+static void
+record_fbsd_chunks(struct disk **disks)
+{
+ int i, j, p;
+
+ j = p = 0;
+ for (i = 0; disks[i]; i++) {
+ struct chunk *c1;
+
+ if (!disks[i]->chunks)
+ msgFatal("No chunk list found for %s!", disks[i]->name);
+ c1 = disks[i]->chunks->part;
+ while (c1) {
+ if (c1->type == freebsd) {
+ struct chunk *c2 = c1->part;
+
+ fbsd_chunk_info[j].type = PART_SLICE;
+ fbsd_chunk_info[j].d = disks[i];
+ fbsd_chunk_info[j].c = c1;
+ fbsd_chunk_info[j++].p = NULL;
+ while (c2) {
+ if (c2->type == part) {
+ if (c2->subtype == FS_SWAP)
+ fbsd_chunk_info[j].type = PART_SWAP;
+ else
+ fbsd_chunk_info[j].type = PART_FILESYSTEM;
+ fbsd_chunk_info[j].d = disks[i];
+ fbsd_chunk_info[j].c = c2;
+ fbsd_chunk_info[j++].p = c2->private;
+ }
+ c2 = c2->next;
+ }
+ }
+ c1 = c1->next;
+ }
+ }
+ fbsd_chunk_info[j].d = NULL;
+ fbsd_chunk_info[j].c = NULL;
+}
+
+int
+get_mountpoint(struct chunk *c)
+{
+ char *val;
+ struct part_info *part;
+
+ val = msgGetInput(c->private,
+ "Please specify mount point for new partition");
+ if (val) {
+ if (!strcmp(val, "/")) {
+ if (c->flags & CHUNK_PAST_1024) {
+msgConfirm("This region cannot be used for your root partition as\nit is past the 1024'th cylinder mark and the system would not be\nable to boot from it. Please pick another location for your\nroot partition and try again!");
+ return 1;
+ }
+ c->flags |= CHUNK_IS_ROOT;
+ }
+ if (check_conflict(val)) {
+ msgConfirm("You already have a mountpoint for %s assigned!", val);
+ return 1;
+ }
+ safe_free(c->private);
+ part = (struct part_info *)malloc(sizeof(struct part_info));
+ strncpy(part->mountpoint, val, FILENAME_MAX);
+ part->newfs = TRUE;
+ c->private = (void *)part;
+ c->private_free = free;
+ return 0;
+ }
+ return 1;
+}
+
+static part_type
+get_partition_type(struct chunk *c)
+{
+ char selection[20];
+ static unsigned char *fs_types[] = {
+ "Swap",
+ "A swap partition.",
+ "FS",
+ "A file system",
+ };
+
+ if (!dialog_menu("Please choose a partition type",
+ "If you want to use this partition for swap space, select Swap.\nIf you want to put a filesystem on it, choose FS.", -1, -1, 2, 2, fs_types, selection, NULL, NULL)) {
+ if (!strcmp(selection, "FS"))
+ return PART_FILESYSTEM;
+ else if (!strcmp(selection, "Swap"))
+ return PART_SWAP;
+ }
+ return PART_NONE;
+}
+
+#define PART_PART_COL 0
+#define PART_MOUNT_COL 8
+#define PART_NEWFS_COL 32
+#define PART_OFF 40
+
+static void
+print_fbsd_chunks(void)
+{
+ int i, srow, prow, pcol;
+ int sz;
+
+ attrset(A_REVERSE);
+ mvaddstr(0, 25, "FreeBSD Partition Editor");
+ attrset(A_NORMAL);
+
+ for (i = 0; i < 2; i++) {
+ attrset(A_UNDERLINE);
+ mvaddstr(CHUNK_PART_START_ROW - 1, PART_PART_COL + (i * PART_OFF),
+ "Part");
+ attrset(A_NORMAL);
+
+ attrset(A_UNDERLINE);
+ mvaddstr(CHUNK_PART_START_ROW - 1, PART_MOUNT_COL + (i * PART_OFF),
+ "Mount");
+ attrset(A_NORMAL);
+
+ attrset(A_UNDERLINE);
+ mvaddstr(CHUNK_PART_START_ROW - 1, PART_NEWFS_COL + (i * PART_OFF),
+ "Newfs");
+ attrset(A_NORMAL);
+ }
+
+ srow = CHUNK_SLICE_START_ROW;
+ prow = CHUNK_PART_START_ROW;
+
+ for (i = 0; fbsd_chunk_info[i].d; i++) {
+ if (i == current_chunk)
+ attrset(A_BOLD);
+ if (fbsd_chunk_info[i].type == PART_SLICE) {
+ sz = space_free(fbsd_chunk_info[i].c);
+ mvprintw(srow++, 0,
+ "Disk: %s\tPartition name: %s\tFree: %d blocks (%dMB)",
+ fbsd_chunk_info[i].d->name,
+ fbsd_chunk_info[i].c->name, sz, (sz / 2048));
+ }
+ else {
+ /* Go for two columns */
+ if (prow == (CHUNK_PART_START_ROW + 9))
+ pcol = PART_OFF;
+ else
+ pcol = 0;
+ mvaddstr(prow, pcol + PART_PART_COL, fbsd_chunk_info[i].c->name);
+ if (fbsd_chunk_info[i].type == PART_FILESYSTEM) {
+ char *mountpoint, *newfs;
+
+ if (fbsd_chunk_info[i].c->private) {
+ mountpoint = ((struct part_info *)fbsd_chunk_info[i].c->private)->mountpoint;
+ newfs = ((struct part_info *)fbsd_chunk_info[i].c->private)->newfs ? "Y" : "N";
+ }
+ else {
+ mountpoint = "?";
+ newfs = "";
+ }
+ mvaddstr(prow, pcol + PART_MOUNT_COL, mountpoint);
+ mvaddstr(prow, pcol + PART_NEWFS_COL, newfs);
+ }
+ else
+ mvaddstr(prow, pcol + PART_MOUNT_COL, "swap");
+ ++prow;
+ }
+ if (i == current_chunk)
+ attrset(A_NORMAL);
+ }
+}
+
+static void
+print_command_summary()
+{
+ int attrs = ColorDisplay ? A_BOLD : A_UNDERLINE;
+
+ mvprintw(19, 0,
+ "The following commands are valid here (upper or lower case):");
+ mvprintw(20, 0, "C = Create FreeBSD Partition D = Delete Partition");
+ mvprintw(21, 0, "M = Mount Partition (no newfs) ESC = Proceed to summary screen");
+ mvprintw(22, 0, "The default target will be displayed in ");
+
+ attrset(attrs);
+ addstr(ColorDisplay ? "bold" : "underline");
+ attrset(A_NORMAL);
+ move(0, 0);
+}
+
void
-partition_disk(struct disk *d)
+partition_disks(struct disk **disks)
{
+ int sz, key = 0;
+ Boolean partitioning;
+ char *msg = NULL;
+
+ dialog_clear();
+ partitioning = TRUE;
+ keypad(stdscr, TRUE);
+ record_fbsd_chunks(disks);
+
+ while (partitioning) {
+ clear();
+ print_fbsd_chunks();
+ print_command_summary();
+ if (msg) {
+ standout(); mvprintw(23, 0, msg); standend();
+ beep();
+ msg = NULL;
+ }
+ refresh();
+ key = toupper(getch());
+ switch (key) {
+ case KEY_UP:
+ case '-':
+ if (current_chunk != 0)
+ --current_chunk;
+ break;
+
+ case KEY_DOWN:
+ case '+':
+ case '\r':
+ case '\n':
+ if (fbsd_chunk_info[current_chunk + 1].d)
+ ++current_chunk;
+ break;
+
+ case KEY_HOME:
+ current_chunk = 0;
+ break;
+
+ case KEY_END:
+ while (fbsd_chunk_info[current_chunk + 1].d)
+ ++current_chunk;
+ break;
+
+ case KEY_F(1):
+ case '?':
+ systemDisplayFile("partitioning.hlp");
+ break;
+
+ case 'C':
+ if (fbsd_chunk_info[current_chunk].type != PART_SLICE) {
+ msg = "Can only create sub-partitions in a master partition (at top)";
+ break;
+ }
+ sz = space_free(fbsd_chunk_info[current_chunk].c);
+ if (sz <= FS_MIN_SIZE)
+ msg = "Not enough space to create additional FreeBSD partition";
+ else {
+ char *val, tmp[20];
+ int size;
+
+ snprintf(tmp, 20, "%d", sz);
+ val = msgGetInput(tmp, "Please specify size for new FreeBSD partition");
+ if (val && (size = strtol(val, 0, 0)) > 0) {
+ part_type type;
+
+ if (get_mountpoint(fbsd_chunk_info[current_chunk].c))
+ break;
+ type = get_partition_type(fbsd_chunk_info[current_chunk].c);
+ if (type == PART_NONE)
+ break;
+ Create_Chunk(fbsd_chunk_info[current_chunk].d,
+ fbsd_chunk_info[current_chunk].c->offset,
+ size,
+ part,
+ type == PART_SWAP ? FS_SWAP : freebsd,
+ fbsd_chunk_info[current_chunk].c->flags);
+ record_fbsd_chunks(disks);
+ }
+ }
+ break;
+
+ case 27: /* ESC */
+ partitioning = FALSE;
+ break;
+ }
+ }
}
int
@@ -71,7 +424,9 @@ write_disks(struct disk **disks)
Set_Boot_Mgr(disks[i], bteasy17);
else if (i == 0 && !msgYesNo("Would you like to remove an existing boot manager?"))
Set_Boot_Mgr(disks[i], mbr);
+#if 0
Write_Disk(disks[i]);
+#endif
}
return 0;
}
OpenPOWER on IntegriCloud