1994-10-20 05:00:00 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdarg.h>
|
1994-11-18 18:13:13 +00:00
|
|
|
#include <fstab.h>
|
1994-10-20 05:00:00 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
1994-11-18 18:13:13 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/devconf.h>
|
1994-10-20 05:00:00 +00:00
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
#include <machine/console.h>
|
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
#include <dialog.h>
|
|
|
|
|
|
|
|
#include "disk.h"
|
1994-10-20 05:00:00 +00:00
|
|
|
#include "sysinstall.h"
|
|
|
|
|
|
|
|
unsigned char **options;
|
|
|
|
unsigned char *scratch;
|
|
|
|
unsigned char *errmsg;
|
|
|
|
unsigned char *bootblocks;
|
|
|
|
|
|
|
|
int dialog_active = 0;
|
|
|
|
|
1994-11-02 08:15:46 +00:00
|
|
|
/* Forward decls */
|
|
|
|
void exit_sysinstall(void);
|
|
|
|
void exit_prompt(void);
|
1994-10-20 05:00:00 +00:00
|
|
|
extern char *part_type(int);
|
|
|
|
|
|
|
|
char selection[30];
|
1994-11-18 18:13:13 +00:00
|
|
|
|
|
|
|
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;
|
1994-10-20 05:00:00 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
alloc_memory()
|
|
|
|
{
|
1994-11-02 06:19:53 +00:00
|
|
|
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);
|
|
|
|
}
|
1994-10-20 05:00:00 +00:00
|
|
|
|
1994-11-02 06:19:53 +00:00
|
|
|
return(0);
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_memory()
|
|
|
|
{
|
1994-11-18 18:13:13 +00:00
|
|
|
int i;
|
1994-10-20 05:00:00 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
free(scratch);
|
|
|
|
free(errmsg);
|
1994-10-20 05:00:00 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
for (i = 0; i < MAX_NO_DEVICES; i++)
|
|
|
|
free(device_list[i]);
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
int
|
|
|
|
query_devices()
|
1994-10-20 05:00:00 +00:00
|
|
|
{
|
1994-11-18 18:13:13 +00:00
|
|
|
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);
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
dev = 0; osize = 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;
|
|
|
|
}
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
1994-11-18 18:13:13 +00:00
|
|
|
return (0);
|
1994-10-20 05:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-11-19 05:20:13 +00:00
|
|
|
configure_disks()
|
1994-10-20 05:00:00 +00:00
|
|
|
{
|
1994-11-18 18:13:13 +00:00
|
|
|
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);
|
|
|
|
}
|
1994-11-02 06:19:53 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
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);
|
|
|
|
if (disk_list[i].selected)
|
|
|
|
sprintf(options[(i*2)+1], " ** %s, (%dMb) -> %s%d",
|
|
|
|
disk_list[i].lbl.d_typename,
|
|
|
|
disk_size(&disk_list[i].lbl),
|
|
|
|
disk_list[i].devconf->dc_name,
|
|
|
|
disk_list[i].devconf->dc_unit);
|
|
|
|
else
|
|
|
|
sprintf(options[(i*2)+1], " %s, (%dMb) -> %s%d",
|
|
|
|
disk_list[i].lbl.d_typename,
|
|
|
|
disk_size(&disk_list[i].lbl),
|
|
|
|
disk_list[i].devconf->dc_name,
|
|
|
|
disk_list[i].devconf->dc_unit);
|
|
|
|
}
|
1994-10-20 05:00:00 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
sprintf(options[no_disks*2], "%d", no_disks+1);
|
|
|
|
sprintf(options[(no_disks*2)+1], " Done");
|
|
|
|
|
1994-11-18 23:34:05 +00:00
|
|
|
dialog_clear_norefresh();
|
1994-11-19 05:20:13 +00:00
|
|
|
if (dialog_menu("FreeBSD Installation", scratch, -1, -1,
|
|
|
|
min(5, no_disks), no_disks, options, selection)) {
|
|
|
|
dialog_clear_norefresh();
|
|
|
|
sprintf(scratch,"\nYou selected cancel.\n");
|
1994-11-18 18:13:13 +00:00
|
|
|
AskAbort(scratch);
|
|
|
|
valid = 0;
|
1994-11-19 00:09:00 +00:00
|
|
|
continue;
|
1994-11-18 18:13:13 +00:00
|
|
|
}
|
|
|
|
choice = atoi(selection);
|
1994-11-19 05:20:13 +00:00
|
|
|
if (choice == no_disks)
|
1994-11-18 18:13:13 +00:00
|
|
|
valid = 1;
|
|
|
|
else {
|
1994-11-19 05:20:13 +00:00
|
|
|
if (edit_mbr(choice-1) == -1) {
|
|
|
|
sprintf(scratch, "\nThe following error occured while\nediting the master boot record.\n%s", errmsg);
|
1994-11-18 18:13:13 +00:00
|
|
|
AskAbort(scratch);
|
|
|
|
valid = 0;
|
1994-11-19 00:09:00 +00:00
|
|
|
continue;
|
1994-11-18 18:13:13 +00:00
|
|
|
};
|
1994-11-19 05:20:13 +00:00
|
|
|
if (edit_disklabel(choice-1) == -1) {
|
|
|
|
sprintf(scratch, "\nThe following error occured while\nediting the disklabel.\n%s", errmsg);
|
1994-11-18 18:13:13 +00:00
|
|
|
AskAbort(scratch);
|
|
|
|
valid = 0;
|
1994-11-19 00:09:00 +00:00
|
|
|
continue;
|
1994-11-18 18:13:13 +00:00
|
|
|
}
|
1994-11-19 05:20:13 +00:00
|
|
|
disk_list[choice-1].selected = 1;
|
1994-11-18 18:13:13 +00:00
|
|
|
}
|
|
|
|
} while (!valid);
|
|
|
|
}
|
1994-11-19 00:09:00 +00:00
|
|
|
|
1994-11-12 05:40:28 +00:00
|
|
|
int
|
1994-10-20 05:00:00 +00:00
|
|
|
stage1()
|
|
|
|
{
|
1994-11-18 18:13:13 +00:00
|
|
|
int i;
|
1994-11-02 06:19:53 +00:00
|
|
|
int ok = 0;
|
Public apology:
I have walked all over Paul Richards code again, and severely lobotomized
some of his stuff, in order to cut some corners for the 2.0-Alpha release.
I belive that we can now manipulate fdisk and disklabel-stuff sufficiently
for the release to actually be produced.
It's not that I don't like Paul and his code, I just need something I
can kick out of the door RSN.
Sysinstall is now under absolute code-freeze, only Jordan has my permission
to commit to this code (stage0 & 5). I would appreciate if everybody
else would finds problems in sysinstall send patches to me, and I will
commit them. THANKYOU.
The fdisk/disklabel editors are made in pure ncurses, and follow a model
"a`la spreadsheet".
There are some important functions which are missing still, and I would
appreciate if somebody would look at them.
The FDISK part needs a "whole-disk" option, and it needs a "rewrite
MBR-boot code" option.
The DISKLABEL part needs to be able to "import DOS-partition".
Both need a "HELP" function, (display a file "/HELP" using dialog is OK).
It seems to me like the wd.c and sd.c should reread the physical record
when a DIOCGDINFO is made, so that they can pick up changes in the
MBR-data. Otherwise there will be a couple of weird cases where we
cannot avoid replicating code from the kernel.
If you want to play with this, look at src/release/Makefile. You may need
to step back to version 1.38 of sys/i386/isa/fd.c to make "rootable"
floppies, it is not clear at this time if that indeed is the problem I
have been having.
Sleep well, my friends, and expect the real Alpha in 24H, if the tree is
still solid.
1994-11-01 10:10:43 +00:00
|
|
|
|
1994-11-18 18:13:13 +00:00
|
|
|
query_devices();
|
|
|
|
configure_disks();
|
|
|
|
exit(1);
|
|
|
|
}
|