Merge in my new mbr and disklabel code.
This commit is contained in:
parent
ade521b8fd
commit
9e3f27547d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=4645
@ -4,12 +4,12 @@ NOMAN= yet
|
||||
|
||||
.PATH: /usr/src/sbin/disklabel
|
||||
|
||||
SRCS = bootarea.c exec.c dkcksum.c label.c main.c mbr.c \
|
||||
SRCS = bootarea.c editor.c exec.c dkcksum.c label.c main.c mbr.c \
|
||||
stage0.c stage1.c stage2.c stage3.c stage4.c stage5.c \
|
||||
termcap.c utils.c makedevs.c ourcurses.c
|
||||
|
||||
CFLAGS += -Wall -g -static
|
||||
LDADD = -ldialog -lncurses -lmytinfo
|
||||
CFLAGS += -Wall -g -static -I${.CURDIR}/../../sys/
|
||||
LDADD = -ldialog -lncurses -lmytinfo -lforms
|
||||
DPADD = ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO}
|
||||
|
||||
makedevs.c: dev2c.sh
|
||||
|
@ -12,119 +12,139 @@
|
||||
* its use.
|
||||
*/
|
||||
|
||||
#include <fstab.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dialog.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dialog.h>
|
||||
#include <ufs/ffs/fs.h>
|
||||
|
||||
#include "mbr.h"
|
||||
#include "disk.h"
|
||||
#include "sysinstall.h"
|
||||
|
||||
extern char *bootblocks;
|
||||
extern struct mbr *mbr;
|
||||
extern char boot1[];
|
||||
extern char boot2[];
|
||||
char boot1[] = BOOT1;
|
||||
char boot2[] = BOOT2;
|
||||
|
||||
void
|
||||
int
|
||||
enable_label(int fd)
|
||||
{
|
||||
int flag = 1;
|
||||
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
||||
Fatal("ioctl(DIOCWLABEL,1) failed: %s",strerror(errno));
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
disable_label(int fd)
|
||||
{
|
||||
int flag = 0;
|
||||
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
||||
Fatal("ioctl(DIOCWLABEL,0) failed: %s",strerror(errno));
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
write_bootblocks(int fd, struct disklabel *lbl)
|
||||
write_bootblocks(int disk)
|
||||
{
|
||||
off_t of = lbl->d_partitions[OURPART].p_offset;
|
||||
int fd;
|
||||
off_t offset;
|
||||
int part = disk_list[disk].inst_part;
|
||||
struct disklabel *lbl = &disk_list[disk].lbl;
|
||||
unsigned char bootblocks[BBSIZE];
|
||||
|
||||
Debug("Seeking to byte %ld ", of * lbl->d_secsize);
|
||||
if (lseek(fd, (of * lbl->d_secsize), SEEK_SET) < 0) {
|
||||
Fatal("Couldn't seek to start of partition\n");
|
||||
}
|
||||
/* Load MBR boot code */
|
||||
|
||||
enable_label(fd);
|
||||
if ((fd = open(boot1, O_RDONLY)) == -1) {
|
||||
sprintf(errmsg, "Couldn't open boot file %s for bootblocks\n%s\n",
|
||||
boot1, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (write(fd, bootblocks, lbl->d_bbsize) != lbl->d_bbsize) {
|
||||
Fatal("Failed to write bootblocks (%p,%d) %d %s\n",
|
||||
bootblocks, lbl->d_bbsize,
|
||||
errno, strerror(errno)
|
||||
);
|
||||
}
|
||||
if (read(fd, bootblocks, MBRSIZE) < 0) {
|
||||
sprintf(errmsg, "Couldn't load boot file %s into bootblocks\n%s\n",
|
||||
boot1, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
disable_label(fd);
|
||||
if (close(fd) == -1) {
|
||||
sprintf(errmsg, "Couldn't close boot file %s\n%s\n", boot1,
|
||||
strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
build_bootblocks(int dfd,struct disklabel *label,struct dos_partition *dospart)
|
||||
{
|
||||
int fd;
|
||||
off_t of = label->d_partitions[OURPART].p_offset;
|
||||
|
||||
Debug("Loading boot code from %s", boot1);
|
||||
|
||||
fd = open(boot1, O_RDONLY);
|
||||
if (fd < 0)
|
||||
Fatal("Couldn't open boot file %s\n", boot1);
|
||||
|
||||
if (read(fd, bootblocks, MBRSIZE) < 0)
|
||||
Fatal("Couldn't read from boot file %s\n", boot1);
|
||||
|
||||
if (close(fd) == -1)
|
||||
Fatal("Couldn't close boot file %s\n", boot1);
|
||||
|
||||
Debug("Loading boot code from %s", boot2);
|
||||
|
||||
fd = open(boot2, O_RDONLY);
|
||||
if (fd < 0)
|
||||
Fatal("Couldn't open boot file %s", boot2);
|
||||
|
||||
if (read(fd, &bootblocks[MBRSIZE], (int)(label->d_bbsize - MBRSIZE)) < 0)
|
||||
Fatal("Couldn't read from boot file %s\n", boot2);
|
||||
|
||||
if (close(fd) == -1)
|
||||
Fatal("Couldn't close boot file %s", boot2);
|
||||
|
||||
bcopy(dospart, &bootblocks[DOSPARTOFF],
|
||||
sizeof(struct dos_partition) * NDOSPART);
|
||||
|
||||
label->d_checksum = 0;
|
||||
label->d_checksum = dkcksum(label);
|
||||
bcopy(label, &bootblocks[(LABELSECTOR * label->d_secsize) + LABELOFFSET],
|
||||
sizeof *label);
|
||||
|
||||
Debug("Seeking to byte %ld ", of * label->d_secsize);
|
||||
|
||||
if (lseek(dfd, (of * label->d_secsize), SEEK_SET) < 0) {
|
||||
Fatal("Couldn't seek to start of partition\n");
|
||||
}
|
||||
|
||||
enable_label(dfd);
|
||||
|
||||
if (write(dfd, bootblocks, label->d_bbsize) != label->d_bbsize) {
|
||||
Fatal("Failed to write bootblocks (%p,%d) %d %s\n",
|
||||
bootblocks, label->d_bbsize,
|
||||
errno, strerror(errno)
|
||||
);
|
||||
}
|
||||
|
||||
disable_label(dfd);
|
||||
|
||||
return(0);
|
||||
/* Load second level boot code */
|
||||
|
||||
if ((fd = open(boot2, O_RDONLY)) == -1) {
|
||||
sprintf(errmsg, "Couldn't open boot file %s for bootblocks\n%s\n",
|
||||
boot2, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (read(fd, &bootblocks[MBRSIZE], (int)(lbl->d_bbsize - MBRSIZE)) < 0) {
|
||||
sprintf(errmsg, "Couldn't load boot file %s into bootblocks\n%s\n",
|
||||
boot2, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (close(fd) == -1) {
|
||||
sprintf(errmsg, "Couldn't close boot file %s\n%s\n", boot2,
|
||||
strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
/* Copy the current MBR table into the boot blocks */
|
||||
|
||||
bcopy(&disk_list[disk].mbr.dospart, &bootblocks[DOSPARTOFF],
|
||||
sizeof(struct dos_partition) * NDOSPART);
|
||||
|
||||
/* Set checksum */
|
||||
lbl->d_checksum = 0;
|
||||
lbl->d_checksum = dkcksum(lbl);
|
||||
|
||||
/* Copy disklabel into bootblocks */
|
||||
|
||||
bcopy(lbl, &bootblocks[(LABELSECTOR * lbl->d_secsize) + LABELOFFSET],
|
||||
sizeof *lbl);
|
||||
|
||||
/* Calculate offset to start of MBR partition we're installing to */
|
||||
|
||||
offset = disk_list[disk].mbr.dospart[part].dp_start;
|
||||
offset *= lbl->d_secsize;
|
||||
|
||||
/* Write the boot blocks out to the raw disk */
|
||||
|
||||
if ((fd = open(diskname(disk), O_RDWR)) == -1) {
|
||||
sprintf(errmsg, "Couldn't open %s to write bootblocks\n%s\n",
|
||||
scratch,strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (lseek(fd, offset, SEEK_SET) < 0) {
|
||||
sprintf(errmsg, "Couldn't seek to bootblocks area %s\n%s\n",
|
||||
scratch, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (enable_label(fd) == -1)
|
||||
return (-1);
|
||||
|
||||
if (write(fd, bootblocks, lbl->d_bbsize) != lbl->d_bbsize) {
|
||||
sprintf(errmsg, "Failed to write out bootblocks to %s\n%s\n",
|
||||
scratch, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (disable_label(fd) == -1)
|
||||
return (-1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
@ -1,20 +1,22 @@
|
||||
/* Stopgap, until Paul does the right thing */
|
||||
#define ESC 27
|
||||
#define TAB 9
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#define DKTYPENAMES
|
||||
#include <sys/param.h>
|
||||
#include <ufs/ffs/fs.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/devconf.h>
|
||||
#include <ufs/ffs/fs.h>
|
||||
|
||||
#include <fstab.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <string.h>
|
||||
#include <dialog.h>
|
||||
|
||||
#include "disk.h"
|
||||
#include "sysinstall.h"
|
||||
#include "editor.h"
|
||||
#include "label.h"
|
||||
|
||||
/* Forward decls */
|
||||
int disk_size(struct disklabel *);
|
||||
@ -22,89 +24,8 @@ int getfstype(char *);
|
||||
int sectstoMb(int, int);
|
||||
|
||||
char *partname[MAXPARTITIONS] = {"a", "b", "c", "d", "e", "f", "g", "h"};
|
||||
|
||||
#define EDITABLES 3
|
||||
#define FSTYPE 0
|
||||
#define UPARTSIZES 1
|
||||
#define MOUNTPOINTS 2
|
||||
struct field {
|
||||
int y;
|
||||
int x;
|
||||
int width;
|
||||
char field[80];
|
||||
} field;
|
||||
|
||||
struct field label_fields[MAXPARTITIONS][EDITABLES];
|
||||
|
||||
int allocated_space;
|
||||
int ourpart_offset;
|
||||
int ourpart_size;
|
||||
|
||||
void
|
||||
yelp(char *str)
|
||||
{
|
||||
standout();
|
||||
mvprintw(24, 0, str);
|
||||
standend();
|
||||
beep();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
sprintf(label_fields[0][2].field, "%s", "/");
|
||||
sprintf(label_fields[1][2].field, "%s", "swap");
|
||||
sprintf(label_fields[4][2].field, "%s", "/usr");
|
||||
}
|
||||
|
||||
void
|
||||
update_label_form(WINDOW *window, struct disklabel *lbl)
|
||||
{
|
||||
int i;
|
||||
long used = 0,ul;
|
||||
|
||||
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);
|
||||
if (i < 2 || i > 3) {
|
||||
ul = strtol(label_fields[i][1].field,0,0);
|
||||
sprintf(label_fields[i][1].field, "%lu",ul);
|
||||
used += ul;
|
||||
}
|
||||
mvwprintw(window, label_fields[i][1].y, label_fields[i][1].x, "%-5s",
|
||||
&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);
|
||||
}
|
||||
mvwprintw(window, 20, 10, "Allocated %5luMb, Unallocated %5lu Mb",
|
||||
used, disk_size(lbl) - used);
|
||||
|
||||
wrefresh(window);
|
||||
}
|
||||
|
||||
extern char boot1[];
|
||||
extern char boot2[];
|
||||
|
||||
int
|
||||
disk_size(struct disklabel *lbl)
|
||||
@ -147,13 +68,52 @@ rndtocylbdry(int size, int secpercyl)
|
||||
return (nocyls * secpercyl);
|
||||
}
|
||||
|
||||
void
|
||||
default_disklabel(struct disklabel *lbl, int avail_sects, int offset)
|
||||
char *
|
||||
diskname(int disk)
|
||||
{
|
||||
int nsects;
|
||||
|
||||
/* Fill in default label entries */
|
||||
|
||||
sprintf(scratch, "/dev/r%s%dd", disk_list[disk].devconf->dc_name,
|
||||
disk_list[disk].devconf->dc_unit);
|
||||
return (scratch);
|
||||
}
|
||||
|
||||
int
|
||||
read_disklabel(int disk)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if ((fd = open(diskname(disk), O_RDONLY)) == -1) {
|
||||
sprintf(errmsg, "Couldn't open %s to read disklabel\n%s\n",
|
||||
scratch,strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (ioctl(fd, DIOCGDINFO, &disk_list[disk].lbl) == -1) {
|
||||
sprintf(errmsg, "Couldn't get disklabel from %s\n%s\n",
|
||||
scratch, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (close(fd) == -1) {
|
||||
sprintf(errmsg, "Couldn't close %s after reading disklabel\n%s\n",
|
||||
scratch, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
edit_disklabel(int disk)
|
||||
{
|
||||
WINDOW *window;
|
||||
int key;
|
||||
int next;
|
||||
int cur_field;
|
||||
int i;
|
||||
struct disklabel *lbl = &disk_list[disk].lbl;
|
||||
int offset;
|
||||
int nsects;
|
||||
int avail_sects;
|
||||
|
||||
lbl->d_magic = DISKMAGIC;
|
||||
bcopy("INSTALLATION", lbl->d_typename, strlen("INSTALLATION"));
|
||||
lbl->d_rpm = 3600;
|
||||
@ -164,176 +124,93 @@ default_disklabel(struct disklabel *lbl, int avail_sects, int offset)
|
||||
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_secpercyl);
|
||||
offset = rndtocylbdry(offset, lbl->d_secpercyl);
|
||||
|
||||
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_secpercyl);
|
||||
|
||||
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_secpercyl);
|
||||
|
||||
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;
|
||||
}
|
||||
lbl->d_npartitions = 8;
|
||||
lbl->d_boot0 = boot1;
|
||||
lbl->d_boot1 = boot2;
|
||||
|
||||
|
||||
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 = line_edit(window, label_fields[y_pos][x_pos].y,
|
||||
label_fields[y_pos][x_pos].x,
|
||||
label_fields[y_pos][x_pos].width,
|
||||
20,
|
||||
item_selected_attr,
|
||||
1,
|
||||
label_fields[y_pos][x_pos].field);
|
||||
switch(key) {
|
||||
case KEY_UP:
|
||||
if (y_pos != 0)
|
||||
y_pos--;
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
if (++y_pos == MAXPARTITIONS)
|
||||
y_pos--;
|
||||
break;
|
||||
case '\n':
|
||||
case TAB:
|
||||
x_pos++;
|
||||
if (x_pos == EDITABLES) {
|
||||
x_pos = 0;
|
||||
if (++y_pos == MAXPARTITIONS)
|
||||
y_pos--;
|
||||
}
|
||||
break;
|
||||
case KEY_BTAB:
|
||||
x_pos--;
|
||||
if (x_pos < 0) {
|
||||
x_pos = EDITABLES - 1;
|
||||
if (--y_pos < 0)
|
||||
y_pos++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (!(window = newwin(24, 79, 0, 0))) {
|
||||
sprintf(errmsg, "Failed to open window for disklabel editor\n");
|
||||
return (-1);
|
||||
}
|
||||
} while (key != '\033');
|
||||
dialog_clear();
|
||||
}
|
||||
|
||||
int
|
||||
build_disklabel(struct disklabel *lbl)
|
||||
{
|
||||
int i, offset;
|
||||
int nsects;
|
||||
int total_sects;
|
||||
keypad(window, TRUE);
|
||||
|
||||
/* Get start of FreeBSD partition from default label */
|
||||
offset = lbl->d_partitions[2].p_offset;
|
||||
draw_box(window, 0, 0, 24, 79, dialog_attr, border_attr);
|
||||
|
||||
for (i=0; i < MAXPARTITIONS; i++) {
|
||||
if (strlen(label_fields[i][MOUNTPOINTS].field) &&
|
||||
atoi(label_fields[i][UPARTSIZES].field)) {
|
||||
sprintf(scratch, "%s%s", avail_disknames[inst_disk], partname[i]);
|
||||
Fname[Nfs] = StrAlloc(scratch);
|
||||
Fmount[Nfs] = StrAlloc(label_fields[i][MOUNTPOINTS].field);
|
||||
Nfs++;
|
||||
nsects = Mbtosects(atoi(label_fields[i][UPARTSIZES].field),
|
||||
lbl->d_secsize);
|
||||
lbl->d_partitions[i].p_size = nsects;
|
||||
lbl->d_partitions[i].p_offset = offset;
|
||||
offset += nsects;
|
||||
total_sects += nsects;
|
||||
lbl->d_partitions[i].p_fstype =
|
||||
getfstype(label_fields[i][FSTYPE].field);
|
||||
lbl->d_npartitions = i+1;
|
||||
} else if (i < 2 || i > 3) {
|
||||
lbl->d_partitions[i].p_size = 0;
|
||||
lbl->d_partitions[i].p_offset = 0;
|
||||
lbl->d_partitions[i].p_fstype = 0;
|
||||
cur_field = 1;
|
||||
while (key != ESC) {
|
||||
for (i=0; i < MAXPARTITIONS; i++) {
|
||||
sprintf(label_field[(i*5)].field, "%s%d%s", disk_list[disk].devconf->dc_name,
|
||||
disk_list[disk].devconf->dc_unit,
|
||||
partname[i]);
|
||||
sprintf(label_field[(i*5)+1].field, "%s",
|
||||
disk_list[disk].mounts[i].fs_mntops);
|
||||
sprintf(label_field[(i*5)+2].field, "%s",
|
||||
fstypenames[lbl->d_partitions[i].p_fstype]);
|
||||
sprintf(label_field[(i*5)+3].field, "%d",
|
||||
sectstoMb(lbl->d_partitions[i].p_size,lbl->d_secsize));
|
||||
sprintf(label_field[(i*5)+4].field, "%s",
|
||||
disk_list[disk].mounts[i].fs_file);
|
||||
}
|
||||
|
||||
disp_fields(window, label_field, sizeof(label_field)/sizeof(struct field));
|
||||
key = edit_line(window, label_field[cur_field].y,
|
||||
label_field[cur_field].x,
|
||||
label_field[cur_field].field,
|
||||
label_field[cur_field].width,
|
||||
label_field[cur_field].maxlen);
|
||||
next = change_field(label_field[cur_field], key);
|
||||
if (next == -1)
|
||||
beep();
|
||||
else
|
||||
cur_field = next;
|
||||
|
||||
/* Update label */
|
||||
for (i=0; i<MAXPARTITIONS; i++) {
|
||||
sprintf(disk_list[disk].mounts[i].fs_spec, "%s",
|
||||
label_field[(i*5)].field);
|
||||
sprintf(disk_list[disk].mounts[i].fs_mntops, "%s",
|
||||
label_field[(i*5)+1].field);
|
||||
sprintf(disk_list[disk].mounts[i].fs_file, "%s",
|
||||
label_field[(i*5)+4].field);
|
||||
}
|
||||
|
||||
avail_sects = lbl->d_partitions[OURPART].p_size;
|
||||
offset = lbl->d_partitions[OURPART].p_offset;
|
||||
for (i=0; i < MAXPARTITIONS; i++) {
|
||||
if (i == OURPART)
|
||||
continue;
|
||||
if (i == RAWPART)
|
||||
continue;
|
||||
lbl->d_partitions[i].p_offset = offset;
|
||||
nsects = atoi(label_field[(i*5)+3].field);
|
||||
nsects = Mbtosects(nsects, lbl->d_secsize);
|
||||
if (nsects > avail_sects)
|
||||
nsects = avail_sects;
|
||||
avail_sects -= nsects;
|
||||
offset += nsects;
|
||||
if (nsects == 0)
|
||||
lbl->d_partitions[i].p_offset = 0;
|
||||
lbl->d_partitions[i].p_size = nsects;
|
||||
lbl->d_partitions[i].p_fsize = DEFFSIZE;
|
||||
lbl->d_partitions[i].p_frag = DEFFRAG;
|
||||
}
|
||||
}
|
||||
Debug("Part%d: %d sects, %d offset, %d end, %d type", i,
|
||||
lbl->d_partitions[i].p_size,
|
||||
lbl->d_partitions[i].p_offset,
|
||||
lbl->d_partitions[i].p_size+
|
||||
lbl->d_partitions[i].p_offset,
|
||||
lbl->d_partitions[i].p_fstype);
|
||||
}
|
||||
return 0;
|
||||
|
||||
if (write_bootblocks(disk) == -1)
|
||||
return(-1);
|
||||
|
||||
dialog_clear();
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
getfstype(char *fstype)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < FSMAXTYPES; i++)
|
||||
if (!strcasecmp(fstype, fstypenames[i]))
|
||||
return(i);
|
||||
return(FS_OTHER);
|
||||
}
|
||||
|
||||
void
|
||||
display_disklabel(int disk)
|
||||
{
|
||||
int i, key=0;
|
||||
WINDOW *window;
|
||||
struct disklabel *lbl = &disk_list[disk].lbl;
|
||||
|
||||
if (use_shadow)
|
||||
draw_shadow(stdscr, 1, 1, LINES-2, COLS-2);
|
||||
@ -343,50 +220,50 @@ display_disklabel(int disk)
|
||||
draw_box(window, 1, 1, LINES - 2, COLS - 2, dialog_attr, border_attr);
|
||||
wattrset(window, dialog_attr);
|
||||
|
||||
mvwprintw(window, 2, 2, "Dumping label for disk %d, %s\n", disk, avail_disklabels[disk].d_typename);
|
||||
mvwprintw(window, 3, 2, "magic = %lu",avail_disklabels[disk].d_magic);
|
||||
mvwprintw(window, 3, 22, "type = %x",avail_disklabels[disk].d_type);
|
||||
mvwprintw(window, 3, 32, "subtype = %x\n",avail_disklabels[disk].d_subtype);
|
||||
mvwprintw(window, 4, 2, "Typename = %s",avail_disklabels[disk].d_typename);
|
||||
mvwprintw(window, 4, 38, "Packname = %s",avail_disklabels[disk].d_packname);
|
||||
mvwprintw(window, 5, 74, "boot0 = %s",avail_disklabels[disk].d_boot0);
|
||||
mvwprintw(window, 5, 50, "boot1 = %s\n",avail_disklabels[disk].d_boot1);
|
||||
mvwprintw(window, 5, 2, "secsize = %ld",avail_disklabels[disk].d_secsize);
|
||||
mvwprintw(window, 5, 20, "nsectors = %ld",avail_disklabels[disk].d_nsectors);
|
||||
mvwprintw(window, 5, 30, "ntracks = %ld",avail_disklabels[disk].d_ntracks);
|
||||
mvwprintw(window, 5, 50, "ncylinders = %ld\n",avail_disklabels[disk].d_ncylinders);
|
||||
mvwprintw(window, 6, 2, "secpercyl = %ld",avail_disklabels[disk].d_secpercyl);
|
||||
mvwprintw(window, 6, 40, "secperunit = %ld\n",avail_disklabels[disk].d_secperunit);
|
||||
mvwprintw(window, 7, 2, "sparespertrack = %d",avail_disklabels[disk].d_sparespertrack);
|
||||
mvwprintw(window, 7, 20, "sparespercyl = %d",avail_disklabels[disk].d_sparespercyl);
|
||||
mvwprintw(window, 7, 40, "acylinders = %ld\n",avail_disklabels[disk].d_acylinders);
|
||||
mvwprintw(window, 8, 2, "rpm = %d",avail_disklabels[disk].d_rpm);
|
||||
mvwprintw(window, 8, 20, "interleave = %d",avail_disklabels[disk].d_interleave);
|
||||
mvwprintw(window, 8, 40, "trackskew = %d",avail_disklabels[disk].d_trackskew);
|
||||
mvwprintw(window, 8, 60, "cylskew = %d\n",avail_disklabels[disk].d_cylskew);
|
||||
mvwprintw(window, 9, 2, "headswitch = %ld",avail_disklabels[disk].d_headswitch);
|
||||
mvwprintw(window, 9, 30, "trkseek = %ld",avail_disklabels[disk].d_trkseek);
|
||||
mvwprintw(window, 9, 55, "flags = %ld\n",avail_disklabels[disk].d_flags);
|
||||
mvwprintw(window, 2, 2, "Dumping label for disk %d, %s\n", disk, lbl->d_typename);
|
||||
mvwprintw(window, 3, 2, "magic = %lu",lbl->d_magic);
|
||||
mvwprintw(window, 3, 22, "type = %x",lbl->d_type);
|
||||
mvwprintw(window, 3, 32, "subtype = %x\n",lbl->d_subtype);
|
||||
mvwprintw(window, 4, 2, "Typename = %s",lbl->d_typename);
|
||||
mvwprintw(window, 4, 38, "Packname = %s",lbl->d_packname);
|
||||
mvwprintw(window, 5, 74, "boot0 = %s",lbl->d_boot0);
|
||||
mvwprintw(window, 5, 50, "boot1 = %s\n",lbl->d_boot1);
|
||||
mvwprintw(window, 5, 2, "secsize = %ld",lbl->d_secsize);
|
||||
mvwprintw(window, 5, 20, "nsectors = %ld",lbl->d_nsectors);
|
||||
mvwprintw(window, 5, 30, "ntracks = %ld",lbl->d_ntracks);
|
||||
mvwprintw(window, 5, 50, "ncylinders = %ld\n",lbl->d_ncylinders);
|
||||
mvwprintw(window, 6, 2, "secpercyl = %ld",lbl->d_secpercyl);
|
||||
mvwprintw(window, 6, 40, "secperunit = %ld\n",lbl->d_secperunit);
|
||||
mvwprintw(window, 7, 2, "sparespertrack = %d",lbl->d_sparespertrack);
|
||||
mvwprintw(window, 7, 20, "sparespercyl = %d",lbl->d_sparespercyl);
|
||||
mvwprintw(window, 7, 40, "acylinders = %ld\n",lbl->d_acylinders);
|
||||
mvwprintw(window, 8, 2, "rpm = %d",lbl->d_rpm);
|
||||
mvwprintw(window, 8, 20, "interleave = %d",lbl->d_interleave);
|
||||
mvwprintw(window, 8, 40, "trackskew = %d",lbl->d_trackskew);
|
||||
mvwprintw(window, 8, 60, "cylskew = %d\n",lbl->d_cylskew);
|
||||
mvwprintw(window, 9, 2, "headswitch = %ld",lbl->d_headswitch);
|
||||
mvwprintw(window, 9, 30, "trkseek = %ld",lbl->d_trkseek);
|
||||
mvwprintw(window, 9, 55, "flags = %ld\n",lbl->d_flags);
|
||||
mvwprintw(window, 10, 2, "Drivedata");
|
||||
for (i=0; i< NDDATA; i++) {
|
||||
mvwprintw(window, 10, 11 + (i*10), " : %d = %ld",i,avail_disklabels[disk].d_drivedata[i]);
|
||||
mvwprintw(window, 10, 11 + (i*10), " : %d = %ld",i,lbl->d_drivedata[i]);
|
||||
}
|
||||
mvwprintw(window, 11, 2, "Spare");
|
||||
for (i=0; i< NSPARE; i++) {
|
||||
mvwprintw(window, 11, 7 + (i*10), " : %d = %ld",i,avail_disklabels[disk].d_spare[i]);
|
||||
mvwprintw(window, 11, 7 + (i*10), " : %d = %ld",i,lbl->d_spare[i]);
|
||||
}
|
||||
mvwprintw(window, 12, 2, "magic2 = %lu",avail_disklabels[disk].d_magic2);
|
||||
mvwprintw(window, 12, 40, "checksum = %d\n",avail_disklabels[disk].d_checksum);
|
||||
mvwprintw(window, 13, 2, "npartitions = %d",avail_disklabels[disk].d_npartitions);
|
||||
mvwprintw(window, 13, 25, "bbsize = %lu",avail_disklabels[disk].d_bbsize);
|
||||
mvwprintw(window, 13, 50, "sbsize = %lu\n",avail_disklabels[disk].d_sbsize);
|
||||
mvwprintw(window, 12, 2, "magic2 = %lu",lbl->d_magic2);
|
||||
mvwprintw(window, 12, 40, "checksum = %d\n",lbl->d_checksum);
|
||||
mvwprintw(window, 13, 2, "npartitions = %d",lbl->d_npartitions);
|
||||
mvwprintw(window, 13, 25, "bbsize = %lu",lbl->d_bbsize);
|
||||
mvwprintw(window, 13, 50, "sbsize = %lu\n",lbl->d_sbsize);
|
||||
for (i=0; i< MAXPARTITIONS; i++) {
|
||||
mvwprintw(window, 14+i, 2, "%d: size: %ld",i,avail_disklabels[disk].d_partitions[i].p_size);
|
||||
mvwprintw(window, 14+i, 20, "offset: %ld",avail_disklabels[disk].d_partitions[i].p_offset);
|
||||
mvwprintw(window, 14+i, 36, "fsize: %ld",avail_disklabels[disk].d_partitions[i].p_fsize);
|
||||
mvwprintw(window, 14+i, 49, "fstype: %d",avail_disklabels[disk].d_partitions[i].p_fstype);
|
||||
mvwprintw(window, 14+i, 60, "frag: %d",avail_disklabels[disk].d_partitions[i].p_frag);
|
||||
mvwprintw(window, 14+i, 70, "cpg: %d",avail_disklabels[disk].d_partitions[i].p_cpg);
|
||||
mvwprintw(window, 14+i, 2, "%d: size: %ld",i,lbl->d_partitions[i].p_size);
|
||||
mvwprintw(window, 14+i, 20, "offset: %ld",lbl->d_partitions[i].p_offset);
|
||||
mvwprintw(window, 14+i, 36, "fsize: %ld",lbl->d_partitions[i].p_fsize);
|
||||
mvwprintw(window, 14+i, 49, "fstype: %d",lbl->d_partitions[i].p_fstype);
|
||||
mvwprintw(window, 14+i, 60, "frag: %d",lbl->d_partitions[i].p_frag);
|
||||
mvwprintw(window, 14+i, 70, "cpg: %d",lbl->d_partitions[i].p_cpg);
|
||||
}
|
||||
|
||||
dialog_update();
|
||||
@ -396,246 +273,3 @@ display_disklabel(int disk)
|
||||
delwin(window);
|
||||
dialog_clear();
|
||||
}
|
||||
|
||||
static int
|
||||
AskWhichPartition(char *prompt)
|
||||
{
|
||||
char buf[10];
|
||||
int i;
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, prompt, buf, 2);
|
||||
if (i != '\n' && i != '\r') return -1;
|
||||
if (!strchr("abefghABEFGH",*buf)) return -1;
|
||||
return tolower(*buf) - 'a';
|
||||
}
|
||||
|
||||
void
|
||||
DiskLabel()
|
||||
{
|
||||
int i, j, done = 0, diskno, flag, k;
|
||||
char buf[128],*p;
|
||||
struct disklabel *lbl, olbl;
|
||||
u_long cyl, hd, sec, tsec;
|
||||
u_long l1, l2, l3, l4;
|
||||
char *yip = NULL;
|
||||
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, "Enter number of disk to Disklabel> ", buf, 2);
|
||||
printf("%d", i);
|
||||
if (i != '\n' && i != '\r') return;
|
||||
diskno = atoi(buf);
|
||||
if (!(diskno >= 0 && diskno < MAX_NO_DISKS && Dname[diskno]))
|
||||
return;
|
||||
olbl = *Dlbl[diskno];
|
||||
lbl = &olbl;
|
||||
cyl = lbl->d_ncylinders;
|
||||
hd = lbl->d_ntracks;
|
||||
sec = lbl->d_nsectors;
|
||||
tsec = lbl->d_secperunit;
|
||||
for (i = lbl->d_npartitions; i < MAXPARTITIONS; i++) {
|
||||
lbl->d_partitions[i].p_offset = 0;
|
||||
lbl->d_partitions[i].p_size = 0;
|
||||
lbl->d_partitions[i].p_fstype = 0;
|
||||
}
|
||||
lbl->d_npartitions = MAXPARTITIONS;
|
||||
|
||||
if(Dname[diskno][0] == 's' && Dname[diskno][1] == 'd')
|
||||
lbl->d_type = DTYPE_SCSI;
|
||||
else
|
||||
lbl->d_type = DTYPE_ST506;
|
||||
|
||||
while(!done) {
|
||||
clear(); standend();
|
||||
if (yip) {
|
||||
yelp(yip);
|
||||
yip = NULL;
|
||||
}
|
||||
j = 0;
|
||||
mvprintw(j++, 0, "%s -- Diskspace editor -- DISKLABEL", TITLE);
|
||||
j++;
|
||||
|
||||
allocated_space = 0;
|
||||
ourpart_size = lbl->d_partitions[OURPART].p_size;
|
||||
ourpart_offset = lbl->d_partitions[OURPART].p_offset;
|
||||
|
||||
mvprintw(j++, 0, "Part Start End Blocks MB Type Mountpoint");
|
||||
for (i = 0; i < MAXPARTITIONS; i++) {
|
||||
mvprintw(j++, 0, "%c ", 'a'+i);
|
||||
printw(" %8u %8u %8u %5u ",
|
||||
lbl->d_partitions[i].p_offset,
|
||||
lbl->d_partitions[i].p_offset+
|
||||
(lbl->d_partitions[i].p_size ?
|
||||
lbl->d_partitions[i].p_size-1 : 0),
|
||||
lbl->d_partitions[i].p_size,
|
||||
(lbl->d_partitions[i].p_size + 1024)/2048);
|
||||
|
||||
k = lbl->d_partitions[i].p_fstype;
|
||||
if (k > FSMAXTYPES)
|
||||
printw(" %04x ", k);
|
||||
else
|
||||
printw("%-10s ", fstypenames[k]);
|
||||
if (i == OURPART)
|
||||
printw("<Entire FreeBSD slice>");
|
||||
else if (i == RAWPART)
|
||||
printw("<Entire Disk>");
|
||||
else {
|
||||
if (Fmount[MP[diskno][i]])
|
||||
printw(Fmount[MP[diskno][i]]);
|
||||
if ((lbl->d_partitions[i].p_offset >= ourpart_offset) &&
|
||||
((lbl->d_partitions[i].p_offset +
|
||||
lbl->d_partitions[i].p_size) <=
|
||||
(ourpart_offset + ourpart_size)))
|
||||
allocated_space += lbl->d_partitions[i].p_size;
|
||||
}
|
||||
}
|
||||
mvprintw(18, 0, "Total size: %d blocks", ourpart_size);
|
||||
mvprintw(19, 0, "Space allocated: %d blocks", allocated_space);
|
||||
mvprintw(21, 0, "Commands available:");
|
||||
mvprintw(22, 0, "(H)elp (S)ize (M)ountpoint (D)elete (R)eread (W)rite (Q)uit");
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i=getch();
|
||||
switch(i) {
|
||||
case 'h': case 'H':
|
||||
ShowFile(HELPME_FILE,"Help file for disklayout");
|
||||
break;
|
||||
case 'd': case 'D':
|
||||
j = AskWhichPartition("Delete which partition? ");
|
||||
if (j < 0) {
|
||||
yip = "Invalid partition";
|
||||
break;
|
||||
}
|
||||
CleanMount(diskno, j);
|
||||
lbl->d_partitions[j].p_fstype = FS_UNUSED;
|
||||
lbl->d_partitions[j].p_size = 0;
|
||||
lbl->d_partitions[j].p_offset = 0;
|
||||
break;
|
||||
|
||||
case 's': case 'S':
|
||||
j = AskWhichPartition("Change size of which partition? ");
|
||||
if (j < 0) {
|
||||
yip = "Invalid partition";
|
||||
break;
|
||||
}
|
||||
if (lbl->d_partitions[j].p_fstype != FS_BSDFFS &&
|
||||
lbl->d_partitions[j].p_fstype != FS_UNUSED &&
|
||||
lbl->d_partitions[j].p_fstype != FS_SWAP) {
|
||||
yip = "Invalid partition type";
|
||||
break;
|
||||
}
|
||||
if (lbl->d_partitions[OURPART].p_size == 0) {
|
||||
yip = "No FreeBSD partition defined?";
|
||||
break;
|
||||
}
|
||||
l1=lbl->d_partitions[OURPART].p_offset;
|
||||
l2=lbl->d_partitions[OURPART].p_offset +
|
||||
lbl->d_partitions[OURPART].p_size;
|
||||
for (i = 0; i < MAXPARTITIONS; i++) {
|
||||
if (i == OURPART) continue;
|
||||
if (i == RAWPART) continue;
|
||||
if (i == j) continue;
|
||||
if (lbl->d_partitions[i].p_size == 0) continue;
|
||||
if (lbl->d_partitions[i].p_offset >= l2) continue;
|
||||
if ((lbl->d_partitions[i].p_offset+
|
||||
lbl->d_partitions[i].p_size) <= l1) continue;
|
||||
l3 = lbl->d_partitions[i].p_offset - l1;
|
||||
l4 = l2 - (lbl->d_partitions[i].p_offset+
|
||||
lbl->d_partitions[i].p_size);
|
||||
if (l3 > 0 && l3 >= l4)
|
||||
l2 = l1+l3;
|
||||
else if (l4 > 0 && l4 > l3)
|
||||
l1 = l2-l4;
|
||||
else
|
||||
l2 = l1;
|
||||
}
|
||||
if (!(l2 - l1)) {
|
||||
yip = "Sizes unchanged - couldn't find room";
|
||||
break;
|
||||
}
|
||||
sprintf(buf, "%lu", (l2-l1+1024L)/2048L);
|
||||
i = AskEm(stdscr, "Size of partition in MB> ", buf, 10);
|
||||
l3= strtol(buf, 0, 0) * 2048L;
|
||||
if (!l3) {
|
||||
yip = "Invalid size given";
|
||||
break;
|
||||
}
|
||||
if (l3 > l2 - l1)
|
||||
l3 = l2 - l1;
|
||||
lbl->d_partitions[j].p_size = l3;
|
||||
lbl->d_partitions[j].p_offset = l1;
|
||||
if (j == 1)
|
||||
lbl->d_partitions[j].p_fstype = FS_SWAP;
|
||||
else
|
||||
lbl->d_partitions[j].p_fstype = FS_BSDFFS;
|
||||
break;
|
||||
|
||||
case 'r': case 'R':
|
||||
olbl = *Dlbl[diskno];
|
||||
/* XXX be more selective here */
|
||||
for (i = 0; i < MAXPARTITIONS; i++)
|
||||
CleanMount(diskno, i);
|
||||
break;
|
||||
|
||||
case 'm': case 'M':
|
||||
if (memcmp(lbl, Dlbl[diskno], sizeof *lbl)) {
|
||||
yip = "Please (W)rite changed partition information first";
|
||||
break;
|
||||
}
|
||||
j = AskWhichPartition("Mountpoint of which partition ? ");
|
||||
if (j < 0) {
|
||||
yip = "Invalid partition";
|
||||
break;
|
||||
}
|
||||
k = lbl->d_partitions[j].p_fstype;
|
||||
if (k != FS_BSDFFS && k != FS_MSDOS && k != FS_SWAP) {
|
||||
yip = "Invalid partition type";
|
||||
break;
|
||||
}
|
||||
if (!lbl->d_partitions[j].p_size) {
|
||||
yip = "Zero partition size";
|
||||
break;
|
||||
}
|
||||
if (k == FS_SWAP)
|
||||
strcpy(buf, "swap");
|
||||
else if (Fmount[MP[diskno][j]])
|
||||
strcpy(buf, Fmount[MP[diskno][j]]);
|
||||
else
|
||||
*buf = 0;
|
||||
if (k != FS_SWAP) {
|
||||
i = AskEm(stdscr, "Mount on directory> ", buf, 28);
|
||||
if (i != '\n' && i != '\r') {
|
||||
yip ="Invalid directory name";
|
||||
break;
|
||||
}
|
||||
}
|
||||
CleanMount(diskno, j);
|
||||
p = SetMount(diskno,j,buf);
|
||||
yip = p;
|
||||
break;
|
||||
|
||||
case 'w': case 'W':
|
||||
*Dlbl[diskno] = *lbl;
|
||||
Dlbl[diskno]->d_magic = DISKMAGIC;
|
||||
Dlbl[diskno]->d_magic2 = DISKMAGIC;
|
||||
Dlbl[diskno]->d_checksum = 0;
|
||||
Dlbl[diskno]->d_checksum = dkcksum(Dlbl[diskno]);
|
||||
*lbl = *Dlbl[diskno];
|
||||
enable_label(Dfd[diskno]);
|
||||
if (ioctl(Dfd[diskno], DIOCSDINFO, Dlbl[diskno]) == -1)
|
||||
Fatal("Couldn't set label: %s", strerror(errno));
|
||||
if (ioctl(Dfd[diskno], DIOCWDINFO, Dlbl[diskno]) == -1)
|
||||
Fatal("Couldn't write label: %s", strerror(errno));
|
||||
disable_label(Dfd[diskno]);
|
||||
yip = "Label written successfully.";
|
||||
break;
|
||||
|
||||
case 'q': case 'Q':
|
||||
if (!memcmp(lbl, Dlbl[diskno], sizeof *lbl))
|
||||
return;
|
||||
/* XXX be more selective here */
|
||||
for (i = 0; i < MAXPARTITIONS; i++)
|
||||
CleanMount(diskno, i);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <unistd.h>
|
||||
#include <dialog.h>
|
||||
#include <fcntl.h>
|
||||
#include <fstab.h>
|
||||
|
||||
#ifdef __i386__ /* temp measure delete nov 15 1994 */
|
||||
#define i386 1
|
||||
@ -23,51 +24,26 @@
|
||||
#warning FOO
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/devconf.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include "mbr.h"
|
||||
#include "sysinstall.h"
|
||||
#include "disk.h"
|
||||
#include "editor.h"
|
||||
#include "mbr.h"
|
||||
|
||||
extern struct mbr *mbr;
|
||||
extern int inst_part;
|
||||
extern int whole_disk;
|
||||
char *part_type(int);
|
||||
int write_mbr(char *, struct mbr *);
|
||||
int read_mbr(char *, struct mbr *);
|
||||
void show_mbr(struct mbr *);
|
||||
int clear_mbr(struct mbr *, char *);
|
||||
int build_mbr(struct mbr *, char *, struct disklabel *);
|
||||
|
||||
|
||||
static unsigned char bootcode[] = {
|
||||
0x33, 0xc0, 0xfa, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0x8e, 0xc0, 0x8e, 0xd8, 0xfb, 0x8b, 0xf4, 0xbf,
|
||||
0x00, 0x06, 0xb9, 0x00, 0x02, 0xfc, 0xf3, 0xa4, 0xea, 0x1d, 0x06, 0x00, 0x00, 0xb0, 0x04, 0xbe,
|
||||
0xbe, 0x07, 0x80, 0x3c, 0x80, 0x74, 0x0c, 0x83, 0xc6, 0x10, 0xfe, 0xc8, 0x75, 0xf4, 0xbe, 0xbd,
|
||||
0x06, 0xeb, 0x43, 0x8b, 0xfe, 0x8b, 0x14, 0x8b, 0x4c, 0x02, 0x83, 0xc6, 0x10, 0xfe, 0xc8, 0x74,
|
||||
0x0a, 0x80, 0x3c, 0x80, 0x75, 0xf4, 0xbe, 0xbd, 0x06, 0xeb, 0x2b, 0xbd, 0x05, 0x00, 0xbb, 0x00,
|
||||
0x7c, 0xb8, 0x01, 0x02, 0xcd, 0x13, 0x73, 0x0c, 0x33, 0xc0, 0xcd, 0x13, 0x4d, 0x75, 0xef, 0xbe,
|
||||
0x9e, 0x06, 0xeb, 0x12, 0x81, 0x3e, 0xfe, 0x7d, 0x55, 0xaa, 0x75, 0x07, 0x8b, 0xf7, 0xea, 0x00,
|
||||
0x7c, 0x00, 0x00, 0xbe, 0x85, 0x06, 0x2e, 0xac, 0x0a, 0xc0, 0x74, 0x06, 0xb4, 0x0e, 0xcd, 0x10,
|
||||
0xeb, 0xf4, 0xfb, 0xeb, 0xfe,
|
||||
'M', 'i', 's', 's', 'i', 'n', 'g', ' ',
|
||||
'o', 'p', 'e', 'r', 'a', 't', 'i', 'n', 'g', ' ', 's', 'y', 's', 't', 'e', 'm', 0,
|
||||
'E', 'r', 'r', 'o', 'r', ' ', 'l', 'o', 'a', 'd', 'i', 'n', 'g', ' ',
|
||||
'o', 'p', 'e', 'r', 'a', 't', 'i', 'n', 'g', ' ', 's', 'y', 's', 't', 'e', 'm', 0,
|
||||
'I', 'n', 'v', 'a', 'l', 'i', 'd', ' ',
|
||||
'p', 'a', 'r', 't', 'i', 't', 'i', 'o', 'n', ' ', 't', 'a', 'b', 'l', 'e', 0,
|
||||
'A', 'u', 't', 'h', 'o', 'r', ' ', '-', ' ',
|
||||
'S', 'i', 'e', 'g', 'm', 'a', 'r', ' ', 'S', 'c', 'h', 'm', 'i', 'd', 't', 0,0,0,
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
extern char boot1[];
|
||||
extern struct disk disk_list[];
|
||||
struct part_type part_types[] = PARTITION_TYPES
|
||||
struct field *last_field;
|
||||
|
||||
char *
|
||||
part_type(int type)
|
||||
@ -85,138 +61,87 @@ part_type(int type)
|
||||
return("Unknown");
|
||||
}
|
||||
|
||||
void
|
||||
read_dospart(int fd, struct dos_partition *dp)
|
||||
{
|
||||
u_char buf[512];
|
||||
if (lseek(fd, 0, SEEK_SET) == -1)
|
||||
AskAbort("Couldn't seek for master boot record read\n");
|
||||
if (read(fd, buf, 512) != 512) {
|
||||
AskAbort("Failed to read master boot record\n");
|
||||
}
|
||||
memcpy(dp, buf+DOSPARTOFF, sizeof(*dp)*NDOSPART);
|
||||
}
|
||||
|
||||
void
|
||||
write_dospart(int fd, struct dos_partition *dp)
|
||||
{
|
||||
u_char buf[512];
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) == -1)
|
||||
AskAbort("Couldn't seek for master boot record read\n");
|
||||
if (read(fd, buf, 512) != 512) {
|
||||
AskAbort("Failed to read master boot record\n");
|
||||
}
|
||||
memcpy(buf+DOSPARTOFF, dp, sizeof(*dp)*NDOSPART);
|
||||
buf[510] = 0x55;
|
||||
buf[511] = 0xaa;
|
||||
if (lseek(fd, 0, SEEK_SET) == -1)
|
||||
AskAbort("Couldn't seek for master boot record write\n");
|
||||
enable_label(fd);
|
||||
if (write(fd, buf, 512) != 512)
|
||||
AskAbort("Failed to write master boot record\n");
|
||||
disable_label(fd);
|
||||
}
|
||||
|
||||
void
|
||||
write_bootcode(int fd)
|
||||
{
|
||||
u_char buf[512];
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) == -1)
|
||||
AskAbort("Couldn't seek for master boot record read\n");
|
||||
if (read(fd, buf, 512) != 512) {
|
||||
AskAbort("Failed to read master boot record\n");
|
||||
}
|
||||
memcpy(buf, bootcode, DOSPARTOFF);
|
||||
buf[510] = 0x55;
|
||||
buf[511] = 0xaa;
|
||||
if (lseek(fd, 0, SEEK_SET) == -1)
|
||||
AskAbort("Couldn't seek for master boot record write\n");
|
||||
enable_label(fd);
|
||||
if (write(fd, buf, 512) != 512)
|
||||
AskAbort("Failed to write master boot record\n");
|
||||
disable_label(fd);
|
||||
}
|
||||
|
||||
int
|
||||
read_mbr(int fd, struct mbr *mbr)
|
||||
read_mbr(char *device, struct mbr *mbr)
|
||||
{
|
||||
if (lseek(fd, 0, SEEK_SET) == -1) {
|
||||
sprintf(errmsg, "Couldn't seek for master boot record read\n");
|
||||
return(-1);
|
||||
}
|
||||
if (read(fd, &(mbr->bootcode), MBRSIZE) == -1) {
|
||||
sprintf(errmsg, "Failed to read master boot record\n");
|
||||
return(-1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
int fd;
|
||||
|
||||
int
|
||||
write_mbr(int fd, struct mbr *mbr)
|
||||
{
|
||||
if (lseek(fd, 0, SEEK_SET) == -1) {
|
||||
sprintf(errmsg, "Couldn't seek for master boot record write\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
enable_label(fd);
|
||||
|
||||
if (write(fd, mbr->bootcode, MBRSIZE) == -1) {
|
||||
sprintf(errmsg, "Failed to write master boot record\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
disable_label(fd);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
show_mbr(struct mbr *mbr)
|
||||
{
|
||||
int i, j, key = 0;
|
||||
int x, y;
|
||||
WINDOW *window;
|
||||
|
||||
if (use_shadow)
|
||||
draw_shadow(stdscr, 1, 1, LINES-2, COLS-2);
|
||||
window = newwin(LINES-2, COLS-2, 1, 1);
|
||||
keypad(window, TRUE);
|
||||
|
||||
draw_box(window, 1, 1, LINES - 2, COLS - 2, dialog_attr, border_attr);
|
||||
wattrset(window, dialog_attr);
|
||||
|
||||
for (i=0; i<NDOSPART/2; i++) {
|
||||
for (j=0; j<NDOSPART/2; j++) {
|
||||
x = (j * 38) + 3;
|
||||
y = (i * 11) + 2;
|
||||
mvwprintw(window, y, x, "Partition %d: flags = %x",
|
||||
(i*2)+j, mbr->dospart[(i*2)+j].dp_flag);
|
||||
mvwprintw(window, y+1, x, "Starting at (C%d, H%d, S%d)",
|
||||
mbr->dospart[(i*2)+j].dp_scyl,
|
||||
mbr->dospart[(i*2)+j].dp_shd,
|
||||
mbr->dospart[(i*2)+j].dp_ssect);
|
||||
mvwprintw(window, y+2, x, "Type: %s (%x)",
|
||||
part_type(mbr->dospart[(i*2)+j].dp_typ),
|
||||
mbr->dospart[(i*2)+j].dp_typ);
|
||||
mvwprintw(window, y+3, x, "Ending at (C%d, H%d, S%d)",
|
||||
mbr->dospart[(i*2)+j].dp_ecyl,
|
||||
mbr->dospart[(i*2)+j].dp_ehd,
|
||||
mbr->dospart[(i*2)+j].dp_esect);
|
||||
mvwprintw(window, y+4, x, "Absolute start sector %ld",
|
||||
mbr->dospart[(i*2)+j].dp_start);
|
||||
mvwprintw(window, y+5, x, "Size (in sectors) %ld", mbr->dospart[(i*2)+j].dp_size);
|
||||
if ((fd = open(device, O_RDONLY)) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't open device %s to read master boot record\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't seek to track 0 of device %s to read master boot record\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (read(fd, &(mbr->bootcode), MBRSIZE) == -1) {
|
||||
sprintf(errmsg, "Failed to read master boot record from device %s\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (close(fd) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't close device %s after reading master boot record\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
write_mbr(char *device, struct mbr *mbr)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if ((fd = open(device, O_WRONLY)) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't open device %s to write master boot record\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't seek to track 0 of device %s to write master boot record\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
dialog_update();
|
||||
|
||||
while (key != '\n' && key != ' ' && key != '\033')
|
||||
key = wgetch(window);
|
||||
|
||||
delwin(window);
|
||||
dialog_clear();
|
||||
if (enable_label(fd) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't write enable MBR area of device %s\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (write(fd, mbr->bootcode, MBRSIZE) == -1) {
|
||||
sprintf(errmsg, "Failed to write master boot record to device %s\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (disable_label(fd) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't write disable MBR area of device %s\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (close(fd) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't close device %s after reading master boot record\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -230,7 +155,8 @@ clear_mbr(struct mbr *mbr, char *bootcode)
|
||||
* then clobber any existing bootcode.
|
||||
*/
|
||||
|
||||
TellEm("Loading MBR code from %s", bootcode);
|
||||
sprintf(scratch, "\nLoading MBR code from %s\n", bootcode);
|
||||
dialog_msgbox(TITLE, scratch, 5, 60, 0);
|
||||
fd = open(bootcode, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
sprintf(errmsg, "Couldn't open boot file %s\n", bootcode);
|
||||
@ -261,7 +187,7 @@ clear_mbr(struct mbr *mbr, char *bootcode)
|
||||
mbr->dospart[i].dp_start = 0;
|
||||
mbr->dospart[i].dp_size = 0;
|
||||
}
|
||||
|
||||
|
||||
mbr->magic = MBR_MAGIC;
|
||||
|
||||
dialog_clear();
|
||||
@ -269,264 +195,195 @@ clear_mbr(struct mbr *mbr, char *bootcode)
|
||||
}
|
||||
|
||||
int
|
||||
build_mbr(struct mbr *mbr, char *bootcode, struct disklabel *lb)
|
||||
dedicated_mbr(struct mbr *mbr, char *bootcode, struct disklabel *lbl)
|
||||
{
|
||||
int i;
|
||||
struct dos_partition *dp = &mbr->dospart[inst_part];
|
||||
struct dos_partition *dp = &mbr->dospart[0];
|
||||
|
||||
if (whole_disk) {
|
||||
/* Install to entire disk */
|
||||
if (clear_mbr(mbr, bootcode) == -1)
|
||||
return(-1);
|
||||
return(-1);
|
||||
dp->dp_scyl = 0;
|
||||
dp->dp_shd = 1;
|
||||
dp->dp_ssect = 1;
|
||||
dp->dp_ecyl = lb->d_ncylinders - 1;
|
||||
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_ecyl = lbl->d_ncylinders - 1;
|
||||
dp->dp_ehd = lbl->d_ntracks - 1;
|
||||
dp->dp_esect = lbl->d_nsectors;
|
||||
dp->dp_start = (dp->dp_scyl * lbl->d_ntracks * lbl->d_nsectors) +
|
||||
(dp->dp_shd * lbl->d_nsectors) +
|
||||
dp->dp_ssect - 1;
|
||||
dp->dp_size =
|
||||
(lb->d_nsectors * lb->d_ntracks * lb->d_ncylinders) - dp->dp_start;
|
||||
}
|
||||
(lbl->d_nsectors * lbl->d_ntracks * lbl->d_ncylinders) - dp->dp_start;
|
||||
|
||||
/* Validate partition - XXX need to spend some time making this robust */
|
||||
if (!dp->dp_start) {
|
||||
strcpy(errmsg, "The start address of the selected partition is 0\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Set partition type to FreeBSD and make it the only active partition */
|
||||
|
||||
for (i=0; i < NDOSPART; i++)
|
||||
mbr->dospart[i].dp_flag &= ~ACTIVE;
|
||||
dp->dp_typ = DOSPTYP_386BSD;
|
||||
dp->dp_flag = ACTIVE;
|
||||
|
||||
return(0);
|
||||
dp->dp_typ = DOSPTYP_386BSD;
|
||||
dp->dp_flag = ACTIVE;
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
edit_mbr(struct mbr *mbr, struct disklabel *label)
|
||||
int
|
||||
get_geom_values(int disk)
|
||||
{
|
||||
|
||||
dialog_msgbox("DOS partition table editor",
|
||||
"This editor is still under construction :-)", -1, -1, 1);
|
||||
show_mbr(mbr);
|
||||
WINDOW *window;
|
||||
struct disklabel *lbl = &disk_list[disk].lbl;
|
||||
int key = 0;
|
||||
int cur_field = 0;
|
||||
int next = 0;
|
||||
|
||||
struct field field[] = {
|
||||
{2, 27, 06, 10, 01, 02, 01, -1, -1, "000000"},
|
||||
{4, 27, 06, 10, 02, 00, 02, -1, -1, "000000"},
|
||||
{6, 27, 06, 10, 00, 01, 00, -1, -1, "000000"},
|
||||
{0, 07, 06, 10, -1, -1, -1, -1, -1, "Disk geomtetry parameters"},
|
||||
{2, 02, 06, 10, -1, -1, -1, -1, -1, "Number of cylinders:"},
|
||||
{4, 02, 06, 10, -1, -1, -1, -1, -1, "Number of tracks (heads):"},
|
||||
{6, 02, 06, 10, -1, -1, -1, -1, -1, "Number of sectors:"}
|
||||
};
|
||||
|
||||
if (!(window = newwin(10, 40, 5, 20))) {
|
||||
sprintf(errmsg, "Failed to open window for geometry editor");
|
||||
return (-1);
|
||||
};
|
||||
|
||||
keypad(window, TRUE);
|
||||
|
||||
dialog_clear();
|
||||
draw_box(window, 0, 0, 9, 40, dialog_attr, border_attr);
|
||||
|
||||
while (key != ESC) {
|
||||
sprintf(field[0].field, "%ld", lbl->d_ncylinders);
|
||||
sprintf(field[1].field, "%ld", lbl->d_ntracks);
|
||||
sprintf(field[2].field, "%ld", lbl->d_nsectors);
|
||||
|
||||
disp_fields(window, field, sizeof(field)/sizeof(struct field));
|
||||
key = edit_line(window, field[cur_field].y, field[cur_field].x,
|
||||
field[cur_field].field, field[cur_field].width,
|
||||
field[cur_field].maxlen);
|
||||
next = change_field(field[cur_field], key);
|
||||
if (next == -1)
|
||||
beep();
|
||||
else
|
||||
cur_field = next;
|
||||
|
||||
lbl->d_ncylinders = atoi(field[0].field);
|
||||
lbl->d_ntracks = atoi(field[1].field);
|
||||
lbl->d_nsectors = atoi(field[2].field);
|
||||
}
|
||||
|
||||
delwin(window);
|
||||
refresh();
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
Fdisk()
|
||||
int
|
||||
edit_mbr(int disk)
|
||||
{
|
||||
int i, j, done=0, diskno, flag;
|
||||
char buf[128];
|
||||
struct dos_partition dp[NDOSPART];
|
||||
struct disklabel *lbl;
|
||||
u_long cyl, hd, sec, tsec;
|
||||
u_long l, l1, l2, l3, l4;
|
||||
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, "Enter number of disk to Fdisk> ", buf, 2);
|
||||
printf("%d", i);
|
||||
if(i != '\n' && i != '\r') return;
|
||||
diskno = atoi(buf);
|
||||
if(!(diskno >= 0 && diskno < MAX_NO_DISKS && Dname[diskno])) return;
|
||||
lbl = Dlbl[diskno];
|
||||
lbl->d_bbsize = 8192;
|
||||
cyl = lbl->d_ncylinders;
|
||||
hd = lbl->d_ntracks;
|
||||
sec = lbl->d_nsectors;
|
||||
tsec = Dlbl[diskno]->d_partitions[RAWPART].p_size;
|
||||
cyl = tsec/(hd*sec);
|
||||
read_dospart(Dfd[diskno], dp);
|
||||
while(!done) {
|
||||
clear(); standend();
|
||||
j = 0;
|
||||
mvprintw(j++, 0, "%s -- Diskspace editor -- FDISK", TITLE);
|
||||
j++;
|
||||
mvprintw(j++, 0,
|
||||
"Geometry: %lu Cylinders, %lu Heads, %lu Sectors, %luMb",
|
||||
cyl, hd, sec, (tsec+1024)/2048);
|
||||
j++;
|
||||
for(i=0;i<NDOSPART;i++, j+=3) {
|
||||
mvprintw(j++, 0, "%d ", i+1);
|
||||
#if 0
|
||||
printw("[%02x %02x %02x %02x %02x %02x %02x %02x %08lx %08lx]\n",
|
||||
dp[i].dp_flag, dp[i].dp_shd, dp[i].dp_ssect, dp[i].dp_scyl,
|
||||
dp[i].dp_typ, dp[i].dp_ehd, dp[i].dp_esect, dp[i].dp_ecyl,
|
||||
dp[i].dp_start, dp[i].dp_size);
|
||||
#endif
|
||||
if(!dp[i].dp_size) {
|
||||
printw("Unused");
|
||||
continue;
|
||||
}
|
||||
printw("Boot?=%s", dp[i].dp_flag == 0x80 ? "Yes" : "No ");
|
||||
printw(" Type=%s\n", part_type(dp[i].dp_typ));
|
||||
printw(" Phys=(c%d/h%d/s%d..c%d/h%d/s%d)",
|
||||
DPCYL(dp[i].dp_scyl, dp[i].dp_ssect), dp[i].dp_shd,
|
||||
DPSECT(dp[i].dp_ssect),
|
||||
DPCYL(dp[i].dp_ecyl, dp[i].dp_esect), dp[i].dp_ehd,
|
||||
DPSECT(dp[i].dp_esect));
|
||||
printw(" Sector=(%lu..%lu)\n",
|
||||
dp[i].dp_start, dp[i].dp_size + dp[i].dp_start-1);
|
||||
printw(" Size=%lu MB, %lu Cylinders", (dp[i].dp_size+1024L)/2048L,
|
||||
dp[i].dp_size/lbl->d_secpercyl);
|
||||
l = dp[i].dp_size%lbl->d_secpercyl;
|
||||
if(l) {
|
||||
printw(" + %lu Tracks", l/lbl->d_nsectors);
|
||||
l = l % lbl->d_nsectors;
|
||||
if(l) {
|
||||
printw(" + %lu Sectors", l);
|
||||
WINDOW *window;
|
||||
int cur_field;
|
||||
int i;
|
||||
int ok;
|
||||
int next;
|
||||
int key = 0;
|
||||
struct mbr *mbr = &disk_list[disk].mbr;
|
||||
|
||||
/* Confirm disk parameters */
|
||||
|
||||
if (get_geom_values(disk) == -1)
|
||||
return(-1);
|
||||
|
||||
/* Read MBR from disk */
|
||||
|
||||
sprintf(scratch, "/dev/r%s%dd", disk_list[disk].devconf->dc_name,
|
||||
disk_list[disk].devconf->dc_unit);
|
||||
if (read_mbr(scratch, &disk_list[disk].mbr) == -1) {
|
||||
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);
|
||||
if (!dialog_yesno(TITLE,
|
||||
"Are you sure you wish to proceed ?",
|
||||
10, 75)) {
|
||||
dialog_clear();
|
||||
if (dedicated_mbr(mbr, boot1, &disk_list[disk].lbl) == -1) {
|
||||
sprintf(scratch, "\n\nCouldn't create new master boot record.\n\n%s", errmsg);
|
||||
return(-1);
|
||||
}
|
||||
ok = 1;
|
||||
}
|
||||
dialog_clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
mvprintw(21, 0, "Commands available:");
|
||||
mvprintw(22, 0, "(H)elp (D)elete (E)dit (R)eread Write (B)ootcode (W)rite (Q)uit");
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i=getch();
|
||||
switch(i) {
|
||||
|
||||
case 'h': case 'H':
|
||||
ShowFile(HELPME_FILE,"Help file for disklayout");
|
||||
break;
|
||||
|
||||
case 'r': case 'R':
|
||||
read_dospart(Dfd[diskno], dp);
|
||||
break;
|
||||
|
||||
case 'b': case 'B':
|
||||
write_bootcode(Dfd[diskno]);
|
||||
break;
|
||||
|
||||
case 'e': case 'E':
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, "Edit which Slice> ", buf, 2);
|
||||
if(i != '\n' && i != '\r') break;
|
||||
l = strtol(buf, 0, 0);
|
||||
if(l < 1 || l > NDOSPART) break;
|
||||
l1=sec; l2=tsec;
|
||||
for(i=0;i<NDOSPART;i++) {
|
||||
if((i+1) == l) continue;
|
||||
if(!dp[i].dp_size) continue;
|
||||
if(dp[i].dp_start > l2) continue;
|
||||
if((dp[i].dp_start + dp[i].dp_size) <= l1) continue;
|
||||
if(dp[i].dp_start > l1)
|
||||
l3 = dp[i].dp_start - l1;
|
||||
else
|
||||
l3 = 0;
|
||||
if(l2 > (dp[i].dp_start + dp[i].dp_size))
|
||||
l4 = l2 - (dp[i].dp_start + dp[i].dp_size);
|
||||
else
|
||||
l4 = 0;
|
||||
if(l3 >= l4)
|
||||
l2 = dp[i].dp_start;
|
||||
else
|
||||
l1 = dp[i].dp_start + dp[i].dp_size;
|
||||
}
|
||||
sprintf(buf, "%lu", (l2-l1+1024L)/2048L);
|
||||
i = AskEm(stdscr, "Size of slice in MB> ", buf, 10);
|
||||
l3=strtol(buf, 0, 0) * 2048L;
|
||||
if(!l3) break;
|
||||
if(l3 > l2-l1)
|
||||
l3 = l2-l1;
|
||||
if((l1+l3) % lbl->d_secpercyl) { /* Special for cyl==0 */
|
||||
l3 += lbl->d_secpercyl - ((l1+l3) % lbl->d_secpercyl);
|
||||
}
|
||||
if(l3+l1 > tsec)
|
||||
l3 = tsec - l1;
|
||||
dp[l-1].dp_start=l1;
|
||||
dp[l-1].dp_size=l3;
|
||||
|
||||
l3 += l1 - 1;
|
||||
|
||||
l2 = l1 / (sec*hd);
|
||||
if(l2>1023) l2 = 1023;
|
||||
dp[l-1].dp_scyl = (l2 & 0xff);
|
||||
dp[l-1].dp_ssect = (l2 >> 2) & 0xc0;
|
||||
l1 -= l2*sec*hd;
|
||||
l2 = l1 / sec;
|
||||
dp[l-1].dp_shd = l2;
|
||||
l1 -= l2*sec;
|
||||
dp[l-1].dp_ssect |= (l1+1) & 0x3f;
|
||||
|
||||
l2 = l3 / (sec*hd);
|
||||
if(l2>1023) l2 = 1023;
|
||||
dp[l-1].dp_ecyl = (l2 & 0xff);
|
||||
dp[l-1].dp_esect = (l2 >> 2) & 0xc0;
|
||||
l3 -= l2*sec*hd;
|
||||
l2 = l3 / sec;
|
||||
dp[l-1].dp_ehd = l2;
|
||||
l3 -= l2*sec;
|
||||
dp[l-1].dp_esect |= (l3+1) & 0x3f;
|
||||
|
||||
l4 = dp[l-1].dp_typ;
|
||||
if(!l4) l4 = MBR_PTYPE_FreeBSD;
|
||||
sprintf(buf, "0x%lx", l4);
|
||||
i = AskEm(stdscr, "Type of slice (0xa5=FreeBSD)> ", buf, 5);
|
||||
l3 = strtol(buf, 0, 0);
|
||||
if(l3 == MBR_PTYPE_FreeBSD) {
|
||||
for(i=0;i<NDOSPART;i++)
|
||||
if(i != (l-1) && dp[i].dp_typ== MBR_PTYPE_FreeBSD)
|
||||
memset(&dp[i], 0, sizeof dp[i]);
|
||||
sprintf(buf, "0x80");
|
||||
} else {
|
||||
sprintf(buf, "0");
|
||||
}
|
||||
dp[l-1].dp_typ=l3;
|
||||
i = AskEm(stdscr, "Bootflag (0x80 for YES)> ", buf, 5);
|
||||
dp[l-1].dp_flag=strtol(buf, 0, 0);
|
||||
if(dp[l-1].dp_flag)
|
||||
for(i=0;i<NDOSPART;i++)
|
||||
if(i != (l-1))
|
||||
dp[i].dp_flag = 0;
|
||||
break;
|
||||
|
||||
case 'd': case 'D':
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, "Delete which Slice> ", buf, 2);
|
||||
if(i != '\n' && i != '\r') break;
|
||||
l = strtol(buf, 0, 0);
|
||||
if(l < 1 || l > NDOSPART) break;
|
||||
memset(&dp[l-1], 0, sizeof dp[l-1]);
|
||||
break;
|
||||
|
||||
case 'w': case 'W':
|
||||
strcpy(buf, "N");
|
||||
i = AskEm(stdscr, "Confirm write> ", buf, 2);
|
||||
if(*buf != 'y' && *buf != 'Y') break;
|
||||
write_dospart(Dfd[diskno], dp);
|
||||
Dlbl[diskno]->d_partitions[OURPART].p_offset = 0;
|
||||
Dlbl[diskno]->d_partitions[OURPART].p_size = 0;
|
||||
for(i=0;i<NDOSPART;i++) {
|
||||
if(dp[i].dp_typ == MBR_PTYPE_FreeBSD) {
|
||||
Dlbl[diskno]->d_partitions[OURPART].p_offset =
|
||||
dp[i].dp_start;
|
||||
Dlbl[diskno]->d_partitions[OURPART].p_size =
|
||||
dp[i].dp_size;
|
||||
sprintf(scratch, "Do you wish to dedicate the whole disk to FreeBSD?\n\nDoing so will overwrite any existing data on the disk.");
|
||||
dialog_clear();
|
||||
if (!dialog_yesno(TITLE, scratch, 10, 75))
|
||||
if (dedicated_mbr(mbr, boot1, &disk_list[disk].lbl) == -1) {
|
||||
sprintf(scratch, "\n\nCouldn't dedicate disk to FreeBSD.\n\n %s", errmsg);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
Dlbl[diskno]->d_magic = DISKMAGIC;
|
||||
Dlbl[diskno]->d_magic2 = DISKMAGIC;
|
||||
Dlbl[diskno]->d_checksum = 0;
|
||||
Dlbl[diskno]->d_checksum = dkcksum(Dlbl[diskno]);
|
||||
flag=1;
|
||||
enable_label(Dfd[diskno]);
|
||||
if(ioctl(Dfd[diskno], DIOCSDINFO, Dlbl[diskno]) == -1)
|
||||
AskAbort("Couldn't set label: %s", strerror(errno));
|
||||
if(ioctl(Dfd[diskno], DIOCWDINFO, Dlbl[diskno]) == -1)
|
||||
AskAbort("Couldn't write label: %s", strerror(errno));
|
||||
flag=0;
|
||||
disable_label(Dfd[diskno]);
|
||||
|
||||
if (Dlbl[diskno]->d_partitions[OURPART].p_size)
|
||||
build_bootblocks(Dfd[diskno], lbl, dp);
|
||||
break;
|
||||
|
||||
case 'q': case 'Q':
|
||||
return;
|
||||
break;
|
||||
/* Fill in fields with mbr data */
|
||||
|
||||
|
||||
if (!(window = newwin(24, 79, 0, 0))) {
|
||||
sprintf(errmsg, "Failed to open window for MBR editor\n");
|
||||
return (-1);
|
||||
};
|
||||
|
||||
keypad(window, TRUE);
|
||||
|
||||
dialog_clear();
|
||||
draw_box(window, 0, 0, 24, 79, dialog_attr, border_attr);
|
||||
|
||||
cur_field = 1;
|
||||
while (key != ESC) {
|
||||
for (i=0; i < NDOSPART; i++) {
|
||||
sprintf(mbr_field[(i*12)+1].field, "%s", part_type(mbr->dospart[i].dp_typ));
|
||||
sprintf(mbr_field[(i*12)+2].field, "%ld", mbr->dospart[i].dp_start);
|
||||
sprintf(mbr_field[(i*12)+3].field, "%d", mbr->dospart[i].dp_scyl);
|
||||
sprintf(mbr_field[(i*12)+4].field, "%d", mbr->dospart[i].dp_shd);
|
||||
sprintf(mbr_field[(i*12)+5].field, "%d", mbr->dospart[i].dp_ssect);
|
||||
sprintf(mbr_field[(i*12)+6].field, "%d", 0);
|
||||
sprintf(mbr_field[(i*12)+7].field, "%d", mbr->dospart[i].dp_ecyl);
|
||||
sprintf(mbr_field[(i*12)+8].field, "%d", mbr->dospart[i].dp_ehd);
|
||||
sprintf(mbr_field[(i*12)+9].field, "%d", mbr->dospart[i].dp_esect);
|
||||
sprintf(mbr_field[(i*12)+10].field, "%ld", mbr->dospart[i].dp_size);
|
||||
sprintf(mbr_field[(i*12)+11].field, "%d", sectstoMb(mbr->dospart[i].dp_size, 512));
|
||||
sprintf(mbr_field[(i*12)+12].field, "%d", mbr->dospart[i].dp_flag);
|
||||
}
|
||||
|
||||
disp_fields(window, mbr_field, sizeof(mbr_field)/sizeof(struct field));
|
||||
key = edit_line(window, mbr_field[cur_field].y, mbr_field[cur_field].x,
|
||||
mbr_field[cur_field].field, mbr_field[cur_field].width,
|
||||
mbr_field[cur_field].maxlen);
|
||||
|
||||
/* Propagate changes to MBR */
|
||||
for (i=0; i < NDOSPART; i++) {
|
||||
mbr->dospart[i].dp_start = atoi(mbr_field[(i*12)+2].field);
|
||||
mbr->dospart[i].dp_scyl = atoi(mbr_field[(i*12)+3].field);
|
||||
mbr->dospart[i].dp_shd = atoi(mbr_field[(i*12)+4].field);
|
||||
mbr->dospart[i].dp_ssect = atoi(mbr_field[(i*12)+5].field);
|
||||
mbr->dospart[i].dp_ecyl = atoi(mbr_field[(i*12)+7].field);
|
||||
mbr->dospart[i].dp_ehd = atoi(mbr_field[(i*12)+8].field);
|
||||
mbr->dospart[i].dp_esect = atoi(mbr_field[(i*12)+9].field);
|
||||
mbr->dospart[i].dp_size = atoi(mbr_field[(i*12)+10].field);
|
||||
}
|
||||
|
||||
next = change_field(mbr_field[cur_field], key);
|
||||
if (next == -1)
|
||||
beep();
|
||||
else
|
||||
cur_field = next;
|
||||
}
|
||||
|
||||
sprintf(scratch, "Writing a new master boot record can erase the current disk contents.\n\n Are you sure you want to write the new MBR?");
|
||||
dialog_clear();
|
||||
if (!dialog_yesno("Write new MBR?", scratch, 10, 75)) {
|
||||
sprintf(scratch, "/dev/r%s%dd", disk_list[disk].devconf->dc_name,
|
||||
disk_list[disk].devconf->dc_unit);
|
||||
if (write_mbr(scratch, mbr) == -1) {
|
||||
sprintf(scratch, "The following error occured while trying to write the new MBR\n\n%s", errmsg);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
dialog_clear();
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -1,80 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 1994, Paul Richards.
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software may be used, modified, copied, distributed, and
|
||||
* sold, in both source and binary form provided that the above
|
||||
* copyright and these terms are retained, verbatim, as the first
|
||||
* lines of this file. Under no circumstances is the author
|
||||
* responsible for the proper functioning of this software, nor does
|
||||
* the author assume any responsibility for damages incurred with
|
||||
* its use.
|
||||
*/
|
||||
|
||||
#define MBRSIZE 512
|
||||
#define MBR_MAGIC 0xAA55
|
||||
#define ACTIVE 0x80
|
||||
|
||||
struct mbr
|
||||
{
|
||||
unsigned char bootcode[DOSPARTOFF];
|
||||
struct dos_partition dospart[4];
|
||||
unsigned short magic;
|
||||
struct field mbr_field[] = {
|
||||
{ 0, 25, 31, -1, -1, -1, -1, -1, -1, "Master Boot Record (MBR) editor"},
|
||||
{ 4, 8, 30, 30, 2, 36, 2, 13, 13, "Uknown"},
|
||||
{ 5, 31, 7, 10, 3, 1, 3, 14, 14, "0"},
|
||||
{ 6, 5, 5, 10, 4, 2, 6, 17, 17, "0"},
|
||||
{ 6, 14, 5, 10, 5, 2, 6, 17, 15, "0"},
|
||||
{ 6, 24, 5, 10, 6, 2, 6, 17, 15, "0"},
|
||||
{ 7, 31, 7, 10, 7, 3, 7, 18, 18, "0"},
|
||||
{ 8, 5, 5, 10, 8, 6, 10, 22, 8, "0"},
|
||||
{ 8, 14, 5, 10, 9, 6, 10, 22, 9, "0"},
|
||||
{ 8, 24, 5, 10, 10, 6, 10, 22, 19, "0"},
|
||||
{ 9, 9, 6, 10, 11, 7, 12, 24, 11, "0"},
|
||||
{ 9, 27, 5, 10, 12, 7, 12, 24, 22, "0"},
|
||||
{10, 10, 10, 10, 13, 10, 25, 24, 24, "Not Active"},
|
||||
{ 4, 47, 30, 30, 14, 2, 2, 2, 1, "Uknown"},
|
||||
{ 5, 70, 7, 10, 15, 3, 3, 3, 2, "0"},
|
||||
{ 6, 44, 5, 10, 16, 1, 5, 1, 16, "0"},
|
||||
{ 6, 54, 5, 10, 17, 1, 6, 2, 17, "0"},
|
||||
{ 6, 64, 5, 10, 18, 1, 7, 3, 3, "0"},
|
||||
{ 7, 70, 7, 10, 19, 6, 6, 6, 6, "0"},
|
||||
{ 8, 44, 5, 10, 20, 2, 2, 2, 20, "0"},
|
||||
{ 8, 54, 5, 10, 21, 3, 2, 2, 21, "0"},
|
||||
{ 8, 64, 5, 10, 22, 4, 2, 2, 7, "0"},
|
||||
{ 9, 48, 6, 10, 23, 2, 2, 2, 23, "0"},
|
||||
{ 9, 66, 5, 10, 24, 2, 2, 2, 10, "0"},
|
||||
{10, 49, 10, 10, 25, 2, 2, 2, 12, "Not Active"},
|
||||
{14, 8, 30, 30, 26, 12, 26, 2, 14, "Uknown"},
|
||||
{15, 31, 7, 10, 27, 25, 27, 3, 15, "0"},
|
||||
{16, 5, 5, 10, 28, 26, 30, 1, 16, "0"},
|
||||
{16, 14, 5, 10, 29, 26, 30, 2, 16, "0"},
|
||||
{16, 24, 5, 10, 30, 26, 30, 3, 16, "0"},
|
||||
{17, 31, 7, 10, 31, 27, 31, 6, 17, "0"},
|
||||
{18, 5, 5, 10, 32, 30, 34, 2, 2, "0"},
|
||||
{18, 14, 5, 10, 33, 30, 34, 2, 2, "0"},
|
||||
{18, 24, 5, 10, 34, 30, 34, 2, 3, "0"},
|
||||
{19, 9, 6, 10, 35, 31, 36, 2, 2, "0"},
|
||||
{19, 27, 5, 10, 36, 31, 36, 2, 2, "0"},
|
||||
{20, 10, 10, 10, 37, 34, 01, 2, 2, "Not Active"},
|
||||
{14, 47, 30, 30, 38, 2, 2, 2, 4, "Uknown"},
|
||||
{15, 70, 7, 10, 39, 3, 3, 3, 4, "0"},
|
||||
{16, 44, 5, 10, 40, 1, 5, 1, 4, "0"},
|
||||
{16, 54, 5, 10, 41, 1, 6, 2, 5, "0"},
|
||||
{16, 64, 5, 10, 42, 1, 7, 3, 6, "0"},
|
||||
{17, 70, 7, 10, 43, 6, 6, 6, 7, "0"},
|
||||
{18, 44, 5, 10, 44, 2, 2, 2, 2, "0"},
|
||||
{18, 54, 5, 10, 45, 3, 2, 2, 2, "0"},
|
||||
{18, 64, 5, 10, 46, 4, 2, 2, 3, "0"},
|
||||
{19, 48, 6, 10, 47, 2, 2, 2, 2, "0"},
|
||||
{19, 66, 5, 10, 48, 2, 2, 2, 2, "0"},
|
||||
{20, 49, 10, 10, 01, 2, 2, 2, 2, "Not Active"},
|
||||
{2, 15, 11, -1, -1, -1, -1, -1, -1, "Partition 1"},
|
||||
{2, 55, 11, -1, -1, -1, -1, -1, -1, "Partition 2"},
|
||||
{12, 15, 11, -1, -1, -1, -1, -1, -1, "Partition 3"},
|
||||
{12, 55, 11, -1, -1, -1, -1, -1, -1, "Partition 4"},
|
||||
{ 4, 2, 5, -1, -1, -1, -1, -1, -1, "Type:"},
|
||||
{ 5, 2, 28, -1, -1, -1, -1, -1, -1, "Starting at absolute sector:"},
|
||||
{ 6, 2, 2, -1, -1, -1, -1, -1, -1, "C:"},
|
||||
{ 6, 11, 2, -1, -1, -1, -1, -1, -1, "H:"},
|
||||
{ 6, 21, 2, -1, -1, -1, -1, -1, -1, "S:"},
|
||||
{ 7, 2, 26, -1, -1, -1, -1, -1, -1, "Ending at absolute sector:"},
|
||||
{ 8, 2, 2, -1, -1, -1, -1, -1, -1, "C:"},
|
||||
{ 8, 11, 2, -1, -1, -1, -1, -1, -1, "H:"},
|
||||
{ 8, 21, 2, -1, -1, -1, -1, -1, -1, "S:"},
|
||||
{ 9, 02, 7, -1, -1, -1, -1, -1, -1, "Size: ("},
|
||||
{ 9, 18, 8, -1, -1, -1, -1, -1, -1, "sectors)"},
|
||||
{ 9, 33, 2, -1, -1, -1, -1, -1, -1, "Mb"},
|
||||
{10, 2, 7, -1, -1, -1, -1, -1, -1, "Status:"},
|
||||
{ 4, 41, 5, -1, -1, -1, -1, -1, -1, "Type:"},
|
||||
{ 5, 41, 28, -1, -1, -1, -1, -1, -1, "Starting at absolute sector:"},
|
||||
{ 6, 41, 2, -1, -1, -1, -1, -1, -1, "C:"},
|
||||
{ 6, 51, 2, -1, -1, -1, -1, -1, -1, "H:"},
|
||||
{ 6, 61, 2, -1, -1, -1, -1, -1, -1, "S:"},
|
||||
{ 7, 41, 26, -1, -1, -1, -1, -1, -1, "Ending at absolute sector:"},
|
||||
{ 8, 41, 2, -1, -1, -1, -1, -1, -1, "C:"},
|
||||
{ 8, 51, 2, -1, -1, -1, -1, -1, -1, "H:"},
|
||||
{ 8, 61, 2, -1, -1, -1, -1, -1, -1, "S:"},
|
||||
{ 9, 41, 7, -1, -1, -1, -1, -1, -1, "Size: ("},
|
||||
{ 9, 57, 8, -1, -1, -1, -1, -1, -1, "sectors)"},
|
||||
{ 9, 72, 2, -1, -1, -1, -1, -1, -1, "Mb"},
|
||||
{10, 41, 7, -1, -1, -1, -1, -1, -1, "Status:"},
|
||||
{14, 02, 5, -1, -1, -1, -1, -1, -1, "Type:"},
|
||||
{15, 02, 28, -1, -1, -1, -1, -1, -1, "Starting at absolute sector:"},
|
||||
{16, 2, 2, -1, -1, -1, -1, -1, -1, "C:"},
|
||||
{16, 11, 2, -1, -1, -1, -1, -1, -1, "H:"},
|
||||
{16, 21, 2, -1, -1, -1, -1, -1, -1, "S:"},
|
||||
{17, 02, 26, -1, -1, -1, -1, -1, -1, "Ending at absolute sector:"},
|
||||
{18, 02, 2, -1, -1, -1, -1, -1, -1, "C:"},
|
||||
{18, 11, 2, -1, -1, -1, -1, -1, -1, "H:"},
|
||||
{18, 21, 2, -1, -1, -1, -1, -1, -1, "S:"},
|
||||
{19, 02, 7, -1, -1, -1, -1, -1, -1, "Size: ("},
|
||||
{19, 18, 8, -1, -1, -1, -1, -1, -1, "sectors)"},
|
||||
{19, 33, 2, -1, -1, -1, -1, -1, -1, "Mb"},
|
||||
{20, 02, 7, -1, -1, -1, -1, -1, -1, "Status:"},
|
||||
{14, 41, 5, -1, -1, -1, -1, -1, -1, "Type:"},
|
||||
{15, 41, 28, -1, -1, -1, -1, -1, -1, "Starting at absolute sector:"},
|
||||
{16, 41, 2, -1, -1, -1, -1, -1, -1, "C:"},
|
||||
{16, 51, 2, -1, -1, -1, -1, -1, -1, "H:"},
|
||||
{16, 61, 2, -1, -1, -1, -1, -1, -1, "S:"},
|
||||
{17, 41, 26, -1, -1, -1, -1, -1, -1, "Ending at absolute sector:"},
|
||||
{18, 41, 2, -1, -1, -1, -1, -1, -1, "C:"},
|
||||
{18, 51, 2, -1, -1, -1, -1, -1, -1, "H:"},
|
||||
{18, 61, 2, -1, -1, -1, -1, -1, -1, "S:"},
|
||||
{19, 41, 7, -1, -1, -1, -1, -1, -1, "Size: ("},
|
||||
{19, 57, 8, -1, -1, -1, -1, -1, -1, "sectors)"},
|
||||
{19, 72, 2, -1, -1, -1, -1, -1, -1, "Mb"},
|
||||
{20, 41, 7, -1, -1, -1, -1, -1, -1, "Status:"}
|
||||
};
|
||||
|
||||
struct part_type
|
||||
{
|
||||
unsigned char type;
|
||||
char *name;
|
||||
};
|
||||
|
||||
#define PARTITION_TYPES \
|
||||
{ \
|
||||
{0x00, "Unused"} \
|
||||
,{0x01, "Primary DOS with 12 bit FAT"} \
|
||||
,{0x02, "XENIX / filesystem"} \
|
||||
,{0x03, "XENIX /usr filesystem"} \
|
||||
,{0x04, "Primary DOS with 16 bit FAT"} \
|
||||
,{0x05, "Extended DOS"} \
|
||||
,{0x06, "Primary 'big' DOS (> 32MB)"} \
|
||||
,{0x07, "OS/2 HPFS, QNX or Advanced UNIX"} \
|
||||
,{0x08, "AIX filesystem"} \
|
||||
,{0x09, "AIX boot partition or Coherent"} \
|
||||
,{0x0A, "OS/2 Boot Manager or OPUS"} \
|
||||
,{0x10, "OPUS"} \
|
||||
,{0x40, "VENIX 286"} \
|
||||
,{0x50, "DM"} \
|
||||
,{0x51, "DM"} \
|
||||
,{0x52, "CP/M or Microport SysV/AT"} \
|
||||
,{0x56, "GB"} \
|
||||
,{0x61, "Speed"} \
|
||||
,{0x63, "ISC UNIX, other System V/386, GNU HURD or Mach"} \
|
||||
,{0x64, "Novell Netware 2.xx"} \
|
||||
,{0x65, "Novell Netware 3.xx"} \
|
||||
,{0x75, "PCIX"} \
|
||||
,{0x80, "Minix 1.1 ... 1.4a"} \
|
||||
,{0x81, "Minix 1.4b ... 1.5.10"} \
|
||||
,{0x82, "Linux"} \
|
||||
,{0x93, "Amoeba filesystem"} \
|
||||
,{0x94, "Amoeba bad block table"} \
|
||||
,{0xA5, "FreeBSD/NetBSD/386BSD"} \
|
||||
,{0xB7, "BSDI BSD/386 filesystem"} \
|
||||
,{0xB8, "BSDI BSD/386 swap"} \
|
||||
,{0xDB, "Concurrent CPM or C.DOS or CTOS"} \
|
||||
,{0xE1, "Speed"} \
|
||||
,{0xE3, "Speed"} \
|
||||
,{0xE4, "Speed"} \
|
||||
,{0xF1, "Speed"} \
|
||||
,{0xF2, "DOS 3.3+ Secondary"} \
|
||||
,{0xF4, "Speed"} \
|
||||
,{0xFF, "BBT (Bad Blocks Table)"} \
|
||||
};
|
||||
|
||||
extern char *part_type(int);
|
||||
extern int write_mbr(int, struct mbr *);
|
||||
extern int read_mbr(int, struct mbr *);
|
||||
extern void show_mbr(struct mbr *);
|
||||
extern int clear_mbr(struct mbr *, char *);
|
||||
extern void edit_mbr(struct mbr *, struct disklabel *);
|
||||
extern int build_mbr(struct mbr *, char *, struct disklabel *);
|
||||
|
@ -1,5 +1,4 @@
|
||||
/*
|
||||
#define DEBUG
|
||||
* Copyright (c) 1994, Paul Richards.
|
||||
*
|
||||
* All rights reserved.
|
||||
@ -13,13 +12,13 @@
|
||||
* its use.
|
||||
*/
|
||||
|
||||
#include <dialog.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <fstab.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
@ -27,39 +26,36 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/devconf.h>
|
||||
#include <ufs/ffs/fs.h>
|
||||
#include <machine/console.h>
|
||||
|
||||
#include "mbr.h"
|
||||
#include "sysinstall.h"
|
||||
#include "bootarea.h"
|
||||
#include <dialog.h>
|
||||
|
||||
#include "disk.h"
|
||||
#include "sysinstall.h"
|
||||
|
||||
struct disklabel *avail_disklabels;
|
||||
int *avail_fds;
|
||||
unsigned char **options;
|
||||
unsigned char **avail_disknames;
|
||||
unsigned char *scratch;
|
||||
unsigned char *errmsg;
|
||||
unsigned char *bootblocks;
|
||||
struct mbr *mbr;
|
||||
|
||||
int no_disks = 0;
|
||||
int inst_disk = 0;
|
||||
int inst_part = 0;
|
||||
int whole_disk = 0;
|
||||
int custom_install = 0;
|
||||
int dialog_active = 0;
|
||||
|
||||
/* Forward decls */
|
||||
void exit_sysinstall(void);
|
||||
void exit_prompt(void);
|
||||
extern char *part_type(int);
|
||||
void Fdisk(void);
|
||||
void DiskLabel(void);
|
||||
|
||||
char selection[30];
|
||||
char boot1[] = BOOT1;
|
||||
char boot2[] = BOOT2;
|
||||
|
||||
char *device_names[] = {"wd", "sd", "cd", "mcd", 0};
|
||||
struct devconf *device_list[MAX_NO_DEVICES];
|
||||
struct disk disk_list[MAX_NO_DEVICES];
|
||||
|
||||
int no_devices;
|
||||
int no_disks;
|
||||
|
||||
int
|
||||
alloc_memory()
|
||||
@ -74,24 +70,6 @@ alloc_memory()
|
||||
if (!errmsg)
|
||||
return(-1);
|
||||
|
||||
avail_disklabels = (struct disklabel *)calloc(MAX_NO_DISKS,
|
||||
sizeof(struct disklabel));
|
||||
if (!avail_disklabels)
|
||||
return(-1);
|
||||
|
||||
avail_fds = (int *)calloc(MAX_NO_DISKS, sizeof(int));
|
||||
if (!avail_fds)
|
||||
return(-1);
|
||||
|
||||
avail_disknames = (unsigned char **)calloc(MAX_NO_DISKS, sizeof(char *));
|
||||
if (!avail_disknames)
|
||||
return(-1);
|
||||
for (i = 0; i < MAX_NO_DISKS; i++) {
|
||||
avail_disknames[i] = (char *)calloc(15, sizeof(char));
|
||||
if (!avail_disknames[i])
|
||||
return(-1);
|
||||
}
|
||||
|
||||
options = (unsigned char **)calloc(MAX_NO_DISKS, sizeof(char *));
|
||||
if (!options)
|
||||
return(-1);
|
||||
@ -101,374 +79,256 @@ alloc_memory()
|
||||
return(-1);
|
||||
}
|
||||
|
||||
mbr = (struct mbr *)malloc(sizeof(struct mbr));
|
||||
if (!mbr)
|
||||
return(-1);
|
||||
|
||||
bootblocks = (char *)malloc(BBSIZE);
|
||||
if (!bootblocks)
|
||||
return(-1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
free_memory()
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
free(scratch);
|
||||
free(errmsg);
|
||||
free(avail_disklabels);
|
||||
free(avail_fds);
|
||||
free(scratch);
|
||||
free(errmsg);
|
||||
|
||||
for (i = 0; i < MAX_NO_DISKS; i++)
|
||||
free(avail_disknames[i]);
|
||||
free(avail_disknames);
|
||||
|
||||
for (i = 0; i < MAX_NO_DISKS; i++)
|
||||
free(options[i]);
|
||||
free(options);
|
||||
|
||||
free(mbr);
|
||||
free(bootblocks);
|
||||
for (i = 0; i < MAX_NO_DEVICES; i++)
|
||||
free(device_list[i]);
|
||||
}
|
||||
|
||||
|
||||
char * device_list[] = {"wd","sd",0};
|
||||
|
||||
void
|
||||
query_disks()
|
||||
int
|
||||
query_devices()
|
||||
{
|
||||
int i,j;
|
||||
char disk[15];
|
||||
char diskname[5];
|
||||
struct stat st;
|
||||
struct disklabel dl;
|
||||
int fd;
|
||||
int i, j;
|
||||
int size, osize;
|
||||
int ndevs;
|
||||
int mib[8];
|
||||
struct devconf *dev;
|
||||
|
||||
for(i = 0; i < MAX_NO_DISKS; i++)
|
||||
if(Dname[i]) {
|
||||
close(Dfd[i]); Dfd[i] = 0;
|
||||
free(Dlbl[i]); Dlbl[i] = 0;
|
||||
free(Dname[i]); Dname[i] = 0;
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_DEVCONF;
|
||||
mib[2] = DEVCONF_NUMBER;
|
||||
|
||||
size = sizeof ndevs;
|
||||
if (sysctl(mib, 3, &ndevs, &size, 0, 0) < 0) {
|
||||
sprintf(errmsg, "Couldn't get device info from kernel\n");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
Ndisk = 0;
|
||||
dev = 0; osize = 0;
|
||||
|
||||
for (j = 0; device_list[j]; j++) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
sprintf(diskname, "%s%d", device_list[j], i);
|
||||
sprintf(disk, "/dev/r%sd", diskname);
|
||||
if (stat(disk, &st) || !(st.st_mode & S_IFCHR))
|
||||
continue;
|
||||
if ((fd = open(disk, O_RDWR)) == -1)
|
||||
continue;
|
||||
if (ioctl(fd, DIOCGDINFO, &dl) == -1) {
|
||||
close(fd);
|
||||
continue;
|
||||
}
|
||||
Dlbl[Ndisk] = Malloc(sizeof dl);
|
||||
memcpy(Dlbl[Ndisk], &dl, sizeof dl);
|
||||
Dname[Ndisk] = StrAlloc(diskname);
|
||||
Dfd[Ndisk] = fd;
|
||||
Ndisk++;
|
||||
if(Ndisk == MAX_NO_DISKS)
|
||||
return;
|
||||
for (i=0; i <= ndevs; i++) {
|
||||
mib[2] = i;
|
||||
if (sysctl(mib, 3, 0, &size, 0, 0) < 0)
|
||||
/* Probably deleted device */
|
||||
continue;
|
||||
if (size > osize) {
|
||||
dev = realloc(dev, size);
|
||||
if (!dev) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't allocate memory for device information\n");
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
osize = size;
|
||||
|
||||
if (sysctl(mib, 3, dev, &size, 0, 0) < 0) {
|
||||
sprintf(errmsg, "Error getting information on device %d\n", i);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
for (j=0; device_names[j]; j++)
|
||||
if (!strcmp(device_names[j], dev->dc_name)) {
|
||||
device_list[no_devices++] = dev;
|
||||
dev = 0; osize = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
select_disk()
|
||||
{
|
||||
int i;
|
||||
int valid;
|
||||
char *disk_names[] = {"wd", "sd", 0};
|
||||
char diskname[20];
|
||||
int i, j;
|
||||
int fd;
|
||||
int valid=0;
|
||||
int choice;
|
||||
|
||||
do {
|
||||
valid = 1;
|
||||
sprintf(scratch,"There are %d disks available for installation: ",
|
||||
no_disks);
|
||||
/* Search for possible installation targets */
|
||||
no_disks = 0;
|
||||
for (i=0; i < no_devices; i++)
|
||||
for (j=0; disk_names[j]; j++)
|
||||
if (!strcmp(disk_names[j], device_list[i]->dc_name)) {
|
||||
/* Try getting drive info */
|
||||
sprintf(diskname, "/dev/r%s%dd",
|
||||
device_list[i]->dc_name,
|
||||
device_list[i]->dc_unit);
|
||||
if ((fd = open(diskname, O_RDONLY)) == -1)
|
||||
continue;
|
||||
if (ioctl(fd, DIOCGDINFO, &disk_list[no_disks].lbl) == -1) {
|
||||
close(fd);
|
||||
continue;
|
||||
}
|
||||
disk_list[no_disks++].devconf = device_list[i];
|
||||
close(fd);
|
||||
}
|
||||
|
||||
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(&avail_disklabels[i]),
|
||||
avail_disknames[i]);
|
||||
}
|
||||
do {
|
||||
if (no_disks == 1)
|
||||
sprintf(scratch,"There is %d disk available for installation: ",
|
||||
no_disks);
|
||||
else
|
||||
sprintf(scratch,"There are %d disks available for installation: ",
|
||||
no_disks);
|
||||
|
||||
if (dialog_menu("FreeBSD Installation", scratch, -1, -1, 5, no_disks,
|
||||
options, selection)) {
|
||||
dialog_clear_norefresh();
|
||||
sprintf(scratch,"\n\n\nYou did not select a valid disk.\n\n");
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
}
|
||||
dialog_clear();
|
||||
} while (!valid);
|
||||
return(atoi(selection) - 1);
|
||||
for (i = 0; i < no_disks; i++) {
|
||||
sprintf(options[(i*2)], "%d",i+1);
|
||||
if (disk_list[i].selected)
|
||||
sprintf(options[(i*2)+1], " ** %s, (%dMb) -> %s%d",
|
||||
disk_list[i].lbl.d_typename,
|
||||
disk_size(&disk_list[i].lbl),
|
||||
disk_list[i].devconf->dc_name,
|
||||
disk_list[i].devconf->dc_unit);
|
||||
else
|
||||
sprintf(options[(i*2)+1], " %s, (%dMb) -> %s%d",
|
||||
disk_list[i].lbl.d_typename,
|
||||
disk_size(&disk_list[i].lbl),
|
||||
disk_list[i].devconf->dc_name,
|
||||
disk_list[i].devconf->dc_unit);
|
||||
}
|
||||
|
||||
sprintf(options[no_disks*2], "%d", no_disks+1);
|
||||
sprintf(options[(no_disks*2)+1], " Done");
|
||||
|
||||
dialog_clear();
|
||||
if (dialog_menu("FreeBSD Installation", scratch, 10, 75, 5, no_disks+1,
|
||||
options, selection)) {
|
||||
dialog_clear();
|
||||
sprintf(scratch,"\n\n\nYou selected cancel\n\n");
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
}
|
||||
|
||||
dialog_clear();
|
||||
|
||||
choice = atoi(selection);
|
||||
if (choice == no_disks+1)
|
||||
valid = 1;
|
||||
else
|
||||
if (disk_list[choice-1].selected)
|
||||
disk_list[choice-1].selected = 0;
|
||||
else
|
||||
disk_list[choice-1].selected = 1;
|
||||
} while (!valid);
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
configure_disks()
|
||||
{
|
||||
int i;
|
||||
int items;
|
||||
int choice;
|
||||
int valid=0;
|
||||
int disks[MAX_NO_DEVICES];
|
||||
|
||||
do {
|
||||
sprintf(scratch, "Select disk to configure");
|
||||
|
||||
items = 0;
|
||||
for (i = 0; i < no_disks; i++) {
|
||||
if (disk_list[i].selected) {
|
||||
sprintf(options[(items*2)], "%d",items+1);
|
||||
sprintf(options[(items*2)+1], "%s%d",
|
||||
disk_list[i].devconf->dc_name,
|
||||
disk_list[i].devconf->dc_unit);
|
||||
disks[items] = i;
|
||||
items++;
|
||||
}
|
||||
}
|
||||
|
||||
sprintf(options[items*2], "%d", items+1);
|
||||
sprintf(options[(items*2)+1], "Done");
|
||||
items++;
|
||||
|
||||
if (dialog_menu("FreeBSD Installation", scratch, 10, 75, 5, items,
|
||||
options, selection)) {
|
||||
dialog_clear();
|
||||
sprintf(scratch,"\n\n\nYou selected cancel\n\n");
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
}
|
||||
dialog_clear();
|
||||
choice = atoi(selection);
|
||||
if (choice == items)
|
||||
valid = 1;
|
||||
else {
|
||||
if (edit_mbr(disks[choice-1]) == -1) {
|
||||
sprintf(scratch, "The following error occured while\nediting the master boot record.\n\n%s", errmsg);
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
};
|
||||
disk_list[disks[choice-1]].inst_part = select_partition(disks[choice-1]);
|
||||
if (edit_disklabel(disks[choice-1]) == -1) {
|
||||
sprintf(scratch, "The following error occured while\nediting the disklabel.\n\n%s", errmsg);
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
}
|
||||
}
|
||||
} while (!valid);
|
||||
|
||||
}
|
||||
int
|
||||
select_partition(int disk)
|
||||
{
|
||||
int valid;
|
||||
int i;
|
||||
int choice;
|
||||
|
||||
|
||||
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(&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)",
|
||||
part_type(mbr->dospart[i].dp_typ),
|
||||
mbr->dospart[i].dp_size * 512 / (1024 * 1024));
|
||||
}
|
||||
if (dialog_menu(TITLE,
|
||||
scratch, -1, -1, 5, 5, options, selection)) {
|
||||
sprintf(scratch,"You did not select a valid partition");
|
||||
dialog_clear_norefresh();
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
}
|
||||
dialog_clear();
|
||||
choice = atoi(selection) - 1;
|
||||
if (choice == -1) {
|
||||
whole_disk = 1;
|
||||
choice = 0;
|
||||
if (dialog_yesno(TITLE, "\n\nInstalling to the whole disk will erase all its current data.\n\nAre you sure you want to do this?", -1, -1)) {
|
||||
valid = 0;
|
||||
whole_disk = 0;
|
||||
}
|
||||
}
|
||||
dialog_clear();
|
||||
valid = 1;
|
||||
|
||||
sprintf(scratch,"Select one of the following areas to install to:");
|
||||
for (i=0; i < NDOSPART; i++) {
|
||||
sprintf(options[(i*2)], "%d",i+1);
|
||||
sprintf(options[(i*2)+1], "%s, (%ldMb)",
|
||||
part_type(disk_list[disk].mbr.dospart[i].dp_typ),
|
||||
disk_list[disk].mbr.dospart[i].dp_size * 512 / (1024 * 1024));
|
||||
}
|
||||
if (dialog_menu(TITLE,
|
||||
scratch, 10, 75, 4, 4, options, selection)) {
|
||||
sprintf(scratch,"You did not select a valid partition");
|
||||
dialog_clear();
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
}
|
||||
dialog_clear();
|
||||
choice = atoi(selection) - 1;
|
||||
} while (!valid);
|
||||
return(choice);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
stage1()
|
||||
{
|
||||
int i,j;
|
||||
int ret=1;
|
||||
int i;
|
||||
int ok = 0;
|
||||
int ready = 0;
|
||||
int foundroot=0,foundusr=0,foundswap=0;
|
||||
char *complaint=0;
|
||||
|
||||
query_disks();
|
||||
/*
|
||||
* Try to be intelligent about this and assign some mountpoints
|
||||
*/
|
||||
#define LEGAL(disk,part) ( \
|
||||
Dlbl[disk]->d_partitions[part].p_size && \
|
||||
(Dlbl[disk]->d_partitions[part].p_offset >= \
|
||||
Dlbl[disk]->d_partitions[OURPART].p_offset) && \
|
||||
((Dlbl[disk]->d_partitions[part].p_size + \
|
||||
Dlbl[disk]->d_partitions[part].p_offset) <= \
|
||||
(Dlbl[disk]->d_partitions[OURPART].p_offset + \
|
||||
Dlbl[disk]->d_partitions[OURPART].p_size)))
|
||||
|
||||
for(i = 0; i < MAX_NO_DISKS && Dname[i]; i++) {
|
||||
if (Dlbl[i]->d_partitions[OURPART].p_size == 0)
|
||||
break;
|
||||
if (!foundroot && LEGAL(i,0) &&
|
||||
Dlbl[i]->d_partitions[0].p_fstype == FS_BSDFFS) {
|
||||
SetMount(i,0,"/");
|
||||
foundroot++;
|
||||
}
|
||||
if (!foundswap && LEGAL(i,1) &&
|
||||
Dlbl[i]->d_partitions[1].p_fstype == FS_SWAP) {
|
||||
SetMount(i,1,"swap");
|
||||
foundswap++;
|
||||
}
|
||||
if (!foundusr && LEGAL(i,4) &&
|
||||
Dlbl[i]->d_partitions[4].p_fstype == FS_BSDFFS) {
|
||||
SetMount(i,4,"/usr");
|
||||
foundusr++;
|
||||
}
|
||||
}
|
||||
while (!ready) {
|
||||
clear(); standend();
|
||||
j = 0;
|
||||
mvprintw(j++, 0, "%s -- Diskspace editor", TITLE);
|
||||
j++;
|
||||
mvprintw(j++, 0, "Disks Total FreeBSD ");
|
||||
j++;
|
||||
for(i = 0; i < MAX_NO_DISKS && Dname[i]; i++) {
|
||||
mvprintw(j++, 0, "%2d: %-6s %5lu MB %5lu MB",
|
||||
i,
|
||||
Dname[i],
|
||||
PartMb(Dlbl[i],RAWPART),
|
||||
PartMb(Dlbl[i],OURPART));
|
||||
}
|
||||
j++;
|
||||
mvprintw(j++, 0, "Filesystems Type Size Mountpoint");
|
||||
j++;
|
||||
for(i = 0; i < MAX_NO_FS; i++) {
|
||||
if(!Fname[i])
|
||||
continue;
|
||||
mvprintw(j++, 0, "%2d: %-5s %-5s %5lu MB %-s",
|
||||
i, Fname[i], Ftype[i], Fsize[i], Fmount[i]);
|
||||
query_devices();
|
||||
|
||||
while (!ok) {
|
||||
select_disk();
|
||||
for (i=0; i < no_disks; i++)
|
||||
if (disk_list[i].selected)
|
||||
ok = 1;
|
||||
if (!ok) {
|
||||
sprintf(scratch, "You did not select any disks to install to.");
|
||||
AskAbort(scratch);
|
||||
}
|
||||
}
|
||||
|
||||
mvprintw(21, 0, "Commands available:");
|
||||
mvprintw(22, 0, "(H)elp (F)disk (D)isklabel (P)roceed (Q)uit");
|
||||
if(complaint) {
|
||||
standout();
|
||||
mvprintw(24, 0, complaint);
|
||||
standend();
|
||||
complaint = 0;
|
||||
}
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i = getch();
|
||||
switch(i) {
|
||||
case 'h': case 'H':
|
||||
ShowFile(HELPME_FILE,"Help file for disklayout");
|
||||
break;
|
||||
case 'p': case 'P':
|
||||
foundroot=0,foundusr=0,foundswap=0;
|
||||
for (i = 1; Fmount[i]; i++) {
|
||||
if(!strcmp(Fmount[i],"/")) foundroot=i;
|
||||
if(!strcmp(Fmount[i],"swap")) foundswap=i;
|
||||
if(!strcmp(Fmount[i],"/usr")) foundusr=i;
|
||||
}
|
||||
if (!foundroot) {
|
||||
complaint = "You must assign something to mount on '/'";
|
||||
break;
|
||||
}
|
||||
if (!foundroot) {
|
||||
complaint = "You must assign something to mount on 'swap'";
|
||||
break;
|
||||
}
|
||||
if (!foundusr && Fsize[foundroot] < 80) {
|
||||
complaint = "You must assign something to mount on '/usr'";
|
||||
break;
|
||||
}
|
||||
ret = 0;
|
||||
goto leave;
|
||||
case 'q': case 'Q':
|
||||
ret = 1;
|
||||
goto leave;
|
||||
case 'f': case 'F':
|
||||
Fdisk();
|
||||
query_disks();
|
||||
break;
|
||||
case 'd': case 'D':
|
||||
DiskLabel();
|
||||
break;
|
||||
default:
|
||||
beep();
|
||||
}
|
||||
}
|
||||
leave:
|
||||
clear();
|
||||
for (i = 0; Dname[i]; i++)
|
||||
close(Dfd[i]);
|
||||
return ret;
|
||||
configure_disks();
|
||||
exit(1);
|
||||
}
|
||||
#if 0
|
||||
while (!ready) {
|
||||
ready = 1;
|
||||
|
||||
inst_disk = select_disk();
|
||||
|
||||
if (read_mbr(avail_fds[inst_disk], mbr) == -1) {
|
||||
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);
|
||||
if (!dialog_yesno(TITLE,
|
||||
"Are you sure you wish to proceed?",
|
||||
-1, -1)) {
|
||||
dialog_clear_norefresh();
|
||||
if (clear_mbr(mbr, boot1) == -1) {
|
||||
sprintf(scratch, "\n\nCouldn't create new master boot record.\n\n%s", errmsg);
|
||||
Fatal(scratch);;
|
||||
}
|
||||
ok = 1;
|
||||
}
|
||||
dialog_clear();
|
||||
}
|
||||
}
|
||||
if (custom_install)
|
||||
if (!dialog_yesno(TITLE, "Do you wish to edit the DOS partition table?",
|
||||
-1, -1)) {
|
||||
dialog_clear_norefresh();
|
||||
edit_mbr(mbr, &avail_disklabels[inst_disk]);
|
||||
}
|
||||
|
||||
dialog_clear_norefresh();
|
||||
inst_part = select_partition(inst_disk);
|
||||
|
||||
ok = 0;
|
||||
while (!ok) {
|
||||
if (build_mbr(mbr, boot1, &avail_disklabels[inst_disk]) != -1) {
|
||||
ready = 1;
|
||||
ok = 1;
|
||||
} else {
|
||||
sprintf(scratch, "The DOS partition table is inconsistent.\n\n%s\nDo you wish to edit it by hand?", errmsg);
|
||||
if (!dialog_yesno(TITLE, scratch, -1, -1)) {
|
||||
dialog_clear_norefresh();
|
||||
edit_mbr(mbr, &avail_disklabels[inst_disk]);
|
||||
} else {
|
||||
dialog_clear_norefresh();
|
||||
AskAbort("Installation cannot proceed without\na valid master boot record\n");
|
||||
ok = 1;
|
||||
ready = 0;
|
||||
}
|
||||
}
|
||||
dialog_clear();
|
||||
}
|
||||
|
||||
if (ready) {
|
||||
default_disklabel(&avail_disklabels[inst_disk],
|
||||
mbr->dospart[inst_part].dp_size,
|
||||
mbr->dospart[inst_part].dp_start);
|
||||
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", -1,-1,1);
|
||||
dialog_clear_norefresh();
|
||||
edit_disklabel(&avail_disklabels[inst_disk]);
|
||||
|
||||
build_disklabel(&avail_disklabels[inst_disk]);
|
||||
if (build_bootblocks(&avail_disklabels[inst_disk]) == -1)
|
||||
Fatal(errmsg);
|
||||
}
|
||||
|
||||
/* ready could have been reset above */
|
||||
if (ready) {
|
||||
if (dialog_yesno(TITLE, "We are now ready to format the hard disk for FreeBSD.\n\nSome or all of the disk will be overwritten during this process.\n\nAre you sure you wish to proceed ?", -1, -1)) {
|
||||
dialog_clear_norefresh();
|
||||
AskAbort("Do you want to quit?");
|
||||
ready = 0;
|
||||
}
|
||||
dialog_clear();
|
||||
}
|
||||
}
|
||||
if (getenv("STAGE0")) {
|
||||
Fatal("We stop here");
|
||||
}
|
||||
/* Write master boot record and bootblocks */
|
||||
if (write_mbr(avail_fds[inst_disk], mbr) == -1)
|
||||
Fatal(errmsg);
|
||||
if (write_bootblocks(avail_fds[inst_disk],
|
||||
mbr->dospart[inst_part].dp_start,
|
||||
avail_disklabels[inst_disk].d_bbsize) == -1)
|
||||
Fatal(errmsg);
|
||||
|
||||
/* close all the open disks */
|
||||
for (i=0; i < no_disks; i++)
|
||||
if (close(avail_fds[i]) == -1) {
|
||||
sprintf(errmsg, "Error on closing file descriptors: %s\n",
|
||||
strerror(errno));
|
||||
Fatal(errmsg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define BOOT1 "/stand/sdboot"
|
||||
#define BOOT2 "/stand/bootsd"
|
||||
|
||||
#define MAX_NO_DEVICES 10
|
||||
#define MAX_NO_DISKS 10
|
||||
#define MAX_NO_FS 30
|
||||
#define MAXFS MAX_NO_FS
|
||||
@ -76,17 +77,14 @@ EXTERN char selection[];
|
||||
EXTERN int debug_fd;
|
||||
|
||||
|
||||
extern unsigned char **avail_disknames;
|
||||
extern int no_disks;
|
||||
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 *);
|
||||
|
||||
/* utils.c */
|
||||
int strheight __P((const char *p));
|
||||
int strwidth __P((const char *p));
|
||||
void Abort __P((void));
|
||||
void ExitSysinstall __P((void));
|
||||
void TellEm __P((char *fmt, ...));
|
||||
@ -136,8 +134,11 @@ int makedevs __P((void));
|
||||
int AskEm __P((WINDOW *w,char *prompt, char *answer, int len));
|
||||
void ShowFile __P((char *filename, char *header));
|
||||
|
||||
/* bootarea.c */
|
||||
void enable_label __P((int fd));
|
||||
void disable_label __P((int fd));
|
||||
int write_bootblocks __P((int fd, struct disklabel *lbl));
|
||||
int build_bootblocks __P((int dfd,struct disklabel *label,struct dos_partition *dospart));
|
||||
/* label.c */
|
||||
int sectstoMb(int, int);
|
||||
int Mb_to_cylbdry(int, struct disklabel *);
|
||||
void default_disklabel(struct disklabel *, int, int);
|
||||
int disk_size(struct disklabel *);
|
||||
|
||||
/* mbr.c */
|
||||
int edit_mbr(int);
|
||||
|
Loading…
Reference in New Issue
Block a user