Clean up the mess from the previous commit which used a out of sync

patch file.

Now, we should be able to configure disklabels using the editor.
This commit is contained in:
paul 1994-10-26 07:34:38 +00:00
parent 6b1d934bd9
commit 3d2409e7dd
2 changed files with 6 additions and 391 deletions

View File

@ -8,6 +8,10 @@
#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);
@ -432,396 +436,6 @@ getfstype(char *fstype)
return(FS_OTHER);
}
#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)
{

View File

@ -302,9 +302,10 @@ 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_msgbox(TITLE, "This is an experimental disklabel configuration\nmenu. It doesn't perform any validation of the entries\nas yet so BE SURE YOU TYPE THINGS CORRECTLY.\n\n Hit escape to quit the editor.\n\nThere may be some delay exiting because of a dialog bug", 20,70,1);
dialog_clear();
edit_disklabel(&avail_disklabels[inst_disk]);
build_disklabel(&avail_disklabels[inst_disk]);
if (build_bootblocks(&avail_disklabels[inst_disk]) == -1)
Fatal(errmsg);
}