diff options
author | jkh <jkh@FreeBSD.org> | 1994-12-27 23:26:59 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1994-12-27 23:26:59 +0000 |
commit | 8b2cef6b70b4605908c2560ceeee5c4f4e277ad5 (patch) | |
tree | e08f30cbdf2653127108aeda590d2864607338e0 /sbin/sysinstall/stage1.c | |
parent | 1bba21e3a1a4a27d8fcf4fd5fcf8eeb133c64f0e (diff) | |
download | FreeBSD-src-8b2cef6b70b4605908c2560ceeee5c4f4e277ad5.zip FreeBSD-src-8b2cef6b70b4605908c2560ceeee5c4f4e277ad5.tar.gz |
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.
Diffstat (limited to 'sbin/sysinstall/stage1.c')
-rw-r--r-- | sbin/sysinstall/stage1.c | 390 |
1 files changed, 185 insertions, 205 deletions
diff --git a/sbin/sysinstall/stage1.c b/sbin/sysinstall/stage1.c index b094827..f778fca 100644 --- a/sbin/sysinstall/stage1.c +++ b/sbin/sysinstall/stage1.c @@ -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; - - free(scratch); - free(errmsg); + int i,j; + char disk[15]; + char diskname[5]; + struct stat st; + struct disklabel dl; + int fd; + + 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; + } - for (i = 0; i < MAX_NO_DEVICES; i++) - free(device_list[i]); + Ndisk = 0; + + for (j = 0; device_list[j]; j++) { + for (i = 0; i < 10; i++) { + sprintf(diskname, "%s%d", device_list[j], i); + sprintf(disk, "/dev/r%sd", diskname); + if (stat(disk, &st) || !(st.st_mode & S_IFCHR)) + continue; + if ((fd = open(disk, O_RDWR)) == -1) + continue; + if (ioctl(fd, DIOCGDINFO, &dl) == -1) { + close(fd); + continue; + } + Dlbl[Ndisk] = Malloc(sizeof dl); + memcpy(Dlbl[Ndisk], &dl, sizeof dl); + Dname[Ndisk] = StrAlloc(diskname); + Dfd[Ndisk] = fd; + Ndisk++; + if(Ndisk == MAX_NO_DISKS) + return; + } + } } int -query_devices() +stage1() { - 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); + int i,j; + int ret=1; + int ready = 0; + int foundroot=0,foundusr=0,foundswap=0; + char *complaint=0; + + 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"); } - 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; - } + 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]); + } } - 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; - - 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]; - } + 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; } - return 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; } + |