diff options
Diffstat (limited to 'sbin/sysinstall')
| -rw-r--r-- | sbin/sysinstall/Makefile | 51 | ||||
| -rw-r--r-- | sbin/sysinstall/bootarea.c | 112 | ||||
| -rw-r--r-- | sbin/sysinstall/bootarea.h | 24 | ||||
| -rw-r--r-- | sbin/sysinstall/bteasy17.uu | 15 | ||||
| -rw-r--r-- | sbin/sysinstall/dev2c.sh | 80 | ||||
| -rw-r--r-- | sbin/sysinstall/disk.h | 96 | ||||
| -rw-r--r-- | sbin/sysinstall/editor.c | 118 | ||||
| -rw-r--r-- | sbin/sysinstall/editor.h | 27 | ||||
| -rw-r--r-- | sbin/sysinstall/exec.c | 86 | ||||
| -rw-r--r-- | sbin/sysinstall/label.c | 379 | ||||
| -rw-r--r-- | sbin/sysinstall/label.h | 52 | ||||
| -rw-r--r-- | sbin/sysinstall/main.c | 100 | ||||
| -rw-r--r-- | sbin/sysinstall/mbr.c | 477 | ||||
| -rw-r--r-- | sbin/sysinstall/mbr.h | 82 | ||||
| -rw-r--r-- | sbin/sysinstall/ourcurses.c | 38 | ||||
| -rw-r--r-- | sbin/sysinstall/rtermcap.c | 14 | ||||
| -rw-r--r-- | sbin/sysinstall/stage0.c | 107 | ||||
| -rw-r--r-- | sbin/sysinstall/stage1.c | 229 | ||||
| -rw-r--r-- | sbin/sysinstall/stage2.c | 235 | ||||
| -rw-r--r-- | sbin/sysinstall/stage3.c | 74 | ||||
| -rw-r--r-- | sbin/sysinstall/stage4.c | 30 | ||||
| -rw-r--r-- | sbin/sysinstall/stage5.c | 52 | ||||
| -rw-r--r-- | sbin/sysinstall/sysinstall.c | 835 | ||||
| -rw-r--r-- | sbin/sysinstall/sysinstall.h | 148 | ||||
| -rw-r--r-- | sbin/sysinstall/termcap.c | 61 | ||||
| -rw-r--r-- | sbin/sysinstall/utils.c | 349 |
26 files changed, 0 insertions, 3871 deletions
diff --git a/sbin/sysinstall/Makefile b/sbin/sysinstall/Makefile deleted file mode 100644 index d141faa72081..000000000000 --- a/sbin/sysinstall/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -PROG = sysinstall -MANEXT = 1 -NOMAN= yet -CLEANFILES= makedevs.c rtermcap - -.PATH: ${.CURDIR}/../disklabel - -SRCS = exec.c dkcksum.c label.c main.c mbr.c \ - stage0.c stage1.c stage2.c stage3.c stage5.c \ - termcap.c utils.c makedevs.c ourcurses.c - -CFLAGS += -Wall -g -static -LDADD = -ldialog -lncurses -lmytinfo -DPADD = ${LIBDIALOG} ${LIBNCURSES} ${LIBMYTINFO} - -.if exists(${.CURDIR}/../../sys/i386/boot/biosboot/obj) -BOOTS=${.CURDIR}/../../sys/i386/boot/biosboot/obj -.else -BOOTS=${.CURDIR}/../../sys/i386/boot/biosboot -.endif - -makedevs.c: dev2c.sh Makefile rtermcap - mkdir -p dev - cp ${.CURDIR}/../../etc/etc.i386/MAKEDEV dev - ( cd dev; sh ./MAKEDEV all ) - sh ${.CURDIR}/dev2c.sh dev > makedevs.tmp - rm -rf dev - uudecode < ${.CURDIR}/bteasy17.uu - file2c 'const unsigned char boot0[] = {' '};' \ - < bteasy17 >> makedevs.tmp - rm -rf bteasy17 - file2c 'const unsigned char boot1[] = {' '};' \ - < ${BOOTS}/boot1 >> makedevs.tmp - file2c 'const unsigned char boot2[] = {' '};' \ - < ${BOOTS}/boot2 >> makedevs.tmp - ./rtermcap cons25 | \ - file2c 'const char termcap_cons25[] = {' ',0};' \ - >> makedevs.tmp - ./rtermcap cons25-m | \ - file2c 'const char termcap_cons25_m[] = {' ',0};' \ - >> makedevs.tmp - ./rtermcap vt100 | \ - file2c 'const char termcap_vt100[] = {' ',0};' \ - >> makedevs.tmp - mv makedevs.tmp makedevs.c - -rtermcap: ${.CURDIR}/rtermcap.c - ${CC} -o rtermcap ${.CURDIR}/rtermcap.c -ltermcap - -.include <bsd.prog.mk> - diff --git a/sbin/sysinstall/bootarea.c b/sbin/sysinstall/bootarea.c deleted file mode 100644 index 917b65ec0af2..000000000000 --- a/sbin/sysinstall/bootarea.c +++ /dev/null @@ -1,112 +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. - */ - -#include <sys/types.h> -#include <sys/errno.h> -#include <sys/disklabel.h> -#include <sys/ioctl.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <unistd.h> -#include <stdio.h> -#include <string.h> -#include <dialog.h> - -#include "mbr.h" -#include "sysinstall.h" - -extern char *bootblocks; -extern struct mbr *mbr; - -int -write_bootblocks(int fd, struct disklabel *lbl) -{ - off_t of = lbl->d_partitions[OURPART].p_offset; - - 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"); - } - - enable_label(fd); - - 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) - ); - } - - disable_label(fd); - - 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); -} diff --git a/sbin/sysinstall/bootarea.h b/sbin/sysinstall/bootarea.h deleted file mode 100644 index 3c17eb9d718b..000000000000 --- a/sbin/sysinstall/bootarea.h +++ /dev/null @@ -1,24 +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 BOOT1 "/stand/sdboot" -#define BOOT2 "/stand/bootsd" - -/* XXX -- calculate these, this is nasty */ -#define DEFFSIZE 1024 -#define DEFFRAG 8 - -int Mb_to_cylbdry(int, struct disklabel *); -void default_disklabel(struct disklabel *, int, int); -int disk_size(struct disklabel *); diff --git a/sbin/sysinstall/bteasy17.uu b/sbin/sysinstall/bteasy17.uu deleted file mode 100644 index 2cc05b2e7b44..000000000000 --- a/sbin/sysinstall/bteasy17.uu +++ /dev/null @@ -1,15 +0,0 @@ -begin 664 bteasy17 -M,\".P([8CM"\`'S\B_2_``:Y``'RI>I@!@``B]58HD@'/#5T'+00]N0%K@26 -M]D0$_W0^Q@2`Z-H`BG0!BTP"ZPCHSP"Y`0`RT;L`?+@!`LT3<AZ!O_X!5:IU -M%NH`?```@/J!=`*R@(OJ0H#RLX@6.@>_O@>Y!`#&!BT',3+VB"V*100\`'0C -M/`5T'_[&OBH'Z'$`OD@'1D:+'`K_=`4R?01U\XVW<@?H6@"#QQ#^!BT'XLN` -M/G4$`G0+OCL'"O9U"LT8ZZR^*@?H.0#H-@`RY,T:B]J#PV"T`<T6M`!U"\T: -M.]-R\J!(!^L*S1:*Q#P<=/,$]CPQ<M8\-7?24+XH![L;!E/\K%`D?[0.S1!8 -MJ(!T\L-6N`$#NP`&N0$`,O;-$U[&!D@'/\,-B@T*1C`@+B`N("Z@9&ES:R`Q -M#0H*1&5F875L=#H@1C^@``$`!``&`P<'"@IC#F0.912`%($9@AZ3)*4GGRMU -M+U(OVS)`-_(]`&1O\TA01M-/<[)5;FGX3F]V96SL36EN:?A,:6YU^$%M;V5B -MX4)3Q$)31.E00TG80U#-5F5N:?A$;W-S9>,_OP`````````````````````` -M```````````````````````````````````````````````````````````` -1````````````````````5:H` -` -end diff --git a/sbin/sysinstall/dev2c.sh b/sbin/sysinstall/dev2c.sh deleted file mode 100644 index d395810704b8..000000000000 --- a/sbin/sysinstall/dev2c.sh +++ /dev/null @@ -1,80 +0,0 @@ -: -# -# ---------------------------------------------------------------------------- -# "THE BEER-WARE LICENSE" (Revision 42): -# <phk@login.dknet.dk> wrote this file. As long as you retain this notice you -# can do whatever you want with this stuff. If we meet some day, and you think -# this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp -# ---------------------------------------------------------------------------- -# -# $Id: stage3.c,v 1.4 1994/10/21 02:14:52 phk Exp $ -# -# During installation, we suffer badly of we have to run MAKEDEV. MAKEDEV -# need sh, ln, chown, mknod, awk, rm, test and probably emacs too when -# we come down to it. So instead this script will make a C-procedure which -# makes all the B & C nodes of a specified directory. -# -# Poul-Henning - -(cd $1; ls -li ) | sed 's/,//' | awk ' -BEGIN { - while (getline < "/etc/passwd") { - split($0,a,":") - uid[a[1]] = a[3] - } - while (getline < "/etc/group") { - split($0,a,":") - gid[a[1]] = a[3] - } - printf("/*\n"); - printf(" * This file is generated from the contents of /dev\n"); - printf(" */\n"); - printf("#define CHK(foo) {i = foo;}\n"); - printf("#include <unistd.h>\n"); - printf("#include <sys/types.h>\n"); - printf("#include <sys/stat.h>\n"); - printf("int makedevs()\n{\n\tint i=0;\n"); - } - { - printf ("/* %s */\n",$0) - $4 = uid[$4] - $5 = gid[$5] - if (substr($2,1,1) == "b") { - k="S_IFBLK" - } else if (substr($2,1,1) == "c") { - k="S_IFCHR" - } else if (substr($2,1,1) == "d") { - next - } else if (substr($2,1,1) == "-") { - next - } else { - next - } - m = 0; - if (substr($2,2,1) == "r") m += 400; - if (substr($2,3,1) == "w") m += 200; - if (substr($2,4,1) == "x") m += 100; - if (substr($2,5,1) == "r") m += 40; - if (substr($2,6,1) == "w") m += 20; - if (substr($2,7,1) == "x") m += 10; - if (substr($2,8,1) == "r") m += 4; - if (substr($2,9,1) == "w") m += 2; - if (substr($2,10,1) == "x") m += 1; - - if (a[$1] != 0) { - printf ("\tCHK(link(\"%s\",\"%s\"));\n", \ - a[$1],$11) - } else { - printf ("\tCHK(mknod(\"%s\",%s,makedev(%d,%d)));\n", \ - $11, k, $6, $7) - printf ("\tCHK(chmod(\"%s\",0%d));\n", \ - $11, m) - printf ("\tCHK(chown(\"%s\",%d,%d));\n", \ - $11, $4,$5) - a[$1] = $11 - } - } -END { - printf("\treturn i;\n}\n"); - } -' diff --git a/sbin/sysinstall/disk.h b/sbin/sysinstall/disk.h deleted file mode 100644 index 622dc0ccd187..000000000000 --- a/sbin/sysinstall/disk.h +++ /dev/null @@ -1,96 +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 - -/* XXX -- calculate these, this is nasty */ -#define DEFFSIZE 1024 -#define DEFFRAG 8 - -/* bootarea.c */ -int write_bootblocks(int); -int enable_label(int); -int disable_label(int); -/* label.c */ -char *diskname(int); - -struct mbr -{ - unsigned char padding[2]; - unsigned char bootcode[DOSPARTOFF]; - struct dos_partition dospart[4]; - unsigned short magic; -}; - -struct disk { - struct disklabel lbl; - struct mbr mbr; - struct devconf *devconf; - int selected; - int inst_part; - struct fstab mounts[MAXPARTITIONS]; -}; - -extern struct disk disk_list[]; - -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"} \ - ,{0xA7, "NEXTSTEP"} \ - ,{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)"} \ -}; diff --git a/sbin/sysinstall/editor.c b/sbin/sysinstall/editor.c deleted file mode 100644 index f4933bd371a6..000000000000 --- a/sbin/sysinstall/editor.c +++ /dev/null @@ -1,118 +0,0 @@ -#include <string.h> -#include <ncurses.h> -#include <dialog.h> - -#include "editor.h" - -int -disp_fields(WINDOW *window, struct field field[], int no_fields) -{ - int i, j; - int len; - - for (i=0; i < no_fields; i++) { - wmove(window, field[i].y, field[i].x); - switch (field[i].type) { - case F_TITLE: - case F_EDIT: - if (field[i].type == F_TITLE) - wattrset(window, title_attr); - else - wattrset(window, dialog_attr); - len=strlen(field[i].field); - for (j=0; j < field[i].width; j++) - if (j < len) - waddch(window, field[i].field[j]); - else - waddch(window, ' '); - break; - case F_BUTTON: - print_button(window, field[i].field, - field[i].y, - field[i].x, - FALSE); - break; - } - } - wrefresh(window); - return (0); -} - -int -change_field(struct field field, int key) -{ - int next; - - switch(key) { - case KEY_UP: - next = field.up; - break; - case KEY_DOWN: - next = field.down; - break; - case '\t': - next = field.right; - break; - case KEY_BTAB: - next = field.left; - break; - case '\n': - case '\r': - next = field.right; - break; - default: - next = -1; - break; - } - return (next); -} - -int -button_press(WINDOW *window, struct field field) -{ - int key; - - print_button(window, field.field, - field.y, - field.x, - TRUE); - key = wgetch(window); - - switch (key) { - case '\n': - case '\r': - return (0); - case KEY_UP: - case KEY_DOWN: - case KEY_BTAB: - case '\t': - default: - return (key); - } -} - -int -toggle_press(WINDOW *window, struct field field) -{ - int key; - - key = wgetch(window); - - switch (key) { - case ' ': - field.spare++; - if (!field.misc[field.spare]) - field.spare = 0; - sprintf(field.field, "%s", field.misc[field.spare]); - return (key); - break; - case '\n': - case '\r': - case KEY_UP: - case KEY_DOWN: - case KEY_BTAB: - case '\t': - default: - return (key); - } -} diff --git a/sbin/sysinstall/editor.h b/sbin/sysinstall/editor.h deleted file mode 100644 index 2783cc811a39..000000000000 --- a/sbin/sysinstall/editor.h +++ /dev/null @@ -1,27 +0,0 @@ -#define ESC 27 -#define TAB 9 - -struct field { - int y; - int x; - int width; - int maxlen; - int next; - int up; - int down; - int left; - int right; - char field[80]; - int type; - int spare; - char *misc; -}; - -#define F_EDIT 0 -#define F_TITLE 1 -#define F_BUTTON 2 -#define F_TOGGLE 3 - -int disp_fields(WINDOW *, struct field *, int); -int change_field(struct field, int); -int edit_line(WINDOW *, int, int, char *, int, int); diff --git a/sbin/sysinstall/exec.c b/sbin/sysinstall/exec.c deleted file mode 100644 index 379f41dc3078..000000000000 --- a/sbin/sysinstall/exec.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: exec.c,v 1.8.2.1 1994/11/21 03:11:59 phk Exp $ - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <unistd.h> -#include <string.h> -#include <dialog.h> -#include <errno.h> -#include <fcntl.h> - -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/reboot.h> - -#include "sysinstall.h" - -int -exec(int magic, char *cmd, char *args, ...) -{ - int pid, w, status; - char *argv[EXEC_MAXARG]; - int arg = 0; - va_list ap; - struct stat dummy; - - if (stat(cmd, &dummy) == -1) { - Fatal("Executable %s does not exist", cmd); - } - - va_start(ap, args); - argv[arg++] = (char *)args; - do { - if (arg >= EXEC_MAXARG) - Fatal("Too many arguments"); - } while ((argv[arg++] = va_arg(ap, char *))); - va_end(ap); - - if ((pid = fork()) == 0) { - switch (magic) { - case 0: - close(0); dup(debug_fd); - close(1); dup(debug_fd); - close(2); dup(debug_fd); - close(debug_fd); - break; - case 1: - close(2); dup(debug_fd); - close(debug_fd); - break; - case 2: - case 3: - close(debug_fd); - break; - case 4: - close(0) ; open("/stand/sysinstall",O_RDONLY); - close(1) ; open("/mnt/stand/sysinstall", - O_WRONLY|O_CREAT|O_TRUNC,0755); - default: - break; - } - execv(cmd, argv); - exit(1); - } - - while ((w = wait(&status)) != pid && w != -1) - ; - if ((status >> 8) == 20 && magic == 3) /* special case for bininst */ - reboot(RB_AUTOBOOT); - if (w == -1) - Fatal("Child process %s terminated abnormally\n", cmd); - return(status); -} diff --git a/sbin/sysinstall/label.c b/sbin/sysinstall/label.c deleted file mode 100644 index fd0b76eded8b..000000000000 --- a/sbin/sysinstall/label.c +++ /dev/null @@ -1,379 +0,0 @@ -/* - * $Id: label.c,v 1.31 1994/12/27 23:26:51 jkh Exp $ - */ - -#include <stdlib.h> -#include <limits.h> -#define DKTYPENAMES -#include <sys/param.h> -#include <ufs/ffs/fs.h> -#include <sys/types.h> -#include <string.h> -#include <sys/disklabel.h> -#include <ufs/ffs/fs.h> - -#include <string.h> -#include <dialog.h> -#include "sysinstall.h" - -static int -AskWhichPartition(char *prompt) -{ - char buf[10]; - int i; - *buf = 0; - i = AskEm(stdscr, prompt, buf, 2); - if (i != '\n' && i != '\r') return -1; - if (!strchr("abefghABEFGH",*buf)) return -1; - return tolower(*buf) - 'a'; -} - -void -DiskLabel() -{ - int i, j, done = 0, diskno, k; - char buf[128],*p; - struct disklabel *lbl, olbl; - struct dos_partition dp[NDOSPART]; - - u_long cyl, hd, sec, tsec; - u_long l1, l2, l3, l4; - char *yip = NULL; - u_long allocated_space, ourpart_size, ourpart_offset; - - *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; - } - olbl = *Dlbl[diskno]; - lbl = &olbl; - cyl = lbl->d_ncylinders; - hd = lbl->d_ntracks; - sec = lbl->d_nsectors; - tsec = lbl->d_secperunit; - for (i = lbl->d_npartitions; i < MAXPARTITIONS; i++) { - lbl->d_partitions[i].p_offset = 0; - lbl->d_partitions[i].p_size = 0; - lbl->d_partitions[i].p_fstype = 0; - } - lbl->d_npartitions = MAXPARTITIONS; - - if(Dname[diskno][0] == 's' && Dname[diskno][1] == 'd') - lbl->d_type = DTYPE_SCSI; - else - lbl->d_type = DTYPE_ST506; - - while(!done) { - clear(); standend(); - if (yip) { - 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': - 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; - } - } -} diff --git a/sbin/sysinstall/label.h b/sbin/sysinstall/label.h deleted file mode 100644 index 7af153e71a4b..000000000000 --- a/sbin/sysinstall/label.h +++ /dev/null @@ -1,52 +0,0 @@ -struct field label_field[] = { - { 6, 02, 10, 10, -1, -1, -1, -1, -1, "wd0a", F_TITLE, 0, 0}, - { 6, 16, 4, 4, -1, 48, 6, 49, 2, "YES", F_EDIT, 0, 0}, - { 6, 27, 7, 7, -1, 48, 7, 1, 3, "MSDOS", F_EDIT, 0, 0}, - { 6, 39, 5, 5, -1, 49, 8, 2, 4, "1000", F_EDIT, 0, 0}, - { 6, 47, 30, 79, -1, 49, 9, 3, 6, "/an/example/mountpoint", F_EDIT, 0, 0}, - { 8, 02, 4, 4, -1, -1, -1, -1, -1, "wd0b", F_TITLE, 0, 0}, - { 8, 16, 4, 4, -1, 1, 11, 4, 7, "YES", F_EDIT, 0, 0}, - { 8, 27, 7, 7, -1, 2, 12, 6, 8, "MSDOS", F_EDIT, 0, 0}, - { 8, 39, 5, 5, -1, 3, 13, 7, 9, "1000", F_EDIT, 0, 0}, - { 8, 47, 30, 79, -1, 4, 14, 8, 11, "/an/example/mountpoint", F_EDIT, 0, 0}, - {10, 02, 10, 10, -1, -1, -1, -1, -1, "wd0c", F_TITLE, 0, 0}, - {10, 16, 4, 4, -1, 6, 16, 9, 12, "YES", F_EDIT, 0, 0}, - {10, 27, 7, 7, -1, 7, 17, 11, 13, "MSDOS", F_EDIT, 0, 0}, - {10, 39, 5, 5, -1, 8, 18, 12, 14, "1000", F_EDIT, 0, 0}, - {10, 47, 30, 79, -1, 9, 19, 13, 16, "/an/example/mountpoint", F_EDIT, 0, 0}, - {12, 02, 10, 10, -1, -1, -1, -1, -1, "wd0d", F_TITLE, 0, 0}, - {12, 16, 4, 4, -1, 11, 21, 14, 17, "YES", F_EDIT, 0, 0}, - {12, 27, 7, 7, -1, 12, 22, 16, 18, "MSDOS", F_EDIT, 0, 0}, - {12, 39, 5, 5, -1, 13, 23, 17, 19, "1000", F_EDIT, 0, 0}, - {12, 47, 30, 79, -1, 14, 24, 18, 21, "/an/example/mountpoint", F_EDIT, 0, 0}, - {14, 02, 10, 10, -1, -1, -1, -1, -1, "wd0e", F_TITLE, 0, 0}, - {14, 16, 4, 4, -1, 16, 26, 19, 22, "YES", F_EDIT, 0, 0}, - {14, 27, 7, 7, -1, 17, 27, 21, 23, "MSDOS", F_EDIT, 0, 0}, - {14, 39, 5, 5, -1, 18, 28, 22, 24, "1000", F_EDIT, 0, 0}, - {14, 47, 30, 79, -1, 19, 29, 23, 26, "/an/example/mountpoint", F_EDIT, 0, 0}, - {16, 02, 10, 10, -1, -1, -1, -1, -1, "wd0f", F_TITLE, 0, 0}, - {16, 16, 4, 4, -1, 21, 31, 24, 27, "YES", F_EDIT, 0, 0}, - {16, 27, 7, 7, -1, 22, 32, 26, 28, "MSDOS", F_EDIT, 0, 0}, - {16, 39, 5, 5, -1, 23, 33, 27, 29, "1000", F_EDIT, 0, 0}, - {16, 47, 30, 79, -1, 24, 34, 28, 31, "/an/example/mountpoint", F_EDIT, 0, 0}, - {18, 02, 10, 10, -1, -1, -1, -1, -1, "wd0g", F_TITLE, 0, 0}, - {18, 16, 4, 4, -1, 26, 36, 29, 32, "YES", F_EDIT, 0, 0}, - {18, 27, 7, 7, -1, 27, 37, 31, 33, "MSDOS", F_EDIT, 0, 0}, - {18, 39, 5, 5, -1, 28, 38, 32, 34, "1000", F_EDIT, 0, 0}, - {18, 47, 30, 79, -1, 29, 39, 33, 36, "/an/example/mountpoint", F_EDIT, 0, 0}, - {20, 02, 10, 10, -1, -1, -1, -1, -1, "wd0h", F_TITLE, 0, 0}, - {20, 16, 4, 4, -1, 31, 48, 34, 37, "YES", F_EDIT, 0, 0}, - {20, 27, 7, 7, -1, 32, 48, 36, 38, "MSDOS", F_EDIT, 0, 0}, - {20, 39, 5, 5, -1, 33, 49, 37, 39, "1000", F_EDIT, 0, 0}, - {20, 47, 30, 79, 1, 34, 49, 38, 48, "/an/example/mountpoint", F_EDIT, 0, 0}, - { 0, 27, 17, 17, -1, -1, -1, -1, -1, "Disk label editor", F_TITLE, 0, 0}, - { 4, 2, 11, 11, -1, -1, -1, -1, -1, "Partition", F_TITLE, 0, 0}, - { 4, 14, 8, 8, -1, -1, -1, -1, -1, "Preserve", F_TITLE, 0, 0}, - { 4, 25, 10, 10, -1, -1, -1, -1, -1, "Filesystem", F_TITLE, 0, 0}, - { 4, 39, 5, 5, -1, -1, -1, -1, -1, "Size", F_TITLE, 0, 0}, - { 4, 47, 10, 10, -1, -1, -1, -1, -1, "Mountpoint", F_TITLE, 0, 0}, - { 2, 02, 11, 11, -1, -1, -1, -1, -1, "Free space:", F_EDIT, 0, 0}, - { 2, 15, 6, 6, -1, -1, -1, -1, -1, "000000", F_TITLE, 0, 0}, - {22, 20, 2, 2, -1, 36, 1, 39, 49, "OK", F_BUTTON, 0, 0}, - {22, 45, 2, 2, -1, 38, 3, 48, 1, "Cancel", F_BUTTON, 0, 0} -}; diff --git a/sbin/sysinstall/main.c b/sbin/sysinstall/main.c deleted file mode 100644 index d1db0e1c5eab..000000000000 --- a/sbin/sysinstall/main.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: main.c,v 1.20 1995/01/30 03:19:52 phk Exp $ - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <unistd.h> -#include <fcntl.h> -#include <signal.h> - -#include <dialog.h> - -#include <sys/ioctl.h> -#include <sys/reboot.h> - -#define EXTERN /* only in main.c */ - -#include "sysinstall.h" - -void -handle_intr(int sig) -{ - dialog_clear_norefresh(); - dialog_msgbox("User Interrupt", - "User interrupted. Aborting the installation", - -1, -1, 1); - ExitSysinstall(); -} - -int -main(int argc, char **argv) -{ - signal(SIGINT, SIG_IGN); - - /* Are we running as init? */ - cpio_fd = -1; - if (getpid() == 1) { - setsid(); - if (argc > 1 && strchr(argv[1],'C')) { - /* Kernel told us that we are on a CDROM root */ - close(0); open("/bootcd/dev/console",O_RDWR); - close(1); dup(0); - close(2); dup(0); - cpio_fd = open("/floppies/cpio.flp",O_RDONLY); - on_cdrom++; - chroot("/bootcd"); - } else { - close(0); open("/dev/console",O_RDWR); - close(1); dup(0); - close(2); dup(0); - } - printf("sysinstall running as init\n\r"); - ioctl(0,TIOCSCTTY,(char *)NULL); - setlogin("root"); - setbuf(stdin,0); - setbuf(stdout,0); - setbuf(stderr,0); - } - if (set_termcap() == -1) { - Fatal("Can't find terminal entry\n"); - } - /* XXX too early to use fatal ! */ - - /* XXX - libdialog has particularly bad return value checking */ - init_dialog(); - /* If we haven't crashed I guess dialog is running ! */ - dialog_active = 1; - - signal(SIGINT, handle_intr); - - if (getpid() != 1) { - stage0(); - stage1(); - end_dialog(); - dialog_active=0; - } else if (!access("/this_is_boot_flp",R_OK)) { - while(1) { - stage0(); - if(!stage1()) - break; - } - stage2(); - end_dialog(); - dialog_active=0; - reboot(RB_AUTOBOOT); - } else { - stage3(); - stage5(); - } - return 0; -} diff --git a/sbin/sysinstall/mbr.c b/sbin/sysinstall/mbr.c deleted file mode 100644 index 03a85a778aa8..000000000000 --- a/sbin/sysinstall/mbr.c +++ /dev/null @@ -1,477 +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. - */ - -#include <stdio.h> -#include <unistd.h> -#include <dialog.h> -#include <fcntl.h> - -#include <sys/types.h> -#include <sys/disklabel.h> -#include <sys/uio.h> - -#include "mbr.h" -#include "sysinstall.h" - -extern struct mbr *mbr; -extern int inst_part; -extern int whole_disk; - -struct part_type part_types[] = PARTITION_TYPES - -char * -part_type(int type) -{ - int num_types = (sizeof(part_types)/sizeof(struct part_type)); - int next_type = 0; - struct part_type *ptr = part_types; - - while (next_type < num_types) { - if(ptr->type == type) - return(ptr->name); - ptr++; - next_type++; - } - return("Unknown"); -} - -void -read_dospart(int fd, struct dos_partition *dp) -{ - u_char buf[512]; - if (lseek(fd, 0, SEEK_SET) == -1) - AskAbort("Couldn't seek for master boot record read\n"); - if (read(fd, buf, 512) != 512) { - AskAbort("Failed to read master boot record\n"); - } - memcpy(dp, buf+DOSPARTOFF, sizeof(*dp)*NDOSPART); -} - -void -write_dospart(int fd, struct dos_partition *dp) -{ - u_char buf[512]; - - if (lseek(fd, 0, SEEK_SET) == -1) - AskAbort("Couldn't seek for master boot record read\n"); - if (read(fd, buf, 512) != 512) { - AskAbort("Failed to read master boot record\n"); - } - memcpy(buf+DOSPARTOFF, dp, sizeof(*dp)*NDOSPART); - buf[510] = 0x55; - buf[511] = 0xaa; - if (lseek(fd, 0, SEEK_SET) == -1) - AskAbort("Couldn't seek for master boot record write\n"); - enable_label(fd); - if (write(fd, buf, 512) != 512) - AskAbort("Failed to write master boot record\n"); - disable_label(fd); -} - -void -write_bootcode(int fd) -{ - u_char buf[512]; - - if (lseek(fd, 0, SEEK_SET) == -1) - AskAbort("Couldn't seek for master boot record read\n"); - if (read(fd, buf, 512) != 512) { - AskAbort("Failed to read master boot record\n"); - } - memcpy(buf, boot0, 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 -WriteBootblock(int dfd,struct disklabel *label,struct dos_partition *dospart) -{ - off_t of = label->d_partitions[OURPART].p_offset; - u_char bootblocks[BBSIZE]; - - memcpy(bootblocks, boot1, MBRSIZE); - - memcpy(&bootblocks[MBRSIZE], boot2, (int)(label->d_bbsize - MBRSIZE)); - - 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); -} - -static int -FillIn(struct dos_partition *dp, int sec, int hd) -{ - u_long l2,l3=0,sect,c,s,h; - - 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; -} - -void -Fdisk() -{ - 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(!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 use (B)oot manager"); - 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) { - - case 'h': case 'H': - clear(); - mvprintw(0, 0, -"%s -- Diskspace editor -- FDISK -- Command Help - -Basic commands: - -(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 - -Advanced commands: - -(U)se entire disk for FreeBSD - Assign ALL disk space on current drive -(G)eometry - Edit the default disk geometry settings -Write (B)oot manager - Install multi-OS bootmanager. - - -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': - grumble = 0; - for(i=0;i<NDOSPART;i++) { - if(dp[i].dp_start == 0 && dp[i].dp_typ== MBR_PTYPE_FreeBSD) { - grumble = "Boot manager not needed."; - break; - } - } - if (!grumble) - 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 - 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; - - case 'u': case 'U': - memset(&dp[0], 0, sizeof dp); - changed=1; - - dp[0].dp_start = 0; - dp[0].dp_size = tsec; - FillIn(&dp[0],sec,hd); - - 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': - 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; - goto wok; - } - } - grumble = "No FreeBSD slice, cannot write."; - break; - - wok: - 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"; - } - - break; - - case 'q': case 'Q': - return; - break; - default: - beep(); - break; - } - } -} - diff --git a/sbin/sysinstall/mbr.h b/sbin/sysinstall/mbr.h deleted file mode 100644 index 9c7d190c747f..000000000000 --- a/sbin/sysinstall/mbr.h +++ /dev/null @@ -1,82 +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 swap"} \ - ,{0x83, "Linux filesystem"} \ - ,{0x93, "Amoeba filesystem"} \ - ,{0x94, "Amoeba bad block table"} \ - ,{0xA5, "FreeBSD/NetBSD/386BSD"} \ - ,{0xA7, "NEXTSTEP"} \ - ,{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 *); diff --git a/sbin/sysinstall/ourcurses.c b/sbin/sysinstall/ourcurses.c deleted file mode 100644 index 4ee3dec82184..000000000000 --- a/sbin/sysinstall/ourcurses.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Stopgap, until Paul does the right thing */ -#define ESC 27 -#define TAB 9 - -#include <stdlib.h> -#include <limits.h> -#include <sys/types.h> -#include <string.h> - -#include <string.h> -#include <dialog.h> -#include "sysinstall.h" - -int -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); -} - -void -ShowFile(char *filename, char *header) -{ - char buf[256]; - if (access(filename, R_OK)) { - sprintf(buf, "The %s file is not provided on the 1.2MB floppy image.", filename); - dialog_msgbox("Sorry!", buf, -1, -1, 1); - dialog_clear_norefresh(); - return; - } - dialog_clear_norefresh(); - dialog_textbox(header, filename, LINES, COLS); - dialog_clear_norefresh(); -} - diff --git a/sbin/sysinstall/rtermcap.c b/sbin/sysinstall/rtermcap.c deleted file mode 100644 index 3f18e8b32ad4..000000000000 --- a/sbin/sysinstall/rtermcap.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdio.h> -#include <termcap.h> - -int -main(int argc, char **argv) -{ - char buf[4096]; - int i; - - i = tgetent(buf, argv[1]); - - printf("%s",buf); - return 0; -} diff --git a/sbin/sysinstall/stage0.c b/sbin/sysinstall/stage0.c deleted file mode 100644 index 8c5a3679b34d..000000000000 --- a/sbin/sysinstall/stage0.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 1994, Jordan Hubbard, Paul Richards and Poul-Henning Kamp. - * - * 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. - * - * [Note: This file bears almost no resemblance to what was here in an - * earlier incarnation]. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/reboot.h> -#include <dialog.h> - -#include "sysinstall.h" - -static unsigned char *welcome[] = { - "1. README", - "READ THIS FIRST.", - "2. Release Notes", - "Read the 2.0 Release Notes (recommended).", - "3. Troubleshooting", - "Read this in case of trouble.", - "4. Partitions and MBRs", - "Verbose description of how these work.", - "5. COPYRIGHT", - "Read FreeBSD Copyright Information.", - "6. Install", - "Proceed with full installation.", - "7. Fixit", - "Repair existing installation (fixit mode).", - "8. Quit", - "Don't do anything, just reboot.", -}; - -void -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, 8, 8, welcome, selection, NULL, NULL)) - ExitSysinstall(); - - switch (atoi(selection)) { - case 1: /* View the README */ - ShowFile(README_FILE, "Read Me First"); - goto evil_goto; - break; - - case 2: /* View the release notes */ - ShowFile(RELNOTES_FILE, "Release Notes"); - goto evil_goto; - break; - - case 3: /* View the troubleshooting file */ - ShowFile(TROUBLE_FILE, "Troubleshooting"); - goto evil_goto; - break; - - 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 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! :) */ - } -} diff --git a/sbin/sysinstall/stage1.c b/sbin/sysinstall/stage1.c deleted file mode 100644 index ade697b1458c..000000000000 --- a/sbin/sysinstall/stage1.c +++ /dev/null @@ -1,229 +0,0 @@ -/* -#define DEBUG - * 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 <dialog.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdarg.h> - -#include <sys/types.h> -#include <sys/errno.h> -#include <sys/disklabel.h> -#include <sys/ioctl.h> -#include <sys/param.h> -#include <sys/stat.h> - -#include "sysinstall.h" - -char * device_list[] = {"wd","sd",0}; - -void -query_disks() -{ - 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; - } - - 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 -stage1() -{ - 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 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"); - } - - 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; -} - diff --git a/sbin/sysinstall/stage2.c b/sbin/sysinstall/stage2.c deleted file mode 100644 index 7d028453ac67..000000000000 --- a/sbin/sysinstall/stage2.c +++ /dev/null @@ -1,235 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: stage2.c,v 1.26 1995/03/15 06:16:10 phk Exp $ - * - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> -#include <unistd.h> - -#include <fcntl.h> -#include <dialog.h> -#include <errno.h> - -#include <sys/stat.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/wait.h> - -#include "sysinstall.h" - -void -stage2() -{ - char *p, *q; - char pbuf[90]; - char dbuf[90]; - FILE *f1; - int i, j, k; - int ffd, pfd[2]; - int zpid, cpid; - - memset(Fsize, 0, sizeof Fsize); - - /* Sort in mountpoint order */ - for (i = 1; Fname[i]; i++) - Fsize[i] = i; - Fsize[i] = 0; - - for (j = 1; 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; - } - } - - for (j = 1; Fsize[j]; j++) { - if (strcmp(Ftype[Fsize[j]], "ufs")) - continue; - p = Fname[Fsize[j]]; - strcpy(pbuf, "/dev/r"); - strcat(pbuf, p); - 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 = 1; Fsize[j]; j++) { - if (!strcmp(Ftype[Fsize[j]], "swap")) - continue; - strcpy(dbuf, "/mnt"); - p = Fname[Fsize[j]]; - q = Fmount[Fsize[j]]; - if (strcmp(q, "/")) - strcat(dbuf, q); - if (!strcmp(Ftype[Fsize[j]], "ufs")) { - MountUfs(p, dbuf, 1, 0); - continue; - } else { - Mkdir(dbuf, FALSE); - } - } - - Mkdir("/mnt/etc", TRUE); - Mkdir("/mnt/dev", TRUE); - Mkdir("/mnt/mnt", TRUE); - Mkdir("/mnt/stand", TRUE); - - TellEm("unzipping /stand/sysinstall onto hard disk"); - exec(4, "/stand/gzip", "zcat", 0 ); - Link("/mnt/stand/sysinstall","/mnt/stand/cpio"); - Link("/mnt/stand/sysinstall","/mnt/stand/bad144"); - Link("/mnt/stand/sysinstall","/mnt/stand/gunzip"); - Link("/mnt/stand/sysinstall","/mnt/stand/gzip"); - Link("/mnt/stand/sysinstall","/mnt/stand/zcat"); - Link("/mnt/stand/sysinstall","/mnt/stand/newfs"); - 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; - } - } - } - - TellEm("make /dev entries"); - chdir("/mnt/dev"); - makedevs(); - chdir("/"); - - TellEm("Making /mnt/etc/fstab"); - f1 = fopen("/mnt/etc/fstab","w"); - if (!f1) - Fatal("Couldn't open /mnt/etc/fstab for writing."); - - TellEm("Writing filesystems"); - chdir("/mnt"); - 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", - Fname[Fsize[j]], Fmount[Fsize[j]], Ftype[Fsize[j]]); - Mkdir(Fmount[Fsize[j]], FALSE); - } - } - chdir("/"); - TellEm("Writing procfs"); - fprintf(f1,"proc\t\t\t/proc\tprocfs rw 0 0\n"); - fclose(f1); - - j = fork(); - if (!j) { - chroot("/mnt"); - chdir("/"); - ffd = cpio_fd; - retry: - while (ffd < 0) { - dialog_msgbox(TITLE, - "Insert CPIO floppy in floppy drive 0", -1, -1, 1); - ffd = open("/dev/rfd0",O_RDONLY); - if (ffd > 0) - break; - Debug("problems opening /dev/rfd0: %d",errno); - } - dialog_clear_norefresh(); - TellEm("gunzip < /dev/fd0 | cpio -idum"); - pipe(pfd); - zpid = fork(); - if (!zpid) { - close(0); dup(ffd); close(ffd); - close(1); dup(pfd[1]); close(pfd[1]); - close(pfd[0]); - i = exec (1,"/stand/gunzip","/stand/gunzip", 0); - exit(i); - } - cpid = fork(); - if (!cpid) { - close(0); dup(pfd[0]); close(pfd[0]); - close(ffd); - close(pfd[1]); - close(1); open("/dev/null",O_WRONLY); - i = exec (1,"/stand/cpio","/stand/cpio","-iduvm", 0); - exit(i); - } - close(pfd[0]); - close(pfd[1]); - close(ffd); - i = wait(&j); - if (i < 0 || j) - Fatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s", - i, j, cpid, zpid, strerror(errno)); - i = wait(&j); - if (i < 0 || j) - Fatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s", - i, j, cpid, zpid, strerror(errno)); - - /* bininst.sh MUST be the last file on the floppy */ - if (access("/OK", R_OK) == -1) { - AskAbort("CPIO floppy was bad! Please check media for defects and retry."); - ffd = -1; - goto retry; - } - unlink("/OK"); - exit (0); - } - i = wait(&k); - Debug("chroot'er: %d %d %d",i,j,k); - - - sync(); - TellEm("Unmount disks"); - for (j = 1; Fsize[j]; j++) - continue; - - for (j--; j > 0; j--) { - if (!strcmp(Ftype[Fsize[j]],"swap")) - continue; - strcpy(dbuf,"/mnt"); - 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\n and hit return to reboot from the hard disk", -1, -1, 1); - dialog_clear(); -} diff --git a/sbin/sysinstall/stage3.c b/sbin/sysinstall/stage3.c deleted file mode 100644 index c08cccbdfdd4..000000000000 --- a/sbin/sysinstall/stage3.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: stage3.c,v 1.9.2.1 1994/11/21 03:12:18 phk Exp $ - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <dialog.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <fstab.h> - -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> - -#include "sysinstall.h" - -void -stage3() -{ - char pbuf[90],*p; - int mountflags; - struct fstab *fs; - - /* - * Mount things in /etc/fstab we like. - */ - - mountflags = MNT_UPDATE; - while((fs = getfsent()) != NULL) { - p = fs->fs_spec; - if (*p++ != '/') continue; - if (*p++ != 'd') continue; - if (*p++ != 'e') continue; - if (*p++ != 'v') continue; - if (*p++ != '/') continue; - - if (!strcmp(fs->fs_type, "sw")) { - if (swapon(fs->fs_spec) == -1) - AskAbort("Unable to swap to %s - are you sure it's right?", - fs->fs_spec); - continue; - } - - if (strcmp(fs->fs_vfstype, "ufs")) continue; - - if (!strcmp(fs->fs_type, "ro")) - mountflags |= MNT_RDONLY; - else if (!strcmp(fs->fs_type, "rw")) - ; - else - continue; - strcpy(pbuf, "/dev/r"); - strcat(pbuf,p); - TellEm("fsck -y %s",pbuf); - if (exec(0, "/stand/fsck", - "/stand/fsck", "-y", pbuf, 0) == -1) - Fatal("exec(fsck) failed"); - - MountUfs(p, fs->fs_file, 0, mountflags); - mountflags = 0; - } - endfsent(); -} diff --git a/sbin/sysinstall/stage4.c b/sbin/sysinstall/stage4.c deleted file mode 100644 index 4f127ace0e04..000000000000 --- a/sbin/sysinstall/stage4.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: stage4.c,v 1.12 1995/01/28 01:13:28 jkh Exp $ - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <dialog.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/wait.h> - -#include "sysinstall.h" - -void -stage4() { /* Obsolete */ } diff --git a/sbin/sysinstall/stage5.c b/sbin/sysinstall/stage5.c deleted file mode 100644 index 218233a76464..000000000000 --- a/sbin/sysinstall/stage5.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: stage5.c,v 1.17 1994/12/27 23:26:57 jkh Exp $ - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <dialog.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/stat.h> - -#include "sysinstall.h" - -static unsigned char msg[] = " -You are now done with the initial phase of the installation that -gets FreeBSD onto your hard disk. At this point, we need to go on -to use FTP, NFS, Tape, CD or DOS floppies to get a bindist onto your -system so that it's actually usable. Select Yes to proceed with this -phase, or No to simply drop into a shell."; - -void -stage5() -{ - int exec_sh = 1; - - 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/scripts/bininst.sh", - "/stand/scripts/-bininst.sh", 0); - dialog_active=1; - } -} diff --git a/sbin/sysinstall/sysinstall.c b/sbin/sysinstall/sysinstall.c deleted file mode 100644 index 1d90daa4d3be..000000000000 --- a/sbin/sysinstall/sysinstall.c +++ /dev/null @@ -1,835 +0,0 @@ -/* -#define DEBUG - * 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 <dialog.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdarg.h> - -#include <sys/types.h> -#include <sys/errno.h> -#include <sys/disklabel.h> -#include <sys/ioctl.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/reboot.h> -#include <sys/stat.h> -#include <sys/utsname.h> -#include <sys/wait.h> -#include <ufs/ffs/fs.h> -#include <machine/console.h> - -#include "mbr.h" -#include "bootarea.h" -#include "sysinstall.h" - -struct disklabel *avail_disklabels; -int *avail_fds; -unsigned char **options; -unsigned char **avail_disknames; -unsigned char *scratch; -unsigned char *errmsg; -unsigned char *bootblocks; -struct mbr *mbr; -struct utsname utsname; -unsigned char *title = utsname.sysname; - -struct sysinstall *sysinstall; -struct sysinstall *sequence; - -int no_disks = 0; -int inst_disk = 0; -int inst_part = 0; -int custom_install; -int dialog_active = 0; - -void exit_sysinstall(); -void abort_installation(char *); -void exit_prompt(); -void fatal(char *); -extern char *part_type(int); -extern int disk_size(int); - -/* To make the binary as small as possible these should be malloc'd */ -char selection[30]; - -void -abort_installation(char *prompt) -{ - strcpy(scratch, prompt); - strcat(scratch,"\n\n Do you wish to abort the installation ?"); - if (!dialog_yesno("Abort installation ?",scratch,10,75)) - exit_prompt(); - dialog_clear(); -} - -void -exit_prompt() -{ - sprintf(scratch,"Are you sure you want to exit sysinstall?"); - if (!dialog_yesno("Exit sysinstall", scratch, 10, 75)) - exit_sysinstall(); - dialog_clear(); -} - -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); - - avail_disklabels = - (struct disklabel *)calloc(MAX_NO_DISKS, sizeof(struct disklabel)); - if (!avail_disklabels) - return(-1); - - avail_fds = (int *) calloc(MAX_NO_DISKS, sizeof(int)); - if (!avail_fds) - return(-1); - - avail_disknames = (unsigned char **) calloc(MAX_NO_DISKS, sizeof(char *)); - if (!avail_disknames) - return(-1); - for (i = 0; i < MAX_NO_DISKS; i++) { - avail_disknames[i] = (char *)calloc(15, sizeof(char)); - if (!avail_disknames[i]) - return(-1); - } - - options = (unsigned char **)calloc(MAX_NO_DISKS, sizeof(char *)); - if (!options) - return(-1); - for (i = 0; i < MAX_NO_DISKS; i++) { - options[i] = (char *)calloc(100, sizeof(char)); - if (!options[i]) - return(-1); - } - - mbr = (struct mbr *)malloc(sizeof(struct mbr)); - if (!mbr) - return(-1); - - bootblocks = (char *)malloc(BBSIZE); - if (!bootblocks) - return(-1); - - sysinstall = (struct sysinstall *)malloc(sizeof(struct sysinstall)); - if (!sysinstall) - return(-1); - - sequence = (struct sysinstall *)malloc(sizeof(struct sysinstall)); - if (!sequence) - return(-1); - return(0); -} - -void -free_memory() -{ - int i; - - free(scratch); - free(errmsg); - free(avail_disklabels); - free(avail_fds); - - for (i = 0; i < MAX_NO_DISKS; i++) - free(avail_disknames[i]); - free(avail_disknames); - - for (i = 0; i < MAX_NO_DISKS; i++) - free(options[i]); - free(options); - - free(mbr); - free(bootblocks); - free(sysinstall); - free(sequence); -} - -void -exit_sysinstall() -{ - if (getpid() == 1) { - if (reboot(RB_AUTOBOOT) == -1) - if (dialog_active) - while (1) - dialog_msgbox("Exit sysinstall", - "Reboot failed -- hit reset", - 10, 75, 20); - else { - fprintf(stderr, "Reboot failed -- hit reset"); - while (1); - } - } else { - free_memory(); - if (dialog_active) - end_dialog(); - exit(0); - } -} - -void -fatal(char *errmsg) -{ - if (dialog_active) - dialog_msgbox("Fatal Error -- Aborting installation", - errmsg, 10, 75, 20); - else - fprintf(stderr, "Fatal Error -- Aborting installation:\n%s\n", errmsg); - exit_sysinstall(); -} - -void -query_disks() -{ - int i; - char disk[15]; - char diskname[5]; - struct stat st; - int fd; - - no_disks = 0; - for (i = 0; i < 10; i++) { - sprintf(diskname,"wd%d",i); - sprintf(disk,"/dev/r%sd",diskname); - if ((stat(disk, &st) == 0) && (st.st_mode & S_IFCHR)) - if ((fd = open(disk, O_RDWR)) != -1) { - avail_fds[no_disks] = fd; - bcopy(diskname, avail_disknames[no_disks], strlen(diskname)); - if (ioctl(fd, DIOCGDINFO, &avail_disklabels[no_disks++]) == -1) - no_disks--; - } - } - - for (i=0;i<10;i++) { - sprintf(diskname,"sd%d",i); - sprintf(disk,"/dev/r%sd",diskname); - if ((stat(disk, &st) == 0) && (st.st_mode & S_IFCHR)) - if ((fd = open(disk, O_RDWR)) != -1) { - avail_fds[no_disks] = fd; - bcopy(diskname, avail_disknames[no_disks], strlen(diskname)); - if (ioctl(fd, DIOCGDINFO, &avail_disklabels[no_disks++]) == -1) - no_disks--; - } - } -} - -int -select_disk() -{ - int i; - int valid; - - do { - valid = 1; - 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, (%dMb) -> %s",avail_disklabels[i].d_typename,disk_size(i),avail_disknames[i]); - } - - if (dialog_menu("FreeBSD Installation", scratch, 10, 75, 5, no_disks, options, selection)) { - sprintf(scratch,"You did not select a valid disk"); - abort_installation(scratch); - valid = 0; - } - dialog_clear(); - } while (!valid); - return(atoi(selection) - 1); -} - -int -select_partition(int disk) -{ - int valid; - int i; - int choice; - - do { - valid = 1; - - sprintf(scratch,"Select one of the following areas to install to:"); - sprintf(options[0], "%d", 0); - sprintf(options[1], "%s, (%dMb)", "Install to entire disk", - disk_size(disk)); - for (i=0; i < NDOSPART; i++) { - sprintf(options[(i*2)+2], "%d",i+1); - sprintf(options[(i*2)+3], "%s, (%ldMb)", - part_type(mbr->dospart[i].dp_typ), - mbr->dospart[i].dp_size * 512 / (1024 * 1024)); - } - if (dialog_menu(title, - scratch, 10, 75, 5, 5, options, selection)) { - sprintf(scratch,"You did not select a valid partition"); - abort_installation(scratch); - valid = 0; - } - dialog_clear(); - choice = atoi(selection); - if (!choice) - if (dialog_yesno(title, "Installing to the whole disk will erase all its present data.\n\nAre you sure you want to do this?", 10, 75)) - valid = 0; - dialog_clear(); - } while (!valid); - - return(atoi(selection) - 1); -} - -int -exec(char *cmd, char *args, ...) -{ - int pid, w, status; - char **argv = NULL; - int arg = 0; - int no_args = 0; - va_list ap; - struct stat dummy; - - if (stat(cmd, &dummy) == -1) { - sprintf(errmsg, "Executable %s does not exist\n", cmd); - return(-1); - } - - va_start(ap, args); - do { - if (arg == no_args) { - no_args += 10; - if (!(argv = realloc(argv, no_args * sizeof(char *)))) { - sprintf(errmsg, "Failed to allocate memory during exec of %s\n", cmd); - return(-1); - } - if (arg == 0) - argv[arg++] = (char *)args; - } - } while ((argv[arg++] = va_arg(ap, char *))); - va_end(ap); - - if ((pid = fork()) == 0) { - execv(cmd, argv); - exit(1); - } - - while ((w = wait(&status)) != pid && w != -1) - ; - - free(argv); - if (w == -1) { - sprintf(errmsg, "Child process %s terminated abnormally\n", cmd); - return(-1); - } - - return(0); -} - -int -set_termcap() -{ - char *term; - - term = getenv("TERM"); - if (term == NULL) { - int color_display; - - if (setenv("TERMCAP", "/etc/termcap.small", 1) < 0) - return -1; - if (ioctl(STDERR_FILENO, GIO_COLOR, &color_display) < 0) { - char buf[64]; - int len; - - /* serial console */ - fprintf(stderr, "Enter your terminal type (must be present in /etc/termcap.small): "); - if (fgets(buf, sizeof(buf), stdin) == NULL) - return -1; - len = strlen(buf); - if (len > 0 && buf[len-1] == '\n') - buf[len-1] = '\0'; - if (setenv("TERM", buf, 1) < 0) - return -1; - } else if (color_display) { - - /* color console */ - if (setenv("TERM", "cons25", 1) < 0) - return -1; - } else { - - /* mono console */ - if (setenv("TERM", "cons25-m", 1) < 0) - return -1; - } - } - return 0; -} - -int -read_status(char *file, struct sysinstall *sysinstall) -{ - FILE *fd; - - if (!(fd = fopen(file, "r"))) { - sprintf(errmsg, "Couldn't open status file %s for reading\n", file); - return(-1); - } - if (fscanf(fd, "Root device: %s\n", sysinstall->root_dev) == -1) { - sprintf(errmsg, "Failed to read root device from file %s\n", file); - return(-1); - } - if (fscanf(fd, "Installation media: %s\n", sysinstall->media) == -1) { - sprintf(errmsg, "Failed to read installation media from file %s\n", file); - return(-1); - } - if (fscanf(fd, "Installation status: %d\n", &sysinstall->status) == -1) { - sprintf(errmsg, "Status file %s has invalid format\n", file); - return(-1); - } - if (fscanf(fd, "Sequence name: %s\n", sysinstall->seq_name) == -1) { - sprintf(errmsg, "Failed to read sequence name from file %s\n", file); - return(-1); - } - if (fscanf(fd, "Sequence number: %d of %d\n", - &sysinstall->seq_no, &sysinstall->seq_size) == -1) { - sprintf(errmsg, "Failed to read sequence information from file %s\n", file); - return(-1); - } - if (fscanf(fd, "Archive: %s\n", sysinstall->archive) == -1) { - sprintf(errmsg, "Failed to read archive name from file %s\n", file); - return(-1); - } - if (fclose(fd) != 0) { - sprintf(errmsg, "Couldn't close file %s after reading status\n", file); - return(-1); - } - return(0); -} - -int -write_status(char *file, struct sysinstall *sysinstall) -{ - FILE *fd; - - if (!(fd = fopen(file, "w"))) { - sprintf(errmsg, "Couldn't open status file %s for writing\n", file); - return(-1); - } - if (fprintf(fd, "Root device: %s\n", sysinstall->root_dev) == -1) { - sprintf(errmsg, "Failed to write root device to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Installation media: %s\n", sysinstall->media) == -1) { - sprintf(errmsg, "Failed to write installation media to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Installation status: %d\n", sysinstall->status) == -1) { - sprintf(errmsg, "Failed to write status information to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Sequence name: %s\n", sysinstall->seq_name) == -1) { - sprintf(errmsg, "Failed to write sequence name to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Sequence number: %d of %d\n", - sysinstall->seq_no, sysinstall->seq_size) == -1) { - sprintf(errmsg, "Failed to write sequence information to file %s\n", file); - return(-1); - } - if (fprintf(fd, "Archive: %s\n", sysinstall->archive) == -1) { - sprintf(errmsg, "Failed to write archive name to file %s\n", file); - return(-1); - } - if (fclose(fd) != 0) { - sprintf(errmsg, "Couldn't close status file %s after status update\n", file); - return(-1); - } - return(0); -} - -int -load_floppy(char *device, int seq_no) -{ - struct ufs_args ufsargs; - - ufsargs.fspec = device; - if (mount(MOUNT_UFS,"/mnt", 0, (caddr_t) &ufsargs) == -1) { - sprintf(errmsg, "Failed to mount floppy %s: %s\n",scratch, strerror(errno)); - return(-1); - } - - strcpy(scratch, "/mnt/"); - strcat(scratch, STATUSFILE); - if (read_status(scratch, sequence) == -1) { - if (unmount("/mnt", 0) == -1) { - strcat(errmsg, "Error unmounting floppy: "); - strcat(errmsg, strerror(errno)); - fatal(errmsg); - } - return(-1); - } - - if ((bcmp(sequence->seq_name, sysinstall->seq_name, - sizeof(sequence->seq_name)) != 0) || (sequence->seq_no != seq_no)) { - sprintf(errmsg, "Mounted floppy is not the one expected\n"); - if (unmount("/mnt", 0) == -1) { - strcat(errmsg, "Error unmounting floppy: "); - strcat(errmsg, strerror(errno)); - fatal(errmsg); - } - return(-1); - } - - return(0); -} - -void -stage1() -{ - int i; - int ok = 0; - int ready = 0; - struct ufs_args ufsargs; - - while (!ready) { - ready = 1; - - query_disks(); - inst_disk = select_disk(); - -#ifdef DEBUG - read_mbr(avail_fds[inst_disk], mbr); - show_mbr(mbr); -#endif - - if (read_mbr(avail_fds[inst_disk], mbr) == -1) { - sprintf(scratch, "The following error occured will trying to read the master boot record:\n\n%s\n\nIn order to install FreeBSD a new master boot record will have to be written which will mean all current data on the hard disk will be lost.", errmsg); - ok = 0; - while (!ok) { - abort_installation(scratch); - if (!dialog_yesno(title, "Are you sure you wish to proceed?", - 10, 75)) { - dialog_clear(); - clear_mbr(mbr); - ok = 1; - } - } - } - - if (custom_install) - if (!dialog_yesno(title, "Do you wish to edit the DOS partition table?", - 10, 75)) { - dialog_clear(); - edit_mbr(mbr, &avail_disklabels[inst_disk]); - } - - inst_part = select_partition(inst_disk); - - ok = 0; - while (!ok) { - if (build_mbr(mbr, &avail_disklabels[inst_disk])) - ok = 1; - else { - sprintf(scratch, "The DOS partition table is inconsistent.\n\n%s\n\nDo you wish to edit it by hand?", errmsg); - if (!dialog_yesno(title, scratch, 10, 75)) { - edit_mbr(mbr, &avail_disklabels[inst_disk]); - dialog_clear(); - } else { - abort_installation(""); - ok = 1; - ready = 0; - } - } - } - - default_disklabel(&avail_disklabels[inst_disk], - mbr->dospart[inst_part].dp_size, - mbr->dospart[inst_part].dp_start); - build_bootblocks(&avail_disklabels[inst_disk]); - - if (ready) { - if (dialog_yesno(title, "We are now ready to format the hard disk for FreeBSD.\n\nSome or all of the disk will be overwritten during this process.\n\nAre you sure you wish to proceed ?", 10, 75)) { - abort_installation(""); - ready = 0; - } - dialog_clear(); - } - } - - /* Write master boot record and bootblocks */ - write_mbr(avail_fds[inst_disk], mbr); - write_bootblocks(avail_fds[inst_disk], - mbr->dospart[inst_part].dp_start, - avail_disklabels[inst_disk].d_bbsize); - -#ifdef DEBUG - read_mbr(avail_fds[inst_disk], mbr); - show_mbr(mbr); -#endif - - /* close all the open disks */ - for (i=0; i < no_disks; i++) - if (close(avail_fds[i]) == -1) { - sprintf(errmsg, "Error on closing file descriptors: %s\n", - strerror(errno)); - fatal(errmsg); - } - - /* newfs the root partition */ - strcpy(scratch, avail_disknames[inst_disk]); - strcat(scratch, "a"); - if (exec("/sbin/newfs","/sbin/newfs", scratch, 0) == -1) - fatal(errmsg); - - /* newfs the /usr partition */ - strcpy(scratch, avail_disknames[inst_disk]); - strcat(scratch, "e"); - if (exec("/sbin/newfs", "/sbin/newfs", scratch, 0) == -1) - fatal(errmsg); - - strcpy(scratch, "/dev/"); - strcat(scratch, avail_disknames[inst_disk]); - strcat(scratch, "a"); - ufsargs.fspec = scratch; - if (mount(MOUNT_UFS,"/mnt", 0, (caddr_t) &ufsargs) == -1) { - sprintf(errmsg, "Error mounting %s: %s\n",scratch, strerror(errno)); - fatal(errmsg); - } - - if (mkdir("/mnt/usr",S_IRWXU) == -1) { - sprintf(errmsg, "Couldn't create directory /mnt/usr: %s\n", - strerror(errno)); - fatal(errmsg); - } - - if (mkdir("/mnt/mnt",S_IRWXU) == -1) { - sprintf(errmsg, "Couldn't create directory /mnt/mnt: %s\n", - strerror(errno)); - fatal(errmsg); - } - - strcpy(scratch, "/dev/"); - strcat(scratch, avail_disknames[inst_disk]); - strcat(scratch, "e"); - ufsargs.fspec = scratch; - if (mount(MOUNT_UFS,"/mnt/usr", 0, (caddr_t) &ufsargs) == -1) { - sprintf(errmsg, "Error mounting %s: %s\n",scratch, strerror(errno)); - fatal(errmsg); - } - - if (exec("/bin/cp","/bin/cp","/kernel","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /kernel to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","/sysinstall","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /sysinstall to /mnt: %s\n", - strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/etc","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /etc to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/sbin","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /sbin to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/bin","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /bin to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/dev","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /dev to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/cp","/bin/cp","-R","/usr","/mnt", 0) == -1) { - sprintf(errmsg, "Couldn't copy /usr to /mnt: %s\n",strerror(errno)); - fatal(errmsg); - } - - sysinstall->status = DISK_READY; - bcopy(avail_disknames[inst_disk], sysinstall->root_dev, - strlen(avail_disknames[inst_disk])); - sprintf(scratch, "/mnt/etc/%s", STATUSFILE); - if (write_status(scratch, sysinstall) == -1) - fatal(errmsg); - - if (unmount("/mnt/usr", 0) == -1) { - sprintf(errmsg, "Error unmounting /mnt/usr: %s\n", strerror(errno)); - fatal(errmsg); - } - - if (unmount("/mnt", 0) == -1) { - sprintf(errmsg, "Error unmounting /mnt: %s\n", strerror(errno)); - fatal(errmsg); - } -} - -void -stage2() -{ - int i; - struct ufs_args ufsargs; - - ufsargs.fspec = sysinstall->root_dev; - if (mount(MOUNT_UFS,"/", 0, (caddr_t) &ufsargs) == -1) { - sprintf(errmsg, "Failed to mount root read/write: %s\n%s", strerror(errno), ufsargs.fspec); - fatal(errmsg); - } - - sprintf(scratch, "Insert floppy %d in drive\n", sysinstall->seq_no + 1); - dialog_msgbox("Stage 2 installation", scratch, 10, 75, 1); - i = load_floppy(sysinstall->media, sysinstall->seq_no + 1); - while (i == -1) { - dialog_msgbox("Stage 2 installation",errmsg, 10, 75, 1); - sprintf(scratch, "Please insert installation floppy %d in the boot drive", sysinstall->seq_no + 1); - dialog_msgbox("Stage 2 installation",scratch, 10, 75, 1); - i = load_floppy(sysinstall->media, sysinstall->seq_no + 1); - }; - if (exec("/bin/cp","/bin/cp","/mnt/pax","/bin", 0) == -1) { - sprintf(errmsg, "Couldn't copy /mnt/pax to /bin %s\n",strerror(errno)); - fatal(errmsg); - } - if (exec("/bin/pax", "/bin/pax", "-r", "-f", sequence->archive, 0) == -1) { - sprintf(errmsg, "Failed to extract from archive file %s\n", sequence->archive); - fatal(errmsg); - } - - sysinstall->status = INSTALLED_BASE; - sprintf(scratch, "/etc/%s", STATUSFILE); - if (write_status(scratch, sysinstall) == -1) - fatal(errmsg); - - if (unmount("/mnt", 0) == -1) { - strcat(errmsg, "Error unmounting floppy: "); - strcat(errmsg, strerror(errno)); - fatal(errmsg); - } -} - -/* - * This is the overall plan: (phk's version) - * - * If (pid == 1) - * reopen stdin, stdout, stderr, and do various other magic. - * - * If (file exists /this_is_boot.flp) - * stage0: - * present /COPYRIGHT - * present /README - * stage1: - * Ask about diskallocation and do the fdisk/disklabel stunt. - * stage2: - * Do newfs, mount and copy over a minimal world. - * make /mnt/etc/fstab. Install ourself as /mnt/sbin/init - * Else - * stage3: - * Read cpio.flp and fiddle around with the bits a bit. - * stage4: - * Read bin-tarballs: - * Using ftp - * Using NFS (?) - * Using floppy - * Using tape - * Using shell-prompt - * stage5: - * Extract bin-tarballs - * stage6: - * Ask various questions and collect answers into system-config - * files. - * stage7: - * execl("/sbin/init"); - */ - -void -main(int argc, char **argv) -{ - int i; - - /* phk's main */ - if (argc > 1 && !strcmp(argv[1],"phk")) { - return Xmain(argc,argv); - } - - /* paul's main */ - /* Are we running as init? */ - if (getpid() == 1) { - close(0); open("/dev/console", O_RDWR); - close(1); dup(0); - close(2); dup(0); - i = 1; - ioctl(0,TIOCSPGRP,&i); - setlogin("root"); - } - - if (set_termcap() == -1) - fatal("Can't find terminal entry\n"); - - if (alloc_memory() == -1) - fatal("Couldn't allocate memory\n"); - -#if 0 /* Later. Our kernels don't say the right thing at present anyway */ - if (uname(&utsname) == -1) { - /* Fake uname entry */ - bcopy("FreeBSD", utsname.sysname, strlen("FreeBSD")); - } -#else - bcopy(TITLE, utsname.sysname, strlen(TITLE)); -#endif - - /* XXX - libdialog has particularly bad return value checking */ - init_dialog(); - /* If we haven't crashed I guess dialog is running ! */ - dialog_active = 1; - - strcpy(scratch, "/etc/"); - strcat(scratch, STATUSFILE); - if (read_status(scratch, sysinstall) == -1) { - fatal(errmsg); - } - - switch(sysinstall->status) { - case NOT_INSTALLED: - stage1(); - dialog_msgbox("Stage 1 complete", - "Remove all floppy disks from the drives and hit return to reboot from the hard disk", - 10, 75, 1); - if (reboot(RB_AUTOBOOT) == -1) - fatal("Reboot failed"); - break; - - case DISK_READY: - dialog_msgbox("Stage 2 install", "Hi!", 10, 75, 1); - stage2(); - dialog_msgbox("Stage 2 complete", - "Well, this is as far as it goes so far :-)\n", - 10, 75, 1); - break; - - case INSTALLED_BASE: - break; - - default: - fatal("Unknown installation status"); - } - exit_sysinstall(); -} diff --git a/sbin/sysinstall/sysinstall.h b/sbin/sysinstall/sysinstall.h deleted file mode 100644 index e127123079d1..000000000000 --- a/sbin/sysinstall/sysinstall.h +++ /dev/null @@ -1,148 +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 TITLE "FreeBSD 2.0-950418-SNAP Install" - -#define MAX_NO_DISKS 10 -#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> -#include <ncurses.h> -#include <string.h> -#include <errno.h> -#include <dialog.h> -#include <ctype.h> - -#include <sys/types.h> -#include <sys/ioctl.h> -#include <sys/dkbad.h> -#include <sys/disklabel.h> - -#define SCRATCHSIZE 1024 -#define ERRMSGSIZE 256 -#define DEFROOTSIZE 18 -#define DEFSWAPSIZE 16 -#define DEFUSRSIZE 80 -#define DEFFSIZE 1024 -#define DEFFRAG 8 - -#define BOOT_MAGIC 0xAA55 -#define ACTIVE 0x80 - -#define COPYRIGHT_FILE "/COPYRIGHT" -#define README_FILE "/README" -#define HELPME_FILE "/DISKSPACE.FAQ" -#define TROUBLE_FILE "/TROUBLESHOOTING" -#define RELNOTES_FILE "/RELNOTES.FreeBSD" - -#ifndef EXTERN -# define EXTERN extern -#endif - -extern unsigned char boot0[]; -extern unsigned char boot1[]; -extern unsigned char boot2[]; - -/* All this "disk" stuff */ -EXTERN int Ndisk; -EXTERN struct disklabel *Dlbl[MAX_NO_DISKS]; -EXTERN char *Dname[MAX_NO_DISKS]; -EXTERN int Dfd[MAX_NO_DISKS]; - -EXTERN int MP[MAX_NO_DISKS][MAXPARTITIONS]; - -/* All this "filesystem" stuff */ -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 on_serial; -EXTERN int on_cdrom; -EXTERN int cpio_fd; - -extern int no_disks; -extern int inst_disk; -extern unsigned char *scratch; -extern unsigned char *errmsg; -extern u_short dkcksum(struct disklabel *); - -/* utils.c */ -void Abort __P((void)); -void ExitSysinstall __P((void)); -void TellEm __P((char *fmt, ...)); -void Debug __P((char *fmt, ...)); -void stage0 __P((void)); -void *Malloc __P((size_t size)); -char *StrAlloc __P((char *str)); -void Fatal __P((char *fmt, ...)); -void AskAbort __P((char *fmt, ...)); -void MountUfs __P((char *device, char *mountpoint, int do_mkdir,int flags)); -void Mkdir __P((char *path, int die)); -void Link __P((char *from, char *to)); -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, ...)); -#define EXEC_MAXARG 100 - -/* stage0.c */ -void stage0 __P((void)); - -/* stage1.c */ -int stage1 __P((void)); - -/* stage2.c */ -void stage2 __P((void)); - -/* stage3.c */ -void stage3 __P((void)); - -/* stage5.c */ -void stage5 __P((void)); - -/* termcap.c */ -int set_termcap __P((void)); - -/* makedevs.c */ -int makedevs __P((void)); - -/* ourcurses.c */ -int AskEm __P((WINDOW *w,char *prompt, char *answer, int len)); -void ShowFile __P((char *filename, char *header)); - -/* mbr.c */ -int build_bootblocks __P((int dfd,struct disklabel *label,struct dos_partition *dospart)); -void Fdisk __P((void)); -void read_dospart __P((int, struct dos_partition *)); - -/* label.c */ -void DiskLabel __P((void)); diff --git a/sbin/sysinstall/termcap.c b/sbin/sysinstall/termcap.c deleted file mode 100644 index bd1e0863d2e5..000000000000 --- a/sbin/sysinstall/termcap.c +++ /dev/null @@ -1,61 +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. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <stdarg.h> -#include <fcntl.h> -#include <machine/console.h> - -#include "sysinstall.h" - -int -set_termcap() -{ - char *term; - extern const char termcap_vt100[]; - extern const char termcap_cons25[]; - extern const char termcap_cons25_m[]; - - term = getenv("TERM"); - if (term == NULL) { - int color_display; - - if (ioctl(STDERR_FILENO, GIO_COLOR, &color_display) < 0) { - if (setenv("TERM", "vt100", 1) < 0) - return -1; - if (setenv("TERMCAP", termcap_vt100, 1) < 0) - return -1; - debug_fd = dup(1); - on_serial++; - } else if (color_display) { - if (setenv("TERM", "cons25", 1) < 0) - return -1; - if (setenv("TERMCAP", termcap_cons25, 1) < 0) - return -1; - debug_fd = open("/dev/ttyv1",O_WRONLY); - } else { - if (setenv("TERM", "cons25-m", 1) < 0) - return -1; - if (setenv("TERMCAP", termcap_cons25_m, 1) < 0) - return -1; - debug_fd = open("/dev/ttyv1",O_WRONLY); - } - } else { - debug_fd = open("sysinstall.debug", - O_WRONLY|O_CREAT|O_TRUNC,0644); - } - return 0; -} diff --git a/sbin/sysinstall/utils.c b/sbin/sysinstall/utils.c deleted file mode 100644 index 243b1912ca74..000000000000 --- a/sbin/sysinstall/utils.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * <phk@login.dkuug.dk> wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $Id: utils.c,v 1.35 1995/01/14 10:31:29 jkh Exp $ - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <unistd.h> -#include <string.h> -#include <dialog.h> -#include <errno.h> - -#include <sys/file.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/reboot.h> -#include <sys/dkbad.h> -#include <sys/disklabel.h> - -#include "sysinstall.h" - -void -strip_trailing_newlines(char *p) -{ - int len = strlen(p); - while (len > 0 && p[len-1] == '\n') - p[--len] = '\0'; -} - -void -Debug(char *fmt, ...) -{ - char *p; - va_list ap; - p = Malloc(2048); - va_start(ap,fmt); - vsnprintf(p, 2048, fmt, ap); - va_end(ap); - write(debug_fd,"Debug <",7); - write(debug_fd,p,strlen(p)); - write(debug_fd,">\n\r",3); - free(p); -} - -void -TellEm(char *fmt, ...) -{ - char *p; - va_list ap; - p = Malloc(2048); - va_start(ap,fmt); - vsnprintf(p, 2048, fmt, ap); - va_end(ap); - strip_trailing_newlines(p); - write(debug_fd,"Progress <",10); - write(debug_fd,p,strlen(p)); - write(debug_fd,">\n\r",3); - if(!on_serial) { - dialog_clear_norefresh(); - dialog_msgbox("Progress", p, -1, -1, 0); - } - free(p); -} - -void -Fatal(char *fmt, ...) -{ - char *p; - va_list ap; - p = Malloc(2048); - va_start(ap,fmt); - vsnprintf(p, 2048, fmt, ap); - va_end(ap); - strip_trailing_newlines(p); - if (dialog_active && !on_serial) - dialog_msgbox("Fatal", p, -1, -1, 1); - else - fprintf(stderr, "Fatal -- %s\n", p); - free(p); - ExitSysinstall(); -} - -void -AskAbort(char *fmt, ...) -{ - char *p; - va_list ap; - - p = Malloc(2048); - va_start(ap,fmt); - vsnprintf(p, 2048, fmt, ap); - va_end(ap); - strcat(p, "\n\nDo you wish to abort the installation?"); - if (!dialog_yesno("Abort", p, -1, -1)) { - dialog_clear_norefresh(); - Abort(); - } - dialog_clear(); - free(p); -} - -void -Abort() -{ - if (dialog_yesno("Exit sysinstall","\n\nAre you sure you want to quit?", - -1, -1)) { - dialog_clear(); - return; - } - ExitSysinstall(); -} - -void -ExitSysinstall() -{ - if (dialog_active) { - clear(); - dialog_update(); - } - if (getpid() == 1) { - if (reboot(RB_AUTOBOOT) == -1) - if (dialog_active) { - clear(); - dialog_msgbox(TITLE, "\n\nCan't reboot machine -- hit reset button", - -1,-1,0); - } else - fprintf(stderr, "Can't reboot the machine -- hit the reset button"); - while(1); - } else { - if (dialog_active) { - end_dialog(); - dialog_active = 0; - } - exit(0); - } -} - -void * -Malloc(size_t size) -{ - void *p = malloc(size); - if (!p) { - exit(7); /* XXX longjmp bad */ - } - return p; -} - -char * -StrAlloc(char *str) -{ - char *p; - - p = (char *)Malloc(strlen(str) + 1); - strcpy(p,str); - return p; -} - -void -MountUfs(char *device, char *mountpoint, int do_mkdir, int flags) -{ - struct ufs_args ufsargs; - char dbuf[90]; - - memset(&ufsargs,0,sizeof ufsargs); - - if(do_mkdir && access(mountpoint,R_OK)) { - Mkdir(mountpoint, TRUE); - } - - strcpy(dbuf,"/dev/"); - strcat(dbuf,device); - - TellEm("mount %s %s",dbuf,mountpoint); - ufsargs.fspec = dbuf; - if (mount(MOUNT_UFS, mountpoint, flags, (caddr_t) &ufsargs) == -1) { - Fatal("Error mounting %s on %s : %s\n", - dbuf, mountpoint, strerror(errno)); - } -} - -void -Mkdir(char *ipath, int die) -{ - struct stat sb; - int final=0; - char *p,*path=StrAlloc(ipath); - - Debug("mkdir(%s)",path); - p = path; - if (p[0] == '/') /* Skip leading '/'. */ - ++p; - for (;!final; ++p) { - if (p[0] == '\0' || (p[0] == '/' && p[1] == '\0')) - final++; - else if (p[0] != '/') - continue; - *p = '\0'; - if (stat(path, &sb)) { - if (errno != ENOENT && die) - Fatal("Couldn't stat directory %s: %s\n", - path,strerror(errno)); - Debug("mkdir(%s..)",path); - if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && - die) - Fatal("Couldn't create directory %s: %s\n", - path,strerror(errno)); - } - *p = '/'; - } - free(path); - return; -} - -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); -} - -void -CopyFile(char *p1, char *p2) -{ - char buf[BUFSIZ]; - int fd1,fd2; - int i; - struct stat st; - - TellEm("Copy %s to %s",p1,p2); - fd1 = open(p1,O_RDONLY); - if (fd1 < 0) Fatal("Couldn't open %s: %s\n",p1,strerror(errno)); - fd2 = open(p2,O_TRUNC|O_CREAT|O_WRONLY,0200); - if (fd2 < 0) Fatal("Couldn't open %s: %s\n",p2,strerror(errno)); - for(;;) { - i = read(fd1,buf,sizeof buf); - if (i > 0) - if (i != write(fd2,buf,i)) { - Fatal("Write errror on %s: %s\n", - p2,strerror(errno)); - } - if (i != sizeof buf) - break; - } - fstat(fd1,&st); - fchmod(fd2,st.st_mode & 07777); - fchown(fd2,st.st_uid,st.st_gid); - close(fd1); - close(fd2); -} - -u_long -PartMb(struct disklabel *lbl,int part) -{ - u_long l; - 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)); -} - |
