Bring the 2.0 RELEASE version back into -current. Now I just need
to resurrect my changes for the last snapshot, which were unfortunately lost in a forest fire on time.
This commit is contained in:
parent
62a1ce7ac9
commit
b4314abf31
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=5250
@ -4,12 +4,11 @@ NOMAN= yet
|
||||
|
||||
.PATH: /usr/src/sbin/disklabel
|
||||
|
||||
SRCS = bootarea.c editor.c exec.c dkcksum.c label.c main.c mbr.c \
|
||||
SRCS = 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 -I${.CURDIR}/../../sys/
|
||||
CLEANFILES += makedevs.c
|
||||
CFLAGS += -Wall -g -static
|
||||
LDADD = -ldialog -lncurses -lmytinfo
|
||||
DPADD = ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO}
|
||||
|
||||
|
@ -12,152 +12,103 @@
|
||||
* 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 <ufs/ffs/fs.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dialog.h>
|
||||
|
||||
#include "disk.h"
|
||||
#include "mbr.h"
|
||||
#include "sysinstall.h"
|
||||
|
||||
char boot1[] = BOOT1;
|
||||
char boot2[] = BOOT2;
|
||||
extern char *bootblocks;
|
||||
extern struct mbr *mbr;
|
||||
extern char boot1[];
|
||||
extern char boot2[];
|
||||
|
||||
int
|
||||
enable_label(int fd)
|
||||
{
|
||||
int flag = 1;
|
||||
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
disable_label(int fd)
|
||||
{
|
||||
int flag = 0;
|
||||
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
write_bootblocks(int disk)
|
||||
write_bootblocks(int fd, struct disklabel *lbl)
|
||||
{
|
||||
int fd;
|
||||
off_t offset;
|
||||
int part = disk_list[disk].inst_part;
|
||||
struct disklabel *lbl = &disk_list[disk].lbl;
|
||||
unsigned char bootblocks[BBSIZE];
|
||||
off_t of = lbl->d_partitions[OURPART].p_offset;
|
||||
|
||||
/* Load MBR boot code */
|
||||
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");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
enable_label(fd);
|
||||
|
||||
if (read(fd, bootblocks, MBRSIZE) < 0) {
|
||||
sprintf(errmsg, "Couldn't load boot file %s into 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 (close(fd) == -1) {
|
||||
sprintf(errmsg, "Couldn't close boot file %s\n%s\n", boot1,
|
||||
strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
disable_label(fd);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Update the in-core label too if possible */
|
||||
|
||||
if (ioctl(fd, DIOCSDINFO, lbl) < 0) {
|
||||
sprintf(errmsg, "Couldn't change in-core disklabel for %s\n\n%s",
|
||||
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);
|
||||
|
||||
if (close(fd) == -1) {
|
||||
sprintf(errmsg, "Couldn't close device %s\n\n%s",
|
||||
scratch, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
return(0);
|
||||
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);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: exec.c,v 1.7 1994/11/08 18:44:13 jkh Exp $
|
||||
* $Id: exec.c,v 1.8.2.1 1994/11/21 03:11:59 phk Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -38,8 +38,7 @@ exec(int magic, char *cmd, char *args, ...)
|
||||
struct stat dummy;
|
||||
|
||||
if (stat(cmd, &dummy) == -1) {
|
||||
sprintf(errmsg, "Executable %s does not exist\n", cmd);
|
||||
return(-1);
|
||||
Fatal("Executable %s does not exist", cmd);
|
||||
}
|
||||
|
||||
va_start(ap, args);
|
||||
|
@ -1,401 +1,383 @@
|
||||
#define DKTYPENAMES
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/devconf.h>
|
||||
#include <ufs/ffs/fs.h>
|
||||
/*
|
||||
* $Id: label.c,v 1.23.2.2 1994/11/21 03:53:45 phk Exp $
|
||||
*/
|
||||
|
||||
#include <fstab.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
#define DKTYPENAMES
|
||||
#include <sys/param.h>
|
||||
#include <ufs/ffs/fs.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <ufs/ffs/fs.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 *);
|
||||
int getfstype(char *);
|
||||
int sectstoMb(int, int);
|
||||
|
||||
char *partname[MAXPARTITIONS] = {"a", "b", "c", "d", "e", "f", "g", "h"};
|
||||
extern char boot1[];
|
||||
extern char boot2[];
|
||||
|
||||
char *yesno[] = {"yes", "no", 0};
|
||||
|
||||
int
|
||||
disk_size(struct disklabel *lbl)
|
||||
static int
|
||||
AskWhichPartition(char *prompt)
|
||||
{
|
||||
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 * secpercyl);
|
||||
}
|
||||
|
||||
char *
|
||||
diskname(int disk)
|
||||
{
|
||||
sprintf(scratch, "/dev/r%s%dd", disk_list[disk].devconf->dc_name,
|
||||
disk_list[disk].devconf->dc_unit);
|
||||
return (scratch);
|
||||
}
|
||||
|
||||
int
|
||||
get_fs_type(char *fstype)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; fstypenames[i]; i++)
|
||||
if (strcmp(fstype, fstypenames[i]))
|
||||
return (i);
|
||||
|
||||
return (FS_OTHER);
|
||||
}
|
||||
|
||||
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 = 0;
|
||||
int done;
|
||||
int next;
|
||||
int cur_field;
|
||||
int cur_part;
|
||||
int i;
|
||||
struct disklabel *lbl = &disk_list[disk].lbl;
|
||||
int offset, slop;
|
||||
int nsects, hog;
|
||||
int avail_sects, free;
|
||||
|
||||
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 = 8;
|
||||
|
||||
/* Initialise the entries */
|
||||
|
||||
for (i=0; i < MAXPARTITIONS; i++) {
|
||||
|
||||
disk_list[disk].mounts[i].fs_spec =
|
||||
(char *)malloc(80);
|
||||
if (!disk_list[disk].mounts[i].fs_spec) {
|
||||
sprintf(errmsg, "Couldn't allocate memory for device mounts\n");
|
||||
return (-1);
|
||||
}
|
||||
sprintf(disk_list[disk].mounts[i].fs_spec,
|
||||
"%s%d%s", disk_list[disk].devconf->dc_name,
|
||||
disk_list[disk].devconf->dc_unit,
|
||||
partname[i]);
|
||||
|
||||
disk_list[disk].mounts[i].fs_file =
|
||||
(char *)malloc(80);
|
||||
if (!disk_list[disk].mounts[i].fs_file) {
|
||||
sprintf(errmsg, "Couldn't allocate memory for mount points\n");
|
||||
return (-1);
|
||||
}
|
||||
sprintf(disk_list[disk].mounts[i].fs_file, "%s", "Not Mounted");
|
||||
|
||||
disk_list[disk].mounts[i].fs_vfstype =
|
||||
(char *)malloc(80);
|
||||
if (!disk_list[disk].mounts[i].fs_vfstype) {
|
||||
sprintf(errmsg, "Couldn't allocate memory for filesystem type\n");
|
||||
return (-1);
|
||||
}
|
||||
switch (lbl->d_partitions[i].p_fstype) {
|
||||
case FS_BSDFFS:
|
||||
sprintf(disk_list[disk].mounts[i].fs_vfstype, "%s", "ufs");
|
||||
break;
|
||||
case FS_MSDOS:
|
||||
sprintf(disk_list[disk].mounts[i].fs_vfstype, "%s", "msdos");
|
||||
break;
|
||||
case FS_SWAP:
|
||||
sprintf(disk_list[disk].mounts[i].fs_vfstype, "%s", "swap");
|
||||
break;
|
||||
default:
|
||||
sprintf(disk_list[disk].mounts[i].fs_vfstype, "%s", "unused");
|
||||
}
|
||||
|
||||
disk_list[disk].mounts[i].fs_mntops =
|
||||
(char *)malloc(80);
|
||||
if (!disk_list[disk].mounts[i].fs_mntops) {
|
||||
sprintf(errmsg, "Couldn't allocate memory for mount options\n");
|
||||
return (-1);
|
||||
}
|
||||
sprintf(disk_list[disk].mounts[i].fs_mntops, "%s", "YES");
|
||||
|
||||
sprintf(label_field[(i*5)+3].field, "%d",
|
||||
sectstoMb(lbl->d_partitions[i].p_size, lbl->d_secsize));
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup the RAWPART and OURPART partition ourselves from the MBR
|
||||
* in case either one doesn't exist or the new MBR invalidates them.
|
||||
*/
|
||||
|
||||
cur_part = disk_list[disk].inst_part;
|
||||
lbl->d_partitions[OURPART].p_size =
|
||||
disk_list[disk].mbr.dospart[cur_part].dp_size;
|
||||
lbl->d_partitions[OURPART].p_offset =
|
||||
disk_list[disk].mbr.dospart[cur_part].dp_start;
|
||||
lbl->d_partitions[RAWPART].p_size = lbl->d_secperunit;
|
||||
lbl->d_partitions[RAWPART].p_offset = 0;
|
||||
|
||||
if (!(window = newwin(LINES, COLS, 0, 0))) {
|
||||
sprintf(errmsg, "Failed to open window for disklabel editor\n");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
keypad(window, TRUE);
|
||||
|
||||
draw_box(window, 0, 0, LINES, COLS, dialog_attr, border_attr);
|
||||
|
||||
/* Only one toggle to set up */
|
||||
for (i=0; i < MAXPARTITIONS; i++)
|
||||
label_field[(i*5)+1].misc = yesno;
|
||||
|
||||
cur_field = 1;
|
||||
done = 0;
|
||||
while (!done && (key != ESC)) {
|
||||
|
||||
/* Update disklabel */
|
||||
|
||||
avail_sects = lbl->d_partitions[OURPART].p_size;
|
||||
offset = lbl->d_partitions[OURPART].p_offset;
|
||||
slop = rndtocylbdry(offset, lbl->d_secpercyl) - 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);
|
||||
nsects = rndtocylbdry(nsects, lbl->d_secpercyl);
|
||||
if (slop) {
|
||||
nsects += slop;
|
||||
slop = 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
for (i=0; i < MAXPARTITIONS; i++) {
|
||||
sprintf(label_field[(i*5)].field, "%s",
|
||||
disk_list[disk].mounts[i].fs_spec);
|
||||
sprintf(label_field[(i*5)+1].field, "%s",
|
||||
disk_list[disk].mounts[i].fs_mntops);
|
||||
sprintf(label_field[(i*5)+2].field, "%s",
|
||||
disk_list[disk].mounts[i].fs_vfstype);
|
||||
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);
|
||||
}
|
||||
|
||||
sprintf(label_field[47].field, "%d",
|
||||
sectstoMb(avail_sects, lbl->d_secsize));
|
||||
|
||||
disp_fields(window, label_field,
|
||||
sizeof(label_field)/sizeof(struct field));
|
||||
|
||||
switch (label_field[cur_field].type) {
|
||||
case F_EDIT:
|
||||
key = line_edit(window, label_field[cur_field].y,
|
||||
label_field[cur_field].x,
|
||||
label_field[cur_field].width,
|
||||
label_field[cur_field].maxlen,
|
||||
item_selected_attr, 1,
|
||||
label_field[cur_field].field);
|
||||
|
||||
/* Update mount info */
|
||||
|
||||
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_file, "%s",
|
||||
label_field[(i*5)+4].field);
|
||||
sprintf(disk_list[disk].mounts[i].fs_vfstype, "%s",
|
||||
label_field[(i*5)+2].field);
|
||||
sprintf(disk_list[disk].mounts[i].fs_mntops, "%s",
|
||||
label_field[(i*5)+1].field);
|
||||
}
|
||||
break;
|
||||
case F_BUTTON:
|
||||
key = button_press(window, label_field[cur_field]);
|
||||
if (!key && !strcmp(label_field[cur_field].field, "OK")) {
|
||||
done = 1;
|
||||
continue;
|
||||
}
|
||||
if (!key && !strcmp(label_field[cur_field].field, "Cancel")) {
|
||||
sprintf(errmsg, "\nUser aborted.\n");
|
||||
dialog_clear_norefresh();
|
||||
return (-1);
|
||||
}
|
||||
break;
|
||||
case F_TOGGLE:
|
||||
key = toggle_press(window, label_field[cur_field]);
|
||||
break;
|
||||
case F_TITLE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
next = change_field(label_field[cur_field], key);
|
||||
if (next == -1) {
|
||||
beep();
|
||||
} else
|
||||
cur_field = next;
|
||||
}
|
||||
|
||||
if (write_bootblocks(disk) == -1)
|
||||
return(-1);
|
||||
|
||||
delwin(window);
|
||||
dialog_clear();
|
||||
return(0);
|
||||
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
|
||||
display_disklabel(int disk)
|
||||
DiskLabel()
|
||||
{
|
||||
int i, key=0;
|
||||
WINDOW *window;
|
||||
struct disklabel *lbl = &disk_list[disk].lbl;
|
||||
int i, j, done = 0, diskno, k;
|
||||
char buf[128],*p;
|
||||
struct disklabel *lbl, olbl;
|
||||
struct dos_partition dp[NDOSPART];
|
||||
|
||||
if (use_shadow)
|
||||
draw_shadow(stdscr, 1, 1, LINES-2, COLS-2);
|
||||
window = newwin(LINES-2, COLS-2, 1, 1);
|
||||
keypad(window, TRUE);
|
||||
u_long cyl, hd, sec, tsec;
|
||||
u_long l1, l2, l3, l4;
|
||||
char *yip = NULL;
|
||||
u_long allocated_space, ourpart_size, ourpart_offset;
|
||||
|
||||
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, 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,lbl->d_drivedata[i]);
|
||||
*buf = 0;
|
||||
i = AskEm(stdscr, "Enter number of disk to Disklabel> ", buf, 3);
|
||||
Debug("%d", i);
|
||||
if (i != '\n' && i != '\r') return;
|
||||
diskno = atoi(buf);
|
||||
if (!(diskno >= 0 && diskno < MAX_NO_DISKS && Dname[diskno])) {
|
||||
return;
|
||||
}
|
||||
mvwprintw(window, 11, 2, "Spare");
|
||||
for (i=0; i< NSPARE; i++) {
|
||||
mvwprintw(window, 11, 7 + (i*10), " : %d = %ld",i,lbl->d_spare[i]);
|
||||
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;
|
||||
}
|
||||
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,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);
|
||||
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) {
|
||||
standout();
|
||||
mvprintw(24, 0, yip);
|
||||
standend();
|
||||
beep();
|
||||
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 Action Mountpoint");
|
||||
for (i = 0; i < MAXPARTITIONS; i++) {
|
||||
refresh();
|
||||
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("%-7.7s ", fstypenames[k]);
|
||||
|
||||
if(!MP[diskno][i])
|
||||
printw(" ");
|
||||
else if(!strcmp(Ftype[MP[diskno][i]],"swap"))
|
||||
printw("swap ");
|
||||
else if(Faction[MP[diskno][i]])
|
||||
printw("newfs ");
|
||||
else
|
||||
printw("mount ");
|
||||
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(17, 0, "Total size: %8lu blocks %5luMb",
|
||||
ourpart_size, (ourpart_size + 1024)/2048);
|
||||
mvprintw(18, 0, "Space allocated: %8lu blocks %5luMb",
|
||||
allocated_space, (allocated_space + 1024)/2048);
|
||||
mvprintw(20, 0, "Commands available: ");
|
||||
if (memcmp(lbl, Dlbl[diskno], sizeof *lbl)) {
|
||||
standout();
|
||||
printw("Use (W)rite to save changes to disk");
|
||||
standend();
|
||||
}
|
||||
mvprintw(21, 0, "(H)elp (T)utorial (E)dit (A)ssign (D)elete (R)eread (W)rite (Q)uit");
|
||||
mvprintw(22, 0, "(P)reserve (S)lice");
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i=getch();
|
||||
switch(i) {
|
||||
case 'h': case 'H': case '?':
|
||||
clear();
|
||||
mvprintw(0, 0,
|
||||
"%s -- Diskspace editor -- DISKLABEL -- Command Help
|
||||
|
||||
Basic commands:
|
||||
|
||||
(H)elp - This screen
|
||||
(T)utorial - More detailed information on MBRs, disklabels, etc.
|
||||
(E)dit - Edit an existing disklabel entry
|
||||
(A)ssign - Assign a filesystem (or swap) to a partition
|
||||
(D)elete - Delete an existing disklabel entry
|
||||
(R)eread - Re-read disklabel from disk, discarding any changes
|
||||
(W)rite - Write updated disklabel information to disk
|
||||
(P)reserve - Don't newfs the filesystem (preserve old contents)
|
||||
(S)lice - Import foreign slice from MBR (for example, DOS)
|
||||
(Q)uit - Exit from the disklabel editor
|
||||
|
||||
Press any key to return to Disklabel editor...
|
||||
", TITLE);
|
||||
getch();
|
||||
break;
|
||||
case 't': case 'T':
|
||||
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 'p': case 'P':
|
||||
j = AskWhichPartition("Preserve which partition> ");
|
||||
if (j < 0) {
|
||||
yip = "Invalid partition";
|
||||
break;
|
||||
}
|
||||
if (!MP[diskno][j]) {
|
||||
yip = "Unmounted partitions are preserved by default";
|
||||
break;
|
||||
}
|
||||
if (lbl->d_partitions[j].p_fstype == FS_SWAP) {
|
||||
yip = "swap partitions cannot be preserved.";
|
||||
break;
|
||||
}
|
||||
if (lbl->d_partitions[j].p_fstype != FS_BSDFFS) {
|
||||
yip = "All non-ufs partitions are preserved by default.";
|
||||
break;
|
||||
}
|
||||
if (!fixit && !strcmp(Fmount[MP[diskno][j]],"/")) {
|
||||
yip = "/ cannot be preserved.";
|
||||
break;
|
||||
}
|
||||
if (!fixit && !strcmp(Fmount[MP[diskno][j]],"/usr")) {
|
||||
yip = "/usr cannot be preserved.";
|
||||
break;
|
||||
}
|
||||
if (!fixit && !strcmp(Fmount[MP[diskno][j]],"/var")) {
|
||||
yip = "/var cannot be preserved.";
|
||||
break;
|
||||
}
|
||||
Faction[MP[diskno][j]] = 1 - Faction[MP[diskno][j]];
|
||||
break;
|
||||
|
||||
case 's': case 'S':
|
||||
read_dospart(Dfd[diskno],&dp[0]);
|
||||
*buf = 0;
|
||||
j = AskEm(stdscr,"Import which fdisk slice> ",buf,4);
|
||||
if(j != '\n' && j != '\r')
|
||||
break;
|
||||
i = strtoul(buf,0,0);
|
||||
if (i < 1 || i > 4) {
|
||||
yip = "Invalid slice, must be '1' to '4'";
|
||||
break;
|
||||
}
|
||||
if (!dp[i-1].dp_size) {
|
||||
yip = "empty slice cannot be imported";
|
||||
break;
|
||||
}
|
||||
j = AskWhichPartition("Import on which partition> ");
|
||||
if (j < 0) {
|
||||
yip = "Invalid partition";
|
||||
break;
|
||||
}
|
||||
CleanMount(diskno, j);
|
||||
lbl->d_partitions[j].p_offset = dp[i-1].dp_start;
|
||||
lbl->d_partitions[j].p_size = dp[i-1].dp_size;
|
||||
switch (dp[i-1].dp_typ) {
|
||||
case 0x01:
|
||||
case 0x04:
|
||||
case 0x06:
|
||||
lbl->d_partitions[j].p_fstype=FS_MSDOS;
|
||||
break;
|
||||
default:
|
||||
lbl->d_partitions[j].p_fstype=FS_OTHER;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'e': case 'E':
|
||||
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 'a': case 'A':
|
||||
if (memcmp(lbl, Dlbl[diskno], sizeof *lbl)) {
|
||||
yip = "Please (W)rite changed partition information first";
|
||||
break;
|
||||
}
|
||||
j = AskWhichPartition("Assign 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, "Directory mountpoint> ", buf, 28);
|
||||
if (i != '\n' && i != '\r')
|
||||
break;
|
||||
p = buf + strlen(buf) - 1;
|
||||
|
||||
while (isspace(*p) && p >= buf)
|
||||
*p-- = '\0';
|
||||
if (*buf && *buf != '/') {
|
||||
yip = "Mountpoint must start with a '/'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
CleanMount(diskno, j);
|
||||
if (!*buf)
|
||||
break;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
dialog_update();
|
||||
|
||||
while (key != '\n' && key != ' ' && key != '\033')
|
||||
key = wgetch(window);
|
||||
delwin(window);
|
||||
dialog_clear();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: main.c,v 1.16 1994/11/17 19:44:49 ache Exp $
|
||||
* $Id: main.c,v 1.17.2.1 1994/11/21 03:12:06 phk Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -36,8 +36,6 @@ jmp_buf jmp_restart;
|
||||
* XXX: mbr: edit geometry
|
||||
*/
|
||||
|
||||
extern int alloc_memory();
|
||||
|
||||
void
|
||||
handle_intr(int sig)
|
||||
{
|
||||
@ -79,9 +77,6 @@ main(int argc, char **argv)
|
||||
|
||||
signal(SIGINT, handle_intr);
|
||||
|
||||
if (alloc_memory() < 0)
|
||||
Fatal("No memory\n");
|
||||
|
||||
if (getpid() != 1) {
|
||||
stage0();
|
||||
stage1();
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include <unistd.h>
|
||||
#include <dialog.h>
|
||||
#include <fcntl.h>
|
||||
#include <fstab.h>
|
||||
|
||||
#ifdef __i386__ /* temp measure delete nov 15 1994 */
|
||||
#define i386 1
|
||||
@ -24,26 +23,47 @@
|
||||
#warning FOO
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/devconf.h>
|
||||
#include <sys/disklabel.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include "sysinstall.h"
|
||||
#include "disk.h"
|
||||
#include "editor.h"
|
||||
#include "mbr.h"
|
||||
#include "sysinstall.h"
|
||||
|
||||
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 *);
|
||||
extern struct mbr *mbr;
|
||||
extern int inst_part;
|
||||
extern int whole_disk;
|
||||
|
||||
|
||||
/*
|
||||
* Guess what ? This is bteasy-1.4... didn't used to look this way, did it ?
|
||||
* Written by Serge Vakulenko, <vak@kiae.su>
|
||||
*/
|
||||
static unsigned char bootcode[] = {
|
||||
51,192,142,192,142,216,250,142,208,188,0,124,251,252,139,244,191,0,6,185,0,
|
||||
1,242,165,234,99,6,0,0,139,213,88,162,72,7,60,53,116,29,180,16,246,228,5,
|
||||
174,4,139,240, 246,68,4,255,116,55,198,4,128,232,215,0,138,116,1,139,76,
|
||||
2,235,8,232,204,0,185,1,0,50,209,187,0,124,184,1,2,205,19,114,23,129,191,
|
||||
254,1,85,170,117,15,234,0,124,0,0,139,234,66,128,242,179,136,22,58,7,191,
|
||||
190,7,185,4,0,198,6,45,7,49,50,246,136,45,138,69,4,60,0,116,37,60,5,116,
|
||||
33,254,198,190,42,7,232,117,0,190,72,7,70,70,139,28,10,255,116,7,58,125,4,
|
||||
117,243,50,255,141,183,116,7,232,92,0,131,199,16,254,6,45,7,226,201,128,62,
|
||||
117,4,2,116,11,190,59,7,10,246,117,10,205,24,235,170,190,42,7,232,59,0,232,
|
||||
56,0,50,228,205,26,139,218,131,195,96,180,1,205,22,117,13,50,228,205,26,59,
|
||||
211,114,242,160,72,7,235,12,50,228,205,22,138,196,60,28,116,241,4,246,60,
|
||||
49,114,212,60,53,119,208,80,190,40,7,187,29,6,83,252,172,80,36,127,180,14,
|
||||
205,16,88,168,128,116,242,195,86,184,1,3,187,0,6,185,1,0,50,246,205,19,94,
|
||||
198,6,72,7,63,195,13,138,13,10,70,48,32,46,32,46,32,46,160,100,105,115,107,
|
||||
32,49,13,10,10,68,101,102,97,117,108,116,58,32,70,63,160,0,1,0,4,0,6,3,7,7,
|
||||
8,10,9,13,10,16,99,20,100,20,101,26,128,26,129,31,130,36,147,42,165,49,159,
|
||||
53,117,57,82,57,219,60,242,66,0,100,111,243,104,112,102,243,102,115,32,97,
|
||||
105,248,111,115,178,117,110,105,248,110,111,118,101,108,236,109,105,110,
|
||||
105,248,108,105,110,117,248,97,109,111,101,98,225,70,114,101,101,66,83,196,
|
||||
98,115,100,233,112,99,105,248,99,112,237,100,111,115,115,101,227,63,191,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,85,170
|
||||
};
|
||||
|
||||
extern char boot1[];
|
||||
extern struct disk disk_list[];
|
||||
struct part_type part_types[] = PARTITION_TYPES
|
||||
struct field *last_field;
|
||||
|
||||
char *
|
||||
part_type(int type)
|
||||
@ -61,396 +81,443 @@ part_type(int type)
|
||||
return("Unknown");
|
||||
}
|
||||
|
||||
int
|
||||
read_mbr(char *device, struct mbr *mbr)
|
||||
void
|
||||
read_dospart(int fd, struct dos_partition *dp)
|
||||
{
|
||||
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(dp, buf+DOSPARTOFF, sizeof(*dp)*NDOSPART);
|
||||
}
|
||||
|
||||
if ((fd = open(device, O_RDONLY)) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't open device %s to read master boot record\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
void
|
||||
write_dospart(int fd, struct dos_partition *dp)
|
||||
{
|
||||
u_char buf[512];
|
||||
|
||||
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 (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);
|
||||
}
|
||||
|
||||
if (read(fd, &(mbr->bootcode), MBRSIZE) == -1) {
|
||||
sprintf(errmsg, "Failed to read master boot record from device %s\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
void
|
||||
write_bootcode(int fd)
|
||||
{
|
||||
u_char buf[512];
|
||||
|
||||
if (close(fd) == -1) {
|
||||
sprintf(errmsg,
|
||||
"Couldn't close device %s after reading master boot record\n",
|
||||
device);
|
||||
return(-1);
|
||||
}
|
||||
return(0);
|
||||
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
|
||||
write_mbr(char *device, struct mbr *mbr)
|
||||
WriteBootblock(int dfd,struct disklabel *label,struct dos_partition *dospart)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
clear_mbr(struct mbr *mbr, char *bootcode)
|
||||
{
|
||||
int i;
|
||||
int fd;
|
||||
|
||||
/*
|
||||
* Must replace any old bootcode that was read
|
||||
* from disk with our bootblocks.
|
||||
*/
|
||||
|
||||
TellEm("Loading MBR code from %s", bootcode);
|
||||
fd = open(bootcode, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
sprintf(errmsg, "Couldn't open boot file %s\n", bootcode);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (read(fd, mbr->bootcode, MBRSIZE) < 0) {
|
||||
sprintf(errmsg, "Couldn't read from boot file %s\n", bootcode);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if (close(fd) == -1) {
|
||||
sprintf(errmsg, "Couldn't close boot file %s\n", bootcode);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Create an empty partition table */
|
||||
off_t of = label->d_partitions[OURPART].p_offset;
|
||||
u_char bootblocks[BBSIZE];
|
||||
|
||||
for (i=0; i < NDOSPART; i++) {
|
||||
mbr->dospart[i].dp_flag = 0;
|
||||
mbr->dospart[i].dp_shd = 0;
|
||||
mbr->dospart[i].dp_ssect = 0;
|
||||
mbr->dospart[i].dp_scyl = 0;
|
||||
mbr->dospart[i].dp_typ = 0;
|
||||
mbr->dospart[i].dp_ehd = 0;
|
||||
mbr->dospart[i].dp_esect = 0;
|
||||
mbr->dospart[i].dp_ecyl = 0;
|
||||
mbr->dospart[i].dp_start = 0;
|
||||
mbr->dospart[i].dp_size = 0;
|
||||
}
|
||||
Debug("Loading boot code from %s", BOOT1);
|
||||
|
||||
mbr->magic = MBR_MAGIC;
|
||||
|
||||
dialog_clear();
|
||||
return(0);
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
dedicated_mbr(struct mbr *mbr, char *bootcode, struct disklabel *lbl)
|
||||
static int
|
||||
FillIn(struct dos_partition *dp, int sec, int hd)
|
||||
{
|
||||
struct dos_partition *dp = &mbr->dospart[0];
|
||||
|
||||
if (clear_mbr(mbr, bootcode) == -1)
|
||||
return(-1);
|
||||
dp->dp_scyl = 0;
|
||||
dp->dp_shd = 1;
|
||||
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 =
|
||||
(lbl->d_nsectors * lbl->d_ntracks * lbl->d_ncylinders) - dp->dp_start;
|
||||
|
||||
dp->dp_typ = MBR_PTYPE_FreeBSD;
|
||||
dp->dp_flag = ACTIVE;
|
||||
u_long l2,l3=0,sect,c,s,h;
|
||||
|
||||
return(0);
|
||||
sect = dp->dp_start;
|
||||
l2 = sect / (sec*hd);
|
||||
sect -= l2*sec*hd;
|
||||
if(l2>1023) l2 = 1023;
|
||||
c = (l2 & 0xff);
|
||||
s = (l2 >> 2) & 0xc0;
|
||||
l2 = sect / sec;
|
||||
h = l2;
|
||||
sect -= l2*sec;
|
||||
s |= (sect+1) & 0x3f;
|
||||
#define NIC(a,b) if (a != b) {a = b; l3++;}
|
||||
NIC(dp->dp_ssect, s);
|
||||
NIC(dp->dp_scyl, c);
|
||||
NIC(dp->dp_shd, h);
|
||||
|
||||
sect = dp->dp_start + dp->dp_size-1;
|
||||
l2 = sect / (sec*hd);
|
||||
sect -= l2*sec*hd;
|
||||
if(l2>1023) l2 = 1023;
|
||||
c = (l2 & 0xff);
|
||||
s = (l2 >> 2) & 0xc0;
|
||||
l2 = sect / sec;
|
||||
h = l2;
|
||||
sect -= l2*sec;
|
||||
s |= (sect+1) & 0x3f;
|
||||
NIC(dp->dp_esect, s);
|
||||
NIC(dp->dp_ecyl, c);
|
||||
NIC(dp->dp_ehd, h);
|
||||
#undef NIC
|
||||
return l2;
|
||||
}
|
||||
|
||||
int
|
||||
get_geom_values(int disk)
|
||||
void
|
||||
Fdisk()
|
||||
{
|
||||
WINDOW *window;
|
||||
struct disklabel *lbl = &disk_list[disk].lbl;
|
||||
int key = 0;
|
||||
int cur_field = 0;
|
||||
int next = 0;
|
||||
int done=0;
|
||||
|
||||
struct field field[] = {
|
||||
{2, 28, 06, 10, 01, 04, 01, 4, 01, "Unset", F_EDIT, 0, 0},
|
||||
{4, 28, 06, 10, 02, 00, 02, 0, 02, "Unset", F_EDIT, 0, 0},
|
||||
{6, 28, 06, 10, 03, 01, 03, 1, 03, "Unset", F_EDIT, 0, 0},
|
||||
{10, 7, 2, 2, 4, 2, 4, 2, 4, "OK", F_BUTTON, 0, 0},
|
||||
{10, 20, 6, 6, 0, 3, 0, 3, 0, "Cancel", F_BUTTON, 0, 0},
|
||||
{0, 07, 24, 24, -1, -1, -1, -1, -1, "BIOS geometry parameters", F_TITLE, 0, 0},
|
||||
{2, 02, 20, 20, -1, -1, -1, -1, -1, "Number of cylinders:", F_TITLE, 0, 0},
|
||||
{4, 02, 25, 25, -1, -1, -1, -1, -1, "Number of tracks (heads):", F_TITLE, 0, 0},
|
||||
{6, 02, 18, 18, -1, -1, -1, -1, -1, "Number of sectors:", F_TITLE, 0, 0}
|
||||
};
|
||||
|
||||
if (!(window = newwin(14, 40, 5, 20))) {
|
||||
sprintf(errmsg, "Failed to open window for geometry editor");
|
||||
return (-1);
|
||||
};
|
||||
|
||||
keypad(window, TRUE);
|
||||
|
||||
dialog_clear_norefresh();
|
||||
draw_box(window, 0, 0, 14, 40, dialog_attr, border_attr);
|
||||
|
||||
done = 0;
|
||||
while (!done && (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));
|
||||
switch (field[cur_field].type) {
|
||||
case F_EDIT:
|
||||
key = line_edit(window, field[cur_field].y, field[cur_field].x,
|
||||
field[cur_field].width, field[cur_field].maxlen,
|
||||
item_selected_attr, 1, field[cur_field].field);
|
||||
break;
|
||||
case F_BUTTON:
|
||||
key = button_press(window, field[cur_field]);
|
||||
if (!key && !strcmp(field[cur_field].field, "OK")) {
|
||||
done = 1;
|
||||
continue;
|
||||
}
|
||||
if (!key && !strcmp(field[cur_field].field, "Cancel")) {
|
||||
sprintf(errmsg, "\nUser aborted.\n");
|
||||
dialog_clear_norefresh();
|
||||
return (-1);
|
||||
}
|
||||
case F_TOGGLE:
|
||||
case F_TITLE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
edit_mbr(int disk)
|
||||
{
|
||||
WINDOW *window;
|
||||
int cur_field;
|
||||
int i;
|
||||
int ok;
|
||||
int next;
|
||||
int key = 0;
|
||||
struct mbr *mbr = &disk_list[disk].mbr;
|
||||
|
||||
/* Confirm disk parameters */
|
||||
#ifdef 0
|
||||
dialog_msgbox("\nBIOS disk geometry values", "In order to setup the boot area of the disk it is necessary to know the BIOS values for the disk geometry i.e. the number of cylinders, heads and sectors. These values may be different form the real geometry of the disk, depending on whether or not your system uses geometry translation. At this stage it is the entries from the BIOS that are needed. If you do not know these they can be found by rebooting the machine and entering th BIOS setup routine. See you BIOS manual for details.\n", -1, -1, 1)
|
||||
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;
|
||||
int changed = 0;
|
||||
char *grumble = NULL;
|
||||
|
||||
*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;
|
||||
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,
|
||||
"Disk: %s Geometry: %lu Cyl * %lu Hd * %lu Sect",
|
||||
Dname[diskno], cyl, hd, sec);
|
||||
printw(" = %luMb = %lu Sect", (tsec+1024)/2048, tsec);
|
||||
j++;
|
||||
for(i=0;i<NDOSPART;i++, j+=4) {
|
||||
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 (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,
|
||||
"\nAre you sure you wish to proceed ?\n",
|
||||
-1, -1)) {
|
||||
dialog_clear();
|
||||
if (dedicated_mbr(mbr, boot1, &disk_list[disk].lbl) == -1) {
|
||||
sprintf(scratch, "\nCouldn't create new master boot record.\n\n%s", errmsg);
|
||||
return(-1);
|
||||
}
|
||||
ok = 1;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
mvprintw(20, 0, "Commands available: ");
|
||||
mvprintw(21, 0, "(H)elp (T)utorial (D)elete (E)dit (R)eread (W)rite MBR (Q)uit");
|
||||
mvprintw(22, 0, "(U)se entire disk for FreeBSD (G)eometry Write MBR (B)ootcode");
|
||||
if (grumble) {
|
||||
standout();
|
||||
mvprintw(24, 0, grumble);
|
||||
standend();
|
||||
grumble = NULL;
|
||||
} else if (changed) {
|
||||
standout();
|
||||
mvprintw(24, 0, "Use (W)rite to save changes to disk");
|
||||
standend();
|
||||
}
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i=getch();
|
||||
switch(i) {
|
||||
|
||||
sprintf(scratch, "\nDo you wish to dedicate the whole disk to FreeBSD?\n\nDoing so will overwrite any existing data on the disk.\n");
|
||||
dialog_clear_norefresh();
|
||||
if (!dialog_yesno(TITLE, scratch, -1, -1))
|
||||
if (dedicated_mbr(mbr, boot1, &disk_list[disk].lbl) == -1) {
|
||||
sprintf(scratch, "\nCouldn't dedicate disk to FreeBSD.\n\n %s", errmsg);
|
||||
return(-1);
|
||||
}
|
||||
case 'h': case 'H':
|
||||
clear();
|
||||
mvprintw(0, 0,
|
||||
"%s -- Diskspace editor -- FDISK -- Command Help
|
||||
|
||||
if (!(window = newwin(LINES, COLS, 0, 0))) {
|
||||
sprintf(errmsg, "Failed to open window for MBR editor\n");
|
||||
return (-1);
|
||||
};
|
||||
Basic commands:
|
||||
|
||||
keypad(window, TRUE);
|
||||
(H)elp - This screen
|
||||
(T)utorial - A more detailed discussion of MBR's, disklabels, etc.
|
||||
(D)elete - Delete an existing partition
|
||||
(E)dit - Edit an existing partition
|
||||
(R)eread - Read fdisk information from disk again, abandoning changes
|
||||
(W)rite MBR - Write modified fdisk information to disk
|
||||
(Q)uit - Exit the FDISK editor
|
||||
|
||||
dialog_clear_norefresh();
|
||||
draw_box(window, 0, 0, LINES, COLS, dialog_attr, border_attr);
|
||||
Advanced commands:
|
||||
|
||||
cur_field = 1;
|
||||
ok = 0;
|
||||
while (!ok && (key != ESC)) {
|
||||
for (i=0; i < NDOSPART; i++) {
|
||||
sprintf(mbr_field[(i*12)+1].field, "%d", 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);
|
||||
}
|
||||
(U)se entire disk for FreeBSD - Assign ALL disk space on current drive
|
||||
(G)eometry - Edit the default disk geometry settings
|
||||
Write MBR (B)ootcode - Install multi-OS bootmanager.
|
||||
|
||||
disp_fields(window, mbr_field, sizeof(mbr_field)/sizeof(struct field));
|
||||
switch (mbr_field[cur_field].type) {
|
||||
case F_EDIT:
|
||||
key = line_edit(window, mbr_field[cur_field].y,
|
||||
mbr_field[cur_field].x,
|
||||
mbr_field[cur_field].width,
|
||||
mbr_field[cur_field].maxlen,
|
||||
item_selected_attr, 1,
|
||||
mbr_field[cur_field].field);
|
||||
/* Propagate changes to MBR */
|
||||
for (i=0; i < NDOSPART; i++) {
|
||||
mbr->dospart[i].dp_typ = atoi(mbr_field[(i*12)+1].field);
|
||||
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);
|
||||
}
|
||||
break;
|
||||
case F_BUTTON:
|
||||
key = button_press(window, mbr_field[cur_field]);
|
||||
if (!key && !strcmp(mbr_field[cur_field].field, "OK")) {
|
||||
ok = 1;
|
||||
continue;
|
||||
}
|
||||
if (!key && !strcmp(mbr_field[cur_field].field, "Cancel")) {
|
||||
sprintf(errmsg, "\nUser aborted.\n");
|
||||
dialog_clear_norefresh();
|
||||
return (-1);
|
||||
}
|
||||
break;
|
||||
case F_TOGGLE:
|
||||
case F_TITLE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
next = change_field(mbr_field[cur_field], key);
|
||||
if (next == -1)
|
||||
beep();
|
||||
|
||||
Press any key to return to FDISK editor...
|
||||
", TITLE);
|
||||
getch();
|
||||
break;
|
||||
case 't': case 'T':
|
||||
ShowFile(HELPME_FILE,"Help file for disklayout");
|
||||
break;
|
||||
|
||||
case 'r': case 'R':
|
||||
read_dospart(Dfd[diskno], dp);
|
||||
changed=0;
|
||||
break;
|
||||
|
||||
case 'b': case 'B':
|
||||
write_bootcode(Dfd[diskno]);
|
||||
grumble = "Wrote boot manager";
|
||||
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
|
||||
cur_field = next;
|
||||
}
|
||||
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;
|
||||
changed=1;
|
||||
dp[l-1].dp_start=l1;
|
||||
dp[l-1].dp_size=l3;
|
||||
FillIn(&dp[l-1],sec,hd);
|
||||
|
||||
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;
|
||||
|
||||
/* Clear active flags */
|
||||
for (i=0; i < NDOSPART; i++)
|
||||
mbr->dospart[i].dp_flag = 0;
|
||||
case 'u': case 'U':
|
||||
memset(&dp[0], 0, sizeof dp);
|
||||
changed=1;
|
||||
|
||||
/* Find first FreeBSD partition and make it active */
|
||||
dp[0].dp_start = 0;
|
||||
dp[0].dp_size = tsec;
|
||||
FillIn(&dp[0],sec,hd);
|
||||
|
||||
disk_list[disk].inst_part = -1;
|
||||
for (i=0; i < NDOSPART; i++)
|
||||
if (mbr->dospart[i].dp_typ == MBR_PTYPE_FreeBSD) {
|
||||
disk_list[disk].inst_part = i;
|
||||
mbr->dospart[i].dp_flag = ACTIVE;
|
||||
break;
|
||||
dp[0].dp_typ = MBR_PTYPE_FreeBSD;
|
||||
dp[0].dp_flag = 0x80;
|
||||
break;
|
||||
|
||||
case 'g': case 'G':
|
||||
sprintf(buf,"%lu",sec);
|
||||
i = AskEm(stdscr, "Number of Sectors> ",buf,7);
|
||||
l2 = strtoul(buf,0,0);
|
||||
if(l2 != sec)
|
||||
changed++;
|
||||
sec=l2;
|
||||
sprintf(buf,"%lu",hd);
|
||||
i = AskEm(stdscr, "Number of Heads> ",buf,7);
|
||||
l2 = strtoul(buf,0,0);
|
||||
if(l2 != hd)
|
||||
changed++;
|
||||
hd=l2;
|
||||
cyl = tsec/(hd*sec);
|
||||
sprintf(buf,"%lu",cyl);
|
||||
i = AskEm(stdscr, "Number of Cylinders> ",buf,7);
|
||||
l2 = strtoul(buf,0,0);
|
||||
if(l2 != cyl)
|
||||
changed++;
|
||||
cyl=l2;
|
||||
|
||||
for (l=0;l<NDOSPART;l++) {
|
||||
if (!dp[l].dp_typ || !dp[l].dp_size)
|
||||
continue;
|
||||
changed += FillIn(&dp[l], sec, hd);
|
||||
}
|
||||
|
||||
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]);
|
||||
changed=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;
|
||||
}
|
||||
}
|
||||
Dlbl[diskno]->d_ntracks = hd;
|
||||
Dlbl[diskno]->d_nsectors = sec;
|
||||
Dlbl[diskno]->d_ncylinders = cyl;
|
||||
Dlbl[diskno]->d_secpercyl = hd*sec;
|
||||
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]);
|
||||
changed=0;
|
||||
|
||||
if (Dlbl[diskno]->d_partitions[OURPART].p_size) {
|
||||
WriteBootblock(Dfd[diskno], lbl, dp);
|
||||
grumble = "Wrote MBR and disklabel to disk";
|
||||
} else {
|
||||
grumble = "Wrote MBR to disk";
|
||||
}
|
||||
|
||||
sprintf(scratch, "\nWriting a new master boot record can erase the current disk contents.\n\n Are you sure you want to write the new MBR?\n");
|
||||
dialog_clear_norefresh();
|
||||
if (!dialog_yesno("Write new MBR?", scratch, -1, -1)) {
|
||||
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, "\nThe following error occured while trying to write the new MBR.\n\n%s", errmsg);
|
||||
return(-1);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'q': case 'Q':
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
beep();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (disk_list[disk].inst_part == -1) {
|
||||
sprintf(errmsg, "\nThere is no space allocated to FreeBSD on %s\n",
|
||||
diskname(disk));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
delwin(window);
|
||||
dialog_clear();
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,109 +1,80 @@
|
||||
struct field mbr_field[] = {
|
||||
{ 0, 25, 31, -1, -1, -1, -1, -1, -1, "Master Boot Record (MBR) editor", F_TITLE, 0, 0},
|
||||
{ 4, 8, 5, 5, 2, 49, 2, 50, 2, "000", F_EDIT, 0, 0},
|
||||
{ 5, 31, 7, 10, 3, 1, 3, 1, 3, "0", F_EDIT, 0, 0},
|
||||
{ 6, 5, 5, 10, 4, 2, 6, 2, 4, "0", F_EDIT, 0, 0},
|
||||
{ 6, 14, 5, 10, 5, 2, 6, 3, 5, "0", F_EDIT, 0, 0},
|
||||
{ 6, 24, 5, 10, 6, 2, 6, 4, 6, "0", F_EDIT, 0, 0},
|
||||
{ 7, 31, 7, 10, 7, 3, 7, 5, 7, "0", F_EDIT, 0, 0},
|
||||
{ 8, 5, 5, 10, 8, 6, 10, 6, 8, "0", F_EDIT, 0, 0},
|
||||
{ 8, 14, 5, 10, 9, 6, 10, 7, 9, "0", F_EDIT, 0, 0},
|
||||
{ 8, 24, 5, 10, 10, 6, 10, 8, 10, "0", F_EDIT, 0, 0},
|
||||
{ 9, 9, 7, 10, 11, 7, 12, 9, 11, "0", F_EDIT, 0, 0},
|
||||
{ 9, 27, 5, 10, 12, 7, 12, 10, 12, "0", F_EDIT, 0, 0},
|
||||
{10, 10, 10, 10, 13, 10, 25, 11, 13, "Not Active", F_EDIT, 0, 0},
|
||||
{ 4, 47, 5, 5, 14, 50, 14, 12, 14, "000", F_EDIT, 0, 0},
|
||||
{ 5, 70, 7, 10, 15, 13, 15, 13, 15, "0", F_EDIT, 0, 0},
|
||||
{ 6, 44, 5, 10, 16, 14, 18, 14, 16, "0", F_EDIT, 0, 0},
|
||||
{ 6, 54, 5, 10, 17, 14, 18, 15, 17, "0", F_EDIT, 0, 0},
|
||||
{ 6, 64, 5, 10, 18, 14, 18, 16, 18, "0", F_EDIT, 0, 0},
|
||||
{ 7, 70, 7, 10, 19, 15, 19, 17, 19, "0", F_EDIT, 0, 0},
|
||||
{ 8, 44, 5, 10, 20, 18, 22, 18, 20, "0", F_EDIT, 0, 0},
|
||||
{ 8, 54, 5, 10, 21, 18, 22, 19, 21, "0", F_EDIT, 0, 0},
|
||||
{ 8, 64, 5, 10, 22, 18, 22, 20, 22, "0", F_EDIT, 0, 0},
|
||||
{ 9, 48, 7, 10, 23, 19, 24, 21, 23, "0", F_EDIT, 0, 0},
|
||||
{ 9, 66, 5, 10, 24, 20, 24, 22, 24, "0", F_EDIT, 0, 0},
|
||||
{10, 49, 10, 10, 25, 22, 37, 23, 25, "Not Active", F_EDIT, 0, 0},
|
||||
{14, 8, 5, 5, 26, 12, 26, 24, 26, "000", F_EDIT, 0, 0},
|
||||
{15, 31, 7, 10, 27, 25, 27, 25, 27, "0", F_EDIT, 0, 0},
|
||||
{16, 5, 5, 10, 28, 26, 30, 26, 28, "0", F_EDIT, 0, 0},
|
||||
{16, 14, 5, 10, 29, 26, 30, 27, 29, "0", F_EDIT, 0, 0},
|
||||
{16, 24, 5, 10, 30, 26, 30, 28, 30, "0", F_EDIT, 0, 0},
|
||||
{17, 31, 7, 10, 31, 27, 31, 29, 31, "0", F_EDIT, 0, 0},
|
||||
{18, 5, 5, 10, 32, 30, 34, 30, 32, "0", F_EDIT, 0, 0},
|
||||
{18, 14, 5, 10, 33, 30, 34, 31, 33, "0", F_EDIT, 0, 0},
|
||||
{18, 24, 5, 10, 34, 30, 34, 32, 34, "0", F_EDIT, 0, 0},
|
||||
{19, 9, 7, 10, 35, 31, 36, 33, 35, "0", F_EDIT, 0, 0},
|
||||
{19, 27, 5, 10, 36, 31, 36, 34, 36, "0", F_EDIT, 0, 0},
|
||||
{20, 10, 10, 10, 37, 34, 49, 35, 37, "Not Active", F_EDIT, 0, 0},
|
||||
{14, 47, 5, 5, 38, 24, 38, 36, 38, "000", F_EDIT, 0, 0},
|
||||
{15, 70, 7, 10, 39, 37, 39, 37, 39, "0", F_EDIT, 0, 0},
|
||||
{16, 44, 5, 10, 40, 38, 42, 38, 40, "0", F_EDIT, 0, 0},
|
||||
{16, 54, 5, 10, 41, 38, 42, 39, 41, "0", F_EDIT, 0, 0},
|
||||
{16, 64, 5, 10, 42, 38, 42, 40, 42, "0", F_EDIT, 0, 0},
|
||||
{17, 70, 7, 10, 43, 39, 43, 41, 43, "0", F_EDIT, 0, 0},
|
||||
{18, 44, 5, 10, 44, 42, 46, 42, 44, "0", F_EDIT, 0, 0},
|
||||
{18, 54, 5, 10, 45, 43, 46, 43, 45, "0", F_EDIT, 0, 0},
|
||||
{18, 64, 5, 10, 46, 43, 46, 44, 46, "0", F_EDIT, 0, 0},
|
||||
{19, 48, 7, 10, 47, 43, 48, 45, 47, "0", F_EDIT, 0, 0},
|
||||
{19, 66, 5, 10, 48, 44, 48, 46, 48, "0", F_EDIT, 0, 0},
|
||||
{20, 49, 10, 10, 49, 46, 50, 47, 49, "Not Active", F_EDIT, 0, 0},
|
||||
{22, 15, 2, 2, 50, 36, 1, 48, 50, "OK", F_BUTTON, 0, 0},
|
||||
{22, 50, 6, 6, 1, 48, 13, 49, 1, "Cancel", F_BUTTON, 0, 0},
|
||||
{2, 15, 11, -1, -1, -1, -1, -1, -1, "Partition 1", F_TITLE, 0, 0},
|
||||
{2, 55, 11, -1, -1, -1, -1, -1, -1, "Partition 2", F_TITLE, 0, 0},
|
||||
{12, 15, 11, -1, -1, -1, -1, -1, -1, "Partition 3", F_TITLE, 0, 0},
|
||||
{12, 55, 11, -1, -1, -1, -1, -1, -1, "Partition 4", F_TITLE, 0, 0},
|
||||
{ 4, 2, 5, -1, -1, -1, -1, -1, -1, "Type:", F_TITLE, 0, 0},
|
||||
{ 5, 2, 28, -1, -1, -1, -1, -1, -1, "Starting at absolute sector:", F_TITLE, 0, 0},
|
||||
{ 6, 2, 2, -1, -1, -1, -1, -1, -1, "C:", F_TITLE, 0, 0},
|
||||
{ 6, 11, 2, -1, -1, -1, -1, -1, -1, "H:", F_TITLE, 0, 0},
|
||||
{ 6, 21, 2, -1, -1, -1, -1, -1, -1, "S:", F_TITLE, 0, 0},
|
||||
{ 7, 2, 26, -1, -1, -1, -1, -1, -1, "Ending at absolute sector:", F_TITLE, 0, 0},
|
||||
{ 8, 2, 2, -1, -1, -1, -1, -1, -1, "C:", F_TITLE, 0, 0},
|
||||
{ 8, 11, 2, -1, -1, -1, -1, -1, -1, "H:", F_TITLE, 0, 0},
|
||||
{ 8, 21, 2, -1, -1, -1, -1, -1, -1, "S:", F_TITLE, 0, 0},
|
||||
{ 9, 02, 7, -1, -1, -1, -1, -1, -1, "Size: (", F_TITLE, 0, 0},
|
||||
{ 9, 18, 8, -1, -1, -1, -1, -1, -1, "sectors)", F_TITLE, 0, 0},
|
||||
{ 9, 33, 2, -1, -1, -1, -1, -1, -1, "Mb", F_TITLE, 0, 0},
|
||||
{10, 2, 7, -1, -1, -1, -1, -1, -1, "Status:", F_TITLE, 0, 0},
|
||||
{ 4, 41, 5, -1, -1, -1, -1, -1, -1, "Type:", F_TITLE, 0, 0},
|
||||
{ 5, 41, 28, -1, -1, -1, -1, -1, -1, "Starting at absolute sector:", F_TITLE, 0, 0},
|
||||
{ 6, 41, 2, -1, -1, -1, -1, -1, -1, "C:", F_TITLE, 0, 0},
|
||||
{ 6, 51, 2, -1, -1, -1, -1, -1, -1, "H:", F_TITLE, 0, 0},
|
||||
{ 6, 61, 2, -1, -1, -1, -1, -1, -1, "S:", F_TITLE, 0, 0},
|
||||
{ 7, 41, 26, -1, -1, -1, -1, -1, -1, "Ending at absolute sector:", F_TITLE, 0, 0},
|
||||
{ 8, 41, 2, -1, -1, -1, -1, -1, -1, "C:", F_TITLE, 0, 0},
|
||||
{ 8, 51, 2, -1, -1, -1, -1, -1, -1, "H:", F_TITLE, 0, 0},
|
||||
{ 8, 61, 2, -1, -1, -1, -1, -1, -1, "S:", F_TITLE, 0, 0},
|
||||
{ 9, 41, 7, -1, -1, -1, -1, -1, -1, "Size: (", F_TITLE, 0, 0},
|
||||
{ 9, 57, 8, -1, -1, -1, -1, -1, -1, "sectors)", F_TITLE, 0, 0},
|
||||
{ 9, 72, 2, -1, -1, -1, -1, -1, -1, "Mb", F_TITLE, 0, 0},
|
||||
{10, 41, 7, -1, -1, -1, -1, -1, -1, "Status:", F_TITLE, 0, 0},
|
||||
{14, 02, 5, -1, -1, -1, -1, -1, -1, "Type:", F_TITLE, 0, 0},
|
||||
{15, 02, 28, -1, -1, -1, -1, -1, -1, "Starting at absolute sector:", F_TITLE, 0, 0},
|
||||
{16, 2, 2, -1, -1, -1, -1, -1, -1, "C:", F_TITLE, 0, 0},
|
||||
{16, 11, 2, -1, -1, -1, -1, -1, -1, "H:", F_TITLE, 0, 0},
|
||||
{16, 21, 2, -1, -1, -1, -1, -1, -1, "S:", F_TITLE, 0, 0},
|
||||
{17, 02, 26, -1, -1, -1, -1, -1, -1, "Ending at absolute sector:", F_TITLE, 0, 0},
|
||||
{18, 02, 2, -1, -1, -1, -1, -1, -1, "C:", F_TITLE, 0, 0},
|
||||
{18, 11, 2, -1, -1, -1, -1, -1, -1, "H:", F_TITLE, 0, 0},
|
||||
{18, 21, 2, -1, -1, -1, -1, -1, -1, "S:", F_TITLE, 0, 0},
|
||||
{19, 02, 7, -1, -1, -1, -1, -1, -1, "Size: (", F_TITLE, 0, 0},
|
||||
{19, 18, 8, -1, -1, -1, -1, -1, -1, "sectors)", F_TITLE, 0, 0},
|
||||
{19, 33, 2, -1, -1, -1, -1, -1, -1, "Mb", F_TITLE, 0, 0},
|
||||
{20, 02, 7, -1, -1, -1, -1, -1, -1, "Status:", F_TITLE, 0, 0},
|
||||
{14, 41, 5, -1, -1, -1, -1, -1, -1, "Type:", F_TITLE, 0, 0},
|
||||
{15, 41, 28, -1, -1, -1, -1, -1, -1, "Starting at absolute sector:", F_TITLE, 0, 0},
|
||||
{16, 41, 2, -1, -1, -1, -1, -1, -1, "C:", F_TITLE, 0, 0},
|
||||
{16, 51, 2, -1, -1, -1, -1, -1, -1, "H:", F_TITLE, 0, 0},
|
||||
{16, 61, 2, -1, -1, -1, -1, -1, -1, "S:", F_TITLE, 0, 0},
|
||||
{17, 41, 26, -1, -1, -1, -1, -1, -1, "Ending at absolute sector:", F_TITLE, 0, 0},
|
||||
{18, 41, 2, -1, -1, -1, -1, -1, -1, "C:", F_TITLE, 0, 0},
|
||||
{18, 51, 2, -1, -1, -1, -1, -1, -1, "H:", F_TITLE, 0, 0},
|
||||
{18, 61, 2, -1, -1, -1, -1, -1, -1, "S:", F_TITLE, 0, 0},
|
||||
{19, 41, 7, -1, -1, -1, -1, -1, -1, "Size: (", F_TITLE, 0, 0},
|
||||
{19, 57, 8, -1, -1, -1, -1, -1, -1, "sectors)", F_TITLE, 0, 0},
|
||||
{19, 72, 2, -1, -1, -1, -1, -1, -1, "Mb", F_TITLE, 0, 0},
|
||||
{20, 41, 7, -1, -1, -1, -1, -1, -1, "Status:", F_TITLE, 0, 0}
|
||||
/*
|
||||
* 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 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 *);
|
||||
|
@ -17,6 +17,7 @@ AskEm(WINDOW *w,char *prompt, char *answer, int len)
|
||||
int x,y;
|
||||
mvwprintw(w,23,0,prompt);
|
||||
getyx(w,y,x);
|
||||
wclrtoeol(w);
|
||||
return line_edit(w,y,x,len,len+1,item_selected_attr,1,answer);
|
||||
}
|
||||
|
||||
|
@ -28,16 +28,18 @@ static unsigned char *welcome[] = {
|
||||
"1. README",
|
||||
"READ THIS FIRST.",
|
||||
"2. Release Notes",
|
||||
"Read the 2.0 Release Notes (recommended).",
|
||||
"Read the 2.0 Release Notes (recommended).",
|
||||
"3. Troubleshooting",
|
||||
"Read this in case of trouble.",
|
||||
"4. COPYRIGHT",
|
||||
"4. Partitions and MBRs",
|
||||
"Verbose description of how these work.",
|
||||
"5. COPYRIGHT",
|
||||
"Read FreeBSD Copyright Information.",
|
||||
"5. Install",
|
||||
"6. Install",
|
||||
"Proceed with full installation.",
|
||||
"6. Fixit",
|
||||
"7. Fixit",
|
||||
"Repair existing installation (`fixit' mode).",
|
||||
"7. Quit",
|
||||
"8. Quit",
|
||||
"Don't do anything, just reboot.",
|
||||
};
|
||||
|
||||
@ -46,7 +48,7 @@ stage0()
|
||||
{
|
||||
evil_goto:
|
||||
if (dialog_menu("Welcome to FreeBSD!",
|
||||
"Use ALT-F2 and ALT-F1 to toggle between debugging\ninformation screen (ALT-F2) or this dialog screen (ALT-F1)\n\nPlease select one of the following options:", -1, -1, 7, 7, welcome, selection))
|
||||
"Use ALT-F2 and ALT-F1 to toggle between debugging\ninformation screen (ALT-F2) or this dialog screen (ALT-F1)\n\nPlease select one of the following options:", -1, -1, 8, 8, welcome, selection))
|
||||
ExitSysinstall();
|
||||
|
||||
switch (atoi(selection)) {
|
||||
@ -65,21 +67,39 @@ stage0()
|
||||
goto evil_goto;
|
||||
break;
|
||||
|
||||
case 4: /* View copyrights */
|
||||
case 4: /* View DISK FAQ */
|
||||
ShowFile(HELPME_FILE, "DISK FAQ");
|
||||
goto evil_goto;
|
||||
break;
|
||||
|
||||
case 5: /* View copyrights */
|
||||
ShowFile(COPYRIGHT_FILE, "COPYRIGHT");
|
||||
goto evil_goto;
|
||||
break;
|
||||
|
||||
case 5: /* Proceed (do nothing special, really) */
|
||||
break;
|
||||
|
||||
case 6:
|
||||
dialog_msgbox("Sorry!", "This feature is not currently implemented.",
|
||||
-1, -1, 1);
|
||||
goto evil_goto;
|
||||
case 6: /* Proceed (do nothing special, really) */
|
||||
fixit = 0;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
dialog_clear();
|
||||
dialog_update();
|
||||
dialog_msgbox("WARNING!",
|
||||
"The usual install procedure will be invoked, but with most of the
|
||||
sanity checks disabled. The suggested course of action is to:
|
||||
1. Go to (F)disk and do a (W)rite, and possibly a (B)oot too
|
||||
if your MBR has been wiped.
|
||||
2. Go into (D)isklabel and identify your root (/) and swap
|
||||
partitions.
|
||||
3. Select (P)roceed to reboot and load the cpio floppy.
|
||||
4. You will now be in the stand-alone shell, where you may
|
||||
conduct further repairs with the tools you'll find in
|
||||
/stand.
|
||||
5. Good luck... You'll probably need it.", -1, -1, 1);
|
||||
fixit = 1;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
/* Be neat.. */
|
||||
ExitSysinstall();
|
||||
break; /* hope not! :) */
|
||||
|
@ -1,4 +1,5 @@
|
||||
/*
|
||||
#define DEBUG
|
||||
* Copyright (c) 1994, Paul Richards.
|
||||
*
|
||||
* All rights reserved.
|
||||
@ -12,14 +13,13 @@
|
||||
* its use.
|
||||
*/
|
||||
|
||||
#define DKTYPENAMES
|
||||
#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,223 +27,203 @@
|
||||
#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 <dialog.h>
|
||||
|
||||
#include "disk.h"
|
||||
#include "sysinstall.h"
|
||||
|
||||
unsigned char **options;
|
||||
unsigned char *scratch;
|
||||
unsigned char *errmsg;
|
||||
unsigned char *bootblocks;
|
||||
|
||||
int dialog_active = 0;
|
||||
|
||||
/* Forward decls */
|
||||
void exit_sysinstall(void);
|
||||
void exit_prompt(void);
|
||||
extern char *part_type(int);
|
||||
|
||||
char selection[30];
|
||||
|
||||
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()
|
||||
{
|
||||
int i;
|
||||
|
||||
scratch = (char *) calloc(SCRATCHSIZE, sizeof(char));
|
||||
if (!scratch)
|
||||
return(-1);
|
||||
|
||||
errmsg = (char *) calloc(ERRMSGSIZE, sizeof(char));
|
||||
if (!errmsg)
|
||||
return(-1);
|
||||
|
||||
options = (unsigned char **)calloc(MAX_NO_DISKS, sizeof(char *));
|
||||
if (!options)
|
||||
return(-1);
|
||||
for (i = 0; i < MAX_NO_DISKS; i++) {
|
||||
options[i] = (char *)calloc(100, sizeof(char));
|
||||
if (!options[i])
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
char * device_list[] = {"wd","sd",0};
|
||||
|
||||
void
|
||||
free_memory()
|
||||
query_disks()
|
||||
{
|
||||
int i;
|
||||
int i,j;
|
||||
char disk[15];
|
||||
char diskname[5];
|
||||
struct stat st;
|
||||
struct disklabel dl;
|
||||
int fd;
|
||||
|
||||
free(scratch);
|
||||
free(errmsg);
|
||||
|
||||
for (i = 0; i < MAX_NO_DEVICES; i++)
|
||||
free(device_list[i]);
|
||||
}
|
||||
|
||||
int
|
||||
query_devices()
|
||||
{
|
||||
int i, j;
|
||||
int size, osize;
|
||||
int ndevs;
|
||||
int mib[8];
|
||||
struct devconf *dev;
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
dev = 0; osize = 0;
|
||||
Ndisk = 0;
|
||||
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
configure_disks()
|
||||
{
|
||||
char *disk_names[] = {"wd", "sd", 0};
|
||||
char diskname[20];
|
||||
int i, j;
|
||||
int fd;
|
||||
int valid=0;
|
||||
int choice;
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
for (i = 0; i < no_disks; i++) {
|
||||
sprintf(options[(i*2)], "%d",i+1);
|
||||
sprintf(options[(i*2)+1], "%s%d: %s (%dMb)",
|
||||
disk_list[i].devconf->dc_name,
|
||||
disk_list[i].devconf->dc_unit,
|
||||
disk_list[i].lbl.d_typename,
|
||||
disk_size(&disk_list[i].lbl));
|
||||
}
|
||||
|
||||
sprintf(options[no_disks*2], "%d", no_disks+1);
|
||||
sprintf(options[(no_disks*2)+1], " Done");
|
||||
|
||||
dialog_clear_norefresh();
|
||||
if (dialog_menu("FreeBSD Installation", scratch, -1, -1,
|
||||
min(5, no_disks+1), no_disks+1, options, selection)) {
|
||||
dialog_clear_norefresh();
|
||||
sprintf(scratch,"\nYou selected cancel.\n");
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
continue;
|
||||
}
|
||||
choice = atoi(selection) - 1;
|
||||
if (choice == no_disks)
|
||||
valid = 1;
|
||||
else {
|
||||
if (edit_mbr(choice) == -1) {
|
||||
sprintf(scratch, "\nThe following error occured while\nediting the master boot record.\n%s", errmsg);
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
continue;
|
||||
};
|
||||
if (edit_disklabel(choice) == -1) {
|
||||
sprintf(scratch, "\nThe following error occured while\nediting the disklabel.\n%s", errmsg);
|
||||
AskAbort(scratch);
|
||||
valid = 0;
|
||||
continue;
|
||||
}
|
||||
disk_list[choice].selected = 1;
|
||||
}
|
||||
} while (!valid);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
stage1()
|
||||
{
|
||||
int i, j;
|
||||
int i,j;
|
||||
int ret=1;
|
||||
int ready = 0;
|
||||
int foundroot=0,foundusr=0,foundswap=0;
|
||||
char *complaint=0;
|
||||
|
||||
query_devices();
|
||||
configure_disks();
|
||||
/* List filesystems */
|
||||
for (i=0; i < MAX_NO_DEVICES; i++) {
|
||||
if (!disk_list[i].selected)
|
||||
continue;
|
||||
for (j=0; j < MAXPARTITIONS; j++) {
|
||||
if ((j == OURPART) || (j == RAWPART))
|
||||
continue;
|
||||
if (!disk_list[i].lbl.d_partitions[j].p_size)
|
||||
continue;
|
||||
mounts[no_mounts++] = &disk_list[i].mounts[j];
|
||||
}
|
||||
query_disks();
|
||||
|
||||
while (!ready) {
|
||||
clear(); standend();
|
||||
j = 2;
|
||||
if (fixit) {
|
||||
mvprintw(j++, 50, "|Suggested course of action:");
|
||||
mvprintw(j++, 50, "|");
|
||||
mvprintw(j++, 50, "|(F)disk, (W)rite");
|
||||
mvprintw(j++, 50, "|possibly (F)disk, (B)oot");
|
||||
mvprintw(j++, 50, "|(D)isklabel, (A)ssign <root>");
|
||||
mvprintw(j++, 50, "|(A)ssign swap");
|
||||
mvprintw(j++, 50, "|(P)roceed");
|
||||
mvprintw(j++, 50, "|Reboot");
|
||||
mvprintw(j++, 50, "|Load cpio floppy");
|
||||
mvprintw(j++, 50, "|Choose stand-alone shell");
|
||||
mvprintw(j++, 50, "|");
|
||||
mvprintw(j++, 50, "|Your old kernel, /etc/fstab");
|
||||
mvprintw(j++, 50, "|and /sbin/init files are");
|
||||
mvprintw(j++, 50, "|renamed since they will be");
|
||||
mvprintw(j++, 50, "|replaced from this floppy.");
|
||||
} else {
|
||||
mvprintw(j++, 50, "|You should now assign some");
|
||||
mvprintw(j++, 50, "|space to root, swap, and");
|
||||
mvprintw(j++, 50, "|(optionally) /usr partitions");
|
||||
mvprintw(j++, 50, "|Root (/) should be a minimum");
|
||||
mvprintw(j++, 50, "|of 18MB with a 30MB /usr");
|
||||
mvprintw(j++, 50, "|or 50MB without a /usr.");
|
||||
mvprintw(j++, 50, "|Swap space should be a");
|
||||
mvprintw(j++, 50, "|minimum of 12MB or RAM * 2");
|
||||
mvprintw(j++, 50, "|Be sure to also (A)ssign a");
|
||||
mvprintw(j++, 50, "|mount point to each one or");
|
||||
mvprintw(j++, 50, "|it will NOT be enabled.");
|
||||
mvprintw(j++, 50, "|");
|
||||
mvprintw(j++, 50, "|We suggest that you invoke");
|
||||
mvprintw(j++, 50, "|(F)disk, (W)rite the bootcode");
|
||||
mvprintw(j++, 50, "|then (D)isklabel your disk.");
|
||||
mvprintw(j++, 50, "|If installing on a drive");
|
||||
mvprintw(j++, 50, "|other than 0, also read the");
|
||||
mvprintw(j++, 50, "|TROUBLESHOOTING doc first");
|
||||
}
|
||||
return 0;
|
||||
|
||||
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 Action Mountpoint");
|
||||
j++;
|
||||
for(i = 0; i < MAX_NO_FS; i++) {
|
||||
if(!Fname[i])
|
||||
continue;
|
||||
if(!strcmp(Ftype[i],"swap")) {
|
||||
mvprintw(j++, 0, "%2d: %-5s %-5s %5lu MB %-6s %-s",
|
||||
i, Fname[i], Ftype[i], Fsize[i], "swap", Fmount[i]);
|
||||
} else {
|
||||
mvprintw(j++, 0, "%2d: %-5s %-5s %5lu MB %-6s %-s",
|
||||
i, Fname[i], Ftype[i], Fsize[i],
|
||||
Faction[i] ? "newfs" : "mount", Fmount[i]);
|
||||
}
|
||||
}
|
||||
|
||||
mvprintw(20, 0, "Commands available:");
|
||||
mvprintw(21, 0, "(H)elp (T)utorial (F)disk (D)isklabel (P)roceed (Q)uit");
|
||||
if(complaint) {
|
||||
standout();
|
||||
mvprintw(22, 0, complaint);
|
||||
standend();
|
||||
complaint = 0;
|
||||
}
|
||||
mvprintw(23, 0, "Enter Command> ");
|
||||
i = getch();
|
||||
switch(i) {
|
||||
case 'h': case 'H':
|
||||
clear();
|
||||
mvprintw(0, 0,
|
||||
"%s -- Diskspace editor -- Command Help
|
||||
|
||||
(T)utorial - Read a more detailed tutorial on how disklabels, MBRs,
|
||||
etc. work.
|
||||
(P)roceed - Proceed with system installation.
|
||||
(Q)uit - Don't install anything.
|
||||
(F)disk - Enter the FDISK (MBR) editor.
|
||||
(D)isklabel - Enter the disklabel editor.
|
||||
|
||||
Press any key to return to Diskspace editor...", TITLE);
|
||||
getch();
|
||||
break;
|
||||
case 't': case 'T':
|
||||
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 = "Please assign mountpoint for '/'";
|
||||
break;
|
||||
}
|
||||
if (!foundswap) {
|
||||
complaint = "Please assign mountpoint for swap";
|
||||
break;
|
||||
}
|
||||
if (!fixit && !foundusr && Fsize[foundroot] < 60) {
|
||||
complaint = "Please assign mountpoint for /usr";
|
||||
break;
|
||||
}
|
||||
if (dialog_yesno("Last Chance!",
|
||||
"Are you sure you want to proceed with the installation?\nLast chance before wiping your hard disk!", -1, -1))
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: stage2.c,v 1.17 1994/11/19 00:17:55 ache Exp $
|
||||
* $Id: stage2.c,v 1.16.2.1 1994/11/21 03:12:16 phk Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fstab.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <dialog.h>
|
||||
#include <errno.h>
|
||||
@ -35,59 +35,50 @@ stage2()
|
||||
char dbuf[90];
|
||||
FILE *f1;
|
||||
int i, j;
|
||||
int fidx[MAX_NO_MOUNTS];
|
||||
struct fstab *fp;
|
||||
|
||||
if (dialog_yesno("Last Chance!", "Are you sure you want to proceed with the installation?\nLast chance before wiping your hard disk!", -1, -1))
|
||||
exit(0);
|
||||
memset(Fsize, 0, sizeof Fsize);
|
||||
|
||||
/* Sort in mountpoint order */
|
||||
memset(fidx, 0, sizeof fidx);
|
||||
for (i = 1; Fname[i]; i++)
|
||||
Fsize[i] = i;
|
||||
Fsize[i] = 0;
|
||||
|
||||
for (i = 0; i < no_mounts; i++) {
|
||||
Debug("%d %s %s %s %s",i,
|
||||
mounts[i]->fs_spec,
|
||||
mounts[i]->fs_file,
|
||||
mounts[i]->fs_vfstype,
|
||||
mounts[i]->fs_mntops);
|
||||
}
|
||||
for (j = 1; j;)
|
||||
for (j = 0, i = 0; i < (no_mounts-1); i++) {
|
||||
if (strcmp(mounts[i]->fs_file, mounts[i+1]->fs_file) > 0) {
|
||||
fp = mounts[i];
|
||||
mounts[i] = mounts[i+1];
|
||||
mounts[i+1] = fp;
|
||||
j++;
|
||||
for (j = 0, i = 1; Fsize[i+1]; i++) {
|
||||
if (strcmp(Fmount[Fsize[i]], Fmount[Fsize[i+1]]) > 0) {
|
||||
j = Fsize[i];
|
||||
Fsize[i] = Fsize[i+1];
|
||||
Fsize[i + 1] = j;
|
||||
}
|
||||
}
|
||||
Debug("sorted by mountpoint");
|
||||
for (j = 0; j < no_mounts; j++) {
|
||||
if (strcmp(mounts[j]->fs_vfstype, "ufs"))
|
||||
|
||||
for (j = 1; Fsize[j]; j++) {
|
||||
if (strcmp(Ftype[Fsize[j]], "ufs"))
|
||||
continue;
|
||||
if (!strcmp(mounts[j]->fs_mntops, "YES"))
|
||||
continue;
|
||||
p = mounts[j]->fs_spec;
|
||||
TellEm("newfs /dev/r%s",p);
|
||||
p = Fname[Fsize[j]];
|
||||
strcpy(pbuf, "/dev/r");
|
||||
strcat(pbuf, p);
|
||||
i = exec(0, "/stand/newfs", "/stand/newfs", "-n", "1", pbuf, 0);
|
||||
if (i)
|
||||
Fatal("Exec(/stand/newfs) failed, code=%d.",i);
|
||||
if (!Faction[Fsize[j]]) {
|
||||
TellEm("fsck -y /dev/r%s",p);
|
||||
i = exec(0, "/stand/fsck", "/stand/fsck", "-y", pbuf, 0);
|
||||
if (i)
|
||||
Fatal("Exec(/stand/fsck) failed, code=%d.",i);
|
||||
} else {
|
||||
TellEm("newfs /dev/r%s",p);
|
||||
i = exec(0, "/stand/newfs", "/stand/newfs", "-n", "1", pbuf, 0);
|
||||
if (i)
|
||||
Fatal("Exec(/stand/newfs) failed, code=%d.",i);
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < no_mounts; j++) {
|
||||
if (!strcmp(mounts[j]->fs_vfstype, "swap"))
|
||||
break;
|
||||
p = mounts[j]->fs_spec;
|
||||
q = mounts[j]->fs_file;
|
||||
strcpy(dbuf, "/mnt");
|
||||
if (strcmp(q, "/")) {
|
||||
if (*q != '/')
|
||||
strcat(dbuf, "/");
|
||||
strcat(dbuf, q);
|
||||
}
|
||||
Mkdir(dbuf);
|
||||
if (strcmp(mounts[j]->fs_vfstype, "ufs"))
|
||||
for (j = 1; Fsize[j]; j++) {
|
||||
if (strcmp(Ftype[Fsize[j]], "ufs"))
|
||||
continue;
|
||||
strcpy(dbuf, "/mnt");
|
||||
p = Fname[Fsize[j]];
|
||||
q = Fmount[Fsize[j]];
|
||||
if (strcmp(q, "/"))
|
||||
strcat(dbuf, q);
|
||||
MountUfs(p, dbuf, 1, 0);
|
||||
}
|
||||
|
||||
@ -98,6 +89,9 @@ stage2()
|
||||
|
||||
TellEm("unzipping /stand/sysinstall onto hard disk");
|
||||
exec(4, "/stand/gzip", "zcat", 0 );
|
||||
/*
|
||||
CopyFile("/stand/sysinstall","/mnt/stand/sysinstall");
|
||||
*/
|
||||
Link("/mnt/stand/sysinstall","/mnt/stand/cpio");
|
||||
Link("/mnt/stand/sysinstall","/mnt/stand/bad144");
|
||||
Link("/mnt/stand/sysinstall","/mnt/stand/gunzip");
|
||||
@ -107,6 +101,30 @@ stage2()
|
||||
Link("/mnt/stand/sysinstall","/mnt/stand/fsck");
|
||||
Link("/mnt/stand/sysinstall","/mnt/stand/dialog");
|
||||
|
||||
if (fixit) {
|
||||
for (i=0;i<100;i++) {
|
||||
sprintf(pbuf,"/mnt/etc/fstab.before.fixit.%d",i);
|
||||
if (access(pbuf,R_OK)) {
|
||||
rename("/mnt/etc/fstab",pbuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i=0;i<100;i++) {
|
||||
sprintf(pbuf,"/mnt/kernel.before.fixit.%d",i);
|
||||
if (access(pbuf,R_OK)) {
|
||||
rename("/mnt/kernel",pbuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i=0;i<100;i++) {
|
||||
sprintf(pbuf,"/mnt/sbin/init.before.fixit.%d",i);
|
||||
if (access(pbuf,R_OK)) {
|
||||
rename("/mnt/sbin/init",pbuf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CopyFile("/kernel","/mnt/kernel");
|
||||
TellEm("make /dev entries");
|
||||
chdir("/mnt/dev");
|
||||
@ -119,15 +137,12 @@ stage2()
|
||||
Fatal("Couldn't open /mnt/etc/fstab for writing.");
|
||||
|
||||
TellEm("Writing filesystems");
|
||||
for (j = 0; j < no_mounts; j++) {
|
||||
if (!strcmp(mounts[j]->fs_vfstype,"swap"))
|
||||
fprintf(f1, "/dev/%s\t\tnone\tswap sw 0 0\n",
|
||||
mounts[j]->fs_spec);
|
||||
for (j = 1; Fsize[j]; j++) {
|
||||
if (!strcmp(Ftype[Fsize[j]],"swap"))
|
||||
fprintf(f1, "/dev/%s\t\tnone\tswap sw 0 0\n", Fname[Fsize[j]]);
|
||||
else
|
||||
fprintf(f1, "/dev/%s\t\t%s\t%s rw 1 1\n",
|
||||
mounts[j]->fs_spec,
|
||||
mounts[j]->fs_file,
|
||||
mounts[j]->fs_vfstype);
|
||||
Fname[Fsize[j]], Fmount[Fsize[j]], Ftype[Fsize[j]]);
|
||||
}
|
||||
TellEm("Writing procfs");
|
||||
fprintf(f1,"proc\t\t/proc\tprocfs rw 0 0\n");
|
||||
@ -139,16 +154,19 @@ stage2()
|
||||
close(i);
|
||||
|
||||
TellEm("Unmount disks");
|
||||
for (j = no_mounts-1; j >= 0; j--) {
|
||||
if (strcmp(mounts[j]->fs_vfstype,"ufs"))
|
||||
for (j = 1; Fsize[j]; j++)
|
||||
continue;
|
||||
|
||||
for (j--; j > 0; j--) {
|
||||
if (!strcmp(Ftype[Fsize[j]],"swap"))
|
||||
continue;
|
||||
strcpy(dbuf,"/mnt");
|
||||
if (strcmp(mounts[j]->fs_file,"/"))
|
||||
strcat(dbuf, mounts[j]->fs_file);
|
||||
if (strcmp(Fmount[Fsize[j]],"/"))
|
||||
strcat(dbuf, Fmount[Fsize[j]]);
|
||||
TellEm("unmount %s", dbuf);
|
||||
/* Don't do error-check, we reboot anyway... */
|
||||
unmount(dbuf, 0);
|
||||
}
|
||||
dialog_msgbox(TITLE,"Remove the floppy from the drive\nand hit return to reboot from the hard disk", -1, -1, 1);
|
||||
dialog_msgbox(TITLE,"Remove the floppy from the drive\n and hit return to reboot from the hard disk", -1, -1, 1);
|
||||
dialog_clear();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: stage3.c,v 1.8 1994/11/08 13:40:01 phk Exp $
|
||||
* $Id: stage3.c,v 1.9.2.1 1994/11/21 03:12:18 phk Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -65,7 +65,7 @@ stage3()
|
||||
TellEm("fsck -y %s",pbuf);
|
||||
if (exec(0, "/stand/fsck",
|
||||
"/stand/fsck", "-y", pbuf, 0) == -1)
|
||||
Fatal(errmsg);
|
||||
Fatal("exec(fsck) failed");
|
||||
|
||||
MountUfs(p, fs->fs_file, 0, mountflags);
|
||||
mountflags = 0;
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: stage5.c,v 1.15 1994/11/11 07:58:09 jkh Exp $
|
||||
* $Id: stage5.c,v 1.16.2.1 1994/11/21 03:12:20 phk Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -36,15 +36,16 @@ stage5()
|
||||
{
|
||||
int exec_sh = 1;
|
||||
|
||||
if (!dialog_yesno("End of initial installation", msg, -1, -1))
|
||||
exec_sh = 0;
|
||||
end_dialog();
|
||||
dialog_active=0;
|
||||
setenv("PATH","/stand",1);
|
||||
for(;;) {
|
||||
exec_sh = dialog_yesno("End of initial installation",
|
||||
msg, -1, -1);
|
||||
end_dialog();
|
||||
dialog_active=0;
|
||||
if (exec_sh)
|
||||
exec (2,"/stand/sh","/stand/-sh", 0);
|
||||
else
|
||||
exec (3,"/stand/bininst","/stand/-bininst", 0);
|
||||
dialog_active=1;
|
||||
}
|
||||
}
|
||||
|
@ -12,18 +12,16 @@
|
||||
* its use.
|
||||
*/
|
||||
|
||||
#define TITLE "FreeBSD 2.0-BETA Installation"
|
||||
#define TITLE "FreeBSD 2.0-RELEASE Installation"
|
||||
|
||||
#define BOOT1 "/stand/sdboot"
|
||||
#define BOOT2 "/stand/bootsd"
|
||||
|
||||
#define MAX_NO_DEVICES 10
|
||||
#define MAX_NO_DISKS 10
|
||||
#define MAX_NO_MOUNTS 30
|
||||
#define MAX_NO_FS 30
|
||||
#define MAXFS MAX_NO_FS
|
||||
|
||||
|
||||
#define BBSIZE 8192 /* Actually in ufs/ffs/fs.h I think */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -38,9 +36,6 @@
|
||||
#include <sys/dkbad.h>
|
||||
#include <sys/disklabel.h>
|
||||
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
#define SCRATCHSIZE 1024
|
||||
#define ERRMSGSIZE 256
|
||||
#define DEFROOTSIZE 18
|
||||
@ -75,23 +70,22 @@ EXTERN int Nfs;
|
||||
EXTERN char *Fname[MAX_NO_FS+1];
|
||||
EXTERN char *Fmount[MAX_NO_FS+1];
|
||||
EXTERN char *Ftype[MAX_NO_FS+1];
|
||||
EXTERN int Faction[MAX_NO_FS+1];
|
||||
EXTERN u_long Fsize[MAX_NO_FS+1];
|
||||
|
||||
EXTERN int dialog_active;
|
||||
EXTERN char selection[];
|
||||
EXTERN int debug_fd;
|
||||
EXTERN int dialog_active;
|
||||
EXTERN int fixit;
|
||||
|
||||
EXTERN int no_mounts;
|
||||
EXTERN struct fstab *mounts[MAX_NO_MOUNTS];
|
||||
|
||||
extern int no_disks;
|
||||
extern int inst_disk;
|
||||
extern unsigned char *scratch;
|
||||
extern unsigned char *errmsg;
|
||||
|
||||
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, ...));
|
||||
@ -108,6 +102,8 @@ void CopyFile __P((char *p1, char *p2));
|
||||
u_long PartMb(struct disklabel *lbl,int part);
|
||||
char * SetMount __P((int disk, int part, char *path));
|
||||
void CleanMount __P((int disk, int part));
|
||||
void enable_label __P((int fd));
|
||||
void disable_label __P((int fd));
|
||||
|
||||
/* exec.c */
|
||||
int exec __P((int magic, char *cmd, char *args, ...));
|
||||
@ -141,11 +137,9 @@ int makedevs __P((void));
|
||||
int AskEm __P((WINDOW *w,char *prompt, char *answer, int len));
|
||||
void ShowFile __P((char *filename, char *header));
|
||||
|
||||
/* 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);
|
||||
int build_bootblocks __P((int dfd,struct disklabel *label,struct dos_partition *dospart));
|
||||
void Fdisk __P((void));
|
||||
|
||||
/* label.c */
|
||||
void DiskLabel __P((void));
|
||||
|
@ -6,7 +6,7 @@
|
||||
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
|
||||
* ----------------------------------------------------------------------------
|
||||
*
|
||||
* $Id: utils.c,v 1.31 1994/11/19 00:09:00 ache Exp $
|
||||
* $Id: utils.c,v 1.30.2.1 1994/11/21 03:12:24 phk Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -99,19 +99,19 @@ AskAbort(char *fmt, ...)
|
||||
va_start(ap,fmt);
|
||||
vsnprintf(p, 2048, fmt, ap);
|
||||
va_end(ap);
|
||||
strcat(p, "\nDo you wish to abort the installation?\n");
|
||||
strcat(p, "\n\nDo you wish to abort the installation?");
|
||||
if (!dialog_yesno("Abort", p, -1, -1)) {
|
||||
dialog_clear_norefresh();
|
||||
Abort();
|
||||
} else
|
||||
dialog_clear();
|
||||
}
|
||||
dialog_clear();
|
||||
free(p);
|
||||
}
|
||||
|
||||
void
|
||||
Abort()
|
||||
{
|
||||
if (dialog_yesno("Exit sysinstall","\nAre you sure you want to quit?\n",
|
||||
if (dialog_yesno("Exit sysinstall","\n\nAre you sure you want to quit?",
|
||||
-1, -1)) {
|
||||
dialog_clear();
|
||||
return;
|
||||
@ -223,6 +223,8 @@ void
|
||||
Link(char *from, char *to)
|
||||
{
|
||||
TellEm("ln %s %s", from, to);
|
||||
if(fixit)
|
||||
unlink(to);
|
||||
if (link(from, to) == -1)
|
||||
Fatal("Couldn't create link: %s -> %s\n", from, to);
|
||||
}
|
||||
@ -264,3 +266,81 @@ PartMb(struct disklabel *lbl,int part)
|
||||
l = 1024*1024/lbl->d_secsize;
|
||||
return (lbl->d_partitions[part].p_size + l/2)/l;
|
||||
}
|
||||
|
||||
void
|
||||
CleanMount(int disk, int part)
|
||||
{
|
||||
int i = MP[disk][part];
|
||||
Faction[i] = 0;
|
||||
if (Fmount[i]) {
|
||||
free(Fmount[i]);
|
||||
Fmount[i] = 0;
|
||||
}
|
||||
if (Fname[i]) {
|
||||
free(Fname[i]);
|
||||
Fname[i] = 0;
|
||||
}
|
||||
if (Ftype[i]) {
|
||||
free(Ftype[i]);
|
||||
Ftype[i] = 0;
|
||||
}
|
||||
MP[disk][part] = 0;
|
||||
}
|
||||
|
||||
char *
|
||||
SetMount(int disk, int part, char *path)
|
||||
{
|
||||
int k;
|
||||
char buf[80];
|
||||
|
||||
CleanMount(disk,part);
|
||||
for (k = 1; k < MAX_NO_FS; k++)
|
||||
if (!Fmount[k])
|
||||
break;
|
||||
|
||||
if (k >= MAX_NO_FS)
|
||||
return "Maximum number of filesystems exceeded";
|
||||
|
||||
Fmount[k] = StrAlloc(path);
|
||||
sprintf(buf, "%s%c", Dname[disk], part + 'a');
|
||||
Fname[k] = StrAlloc(buf);
|
||||
switch (Dlbl[disk]->d_partitions[part].p_fstype) {
|
||||
case FS_BSDFFS:
|
||||
Ftype[k] = StrAlloc("ufs");
|
||||
if(!fixit)
|
||||
Faction[k] = 1;
|
||||
break;
|
||||
case FS_MSDOS:
|
||||
Ftype[k] = StrAlloc("msdos");
|
||||
Faction[k] = 0;
|
||||
break;
|
||||
case FS_SWAP:
|
||||
Ftype[k] = StrAlloc("swap");
|
||||
Faction[k] = 1;
|
||||
break;
|
||||
default:
|
||||
CleanMount(disk,part);
|
||||
return "Unknown filesystem-type";
|
||||
}
|
||||
Fsize[k] = (Dlbl[disk]->d_partitions[part].p_size+1024)/2048;
|
||||
|
||||
MP[disk][part] = k;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
enable_label(int fd)
|
||||
{
|
||||
int flag = 1;
|
||||
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
||||
Fatal("ioctl(DIOCWLABEL,1) failed: %s",strerror(errno));
|
||||
}
|
||||
|
||||
void
|
||||
disable_label(int fd)
|
||||
{
|
||||
int flag = 0;
|
||||
if (ioctl(fd, DIOCWLABEL, &flag) < 0)
|
||||
Fatal("ioctl(DIOCWLABEL,0) failed: %s",strerror(errno));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user