summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorpaul <paul@FreeBSD.org>1994-10-26 04:09:19 +0000
committerpaul <paul@FreeBSD.org>1994-10-26 04:09:19 +0000
commitefce06b340639951a5b3811de1136a266fca092a (patch)
tree4d2a8c6688aeaaae089151a63fa9bd74d5c0b1ad /sbin
parentcdef6c396b96ae52675c52c9c665b52992257abe (diff)
downloadFreeBSD-src-efce06b340639951a5b3811de1136a266fca092a.zip
FreeBSD-src-efce06b340639951a5b3811de1136a266fca092a.tar.gz
Completed disklabel configuration editor. The editor is working but the
glue code to pass the edited configuration onto the following stages isn't done yet.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/sysinstall/bootarea.c118
-rw-r--r--sbin/sysinstall/label.c390
-rw-r--r--sbin/sysinstall/mbr.c7
-rw-r--r--sbin/sysinstall/stage1.c13
-rw-r--r--sbin/sysinstall/sysinstall.h8
5 files changed, 410 insertions, 126 deletions
diff --git a/sbin/sysinstall/bootarea.c b/sbin/sysinstall/bootarea.c
index 7e0ce3c..87eca3e 100644
--- a/sbin/sysinstall/bootarea.c
+++ b/sbin/sysinstall/bootarea.c
@@ -13,27 +13,23 @@
*/
#include <sys/types.h>
-#include <sys/param.h>
#include <sys/errno.h>
#include <sys/disklabel.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <sys/uio.h>
-#include <ufs/ffs/fs.h>
-#include <string.h>
#include <unistd.h>
#include <stdio.h>
+#include <string.h>
#include <dialog.h>
#include "mbr.h"
-#include "bootarea.h"
#include "sysinstall.h"
extern char *bootblocks;
extern struct mbr *mbr;
extern char boot1[];
extern char boot2[];
-extern char **avail_disknames;
int
enable_label(int fd)
@@ -143,115 +139,3 @@ build_bootblocks(struct disklabel *label)
return(0);
}
-
-/* Convert a size in Mb to a round number of cylinders */
-int
-Mb_to_cylbdry(int size, struct disklabel *label)
-{
- int nsects, ncyls;
-
- nsects = (size * 1024 * 1024) / label->d_secsize;
- ncyls = nsects / label->d_secpercyl;
- nsects = ++ncyls * label->d_secpercyl;
-
- return(nsects);
-}
-
-void
-default_disklabel(struct disklabel *label, int avail_sects, int offset)
-{
-
- int nsects;
- int cylfill;
-
- /* Fill in default label entries */
- label->d_magic = DISKMAGIC;
- bcopy("INSTALLATION",label->d_typename, strlen("INSTALLATION"));
- label->d_rpm = 3600;
- label->d_interleave = 1;
- label->d_trackskew = 0;
- label->d_cylskew = 0;
- label->d_magic2 = DISKMAGIC;
- label->d_checksum = 0;
- label->d_bbsize = BBSIZE;
- label->d_sbsize = SBSIZE;
- label->d_npartitions = 5;
-
- /* Set up c and d as raw partitions for now */
- label->d_partitions[2].p_size = avail_sects;
- label->d_partitions[2].p_offset = offset;
- label->d_partitions[2].p_fsize = DEFFSIZE; /* XXX */
- label->d_partitions[2].p_fstype = FS_UNUSED;
- label->d_partitions[2].p_frag = DEFFRAG;
-
- label->d_partitions[3].p_size = label->d_secperunit;
- label->d_partitions[3].p_offset = 0;
- label->d_partitions[3].p_fsize = DEFFSIZE;
- label->d_partitions[3].p_fstype = FS_UNUSED;
- label->d_partitions[3].p_frag = DEFFRAG;
-
- /* Round offset to a cylinder */
- cylfill = offset / label->d_secpercyl;
- cylfill++;
- cylfill *= label->d_secpercyl;
- cylfill = cylfill - offset;
-
- /* Default root */
- nsects = Mb_to_cylbdry(DEFROOTSIZE, label);
- nsects += cylfill;
-
- label->d_partitions[0].p_size = nsects;
- label->d_partitions[0].p_offset = offset;
- label->d_partitions[0].p_fsize = DEFFSIZE;
- label->d_partitions[0].p_fstype = FS_BSDFFS;
- label->d_partitions[0].p_frag = DEFFRAG;
-
- avail_sects -= nsects;
- offset += nsects;
- nsects = Mb_to_cylbdry(DEFSWAPSIZE, label);
-
- label->d_partitions[1].p_size = nsects;
- label->d_partitions[1].p_offset = offset;
- label->d_partitions[1].p_fsize = DEFFSIZE;
- label->d_partitions[1].p_fstype = FS_SWAP;
- label->d_partitions[1].p_frag = DEFFRAG;
-
- avail_sects -= nsects;
- offset += nsects;
- nsects = Mb_to_cylbdry(DEFUSRSIZE, label);
-
- if (avail_sects > nsects)
- nsects = avail_sects;
-
- label->d_partitions[4].p_size = nsects;
- label->d_partitions[4].p_offset = offset;
- label->d_partitions[4].p_fsize = DEFFSIZE;
- label->d_partitions[4].p_fstype = FS_BSDFFS;
- label->d_partitions[4].p_frag = DEFFRAG;
-
-#ifdef notyet
- if (custom_install)
- customise_label()
-#endif
-
- sprintf(scratch, "%sa", avail_disknames[inst_disk]);
- devicename[0] = StrAlloc(scratch);
- mountpoint[0] = StrAlloc("/");
- sprintf(scratch, "%sb", avail_disknames[inst_disk]);
- devicename[1] = StrAlloc(scratch);
- mountpoint[1] = StrAlloc("swap");
- sprintf(scratch, "%se", avail_disknames[inst_disk]);
- devicename[2] = StrAlloc(scratch);
- mountpoint[2] = StrAlloc("/usr");
-}
-
-int
-disk_size(int disk)
-{
- struct disklabel *label = avail_disklabels + disk;
- int size;
-
- size = label->d_secsize * label->d_nsectors
- * label->d_ntracks * label->d_ncylinders;
- return(size/1024/1024);
-}
diff --git a/sbin/sysinstall/label.c b/sbin/sysinstall/label.c
index f90138c..13d18ad 100644
--- a/sbin/sysinstall/label.c
+++ b/sbin/sysinstall/label.c
@@ -1,9 +1,399 @@
+#define DKTYPENAMES
+#include <sys/param.h>
#include <sys/types.h>
#include <sys/disklabel.h>
+#include <ufs/ffs/fs.h>
+#include <string.h>
#include <dialog.h>
#include "sysinstall.h"
+int disk_size(struct disklabel *);
+int sectstoMb(int, int);
+
+char *partname[MAXPARTITIONS] = {"a", "b", "c", "d", "e", "f", "g", "h"};
+
+#define EDITABLES 3
+struct field {
+ int y;
+ int x;
+ int width;
+ char field[80];
+} field;
+
+struct field label_fields[MAXPARTITIONS][EDITABLES];
+
+void
+setup_label_fields(struct disklabel *lbl)
+{
+ int i;
+
+ for (i=0; i < MAXPARTITIONS; i++) {
+ label_fields[i][0].y = 4 + (i * 2);
+ label_fields[i][0].x = 15;
+ label_fields[i][0].width = 15;
+ sprintf(label_fields[i][0].field, "%s",
+ fstypenames[lbl->d_partitions[i].p_fstype]);
+ label_fields[i][1].y = 4 + (i * 2);
+ label_fields[i][1].x = 35;
+ label_fields[i][1].width = 9;
+ sprintf(label_fields[i][1].field, "%d",
+ sectstoMb(lbl->d_partitions[i].p_size, lbl->d_secsize));
+ label_fields[i][2].y = 4 + (i * 2);
+ label_fields[i][2].x = 45;
+ label_fields[i][2].width = 30;
+ if (mountpoint[i])
+ strcpy(label_fields[i][2].field, mountpoint[i]);
+ }
+}
+
+void
+update_label_form(WINDOW *window, struct disklabel *lbl)
+{
+ int i;
+
+ mvwprintw(window, 2, 2, "Partition");
+ mvwprintw(window, 2, 15, "Filesystem Type");
+ mvwprintw(window, 2, 35, "Size");
+ mvwprintw(window, 2, 45, "Mount point");
+ for (i=0; i < MAXPARTITIONS; i++) {
+ mvwprintw(window, 4+(i*2), 6, "%s", partname[i]);
+ mvwprintw(window, label_fields[i][0].y, label_fields[i][0].x, "%s",
+ &label_fields[i][0].field);
+ mvwprintw(window, label_fields[i][1].y, label_fields[i][1].x, "%s",
+ &label_fields[i][1].field);
+ if (label_fields[i][2].field)
+ mvwprintw(window, label_fields[i][2].y, label_fields[i][2].x, "%s",
+ &label_fields[i][2].field);
+ }
+ wrefresh(window);
+}
+
+int
+edit_line(WINDOW *window, int y, int x, char *field, int width, int maxlen)
+{
+ int len;
+ int key = 0;
+ int fpos, dispos, curpos;
+ int i;
+ int done = 0;
+
+ len = strlen(field);
+ if (len < width) {
+ fpos = len;
+ curpos = len;
+ dispos = 0;
+ } else {
+ fpos = width;
+ curpos = width;
+ dispos = len - width;
+ };
+
+
+ do {
+ wattrset(window, item_selected_attr);
+ wmove(window, y, x);
+ for (i=0; i < width; i++)
+ if (i < (len - dispos))
+ waddch(window, field[dispos+i]);
+ else
+ waddch(window, ' ');
+ wmove(window, y, x + curpos);
+ wrefresh(window);
+
+ key = wgetch(window);
+ switch (key) {
+ case TAB:
+ case KEY_BTAB:
+ case KEY_UP:
+ case KEY_DOWN:
+ case ESC:
+ case '\n':
+ done = 1;
+ break;
+ case KEY_HOME:
+ if (len < width) {
+ fpos = len;
+ curpos = len;
+ dispos = 0;
+ } else {
+ fpos = width;
+ curpos = width;
+ dispos = len - width;
+ };
+ break;
+ case KEY_END:
+ if (len < width) {
+ dispos = 0;
+ curpos = len - 1;
+ } else {
+ dispos = len - width - 1;
+ curpos = width - 1;
+ }
+ fpos = len - 1;
+ break;
+ case KEY_LEFT:
+ if ((!curpos) && (!dispos)) {
+ beep();
+ break;
+ }
+ if (--curpos < 0) {
+ curpos = 0;
+ if (--dispos < 0)
+ dispos = 0;
+ }
+ if (--fpos < 0)
+ fpos = 0;
+ break;
+ case KEY_RIGHT:
+ if ((curpos + dispos) == len) {
+ beep();
+ break;
+ }
+ if ((curpos == (width-1)) && (dispos == (maxlen - width -1))) {
+ beep();
+ break;
+ }
+ if (++curpos >= width) {
+ curpos = width - 1;
+ dispos++;
+ }
+ if (dispos >= len)
+ dispos = len - 1;
+ if (++fpos >= len) {
+ fpos = len;
+ }
+ break;
+ case KEY_BACKSPACE:
+ case KEY_DC:
+ if ((!curpos) && (!dispos)) {
+ beep();
+ break;
+ }
+ if (fpos > 0) {
+ memmove(field+fpos-1, field+fpos, len - fpos);
+ len--;
+ fpos--;
+ if (curpos > 0)
+ --curpos;
+ if (!curpos)
+ --dispos;
+ if (dispos < 0)
+ dispos = 0;
+ } else
+ beep();
+ break;
+ default:
+ if (len < maxlen - 1) {
+ memmove(field+fpos+1, field+fpos, len - fpos);
+ field[fpos] = key;
+ len++;
+ fpos++;
+ if (++curpos == width) {
+ --curpos;
+ dispos++;
+ }
+ if (len == (maxlen - 1)) {
+ dispos = (maxlen - width - 1);
+ }
+ } else
+ beep();
+ break;
+ }
+ } while (!done);
+ wattrset(window, dialog_attr);
+ wmove(window, y, x);
+ for (i=0; i < width; i++)
+ if (i < (len - dispos))
+ waddch(window, field[dispos+i]);
+ else
+ waddch(window, ' ');
+ wmove(window, y, x + curpos);
+ wrefresh(window);
+ field[len] = 0;
+ delwin(window);
+ refresh();
+ return (key);
+}
+
+int
+disk_size(struct disklabel *lbl)
+{
+ int size;
+
+ size = lbl->d_secsize * lbl->d_nsectors *
+ lbl->d_ntracks * lbl->d_ncylinders;
+ return (size / 1024 / 1024);
+}
+
+int
+sectstoMb(int nsects, int secsize)
+{
+ int size;
+
+ size = nsects * secsize;
+ if (size)
+ size /= 1024 * 1024;
+ return (size);
+}
+
+int
+Mbtosects(int Mb, int secsize)
+{
+ int nsects;
+
+ nsects = (Mb * 1024 * 1024) / secsize;
+ return(nsects);
+}
+
+int
+rndtocylbdry(int size, int secpercyl)
+{
+ int nocyls;
+
+ nocyls = size / secpercyl;
+ if ((nocyls * secpercyl) < size)
+ nocyls ++;
+ return (nocyls);
+}
+
+void
+default_disklabel(struct disklabel *lbl, int avail_sects, int offset)
+{
+ int nsects;
+
+ /* Fill in default label entries */
+
+ lbl->d_magic = DISKMAGIC;
+ bcopy("INSTALLATION", lbl->d_typename, strlen("INSTALLATION"));
+ lbl->d_rpm = 3600;
+ lbl->d_interleave = 1;
+ lbl->d_trackskew = 0;
+ lbl->d_cylskew = 0;
+ lbl->d_magic2 = DISKMAGIC;
+ lbl->d_checksum = 0;
+ lbl->d_bbsize = BBSIZE;
+ lbl->d_sbsize = SBSIZE;
+ lbl->d_npartitions = 5;
+
+ /* Set up c and d as raw partitions for now */
+ lbl->d_partitions[2].p_size = avail_sects;
+ lbl->d_partitions[2].p_offset = offset;
+ lbl->d_partitions[2].p_fsize = DEFFSIZE; /* XXX */
+ lbl->d_partitions[2].p_fstype = FS_UNUSED;
+ lbl->d_partitions[2].p_frag = DEFFRAG;
+
+ lbl->d_partitions[3].p_size = lbl->d_secperunit;
+ lbl->d_partitions[3].p_offset = 0;
+ lbl->d_partitions[3].p_fsize = DEFFSIZE;
+ lbl->d_partitions[3].p_fstype = FS_UNUSED;
+ lbl->d_partitions[3].p_frag = DEFFRAG;
+
+ /* Default root */
+ nsects = rndtocylbdry(Mbtosects(DEFROOTSIZE, lbl->d_secsize),
+ lbl->d_secperunit);
+
+ lbl->d_partitions[0].p_size = nsects;
+ lbl->d_partitions[0].p_offset = offset;
+ lbl->d_partitions[0].p_fsize = DEFFSIZE;
+ lbl->d_partitions[0].p_fstype = FS_BSDFFS;
+ lbl->d_partitions[0].p_frag = DEFFRAG;
+
+ avail_sects -= nsects;
+ offset += nsects;
+ nsects = rndtocylbdry(Mbtosects(DEFSWAPSIZE, lbl->d_secsize),
+ lbl->d_secperunit);
+
+ lbl->d_partitions[1].p_size = nsects;
+ lbl->d_partitions[1].p_offset = offset;
+ lbl->d_partitions[1].p_fsize = DEFFSIZE;
+ lbl->d_partitions[1].p_fstype = FS_SWAP;
+ lbl->d_partitions[1].p_frag = DEFFRAG;
+
+ avail_sects -= nsects;
+ offset += nsects;
+ nsects = rndtocylbdry(Mbtosects(DEFUSRSIZE, lbl->d_secsize),
+ lbl->d_secperunit);
+
+ if (avail_sects > nsects)
+ nsects = avail_sects;
+
+ lbl->d_partitions[4].p_size = nsects;
+ lbl->d_partitions[4].p_offset = offset;
+ lbl->d_partitions[4].p_fsize = DEFFSIZE;
+ lbl->d_partitions[4].p_fstype = FS_BSDFFS;
+ lbl->d_partitions[4].p_frag = DEFFRAG;
+
+ sprintf(scratch, "%sa", avail_disknames[inst_disk]);
+ devicename[0] = StrAlloc(scratch);
+ mountpoint[0] = StrAlloc("/");
+ sprintf(scratch, "%sb", avail_disknames[inst_disk]);
+ devicename[1] = StrAlloc(scratch);
+ mountpoint[1] = StrAlloc("swap");
+ sprintf(scratch, "%se", avail_disknames[inst_disk]);
+ devicename[2] = StrAlloc(scratch);
+ mountpoint[2] = StrAlloc("/usr");
+}
+
+void
+edit_disklabel(struct disklabel *lbl)
+{
+ int key=0;
+ int x_pos = 0;
+ int y_pos = 0;
+ WINDOW *window;
+
+ if (use_shadow)
+ draw_shadow(stdscr, 1, 1, LINES-3, COLS-5);
+
+ window = newwin(LINES - 2, COLS - 4, 0, 0);
+ keypad(window, TRUE);
+
+ draw_box(window, 1, 1, LINES - 3, COLS - 5, dialog_attr, border_attr);
+ wattrset(window, dialog_attr);
+
+ setup_label_fields(lbl);
+ do {
+ update_label_form(window, lbl);
+ key = edit_line(window, label_fields[y_pos][x_pos].y,
+ label_fields[y_pos][x_pos].x,
+ label_fields[y_pos][x_pos].field,
+ label_fields[y_pos][x_pos].width,
+ 20);
+ switch(key) {
+ case KEY_UP:
+ if (y_pos != 0)
+ y_pos--;
+ break;
+ case KEY_DOWN:
+ if (y_pos != MAXPARTITIONS)
+ y_pos++;
+ break;
+ case TAB:
+ x_pos++;
+ if (x_pos == EDITABLES)
+ x_pos = 0;
+ break;
+ case KEY_BTAB:
+ x_pos--;
+ if (x_pos < 0)
+ x_pos = EDITABLES - 1;
+ break;
+ case '\n':
+ ++y_pos;
+ if (y_pos == MAXPARTITIONS) {
+ y_pos = 0;
+ if (++x_pos == EDITABLES)
+ x_pos = 0;
+ }
+ break;
+ default:
+ break;
+ }
+ } while (key != '\033');
+ dialog_clear();
+}
+
void
display_disklabel(int disk)
{
diff --git a/sbin/sysinstall/mbr.c b/sbin/sysinstall/mbr.c
index c7640da..3199198 100644
--- a/sbin/sysinstall/mbr.c
+++ b/sbin/sysinstall/mbr.c
@@ -200,9 +200,10 @@ build_mbr(struct mbr *mbr, char *bootcode, struct disklabel *lb)
dp->dp_ehd = lb->d_ntracks - 1;
dp->dp_esect = lb->d_nsectors;
dp->dp_start = (dp->dp_scyl * lb->d_ntracks * lb->d_nsectors) +
- (dp->dp_shd * lb->d_nsectors) +
- dp->dp_ssect - 1;
- dp->dp_size = (lb->d_nsectors * lb->d_ntracks * lb->d_ncylinders) - dp->dp_start;
+ (dp->dp_shd * lb->d_nsectors) +
+ dp->dp_ssect - 1;
+ dp->dp_size = (lb->d_nsectors * lb->d_ntracks * lb->d_ncylinders) -
+ dp->dp_start;
}
/* Validate partition - XXX need to spend some time making this robust */
diff --git a/sbin/sysinstall/stage1.c b/sbin/sysinstall/stage1.c
index 9c2a160..6e95cc3 100644
--- a/sbin/sysinstall/stage1.c
+++ b/sbin/sysinstall/stage1.c
@@ -31,7 +31,6 @@
#include <machine/console.h>
#include "mbr.h"
-#include "bootarea.h"
#include "sysinstall.h"
struct disklabel *avail_disklabels;
@@ -53,7 +52,7 @@ int dialog_active = 0;
void exit_sysinstall();
void exit_prompt();
extern char *part_type(int);
-extern int disk_size(int);
+extern int disk_size(struct disklabel *);
char selection[30];
char boot1[] = BOOT1;
@@ -179,7 +178,7 @@ select_disk()
for (i=0;i<no_disks;i++) {
sprintf(options[(i*2)], "%d",i+1);
- sprintf(options[(i*2)+1], "%s, (%dMb) -> %s",avail_disklabels[i].d_typename,disk_size(i),avail_disknames[i]);
+ sprintf(options[(i*2)+1], "%s, (%dMb) -> %s",avail_disklabels[i].d_typename,disk_size(&avail_disklabels[i]),avail_disknames[i]);
}
if (dialog_menu("FreeBSD Installation", scratch, 10, 75, 5, no_disks, options, selection)) {
@@ -202,11 +201,12 @@ select_partition(int disk)
do {
valid = 1;
+ whole_disk = 0;
sprintf(scratch,"Select one of the following areas to install to:");
sprintf(options[0], "%d", 0);
sprintf(options[1], "%s, (%dMb)", "Install to entire disk",
- disk_size(disk));
+ disk_size(&avail_disklabels[inst_disk]));
for (i=0; i < NDOSPART; i++) {
sprintf(options[(i*2)+2], "%d",i+1);
sprintf(options[(i*2)+3], "%s, (%ldMb)",
@@ -251,7 +251,7 @@ stage1()
inst_disk = select_disk();
if (read_mbr(avail_fds[inst_disk], mbr) == -1) {
- sprintf(scratch, "The following error occured will trying\nto read the master boot record:\n\n%s\nIn order to install FreeBSD a new master boot record\nwill have to be written which will mean all current\ndata on the hard disk will be lost.", errmsg);
+ sprintf(scratch, "The following error occured while trying\nto read the master boot record:\n\n%s\nIn order to install FreeBSD a new master boot record\nwill have to be written which will mean all current\ndata on the hard disk will be lost.", errmsg);
ok = 0;
while (!ok) {
AskAbort(scratch);
@@ -302,6 +302,9 @@ stage1()
default_disklabel(&avail_disklabels[inst_disk],
mbr->dospart[inst_part].dp_size,
mbr->dospart[inst_part].dp_start);
+ dialog_msgbox(TITLE, "This is an example of how the disklabel configuration\nwill look. It doesn't pass the data back into the real\nstructures yet but you can play around with the\n field editing to get an idea of how it will work.\nHit escape to quit the editor.", 10,70,1);
+ dialog_clear();
+ edit_disklabel(&avail_disklabels[inst_disk]);
if (build_bootblocks(&avail_disklabels[inst_disk]) == -1)
Fatal(errmsg);
}
diff --git a/sbin/sysinstall/sysinstall.h b/sbin/sysinstall/sysinstall.h
index 9cb44b4..9904e88 100644
--- a/sbin/sysinstall/sysinstall.h
+++ b/sbin/sysinstall/sysinstall.h
@@ -14,6 +14,9 @@
#define TITLE "FreeBSD 2.0.1-Development Installation"
+#define BOOT1 "/stand/sdboot"
+#define BOOT2 "/stand/bootsd"
+
#define MAXFS 25
#define MAX_NO_DISKS 10
@@ -21,7 +24,9 @@
#define ERRMSGSIZE 256
#define DEFROOTSIZE 16
#define DEFSWAPSIZE 16
-#define DEFUSRSIZE 80 /* My disk is not that big Paul ! */
+#define DEFUSRSIZE 80
+#define DEFFSIZE 1024
+#define DEFFRAG 8
#define BOOT_MAGIC 0xAA55
#define ACTIVE 0x80
@@ -42,6 +47,7 @@ extern int inst_disk;
extern unsigned char *scratch;
extern unsigned char *errmsg;
extern int *avail_fds;
+extern unsigned char **avail_disknames;
extern struct disklabel *avail_disklabels;
extern u_short dkcksum(struct disklabel *);
OpenPOWER on IntegriCloud